import{Ar as Tu,Da as e5,Eo as kb,Gr as Va,Ia as f$,Io as lA,Is as rh,J as EI,Lr as Uj,Oi as Zt,Oo as kj,Q as EV,Qi as bV,Qr as W$,Wa as g,Yi as bI,Za as gx,_s as ph,g as BRe,ga as ci,gc as wf,ta as bi,u as AV,ua as cA,vc as wp}from"./chunk-B_pj7Jpm.js";import{A as qn,O as ln,r as D,s as Jn}from"./chunk-BPHMC4rz.js";import{t as Vt}from"./chunk-BrcGtY4C.js";var v=class i{notifier=g(bi);inputId=ph.required();availableItems=ph([]);placeholder=ph(void 0);maxIndividualItems=ph(void 0);allSelectedLabel=ph(void 0);selectedLabel=ph(void 0);virtualScroll=ph(!1,{transform:Tu});selectedItemsLabel;selectedItems;propagateChange=e=>{};writeValue(e){if(e){this.selectedItems=e,this.updateLabel();return}this.selectAll()}registerOnChange(e){this.propagateChange=e}registerOnTouched(){}ngOnChanges(){this.updateLabel()}onModelChange(){this.updateLabel(),this.isMaxItemsValid()&&this.propagateChange(this.buildOutputItems())}onPanelHide(){Array.isArray(this.selectedItems)&&this.selectedItems.length===0&&this.selectAll(),this.checkMaxItemsOrSelectAll()}isMaxItemsValid(){let e=this.maxIndividualItems();if(!e)return!0;let t=this.buildOutputItems();return t?!(t.length>=e):!0}checkMaxItemsOrSelectAll(){this.isMaxItemsValid()||(this.notifier.error(BRe("Þú getur ekki valið meira en {maxItems, plural, =1 {1 atriði} other {{maxItems} atriði}}",{maxItems:this.maxIndividualItems()})),this.selectAll())}selectAll(){this.selectedItems=this.availableItems().map(e=>e.id+``),this.updateLabel()}updateLabel(){let e=this.availableItems();this.selectedItems?.length===e?.length?this.selectedItemsLabel=this.allSelectedLabel():this.selectedItemsLabel=this.selectedLabel()}buildOutputItems(){if(Array.isArray(this.selectedItems))return this.selectedItems.length===0||this.selectedItems.length===this.availableItems().length?null:this.selectedItems}static ɵfac=function(t){return new(t||i)};static ɵcmp=Va({type:i,selectors:[[`my-select-checkbox-default-all`]],inputs:{inputId:[1,`inputId`],availableItems:[1,`availableItems`],placeholder:[1,`placeholder`],maxIndividualItems:[1,`maxIndividualItems`],allSelectedLabel:[1,`allSelectedLabel`],selectedLabel:[1,`selectedLabel`],virtualScroll:[1,`virtualScroll`]},features:[e5([{provide:D,useExisting:wf(()=>i),multi:!0}]),ci],decls:1,vars:6,consts:[[`showClear`,`false`,`showToggleAll`,`true`,3,`ngModelChange`,`panelHide`,`ngModel`,`availableItems`,`placeholder`,`inputId`,`selectedItemsLabel`,`virtualScroll`]],template:function(t,l){t&1&&(wp(0,`my-select-checkbox`,0),lA(`ngModelChange`,function(s){return W$(l.selectedItems,s)||(l.selectedItems=s),s}),rh(`ngModelChange`,function(){return l.onModelChange()})(`panelHide`,function(){return l.onPanelHide()}),kb(),kj()),t&2&&(cA(`ngModel`,l.selectedItems),gx(`availableItems`,l.availableItems())(`placeholder`,l.placeholder())(`inputId`,l.inputId())(`selectedItemsLabel`,l.selectedItemsLabel)(`virtualScroll`,l.virtualScroll()),Uj())},dependencies:[Vt,Jn,qn,ln],encapsulation:2,changeDetection:1})};function $(i,e){if(i&1){let t=AV();wp(0,`my-select-checkbox-default-all`,1),lA(`ngModelChange`,function(a){EI(t);let s=f$();return W$(s.selectedLanguages,a)||(s.selectedLanguages=a),bI(a)}),rh(`ngModelChange`,function(){EI(t);return bI(f$().onModelChange())}),kb(),kj()}if(i&2){let t=f$();gx(`availableItems`,t.availableLanguages),cA(`ngModel`,t.selectedLanguages),gx(`inputId`,t.inputId())(`maxIndividualItems`,t.maxLanguages()),Uj()}}var G=class i{server=g(Zt);inputId=ph.required();maxLanguages=ph(void 0);selectedLanguages;availableLanguages;ngOnInit(){this.server.getVideoLanguages().subscribe(e=>{let t=e.find(l=>l.id===`zxx`);this.availableLanguages=[{label:"Óþekkt tungumál",id:`_unknown`},t,...e.filter(l=>l.id!==`zxx`).map(l=>({label:l.label,id:l.id}))]})}propagateChange=e=>{};writeValue(e){this.selectedLanguages=e}registerOnChange(e){this.propagateChange=e}registerOnTouched(){}onModelChange(){this.propagateChange(this.selectedLanguages)}static ɵfac=function(t){return new(t||i)};static ɵcmp=Va({type:i,selectors:[[`my-select-languages`]],inputs:{inputId:[1,`inputId`],maxLanguages:[1,`maxLanguages`]},features:[e5([{provide:D,useExisting:wf(()=>i),multi:!0}])],decls:1,vars:1,consts:()=>{let e;e="Öll tungumál";let t;t="";let l;return l="Bæta við nýju tungumáli",[[`virtualScroll`,`true`,`virtualScrollItemSize`,`37`,`allSelectedLabel`,e,`selectedLabel`,t,`placeholder`,l,3,`availableItems`,`ngModel`,`inputId`,`maxIndividualItems`],[`virtualScroll`,`true`,`virtualScrollItemSize`,`37`,`allSelectedLabel`,e,`selectedLabel`,t,`placeholder`,l,3,`ngModelChange`,`availableItems`,`ngModel`,`inputId`,`maxIndividualItems`]]},template:function(t,l){t&1&&EV(0,$,1,4,`my-select-checkbox-default-all`,0),t&2&&bV(l.availableLanguages?0:-1)},dependencies:[v,Jn,qn,ln],encapsulation:2,changeDetection:1})};export{v as n,G as t};
//# debugId=cb0b79f0-be73-5b88-ba3d-7c1a2536ac6a
//# sourceMappingURL=chunk-M2X1-U1Z.js.map