"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_redux_1 = require("react-redux");
const components_1 = require("../themes/components");
const react_native_1 = require("react-native");
const roomSlice_1 = require("../store/roomSlice");
const PeerView_1 = __importDefault(require("./video/PeerView"));
const UserTrackProvider_1 = require("../services/UserTrackProvider");
const ConfigProvider_1 = require("../utils/ConfigProvider");
const participantSlice_1 = require("../store/participantSlice");
const OrientationContext_1 = require("../services/OrientationContext");
const borderRadius_1 = __importDefault(require("../themes/foundations/borderRadius"));
function SelfPreview() {
    const { sessionConfig } = react_1.useContext(ConfigProvider_1.ConfigServiceContext);
    const windowDimensions = react_native_1.useWindowDimensions();
    const { width } = sessionConfig.theme.dimensions || windowDimensions;
    const { orientation } = react_1.default.useContext(OrientationContext_1.OrientationContext);
    const isLandscape = orientation === 'LANDSCAPE';
    let selfVideoWidth = Math.floor((width * 3) / 9);
    if (width < 1024 && width > 500) {
        selfVideoWidth = Math.floor((width * 4) / 9);
    }
    else if (width < 500) {
        selfVideoWidth = Math.floor((width * 7.2) / 9);
    }
    const selfVideoHeight = Math.floor((selfVideoWidth * (isLandscape ? 3 : 5)) / 4.4);
    const id = react_redux_1.useSelector((state) => state.participant.id);
    const videoOff = react_redux_1.useSelector((state) => state.participant.videoOff);
    const audioMuted = react_redux_1.useSelector((state) => state.participant.audioMuted);
    const displayName = react_redux_1.useSelector((state) => state.participant.displayName);
    const picture = react_redux_1.useSelector((state) => state.participant.displayImageURL);
    const device = react_redux_1.useSelector((state) => state.participant.device);
    const permissions = react_redux_1.useSelector((state) => state.participant.participantPermissions);
    const videoProduction = react_redux_1.useSelector((state) => state.participant.videoProduction);
    const audioProduction = react_redux_1.useSelector((state) => state.participant.audioProduction);
    const { mediaTracks: { webcamTrack, audioTrack }, inputDevices: { audioInputDevices, videoInputDevices, onAudioInputChange, onVideoInputChange, toggleAudioState, toggleVideoState, }, } = react_1.useContext(UserTrackProvider_1.UserTrackContext);
    const permissionDeniedMessage = (react_1.default.createElement(components_1.Box, { status: "error", bg: "danger.500", p: 12, borderRadius: borderRadius_1.default.small, mt: 10, width: selfVideoWidth },
        react_1.default.createElement(components_1.HStack, { width: selfVideoWidth },
            react_1.default.createElement(components_1.VStack, null,
                react_1.default.createElement(components_1.Text, { mb: 2, fontSize: "lg", fontWeight: "bold" }, "Permission Denied"),
                react_1.default.createElement(components_1.Text, { fontSize: "sm" }, "We could not get permission to access your device.")))));
    const selfPeer = {
        id,
        device,
        displayName,
        audioMuted,
        picture,
        videoVisible: !videoOff,
        videoTrack: webcamTrack,
        audioTrack,
        isMe: true,
    };
    return (
    // eslint-disable-next-line react/jsx-props-no-spreading
    react_1.default.createElement(components_1.Flex, { direction: "column", justify: "center" },
        react_1.default.createElement(PeerView_1.default, { height: selfVideoHeight, width: selfVideoWidth, peer: selfPeer },
            react_1.default.createElement(components_1.Flex, { position: "absolute", bottom: 1, zIndex: 2000 },
                react_1.default.createElement(components_1.Flex, { direction: "row", justify: "flex-end", width: selfVideoWidth, mb: 10 },
                    react_1.default.createElement(components_1.Button, { disabled: audioProduction ===
                            roomSlice_1.MediaStates.NOT_APPLICABLE ||
                            permissions.microphone === participantSlice_1.permissionEnum.DENIED, onClick: toggleAudioState },
                        react_1.default.createElement(components_1.Box, { height: 36, width: 36, bg: "secondary.800", borderRadius: borderRadius_1.default.small, align: "center", mr: 5, justify: "center" }, !audioMuted && audioTrack ? (react_1.default.createElement(components_1.Icon, { name: "mic", boxSize: "20", fill: "textPrimary.200" })) : (react_1.default.createElement(components_1.Icon, { name: "mic-off", boxSize: "20", fill: "danger.500" })))),
                    react_1.default.createElement(components_1.Button, { disabled: videoProduction ===
                            roomSlice_1.MediaStates.NOT_APPLICABLE ||
                            permissions.camera === participantSlice_1.permissionEnum.DENIED, onClick: toggleVideoState },
                        react_1.default.createElement(components_1.Box, { height: 36, width: 36, bg: "secondary.800", borderRadius: borderRadius_1.default.small, align: "center", mr: 20, justify: "center" }, !videoOff ? (react_1.default.createElement(components_1.Icon, { name: "videocam", boxSize: "20", fill: "textPrimary.200" })) : (react_1.default.createElement(components_1.Icon, { name: "videocam-off", boxSize: "20", fill: "danger.500" }))))))),
        (permissions.camera === participantSlice_1.permissionEnum.DENIED ||
            permissions.microphone === participantSlice_1.permissionEnum.DENIED) &&
            permissionDeniedMessage));
}
exports.default = SelfPreview;
//# sourceMappingURL=SelfPreview.js.map