import { p as proxyCustomElement, H, e as createEvent, h, c as Host } from './p-ae373651.js';
import { e as defaultIconPack, i as useLanguage } from './p-5b3a7f00.js';
import { S as SyncWithStore } from './p-070aa695.js';
import { s as shorten, f as formatName, g as getInitials } from './p-efabd2ce.js';
import { d as defineCustomElement$1 } from './p-bece0226.js';

const rtkPollCss = ":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)))}.ctr{margin-bottom:var(--rtk-space-3, 12px);display:flex;width:100%;flex-direction:column;color:rgb(var(--rtk-colors-text-1000, 255 255 255))}.poll-title{margin-top:var(--rtk-space-3, 12px);margin-bottom:var(--rtk-space-3, 12px);margin-right:var(--rtk-space-4, 16px);font-size:12px}.poll{border-radius:var(--rtk-border-radius-md, 8px);--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-800, 30 30 30) / var(--tw-bg-opacity));display:flex;flex-direction:column;padding:var(--rtk-space-4, 16px)}.poll-question{padding-left:var(--rtk-space-2, 8px);padding-right:var(--rtk-space-2, 8px);font-size:14px;overflow-wrap:break-word}.poll-answers{display:flex;flex-direction:row;justify-content:space-between;font-size:12px;margin-top:var(--rtk-space-4, 16px);margin-bottom:var(--rtk-space-1, 4px);padding-left:var(--rtk-space-1, 4px);padding-right:var(--rtk-space-3, 12px)}.poll-option{display:flex;flex-direction:column;margin-top:var(--rtk-space-2, 8px);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));padding:var(--rtk-space-2, 8px);word-break:break-word}.poll-option.open-vote:hover{cursor:pointer}.poll-option label{display:flex;flex-direction:row;cursor:inherit}.poll-option-header{display:flex;flex-direction:row;justify-content:space-between;padding:var(--rtk-space-1, 4px)}.poll-option-header[data-disabled='true']:hover{cursor:default}.poll-option-header input{margin-top:var(--rtk-space-0, 0px);margin-bottom:var(--rtk-space-0, 0px);margin-left:var(--rtk-space-0\\.5, 2px);margin-right:var(--rtk-space-2, 8px);cursor:inherit}.poll-option-header .counter{color:rgb(var(--rtk-colors-text-1000, 255 255 255));font-size:12px}.votes{margin-top:var(--rtk-space-1, 4px);display:flex;flex-direction:row;flex-wrap:wrap}.vote{margin-right:var(--rtk-space-1, 4px);height:var(--rtk-space-8, 32px);width:var(--rtk-space-8, 32px);display:flex;align-items:center;justify-content:center;border-radius:var(--rtk-border-radius-md, 8px);--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-video-bg, 24 24 24) / var(--tw-bg-opacity));color:rgb(var(--rtk-colors-text-1000, 255 255 255));border-radius:var(--rtk-border-radius-none, 0);clip-path:circle()}.active{--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-brand-500, 33 96 253) / var(--tw-bg-opacity));color:rgb(var(--rtk-colors-text-on-brand-900, var(--rtk-colors-text-900, 255 255 255 / 0.88)))}.active .counter{color:rgb(var(--rtk-colors-text-on-brand-900, var(--rtk-colors-text-900, 255 255 255 / 0.88)))}";
const RtkPollStyle0 = rtkPollCss;

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();
        this.onVote = createEvent(this, "rtkVotePoll", 7);
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** Language */
        this.t = useLanguage();
        this.MAX_VOTES_RENDER = 10;
    }
    vote(e, index) {
        if (this.poll.voted.includes(this.self)) {
            e.preventDefault();
        }
        else {
            this.onVote.emit({ id: this.poll.id, index });
        }
    }
    render() {
        const hasVoted = this.poll.voted.includes(this.self);
        return (h(Host, { key: '69e61c49e0f7f2015538447a8862bdb7fd3b4840' }, h("div", { key: '00dec58cb19f30a4fc01926dd383edb270cd61c3', class: "ctr" }, h("p", { key: '04d88ddf1f20e1a7e5b017f058b585723498f474', class: "poll-title" }, this.t('polls.by'), " ", shorten(formatName(this.poll.createdBy), 20)), h("div", { key: '5432167291df04bc4a4bfa23117df79c8512027d', class: "poll" }, h("p", { key: 'bee55a8193f96f582cf1c3006393740ab652dea7', class: "poll-question" }, this.poll.question), h("div", { key: 'aefe01131512e992e756196b5b451d4423bb9635', class: "poll-answers" }, h("span", { key: '973f566c9d84a6519f7ab307fd072215fe76f72d' }, this.t('polls.answers')), h("span", { key: '2a87b4bd72b99916cf20070c792742d04c1a44ca' }, this.poll.voted.length)), this.poll.options.map((item, index) => (h("div", { class: {
                active: item.votes.some((x) => x.id === this.self),
                'open-vote': this.permissions.polls.canVote && !hasVoted,
                'poll-option': true,
            } }, h("div", { class: "poll-option-header", "data-disabled": !this.permissions.polls.canVote }, h("label", null, !hasVoted && (h("input", { disabled: !this.permissions.polls.canVote, readOnly: hasVoted, type: "radio", checked: item.votes.some((x) => x.id === this.self), onClick: (e) => this.vote(e, index) })), h("p", null, item.text)), h("span", { class: "counter" }, item.count)), h("div", { class: "votes" }, item.votes.slice(0, this.MAX_VOTES_RENDER).map((vote) => {
            if (this.poll.anonymous && this.self !== this.poll.createdByUserId)
                return;
            return (h("rtk-tooltip", { label: vote.name }, h("div", { class: "vote" }, getInitials(vote.name))));
        }), item.votes.length > this.MAX_VOTES_RENDER && (h("rtk-tooltip", { label: `+${item.votes.length - this.MAX_VOTES_RENDER} more ` }, h("div", { class: "vote" }, "+", item.votes.length - this.MAX_VOTES_RENDER)))))))))));
    }
    static get style() { return RtkPollStyle0; }
}, [1, "rtk-poll", {
        "poll": [16],
        "self": [1],
        "permissions": [16],
        "iconPack": [16],
        "t": [16]
    }]);
__decorate([
    SyncWithStore()
], RtkPolls.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkPolls.prototype, "t", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-poll", "rtk-tooltip"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-poll":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkPolls);
            }
            break;
        case "rtk-tooltip":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { RtkPolls as R, defineCustomElement as d };
