import{D as t,bR as p,bE as y,o as b,I as B,cy as _,K as g,R as D,Q as C,ah as $,b9 as w,bq as u,bV as R,df as F,B as K,dg as N,S as J,bt as k,r as d,c0 as L,aw as O,dh as T,di as q}from"./index-CNZMR1GT.js";import{b as G}from"./useTitle-BClow7LS.js";import{G as W}from"./index-3N2OqIV6.js";import{I as H}from"./SettingItem-EdBZszST.js";import{R as V}from"./ResponsiveGrid-VTNos9Q3.js";import{a as j}from"./FolderTree-CTh3_qOS.js";import{c as m}from"./index-DvQYEsdd.js";import"./index-DsSWFirV.js";import"./index-DUl6hczb.js";import"./item_type-CyD6qwPS.js";const E=e=>{const s=b();return t(_,{w:"$full",overflowX:"auto",shadow:"$md",rounded:"$lg",p:"$2",direction:{"@initial":"column","@xl":"row"},spacing:"$2",get children(){return[t(p,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[t(y,{for:"path",display:"flex",alignItems:"center",get children(){return s("global.name")}}),t(B,{id:"name",get value(){return e.name},onChange:n=>e.onChange({...e,name:n.currentTarget.value})})]}}),t(p,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[t(y,{for:"path",display:"flex",alignItems:"center",get children(){return s("metas.path")}}),t(j,{id:"path",get value(){return e.path},onChange:n=>e.onChange({...e,path:n})})]}}),t(_,{direction:{"@initial":"row","@xl":"column"},justifyContent:{"@xl":"center"},spacing:"$1",get children(){return t(g,{colorScheme:"danger",onClick:async()=>{e.onDelete()},get children(){return s("global.delete")}})}})]}})},M=e=>{const s=b();return console.log(e.buckets),t($,{alignItems:"start",w:"$full",get children(){return[t(y,{display:"flex",alignItems:"center",get children(){return s("settings.s3_buckets")}}),t(g,{onClick:()=>{e.setSettings(n=>n.key==="s3_buckets","value",JSON.stringify([...e.buckets,{name:"",path:""}])),console.log(e.buckets)},get children(){return s("global.add")}}),t(D,{get each(){return e.buckets},children:n=>t(E,C(n,{onChange:r=>{console.log(r),e.setSettings(a=>a.key==="s3_buckets","value",JSON.stringify(e.buckets.map(a=>a.name===n.name?r:a)))},onDelete:()=>{e.setSettings(r=>r.key==="s3_buckets","value",JSON.stringify(e.buckets.filter(r=>r.name!==n.name)))}}))})]}})},v=e=>{const s={...e.find(n=>n.key==="s3_buckets")};return s.value?JSON.parse(s.value):[]},se=()=>{const e=b();G("manage.sidemenu.s3");const[s,n]=w(()=>u.get("/admin/setting/list?group=".concat(W.S3))),[r,a]=R([]),h=async()=>{const c=await n();k(c,a)};h();const[I,x]=w(()=>u.post("/admin/setting/save",F(r))),[A,S]=K(!1);return t($,{w:"$full",alignItems:"start",spacing:"$2",get children(){return[t(V,{get children(){return[t(N,{each:r,children:(c,o)=>t(J,{get when(){return c().key!="s3_buckets"},get children(){return t(H,C(c,{onChange:l=>{a(i=>c().key===i.key,"value",l)},onDelete:async()=>{S(!0);const l=await u.post("/admin/setting/delete?key=".concat(c().key));S(!1),k(l,()=>{d.success(e("global.delete_success")),h()})}}))}})}),t(g,{onClick:()=>{const c=m.lib.WordArray.random(15),o=m.lib.WordArray.random(240/8),l=m.enc.Base64.stringify(c).replace(/[\r\n]/g,""),i=m.enc.Base64.stringify(o).replace(/[\r\n]/g,"");a(f=>f.key==="s3_access_key_id","value",l),a(f=>f.key==="s3_secret_access_key","value",i)},get children(){return e("settings.s3_generate")}}),t(L,{get children(){return e("settings.s3_restart_to_apply")}}),t(M,{get buckets(){return v(r)},setSettings:a})]}}),t(O,{spacing:"$2",get children(){return[t(g,{colorScheme:"accent",onClick:h,get loading(){return s()||A()},get children(){return e("global.refresh")}}),t(g,{get loading(){return I()},onClick:async()=>{const c=v(r),o=new Set;for(const i of c){if(i.name===""||i.path===""){d.error(e("settings.s3_buckets_empty"));return}if(o.has(i.name)){d.error(e("settings.s3_buckets_duplicate_name"));return}o.add(i.name)}const l=await x();k(l,async()=>{d.success(e("global.save_success")),T(await u.get("/public/settings"),q)})},get children(){return e("global.save")}})]}})]}})};export{se as default};
