import{o as d}from"./chunk-GQP2MJQK.js";import{w as l}from"./chunk-ZVAMPSQU.js";var c=n=>{for(var o in n)n.hasOwnProperty(o)&&delete n[o]};var p="completionTracker",r="1",h=3,B=(()=>{let o=class o{constructor(){this.scaleByRecipeId={},this.ingredientCompletionByRecipeId={},this.instructionCompletionByRecipeId={},this.lastTouchedByRecipeId={};try{let e=localStorage.getItem(p);if(e){let t=JSON.parse(e);this.scaleByRecipeId=t.scaleByRecipeId||{},this.ingredientCompletionByRecipeId=t.ingredientCompletionByRecipeId||{},this.instructionCompletionByRecipeId=t.instructionCompletionByRecipeId||{},this.lastTouchedByRecipeId=t.lastTouchedByRecipeId||{}}this.cleanupExpiredEntries()}catch(e){d(e)}}cleanupExpiredEntries(){let e=h*24*60*60*1e3,t=Date.now(),i=new Date(t-e).getTime();Object.keys(this.lastTouchedByRecipeId).forEach(s=>{this.lastTouchedByRecipeId[s]<i&&(delete this.lastTouchedByRecipeId[s],delete this.scaleByRecipeId[s],delete this.ingredientCompletionByRecipeId[s],delete this.instructionCompletionByRecipeId[s])}),Object.keys(this.scaleByRecipeId).forEach(s=>{this.lastTouchedByRecipeId[s]||delete this.scaleByRecipeId[s]}),Object.keys(this.ingredientCompletionByRecipeId).forEach(s=>{this.lastTouchedByRecipeId[s]||delete this.ingredientCompletionByRecipeId[s]}),Object.keys(this.instructionCompletionByRecipeId).forEach(s=>{this.lastTouchedByRecipeId[s]||delete this.instructionCompletionByRecipeId[s]}),this.save()}setRecipeScale(e,t){this.scaleByRecipeId[e]=t,this.lastTouchedByRecipeId[e]=Date.now(),this.save()}getRecipeScale(e){return this.scaleByRecipeId[e]||"1"}toggleIngredientComplete(e,t){this.ingredientCompletionByRecipeId[e]=this.ingredientCompletionByRecipeId[e]||[];let i=this.ingredientCompletionByRecipeId[e];i.includes(t)?i.splice(i.indexOf(t),1):i.push(t),this.lastTouchedByRecipeId[e]=Date.now(),this.save()}toggleInstructionComplete(e,t){this.instructionCompletionByRecipeId[e]=this.instructionCompletionByRecipeId[e]||[];let i=this.instructionCompletionByRecipeId[e];i.includes(t)?i.splice(i.indexOf(t),1):i.push(t),this.lastTouchedByRecipeId[e]=Date.now(),this.save()}getInstructionComplete(e,t){var i;return((i=this.instructionCompletionByRecipeId[e])==null?void 0:i.includes(t))||!1}getIngredientComplete(e,t){var i;return((i=this.ingredientCompletionByRecipeId[e])==null?void 0:i.includes(t))||!1}save(){localStorage.setItem(p,JSON.stringify({scaleByRecipeId:this.scaleByRecipeId,ingredientCompletionByRecipeId:this.ingredientCompletionByRecipeId,instructionCompletionByRecipeId:this.instructionCompletionByRecipeId,lastTouchedByRecipeId:this.lastTouchedByRecipeId,version:r}))}reset(){c(this.scaleByRecipeId),c(this.ingredientCompletionByRecipeId),c(this.instructionCompletionByRecipeId),c(this.lastTouchedByRecipeId),localStorage.removeItem(p)}};o.\u0275fac=function(t){return new(t||o)},o.\u0275prov=l({token:o,factory:o.\u0275fac,providedIn:"root"});let n=o;return n})();export{B as a};
