import { p as proxyCustomElement, H, h, c as Host } from './p-ae373651.js';
import { e as defaultIconPack, i as useLanguage } from './p-5b3a7f00.js';
import './p-a83ccdbd.js';
import { S as SyncWithStore } from './p-070aa695.js';
import { d as getBatteryLevelVerdict, e as getBatteryChargingVerdict, f as getOverallBatteryVerdict } from './p-0e02697c.js';

const rtkDebuggerSystemCss = ":host{line-height:initial;font-family:var(--rtk-font-family, sans-serif);font-feature-settings:normal;font-variation-settings:normal}p{margin:var(--rtk-space-0, 0px);padding:var(--rtk-space-0, 0px)}.scrollbar{scrollbar-width:thin;scrollbar-color:var(--rtk-scrollbar-color, rgb(var(--rtk-colors-background-600, 60 60 60)))\n    var(--rtk-scrollbar-background, transparent)}.scrollbar::-webkit-scrollbar{height:var(--rtk-space-1\\.5, 6px);width:var(--rtk-space-1\\.5, 6px);border-radius:9999px;background-color:var(--rtk-scrollbar-background, transparent)}.scrollbar::-webkit-scrollbar-thumb{border-radius:9999px;background-color:var(--rtk-scrollbar-color, rgb(var(--rtk-colors-background-600, 60 60 60)))}:host{position:relative;display:flex;flex-direction:column;overflow:hidden;height:100%;width:100%;color:rgb(var(--rtk-colors-text-1000, 255 255 255));--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-600, 60 60 60) / var(--tw-bg-opacity))}.tab-body::-webkit-scrollbar{width:var(--rtk-space-1\\.5, 6px);border-radius:var(--rtk-border-radius-md, 8px);--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-1000, 8 8 8) / var(--tw-bg-opacity))}.tab-body::-webkit-scrollbar-thumb{border-radius:var(--rtk-border-radius-md, 8px);--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-700, 44 44 44) / var(--tw-bg-opacity))}h3{margin:var(--rtk-space-0, 0px);padding:var(--rtk-space-0, 0px);font-size:16px;font-weight:600}#header{margin-top:var(--rtk-space-2, 8px);margin-bottom:var(--rtk-space-5, 20px);display:flex;align-items:center;justify-content:space-evenly}.tab-body{margin:var(--rtk-space-4, 16px);display:flex;height:100%;flex-direction:column;justify-content:space-between;overflow-y:auto}.status-container{border:var(--rtk-border-width-sm, 1px) solid rgb(var(--rtk-colors-background-600, 60 60 60));border-radius:8px;padding:16px}.status-section{margin-bottom:12px}.section-header{display:flex;justify-content:space-between;align-items:center;font-weight:bold;padding:8px 0}.section-body.missing-stats{display:flex;text-align:center;justify-content:center}.section-header .status{color:rgba(var(--rtk-colors-success));font-weight:bold}.section-header .arrow{font-size:14px}.battery-table{border:var(--rtk-border-width-sm, 1px) solid rgb(var(--rtk-colors-background-600, 60 60 60));border-radius:8px;margin-top:8px;overflow:hidden}.battery-row{display:flex;justify-content:space-between;padding:12px;border-bottom:var(--rtk-border-width-sm, 1px) solid rgb(var(--rtk-colors-background-600, 60 60 60))}.battery-row:last-child{border-bottom:none}.battery-cell{display:flex;flex-direction:column}.battery-cell.label strong{font-size:14px}.battery-cell.label .description{font-size:12px;color:rgb(var(--rtk-colors-text-700, 255 255 255 / 0.64));margin-top:4px}.battery-cell.value{text-align:right}.status.good{color:rgba(var(--rtk-colors-success))}.status.average{color:rgba(var(--rtk-colors-warning))}.status.poor{color:rgba(var(--rtk-colors-danger))}.value{font-size:14px;color:rgb(var(--rtk-colors-text-700, 255 255 255 / 0.64));margin-top:4px}rtk-settings-video{display:flex;flex-direction:column}";
const RtkDebuggerSystemStyle0 = rtkDebuggerSystemCss;

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
        r = Reflect.decorate(decorators, target, key, desc);
    else
        for (var i = decorators.length - 1; i >= 0; i--)
            if (d = decorators[i])
                r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const RtkDebuggerSystem = /*@__PURE__*/ proxyCustomElement(class RtkDebuggerSystem extends H {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** Language */
        this.t = useLanguage();
        /** Is Network section expanded */
        this.isBatterySectionOpen = true;
        /** Summarised health of network stats */
        this.batterySectionHealth = null;
        /** Battery manager */
        this.battery = null;
        /** Stats as formatted array to display */
        this.batteryFormattedStats = [];
        this.batteryUpdateListener = () => {
            const batteryLevelPercentage = Math.round(this.battery.level * 100);
            const newBatteryStats = [];
            newBatteryStats.push({
                name: this.t('debugger.system.battery.level.label'),
                value: `${batteryLevelPercentage}%`,
                description: this.t('debugger.system.battery.level.description'),
                verdict: getBatteryLevelVerdict({
                    batteryLevelPercentage,
                }),
            });
            newBatteryStats.push({
                name: this.t('debugger.system.battery.charging.label'),
                value: `${this.battery.charging
                    ? this.t('debugger.system.battery.charging.is_charging')
                    : this.t('debugger.system.battery.charging.is_not_charging')}`,
                description: this.t('debugger.system.battery.charging.description'),
                verdict: getBatteryChargingVerdict({
                    batteryLevelPercentage,
                    chargingTimeInSeconds: this.battery.chargingTime,
                    dischargingTimeInSeconds: this.battery.dischargingTime,
                    charging: this.battery.charging,
                }),
            });
            this.batterySectionHealth = getOverallBatteryVerdict({
                stats: newBatteryStats,
            });
            this.batteryFormattedStats = newBatteryStats;
        };
    }
    toggleSection(section) {
        if (section === 'battery')
            this.isBatterySectionOpen = !this.isBatterySectionOpen;
    }
    connectedCallback() {
        this.meetingChanged(this.meeting);
    }
    disconnectedCallback() {
        if (!this.meeting) {
            return;
        }
        if (this.battery) {
            this.battery.removeEventListener('levelchange', this.batteryUpdateListener);
            this.battery.removeEventListener('chargingchange', this.batteryUpdateListener);
        }
    }
    async meetingChanged(meeting) {
        if (!meeting)
            return;
        if (typeof navigator.getBattery !== 'undefined') {
            this.battery = await navigator.getBattery();
            this.battery.addEventListener('levelchange', this.batteryUpdateListener);
            this.battery.addEventListener('chargingchange', this.batteryUpdateListener);
            this.batteryUpdateListener();
        }
    }
    render() {
        var _a, _b;
        if (!this.meeting) {
            return;
        }
        return (h(Host, null, h("div", { id: "header" }), h("div", { class: "tab-body" }, h("div", { class: "status-container" }, h("div", { class: "status-section" }, h("div", { class: "section-header", onClick: () => this.toggleSection('battery') }, h("span", null, this.t('debugger.system.sections.battery')), this.batterySectionHealth && (h("span", { class: `status ${(_a = this.batterySectionHealth) === null || _a === void 0 ? void 0 : _a.toLowerCase()}` }, this.t(`debugger.quality.${(_b = this.batterySectionHealth) === null || _b === void 0 ? void 0 : _b.toLowerCase()}`)))), this.isBatterySectionOpen && !!this.batteryFormattedStats.length && (h("div", { class: "section-body battery-table" }, this.batteryFormattedStats.map((formattedStatsObj) => {
            var _a, _b;
            return (h("div", { class: "battery-row" }, h("div", { class: "battery-cell label" }, h("strong", null, formattedStatsObj.name), h("span", { class: "description" }, formattedStatsObj.description)), h("div", { class: "battery-cell value" }, h("span", { class: `status ${(_a = formattedStatsObj.verdict) === null || _a === void 0 ? void 0 : _a.toLowerCase()}` }, this.t(`debugger.quality.${(_b = formattedStatsObj.verdict) === null || _b === void 0 ? void 0 : _b.toLowerCase()}`)), h("span", { class: "value" }, formattedStatsObj.value))));
        }))))))));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
    static get style() { return RtkDebuggerSystemStyle0; }
}, [1, "rtk-debugger-system", {
        "meeting": [16],
        "states": [16],
        "size": [513],
        "iconPack": [16],
        "t": [16],
        "isBatterySectionOpen": [32],
        "batterySectionHealth": [32],
        "battery": [32],
        "batteryFormattedStats": [32]
    }, undefined, {
        "meeting": ["meetingChanged"]
    }]);
__decorate([
    SyncWithStore()
], RtkDebuggerSystem.prototype, "meeting", void 0);
__decorate([
    SyncWithStore()
], RtkDebuggerSystem.prototype, "states", void 0);
__decorate([
    SyncWithStore()
], RtkDebuggerSystem.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkDebuggerSystem.prototype, "t", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-debugger-system"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-debugger-system":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkDebuggerSystem);
            }
            break;
    } });
}
defineCustomElement();

export { RtkDebuggerSystem as R, defineCustomElement as d };
