const byPosition=(n=[])=>[...n].sort(((n,i)=>{var e,t;return(null!==(e=null==n?void 0:n.position)&&void 0!==e?e:0)-(null!==(t=null==i?void 0:i.position)&&void 0!==t?t:0)})),getPerBundleQuantity=(n,i=1)=>{const e=Math.max(Number(i)||1,1),t=Math.max(Number(null==n?void 0:n.quantity)||1,1);return Math.max(Math.round(t/e),1)},getBundleComponentRowsFromLineItems=(n=[],i=1,e=!0,t="·")=>{const o=(t||"·").trim()||"·";return(n||[]).map((n=>{var t;const l=((null==n?void 0:n.variant_options)||[]).filter(Boolean),d=l.length?l.join(` ${o} `):((null==n?void 0:n.variant_display_options)||"").trim();if(!e&&!d)return null;const r=null===(t=null==n?void 0:n.price)||void 0===t?void 0:t.product,u=(null==r?void 0:r.name)||"";if(!u)return null;const a=getPerBundleQuantity(n,i);return{id:null==n?void 0:n.id,name:u,variants:d,qty:a}})).filter(Boolean)},getBundleComponentRowsFromBundleItems=(n=[])=>byPosition(n).map((n=>{const i=null==n?void 0:n.component_product,e=(null==i?void 0:i.name)||"",t=Math.max(Number(null==n?void 0:n.quantity)||1,1);return e?{id:null==n?void 0:n.id,name:e,variants:"",qty:t}:null})).filter(Boolean),groupBundleLineItems=(n=[])=>{const i=[],e=[],t={};return(n||[]).forEach((n=>{var o,l;if(null==n?void 0:n.component_line_item)return;const d=null===(o=null==n?void 0:n.price)||void 0===o?void 0:o.product;if(null==d?void 0:d.bundle)return e.push(n),void(t[n.id]=byPosition((null===(l=null==n?void 0:n.component_line_items)||void 0===l?void 0:l.data)||[]));i.push(n)})),{regular:i,bundleParents:e,componentsByParent:t}},convertLineItemsToLineItemData=n=>((null==n?void 0:n.data)||[]).filter((n=>!(null==n?void 0:n.component_line_item))).map((n=>{var i;return{...(null==n?void 0:n.id)?{id:n.id}:{},price_id:n.price.id,quantity:n.quantity,variant_id:null===(i=n.variant)||void 0===i?void 0:i.id}})),getLineItemPriceIds=n=>((null==n?void 0:n.data)||[]).map((n=>n.price.id)),getLineItemByPriceId=(n,i)=>((null==n?void 0:n.data)||[]).find((n=>n.price.id===i)),isPriceInOrder=(n,i)=>!!getLineItemPriceIds(null==i?void 0:i.line_items).find((i=>(null==n?void 0:n.id)===i));export{groupBundleLineItems as a,getLineItemByPriceId as b,convertLineItemsToLineItemData as c,getPerBundleQuantity as d,getBundleComponentRowsFromBundleItems as e,getBundleComponentRowsFromLineItems as g,isPriceInOrder as i};