'use strict';

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

const spwSidebarCss = () => `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;height:100%}.spw-sidebar{height:100%;width:var(--spw-ds-bo-sidebar-width);display:flex;flex-direction:column;background:white;border-right:1px solid var(--spw-colors-support-grey-grey-300);position:fixed;top:0;left:0;z-index:800}@media (min-width: 1024px){.spw-sidebar{transition:width 0.2s ease}}.spw-sidebar--with-topbar{top:var(--spw-ds-bo-topbar-height);height:calc(100% - var(--spw-ds-bo-topbar-height))}.spw-sidebar__toggle{display:none}@media (min-width: 1024px){.spw-sidebar__toggle{position:absolute;right:0;top:67px;flex-basis:auto;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-sidebar__toggle spw-icon{position:relative;transition:transform 0.15s 0.2s ease}.spw-sidebar--expanded .spw-sidebar__toggle spw-icon{transform:rotate(180deg)}}.spw-sidebar__content{overflow:hidden;flex:1 1 auto;overflow-y:auto;padding:16px 0;display:flex;flex-direction:column;justify-content:space-between}.spw-sidebar__content::-webkit-scrollbar{width:14px;height:14px}.spw-sidebar__content::-webkit-scrollbar-thumb{background:var(--spw-color-themes-grey-grey-400);border-radius:20px;border:4px solid var(--spw-ds-white)}.spw-sidebar__content::-webkit-scrollbar-track{background:var(--spw-ds-white)}.spw-sidebar__content{scrollbar-face-color:var(--spw-color-themes-grey-grey-400);scrollbar-track-color:var(--spw-ds-white)}@media (max-width: 1023px){.spw-sidebar__content{padding:0}}.spw-sidebar--expanded{width:var(--spw-ds-bo-sidebar-expanded-width)}.spw-sidebar--collapsed{width:var(--spw-ds-bo-sidebar-width)}.spw-sidebar__resize-border{display:none;position:absolute;top:0;right:0;width:10px;height:100%;transform:translateX(50%);cursor:col-resize;align-items:center;justify-content:center;background:transparent;z-index:10}`;

const SpwSidebar = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        /** Si true, la sidebar est dépliée par défaut */
        this.defaultExpanded = false;
        this.hasTopbar = false;
        this.BODY_CLASS = 'spw-sidebar-expanded';
        this.toggleSidebar = () => {
            this.expanded = !this.expanded;
            document.body.classList.toggle(this.BODY_CLASS, this.expanded);
        };
        this.checkTopbarClass = () => {
            this.hasTopbar = document.body.classList.contains('has-topbar');
        };
        this.checkExpandedState = () => {
            const bodyHasExpandedClass = document.body.classList.contains(this.BODY_CLASS);
            if (this.expanded !== bodyHasExpandedClass) {
                this.expanded = bodyHasExpandedClass;
            }
        };
    }
    componentWillLoad() {
        this.expanded = this.defaultExpanded;
        if (this.expanded) {
            document.body.classList.add(this.BODY_CLASS);
        }
        this.checkTopbarClass();
        this.observeBodyClassChanges();
    }
    disconnectedCallback() {
        var _a;
        document.body.classList.remove(this.BODY_CLASS);
        (_a = this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
    }
    /** Ouvre la sidebar */
    async open() {
        if (!this.expanded) {
            this.expanded = true;
            document.body.classList.add(this.BODY_CLASS);
        }
    }
    /** Ferme la sidebar */
    async close() {
        if (this.expanded) {
            this.expanded = false;
            document.body.classList.remove(this.BODY_CLASS);
        }
    }
    /** Ouvre ou ferme la sidebar */
    async toggle() {
        this.expanded = !this.expanded;
        document.body.classList.toggle(this.BODY_CLASS, this.expanded);
    }
    observeBodyClassChanges() {
        this.observer = new MutationObserver(() => {
            this.checkTopbarClass();
            this.checkExpandedState();
        });
        this.observer.observe(document.body, {
            attributes: true,
            attributeFilter: ['class'],
        });
    }
    get hostClass() {
        return {
            '--expanded': this.expanded,
            '--collapsed': !this.expanded,
        };
    }
    get elementClass() {
        return {
            'spw-sidebar': true,
            'spw-sidebar--expanded': this.expanded,
            'spw-sidebar--collapsed': !this.expanded,
            'spw-sidebar--with-topbar': this.hasTopbar,
        };
    }
    render() {
        return (index.h(index.Host, { key: '85674117e60989814f7d7a37f3dd3b904379d110', class: this.hostClass }, index.h("div", { key: 'a7dc79b161de709d47cda189859f6fbddf816035', class: this.elementClass }, index.h("span", { key: 'ee66487ae37380cc48444f049bd9aaef8c597928', class: "spw-sidebar__toggle", onClick: this.toggleSidebar, "aria-expanded": this.expanded.toString() }, index.h("spw-icon", { key: '479cf95d769990758fd766ebed32554863cf7508', icon: "fa-chevron-right" })), index.h("div", { key: '3d96559cf723cd903a77fb943ba58cca0036b96a', class: "spw-sidebar__content" }, index.h("slot", { key: '62d878e457b129647df984e5b960b9fd61a9b0fa', name: "navigation-top" }), index.h("slot", { key: 'fca6deed9ea823420628c03078e53b7cdd502e49', name: "navigation-bottom" })), index.h("div", { key: '67d0697a069f050892328f652b4e6930deb7a3fa', class: "spw-sidebar__resize-border", onClick: this.toggleSidebar }))));
    }
    get el() { return index.getElement(this); }
};
SpwSidebar.style = spwSidebarCss();

exports.spw_sidebar = SpwSidebar;
