import{T as e,g as t,h as n,y as r}from"./BrandWordmark-Yl88w34l.js";import{t as i}from"./vendor-db-DIvbC3Z6.js";var a=new Set([`themealdb`,`reciperadar`,`forkify`,`openrecipes-dump`]);function o(e){return a.has(e)}function s(){return{kind:`manual`}}function c(e){return e.filter(e=>e!==`open-recipes`&&!o(e))}function l(e){let t=e.tags??[],n=t.find(o);return t.includes(`open-recipes`)||n?{kind:`online`,provider:n,importedAt:e.createdAt}:s()}function u(e){return e.origin??l(e)}var d=new class extends i{products;recipes;shoppingItems;offCache;recipeImages;storageLocations;foodCategories;units;constructor(){super(`haeltbis`),this.version(1).stores({products:`id, barcode, name, expirationDate, storageLocation, category`,recipes:`id, title, *tags`,shoppingItems:`id, name, checked, recipeId, createdAt`,offCache:`barcode, fetchedAt`}),this.version(2).stores({products:`id, barcode, name, expirationDate, storageLocation, category`,recipes:`id, title, *tags`,shoppingItems:`id, name, checked, recipeId, createdAt`,offCache:`barcode, fetchedAt`,storageLocations:`id, sortOrder, label`,foodCategories:`id, sortOrder, label`}),this.version(3).stores({products:`id, barcode, name, expirationDate, storageLocation, category, unit`,recipes:`id, title, *tags`,shoppingItems:`id, name, checked, recipeId, createdAt`,offCache:`barcode, fetchedAt`,storageLocations:`id, sortOrder, label`,foodCategories:`id, sortOrder, label`,units:`id, sortOrder, label, family`}),this.version(4).stores({products:`id, barcode, name, expirationDate, storageLocation, category, unit`,recipes:`id, title, *tags`,shoppingItems:`id, name, checked, recipeId, createdAt`,offCache:`barcode, fetchedAt`,storageLocations:`id, sortOrder, label`,foodCategories:`id, sortOrder, label`,units:`id, sortOrder, label, family`,recipeImages:`recipeId, fetchedAt`}),this.version(5).stores({products:`id, barcode, name, expirationDate, storageLocation, category, unit`,recipes:`id, title, *tags`,shoppingItems:`id, name, checked, recipeId, createdAt`,offCache:`barcode, fetchedAt`,storageLocations:`id, sortOrder, label`,foodCategories:`id, sortOrder, label`,units:`id, sortOrder, label, family`,recipeImages:`recipeId, fetchedAt`}).upgrade(async e=>{await e.table(`recipes`).toCollection().modify(e=>{e.origin?.kind||(e.origin=l(e),e.tags=c(e.tags))})})}};function f(e,t){return{ingredient:e,status:t===`ambiguous`?`ambiguous`:`missing`,availableQuantity:0,requiredQuantity:e.quantity,unit:e.unit,matchedProductIds:[],coverageRatio:0,availabilityColor:`red`,shoppingListAmount:0,matchConfidence:t}}function p(t,n){if(t.productHint){let e=n.filter(e=>e.barcode===t.productHint);if(e.length===1)return{products:e,confidence:`certain`};if(e.length>1)return{products:[],confidence:`ambiguous`}}let r=e(t.name,n,e=>e.name);return{products:r.matches.map(e=>e.item),confidence:r.confidence}}function m(e,t){let{products:i,confidence:a}=p(e,t);if(a!==`certain`)return f(e,a);if(i.length===0)return f(e,`none`);let o=i.filter(t=>n(t.unit,e.unit));if(o.length===0){let t=i.some(e=>e.quantity>0);return{ingredient:e,status:t?`sufficient`:`missing`,availableQuantity:t?e.quantity:0,requiredQuantity:e.quantity,unit:e.unit,matchedProductIds:i.map(e=>e.id),coverageRatio:+!!t,availabilityColor:t?`green`:`red`,shoppingListAmount:0,matchConfidence:`certain`}}let s=o.reduce((e,t)=>e+r(t.quantity,t.unit),0),c=r(e.quantity,e.unit),l=c<=0?1:Math.min(1,s/c),u=`sufficient`;return s<=0?u=`missing`:s<c&&(u=`partial`),{ingredient:e,status:u,availableQuantity:s,requiredQuantity:c,unit:e.unit,matchedProductIds:o.map(e=>e.id),coverageRatio:l,availabilityColor:u===`sufficient`?`green`:u===`partial`?`yellow`:`red`,shoppingListAmount:0,matchConfidence:`certain`}}function h(e){let t=e.filter(e=>e.status===`sufficient`||e.status===`partial`).map(e=>e.coverageRatio).filter(e=>e>0);return t.length===0?0:Math.min(...t)}function g(e,t){let n=h(t),r=t.filter(e=>e.status===`partial`||e.status===`missing`||e.status===`unitMismatch`||e.status===`ambiguous`);return{recipe:e,scaleFactor:n,ingredients:e.ingredients.map(e=>({...e,quantity:Math.round(e.quantity*n*100)/100})),bottlenecks:r}}function _(e,n,r){return`${Number.isInteger(e)?String(e):e.toFixed(1)} ${r?.trim()||t(n)}`.trim()}export{g as a,u as c,_ as i,m as n,d as o,p as r,s,h as t};