import{proxyCustomElement,HTMLElement,h,Host}from"@stencil/core/internal/client";import{s as state}from"./mutations2.js";import{l as lockCheckout,b as unLockCheckout}from"./mutations4.js";import{d as createOrUpdateCheckout}from"./index5.js";import{c as checkoutIsLocked}from"./getters2.js";import{c as createErrorNotice}from"./mutations3.js";import{s as speak}from"./index2.js";import{g as getFormattedPrice}from"./price.js";import{d as defineCustomElement$6}from"./sc-block-ui2.js";import{d as defineCustomElement$5}from"./sc-form-control2.js";import{d as defineCustomElement$4}from"./sc-radio2.js";import{d as defineCustomElement$3}from"./sc-radio-group2.js";import{d as defineCustomElement$2}from"./sc-spinner2.js";import{d as defineCustomElement$1}from"./sc-visually-hidden2.js";const scShippingChoicesCss=":host{display:block}.shipping-choice{width:100%;padding:var(--sc-spacing-medium);margin:0;box-sizing:border-box;border-bottom:var(--sc-input-border, 1px solid var(--sc-color-gray-300));background-color:var(--sc-shipping-choice-background-color, var(--sc-input-background-color))}.shipping-choice__empty{background:var(--sc-alert-background-color, var(--sc-color-gray-100));opacity:0.75;padding:var(--sc-spacing-large);border-radius:var(--sc-input-border-radius-medium);line-height:var(--sc-line-height-dense);font-size:var(--sc-font-size-small);border:solid 1px var(--sc-input-border-color, var(--sc-input-border))}.shipping-choice:last-child{border-bottom-width:0}.shipping-choice__text{display:flex;flex-direction:column;gap:var(--sc-spacing-xx-small)}.shipping-choice__price{color:var(--sc-input-label-color);font-weight:var(--sc-price-choice-price-font-weight, var(--sc-font-weight-normal));white-space:nowrap;display:var(--sc-shipping-choice-price-display, inherit)}.shipping-choice__name{display:inline-block;color:var(--sc-price-choice-name-color, var(--sc-input-label-color));font-size:var(--sc-price-choice-name-size, var(--sc-input-label-font-size-medium));font-weight:var(--sc-price-choice-name-font-weight, var(--sc-font-weight-bold));text-transform:var(--sc-price-choice-text-transform, var(--sc-input-label-text-transform, none));line-height:var(--sc-shipping-name-line-height, 1)}.shipping-choice__description{color:var(--sc-input-label-color);font-weight:var(--sc-price-choice-price-font-weight, var(--sc-font-weight-normal));line-height:var(--sc-shipping-description-line-height, 1.2)}sc-radio-group::part(items){border:var(--sc-input-border, 1px solid var(--sc-color-gray-300));border-radius:var(--sc-shipping-choice-border-radius, var(--sc-input-border-radius-medium));box-shadow:var(--sc-shipping-box-shadow, var(--sc-input-box-shadow));overflow:hidden;position:relative}sc-radio::part(base){width:100%}sc-radio::part(label){width:100%;display:flex;justify-content:space-between;gap:var(--sc-spacing-small)}sc-radio-group::slotted(sc-radio:not(:last-of-type)){margin-bottom:0}",ScShippingChoicesStyle0=scShippingChoicesCss,ScShippingChoices=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.label=void 0,this.showDescription=!0,this.shippingChoices=void 0}async updateCheckout(e){if(e)try{lockCheckout("selected_shipping_choice"),state.checkout=await createOrUpdateCheckout({id:state.checkout.id,data:{selected_shipping_choice_id:e}}),speak(wp.i18n.__("Shipping choice updated.","surecart"),"assertive");const{total_amount:i,currency:s}=state.checkout;
/** translators: %1$s: formatted amount */speak(wp.i18n.sprintf(wp.i18n.__("Your order total has changed to: %1$s.","surecart"),getFormattedPrice({amount:i,currency:s})),"assertive")}catch(e){console.error(e),createErrorNotice(e)}finally{unLockCheckout("selected_shipping_choice")}}render(){var e,i,s,o,c;const t=this.shippingChoices||(null===(i=null===(e=null==state?void 0:state.checkout)||void 0===e?void 0:e.shipping_choices)||void 0===i?void 0:i.data);if(!this.shippingChoices){if(!(null===(s=null==state?void 0:state.checkout)||void 0===s?void 0:s.selected_shipping_choice_required))return h(Host,{style:{display:"none"}});if(!(null==t?void 0:t.length)&&!(null===(c=null===(o=null==state?void 0:state.checkout)||void 0===o?void 0:o.shipping_address)||void 0===c?void 0:c.country))return h("sc-form-control",{label:this.label||wp.i18n.__("Shipping","surecart")},h("div",{class:"shipping-choice__empty"},wp.i18n.__("To check available shipping choices, please provide your shipping country in the address section.","surecart")));if(!(null==t?void 0:t.length))return h("sc-form-control",{part:"empty",label:this.label||wp.i18n.__("Shipping","surecart")},h("div",{class:"shipping-choice__empty"},wp.i18n.__("Sorry, we are not able to ship to your address.","surecart")))}return h(Host,null,h("sc-radio-group",{part:"base",label:this.label||wp.i18n.__("Shipping","surecart"),class:"shipping-choices",onScChange:e=>this.updateCheckout(e.detail)},(t||[]).map((({id:e,display_amount:i,shipping_method:s})=>{var o;return h("sc-radio",{key:e,checked:(null===(o=null==state?void 0:state.checkout)||void 0===o?void 0:o.selected_shipping_choice)===e,exportparts:"base:radio__base,label:radio__label,control:radio__control,checked-icon:radio__checked-icon",class:"shipping-choice",value:e},h("div",{class:"shipping-choice__text"},h("div",{class:"shipping-choice__name"},(null==s?void 0:s.name)||wp.i18n.__("Standard Shipping","surecart")),this.showDescription&&!!(null==s?void 0:s.description)&&h("div",{class:"shipping-choice__description"},null==s?void 0:s.description)),h("div",{class:"shipping-choice__price"},i||wp.i18n.__("Free","surecart")))}))),checkoutIsLocked("selected_shipping_choice")&&h("sc-block-ui",null))}static get style(){return ScShippingChoicesStyle0}},[1,"sc-shipping-choices",{label:[1],showDescription:[4,"show-description"],shippingChoices:[16]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-shipping-choices","sc-block-ui","sc-form-control","sc-radio","sc-radio-group","sc-spinner","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-shipping-choices":customElements.get(e)||customElements.define(e,ScShippingChoices);break;case"sc-block-ui":customElements.get(e)||defineCustomElement$6();break;case"sc-form-control":customElements.get(e)||defineCustomElement$5();break;case"sc-radio":customElements.get(e)||defineCustomElement$4();break;case"sc-radio-group":customElements.get(e)||defineCustomElement$3();break;case"sc-spinner":customElements.get(e)||defineCustomElement$2();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$1()}}))}export{ScShippingChoices as S,defineCustomElement as d};