/*!
 * Crafted with ❤ by Salla
 */
import{D as n}from"./p-CoQJOPRz.js";let t=0;function r(n){const r="undefined"!=typeof globalThis?globalThis.crypto:void 0;return r&&"function"==typeof r.randomUUID?`new-${n}-${r.randomUUID()}`:(t+=1,`new-${n}-${Date.now()}-${t}`)}function u(n){return null==n?n:"function"==typeof structuredClone?structuredClone(n):JSON.parse(JSON.stringify(n))}function e(n){return{items:{update:n.items.update,remove:n.items.remove,add:n.items.add.map((({itemId:n,...t})=>t))}}}function i(n,t,e,i={}){const o=u(n);return{id:r(n.id),quantity:t,isNew:!0,selectedOptions:i,product:{...o,options:u(e)}}}function o(n){return"undefined"!=typeof File&&n instanceof File?n.name:String(n)}function c(n={}){return JSON.stringify(Object.entries(n).filter((([,n])=>null!=n&&o(n).length>0)).map((([n,t])=>[String(n),o(t)])).sort((([n],[t])=>n.localeCompare(t))))}function s(n){return Boolean(n&&Object.values(n).some((n=>null!=n&&o(n).length>0)))}const f=new Set([n.COLOR,n.COUNTRY,n.DIGITAL_CARD_VALUE,n.MULTIPLE_OPTIONS,n.RADIO,n.SINGLE_OPTION,n.THUMBNAIL]);function l(n){if(s(n?.selectedOptions))return n.selectedOptions;const t=function(n=[]){return n.reduce(((n,t)=>{if(null==t?.id)return n;const r=t.details?.filter((n=>n?.is_selected))||[],u=r[r.length-1],e=u?.id??t.value;return null==e||0===String(e).length||(n[String(t.id)]=String(e)),n}),{})}(n?.product?.options);return s(t)?t:function(n){return(n?.options||[]).reduce(((t,r)=>{if(null==r?.id)return t;const u=r.value??r.display_value;return null==u||0===String(u).length||(t[String(r.id)]=function(n,t,r){const u=n?.product?.options?.find((n=>String(n.id)===String(t))),e=String(r);if(!u?.details?.length||!f.has(u.type))return e;const i=u.details.find((n=>[n.id,n.name,n.option_value,n.color,n.image,n.code,n.display_value].some((n=>null!=n&&String(n)===e))));return i?String(i.id):e}(n,r.id,u)),t}),{})}(n)}function a(n=[],t,r={}){const u=c(r);return n.find((n=>String(n.product?.id)===String(t)&&c(l(n))===u))}function d(n){const t=Number(n?.max_quantity??n?.max_quantity_per_order);return Number.isFinite(t)&&t>0?t:void 0}function S(n,t){return!Number.isFinite(n)||n<1?1:t&&n>t?t:n}function g(n=[],t,r,u,e){return n.map((n=>n.id===t?function(n,t,r,u){return{...n,quantity:t,selectedOptions:u??l(n),product:n.product?{...n.product,options:r??n.product.options}:n.product}}(n,r,u,e):n))}function p(n=[],t){return n.filter((n=>n.id!==t))}function m(n,t){return{...n,...t}}function b(n=[],t,r,u={}){const e=n.filter((n=>n.id!==t));return e.push({id:t,quantity:r,options:u}),e}function y(n=[],t,r,u){return n.map((n=>n.itemId===t?{...n,quantity:r,options:u??n.options}:n))}export{d as a,u as b,S as c,y as d,b as e,a as f,l as g,i as h,e as i,m,p as r,g as u}