| 1 |
import{h as w,l as d,r as V,e as m,o as _,d as e,a as u,b as A,t as l,u as r,F as G,g as N,f,w as c,n as P}from"./vue.esm-bundler.js?ver=1.6.0";import{t as s}from"./Translator.js?ver=1.6.0";import{B as Y}from"./Badge.js?ver=1.6.0";import{T}from"./TransitionAccordion.js?ver=1.6.0";import{R as H}from"./Rest.js?ver=1.6.0";import{n as q}from"./Notify.js?ver=1.6.0";import"./Arr.js?ver=1.6.0";import"./Model.js?ver=1.6.0";import"./common.js?ver=1.6.0";import"./dayjs.min.js?ver=1.6.0";import"./Str.js?ver=1.6.0";import"./timezone.js?ver=1.6.0";import"./index.js?ver=1.6.0";import"./vue-router.js?ver=1.6.0";import"./Url.js?ver=1.6.0";import"./DynamicIcon.js?ver=1.6.0";import"./_plugin-vue_export-helper.js?ver=1.6.0";import"./index3.js?ver=1.6.0";import"./IconButton.js?ver=1.6.0";import"./Utils.js?ver=1.6.0";const I={class:"fct-subscription-mode-manager"},J={class:"flex items-start justify-between gap-4 rounded border border-gray-divider bg-gray-25 p-4 dark:border-slate-700 dark:bg-slate-800"},Q={class:"flex items-center gap-2"},X={class:"mt-2 text-sm text-system-mid dark:text-slate-300"},Z={key:0,class:"mt-1 text-xs text-system-dark-light dark:text-slate-400"},ee={key:1,class:"mt-2 pl-4 text-xs list-disc text-system-dark-light dark:text-slate-400"},te={class:"-ml-4 mb-1 list-none font-medium text-system-mid dark:text-slate-300"},ae=["aria-label"],se=["aria-checked","tabindex"],le={class:"fct-subscription-mode-card__header"},oe={class:"fct-subscription-mode-card__title"},re={class:"fct-subscription-mode-recommended"},ne={class:"fct-subscription-mode-card__desc"},ie={class:"fct-subscription-mode-card__extras"},ce={class:"fct-subscription-mode-note"},de=["aria-checked","tabindex"],ue={class:"fct-subscription-mode-card__header"},pe={class:"fct-subscription-mode-card__title"},me={class:"fct-subscription-mode-card__desc"},_e={class:"fct-subscription-mode-card__extras"},ge={class:"fct-subscription-mode-note"},fe={key:0,class:"fct-subscription-mode-support"},be={key:0,class:"fct-subscription-mode-card__schedule-link"},ve={class:"fct-schedule-tooltip__title"},ye={class:"fct-schedule-tooltip__list"},he={class:"fct-subscription-mode-card__schedule-trigger"},we={class:"fct-subscription-mode-safety-note"},Ke={__name:"SubscriptionModeManager",props:{name:{type:String,required:!0},field:{type:Object},fieldKey:{type:String},value:{required:!0},variant:{type:String},nesting:{type:Boolean,default:!1},statePath:{type:String},form:{type:Object,required:!0},label:{type:String},attribute:{type:Object},callback:{type:Function}},setup(z){const p=z,v=w(!1),y=w(!1),i=w("gateway_managed"),k=w(!1),x=w(!1),$=d(()=>{var t;return((t=p.value)==null?void 0:t.subscription_management_mode)||"gateway_managed"}),R=d(()=>{var t;return((t=p.value)==null?void 0:t.subscription_system_charge)==="yes"}),M=d(()=>{var t;return((t=p.value)==null?void 0:t.subscription_manual_fallback)==="yes"}),C=d(()=>$.value==="store_managed"),S=d(()=>{var t;return((t=p.field)==null?void 0:t.schedule_items)||[]}),O=d(()=>{var t;return((t=p.field)==null?void 0:t.system_charge_gateways)||[]}),F=d(()=>{const t=O.value.map(o=>o.label);if(!t.length)return"";const a=O.value.filter(o=>o.active).map(o=>o.label);if(O.value.filter(o=>!o.active).map(o=>o.label),a.length)return s("Supported by %1$s.",t.join(", "));if(a.length)return s("Supported by %1$s.",a.join(", "))}),j=d(()=>C.value?R.value?{label:s("Store Billing · Auto-charge"),type:"warning"}:{label:s("Store Billing"),type:"warning"}:M.value?{label:s("Gateway Billing · All methods"),type:"success"}:{label:s("Gateway Billing"),type:"success"}),K=d(()=>s("Gateways without built-in recurring billing can still sell subscriptions. Their renewals are invoiced by email before each due date.")),U=d(()=>C.value?R.value?s("Your store creates renewal invoices and charges saved payment methods automatically."):s("Your store creates renewal invoices before each due date. Customers pay via email link."):s("Stripe, PayPal, and other subscription-ready gateways charge renewals automatically.")),E=()=>{i.value=$.value,k.value=R.value,x.value=M.value,v.value=!0},L=()=>{const t=p.statePath||"",a=i.value,o=k.value?"yes":"no",g=x.value?"yes":"no";y.value=!0,H.post("settings/store",{subscription_management_mode:a,subscription_system_charge:o,subscription_manual_fallback:g}).then(()=>{p.form.setValue(`${t}subscription_management_mode`,a),p.form.setValue(`${t}subscription_system_charge`,o),p.form.setValue(`${t}subscription_manual_fallback`,g),q.success(s("Renewal billing updated")),v.value=!1}).catch(b=>{var B;q.error(((B=b.data)==null?void 0:B.message)||s("Could not save the subscription billing mode."))}).finally(()=>{y.value=!1})},W=t=>{y.value||t()},h=["gateway_managed","store_managed"],D=t=>{var g,b;const a=h.indexOf(i.value);let o=-1;if(t.key==="ArrowDown"||t.key==="ArrowRight")o=(a+1)%h.length;else if(t.key==="ArrowUp"||t.key==="ArrowLeft")o=(a-1+h.length)%h.length;else if(t.key===" "||t.key==="Enter"){t.preventDefault();return}else return;t.preventDefault(),i.value=h[o],(b=(g=t.currentTarget.closest('[role="radiogroup"]'))==null?void 0:g.querySelectorAll('[role="radio"]')[o])==null||b.focus()};return(t,a)=>{const o=V("el-button"),g=V("el-checkbox"),b=V("el-tooltip"),B=V("el-dialog");return _(),m("div",I,[e("div",J,[e("div",null,[e("div",Q,[u(Y,{type:j.value.type,text:j.value.label},null,8,["type","text"])]),e("p",X,l(U.value),1),!C.value&&M.value?(_(),m("p",Z,l(K.value),1)):A("",!0),C.value&&S.value.length?(_(),m("ul",ee,[e("li",te,l(r(s)("Renewal invoices created"))+":",1),(_(!0),m(G,null,N(S.value,n=>(_(),m("li",{key:n.label,class:"mb-0.5"},[e("strong",null,l(n.label)+":",1),f(" "+l(n.when),1)]))),128))])):A("",!0)]),u(o,{plain:"",size:"small",onClick:E},{default:c(()=>[f(l(r(s)("Change")),1)]),_:1})]),u(B,{modelValue:v.value,"onUpdate:modelValue":a[5]||(a[5]=n=>v.value=n),title:r(s)("Renewal Billing"),width:"560px","append-to-body":"","before-close":W,class:"fct-subscription-mode-dialog"},{footer:c(()=>[u(o,{disabled:y.value,onClick:a[4]||(a[4]=n=>v.value=!1)},{default:c(()=>[f(l(r(s)("Cancel")),1)]),_:1},8,["disabled"]),u(o,{type:"primary",loading:y.value,onClick:L},{default:c(()=>[f(l(r(s)("Apply")),1)]),_:1},8,["loading"])]),default:c(()=>[e("div",{class:"fct-subscription-mode-cards",role:"radiogroup","aria-label":r(s)("Renewal Billing")},[e("div",{class:P(["fct-subscription-mode-card",{"is-selected":i.value==="gateway_managed"}]),role:"radio","aria-checked":i.value==="gateway_managed",tabindex:i.value==="gateway_managed"?0:-1,onClick:a[1]||(a[1]=n=>i.value="gateway_managed"),onKeydown:D},[e("div",le,[a[6]||(a[6]=e("span",{class:"fct-subscription-mode-card__radio"},null,-1)),e("span",oe,l(r(s)("Gateway Billing")),1),e("span",re,l(r(s)("Recommended")),1)]),e("p",ne,l(r(s)("Stripe, PayPal, and other subscription-ready gateways charge customers automatically each cycle.")),1),u(T,{visible:i.value==="gateway_managed"},{default:c(()=>[e("div",ie,[u(g,{modelValue:x.value,"onUpdate:modelValue":a[0]||(a[0]=n=>x.value=n)},{default:c(()=>[f(l(r(s)("Allow all payment methods")),1)]),_:1},8,["modelValue"]),e("p",ce,l(r(s)("Gateways without built-in recurring billing (SSLCommerz, Authorize.Net, bank transfer, etc.) can still sell subscriptions. Their renewals are invoiced by email before each due date.")),1)])]),_:1},8,["visible"])],42,se),e("div",{class:P(["fct-subscription-mode-card",{"is-selected":i.value==="store_managed"}]),role:"radio","aria-checked":i.value==="store_managed",tabindex:i.value==="store_managed"?0:-1,onClick:a[3]||(a[3]=n=>i.value="store_managed"),onKeydown:D},[e("div",ue,[a[7]||(a[7]=e("span",{class:"fct-subscription-mode-card__radio"},null,-1)),e("span",pe,l(r(s)("Store Billing")),1)]),e("p",me,l(r(s)("Your store creates a renewal invoice before each due date. Customers pay via a link in the email.")),1),u(T,{visible:i.value==="store_managed"},{default:c(()=>[e("div",_e,[u(g,{modelValue:k.value,"onUpdate:modelValue":a[2]||(a[2]=n=>k.value=n)},{default:c(()=>[f(l(r(s)("Auto-charge saved payment methods")),1)]),_:1},8,["modelValue"]),e("p",ge,l(r(s)("When supported, the customer's saved payment method is charged automatically on each renewal due date.")),1),F.value?(_(),m("p",fe,l(F.value),1)):A("",!0)]),S.value.length?(_(),m("div",be,[u(b,{placement:"bottom-start",effect:"dark","popper-class":"fct-tooltip fct-schedule-tooltip"},{content:c(()=>[e("p",ve,l(r(s)("When are renewal orders created?")),1),e("ul",ye,[(_(!0),m(G,null,N(S.value,n=>(_(),m("li",{key:n.label},[e("strong",null,l(n.label)+":",1),f(" "+l(n.when),1)]))),128))])]),default:c(()=>[e("span",he,[a[8]||(a[8]=e("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[e("circle",{cx:"8",cy:"8",r:"7",stroke:"currentColor","stroke-width":"1.5"}),e("path",{d:"M8 5v3",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"}),e("circle",{cx:"8",cy:"11",r:".75",fill:"currentColor"})],-1)),f(" "+l(r(s)("When are renewal orders created?")),1)])]),_:1})])):A("",!0)]),_:1},8,["visible"])],42,de)],8,ae),e("div",we,[a[9]||(a[9]=e("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[e("circle",{cx:"8",cy:"8",r:"7",stroke:"currentColor","stroke-width":"1.5"}),e("path",{d:"M8 5v3",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"}),e("circle",{cx:"8",cy:"11",r:".75",fill:"currentColor"})],-1)),e("span",null,l(r(s)("Only affects new subscriptions. Existing ones keep their current billing method.")),1)])]),_:1},8,["modelValue","title"])])}}};export{Ke as default}; |