/* empty css       *//* empty css            */import{a as z}from"./fp-el-skeleton-item.js?ver=1.3.1";import{u as J,ad as M,j as A,z as v,a5 as D,A as G,o as y,c as K,l as c,b as E,w as P,d as U,a as x,R as u,N as r,G as H,a2 as L,a4 as Q}from"./admin.js?ver=1.3.1";import{u as W,_ as X,a as Y}from"./fp-SetupInstructionsDialog.js?ver=1.3.1";import"./fp-el-tag.js?ver=1.3.1";import"./fp-_Uint8Array.js?ver=1.3.1";import"./fp-el-select.js?ver=1.3.1";import"./fp-index6.js?ver=1.3.1";import"./fp-index7.js?ver=1.3.1";import"./fp-castArray.js?ver=1.3.1";import"./fp-debounce.js?ver=1.3.1";/* empty css            *//* empty css           */import"./fp-el-radio-group.js?ver=1.3.1";import"./fp-el-checkbox.js?ver=1.3.1";import"./fp-el-tooltip.js?ver=1.3.1";/* empty css           */import"./fp-el-switch.js?ver=1.3.1";import"./fp-el-overlay.js?ver=1.3.1";import"./fp-refs.js?ver=1.3.1";const Z={class:"fplayer-settings-section fplayer-storage-config-page"},ee={class:"fplayer-storage-config-actions",style:{padding:"20px 0 0"}},Se={__name:"StorageConfigPage",setup(te,{expose:F}){const O=J(),$=M(),l=A(()=>O.params.key),f=v(""),{settings:d,fieldsMap:b,currentConfig:_,loading:g,configName:w,validationErrors:h,getValue:p,setValue:C,getFieldOptions:B,togglePasswordVisibility:I,isPasswordVisible:j,validate:V}=W(l),m=v(!1),S=v(null),R=t=>{S.value=t,m.value=!0},k=async()=>{var t;g.value=!0;try{const[e,n]=await Promise.all([u.get("integrations/fields"),u.get("integrations")]),a={},o={};e&&Object.keys(e).forEach(s=>{a[s]={...e[s],source:"standard",category:"others"},h.value[s]={}}),n&&Object.keys(n).forEach(s=>{o[s]=n[s],o[s]||(o[s]={enabled:"no"})}),b.value=a,Object.keys(a).forEach(s=>{const N=a[s];if(!o[s]){const i=N.source==="standard";o[s]={enabled:i?"no":!1}}(N.fields||[]).forEach(i=>{i.default!==null&&i.default!==void 0&&o[s][i.key]===void 0&&(o[s][i.key]=i.default),(i.type==="complex_array"||i.type==="array")&&!o[s][i.key]&&(o[s][i.key]=[])})}),d.value=o,w.value=((t=a[l.value])==null?void 0:t.name)||l.value,a[l.value]||$.replace({name:"settings.storage"})}catch{r.error("Failed to load storage data")}finally{g.value=!1}},T=async()=>{const t=l.value;if(!p("enabled")){try{const e=await u.post(`integrations/${t}`,{settings:{enabled:"no"}});r.success(e.message||"Integration disabled")}catch(e){r.error(e.message||"Failed to disable integration"),C("enabled",!0)}return}if(!V()){r.error("Please fill in all required fields");return}try{let e=JSON.parse(JSON.stringify(d.value[t]||{}));const n=await u.post(`integrations/${t}`,{settings:e});r.success(n.message||"Integration settings saved successfully"),n.settings&&(d.value[t]=n.settings)}catch(e){r.error(e.message||"Failed to save integration settings")}},q=async()=>{const t=l.value,e=d.value[t]||{},n=b.value[t];if(!p("enabled")){r.error("Please enable the integration first");return}if(!V()){r.error("Please fill in required fields before testing connection");return}f.value=t;try{let a;n.source==="standard"?a=await u.post(`integrations/${t}/test-connection`,{settings:e}):a=await u.post(`email-providers/${t}/test-connection`,{settings:e}),r.success(a.message||"Connection test successful")}catch(a){r.error(a.message||"Connection test failed")}finally{f.value=""}};return D(()=>{k()}),G(l,()=>{k()}),F({save:T,configName:w,loading:g}),(t,e)=>{const n=z,a=Q;return y(),K("div",Z,[c(g)?(y(),E(n,{key:0,rows:6,animated:""})):c(_).name?(y(),E(X,{key:1,fields:c(_).fields||[],"get-value":c(p),"set-value":c(C),"get-field-options":c(B),"toggle-password-visibility":c(I),"is-password-visible":c(j),"validation-errors":c(h),"provider-key":l.value,onShowSetupInstructions:R},{"after-fields":P(()=>[H("div",ee,[x(a,{type:"info",plain:"",size:"small",onClick:q,loading:f.value===l.value},{default:P(()=>e[1]||(e[1]=[L(" Test Connection ")])),_:1},8,["loading"])])]),_:1},8,["fields","get-value","set-value","get-field-options","toggle-password-visibility","is-password-visible","validation-errors","provider-key"])):U("",!0),x(Y,{modelValue:m.value,"onUpdate:modelValue":e[0]||(e[0]=o=>m.value=o),instructions:S.value},null,8,["modelValue","instructions"])])}}};export{Se as default};
