import { r as registerInstance, c as createEvent, h, H as Host } from './index-BIwHMk6j.js';
import { c as createRandomString } from './random-string-C2JP2nLw.js';

const documentPickerCss = () => `@charset "UTF-8";:host(limebb-document-picker){--checkbox-label-overflow-wrap:break-word;--switch-label-overflow-wrap:break-word}:host(limebb-document-picker:not([invalid]):not([invalid=true])) .limel-notched-outline{--limel-notched-outline-border-color:transparent;--limel-notched-outline-background-color:transparent}.limel-notched-outline{padding:0.75rem 0.5rem}limel-masonry-layout{--masonry-layout-min-column-width:10rem;--masonry-layout-gap:0.5rem}:host(limebb-document-picker:focus),:host(limebb-document-picker:focus-visible),:host(limebb-document-picker:focus-within){--limel-h-l-grid-template-rows-transition-speed:0.46s;--limel-h-l-grid-template-rows:1fr}:host(limebb-document-picker){--limel-h-l-grid-template-rows-transition-speed:0.3s;--limel-h-l-grid-template-rows:0fr}:host(limebb-document-picker:focus) limel-helper-line,:host(limebb-document-picker:focus-visible) limel-helper-line,:host(limebb-document-picker:focus-within) limel-helper-line,:host(limebb-document-picker:hover) limel-helper-line{will-change:grid-template-rows}`;

const DocumentPicker = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.change = createEvent(this, "change");
        /**
         * The list of document items to display in the picker.
         */
        this.items = [];
        /**
         * Set to `true` to indicate that the current selection is invalid.
         */
        this.invalid = false;
        /**
         * Set to `true` to indicate that selecting an item is required.
         */
        this.required = false;
        /**
         * Defines whether the picker allows single or multiple selection.
         * - 'radio': Allows single selection within a group.
         * - 'checkbox': Allows multiple selection.
         */
        this.type = 'checkbox';
        this.handleItemInteract = (event) => {
            event.stopPropagation();
            const interactedItem = event.detail;
            if (!interactedItem) {
                return;
            }
            let updatedItems;
            if (this.type === 'radio') {
                // For radio buttons: either select the clicked item (and deselect others)
                // or allow deselecting if clicking the already selected item
                updatedItems = this.items
                    .map((item) => {
                    if (item.file.id === interactedItem.file.id) {
                        return Object.assign(Object.assign({}, item), { selected: interactedItem.selected });
                    }
                    return Object.assign(Object.assign({}, item), { selected: false });
                })
                    .find((item) => item.selected);
            }
            else {
                updatedItems = this.items
                    .map((item) => {
                    if (item.file.id === interactedItem.file.id) {
                        return Object.assign(Object.assign({}, item), { selected: interactedItem.selected });
                    }
                    return item;
                })
                    .filter((item) => item.selected);
            }
            this.change.emit(updatedItems);
        };
        this.renderHelperLine = () => {
            if (!this.helperText) {
                return;
            }
            return (h("limel-helper-line", { helperText: this.helperText, helperTextId: this.helperTextId, invalid: this.invalid }));
        };
        this.helperTextId = createRandomString();
        this.labelId = createRandomString();
    }
    render() {
        return (h(Host, { key: 'cf8c1618a2d98a0278e16a634df162b9e0e7cb3e' }, h("limel-notched-outline", { key: '07e5f29db31eb7fc89b915e311bba3c2c6e2826a', labelId: this.labelId, label: this.label, required: this.required, invalid: this.invalid, hasFloatingLabel: true }, h("limel-masonry-layout", { key: '65a36951d5ffa6e23ee90fc98e2bac82ba26e6ed', slot: "content", role: this.type === 'radio' ? 'radiogroup' : 'group', "aria-labelledby": this.label ? this.labelId : undefined, "aria-describedby": this.helperText ? this.helperTextId : undefined }, this.renderItems())), this.renderHelperLine()));
    }
    renderItems() {
        return this.items.map((item) => (h("limebb-document-item", { platform: this.platform, context: this.context, item: item, key: item.file.id, type: this.type, onInteract: this.handleItemInteract })));
    }
};
DocumentPicker.style = documentPickerCss();

export { DocumentPicker as limebb_document_picker };
