import{_ as H,a as Q}from"./Qlbn3NkC.js";import{_ as T}from"./DyFiwf46.js";import{g as I,m as P,S as R,n as U,r as v,D as G,P as K,w as o,q as a,H as L,o as M,b as n,B as k,d as F,t as C,C as W,Q as d,p as X,c as Y,R as Z,a as g}from"./Czresmtb.js";import{S as ee}from"./UVkYmYJL.js";import{_ as te}from"./us3hyXeL.js";import{_ as ne}from"./ByO-3iZ4.js";import{_ as A}from"./DxTvTv-W.js";import{_ as oe}from"./Bbw6XuZN.js";import{_ as E}from"./D3k1Qa3g.js";import S from"./CCyh6GyX.js";import{_ as ae}from"./DBEVwlga.js";import{_ as se}from"./SzXeczgo.js";import"./DlAUqK2U.js";import"./poFbq7Xm.js";import"./D4t6JTJM.js";import"./CFdxo1g5.js";import"./C5Ksf8W7.js";import"./BwhG0EbZ.js";import"./CITJg5vM.js";import"./Bk_rJcZu.js";import"./CXo726-H.js";import"./uEz0rSNB.js";import"./CBaAmZ2K.js";import"./Dhvxr_Pa.js";import"./ZSyOeJ1o.js";import"./TP8I8QlK.js";import"./CM8LO42l.js";import"./CGVEu9yq.js";import"./DRcMdvSr.js";import"./Cz32yFEB.js";import"./ARX9GZ8p.js";const le=I({__name:"form-item",props:{show:{type:Boolean},policy:{}},emits:["update:show","saved"],setup(V,{emit:l}){var b,_,w,t;const{t:i}=P(),{$api:f}=R(),y=U(),m=l,r=V,c=v(((b=r.policy)==null?void 0:b.name)||""),p=v(typeof((_=r.policy)==null?void 0:_.content)=="object"?JSON.stringify((w=r.policy)==null?void 0:w.content,null,2):((t=r.policy)==null?void 0:t.content)||"");G(()=>r.policy,e=>{e&&(c.value=e.name||"",p.value=typeof e.content=="object"?JSON.stringify(e.content,null,2):e.content||"")},{immediate:!0});const h=()=>m("update:show",!1);async function N(){try{const e=await f.put(`/add-canned-policy?name=${c.value}`,JSON.parse(p.value||"{}"));y.success(i("Saved")),h(),m("saved")}catch(e){y.error(i("Save Failed")),console.error("Error:",e)}}return(e,s)=>{const $=A,x=ne,j=T,B=ee,O=te,J=oe,D=k,z=E,q=L;return M(),K(q,{show:e.show,"onUpdate:show":s[3]||(s[3]=u=>e.$emit("update:show",u)),"mask-closable":!1,preset:"card",title:a(i)("Policy Original"),class:"max-w-screen-md",segmented:{content:!0,action:!0}},{action:o(()=>[n(z,{justify:"center"},{default:o(()=>[n(D,{onClick:s[2]||(s[2]=u=>h())},{default:o(()=>[F(C(a(i)("Cancel")),1)]),_:1}),n(D,{type:"primary",onClick:N},{default:o(()=>[F(C(a(i)("Submit")),1)]),_:1})]),_:1})]),default:o(()=>[n(J,{"label-placement":"top","label-align":"left","label-width":100},{default:o(()=>[n(O,{cols:24,"x-gap":18},{default:o(()=>[n(x,{span:24,label:a(i)("Policy Name"),path:"name"},{default:o(()=>[n($,{value:c.value,"onUpdate:value":s[0]||(s[0]=u=>c.value=u)},null,8,["value"])]),_:1},8,["label"]),n(x,{span:24,label:a(i)("Policy Original"),path:"content"},{default:o(()=>[n(B,{class:"w-full max-h-[60vh]"},{default:o(()=>[n(j,{modelValue:p.value,"onUpdate:modelValue":s[1]||(s[1]=u=>p.value=u)},null,8,["modelValue"])]),_:1})]),_:1},8,["label"])]),_:1})]),_:1})]),_:1},8,["show","title"])}}}),re={class:"text-2xl font-bold"},ie={class:"flex items-center justify-between"},ce={class:"flex items-center justify-between"},me={class:"flex items-center gap-4"},ze=I({__name:"index",setup(V){const{t:l}=P(),{$api:i}=R(),f=U(),y=v([]),m=v(),r=v(),c=W({get:()=>!!r.value,set:t=>{t||(r.value=null)}}),p=t=>{r.value=t},h=()=>{r.value={name:"",content:"{}"}},N=[{title:l("Name"),key:"name",filter(t,e){return!!e.name.includes(t.toString())}},{title:l("Actions"),key:"actions",align:"center",width:180,render:t=>d(E,{justify:"center"},{default:()=>[d(k,{size:"small",secondary:!0,onClick:()=>p(t)},{default:()=>"",icon:()=>d(S,{name:"ri:edit-2-line"})}),d(ae,{onPositiveClick:()=>w(t)},{default:()=>l("Confirm Delete"),trigger:()=>d(k,{size:"small",secondary:!0},{default:()=>"",icon:()=>d(S,{name:"ri:delete-bin-5-line"})})})]})}];function b(t){m.value&&m.value.filter({name:[t]})}const _=async()=>{try{const t=await i.get("/list-canned-policies");y.value=Object.keys(t).sort((e,s)=>e.localeCompare(s)).map(e=>({name:e,content:t[e]}))}catch{f.error(l("Failed to fetch data"))}};X(()=>{_()});async function w(t){try{await i.delete(`/remove-canned-policy?name=${encodeURIComponent(t.name)}`),f.success(l("Delete Success")),_()}catch{f.error(l("Delete Failed"))}}return(t,e)=>{const s=H,$=A,x=se,j=Q,B=le;return M(),Y("div",null,[n(s,null,{title:o(()=>[g("h1",re,C(a(l)("IAM Policies")),1)]),_:1}),n(j,{class:"flex flex-col gap-4"},{default:o(()=>[g("div",ie,[g("div",ce,[n($,{placeholder:a(l)("Search"),onInput:b},{prefix:o(()=>[n(a(S),{name:"ri:search-2-line"})]),_:1},8,["placeholder"])]),g("div",me,[n(a(k),{onClick:h},{default:o(()=>[n(a(S),{name:"ri:add-line",class:"mr-2"}),g("span",null,C(a(l)("New Policy")),1)]),_:1})])]),n(x,{ref_key:"tableRef",ref:m,class:"border dark:border-neutral-700 rounded overflow-hidden",columns:N,data:a(y),pagination:!1,bordered:!1},null,8,["data"])]),_:1}),n(B,{show:a(c),"onUpdate:show":e[0]||(e[0]=O=>Z(c)?c.value=O:null),policy:a(r),onSaved:_},null,8,["show","policy"])])}}});export{ze as default};
