import{r as i,c as t,h as r,H as s,g as e}from"./p-52e3bb32.js";const a=class{constructor(r){i(this,r),this.afOnSelectedCategoryChange=t(this,"afOnSelectedCategoryChange",7),this.afCategories=[],this.afAllCategories=!0,this.afAllCategoriesSelected=!0,this.afAllCategoriesText="Alla kategorier",this.afVisibleCollapsed=0,this.afStartCollapsed=!1,this.afMultiselect=!0,this.afHideToggle=!1,this.selectedCategories=[],this.collapsed=!1}afCategoriesChangeHandler(){this.selectedCategories=this.afCategories.filter((i=>i.selected)).map((i=>i.name)),0===this.selectedCategories.length&&this.afAllCategories&&this.afAllCategoriesSelected&&(this.selectedCategories=[this.afAllCategoriesText])}componentDidLoad(){this.afCategoriesChangeHandler(),this.collapsed=this.afStartCollapsed}displayCategories(){return this.afHideToggle?[{name:this.afAllCategoriesText},...this.afCategories]:this.afAllCategories?this.collapsed&&this.afCategories.length+1>this.afVisibleCollapsed?[{name:this.afAllCategoriesText},...this.afCategories.slice(0,this.afVisibleCollapsed-1)]:[{name:this.afAllCategoriesText},...this.afCategories]:this.collapsed&&this.afCategories.length>this.afVisibleCollapsed?this.afCategories.slice(0,this.afVisibleCollapsed):this.afCategories}toggleCategory(i){if(!this.afMultiselect)return this.afAllCategories&&i.name===this.afAllCategoriesText&&(this.selectedCategories.includes(this.afAllCategoriesText)?(this.selectedCategories=[],this.afOnSelectedCategoryChange.emit([])):(this.selectedCategories=[this.afAllCategoriesText],this.afOnSelectedCategoryChange.emit(this.afCategories.map((i=>i.name))))),this.selectedCategories=[i.name],void this.afOnSelectedCategoryChange.emit(this.selectedCategories);this.afAllCategories&&i.name===this.afAllCategoriesText?this.selectedCategories.includes(this.afAllCategoriesText)?(this.selectedCategories=[],this.afOnSelectedCategoryChange.emit([])):(this.selectedCategories=[this.afAllCategoriesText],this.afOnSelectedCategoryChange.emit(this.afCategories.map((i=>i.name)))):(this.selectedCategories=this.selectedCategories.findIndex((t=>t===i.name))>=0?this.selectedCategories.filter((t=>t!==i.name)):this.afAllCategories?[...this.selectedCategories.filter((i=>i!==this.afAllCategoriesText)),i.name]:[...this.selectedCategories,i.name],this.afOnSelectedCategoryChange.emit(this.selectedCategories))}toggleCollapsed(){this.collapsed=!this.collapsed}toggleHidden(){this.afHideToggle=!this.toggleHidden}render(){return r(s,{key:"d12f4ac366631a31dd0578b1241510210c1a2eec"},r("div",{key:"b24c2101967cdf45646831bbc81121be8050557b",class:{"digi-form-category-filter":!0}},this.displayCategories().map((i=>r("digi-button",{class:{"digi-form-category-filter--category":!0,"digi-form-category-filter--category--not-selected":!this.selectedCategories.includes(i.name)},afVariation:"primary",afAriaPressed:this.selectedCategories.includes(i.name),onAfOnClick:()=>{this.toggleCategory(i)}},void 0===i.hits&&i.name,void 0!==i.hits&&r("span",null,i.name," ",r("span",{class:"digi-form-category-filter--category--thin-text"},"(",i.hits,")"))))),!1===this.afHideToggle&&this.afCategories.length>this.afVisibleCollapsed&&r("div",{key:"2ab08f68cc055f2e5dfc6d507079654c8ae59af4"},r("digi-button",{key:"0286e062fa8df32f71e9149a35e3af51a8f35f7d",afVariation:"function",afAriaExpanded:!this.collapsed,onClick:()=>{this.toggleCollapsed()}},this.collapsed?"Visa alla":"Visa färre",r(this.collapsed?"digi-icon-plus":"digi-icon-minus",{slot:"icon","aria-hidden":"true"})))))}get hostElement(){return e(this)}static get watchers(){return{afCategories:["afCategoriesChangeHandler"]}}};a.style=".sc-digi-form-category-filter-h{--digi--form-category-filter--gap:var(--digi--padding--small)}.sc-digi-form-category-filter-h .digi-form-category-filter.sc-digi-form-category-filter{display:flex;flex-wrap:wrap;gap:var(--digi--form-category-filter--gap)}.sc-digi-form-category-filter-h .digi-form-category-filter--category.sc-digi-form-category-filter{--digi--button--icon--spacing:0px}.sc-digi-form-category-filter-h .digi-form-category-filter--category--not-selected.sc-digi-form-category-filter{--digi--button--color--background--primary--default:var(--digi--color--background--interactive--default--quaternary);--digi--button--color--text--primary--default:var(--digi--color--text--interactive--brand-primary);--digi--button--color--border--primary--default:var(--digi--color--background--interactive--default--quaternary)}.sc-digi-form-category-filter-h .digi-form-category-filter--category--thin-text.sc-digi-form-category-filter{font-weight:400}";export{a as digi_form_category_filter}