import{r as t,h as e,g as i}from"./p-b891c2f1.js";import{_ as s,s as n}from"./p-684c85b4.js";import"./p-aafd8ea4.js";import{a as r}from"./p-6fd3642a.js";import{o}from"./p-c2833cb1.js";import{a}from"./p-1c2e2695.js";import"./p-112455b1.js";const c=class{constructor(e){t(this,e)}componentWillLoad(){o(this.el,(()=>{this.getSubscription()}))}async cancelPendingUpdate(){var t;if(confirm(s("Are you sure you want to cancel the pending update to your plan?","surecart")))try{this.busy=!0,this.subscription=await r({path:a(`surecart/v1/subscriptions/${null===(t=this.subscription)||void 0===t?void 0:t.id}/`,{expand:["price","price.product","latest_invoice","product"]}),method:"PATCH",data:{purge_pending_update:!0}})}catch(t){this.error=(null==t?void 0:t.message)?t.message:s("Something went wrong","surecart"),console.error(this.error)}finally{this.busy=!1}}async getSubscription(){if(!this.subscription)try{this.loading=!0,this.subscription=await await r({path:a(`surecart/v1/subscriptions/${this.subscriptionId}`,{expand:["price","price.product","latest_invoice"],...this.query||{}})})}catch(t){this.error=(null==t?void 0:t.message)?t.message:s("Something went wrong","surecart"),console.error(this.error)}finally{this.loading=!1}}renderName(t){var e,i,n;return"string"!=typeof(null===(e=null==t?void 0:t.price)||void 0===e?void 0:e.product)?null===(n=null===(i=null==t?void 0:t.price)||void 0===i?void 0:i.product)||void 0===n?void 0:n.name:s("Subscription","surecart")}renderRenewalText(t){const i=e("sc-subscription-status-badge",{subscription:t});return(null==t?void 0:t.cancel_at_period_end)&&t.current_period_end_at?e("span",null,i," ",n(s("Your plan will be canceled on","surecart"))," ",e("sc-format-date",{date:1e3*t.current_period_end_at,month:"long",day:"numeric",year:"numeric"})):"trialing"===t.status&&t.trial_end_at?e("span",null,i," ",n(s("Your plan begins on","surecart"))," ",e("sc-format-date",{date:1e3*t.trial_end_at,month:"long",day:"numeric",year:"numeric"})):"active"===t.status&&t.current_period_end_at?e("span",null,i," ",n(s("Your plan renews on","surecart"))," ",e("sc-format-date",{date:1e3*t.current_period_end_at,month:"long",day:"numeric",year:"numeric"})):i}renderEmpty(){return e("slot",{name:"empty"},s("This subscription does not exist.","surecart"))}renderLoading(){return e("sc-stacked-list-row",{style:{"--columns":"2"},"mobile-size":0},e("div",{style:{padding:"0.5em"}},e("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),e("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),e("sc-skeleton",{style:{width:"40%"}})))}renderContent(){return this.loading?this.renderLoading():this.subscription?e("sc-stacked-list-row",{"mobile-size":0},e("sc-subscription-details",{subscription:this.subscription})):this.renderEmpty()}render(){var t,i,n,r;return e("sc-dashboard-module",{heading:this.heading||s("Current Plan","surecart"),class:"subscription",error:this.error},!!this.subscription&&e("sc-flex",{slot:"end"},!!Object.keys(null===(t=this.subscription)||void 0===t?void 0:t.pending_update).length&&e("sc-button",{type:"link",onClick:()=>this.cancelPendingUpdate()},e("sc-icon",{name:"x-octagon",slot:"prefix"}),s("Cancel Scheduled Update","surecart")),(null===(i=null==this?void 0:this.subscription)||void 0===i?void 0:i.cancel_at_period_end)?e("sc-button",{type:"link",href:a(window.location.href,{action:"renew"})},e("sc-icon",{name:"repeat",slot:"prefix"}),s("Renew Plan","surecart")):"canceled"!==(null===(n=this.subscription)||void 0===n?void 0:n.status)&&(null===(r=this.subscription)||void 0===r?void 0:r.current_period_end_at)&&this.showCancel&&e("sc-button",{type:"link",href:a(window.location.href,{action:"cancel"})},e("sc-icon",{name:"x",slot:"prefix"}),s("Cancel Plan","surecart"))),e("sc-card",{"no-padding":!0,style:{"--overflow":"hidden"}},e("sc-stacked-list",null,this.renderContent())),this.busy&&e("sc-block-ui",{spinner:!0}))}get el(){return i(this)}};c.style=":host{display:block}.subscription{display:grid;gap:0.5em}.subscription a{text-decoration:none;font-weight:var(--sc-font-weight-semibold);display:inline-flex;align-items:center;gap:0.25em;color:var(--sc-color-primary-500)}.subscription a.cancel{color:var(--sc-color-danger-500)}";export{c as sc_subscription}