var __decorate=this&&this.__decorate||function(e,t,o,r){var n,l=arguments.length,s=l<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,r);else for(var i=e.length-1;i>=0;i--)(n=e[i])&&(s=(l<3?n(s):l>3?n(t,o,s):n(t,o))||s);return l>3&&s&&Object.defineProperty(t,o,s),s};import{css as e,html as t,LitElement as o}from"lit";import{customElement as r,property as n,queryAssignedElements as l}from"lit/decorators.js";import{when as s}from"lit/directives/when.js";let getStyles=()=>e`
    * {
        box-sizing: border-box;
    }
    
    :host {
        position: relative;
    }

    ol {
        list-style: none;
        padding: 0;
        margin: 0;
    }
    
    ::slotted(*[slot="parent"]) {
        cursor: pointer;
    }
    
    #chevron {
        position: absolute;
        height: 44px;
        display: flex;
        align-items: center;
        aspect-ratio: 1/1.25;
        padding-left: 4px;
        font-size: 18px;
        color: #cccccc;
        z-index: 10;
    }
    
    #chevron:hover {
        color: unset;
    }

    :host(:not([readonly])) > #chevron {
        cursor: pointer;
    }
`,OrTreeGroup=class extends o{constructor(){super(...arguments),this.expanded=!1,this.leaf=!1,this.readonly=!1,this._slotClickListener=e=>this.leaf?this._onExpandToggle(e):null,this._chevronClickListener=e=>this._onExpandToggle(e)}static get styles(){return[getStyles()]}select(){let e=this.getGroupNode();!this.leaf&&e&&(e.selected=!0)}selectAll(){this.select(),this.getChildNodes().forEach(e=>e.selected=!0)}deselect(){let e=this.getGroupNode();e&&(e.selected=!1)}deselectAll(){this.deselect(),this.getChildNodes().forEach(e=>e.selected=!1)}getGroupNode(){var e;return null==(e=this._parentNodes)?void 0:e[0]}getChildNodes(){return Array.from(this._childNodes||[]).map(e=>e.querySelector("or-tree-node")).filter(e=>null!=e)}firstUpdated(e){var t;return null==(t=this._parentNodes)||t.forEach(e=>{e.addEventListener("click",this._slotClickListener)}),super.firstUpdated(e)}disconnectedCallback(){var e;null==(e=this._parentNodes)||e.forEach(e=>{e.removeEventListener("click",this._slotClickListener)}),super.disconnectedCallback()}render(){return t`
            ${s(!this.readonly,()=>this._getIconTemplate(this.expanded))}
            <slot name="parent"></slot>
            <ol ?hidden=${!this.expanded}>
                <slot @slotchange=${this._onSlotChange}></slot>
            </ol>
        `}_getIconTemplate(e=!1){return t`
            <or-icon id="chevron" part="chevron" icon="${e?"chevron-down":"chevron-right"}"
                     @click="${this._chevronClickListener}"
            ></or-icon>
        `}_onExpandToggle(e){this.expanded=!this.expanded}_onSlotChange(e){this._applyIndentToChildren()}_applyIndentToChildren(e=this.getChildNodes()){e.forEach(e=>{let t=(e=>{let t=0;for(;e;)"or-tree-group"===e.tagName.toLowerCase()&&t++,e=e.parentElement;return t})(e);"parent"===e.slot&&t--,e.style.setProperty("--or-tree-node-indent",`${24+12*t}px`)})}};__decorate([n({type:Boolean,reflect:!0})],OrTreeGroup.prototype,"expanded",void 0),__decorate([n({type:Boolean})],OrTreeGroup.prototype,"leaf",void 0),__decorate([n({type:Boolean})],OrTreeGroup.prototype,"readonly",void 0),__decorate([l({slot:void 0})],OrTreeGroup.prototype,"_childNodes",void 0),__decorate([l({slot:"parent"})],OrTreeGroup.prototype,"_parentNodes",void 0),OrTreeGroup=__decorate([r("or-tree-group")],OrTreeGroup);export{OrTreeGroup};