import{r as t,h as s,F as i}from"./p-b891c2f1.js";import{_ as e}from"./p-684c85b4.js";import"./p-aafd8ea4.js";import{a as r}from"./p-6fd3642a.js";import{a as n}from"./p-1c2e2695.js";import"./p-112455b1.js";const o=class{constructor(s){t(this,s)}componentDidLoad(){this.fetchItems()}async fetchItems(){try{this.loading=!0,await this.fetchSubscription()}catch(t){console.error(this.error),this.error=(null==t?void 0:t.message)||e("Something went wrong","surecart")}finally{this.loading=!1}}async fetchSubscription(){this.subscriptionId&&(this.subscription=await r({path:n(`/surecart/v1/subscriptions/${this.subscriptionId}`,{expand:["price","price.product","latest_invoice","product"]})}))}async renewSubscription(){try{this.error="",this.busy=!0,await r({path:`/surecart/v1/subscriptions/${this.subscriptionId}/renew/`,method:"PATCH"}),this.successUrl?window.location.assign(this.successUrl):this.busy=!1}catch(t){this.error=(null==t?void 0:t.message)||e("Something went wrong","surecart"),this.busy=!1}}renderContent(){var t;return this.loading?this.renderLoading():s(i,null,s("sc-subscription-details",{subscription:null==this?void 0:this.subscription,hideRenewalText:!0}),s("sc-alert",{type:"info",open:!0},e("This plan will no longer be canceled. It will renew on","surecart")," ",s("sc-format-date",{type:"timestamp",date:null===(t=null==this?void 0:this.subscription)||void 0===t?void 0:t.current_period_end_at,month:"long",day:"numeric",year:"numeric"}),"."," "))}renderLoading(){return s("div",{style:{padding:"0.5em"}},s("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),s("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),s("sc-skeleton",{style:{width:"40%"}}))}render(){return s("sc-dashboard-module",{heading:this.heading||e("Renew your plan","surecart"),class:"subscription-cancel",error:this.error},s("sc-card",null,this.renderContent(),s("sc-button",{type:"primary",full:!0,loading:this.loading||this.busy,disabled:this.loading||this.busy,onClick:()=>this.renewSubscription()},e("Renew Plan","surecart")),!!this.backUrl&&s("sc-button",{href:this.backUrl,full:!0,loading:this.loading||this.busy,disabled:this.loading||this.busy},e("Go Back","surecart"))),this.busy&&s("sc-block-ui",null))}};o.style=":host{display:block;position:relative}.subscription-renew{display:grid;gap:0.5em}";export{o as sc_subscription_renew}