import{h}from"@stencil/core";import{state as checkoutState}from"../../../../store/checkout/index";import{hasSubscription}from"../../../../functions/line-items";import{intervalString}from"../../../../functions/price";import{removeCheckoutLineItem,updateCheckoutLineItem}from"../../../../store/checkout/mutations";import{formBusy}from"../../../../store/form/getters";import{getMaxStockQuantity}from"../../../../functions/quantity";export class ScLineItems{constructor(){this.editable=void 0,this.removable=void 0}isEditable(e){var t;return!((null===(t=null==e?void 0:e.price)||void 0===t?void 0:t.ad_hoc)||(null==e?void 0:e.bump_amount)||(null==e?void 0:e.locked))&&this.editable}render(){var e,t,i,l,o;return formBusy()&&!(null===(i=null===(t=null===(e=null==checkoutState?void 0:checkoutState.checkout)||void 0===e?void 0:e.line_items)||void 0===t?void 0:t.data)||void 0===i?void 0:i.length)?h("sc-line-item",null,h("sc-skeleton",{style:{width:"50px",height:"50px","--border-radius":"0"},slot:"image"}),h("sc-skeleton",{slot:"title",style:{width:"120px",display:"inline-block"}}),h("sc-skeleton",{slot:"description",style:{width:"60px",display:"inline-block"}}),h("sc-skeleton",{style:{width:"120px",display:"inline-block"},slot:"price"}),h("sc-skeleton",{style:{width:"60px",display:"inline-block"},slot:"price-description"})):h("div",{class:"line-items",part:"base",tabindex:"0"},((null===(o=null===(l=null==checkoutState?void 0:checkoutState.checkout)||void 0===l?void 0:l.line_items)||void 0===o?void 0:o.data)||[]).map((e=>{var t,i,l,o,n,a,u,c;const r=getMaxStockQuantity(null===(t=null==e?void 0:e.price)||void 0===t?void 0:t.product,null==e?void 0:e.variant);return h("div",{class:"line-item"},h("sc-product-line-item",{key:e.id,image:null==e?void 0:e.image,name:null===(l=null===(i=null==e?void 0:e.price)||void 0===i?void 0:i.product)||void 0===l?void 0:l.name,priceName:null===(o=null==e?void 0:e.price)||void 0===o?void 0:o.name,variantLabel:((null==e?void 0:e.variant_options)||[]).filter(Boolean).join(" / ")||null,purchasableStatusDisplay:null==e?void 0:e.purchasable_status_display,...r?{max:r}:{},editable:this.isEditable(e),removable:!(null==e?void 0:e.locked)&&this.removable,quantity:e.quantity,fees:null===(n=null==e?void 0:e.fees)||void 0===n?void 0:n.data,setupFeeTrialEnabled:null===(a=null==e?void 0:e.price)||void 0===a?void 0:a.setup_fee_trial_enabled,amount:null!==e.ad_hoc_amount?e.ad_hoc_amount:e.subtotal_amount,scratchAmount:null==e.ad_hoc_amount&&(null==e?void 0:e.scratch_amount),currency:null===(u=null==checkoutState?void 0:checkoutState.checkout)||void 0===u?void 0:u.currency,trialDurationDays:null===(c=null==e?void 0:e.price)||void 0===c?void 0:c.trial_duration_days,interval:!!(null==e?void 0:e.price)&&intervalString(null==e?void 0:e.price,{showOnce:hasSubscription(null==checkoutState?void 0:checkoutState.checkout)}),onScUpdateQuantity:t=>updateCheckoutLineItem({id:e.id,data:{quantity:t.detail}}),onScRemove:()=>removeCheckoutLineItem(null==e?void 0:e.id),exportparts:"base:line-item, product-line-item, image:line-item__image, text:line-item__text, title:line-item__title, suffix:line-item__suffix, price:line-item__price, price__amount:line-item__price-amount, price__description:line-item__price-description, price__scratch:line-item__price-scratch, static-quantity:line-item__static-quantity, remove-icon__base:line-item__remove-icon, quantity:line-item__quantity, quantity__minus:line-item__quantity-minus, quantity__minus-icon:line-item__quantity-minus-icon, quantity__plus:line-item__quantity-plus, quantity__plus-icon:line-item__quantity-plus-icon, quantity__input:line-item__quantity-input, line-item__price-description:line-item__price-description"}))})))}static get is(){return"sc-line-items"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-line-items.css"]}}static get styleUrls(){return{$:["sc-line-items.css"]}}static get properties(){return{editable:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Is the line item editable?"},attribute:"editable",reflect:!1},removable:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Is the line item removable?"},attribute:"removable",reflect:!1}}}}