import{css as t,html as e}from"../../../../../lit/index.js";import{CollectionList as i}from"../../../../collection-list/collection-list.js";import"../../../../collection-list/lib/collection-item.js";import"../query/site-query.js";import{store as s}from"../../core/haxcms-site-store.js";export class SiteCollectionList extends i{constructor(){super(),this.editMode=!1,this.conditions={},this.sortObj={},this.results=[],this.breakSmartCollection=!1,this.limit=8,this.sort="title",this.parent="",this.tags="",this.pageType="",this.published="true",this.hideInMenu="",this.relatedItems="",this.t={allItems:"All items",topLevelItems:"Top level items"}}render(){return e`
      <site-query
        @result-changed="${this.resultEvent}"
        .sort="${this.sortObj}"
        .conditions="${this.conditions}"
        limit="${this.limit}"
      ></site-query>
      <collection-list
        items-per-row="${this.itemsPerRow}"
        ?lock-items="${this.editMode}"
      >
        ${this.results.map((t=>e`
            <collection-item
              line1="${t.title}"
              line2="${t.description}"
              url="${t.slug}"
              image="${t.metadata.image}"
              tags="${t.metadata.tags}"
              icon="${t.metadata.icon}"
              accent-color="${t.metadata.accentColor}"
            ></collection-item>
          `))}
      </collection-list>
    `}resultEvent(t){this.results=[...t.detail.value]}static get properties(){return{...super.properties,editMode:{type:Boolean},conditions:{type:Object},limit:{type:Number},sort:{type:String},parent:{type:String},tags:{type:String},pageType:{type:String,attribute:"page-type"},published:{type:String},hideInMenu:{type:String,attribute:"hide-in-menu"},relatedItems:{type:String,attribute:"related-items"},sortObj:{type:Object},results:{type:Array},breakSmartCollection:{type:Boolean,attribute:"break-smart-collection",reflect:!0}}}updated(t){super.updated&&super.updated(t),t.forEach(((t,e)=>{if(this.shadowRoot&&"results"==e&&this.dispatchEvent(new CustomEvent("results-changed",{detail:{value:this[e]}})),this.shadowRoot&&["parent","tags","pageType","published","hideInMenu","relatedItems"].includes(e)){let t={};""!==this.parent&&(t.parent=this.parent),""!==this.tags&&null!==this.tags&&(t["metadata.tags"]=this.tags),""!==this.pageType&&null!==this.pageType&&(t["metadata.pageType"]=this.pageType),"null"!==this.published&&(t["metadata.published"]="true"===this.published),"null"!=this.hideInMenu&&(t["metadata.hideInMenu"]="true"===this.hideInMenu),""!=this.relatedItems&&null!==this.relatedItems&&(t["metadata.relatedItems"]=this.relatedItems),this.conditions={...t}}if(this.shadowRoot&&"sort"===e){let t={};t[this[e]]="ASC",this.sortObj={...t}}if("breakSmartCollection"===e&&this.breakSmartCollection){let t=this.shadowRoot.querySelector("collection-list").cloneNode(!0);t.removeAttribute("lock-items"),this.parentNode.insertBefore(t,this),setTimeout((()=>{this.remove()}),0)}}))}haxHooks(){return{editModeChanged:"haxeditModeChanged",activeElementChanged:"haxactiveElementChanged",setupActiveElementForm:"haxsetupActiveElementForm"}}haxeditModeChanged(t){this.editMode=t}haxactiveElementChanged(t,e){e&&(this.editMode=e)}haxsetupActiveElementForm(t){const e=s.getManifestItems(!0);var i=[];e.forEach((t=>{if(t.id!=this.itemId){let s=t,r="- ";for(;s&&null!=s.parent;)s=e.find((t=>t.id==s.parent)),s&&(r="--"+r);i.push({text:r+t.title,value:t.id})}})),t.settings.configure.forEach(((e,s)=>{"parent"===e.property&&(t.settings.configure[s].inputMethod="select",t.settings.configure[s].itemsList=[{text:`-- ${this.t.allItems} --`,value:""},{text:`-- ${this.t.topLevelItems} --`,value:null},...i]),"relatedItems"===e.property&&(t.settings.configure[s].inputMethod="select",t.settings.configure[s].itemsList=[{text:`-- ${this.t.allItems} --`,value:""},...i])}))}static get haxProperties(){return new URL(`./${this.tag}.haxProperties.json`,import.meta.url).href}static get styles(){return[super.styles,t`
        :host {
          display: block;
          margin: var(--ddd-spacing-10) 0;
        }
      `]}static get tag(){return"site-collection-list"}}customElements.define(SiteCollectionList.tag,SiteCollectionList);