"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VideoProvider = VideoProvider;
exports.VideoFetcher = VideoFetcher;
exports.VideoPoller = VideoPoller;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const video_store_1 = require("../video-store");
const context_1 = require("../video-store/context");
const fetch_1 = require("./fetch");
function VideoProvider({ children, aturi, ignoreOuterContext = false, }) {
    const context = (0, react_1.useContext)(context_1.VideoContext);
    const store = (0, react_1.useRef)((0, video_store_1.makeVideoStore)({ aturi })).current;
    if (context) {
        // this is ok, there's use cases for having one in another
        // like having a player component that's independently usable
        // but can also be embedded within an entire video page
        if (!ignoreOuterContext) {
            return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
        }
    }
    window.videoStore = store;
    return ((0, jsx_runtime_1.jsx)(context_1.VideoContext.Provider, { value: { store: store }, children: (0, jsx_runtime_1.jsx)(VideoPoller, { aturi: aturi, children: children }) }));
}
function VideoFetcher({ aturi }) {
    (0, fetch_1.useVideoFetch)(aturi);
    return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
}
function VideoPoller({ children, aturi, }) {
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(VideoFetcher, { aturi: aturi }), children] }));
}
//# sourceMappingURL=index.js.map