'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index$1 = require('./index-2e5758b6.js');
const uiStore = require('./ui-store-583d205a.js');
const index$2 = require('./index-6f8c1928.js');
const grid = require('./grid-edc342a7.js');
const ResizeObserver_es = require('./ResizeObserver.es-ba961f16.js');
const index = require('./index-3f8e5441.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 = class {
    constructor(hostRef) {
        index$1.registerInstance(this, hostRef);
        /** 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 = uiStore.createDefaultConfig();
        /** Icon Pack */
        this.iconPack = uiStore.defaultIconPack;
        /** Language */
        this.t = uiStore.useLanguage();
        this.dimensions = { width: 0, height: 0 };
        this.setHostDimensions = () => {
            const { clientWidth: width, clientHeight: height } = this.host;
            this.dimensions = { width, height };
        };
    }
    connectedCallback() {
        this.resizeObserver = new ResizeObserver_es.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 } = grid.useGrid({
            dimensions: this.dimensions,
            count: this.participants.length,
            aspectRatio: this.aspectRatio,
            gap: this.gap,
        });
        return (index$1.h(index$1.Host, null, index$1.h("slot", null, this.participants.map((participant, index) => {
            const { top, left } = getPosition(index);
            return (index$1.h(index$2.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 index$1.getElement(this); }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
};
__decorate([
    index.SyncWithStore()
], RtkSimpleGrid.prototype, "meeting", void 0);
__decorate([
    index.SyncWithStore()
], RtkSimpleGrid.prototype, "states", void 0);
__decorate([
    index.SyncWithStore()
], RtkSimpleGrid.prototype, "config", void 0);
__decorate([
    index.SyncWithStore()
], RtkSimpleGrid.prototype, "iconPack", void 0);
__decorate([
    index.SyncWithStore()
], RtkSimpleGrid.prototype, "t", void 0);
RtkSimpleGrid.style = RtkSimpleGridStyle0;

exports.rtk_simple_grid = RtkSimpleGrid;
