"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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const components_1 = require("../../themes/components");
// import stats from '@src/utils/callStats';
const react_1 = __importStar(require("react"));
const react_redux_1 = require("react-redux");
const styled_components_1 = require("styled-components");
const borderRadius_1 = __importDefault(require("../../themes/foundations/borderRadius"));
const NetworkCheck = () => {
    // console.log(stats)
    const [preCallResult, setPreCallResult] = react_1.useState(null);
    const peerId = react_redux_1.useSelector((state) => state.participant.peerId);
    const userDisplayName = react_redux_1.useSelector((state) => state.participant.displayName);
    const { colors } = react_1.useContext(styled_components_1.ThemeContext);
    react_1.useEffect(() => {
        const precallTest = () => __awaiter(void 0, void 0, void 0, function* () {
            // stats.initialize(peerId, userDisplayName);
            // stats.onPreCallTestResults((status, result) => {
            // 	if (status !== 'success') return;
            // 	const callResult = {
            // 		speedIcon: <Icon name="exclamation" color="warning.500" />,
            // 		qualityIcon: <Icon name="exclamation" color="warning.500" />,
            // 	};
            // 	if (result.fractionalLoss !== undefined
            // 		&& result.jitter !== undefined
            // 		&& result.rtt !== undefined) {
            // 		if (result.fractionalLoss < 0.01
            // 			&& result.jitter < 150
            // 			&& result.rtt < 150) {
            // 			callResult.qualityIcon = <Icon name="signal" color="success.500" />;
            // 		} else if (result.fractionalLoss < 0.04
            // 			&& result.jitter < 300
            // 			&& result.rtt < 300) {
            // 			callResult.qualityIcon = <Icon name="signal-cellular-2" color="warning.500" />;
            // 		} else {
            // 			callResult.qualityIcon = <Icon name="signal-cellular-1" color="danger.500" />;
            // 		}
            // 	}
            // 	if (result.throughput !== undefined) {
            // 		if (result.throughput > 2000) {
            // 			callResult.speedIcon = <Icon name="signal" color="success.500" />;
            // 		} else if (result.throughput > 1000) {
            // 			callResult.speedIcon = <Icon name="signal-cellular-2" color="warning.500" />;
            // 		} else {
            // 			callResult.speedIcon = <Icon name="signal-cellular-1" color="danger.500" />;
            // 		}
            // 	}
            // 	setPreCallResult(callResult);
            // });
        });
        // precallTest();
        const timeout = setTimeout(() => {
            setPreCallResult((result) => (result || {
                speedIcon: react_1.default.createElement(components_1.Icon, { name: "exclamation", color: "warning.500" }),
                qualityIcon: react_1.default.createElement(components_1.Icon, { name: "exclamation", color: "warning.500" }),
            }));
        }, 4000);
        return () => {
            clearTimeout(timeout);
            // stats.onPreCallTestResults(() => { });
        };
    }, []);
    return (react_1.default.createElement(components_1.Box, { background: "secondary.800", px: 4, py: 10, borderRadius: borderRadius_1.default.small },
        react_1.default.createElement(components_1.HStack, { justifyContent: "space-around" },
            react_1.default.createElement(components_1.Text, { py: 4 }, "Network "),
            react_1.default.createElement(components_1.HStack, { background: "secondary.700", px: 4, py: 1, borderRadius: borderRadius_1.default.small, flexGrow: 0.5, justifyContent: "space-around" },
                react_1.default.createElement(components_1.HStack, { py: 4 },
                    react_1.default.createElement(components_1.Text, { mr: 10 }, "Speed:"),
                    preCallResult ? preCallResult.speedIcon : react_1.default.createElement(components_1.Spinner, { color: colors.textPrimary['100'], size: "small" })),
                react_1.default.createElement(components_1.HStack, { py: 4 },
                    react_1.default.createElement(components_1.Text, { mr: 10 }, "Quality:"),
                    preCallResult ? preCallResult.qualityIcon : react_1.default.createElement(components_1.Spinner, { color: colors.textPrimary['100'], size: "small" }))))));
};
exports.default = NetworkCheck;
//# sourceMappingURL=index.js.map