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 { d as defineCustomElement$2 } from './p-85587a5c.js';
import { d as defineCustomElement$1 } from './p-3e0452c4.js';

const rtkPollFormCss = ":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)))}.create-poll{margin-top:var(--rtk-space-3, 12px);margin-bottom:var(--rtk-space-3, 12px);display:flex;flex:1 1 0%;flex-direction:column;padding:var(--rtk-space-3, 12px);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))}.create-poll p{margin:var(--rtk-space-0, 0px);padding:var(--rtk-space-0, 0px);text-align:center}.create-poll textarea{display:flex;border-radius:var(--rtk-border-radius-sm, 4px);padding:var(--rtk-space-2, 8px);font-family:var(--rtk-font-family, sans-serif);border-width:var(--rtk-border-width-none, 0);border-style:none;font-weight:500;outline:2px solid transparent;outline-offset:2px;margin-top:var(--rtk-space-3, 12px);margin-bottom:var(--rtk-space-3, 12px);resize:vertical;--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-900, 26 26 26) / var(--tw-bg-opacity));color:rgb(var(--rtk-colors-text-700, 255 255 255 / 0.64))}.create-poll textarea:focus{outline-style:solid;outline-offset:2px;outline-color:rgb(var(--rtk-colors-background-600, 60 60 60))}.option{display:flex;flex-direction:row;align-items:center;margin-bottom:var(--rtk-space-3, 12px);width:100%}.option input{width:100%;border-radius:var(--rtk-border-radius-sm, 4px);padding:var(--rtk-space-2, 8px);border-width:var(--rtk-border-width-none, 0);border-style:none;outline:2px solid transparent;outline-offset:2px;--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-900, 26 26 26) / var(--tw-bg-opacity));color:rgb(var(--rtk-colors-text-700, 255 255 255 / 0.64))}.remove-option{margin-left:var(--rtk-space-2, 8px);width:var(--rtk-space-10, 40px);border-radius:var(--rtk-border-radius-sm, 4px)}.add-option{margin-bottom:var(--rtk-space-3, 12px)}label{margin-bottom:var(--rtk-space-3, 12px)}.error-text{margin-top:var(--rtk-space-3, 12px);text-align:center;font-size:12px;--tw-text-opacity:1;color:rgba(var(--rtk-colors-danger, 255 45 45) / var(--tw-text-opacity))}";
const RtkPollFormStyle0 = rtkPollFormCss;

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 RtkPoll = /*@__PURE__*/ proxyCustomElement(class RtkPoll extends H {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.onCreate = createEvent(this, "rtkCreatePoll", 7);
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** Language */
        this.t = useLanguage();
        /** Options */
        this.options = ['', ''];
        this.anonymous = false;
        this.hideVotes = true;
    }
    removeOption(index) {
        var _a;
        this.options = this.options.filter((_, ind) => ind !== index);
        if (((_a = this.error) === null || _a === void 0 ? void 0 : _a.code) === 1)
            this.error = undefined;
    }
    addOption() {
        this.options = [...this.options, ''];
    }
    updateOption(ev, index) {
        var _a;
        this.options[index] = ev.target.value;
        if (((_a = this.error) === null || _a === void 0 ? void 0 : _a.code) === 1)
            this.error = undefined;
    }
    handleSubmit() {
        const pollObject = {
            question: this.question.value,
            options: this.options,
            anonymous: this.anonymous,
            hideVotes: this.anonymous ? true : this.hideVotes,
        };
        if (!pollObject.question) {
            this.error = {
                code: 0,
                message: this.t('polls.errors.question_required'),
            };
            return;
        }
        if (this.options.filter((op) => op.trim() === '').length > 0) {
            this.error = {
                code: 1,
                message: this.t('polls.errors.empty_option'),
            };
            return;
        }
        this.onCreate.emit(pollObject);
    }
    render() {
        return (h(Host, { key: 'ff160dd70e52bfa8a0c5116acea73a16cb84b9b8' }, h("div", { key: '2f14946249e12cbc38db8cca86d370030286dc8e', class: "create-poll" }, h("p", { key: 'a6e3704c58e3526aa2e0f517f529c7ee48627f30' }, this.t('polls.question')), h("textarea", { key: '6b076d162f80cc4e08ecc9379e829f37d43d06bb', onInput: () => {
                if (this.error && this.error.code === 0)
                    this.error = undefined;
            }, ref: (e) => (this.question = e), placeholder: this.t('polls.question.placeholder') }), this.options.map((item, index) => (h("div", { class: "option" }, h("input", { placeholder: this.t('polls.option.placeholder'), value: item, onInput: (event) => this.updateOption(event, index) }), index > 1 && (h("rtk-button", { kind: "icon", class: "auto remove-option", variant: "secondary", onClick: () => this.removeOption(index) }, h("rtk-icon", { icon: this.iconPack.subtract })))))), h("rtk-button", { key: 'be4055b21c6c810d0721fe2daf3308011b2c6d8f', class: "add-option", variant: "secondary", onClick: () => this.addOption() }, this.t('polls.option')), h("label", { key: '0e22f9da27289adf831d5a9458237aa11758fd41' }, h("input", { key: '577da1d275259a4e9ebffedf153f52e799172c42', id: "anonymous", type: "checkbox", onChange: (e) => (this.anonymous = e.target.checked) }), this.t('polls.results.anon')), h("label", { key: 'c06bcbfb6d15125c614764002985d20713e672a4' }, h("input", { key: '9e9bb29126ed51c0bbd06481b44f690d737fbb64', id: "hideVotes", type: "checkbox", disabled: this.anonymous, checked: this.anonymous ? true : this.hideVotes, onChange: (e) => (this.hideVotes = e.target.checked) }), this.t('polls.results.hide')), h("rtk-button", { key: 'ab48323f46db1f6e485bea960f6d7ec6bb684075', kind: "wide", onClick: () => this.handleSubmit() }, this.t('polls.create')), this.error && h("span", { key: '1d61b167ee24001d0b66acdb361262bf7f2ffcc6', class: "error-text" }, this.error.message))));
    }
    static get style() { return RtkPollFormStyle0; }
}, [1, "rtk-poll-form", {
        "iconPack": [16],
        "t": [16],
        "options": [32],
        "anonymous": [32],
        "hideVotes": [32],
        "error": [32]
    }]);
__decorate([
    SyncWithStore()
], RtkPoll.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkPoll.prototype, "t", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-poll-form", "rtk-button", "rtk-icon"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-poll-form":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkPoll);
            }
            break;
        case "rtk-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "rtk-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { RtkPoll as R, defineCustomElement as d };
