import{h}from"@stencil/core";import{state as checkoutState}from"../../../../store/checkout/index";import{toggleSwap}from"../../../../services/session/index";import{updateFormState}from"../../../../store/form/mutations";import{createErrorNotice}from"../../../../store/notices/mutations";export class ScSwap{constructor(){this.lineItem=void 0}async onSwapToggleChange(t){var e;try{updateFormState("FETCH"),checkoutState.checkout=await toggleSwap({id:null===(e=this.lineItem)||void 0===e?void 0:e.id,action:t.target.checked?"swap":"unswap"}),updateFormState("RESOLVE")}catch(t){updateFormState("REJECT"),createErrorNotice(t.message),console.error(t)}}render(){var t,e,i,o,s;if(!(null===(t=null==this?void 0:this.lineItem)||void 0===t?void 0:t.is_swappable))return null;const r=(null===(e=null==this?void 0:this.lineItem)||void 0===e?void 0:e.swap)||(null===(o=null===(i=null==this?void 0:this.lineItem)||void 0===i?void 0:i.price)||void 0===o?void 0:o.current_swap),n=(null==r?void 0:r.swap_price)||this.lineItem.price;return h("div",{class:"swap"},h("sc-switch",{checked:!!(null===(s=null==this?void 0:this.lineItem)||void 0===s?void 0:s.swap),onScChange:t=>this.onSwapToggleChange(t)},null==r?void 0:r.description),!!(null==n?void 0:n.display_amount)&&h("div",{class:"swap__price"},null==n?void 0:n.display_amount," ",null==n?void 0:n.short_interval_text," ",null==n?void 0:n.short_interval_count_text))}static get is(){return"sc-swap"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-swap.scss"]}}static get styleUrls(){return{$:["sc-swap.css"]}}static get properties(){return{lineItem:{type:"unknown",mutable:!1,complexType:{original:"LineItem",resolved:"LineItem",references:{LineItem:{location:"import",path:"../../../../types",id:"src/types.ts::LineItem"}}},required:!1,optional:!1,docs:{tags:[],text:"The product id."}}}}}