"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoplayButton = AutoplayButton;
const jsx_runtime_1 = require("react/jsx-runtime");
const lucide_react_native_1 = require("lucide-react-native");
const react_native_1 = require("react-native");
const __1 = require("../../..");
const ui_1 = require("../../../ui");
function AutoplayButton() {
    const autoplayFailed = (0, __1.usePlayerStore)((x) => x.autoplayFailed);
    const setAutoplayFailed = (0, __1.usePlayerStore)((x) => x.setAutoplayFailed);
    const setMuted = (0, __1.useSetMuted)();
    const setMuteWasForced = (0, __1.usePlayerStore)((x) => x.setMuteWasForced);
    const setUserInteraction = (0, __1.usePlayerStore)((x) => x.setUserInteraction);
    const videoRef = (0, __1.usePlayerStore)((x) => x.videoRef);
    const handlePlayButtonPress = () => {
        if (videoRef && typeof videoRef === "object" && videoRef.current) {
            videoRef.current
                .play()
                .then(() => {
                setAutoplayFailed(false);
                setMuted(false);
                setUserInteraction();
            })
                .catch((err) => {
                console.error("Manual play failed", err);
                if (err.name === "NotAllowedError") {
                    setMuted(true);
                    videoRef.current.muted = true;
                    videoRef
                        .current.play()
                        .then(() => {
                        setAutoplayFailed(false);
                        setMuteWasForced(true);
                        setUserInteraction();
                    })
                        .catch((err) => {
                        console.error("Manual muted play also failed", err);
                    });
                }
            });
        }
    };
    if (!autoplayFailed)
        return null;
    return ((0, jsx_runtime_1.jsx)(__1.View, { style: [
            __1.layout.position.absolute,
            __1.layout.flex.center,
            ui_1.h.percent[100],
            ui_1.w.percent[100],
        ], pointerEvents: "box-none", children: (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: handlePlayButtonPress, style: [
                {
                    flexDirection: "column",
                    alignItems: "center",
                    justifyContent: "center",
                    gap: 8,
                },
            ], children: (0, jsx_runtime_1.jsx)(__1.View, { style: [
                    ui_1.p[4],
                    {
                        backgroundColor: "rgba(200,200,255, 0.1)",
                        borderRadius: 999,
                        borderWidth: 2,
                        borderColor: "rgba(200,200,255, 0.45)",
                        boxShadow: "0 0px 4px rgba(0, 0, 0, 1)",
                        shadowColor: "rgba(0, 0, 0, 1)",
                    },
                ], children: (0, jsx_runtime_1.jsx)(lucide_react_native_1.Play, { size: "48", color: "rgba(120,120,120,0.3)", fill: "rgba(200,200,255,1)" }) }) }) }));
}
//# sourceMappingURL=autoplay-button.js.map