import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import{s as speak}from"./index2.js";import{i as intervalString}from"./price.js";import{s as state}from"./mutations2.js";import{r as removeCheckoutLineItem,a as addCheckoutLineItem,t as trackOrderBump}from"./mutations4.js";import{d as defineCustomElement$2}from"./sc-choice2.js";import{d as defineCustomElement$1}from"./sc-divider2.js";const scOrderBumpCss=":host {\n  display: block;\n}\n\n.bump {\n  display: grid;\n  gap: 1em;\n}\n.bump__text {\n  display: grid;\n  gap: 0.25em;\n}\n.bump__tag {\n  background: var(--sc-color-primary-500);\n  color: var(--sc-color-white);\n  border-radius: var(--sc-input-border-radius-medium);\n  padding: var(--sc-spacing-x-small);\n  font-size: var(--sc-font-size-x-small);\n}\n.bump__product {\n  display: flex;\n  align-items: center;\n  gap: var(--sc-choice-padding, 1.3em 1.1em);\n  line-height: var(--sc-line-height-dense);\n}\n.bump__product--wrapper {\n  container-type: inline-size;\n}\n@container (max-width: 325px) {\n  .bump__product {\n    flex-direction: column;\n    align-items: start;\n  }\n}\n.bump__product-title {\n  font-weight: var(--sc-font-weight-semibold);\n}\n.bump__product-description {\n  color: var(--sc-input-label-color);\n}\n.bump__image {\n  width: var(--sc-product-line-item-image-size, 4em);\n  height: var(--sc-product-line-item-image-size, 4em);\n  flex: 0 0 var(--sc-product-line-item-image-size, 4em);\n  object-fit: cover;\n  border-radius: 4px;\n  border: 1px solid var(--sc-color-gray-200);\n  display: block;\n  box-shadow: var(--sc-input-box-shadow);\n}\n.bump__price--has-discount {\n  display: flex;\n  align-items: baseline;\n  gap: var(--sc-spacing-x-small);\n}\n.bump__price--has-discount .bump__original-price {\n  text-decoration: line-through;\n  color: var(--sc-color-gray-500);\n  font-size: var(--sc-font-size-small);\n}\n.bump__price .bump__new-price {\n  font-size: var(--sc-font-size-large);\n  color: var(--sc-color-gray-700);\n}\n.bump__price .bump__interval {\n  color: var(--sc-color-gray-500);\n}\n.bump__amount {\n  display: flex;\n  align-items: center;\n  gap: var(--sc-spacing-x-small);\n  flex-wrap: wrap;\n  margin-top: var(--sc-spacing-xx-small);\n}",ScOrderBumpStyle0=scOrderBumpCss,ScOrderBump=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.bump=void 0,this.showControl=void 0}lineItem(){var i,e,n;return null===(n=null===(e=null===(i=null==state?void 0:state.checkout)||void 0===i?void 0:i.line_items)||void 0===e?void 0:e.data)||void 0===n?void 0:n.find((i=>{var e;return(null==i?void 0:i.bump)===(null===(e=this.bump)||void 0===e?void 0:e.id)}))}updateLineItem(){var i,e,n,t;const o=(null===(i=this.bump.price)||void 0===i?void 0:i.id)||(null===(e=this.bump)||void 0===e?void 0:e.price);if(this.lineItem())return removeCheckoutLineItem(null===(n=this.lineItem())||void 0===n?void 0:n.id),void speak(wp.i18n.__("Order bump Removed.","surecart"));addCheckoutLineItem({bump:null===(t=this.bump)||void 0===t?void 0:t.id,price:o,quantity:1}),speak(wp.i18n.__("Order bump applied.","surecart"))}componentDidLoad(){var i;trackOrderBump(null===(i=this.bump)||void 0===i?void 0:i.id)}newPrice(){var i,e,n,t,o,d;let r=null,a=(null===(e=null===(i=this.bump)||void 0===i?void 0:i.price)||void 0===e?void 0:e.amount)||0;if((null===(n=this.bump)||void 0===n?void 0:n.amount_off)&&(r=Math.max(0,a-(null===(t=this.bump)||void 0===t?void 0:t.amount_off))),null===(o=this.bump)||void 0===o?void 0:o.percent_off){const i=a*((null===(d=this.bump)||void 0===d?void 0:d.percent_off)/100);r=Math.max(0,a-i)}return r}renderInterval(){var i;const e=intervalString(null===(i=this.bump)||void 0===i?void 0:i.price,{labels:{interval:"/",period:wp.i18n.__("for","surecart")}});return e.trim().length?h("span",{class:"bump__interval"},e):null}renderPrice(){var i,e,n,t,o,d,r,a,s;return h("div",{slot:"description",class:{bump__price:!0,"bump__price--has-discount":!!(null===(i=this.bump)||void 0===i?void 0:i.percent_off)||!!(null===(e=this.bump)||void 0===e?void 0:e.amount_off)},part:"price"},!(!(null===(n=this.bump)||void 0===n?void 0:n.percent_off)&&!(null===(t=this.bump)||void 0===t?void 0:t.amount_off))&&h("span",{"aria-label":
/** translators: %s: old price */
wp.i18n.sprintf(wp.i18n.__("Originally priced at %s.","surecart"),null===(o=this.bump)||void 0===o?void 0:o.subtotal_display_amount),class:"bump__original-price"},null===(d=this.bump)||void 0===d?void 0:d.subtotal_display_amount),h("span",null,h("span",{"aria-hidden":"true"},0===(null===(r=this.bump)||void 0===r?void 0:r.total_amount)&&wp.i18n.__("Free","surecart"),(null===(a=this.bump)||void 0===a?void 0:a.total_amount)>0&&h("span",{class:"bump__new-price"},null===(s=this.bump)||void 0===s?void 0:s.total_display_amount),this.renderInterval())))}renderDiscount(){var i,e,n,t,o,d,r;return(null===(i=this.bump)||void 0===i?void 0:i.amount_off)?h("div",{class:"bump__tag","aria-label":
/** translators: %1$s: amount off, %2$s: currency */
wp.i18n.sprintf(wp.i18n.__("You save %1$s%2$s.","surecart"),null===(e=this.bump)||void 0===e?void 0:e.amount_off,(null===(n=this.bump)||void 0===n?void 0:n.price).currency)},h("span",{"aria-hidden":"true"},wp.i18n._x("Save","Save money","surecart")," ",null===(t=this.bump)||void 0===t?void 0:t.amount_off_display_amount)):(null===(o=this.bump)||void 0===o?void 0:o.percent_off)?h("div",{class:"bump__tag","aria-label":
/** translators: %s: amount percent off */
wp.i18n.sprintf(wp.i18n.__("You save %s%%.","surecart"),null===(d=this.bump)||void 0===d?void 0:d.percent_off)},h("span",{"aria-hidden":"true"},wp.i18n.sprintf(
/** translators: %s: amount percent off */
wp.i18n._x("Save %s%%","Save money","surecart"),null===(r=this.bump)||void 0===r?void 0:r.percent_off))):void 0}render(){var i,e,n,t,o,d,r,a,s,l,u,c,p,m,v,b,_,f;const g=null===(e=null===(i=this.bump)||void 0===i?void 0:i.price)||void 0===e?void 0:e.product;return h("sc-choice",{key:"983d78c5de4e40b4d66f6e755e49000c3ba2e07f",value:null===(n=this.bump)||void 0===n?void 0:n.id,type:"checkbox",showControl:this.showControl,checked:!!this.lineItem(),onClick:i=>{i.preventDefault(),i.stopImmediatePropagation(),this.updateLineItem()},onKeyDown:i=>{"Enter"!==i.key&&" "!==i.key||(i.preventDefault(),i.stopImmediatePropagation(),this.updateLineItem())},exportparts:"base, control, checked-icon, title"},h("div",{key:"54a1819dbbfc23855d4a0920cd853973077fcb58",part:"base-content",class:"bump"},h("div",{key:"6261d9ede9267a35093f1271bcf48c98840cd605",class:"bump__text"},h("div",{key:"8eb1bd33b2592dc8358720b53ca3640bd03fd8b0",class:"bump__title","aria-label":wp.i18n.sprintf(
/* translators: %s: order bump name */
wp.i18n.__("Product: %s.","surecart"),(null===(o=null===(t=this.bump)||void 0===t?void 0:t.metadata)||void 0===o?void 0:o.cta)||(null===(d=this.bump)||void 0===d?void 0:d.name)||(null==g?void 0:g.name))},h("span",{key:"fd3214f1fc3f0e0bdd909d92d96339cc2a1b86a4","aria-hidden":"true"},(null===(a=null===(r=this.bump)||void 0===r?void 0:r.metadata)||void 0===a?void 0:a.cta)||(null===(s=this.bump)||void 0===s?void 0:s.name)||(null==g?void 0:g.name))),h("div",{key:"ef1e4657efc6dc4755641de2154d49e405f4d484",class:"bump__amount"},this.renderPrice(),this.renderDiscount()))),(null===(u=null===(l=this.bump)||void 0===l?void 0:l.metadata)||void 0===u?void 0:u.description)&&h("div",{key:"2e3a416ed1918562a4c1f49113cba05729b87ec3",slot:"footer",class:"bump__product--wrapper"},h("sc-divider",{key:"4d06a09e82fd1ecd41c01bdb048c5a76b0e33d69",style:{"--spacing":"var(--sc-spacing-medium)"}}),h("div",{key:"38c660a40700423b3f3a727f1db8f164a736daeb",class:"bump__product"},!!(null===(c=null==g?void 0:g.line_item_image)||void 0===c?void 0:c.src)&&h("img",{key:"df9c423d1eceadc3e61bc3530ae79c8bbb44a684",...null==g?void 0:g.line_item_image,class:"bump__image"}),h("div",{key:"0698bdcb6b3029cdccb97c5e7dc356cd60d3dab9",class:"bump__product-text"},!!(null===(m=null===(p=this.bump)||void 0===p?void 0:p.metadata)||void 0===m?void 0:m.cta)&&h("div",{key:"6f717ff6352c7fc1c48a4e29a934435bbb9406f1",class:"bump__product-title","aria-hidden":"true"},this.bump.name||(null==g?void 0:g.name)),!!(null===(b=null===(v=this.bump)||void 0===v?void 0:v.metadata)||void 0===b?void 0:b.description)&&h("div",{key:"4747ed4352a726279216fe07b174fd446b69b165",class:"bump__product-description","aria-label":wp.i18n.sprintf(
/* translators: %s: Product description */
wp.i18n.__("Product description: %s.","surecart"),null===(_=this.bump)||void 0===_?void 0:_.rendered_description)},h("span",{key:"f863722bbe36276c26bc2da9f0381f8917f800f6","aria-hidden":"true",innerHTML:null===(f=this.bump)||void 0===f?void 0:f.rendered_description}))))))}static get style(){return ScOrderBumpStyle0}},[1,"sc-order-bump",{bump:[16],showControl:[516,"show-control"]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-order-bump","sc-choice","sc-divider"].forEach((i=>{switch(i){case"sc-order-bump":customElements.get(i)||customElements.define(i,ScOrderBump);break;case"sc-choice":customElements.get(i)||defineCustomElement$2();break;case"sc-divider":customElements.get(i)||defineCustomElement$1()}}))}export{ScOrderBump as S,defineCustomElement as d};