"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VodPlayer = VodPlayer;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_native_1 = require("react-native");
const player_provider_1 = require("../../player-store/player-provider");
const player_store_1 = require("../../player-store/player-store");
const streamplace_store_1 = require("../../streamplace-store");
const video_1 = tslib_1.__importDefault(require("../mobile-player/video"));
function VodPlayer({ src, objectFit = "contain", embedded, muted: mutedProp, pictureInPictureEnabled, children, }) {
    return ((0, jsx_runtime_1.jsx)(player_provider_1.PlayerProvider, { children: (0, jsx_runtime_1.jsx)(VodPlayerInner, { src: src, objectFit: objectFit, embedded: !!embedded, muted: mutedProp, pictureInPictureEnabled: pictureInPictureEnabled, children: children }) }));
}
function VodPlayerInner({ src, objectFit, embedded, muted: mutedProp, pictureInPictureEnabled, children, }) {
    const setSrc = (0, player_store_1.usePlayerStore)((x) => x.setSrc);
    const setMode = (0, player_store_1.usePlayerStore)((x) => x.setMode);
    const setEmbedded = (0, player_store_1.usePlayerStore)((x) => x.setEmbedded);
    const storeSrc = (0, player_store_1.usePlayerStore)((x) => x.src);
    const setMuted = (0, streamplace_store_1.useSetMuted)();
    const muted = (0, streamplace_store_1.useMuted)();
    (0, react_1.useEffect)(() => {
        setMode("vod");
        setSrc(src);
    }, [src, setMode, setSrc]);
    (0, react_1.useEffect)(() => {
        setEmbedded(embedded);
    }, [embedded, setEmbedded]);
    (0, react_1.useEffect)(() => {
        if (mutedProp !== undefined) {
            let wasMuted = muted;
            setTimeout(() => setMuted(mutedProp), 200);
            return () => {
                if (wasMuted !== null)
                    setMuted(wasMuted);
            };
        }
    }, [mutedProp]);
    return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { width: "100%", height: "100%", backgroundColor: "#000" }, children: [storeSrc === src ? ((0, jsx_runtime_1.jsx)(video_1.default, { objectFit: objectFit, pictureInPictureEnabled: pictureInPictureEnabled })) : null, children] }));
}
//# sourceMappingURL=vod-player.js.map