import{d as D,B as E,o as F,c as n,a as e,t as l,s as O,b as y,p as N,w as x,q as j,C as I,F as T,f as W,r,g as v,i as M,j as $,k as o,l as B,n as z,A as Y,y as G}from"./index-DPtT_PqD.js";import{p as L}from"./planService-CZatW7_4.js";const H={class:"stack"},J={class:"panel stack"},K={key:0},Q={key:1,class:"error"},X={key:2,class:"success"},Z={class:"inline-actions"},ee={class:"panel stack"},te={class:"topbar",style:{"margin-bottom":"0"}},se={key:0},ae={key:1},le={class:"field"},ne={class:"grid wide-grid"},oe={class:"metric"},ie=["disabled","onClick"],re={key:0},ve=D({__name:"LockedModulePage",setup(ue){const g=G(),S=Y(),u=E(),h=r([]),c=r("monthly"),p=r(!1),_=r(!1),i=r(""),d=r(""),f=v(()=>String(g.query.feature||"module")),b=v(()=>f.value.charAt(0).toUpperCase()+f.value.slice(1)),k=v(()=>{var s;return["owner","admin"].includes(((s=u.company)==null?void 0:s.user_role)||"")}),C=v(()=>h.value.filter(s=>s.is_active!==!1&&s.features.some(t=>t.slug===f.value))),m=v(()=>{var s,t;return((t=(s=u.company)==null?void 0:s.subscription)==null?void 0:t.plan.id)||null});function U(s){return Number(s||0).toFixed(2)}function V(s){return m.value===s.id?"status-pill":"status-pill off"}function A(){const s=String(g.query.from||"/");return s.startsWith("/")&&!s.startsWith("//")?s:"/"}async function R(){p.value=!0,i.value="",d.value="";try{await u.loadCurrent(!0),h.value=await L.list()}catch(s){i.value=M(s,"Unable to load upgrade options.")}finally{p.value=!1}}async function q(s){_.value=!0,i.value="",d.value="";try{await L.switchPlan({plan_id:s.id,billing_cycle:c.value}),await u.loadCurrent(!0),d.value=`${s.name} plan activated.`,await S.push(A())}catch(t){i.value=M(t,"Unable to switch plan. Owner or admin access is required.")}finally{_.value=!1}}return F(R),(s,t)=>{const w=$("RouterLink");return o(),n("section",H,[e("article",J,[t[3]||(t[3]=e("h2",null,"Module Locked",-1)),e("p",null,l(b.value)+" is not enabled on "+l(O(u).planName)+".",1),p.value?(o(),n("p",K,"Loading upgrade options...")):y("",!0),i.value?(o(),n("p",Q,l(i.value),1)):y("",!0),d.value?(o(),n("p",X,l(d.value),1)):y("",!0),e("div",Z,[N(w,{class:"button ghost",to:"/settings/companies"},{default:x(()=>[...t[1]||(t[1]=[B("View All Plans",-1)])]),_:1}),N(w,{class:"button ghost",to:"/"},{default:x(()=>[...t[2]||(t[2]=[B("Dashboard",-1)])]),_:1})])]),e("article",ee,[e("div",te,[e("div",null,[t[4]||(t[4]=e("h2",null,"Upgrade Options",-1)),k.value?(o(),n("p",ae,"Choose a plan that includes "+l(b.value)+".",1)):(o(),n("p",se,"Only company owner or admin can change the plan."))]),e("div",le,[t[6]||(t[6]=e("label",{for:"locked_billing_cycle"},"Billing Cycle",-1)),j(e("select",{id:"locked_billing_cycle","onUpdate:modelValue":t[0]||(t[0]=a=>c.value=a)},[...t[5]||(t[5]=[e("option",{value:"monthly"},"Monthly",-1),e("option",{value:"yearly"},"Yearly",-1)])],512),[[I,c.value]])])]),e("div",ne,[(o(!0),n(T,null,W(C.value,a=>(o(),n("div",{key:a.id,class:"panel stack"},[e("div",null,[e("h2",null,l(a.name),1),e("p",null,l(a.description||"Plan details"),1),e("span",{class:z(V(a))},l(m.value===a.id?"Current Plan":"Available"),3)]),e("div",oe,[e("span",null,l(c.value),1),e("strong",null,"BDT "+l(U(c.value==="monthly"?a.monthly_price:a.yearly_price)),1)]),e("div",null,[t[7]||(t[7]=e("strong",null,"Includes",-1)),e("p",null,l(a.features.map(P=>P.name).join(", ")),1)]),e("button",{class:"button primary",type:"button",disabled:_.value||!k.value||m.value===a.id,onClick:P=>q(a)},l(m.value===a.id?"Current Plan":"Upgrade"),9,ie)]))),128))]),C.value.length===0&&!p.value?(o(),n("p",re,"No active plan currently includes this module.")):y("",!0)])])}}});export{ve as default};
