2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
import{e as O,y as q,c as a,a as e,t as o,F as f,n as M,i as k,d as S,r as h,m as p,x as P,A as B,o as n}from"./CqYPuxVf.js";const J={class:"mb-8"},Q={class:"text-2xl font-bold text-white"},W={class:"text-slate-400 mt-1"},X={key:0,class:"flex items-center justify-center py-20"},Y={class:"ml-3 text-slate-400"},Z={key:1,class:"bg-red-500/10 border border-red-500/20 rounded-xl p-6 mb-8"},ee={class:"flex items-center gap-3"},se={class:"text-red-300 font-medium"},te={class:"text-red-400/80 text-sm mt-1"},re={key:1,class:"mb-6 flex items-center gap-3"},oe={class:"text-sm text-slate-400"},ae={class:"bg-indigo-500/10 border border-indigo-500/20 rounded-xl p-4 mb-8 flex items-start gap-3"},ne={class:"text-sm text-indigo-300"},le={class:"font-semibold"},ie={key:0,class:"ml-3 text-indigo-400/70"},de={class:"grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8"},ce={class:"bg-slate-800 rounded-xl border border-slate-700 p-6"},ue={class:"flex items-center gap-3 mb-4"},pe={class:"text-lg font-semibold text-white"},me={class:"text-sm text-slate-400 mb-4"},fe={class:"space-y-3"},he={class:"text-sm text-slate-300"},ge={class:"relative inline-flex items-center cursor-pointer"},be=["checked","onChange"],ve={class:"bg-slate-800 rounded-xl border border-slate-700 p-6"},xe={class:"flex items-center gap-3 mb-4"},ke={class:"text-lg font-semibold text-white"},_e={class:"text-sm text-slate-400 mb-4"},ye={class:"space-y-3"},we={class:"text-sm text-slate-300"},Ce={class:"relative inline-flex items-center cursor-pointer"},$e=["checked","onChange"],Me={class:"bg-slate-800 rounded-xl border border-slate-700 p-6"},Pe={class:"flex items-center gap-3 mb-4"},Be={class:"text-lg font-semibold text-white"},je={class:"text-sm text-slate-400 mb-4"},Ve={class:"space-y-3"},Ae={class:"flex flex-col"},ze={class:"text-sm text-slate-300"},Fe={class:"text-xs text-slate-500"},Ne={class:"relative inline-flex items-center cursor-pointer"},Le=["checked","onChange"],Se={class:"bg-slate-800/50 border border-slate-700 rounded-xl p-6 mb-8"},He={class:"text-lg font-semibold text-white mb-4"},De={class:"text-sm text-slate-400 mb-6"},Te={class:"overflow-x-auto"},Ee={class:"w-full text-sm"},Ue={class:"border-b border-slate-700"},Ke={class:"text-left py-3 px-4 text-slate-400 font-medium"},Re={class:"py-2.5 px-4 text-slate-300"},Ie={key:0,class:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-emerald-400/10"},Ge={key:1,class:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-slate-700"},Oe={key:2,class:"flex items-center gap-3 pb-8"},Qe=O({__name:"index",setup(qe){const _=p(!0),x=p(null),m=p({tier:"free",features:{},expires_at:null}),y=p([]),j=p([]),c=p(new Map),g=p(new Map),u=p(null),H=P(()=>Object.entries(m.value.features||{})),V=P(()=>c.value.size>0),D=P(()=>{const s=m.value.tier;return s==="enterprise"?"bg-purple-500/20 text-purple-300":s==="premium"?"bg-amber-500/20 text-amber-300":"bg-slate-500/20 text-slate-300"}),w=[{key:"user_mgmt",label:"User Management",enabled:!0},{key:"billing_admin",label:"Billing Administration",enabled:!0},{key:"robot_config",label:"Robot Configuration",enabled:!0},{key:"system_logs",label:"System Logs Access",enabled:!0},{key:"api_keys",label:"API Key Management",enabled:!1}],C=[{key:"vehicle_crud",label:"Vehicle CRUD",enabled:!0},{key:"service_booking",label:"Service Booking",enabled:!0},{key:"customer_view",label:"Customer Data View",enabled:!0},{key:"report_export",label:"Report Export",enabled:!1},{key:"bulk_import",label:"Bulk Import",enabled:!1}];function A(s,t){const r=`${s}:${t}`;if(c.value.has(r))return c.value.get(r);const d=(s==="superadmin"?w:C).find(l=>l.key===t);return d?d.enabled:!1}function T(s){return s.replace(/^cost_category:/,"").replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function E(s){try{return new Date(s).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}catch{return s}}function U(s,t){return s.actions.includes(t)}function $(s,t,r){const d=r.target.checked,l=`${s}:${t}`;if(!g.value.has(l)){const L=(s==="superadmin"?w:C).find(G=>G.key===t);g.value.set(l,L?L.enabled:!1)}const v=g.value.get(l);d===v?c.value.delete(l):c.value.set(l,d),c.value=new Map(c.value),console.log(`[Permissions] Toggle: group=${s}, key=${t}, newValue=${d}`)}function b(){setTimeout(()=>{u.value=null},5e3)}async function z(){u.value=null;try{const t=B("access_token").value;if(!t){u.value={type:"error",message:"Not authenticated"},b();return}const r=[];if(c.value.forEach((l,v)=>{const N=v.replace(/^(superadmin|garage):/,"").toUpperCase();r.push({action:N,granted:l})}),r.length===0){u.value={type:"error",message:"No changes to save"},b();return}const d=(await Promise.allSettled(r.map(l=>$fetch("/api/v1/admin/permissions/override/0",{method:"PATCH",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:{action:l.action,granted:l.granted}})))).filter(l=>l.status==="rejected");if(d.length>0){const l=d.map(v=>v.reason?.message||"Unknown error");u.value={type:"error",message:`Failed to save ${d.length} permission(s): ${l.join("; ")}`},b();return}c.value=new Map,g.value=new Map,u.value={type:"success",message:`Successfully saved ${r.length} permission change(s).`},b(),console.log("[Permissions] Save successful:",r)}catch(s){console.error("[Permissions] Save failed:",s),u.value={type:"error",message:s?.message||"Failed to save permissions"},b()}}function K(){c.value=new Map,g.value=new Map,u.value=null}async function R(){try{const t=B("access_token").value;if(!t){console.warn("[Permissions] No access token found for feature flags");return}const r=await $fetch("/api/v1/subscriptions/feature-flags",{headers:{Authorization:`Bearer ${t}`}});console.log("[Permissions] Feature flags loaded:",r),m.value=r}catch(s){console.error("[Permissions] Feature flags fetch failed:",s?.message||s)}}async function I(){try{const t=B("access_token").value;if(!t){console.warn("[Permissions] No access token found for permission matrix");return}const r=await $fetch("/api/v1/admin/permissions/matrix",{headers:{Authorization:`Bearer ${t}`}});console.log("[Permissions] Permission matrix loaded:",r),y.value=r.matrix,j.value=r.all_actions}catch(s){console.error("[Permissions] Permission matrix fetch failed:",s?.message||s)}}async function F(){_.value=!0,x.value=null;try{await Promise.all([R(),I()])}catch(s){console.error("[Permissions] fetchAll failed:",s?.message||s),x.value=s?.message||"Failed to load permissions data"}finally{_.value=!1}}return q(()=>{F()}),(s,t)=>(n(),a("div",null,[e("div",J,[e("h1",Q,o(s.$t("permissions.title")),1),e("p",W,o(s.$t("permissions.subtitle")),1)]),_.value?(n(),a("div",X,[t[0]||(t[0]=e("svg",{class:"animate-spin h-8 w-8 text-indigo-400",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})],-1)),e("span",Y,o(s.$t("permissions.loading")),1)])):x.value?(n(),a("div",Z,[e("div",ee,[t[1]||(t[1]=e("svg",{class:"w-6 h-6 text-red-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),e("div",null,[e("h3",se,o(s.$t("permissions.error_title")),1),e("p",te,o(x.value),1)])]),e("button",{onClick:F,class:"mt-4 px-4 py-2 text-sm bg-red-600 hover:bg-red-500 text-white rounded-lg transition"},o(s.$t("permissions.retry")),1)])):(n(),a(f,{key:2},[u.value?(n(),a("div",{key:0,class:M(["mb-6 px-4 py-3 rounded-lg text-sm font-medium",u.value.type==="success"?"bg-emerald-500/10 border border-emerald-500/20 text-emerald-300":"bg-red-500/10 border border-red-500/20 text-red-300"])},o(u.value.message),3)):k("",!0),V.value?(n(),a("div",re,[e("button",{onClick:z,class:"px-6 py-2.5 bg-emerald-600 hover:bg-emerald-500 text-white font-semibold rounded-lg shadow-lg shadow-emerald-600/20 transition-all hover:scale-[1.02] active:scale-[0.98] flex items-center gap-2"},[t[2]||(t[2]=e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"})],-1)),S(" "+o(s.$t("permissions.save_changes")),1)]),e("span",oe,o(s.$t("permissions.modified_count",{count:c.value.size})),1)])):k("",!0),e("div",ae,[t[3]||(t[3]=e("svg",{class:"w-5 h-5 text-indigo-400 flex-shrink-0 mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),e("div",ne,[e("span",le,o(s.$t("permissions.current_tier"))+":",1),e("span",{class:M(["ml-2 px-2 py-0.5 rounded-full text-xs font-medium",D.value])},o(m.value.tier||"free"),3),m.value.expires_at?(n(),a("span",ie,o(s.$t("permissions.expires"))+": "+o(E(m.value.expires_at)),1)):k("",!0)])]),e("div",de,[e("div",ce,[e("div",ue,[t[4]||(t[4]=e("div",{class:"p-2 rounded-lg bg-purple-500/10 text-purple-400"},[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12.75L11.25 15 15 9.75m-3-7.036A11.959 11.959 0 013.598 6 11.99 11.99 0 003 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285z"})])],-1)),e("h2",pe,o(s.$t("permissions.superadmin")),1)]),e("p",me,o(s.$t("permissions.superadmin_desc")),1),e("div",fe,[(n(),a(f,null,h(w,r=>e("div",{key:r.key,class:"flex items-center justify-between py-2 border-b border-slate-700/50 last:border-0"},[e("span",he,o(s.$t(`permissions.perms.${r.key}`)),1),e("label",ge,[e("input",{type:"checkbox",checked:A("superadmin",r.key),class:"sr-only peer",onChange:i=>$("superadmin",r.key,i)},null,40,be),t[5]||(t[5]=e("div",{class:"w-9 h-5 bg-slate-600 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-purple-500/50 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-slate-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-purple-600"},null,-1))])])),64))])]),e("div",ve,[e("div",xe,[t[6]||(t[6]=e("div",{class:"p-2 rounded-lg bg-cyan-500/10 text-cyan-400"},[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8.25 18.75a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m3 0h6m-9 0H3.375a1.125 1.125 0 01-1.125-1.125V14.25m17.25 4.5a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m3 0h1.125c.621 0 1.129-.504 1.09-1.124a17.902 17.902 0 00-3.213-9.193 2.056 2.056 0 00-1.58-.86H14.25M16.5 18.75h-2.25m0-11.177v-.958c0-.568-.422-1.048-.987-1.106a48.554 48.554 0 00-10.026 0 1.106 1.106 0 00-.987 1.106v7.635m12-6.677v6.677m0 4.5v-4.5m0 0h-12"})])],-1)),e("h2",ke,o(s.$t("permissions.garages")),1)]),e("p",_e,o(s.$t("permissions.garages_desc")),1),e("div",ye,[(n(),a(f,null,h(C,r=>e("div",{key:r.key,class:"flex items-center justify-between py-2 border-b border-slate-700/50 last:border-0"},[e("span",we,o(s.$t(`permissions.perms.${r.key}`)),1),e("label",Ce,[e("input",{type:"checkbox",checked:A("garage",r.key),class:"sr-only peer",onChange:i=>$("garage",r.key,i)},null,40,$e),t[7]||(t[7]=e("div",{class:"w-9 h-5 bg-slate-600 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-cyan-500/50 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-slate-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-cyan-600"},null,-1))])])),64))])]),e("div",Me,[e("div",Pe,[t[8]||(t[8]=e("div",{class:"p-2 rounded-lg bg-amber-500/10 text-amber-400"},[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M20.25 7.5l-.625 10.632a2.25 2.25 0 01-2.247 2.118H6.622a2.25 2.25 0 01-2.247-2.118L3.75 7.5m8.25 3v6.75m0 0l-3-3m3 3l3-3M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125z"})])],-1)),e("h2",Be,o(s.$t("permissions.feature_flags")),1)]),e("p",je,o(s.$t("permissions.feature_flags_desc",{tier:m.value.tier||"free"})),1),e("div",Ve,[(n(!0),a(f,null,h(H.value,([r,i])=>(n(),a("div",{key:r,class:"flex items-center justify-between py-2 border-b border-slate-700/50 last:border-0"},[e("div",Ae,[e("span",ze,o(T(r)),1),e("span",Fe,o(r),1)]),e("label",Ne,[e("input",{type:"checkbox",checked:i,class:"sr-only peer",disabled:!0,onChange:d=>$("feature",r,d)},null,40,Le),e("div",{class:M(["w-9 h-5 bg-slate-600 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-amber-500/50 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-slate-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all",i?"peer-checked:bg-amber-600":""])},null,2)])]))),128))])])]),e("div",Se,[e("h3",He,o(s.$t("permissions.rbac_title")),1),e("p",De,o(s.$t("permissions.rbac_desc")),1),e("div",Te,[e("table",Ee,[e("thead",null,[e("tr",Ue,[e("th",Ke,o(s.$t("permissions.action")),1),(n(!0),a(f,null,h(y.value,r=>(n(),a("th",{key:r.role,class:"text-center py-3 px-4 text-slate-400 font-medium"},o(r.role),1))),128))])]),e("tbody",null,[(n(!0),a(f,null,h(j.value,r=>(n(),a("tr",{key:r,class:"border-b border-slate-700/50 hover:bg-slate-700/30"},[e("td",Re,o(r),1),(n(!0),a(f,null,h(y.value,i=>(n(),a("td",{key:i.role,class:"text-center py-2.5 px-4"},[U(i,r)?(n(),a("span",Ie,[...t[9]||(t[9]=[e("svg",{class:"w-4 h-4 text-emerald-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M5 13l4 4L19 7"})],-1)])])):(n(),a("span",Ge,[...t[10]||(t[10]=[e("svg",{class:"w-4 h-4 text-slate-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])]))]))),128))]))),128))])])])]),V.value?(n(),a("div",Oe,[e("button",{onClick:z,class:"px-6 py-2.5 bg-emerald-600 hover:bg-emerald-500 text-white font-semibold rounded-lg shadow-lg shadow-emerald-600/20 transition-all hover:scale-[1.02] active:scale-[0.98] flex items-center gap-2"},[t[11]||(t[11]=e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"})],-1)),S(" "+o(s.$t("permissions.save_changes")),1)]),e("button",{onClick:K,class:"px-4 py-2.5 bg-slate-700 hover:bg-slate-600 text-slate-300 font-medium rounded-lg transition"},o(s.$t("permissions.discard")),1)])):k("",!0)],64))]))}});export{Qe as default};
|