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__title {\n  display: -webkit-box;\n  -webkit-box-orient: vertical;\n  -webkit-line-clamp: 2;\n  line-clamp: 2;\n  overflow: hidden;\n  text-overflow: ellipsis;\n  word-break: break-word;\n}\n.bump__product-title {\n  font-weight: var(--sc-font-weight-semibold);\n  display: -webkit-box;\n  -webkit-box-orient: vertical;\n  -webkit-line-clamp: 2;\n  line-clamp: 2;\n  overflow: hidden;\n  text-overflow: ellipsis;\n  word-break: break-word;\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 e,i,n;return null===(n=null===(i=null===(e=null==state?void 0:state.checkout)||void 0===e?void 0:e.line_items)||void 0===i?void 0:i.data)||void 0===n?void 0:n.find((e=>{var i;return(null==e?void 0:e.bump)===(null===(i=this.bump)||void 0===i?void 0:i.id)}))}updateLineItem(){var e,i,n,t;const o=(null===(e=this.bump.price)||void 0===e?void 0:e.id)||(null===(i=this.bump)||void 0===i?void 0:i.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 e;trackOrderBump(null===(e=this.bump)||void 0===e?void 0:e.id)}newPrice(){var e,i,n,t,o,a;let r=null,s=(null===(i=null===(e=this.bump)||void 0===e?void 0:e.price)||void 0===i?void 0:i.amount)||0;if((null===(n=this.bump)||void 0===n?void 0:n.amount_off)&&(r=Math.max(0,s-(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 e=s*((null===(a=this.bump)||void 0===a?void 0:a.percent_off)/100);r=Math.max(0,s-e)}return r}renderInterval(){var e;const i=intervalString(null===(e=this.bump)||void 0===e?void 0:e.price,{labels:{interval:"/",period:wp.i18n.__("for","surecart")}});return i.trim().length?h("span",{class:"bump__interval"},i):null}renderPrice(){var e,i,n,t,o,a,r,s,d;return h("div",{slot:"description",class:{bump__price:!0,"bump__price--has-discount":!!(null===(e=this.bump)||void 0===e?void 0:e.percent_off)||!!(null===(i=this.bump)||void 0===i?void 0:i.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===(a=this.bump)||void 0===a?void 0:a.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===(s=this.bump)||void 0===s?void 0:s.total_amount)>0&&h("span",{class:"bump__new-price"},null===(d=this.bump)||void 0===d?void 0:d.total_display_amount),this.renderInterval())))}renderDiscount(){var e,i,n,t,o;if(null===(e=this.bump)||void 0===e?void 0:e.amount_off)return 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===(i=this.bump)||void 0===i?void 0:i.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));if(null===(o=this.bump)||void 0===o?void 0:o.percent_off){const e=`${this.bump.percent_off}%`;return h("div",{class:"bump__tag","aria-label":
/** translators: %s is the discount percentage (e.g. "10%"). */
wp.i18n.sprintf(wp.i18n.__("You save %s.","surecart"),e)},h("span",{"aria-hidden":"true"},wp.i18n.sprintf(
/** translators: %s is the discount percentage (e.g. "10%"). */
wp.i18n._x("Save %s","Save money","surecart"),e)))}}render(){var e,i,n,t,o,a,r,s,d,l,c,u,p,m,v,b,_,f;const g=null===(i=null===(e=this.bump)||void 0===e?void 0:e.price)||void 0===i?void 0:i.product;return h("sc-choice",{key:"05bb127936345059e4a693ffb801f1d6f379b236",value:null===(n=this.bump)||void 0===n?void 0:n.id,type:"checkbox",showControl:this.showControl,checked:!!this.lineItem(),onClick:e=>{e.preventDefault(),e.stopImmediatePropagation(),this.updateLineItem()},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),e.stopImmediatePropagation(),this.updateLineItem())},exportparts:"base, control, checked-icon, title"},h("div",{key:"631d30b5e3653656c7931271bf75a3cd202aa04f",part:"base-content",class:"bump"},h("div",{key:"10f22d4a4189c1a1a308c736c4b6e55d58cc0168",class:"bump__text"},h("div",{key:"ce19233d17e2760f9316c78c15f4f36a052bbd0c",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===(a=this.bump)||void 0===a?void 0:a.name)||(null==g?void 0:g.name))},h("span",{key:"e8b7c15c9b778ac317f7543d174af16f6eaa3851","aria-hidden":"true"},(null===(s=null===(r=this.bump)||void 0===r?void 0:r.metadata)||void 0===s?void 0:s.cta)||(null===(d=this.bump)||void 0===d?void 0:d.name)||(null==g?void 0:g.name))),h("div",{key:"bfbec3b44de2eec1db920bb02ab4dc9ffe748629",class:"bump__amount"},this.renderPrice(),this.renderDiscount()))),(null===(c=null===(l=this.bump)||void 0===l?void 0:l.metadata)||void 0===c?void 0:c.description)&&h("div",{key:"9ec1e3641218dfe944a6be2371c71e3012470ce6",slot:"footer",class:"bump__product--wrapper"},h("sc-divider",{key:"3c7dc55682f85184d55abbb968ba3da807b894a4",style:{"--spacing":"var(--sc-spacing-medium)"}}),h("div",{key:"369ec1658d2a6fca96c474c8a5b77a23f7a8e09d",class:"bump__product"},!!(null===(u=null==g?void 0:g.line_item_image)||void 0===u?void 0:u.src)&&h("img",{key:"a52a16131bf388ae077d1f08975ac016919ca577",...null==g?void 0:g.line_item_image,class:"bump__image"}),h("div",{key:"b25efd0119129c0b333f209aec14cae92419d225",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:"0944412683e898b10ff10dff88d88a0663efdc95",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:"05e8ce6ea11990b1a8be39c290a80dd499a46032",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:"30986f3ce04ac536b55660e021af758634886ca7","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((e=>{switch(e){case"sc-order-bump":customElements.get(e)||customElements.define(e,ScOrderBump);break;case"sc-choice":customElements.get(e)||defineCustomElement$2();break;case"sc-divider":customElements.get(e)||defineCustomElement$1()}}))}export{ScOrderBump as S,defineCustomElement as d};