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(t){var e;return!((null===(e=null==t?void 0:t.price)||void 0===e?void 0:e.ad_hoc)||(null==t?void 0:t.bump_amount)||(null==t?void 0:t.locked))&&this.editable}render(){var t,e,i,l,o;return formBusy()&&!(null===(i=null===(e=null===(t=null==checkoutState?void 0:checkoutState.checkout)||void 0===t?void 0:t.line_items)||void 0===e?void 0:e.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((t=>{var e,i,l,o,n,a,u,c;const s=getMaxStockQuantity(null===(e=null==t?void 0:t.price)||void 0===e?void 0:e.product,null==t?void 0:t.variant);return h("div",{class:"line-item"},h("sc-product-line-item",{key:t.id,image:null==t?void 0:t.image,name:null===(l=null===(i=null==t?void 0:t.price)||void 0===i?void 0:i.product)||void 0===l?void 0:l.name,priceName:null===(o=null==t?void 0:t.price)||void 0===o?void 0:o.name,variantLabel:((null==t?void 0:t.variant_options)||[]).filter(Boolean).join(" / ")||null,purchasableStatusDisplay:null==t?void 0:t.purchasable_status_display,...s?{max:s}:{},editable:this.isEditable(t),removable:!(null==t?void 0:t.locked)&&this.removable,quantity:t.quantity,fees:null===(n=null==t?void 0:t.fees)||void 0===n?void 0:n.data,setupFeeTrialEnabled:null===(a=null==t?void 0:t.price)||void 0===a?void 0:a.setup_fee_trial_enabled,amount:null!==t.ad_hoc_amount?t.ad_hoc_amount:t.subtotal_amount,scratchAmount:null==t.ad_hoc_amount&&(null==t?void 0:t.scratch_amount),scratchDisplayAmount:null==t?void 0:t.scratch_display_amount,currency:null===(u=null==checkoutState?void 0:checkoutState.checkout)||void 0===u?void 0:u.currency,displayAmount:null!==t.ad_hoc_amount?t.ad_hoc_display_amount:t.subtotal_display_amount,trialDurationDays:null===(c=null==t?void 0:t.price)||void 0===c?void 0:c.trial_duration_days,interval:!!(null==t?void 0:t.price)&&intervalString(null==t?void 0:t.price,{showOnce:hasSubscription(null==checkoutState?void 0:checkoutState.checkout)}),onScUpdateQuantity:e=>updateCheckoutLineItem({id:t.id,data:{quantity:e.detail}}),onScRemove:()=>removeCheckoutLineItem(null==t?void 0:t.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}}}}