import{E as e,bR as t,bE as n,q as s,bo as r,cA as a,a8 as i,G as l,F as c,a7 as o,b7 as g,bq as u,bV as d,dk as m,X as h,dl as p,S as f,bt as b,x as k,c1 as y,ao as _,dm as v,dn as x}from"./index-C-dDkA_D.js";import{b as w}from"./useTitle-Dwsro-_9.js";import{G as S}from"./index-Ddnz8quC.js";import{I as $}from"./SettingItem-DATBsMwf.js";import{R as C}from"./ResponsiveGrid-EC2vEAXl.js";import{a as j}from"./FolderTree-BPZyL9IS.js";import{c as I}from"./index-D1JlzeXV.js";import"./index-BA8MiV3y.js";import"./index-2YNnOdV-.js";import"./item_type-Bo2djN9R.js";const D=l=>{const c=s();return e(a,{w:"$full",overflowX:"auto",shadow:"$md",rounded:"$lg",p:"$2",direction:{"@initial":"column","@xl":"row"},spacing:"$2",get children(){return[e(t,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[e(n,{for:"path",display:"flex",alignItems:"center",get children(){return c("global.name")}}),e(r,{id:"name",get value(){return l.name},onChange:e=>l.onChange({...l,name:e.currentTarget.value})})]}}),e(t,{w:"$full",display:"flex",flexDirection:"column",required:!0,get children(){return[e(n,{for:"path",display:"flex",alignItems:"center",get children(){return c("metas.path")}}),e(j,{id:"path",get value(){return l.path},onChange:e=>l.onChange({...l,path:e})})]}}),e(a,{direction:{"@initial":"row","@xl":"column"},justifyContent:{"@xl":"center"},spacing:"$1",get children(){return e(i,{colorScheme:"danger",onClick:async()=>{l.onDelete()},get children(){return c("global.delete")}})}})]}})},J=t=>{const r=s();return console.log(t.buckets),e(o,{alignItems:"start",w:"$full",get children(){return[e(n,{display:"flex",alignItems:"center",get children(){return r("settings.s3_buckets")}}),e(i,{onClick:()=>{t.setSettings(e=>"s3_buckets"===e.key,"value",JSON.stringify([...t.buckets,{name:"",path:""}])),console.log(t.buckets)},get children(){return r("global.add")}}),e(l,{get each(){return t.buckets},children:n=>e(D,c(n,{onChange:e=>{console.log(e),t.setSettings(e=>"s3_buckets"===e.key,"value",JSON.stringify(t.buckets.map(t=>t.name===n.name?e:t)))},onDelete:()=>{t.setSettings(e=>"s3_buckets"===e.key,"value",JSON.stringify(t.buckets.filter(e=>e.name!==n.name)))}}))})]}})},q=e=>{const t={...e.find(e=>"s3_buckets"===e.key)};return t.value?JSON.parse(t.value):[]},N=()=>{const t=s();w("manage.sidemenu.s3");const[n,r]=g(()=>u.get(`/admin/setting/list?group=${S.S3}`)),[a,l]=d([]),j=async()=>{const e=await r();b(e,l)};j();const[D,N]=g(()=>u.post("/admin/setting/save",m(a))),[O,A]=h(!1);return e(o,{w:"$full",alignItems:"start",spacing:"$2",get children(){return[e(C,{get children(){return[e(p,{each:a,children:(n,s)=>e(f,{get when(){return"s3_buckets"!=n().key},get children(){return e($,c(n,{onChange:e=>{l(e=>n().key===e.key,"value",e)},onDelete:async()=>{A(!0);const e=await u.post(`/admin/setting/delete?key=${n().key}`);A(!1),b(e,()=>{k.success(t("global.delete_success")),j()})}}))}})}),e(i,{onClick:()=>{const e=I.lib.WordArray.random(15),t=I.lib.WordArray.random(30),n=I.enc.Base64.stringify(e).replace(/[\r\n]/g,""),s=I.enc.Base64.stringify(t).replace(/[\r\n]/g,"");l(e=>"s3_access_key_id"===e.key,"value",n),l(e=>"s3_secret_access_key"===e.key,"value",s)},get children(){return t("settings.s3_generate")}}),e(y,{get children(){return t("settings.s3_restart_to_apply")}}),e(J,{get buckets(){return q(a)},setSettings:l})]}}),e(_,{spacing:"$2",get children(){return[e(i,{colorScheme:"accent",onClick:j,get loading(){return n()||O()},get children(){return t("global.refresh")}}),e(i,{get loading(){return D()},onClick:async()=>{const e=q(a),n=new Set;for(const r of e){if(""===r.name||""===r.path)return void k.error(t("settings.s3_buckets_empty"));if(n.has(r.name))return void k.error(t("settings.s3_buckets_duplicate_name"));n.add(r.name)}const s=await N();b(s,async()=>{k.success(t("global.save_success")),v(await u.get("/public/settings"),x)})},get children(){return t("global.save")}})]}})]}})};export{N as default};
