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 './p-a83ccdbd.js';
import { s as smoothScrollToBottom } from './p-0752f2ba.js';
import { S as SyncWithStore } from './p-070aa695.js';
import { d as defineCustomElement$5 } from './p-85587a5c.js';
import { d as defineCustomElement$4 } from './p-3e0452c4.js';
import { d as defineCustomElement$3 } from './p-3ff755e5.js';
import { d as defineCustomElement$2 } from './p-73901fd8.js';
import { d as defineCustomElement$1 } from './p-bece0226.js';

const rtkPollsCss = ":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{margin-top:var(--rtk-space-2, 8px);display:flex;height:100%;width:100%;flex-direction:column;font-size:14px}*{box-sizing:border-box}.ctr{box-sizing:border-box;padding:var(--rtk-space-3, 12px);padding-top:var(--rtk-space-0, 0px);display:flex;flex:1 1 0%;flex-direction:column}.polls-view{overflow-y:auto;flex:1 1 0%;flex-basis:0}.empty-polls{display:flex;height:100%;width:100%;align-items:center;justify-content:center}";
const RtkPollsStyle0 = rtkPollsCss;

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 RtkPolls = /*@__PURE__*/ proxyCustomElement(class RtkPolls extends H {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        /** Config */
        this.config = createDefaultConfig();
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** Language */
        this.t = useLanguage();
        /** Create State */
        this.create = false;
        /** Polls */
        this.polls = [];
        this.onPollsUpdate = (data) => {
            this.polls = [...data.polls];
        };
        this.onUpdatePermissions = () => {
            this.permissions = this.meeting.self.permissions;
        };
    }
    connectedCallback() {
        this.meetingChanged(this.meeting);
    }
    disconnectedCallback() {
        var _a;
        if (!this.meeting)
            return;
        (_a = this.meeting.polls) === null || _a === void 0 ? void 0 : _a.removeListener('pollsUpdate', this.onPollsUpdate);
        this.meeting.self.permissions.removeListener('pollsUpdate', this.onUpdatePermissions);
    }
    meetingChanged(meeting) {
        if (!meeting)
            return;
        if (!meeting.polls)
            return;
        this.permissions = this.meeting.self.permissions;
        this.polls = [...meeting.polls.items];
        meeting.polls.addListener('pollsUpdate', this.onPollsUpdate);
        this.meeting.self.permissions.addListener('pollsUpdate', this.onUpdatePermissions);
        this.onCreate = async (data) => {
            this.create = false;
            await meeting.polls.create(data.question, data.options, data.anonymous, data.hideVotes);
        };
        this.onVote = async (id, index) => {
            await meeting.polls.vote(id, index);
        };
    }
    toggleCreateState() {
        this.create = !this.create;
    }
    componentDidRender() {
        smoothScrollToBottom(this.pollEl);
    }
    render() {
        var _a, _b;
        return (h(Host, { key: '0e868573a28a637e9df91a0c2e10bc1a73da2848' }, h("div", { key: '63cf282074f7c9eb248c4a645f6798001379907b', class: "ctr", part: "container" }, h("div", { key: '3237128bcbff4b513970e9832f26326a8be1cf56', class: "polls-view scrollbar", ref: (el) => (this.pollEl = el), part: "polls" }, this.polls.length == 0 && this.create !== true && (h("div", { key: '12b3c463d0f63f0a62ab33f17c0f18bb44fa0408', class: "empty-polls" }, this.t('polls.empty'))), this.polls.map((item) => {
            var _a;
            return (h("rtk-poll", { key: item.id, poll: item, onRtkVotePoll: (e) => {
                    this.onVote(e.detail.id, e.detail.index);
                }, self: (_a = this.meeting) === null || _a === void 0 ? void 0 : _a.self.userId, iconPack: this.iconPack, t: this.t, permissions: this.permissions }));
        }), this.create && (h("rtk-poll-form", { key: 'fb8b90bb86654aa8742ced745f88e5fbdc9282bf', part: "poll-form", onRtkCreatePoll: (e) => {
                this.onCreate(e.detail);
            }, iconPack: this.iconPack, t: this.t }))), ((_b = (_a = this.permissions) === null || _a === void 0 ? void 0 : _a.polls) === null || _b === void 0 ? void 0 : _b.canCreate) && (h("rtk-button", { key: '7fffe35088db7620b4301145c6efa2f6da05153c', kind: "wide", onClick: () => this.toggleCreateState(), variant: this.create ? 'secondary' : 'primary', part: "button" }, this.create ? this.t('polls.cancel') : this.t('polls.create'))))));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
    static get style() { return RtkPollsStyle0; }
}, [1, "rtk-polls", {
        "meeting": [16],
        "config": [16],
        "size": [513],
        "iconPack": [16],
        "t": [16],
        "create": [32],
        "polls": [32],
        "permissions": [32]
    }, undefined, {
        "meeting": ["meetingChanged"]
    }]);
__decorate([
    SyncWithStore()
], RtkPolls.prototype, "meeting", void 0);
__decorate([
    SyncWithStore()
], RtkPolls.prototype, "config", void 0);
__decorate([
    SyncWithStore()
], RtkPolls.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkPolls.prototype, "t", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-polls", "rtk-button", "rtk-icon", "rtk-poll", "rtk-poll-form", "rtk-tooltip"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-polls":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkPolls);
            }
            break;
        case "rtk-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "rtk-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "rtk-poll":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "rtk-poll-form":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "rtk-tooltip":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { RtkPolls as R, defineCustomElement as d };
