import { p as proxyCustomElement, H, h, c as Host } from './p-ae373651.js';
import { c as createDefaultConfig, e as defaultIconPack, i as useLanguage } from './p-5b3a7f00.js';
import { R as Render } from './p-88bd1053.js';
import { u as useGrid } from './p-b13ddb7d.js';
import { i as index } from './p-f47d4fe8.js';
import { S as SyncWithStore } from './p-070aa695.js';

const rtkSimpleGridCss = ":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)}:host{position:relative;display:block;height:100%;width:100%}";
const RtkSimpleGridStyle0 = rtkSimpleGridCss;

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 RtkSimpleGrid$1 = /*@__PURE__*/ proxyCustomElement(class RtkSimpleGrid extends H {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        /** Participants */
        this.participants = [];
        /**
         * Aspect Ratio of participant tile
         *
         * Format: `width:height`
         */
        this.aspectRatio = '16:9';
        /** Gap between participant tiles */
        this.gap = 8;
        /** UI Config */
        this.config = createDefaultConfig();
        /** Icon Pack */
        this.iconPack = defaultIconPack;
        /** Language */
        this.t = useLanguage();
        this.dimensions = { width: 0, height: 0 };
        this.setHostDimensions = () => {
            const { clientWidth: width, clientHeight: height } = this.host;
            this.dimensions = { width, height };
        };
    }
    connectedCallback() {
        this.resizeObserver = new index(this.setHostDimensions);
        this.resizeObserver.observe(this.host);
        this.meetingChanged(this.meeting);
    }
    meetingChanged(meeting) {
        const meta = meeting === null || meeting === void 0 ? void 0 : meeting.meta;
        if (meta)
            this.mediaConnection = Object.assign({}, meta.mediaState);
    }
    disconnectedCallback() {
        var _a;
        (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
    }
    render() {
        if (!this.meeting)
            return null;
        const defaults = {
            meeting: this.meeting,
            config: this.config,
            states: this.states,
            size: this.size,
            iconPack: this.iconPack,
            t: this.t,
        };
        const { width, height, getPosition } = useGrid({
            dimensions: this.dimensions,
            count: this.participants.length,
            aspectRatio: this.aspectRatio,
            gap: this.gap,
        });
        return (h(Host, null, h("slot", null, this.participants.map((participant, index) => {
            const { top, left } = getPosition(index);
            return (h(Render, { element: "rtk-participant-tile", defaults: defaults, props: {
                    participant,
                    style: {
                        position: 'absolute',
                        top: `${top}px`,
                        left: `${left}px`,
                        width: `${width}px`,
                        height: `${height}px`,
                    },
                    key: participant.id,
                    'data-participant': participant.id,
                    mediaConnection: this.mediaConnection,
                }, childProps: { participant }, deepProps: true }));
        }))));
    }
    get host() { return this; }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
    static get style() { return RtkSimpleGridStyle0; }
}, [1, "rtk-simple-grid", {
        "participants": [16],
        "aspectRatio": [1, "aspect-ratio"],
        "gap": [2],
        "size": [513],
        "meeting": [16],
        "states": [16],
        "config": [16],
        "iconPack": [16],
        "t": [16],
        "dimensions": [32],
        "mediaConnection": [32]
    }, undefined, {
        "meeting": ["meetingChanged"]
    }]);
__decorate([
    SyncWithStore()
], RtkSimpleGrid$1.prototype, "meeting", void 0);
__decorate([
    SyncWithStore()
], RtkSimpleGrid$1.prototype, "states", void 0);
__decorate([
    SyncWithStore()
], RtkSimpleGrid$1.prototype, "config", void 0);
__decorate([
    SyncWithStore()
], RtkSimpleGrid$1.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkSimpleGrid$1.prototype, "t", void 0);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-simple-grid"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-simple-grid":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkSimpleGrid$1);
            }
            break;
    } });
}
defineCustomElement$1();

const RtkSimpleGrid = RtkSimpleGrid$1;
const defineCustomElement = defineCustomElement$1;

export { RtkSimpleGrid, defineCustomElement };
