'use strict';

var index = require('./index-DuCXzb-X.js');

const spwTableSidebarCss = () => `html{line-height:1.3;-webkit-text-size-adjust:100%;}h1,h2,h3,h4,h5,h6,p,ul,li{padding:0;margin:0}ul{list-style:none}:host{box-sizing:border-box;line-height:1.3;-webkit-text-size-adjust:100%;font-size:100%}:host *,:host *::before,:host *::after{box-sizing:inherit;font-family:var(--spw-ds-font-main)}body{margin:0}hr{box-sizing:content-box;height:0;overflow:visible;}pre{font-family:monospace, monospace;font-size:1em;}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted;}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em;}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0;}button,input{overflow:visible}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}button::-moz-focus-inner,[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal;}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0;}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px;}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit;}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}:root{--spw-ds-container-xl:1232px;--spw-ds-container-lg:1024px;--spw-ds-container-md:768px;--spw-ds-container-sm:640px}.spw-ds-container{width:100%;padding-left:16px;padding-right:16px;margin-left:auto;margin-right:auto}@media (min-width: 460px){.spw-ds-container{max-width:var(--spw-ds-container-sm)}}@media (min-width: 768px){.spw-ds-container{max-width:var(--spw-ds-container-md)}}@media (min-width: 1024px){.spw-ds-container{max-width:var(--spw-ds-container-lg)}}@media (min-width: 1350px){.spw-ds-container{max-width:var(--spw-ds-container-xl)}}:host{display:block;position:relative}.spw-table-sidebar{width:200px;height:100%;background:white;border:1px solid var(--spw-color-themes-grey-grey-300);border-right:0;z-index:99;transition:width 0.2s ease;display:flex;flex-direction:column;position:relative}.spw-table-sidebar__toggle{position:absolute;right:0;top:36px;width:20px;padding:6px 0;display:inline-flex;align-items:center;justify-content:center;border-radius:6px;box-shadow:var(--spw-effect-elevation-6);border:1px solid var(--spw-colors-support-grey-grey-300);cursor:pointer;font-size:13px;z-index:20;transform:translateX(50%);background:white;line-height:1}.spw-table-sidebar__toggle spw-icon{position:relative;transition:transform 0.15s 0.2s ease}.spw-table-sidebar--expanded .spw-table-sidebar__toggle spw-icon{transform:rotate(0deg)}.spw-table-sidebar--collapsed .spw-table-sidebar__toggle spw-icon{transform:rotate(180deg)}.spw-table-sidebar__content{overflow:hidden;flex:1 1 auto;overflow-y:auto;display:flex;flex-direction:column}.spw-table-sidebar__content::-webkit-scrollbar{width:14px;height:14px}.spw-table-sidebar__content::-webkit-scrollbar-thumb{background:var(--spw-color-themes-grey-grey-400);border-radius:20px;border:4px solid var(--spw-ds-white)}.spw-table-sidebar__content::-webkit-scrollbar-track{background:var(--spw-ds-white)}.spw-table-sidebar__content{scrollbar-face-color:var(--spw-color-themes-grey-grey-400);scrollbar-track-color:var(--spw-ds-white)}.spw-table-sidebar--collapsed .spw-table-sidebar__content{display:none}.spw-table-sidebar__mini{padding:16px 0;text-align:center;display:none}.spw-table-sidebar--collapsed .spw-table-sidebar__mini{display:block}.spw-table-sidebar__mini spw-icon{cursor:pointer}.spw-table-sidebar--expanded{width:var(--spw-table-sidebar-width)}.spw-table-sidebar--collapsed{width:50px}.spw-table-sidebar__header,.spw-table-sidebar__footer{padding:16px;position:sticky;background:var(--spw-ds-white);z-index:10}.spw-table-sidebar__header{top:0;padding-bottom:16px;border-bottom:1px solid var(--spw-color-themes-grey-grey-200);display:flex;align-items:center;justify-content:space-between;gap:8px}.spw-table-sidebar__header-title{display:flex;align-items:center;gap:8px;flex:1;min-width:0}.spw-table-sidebar__header-reset{flex-shrink:0}.spw-table-sidebar__footer{bottom:0;padding-top:16px;border-top:1px solid var(--spw-color-themes-grey-grey-200)}.spw-table-sidebar__scrollable-content{padding:16px;flex:1}`;

