import{s as R}from"./chunk-LvLJmgfZ.js";import{t as ee}from"./react-Bj1aDYRI.js";import{t as te}from"./compiler-runtime-B3qBwwSJ.js";import{t as re}from"./jsx-runtime-Blw4afVn.js";import{c as ae,i as ne,n as oe,s as le,t as ie}from"./select-BP75_5jJ.js";import{t as V}from"./label-CqjrpwRC.js";import{t as z}from"./button-DDGiD1NW.js";import{r as se}from"./requests-9-v2bhoi.js";import{r as B}from"./input-JxFwu-3G.js";import{t as W}from"./use-toast-BwJoaaDM.js";import{a as ce,c as de,i as ue,n as me,r as he}from"./dialog-BCVepWLJ.js";import{t as fe}from"./links-wcQA1Np1.js";import{r as G}from"./field-BsxD35VE.js";import{r as pe}from"./textarea-DtCcemo9.js";var H="path:";function I(t){return typeof t=="string"?t.startsWith(H):!1}function ve(t){return`${H}${t}`}function Q(t){return t.slice(5)}var D="env:";function ge(t){return t}function U(t){return typeof t=="string"?t.startsWith(D):!1}function xe(t){return`${D}${t}`}function je(t){return t.replace(D,"")}function ye(t,e){return I(t)?{kind:"path",path:Q(t)}:{kind:"json",expr:U(t)?`json.loads(${e(t)})`:`json.loads(r"""${t}""")`}}function Se(t){let e=t.trimStart();return e.startsWith("{")||e.startsWith("[")}function J(t){let e=t.trim();if(!e)return"";try{return JSON.stringify(JSON.parse(e))}catch{return t.replaceAll(/\r?\n/g,"")}}function _e(t){return t.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(`
`,"\\n").replaceAll("\r","\\r").replaceAll("	","\\t")}var be=te(),K=R(ee(),1),r=R(re(),1);function Ne(t){return t.toSorted((e,a)=>e.provider==="env"?1:a.provider==="env"?-1:0)}const Ae=t=>{let e=(0,be.c)(47),{providerNames:a,onClose:$,onSuccess:F,initialValue:O,multiline:P}=t,j=O===void 0?"":O,n=P===void 0?!1:P,{writeSecret:Y}=se(),[o,X]=K.useState(""),y;e[0]!==j||e[1]!==n?(y=()=>n?J(j):j,e[0]=j,e[1]=n,e[2]=y):y=e[2];let[l,L]=K.useState(y),[i,Z]=K.useState(a[0]),S;e[3]!==o||e[4]!==i||e[5]!==n||e[6]!==F||e[7]!==l||e[8]!==Y?(S=async s=>{if(s.preventDefault(),!i){W({title:"Error",description:"No location selected for the secret.",variant:"danger"});return}let M=n?J(l):l;if(!o||!M||!i){W({title:"Error",description:"Please fill in all fields.",variant:"danger"});return}try{await Y({key:o,value:M,provider:"dotenv",name:i}),W({title:"Secret created",description:"The secret has been created successfully."}),F(o)}catch{W({title:"Error",description:"Failed to create secret. Please try again.",variant:"danger"})}},e[3]=o,e[4]=i,e[5]=n,e[6]=F,e[7]=l,e[8]=Y,e[9]=S):S=e[9];let q=S,_;e[10]===Symbol.for("react.memo_cache_sentinel")?(_=(0,r.jsxs)(ce,{children:[(0,r.jsx)(de,{children:"Add Secret"}),(0,r.jsx)(he,{children:"Add a new secret to your environment variables."})]}),e[10]=_):_=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=(0,r.jsx)(V,{htmlFor:"key",children:"Key"}),e[11]=b):b=e[11];let N;e[12]===Symbol.for("react.memo_cache_sentinel")?(N=s=>{X(Ce(s.target.value))},e[12]=N):N=e[12];let c;e[13]===o?c=e[14]:(c=(0,r.jsxs)("div",{className:"grid gap-2",children:[b,(0,r.jsx)(B,{id:"key",value:o,onChange:N,placeholder:"MY_SECRET_KEY",required:!0})]}),e[13]=o,e[14]=c);let A;e[15]===Symbol.for("react.memo_cache_sentinel")?(A=(0,r.jsx)(V,{htmlFor:"value",children:"Value"}),e[15]=A):A=e[15];let d;e[16]!==n||e[17]!==l?(d=n?(0,r.jsx)(pe,{id:"value",value:l,onChange:s=>L(J(s.target.value)),required:!0,className:"my-0 font-code text-xs break-all",rows:8,autoFocus:!0,autoComplete:"off"}):(0,r.jsx)(B,{id:"value",type:"password",value:l,onChange:s=>L(s.target.value),required:!0,autoComplete:"off"}),e[16]=n,e[17]=l,e[18]=d):d=e[18];let C;e[19]===Symbol.for("react.memo_cache_sentinel")?(C=ke()&&(0,r.jsx)(G,{children:"Note: You are sending this key over http."}),e[19]=C):C=e[19];let u;e[20]===d?u=e[21]:(u=(0,r.jsxs)("div",{className:"grid gap-2",children:[A,d,C]}),e[20]=d,e[21]=u);let k;e[22]===Symbol.for("react.memo_cache_sentinel")?(k=(0,r.jsx)(V,{htmlFor:"location",children:"Location"}),e[22]=k):k=e[22];let m;e[23]===a.length?m=e[24]:(m=a.length===0&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"No dotenv locations configured."}),e[23]=a.length,e[24]=m);let h;e[25]!==i||e[26]!==a?(h=a.length>0&&(0,r.jsxs)(ie,{value:i,onValueChange:s=>Z(s),children:[(0,r.jsx)(le,{children:(0,r.jsx)(ae,{placeholder:"Select a provider"})}),(0,r.jsx)(oe,{children:a.map(we)})]}),e[25]=i,e[26]=a,e[27]=h):h=e[27];let w;e[28]===Symbol.for("react.memo_cache_sentinel")?(w=(0,r.jsxs)(G,{children:["You can configure the location by setting the"," ",(0,r.jsx)(fe,{href:"https://links.marimo.app/dotenv",children:"dotenv configuration"}),"."]}),e[28]=w):w=e[28];let f;e[29]!==m||e[30]!==h?(f=(0,r.jsxs)("div",{className:"grid gap-2",children:[k,m,h,w]}),e[29]=m,e[30]=h,e[31]=f):f=e[31];let p;e[32]!==u||e[33]!==f||e[34]!==c?(p=(0,r.jsxs)("div",{className:"grid gap-4 py-4",children:[c,u,f]}),e[32]=u,e[33]=f,e[34]=c,e[35]=p):p=e[35];let v;e[36]===$?v=e[37]:(v=(0,r.jsx)(z,{type:"button",variant:"outline",onClick:$,children:"Cancel"}),e[36]=$,e[37]=v);let T=!o||!l||!i,g;e[38]===T?g=e[39]:(g=(0,r.jsx)(z,{type:"submit",disabled:T,children:"Add Secret"}),e[38]=T,e[39]=g);let x;e[40]!==v||e[41]!==g?(x=(0,r.jsxs)(ue,{children:[v,g]}),e[40]=v,e[41]=g,e[42]=x):x=e[42];let E;return e[43]!==q||e[44]!==p||e[45]!==x?(E=(0,r.jsx)(me,{children:(0,r.jsxs)("form",{onSubmit:q,children:[_,p,x]})}),e[43]=q,e[44]=p,e[45]=x,e[46]=E):E=e[46],E};function Ce(t){return t.replaceAll(/\W/g,"_")}function ke(){return window.location.href.startsWith("http://")}function we(t){return(0,r.jsx)(ne,{value:t,children:t},t)}export{ye as a,xe as c,ve as d,Q as f,Se as i,je as l,Ne as n,ge as o,_e as r,U as s,Ae as t,I as u};
