"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.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 });
/* eslint-disable no-underscore-dangle */
const react_1 = __importStar(require("react"));
const react_redux_1 = require("react-redux");
const react_native_1 = require("react-native");
const OrientationContext_1 = require("../services/OrientationContext");
const borderRadius_1 = __importDefault(require("../themes/foundations/borderRadius"));
const Clock_1 = __importDefault(require("./Clock"));
/* import NotificationBar from '../components/NotificationBar';
 */ const ConfigProvider_1 = require("../utils/ConfigProvider");
const roomSlice_1 = require("../store/roomSlice");
const components_1 = require("../themes/components");
const CameraSwitcher_1 = __importDefault(require("./video/CameraSwitcher"));
const src_1 = require("../utils/dyte-utils/src");
const participantSlice_1 = require("../store/participantSlice");
const PeersService_1 = require("../services/PeersService");
const notificationCircle_1 = __importDefault(require("./notificationCircle"));
const DrawerService_1 = require("../services/DrawerService");
const Divider = (props) => react_1.default.createElement(components_1.Text, { mr: 8, ml: 8 }, "|");
const _StageHeader = ({ title, copyLink, linkCopied, width, height, noOfParticipants, }) => {
    const waitingState = react_redux_1.useSelector((state) => state.room.waitingState);
    const { meeting, sessionConfig } = react_1.useContext(ConfigProvider_1.ConfigServiceContext);
    const plugins = react_redux_1.useSelector((state) => state.plugin.main);
    const { orientation } = react_1.default.useContext(OrientationContext_1.OrientationContext);
    const mobileLandscape = orientation === 'LANDSCAPE';
    const recordingPeer = react_redux_1.useSelector((state) => state.peers.recordingPeer);
    const [blink, setBlink] = react_1.useState(false);
    const blinkRef = react_1.useRef(null);
    const recordingRef = react_1.useRef(false);
    const roomViewType = react_redux_1.useSelector((state) => state.room.roomViewType);
    const presentingState = react_redux_1.useSelector((state) => state.participant.presentingState);
    const videoOff = react_redux_1.useSelector((state) => state.participant.videoOff);
    const peersService = react_1.useContext(PeersService_1.PeersServiceContext);
    const { processedPeers } = peersService;
    const { selfPeer, joinedProcessedPeers } = peersService;
    const { setDrawerExpander, setopenedTab, } = react_1.default.useContext(DrawerService_1.DrawerContext);
    react_1.useEffect(() => {
        if (recordingPeer && !recordingRef.current) {
            meeting === null || meeting === void 0 ? void 0 : meeting.emit(meeting.Events.recordingStarted);
            recordingRef.current = true;
            blinkRef.current = setInterval(() => {
                setBlink((e) => !e);
            }, 1000);
        }
        else if (!recordingPeer && recordingRef.current) {
            recordingRef.current = false;
            meeting === null || meeting === void 0 ? void 0 : meeting.emit(meeting.Events.recordingStopped);
            clearInterval(blinkRef.current);
        }
    }, [recordingPeer]);
    react_1.useEffect(() => () => {
        if (blinkRef.current) {
            clearInterval(blinkRef.current);
        }
    }, []);
    if (mobileLandscape || plugins.length > 0)
        return null;
    const openParticipantTab = () => {
        setDrawerExpander(true);
        setopenedTab('participants');
    };
    return (react_1.default.createElement(components_1.Flex, { height: 56, width: width, bg: "secondary.1000", justify: "center", align: "center", pt: react_native_1.Platform.OS === 'android' ? 10 : 26 },
        react_1.default.createElement(components_1.Flex, { borderRadius: borderRadius_1.default.medium, width: width - 8, justify: "space-between", direction: "row", px: 12 },
            react_1.default.createElement(components_1.VStack, null,
                react_1.default.createElement(components_1.Stack, { align: "center", width: width / 2 }, sessionConfig.theme.header.elements.title ? (react_1.default.createElement(components_1.Text, { fontWeight: "bold" }, title))
                    : null),
                react_1.default.createElement(components_1.Stack, { isInline: true, spacing: 2, pt: 2, align: "center" },
                    sessionConfig.theme.header.elements.timer && waitingState !== roomSlice_1.WaitingState.WAITING && (react_1.default.createElement(Clock_1.default, null)),
                    recordingPeer && blink && (react_1.default.createElement(components_1.Box, { ml: 12, bg: "danger.500", pl: 4, pr: 6, borderRadius: 4, direction: "row", alignItems: "center" },
                        react_1.default.createElement(components_1.Icon, { boxSize: "15", name: "fiber-manual-record", fill: "white" }),
                        react_1.default.createElement(components_1.Text, { color: "white" }, "REC"))))),
            react_1.default.createElement(components_1.HStack, { align: "flex-end", mb: 2 },
                sessionConfig.theme.control_bar.elements.participants
                    && (react_1.default.createElement(components_1.Box, { mr: 28 },
                        react_1.default.createElement(components_1.Box, { position: "absolute", top: -12, zIndex: 25, right: joinedProcessedPeers.length + 1 > 99 ? -18 : -10 },
                            react_1.default.createElement(notificationCircle_1.default, { number: joinedProcessedPeers.length + 1, color: "primary.500" })),
                        react_1.default.createElement(components_1.Button, { onClick: openParticipantTab },
                            react_1.default.createElement(components_1.Icon, { boxSize: "24", name: "people", fill: "textPrimary.100" })))),
                !videoOff && (roomViewType !== src_1.DyteViewTypes.webinar
                    || presentingState === participantSlice_1.PresentingState.PRESENTING) && react_1.default.createElement(CameraSwitcher_1.default, null)))));
};
exports.default = react_1.default.memo(_StageHeader);
//# sourceMappingURL=StageHeader.js.map