import{h}from"@stencil/core";import{state as checkoutState}from"../../../../store/checkout/index";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 i;return!((null===(i=null==e?void 0:e.price)||void 0===i?void 0:i.ad_hoc)||(null==e?void 0:e.bump_amount)||(null==e?void 0:e.locked))&&this.editable}render(){var e,i,t,l,o;if(formBusy()&&!(null===(t=null===(i=null===(e=null==checkoutState?void 0:checkoutState.checkout)||void 0===e?void 0:e.line_items)||void 0===i?void 0:i.data)||void 0===t?void 0:t.length))return 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"}));const n=((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)||[]).sort(((e,i)=>{const t=(null==e?void 0:e.is_swappable)?1:0;return((null==i?void 0:i.is_swappable)?1:0)-t}));return h("div",{class:"line-items",part:"base",tabindex:"0"},n.map((e=>{var i,t,l,o,n,a,s,r;const u=getMaxStockQuantity(null===(i=null==e?void 0:e.price)||void 0===i?void 0:i.product,null==e?void 0:e.variant);return h("div",{class:"line-item "+((null==e?void 0:e.is_swappable)?"line-item--has-swap":"")},h("sc-product-line-item",{key:e.id,image:null==e?void 0:e.image,name:null===(l=null===(t=null==e?void 0:e.price)||void 0===t?void 0:t.product)||void 0===l?void 0:l.name,price:null===(o=null==e?void 0:e.price)||void 0===o?void 0:o.name,variant:null==e?void 0:e.variant_display_options,fees:null===(n=null==e?void 0:e.fees)||void 0===n?void 0:n.data,amount:e.ad_hoc_display_amount?e.ad_hoc_display_amount:e.subtotal_display_amount,scratch:e.ad_hoc_display_amount?null:null==e?void 0:e.scratch_display_amount,trial:null===(a=null==e?void 0:e.price)||void 0===a?void 0:a.trial_text,interval:`${null===(s=null==e?void 0:e.price)||void 0===s?void 0:s.short_interval_text} ${null===(r=null==e?void 0:e.price)||void 0===r?void 0:r.short_interval_count_text}`,quantity:e.quantity,purchasableStatus:null==e?void 0:e.purchasable_status_display,note:null==e?void 0:e.display_note,...u?{max:u}:{},editable:this.isEditable(e),removable:!(null==e?void 0:e.locked)&&this.removable,onScUpdateQuantity:i=>updateCheckoutLineItem({id:e.id,data:{quantity:i.detail}}),onScRemove:()=>removeCheckoutLineItem(null==e?void 0:e.id),exportparts:"base:line-item, product-line-item, image:line-item__image, placeholder__image: line-item__placeholder-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"}),h("sc-swap",{lineItem:e}))})))}static get is(){return"sc-line-items"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-line-items.scss"]}}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}}}}