1import{a as t}from"./BaseElement.wji90fuE.min.js";import{t as e,h as a,s as r,x as n,T as s}from"./vendor-lit.2u3dzq2T.min.js";Object.getOwnPropertyDescriptor;const i=/^(\d{4})-(\d{2})-(\d{2})/;let l=class extends t{constructor(){super(...arguments),this.fetchGiftCardBalanceTask=new a(this,{task:async([t])=>{const e=await this.lookupBalanceViaProxy(t);if("found"===e.status)return e.balance;throw new Error("not_found"===e.status?this.notFoundMessage:this.unavailableMessage)},autoRun:!1})}get proxyBase(){return window.__T1_PROXY_BASE__||"/apps/talonone-proxy/api/public"}get notFoundMessage(){return this.getAttribute("data-not-found-message")||"Gift card not found"}get unavailableMessage(){return this.getAttribute("data-unavailable-message")||"We couldn't check that balance right now. Please try again."}get expiryLabel(){return this.getAttribute("data-expiry-label")||"Expires %s"}get expiredLabel(){return this.getAttribute("data-expired-label")||"Expired"}get expiryDateFormat(){return this.getAttribute("data-expiry-date-format")||"long"}async lookupBalanceViaProxy(t){var e;let a,r;try{a=await fetch(`${this.proxyBase}/gift-cards/balance`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({code:t}),signal:AbortSignal.timeout(5e3)})}catch(o){return{status:"unavailable"}}if(!a.ok)return{status:"unavailable"};try{r=await a.json()}catch(o){return{status:"unavailable"}}const n=null==(e=null==r?void 0:r.cards)?void 0:e[0];if(!n)return{status:"not_found"};if(!n.balanceCurrency||!n.balanceAmount||Number.isNaN(Number(n.balanceAmount)))return{status:"unavailable"};if(!n.enabled)return{status:"not_found"};const s=null===n.expiresOn?null:function(t){const e=i.exec(t);if(!e)return null;const[,a,r,n]=e.map(Number),s=new Date(a,r-1,n);return s.getMonth()!==r-1||s.getDate()!==n?null:s}(n.expiresOn);if(null!==n.expiresOn&&null===s)return{status:"unavailable"};const l=new Date;l.setHours(0,0,0,0);const u=null!==s&&s<l;return{status:"found",balance:{amount:u?"0":n.balanceAmount,currencyCode:n.balanceCurrency,expiresOn:s,expired:u}}}async handleSubmit(t){if(t.preventDefault(),this.fetchGiftCardBalanceTask.status===r.PENDING)return;const e=t.target,a=new FormData(e).get("code");a&&""!==a.trim()&&await this.fetchGiftCardBalanceTask.run([a.trim()])}get resultHTML(){let t=s;if(this.fetchGiftCardBalanceTask.status===r.PENDING&&(t=n`<p class="body-xs">Loading...</p>`),this.fetchGiftCardBalanceTask.status===r.ERROR&&(t=n`<p class="body-xs text-u-error"> 2 ${this.fetchGiftCardBalanceTask.error.message} 3 </p>`),this.fetchGiftCardBalanceTask.status===r.COMPLETE&&this.fetchGiftCardBalanceTask.value){const e=this.fetchGiftCardBalanceTask.value,a=this.getAttribute("data-locale")||"en-US",r=new Intl.NumberFormat(a,{style:"currency",currency:e.currencyCode}).format(parseFloat(e.amount)),i=e.expiresOn?new Intl.DateTimeFormat(a,"numeric"===this.expiryDateFormat?{day:"2-digit",month:"2-digit",year:"numeric"}:{day:"numeric",month:"long",year:"numeric"}).format(e.expiresOn):null;t=n` 4 <div class="subtitle-md">Your Balance</div> 5 <div class="heading-xl">${r}</div> 6 ${i?n`<p class="body-sm"> 7 ${this.expiryLabel.replace("%s",i)} 8 </p>`:s} 9 ${e.expired?n`<p class="body-sm">${this.expiredLabel}</p>`:s} 10 `}return n`<div 11 role="status" 12 class="flex flex-col gap-2xs px-sm py-6 empty:hidden" 13 style="background-color: var(--status-bg-color, #F1F1F1);" 14 >${t}</div>`}render(){return n` 15 <slot @submit=${this.handleSubmit}></slot> 16 ${this.resultHTML} 17 `}};l=((t,e)=>{for(var a,r=e,n=t.length-1;n>=0;n--)(a=t[n])&&(r=a(r)||r);return r})([e("elc-gift-card-balance")],l);export{l as ELCGiftCardBalance};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.