import{r as i,c as l,h as t}from"./p-b891c2f1.js";import{o}from"./p-494248b1.js";import{h as e}from"./p-eaac2001.js";import{i as s}from"./p-936390dd.js";import"./p-684c85b4.js";import"./p-aafd8ea4.js";import"./p-112455b1.js";const n=class{constructor(t){i(this,t),this.scUpdateLineItem=l(this,"scUpdateLineItem",7),this.scRemoveLineItem=l(this,"scRemoveLineItem",7),this.editLineItems=!0,this.removeLineItems=!0,this.lockedChoices=[]}updateQuantity(i,l){this.scUpdateLineItem.emit({price_id:i.price.id,quantity:l})}removeLineItem(i){this.scRemoveLineItem.emit({price_id:i.price.id,quantity:1})}getName(i){var l,t,o,e,s;let n="";return n=Object.keys(this.prices||{}).filter((l=>this.prices[l].product===i.price.product.id)).length>1?`${null===(t=null===(l=null==i?void 0:i.price)||void 0===l?void 0:l.product)||void 0===t?void 0:t.name} – ${null===(o=null==i?void 0:i.price)||void 0===o?void 0:o.name}`:null===(s=null===(e=null==i?void 0:i.price)||void 0===e?void 0:e.product)||void 0===s?void 0:s.name,n}isLocked(i){return this.lockedChoices.some((l=>l.id===i.price.id))}isEditable(){return null!==this.editable?this.editable:this.editLineItems}isRemovable(){return null!==this.removable?this.removable:this.removeLineItems}render(){var i,l,o,n,d;return this.loading&&!(null===(o=null===(l=null===(i=this.order)||void 0===i?void 0:i.line_items)||void 0===l?void 0:l.data)||void 0===o?void 0:o.length)?t("sc-line-item",null,t("sc-skeleton",{style:{width:"50px",height:"50px","--border-radius":"0"},slot:"image"}),t("sc-skeleton",{slot:"title",style:{width:"120px",display:"inline-block"}}),t("sc-skeleton",{slot:"description",style:{width:"60px",display:"inline-block"}}),t("sc-skeleton",{style:{width:"120px",display:"inline-block"},slot:"price"}),t("sc-skeleton",{style:{width:"60px",display:"inline-block"},slot:"price-description"})):t("div",{class:"line-items"},((null===(d=null===(n=this.order)||void 0===n?void 0:n.line_items)||void 0===d?void 0:d.data)||[]).sort(((i,l)=>{var t,o,e,s;return(null===(t=i.price)||void 0===t?void 0:t.id)<(null===(o=l.price)||void 0===o?void 0:o.id)?-1:(null===(e=i.price)||void 0===e?void 0:e.id)>(null===(s=l.price)||void 0===s?void 0:s.id)?1:0})).map((i=>{var l,o,n,d,v,r,u;return t("sc-product-line-item",{key:i.id,imageUrl:null===(o=null===(l=null==i?void 0:i.price)||void 0===l?void 0:l.product)||void 0===o?void 0:o.image_url,name:null===(d=null===(n=null==i?void 0:i.price)||void 0===n?void 0:n.product)||void 0===d?void 0:d.name,editable:this.isEditable()&&!(null===(v=null==i?void 0:i.price)||void 0===v?void 0:v.ad_hoc),removable:this.isRemovable(),quantity:i.quantity,amount:null!==i.ad_hoc_amount?i.ad_hoc_amount:i.subtotal_amount,currency:null===(r=this.order)||void 0===r?void 0:r.currency,trialDurationDays:null===(u=null==i?void 0:i.price)||void 0===u?void 0:u.trial_duration_days,interval:!!(null==i?void 0:i.price)&&s(null==i?void 0:i.price,{showOnce:e(this.order)}),onScUpdateQuantity:l=>this.updateQuantity(i,l.detail),onScRemove:()=>this.removeLineItem(i)})})))}};o(n,["order","loading","prices","lockedChoices","editLineItems","removeLineItems"],!1),n.style=":host{display:block}:slotted(*~*){margin-top:20px}sc-product-line-item~sc-product-line-item,sc-line-item~sc-line-item{margin-top:20px}";export{n as sc_line_items}