"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FindTopmost = void 0;
const index_js_1 = require("../model/index.js");
class FindTopmost extends index_js_1.Pipe {
    async apply(inputSet) {
        const zIndexes = await Promise.all(inputSet.map(el => el.evaluateJson((el) => {
            let max = 0;
            while (el.offsetParent) {
                const z = parseInt(window.getComputedStyle(el).getPropertyValue('z-index'));
                if (z && z > max) {
                    max = z;
                }
                el = el.offsetParent;
            }
            const z = parseInt(window.getComputedStyle(el).getPropertyValue('z-index'));
            if (z && z > max) {
                max = z;
            }
            return max;
        })));
        const zipped = inputSet.map((el, i) => [el, zIndexes[i]]);
        const sortedEls = zipped
            .sort((a, b) => a[1] > b[1] ? 1 : -1)
            .map(zip => zip[0]);
        return [sortedEls[0]];
    }
}
exports.FindTopmost = FindTopmost;
FindTopmost.$type = 'DOM.topmost';
FindTopmost.$help = ``;
//# sourceMappingURL=DOM.topmost.js.map