/*!
 * Custom elements for Nanopore-Digital Web applications
 */
import { r as registerInstance, g as getElement, a as Host } from './index-BM3Om9WE.js';
import { h } from './renderer-DpNDfhNy.js';

const Rating = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
    }
    get host() { return getElement(this); }
    /** The default state. `false` - excess items are hidden. `true` - excess items are shown. */
    show = false;
    /** Optional JS selector to target which elements to hide or show */
    childrenSelector;
    /** The maximum number of items to show when `show` is true.
     * Excess items will be hidden. */
    maxToShow = 3;
    /** Only show the 'show more' button */
    noHideBtn = false;
    get children() {
        let children;
        if (this.childrenSelector) {
            children = this.host.querySelectorAll(this.childrenSelector);
        }
        else {
            children = this.host.children;
        }
        return Array.from(children).filter((ele) => !ele.hasAttribute('slot'));
    }
    handleShowHideElements() {
        this.children.forEach((ele, i) => {
            if (this.show) {
                if (ele.style.display === 'none') {
                    ele.style.display = '';
                }
            }
            else {
                if (i >= this.maxToShow) {
                    ele.style.display = 'none';
                }
                else {
                    ele.style.display = '';
                }
            }
        });
    }
    handleClick(_e) {
        this.show = !this.show;
    }
    connectedCallback() {
        this.handleShowHideElements();
    }
    render() {
        return (h(Host, { key: 'b129148afdc959f912a16d1e2642c3e920a0a381', class: "nano-more-less" }, h("slot", { key: '92aa96b6301d14f7b4d9aee9cc4cafbf0ff75431', onSlotchange: () => this.handleShowHideElements() }), this.children?.length > this.maxToShow && [
            h("div", { key: '73a5c457e8243cd8cf8e8ec1e681aa2c62244936', style: { display: this.show ? 'none' : 'contents' }, class: "button-wrapper", part: "button-wrapper button-wrapper--less", onClick: (e) => this.handleClick(e) }, h("slot", { key: '48802275120ff78676a19b25f792806dd03db2c1', name: "less" }, h("button", { key: '703d054e4560cf22d571a29838dfbd649062f7ca', part: "button button--less" }, "Show more (+", this.children.length - this.maxToShow, ")"))),
            !this.noHideBtn ? (h("div", { style: { display: this.show ? 'contents' : 'none' }, class: "button-wrapper", part: "button-wrapper button-wrapper--more", onClick: (e) => this.handleClick(e) }, h("slot", { name: "more" }, h("button", { part: "button button--more" }, "Show less (-", this.children.length - this.maxToShow, ")")))) : (''),
        ]));
    }
    static get watchers() { return {
        "maxToShow": ["handleShowHideElements"],
        "show": ["handleShowHideElements"],
        "childrenSelector": ["handleShowHideElements"]
    }; }
};
Rating.style = ":host { display: contents; }";

export { Rating as nano_more_less };
