import{a as Q}from"./chunk-U5JHIRNW.js";import{a as J}from"./chunk-KNMWXIQN.js";import{k as G}from"./chunk-3JLWQSYQ.js";import{A as _,C as g,D as p,Fa as m,G as B,Ha as h,Ja as M,Jc as A,Ka as w,Kb as F,La as y,Nb as O,Pa as P,Qb as W,Qc as j,S as o,Ta as I,Ua as f,Va as E,X as T,ad as $,bd as H,da as u,ea as x,fb as D,ga as k,ha as V,ia as b,ka as a,la as c,lc as R,ma as N,md as U,ne as z,ra as S,ta as C,td as K,ud as q,va as d,xb as L}from"./chunk-ZVAMPSQU.js";import{j as v}from"./chunk-FB5LSH2R.js";var X=n=>({scale:n});function Y(n,r){if(n&1){let s=S();a(0,"ion-item")(1,"ion-checkbox",0),y("ngModelChange",function(e){let i=g(s).$index,l=d(2);return w(l.ingredientBinders[i],e)||(l.ingredientBinders[i]=e),p(e)}),C("ngModelChange",function(){let e=g(s).$index,i=d(2);return p(i.toggleIngredient(e))}),m(2),c()()}if(n&2){let s=r.$implicit,t=r.$index,e=d(2);o(),M("ngModel",e.ingredientBinders[t]),o(),h(" ",s.plaintextContent," ")}}function Z(n,r){if(n&1){let s=S();a(0,"div")(1,"p"),m(2),I(3,"translate"),c(),a(4,"ion-item")(5,"ion-checkbox",0),y("ngModelChange",function(e){g(s);let i=d();return w(i.allSelected,e)||(i.allSelected=e),p(e)}),C("ngModelChange",function(){g(s);let e=d();return p(e.resetAll())}),m(6),I(7,"translate"),c()(),V(8,Y,3,2,"ion-item",null,k),N(10,"br"),a(11,"a",1),C("click",function(){g(s);let e=d();return p(e.changeScale())}),m(12),I(13,"translate"),c()()}if(n&2){let s=d();o(2),h(" ",f(3,4,"components.selectIngredients.title")," "),o(3),M("ngModel",s.allSelected),o(),h(" ",f(7,6,"components.selectIngredients.toggleAll")," "),o(2),b(s.scaledIngredients),o(4),h(" ",E(13,8,"components.selectIngredients.scale",P(11,X,s.scaleDisplay))," ")}}function ee(n,r){n&1&&(a(0,"div")(1,"p")(2,"b"),m(3),I(4,"translate"),c()()()),n&2&&(o(3),h(" ",f(4,1,"components.selectIngredients.null")," "))}var ue=(()=>{let r=class r{constructor(){this.modalCtrl=_(A),this.preferencesService=_(J),this.translate=_($),this.utilService=_(G),this.allSelected=!0,this.ingredientBinders={},this.scaledIngredients=[],this.scale="1",this.decimalNotationMode=".",this.selectedIngredients=[],this.selectedIngredientsChange=new B}get ingredients(){return this._ingredients}set ingredients(t){this._ingredients=t,this.selectedIngredients=[],this.ingredientBinders={},this.applyScale(!0)}get scaleDisplay(){return U(this.scale,this.decimalNotationMode)}set initialScale(t){this.scale=t,this.applyScale()}changeScale(){return v(this,null,function*(){var i;let t=yield this.modalCtrl.create({component:Q,componentProps:{scale:this.scale,ingredients:(i=this.scaledIngredients)!=null?i:[],decimalNotationMode:this.decimalNotationMode},cssClass:"scaleRecipeModal"});yield t.present();let{data:e}=yield t.onDidDismiss();e!=null&&e.scale&&(this.scale=e.scale,this.applyScale())})}isIngredientIgnored(t){let e=this.preferencesService.preferences[z.IgnoreItemTitles].split("\n").filter(l=>l.trim()).map(l=>l.toLowerCase()),i=t.originalContent.toLowerCase();for(let l of e)if(i.includes(l))return!0;return!1}applyScale(t){this.decimalNotationMode=K(this._ingredients,this.utilService.getCurrentLocale()),this.scaledIngredients=q(this._ingredients,this.scale,{decimalNotationMode:this.decimalNotationMode}).filter(e=>!e.isHeader),this.selectedIngredients=[];for(let e=0;e<(this.scaledIngredients||[]).length;e++){let i=this.isIngredientIgnored(this.scaledIngredients[e]);t&&(this.ingredientBinders[e]=!i),this.ingredientBinders[e]&&this.selectedIngredients.push(this.scaledIngredients[e])}this.selectedIngredientsChange.emit(this.selectedIngredients)}toggleIngredient(t){this.ingredientBinders[t]?this.selectedIngredients.push(this.scaledIngredients[t]):this.selectedIngredients.splice(this.selectedIngredients.indexOf(this.scaledIngredients[t]),1),this.selectedIngredientsChange.emit(this.selectedIngredients)}resetAll(){for(let t in Object.keys(this.ingredientBinders))this.ingredientBinders.hasOwnProperty(t)&&(this.ingredientBinders[t]=this.allSelected,this.toggleIngredient(parseInt(t,10)))}};r.\u0275fac=function(e){return new(e||r)},r.\u0275cmp=T({type:r,selectors:[["select-ingredients"]],inputs:{ingredients:"ingredients",initialScale:"initialScale"},outputs:{selectedIngredientsChange:"selectedIngredientsChange"},decls:3,vars:2,consts:[["labelPlacement","end","justify","start","checked","true",3,"ngModelChange","ngModel"],[1,"scale",3,"click"]],template:function(e,i){e&1&&(a(0,"div"),u(1,Z,14,13,"div"),u(2,ee,5,3,"div"),c()),e&2&&(o(),x(i.scaledIngredients&&i.scaledIngredients.length>0?1:-1),o(),x(!i.scaledIngredients||i.scaledIngredients.length===0?2:-1))},dependencies:[D,W,F,O,L,R,j,H],styles:[".scale[_ngcontent-%COMP%]{cursor:pointer}"]});let n=r;return n})();export{ue as a};
