"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.webDocument = void 0;
const PositionObserver_1 = require("../../../PositionObserver");
const IntersectionObserver_1 = require("../../../noop/IntersectionObserver");
const MutationObserver_1 = require("../../../noop/MutationObserver");
const ResizeObserver_1 = require("../../../noop/ResizeObserver");
const theme_1 = require("../../../theme");
function webDocument(window, root, opt) {
    const { document } = window;
    // @ts-ignore
    const MutationObserver = window.MutationObserver || MutationObserver_1.NoopMutationObserver;
    // @ts-ignore
    const ResizeObserver = window.ResizeObserver || ResizeObserver_1.NoopResizeObserver;
    const IntersectionObserver = 
    // @ts-ignore
    window.IntersectionObserver || IntersectionObserver_1.NoopIntersectionObserver;
    const _document = {
        createElement(tagName) {
            return document.createElement(tagName);
        },
        createElementNS(namespaceURI, qualifiedName) {
            return document.createElementNS(namespaceURI, qualifiedName);
        },
        createTextNode(text) {
            return document.createTextNode(text);
        },
        elementFromPoint(x, y) {
            return root.shadowRoot.elementFromPoint(x, y);
        },
        elementsFromPoint(x, y) {
            return root.shadowRoot.elementsFromPoint(x, y);
        },
        getSelection() {
            var _a, _b;
            // @ts-ignore
            return ((_b = (_a = root.shadowRoot) === null || _a === void 0 ? void 0 : _a.getSelection) === null || _b === void 0 ? void 0 : _b.call(_a)) || document.getSelection();
        },
        createRange() {
            return document.createRange();
        },
        exitPictureInPicture() {
            return document.exitPictureInPicture();
        },
        MutationObserver: MutationObserver,
        ResizeObserver: ResizeObserver,
        PositionObserver: PositionObserver_1.PositionObserver,
        IntersectionObserver: IntersectionObserver,
        setTheme: function (theme) {
            return __awaiter(this, void 0, void 0, function* () {
                const color = (0, theme_1.themeBackgroundColor)(theme);
                document.body.style.backgroundColor = color;
            });
        },
    };
    return _document;
}
exports.webDocument = webDocument;
//# sourceMappingURL=document.js.map