const SpwTableSidebar = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.sidebarReset = index.createEvent(this, "sidebarReset", 7);
        /** Si true, la sidebar est dépliée par défaut */
        this.defaultExpanded = true;
        /** Permet de définir un titre à la sidebar */
        this.sidebarTitle = 'Filtres';
        /** Permet de définir une icône à côté du titre de la sidebar (référence font-awesome) */
        this.sidebarIcon = 'fa-filter';
        /** Permet de définir une largeur en px pour la sidebar dépliée */
        this.sidebarWidth = 260;
        /** Si true, affiche une icône de reset à côté du titre */
        this.hasReset = true;
        /** Icône à utiliser pour le bouton de reset (référence font-awesome) */
        this.resetIcon = 'fa-arrow-rotate-left';
        this.toggleSidebar = () => {
            this.expanded = !this.expanded;
        };
        this.handleReset = (event) => {
            event.stopPropagation();
            this.sidebarReset.emit();
        };
    }
    componentWillLoad() {
        this.expanded = this.defaultExpanded;
    }
    componentDidLoad() {
        setTimeout(() => {
            this.observeTableHeight();
        }, 0);
    }
    disconnectedCallback() {
        if (this.resizeObserver) {
            this.resizeObserver.disconnect();
        }
        if (this.mutationObserver) {
            this.mutationObserver.disconnect();
        }
        if (this.debounceTimer) {
            clearTimeout(this.debounceTimer);
        }
    }
    calculateTotalHeight() {
        const spwTable = this.findSpwTable();
        if (!spwTable)
            return 0;
        const shadowRoot = spwTable.shadowRoot;
        if (!shadowRoot)
            return spwTable.offsetHeight;
        const tableContainer = shadowRoot.querySelector('.spw-table-container');
        let totalHeight = tableContainer ? tableContainer.offsetHeight : 0;
        const resizeHandle = shadowRoot.querySelector('.spw-table-resize-handle');
        if (resizeHandle) {
            totalHeight += resizeHandle.offsetHeight;
        }
        const footerSlot = spwTable.querySelector('[slot="table-footer"]');
        if (footerSlot && footerSlot instanceof HTMLElement) {
            totalHeight += footerSlot.offsetHeight;
        }
        return totalHeight;
    }
    observeTableHeight() {
        const spwTable = this.findSpwTable();
        if (!spwTable) {
            return;
        }
        const updateFullHeight = () => {
            const height = this.calculateTotalHeight();
            if (height > 0) {
                this.observedHeight = height;
            }
        };
        this.resizeObserver = new ResizeObserver(() => {
            updateFullHeight();
        });
        this.resizeObserver.observe(spwTable);
        this.mutationObserver = new MutationObserver(_ => {
            if (this.debounceTimer) {
                clearTimeout(this.debounceTimer);
            }
            this.debounceTimer = setTimeout(() => {
                updateFullHeight();
            }, 50);
        });
        this.mutationObserver.observe(spwTable, {
            childList: true,
            subtree: true,
            attributes: true,
            attributeFilter: ['style', 'class'],
        });
        if (spwTable.shadowRoot) {
            const shadowObserver = new MutationObserver(() => {
                updateFullHeight();
            });
            shadowObserver.observe(spwTable.shadowRoot, {
                childList: true,
                subtree: true,
                attributes: true,
            });
        }
        updateFullHeight();
    }
    findSpwTable() {
        const spwTableContainer = this.el.parentElement;
        if (!spwTableContainer || spwTableContainer.tagName.toLowerCase() !== 'spw-table-container') {
            return null;
        }
        const spwTable = spwTableContainer.querySelector('spw-table');
        return spwTable;
    }
    get hostClass() {
        return {
            '--expanded': this.expanded,
            '--collapsed': !this.expanded,
        };
    }
    get elementClass() {
        return {
            'spw-table-sidebar': true,
            'spw-table-sidebar--expanded': this.expanded,
            'spw-table-sidebar--collapsed': !this.expanded,
        };
    }
    render() {
        const style = Object.assign(Object.assign({}, (this.observedHeight !== undefined && { height: `${this.observedHeight}px` })), { '--spw-table-sidebar-width': `${this.sidebarWidth}px` });
        return (index.h(index.Host, { key: 'b8b4b59f8ddff138601e3723ab3b96919807bb8c', style: style, class: this.hostClass }, index.h("nav", { key: '069e5baf3dce00f9c45c7943f8f6e588e79c3fe6', class: this.elementClass }, index.h("span", { key: '5229c33d65e6bc1c08e4d1e3b0f8afc6d24a7431', class: "spw-table-sidebar__toggle", onClick: this.toggleSidebar, "aria-expanded": this.expanded.toString() }, index.h("spw-icon", { key: 'a50c05d8561210ef66026395e26e3cbaa506e77e', icon: "fa-chevron-left" })), index.h("div", { key: 'efb6cae5e348f52f026db07f6381d1f8785e85af', class: "spw-table-sidebar__mini", onClick: this.toggleSidebar }, index.h("spw-icon", { key: '3cea2ba602cc1757f4abcbfc2628ad19f521d4dd', icon: this.sidebarIcon, variant: "fa-regular" })), index.h("div", { key: '23dccad9d9cf67ad86580fa1b9cb1b52e004be20', class: "spw-table-sidebar__content" }, index.h("div", { key: 'aba8097d393fc7cefce1bcf1666403104a6b67c5', class: "spw-table-sidebar__header" }, index.h("span", { key: 'b5e89956cc8d101c938073d311ba2bd742b8dde8', class: "spw-table-sidebar__header-title" }, index.h("spw-icon", { key: '3277432f0fac70bd812714423c880c43026c19fd', icon: this.sidebarIcon, variant: "fa-regular" }), " ", this.sidebarTitle), this.hasReset && (index.h("spw-button", { key: '2244b989d733aa649d7d74d26fd548338c365d28', class: "spw-table-sidebar__header-reset", onClick: this.handleReset, type: "button", variant: "secondary", size: "small", isIconOnly: true, icon: this.resetIcon }))), index.h("div", { key: 'cac5fd1d25cc788ebb52997b2c244f554b8ed1aa', class: "spw-table-sidebar__scrollable-content" }, index.h("slot", { key: 'cad3dfe8b3fe8d41286d0891b7a8a3fe233def05' })), index.h("div", { key: 'ca8b941d16b2725f53dfb7099f40fda72a7901b6', class: "spw-table-sidebar__footer" }, index.h("slot", { key: 'd7dba20a95384af715ef218ceba8b77bd5f86d84', name: "sidebar-footer" }))))));
    }
    get el() { return index.getElement(this); }
};
SpwTableSidebar.style = spwTableSidebarCss();

exports.spw_table_sidebar = SpwTableSidebar;
