import{r as i,c as s,h as o}from"./p-b891c2f1.js";import{_ as t}from"./p-684c85b4.js";import"./p-aafd8ea4.js";import{g as l}from"./p-936390dd.js";import"./p-112455b1.js";const n=class{constructor(o){i(this,o),this.scApplyCoupon=s(this,"scApplyCoupon",7)}handleOpenChange(i){i&&setTimeout((()=>this.input.triggerFocus()),50)}handleBlur(){this.input.value||(this.open=!1,this.error="")}applyCoupon(){this.scApplyCoupon.emit(this.input.value.toUpperCase())}render(){var i,s,n,e,r,a;if(this.loading)return o("sc-skeleton",{style:{width:"120px",display:"inline-block"}});if(null===(s=null===(i=null==this?void 0:this.discount)||void 0===i?void 0:i.promotion)||void 0===s?void 0:s.code){let i="";return(null===(n=null==this?void 0:this.discount)||void 0===n?void 0:n.coupon)&&(i=l(null===(e=null==this?void 0:this.discount)||void 0===e?void 0:e.coupon)),o("sc-line-item",null,o("span",{slot:"description"},o("div",null,t("Discount")),o("sc-tag",{type:"success",class:"coupon-tag",clearable:!0,onScClear:()=>{this.scApplyCoupon.emit(null),this.open=!1}},null===(a=null===(r=null==this?void 0:this.discount)||void 0===r?void 0:r.promotion)||void 0===a?void 0:a.code)),i&&o("span",{class:"coupon-human-discount",slot:"price-description"},"(",i,")"),o("span",{slot:"price"},o("sc-format-number",{type:"currency",currency:null==this?void 0:this.currency,value:null==this?void 0:this.discountAmount})))}return o("div",{class:{"coupon-form":!0,"coupon-form--is-open":this.open||this.forceOpen}},o("div",{class:"trigger",onMouseDown:()=>{this.open||(this.open=!0)}},o("slot",{name:"label"},this.label)),o("div",{class:"form"},o("sc-input",{onScBlur:()=>this.handleBlur(),ref:i=>this.input=i,clearable:!0}),!!this.error&&o("sc-alert",{type:"danger",open:!0},o("span",{slot:"title"},this.error)),o("sc-button",{type:"primary",loading:this.busy,full:!0,onClick:()=>this.applyCoupon()},o("slot",null))),this.loading&&o("sc-block-ui",null))}static get watchers(){return{open:["handleOpenChange"]}}};n.style=":host{display:block}.coupon-form{position:relative}.form{opacity:0;visibility:hidden;height:0;transition:opacity var(--sc-transition-fast) ease-in-out}.coupon-form--is-open .form{opacity:1;visibility:visible;height:auto;margin-top:var(--sc-spacing-small);display:grid;gap:var(--sc-spacing-small)}.coupon-form--is-open .trigger{color:var(--sc-input-label-color)}.coupon-form--is-open .trigger:hover{text-decoration:none}.trigger{cursor:pointer;font-size:var(--sc-font-size-small);color:var(--sc-input-label-color);user-select:none}.trigger:hover{text-decoration:underline}";export{n as sc_coupon_form}