import{r as e,u as fe}from"./vendor-react-C0ZmnAiH.js";import{p as ee,y as Ze,Z as _e,_ as He,s as xe,v as Me,I as ke,J as Ve,$ as le,B as W}from"./index-ccpu5IUx.js";import{j as t,i as h}from"./vendor-ui-BUsIib4b.js";import{n as De}from"./Key.es-BvJDJMdJ.js";import{c as Ne,a as de,u as G}from"./vendor-query-CD5rVjAu.js";import{A as T,b as U,u as O}from"./vendor-utils-DwtcRXMR.js";import{R as ze,a as ue}from"./radio-group-h3DCFlEA.js";import{L as me}from"./label-Do0e7X6T.js";import{U as Ie}from"./index-Jtxtz2gd.js";import{U as Te}from"./index-C_2p6STl.js";import{u as Fe}from"./use_user-BKIOew3g.js";import{B as $e}from"./badge-Dksr9fi5.js";import{T as Le,a as Re,b as Oe,c as qe}from"./tooltip-bxA1RoBu.js";const Ke=new Map([["bold",e.createElement(e.Fragment,null,e.createElement("path",{d:"M208,76H100V56a28,28,0,0,1,28-28c13.51,0,25.65,9.62,28.24,22.39a12,12,0,1,0,23.52-4.78C174.87,21.5,153.1,4,128,4A52.06,52.06,0,0,0,76,56V76H48A20,20,0,0,0,28,96V208a20,20,0,0,0,20,20H208a20,20,0,0,0,20-20V96A20,20,0,0,0,208,76Zm-4,128H52V100H204Zm-88-30.34V180a12,12,0,0,0,24,0v-6.34a32,32,0,1,0-24,0ZM128,136a8,8,0,1,1-8,8A8,8,0,0,1,128,136Z"}))],["duotone",e.createElement(e.Fragment,null,e.createElement("path",{d:"M208,88H48a8,8,0,0,0-8,8V208a8,8,0,0,0,8,8H208a8,8,0,0,0,8-8V96A8,8,0,0,0,208,88Zm-80,72a20,20,0,1,1,20-20A20,20,0,0,1,128,160Z",opacity:"0.2"}),e.createElement("path",{d:"M208,80H96V56a32,32,0,0,1,32-32c15.37,0,29.2,11,32.16,25.59a8,8,0,0,0,15.68-3.18C171.32,24.15,151.2,8,128,8A48.05,48.05,0,0,0,80,56V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80Zm0,128H48V96H208V208Zm-80-96a28,28,0,0,0-8,54.83V184a8,8,0,0,0,16,0V166.83A28,28,0,0,0,128,112Zm0,40a12,12,0,1,1,12-12A12,12,0,0,1,128,152Z"}))],["fill",e.createElement(e.Fragment,null,e.createElement("path",{d:"M208,80H96V56a32,32,0,0,1,32-32c15.37,0,29.2,11,32.16,25.59a8,8,0,0,0,15.68-3.18C171.32,24.15,151.2,8,128,8A48.05,48.05,0,0,0,80,56V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80Zm-72,78.63V184a8,8,0,0,1-16,0V158.63a24,24,0,1,1,16,0Z"}))],["light",e.createElement(e.Fragment,null,e.createElement("path",{d:"M208,82H94V56a34,34,0,0,1,34-34c16.3,0,31,11.69,34.12,27.19a6,6,0,0,0,11.76-2.38C169.55,25.48,150.26,10,128,10A46.06,46.06,0,0,0,82,56V82H48A14,14,0,0,0,34,96V208a14,14,0,0,0,14,14H208a14,14,0,0,0,14-14V96A14,14,0,0,0,208,82Zm2,126a2,2,0,0,1-2,2H48a2,2,0,0,1-2-2V96a2,2,0,0,1,2-2H208a2,2,0,0,1,2,2Zm-82-94a26,26,0,0,0-6,51.29V184a6,6,0,0,0,12,0V165.29A26,26,0,0,0,128,114Zm0,40a14,14,0,1,1,14-14A14,14,0,0,1,128,154Z"}))],["regular",e.createElement(e.Fragment,null,e.createElement("path",{d:"M208,80H96V56a32,32,0,0,1,32-32c15.37,0,29.2,11,32.16,25.59a8,8,0,0,0,15.68-3.18C171.32,24.15,151.2,8,128,8A48.05,48.05,0,0,0,80,56V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80Zm0,128H48V96H208V208Zm-80-96a28,28,0,0,0-8,54.83V184a8,8,0,0,0,16,0V166.83A28,28,0,0,0,128,112Zm0,40a12,12,0,1,1,12-12A12,12,0,0,1,128,152Z"}))],["thin",e.createElement(e.Fragment,null,e.createElement("path",{d:"M208,84H92V56a36,36,0,0,1,36-36c17.24,0,32.75,12.38,36.08,28.8a4,4,0,1,0,7.84-1.6C167.78,26.81,149.31,12,128,12A44.05,44.05,0,0,0,84,56V84H48A12,12,0,0,0,36,96V208a12,12,0,0,0,12,12H208a12,12,0,0,0,12-12V96A12,12,0,0,0,208,84Zm4,124a4,4,0,0,1-4,4H48a4,4,0,0,1-4-4V96a4,4,0,0,1,4-4H208a4,4,0,0,1,4,4Zm-84-92a24,24,0,0,0-4,47.66V184a4,4,0,0,0,8,0V163.66A24,24,0,0,0,128,116Zm0,40a16,16,0,1,1,16-16A16,16,0,0,1,128,156Z"}))]]),Pe=new Map([["bold",e.createElement(e.Fragment,null,e.createElement("path",{d:"M56.88,31.93A12,12,0,0,0,36,40a20,20,0,0,0-8,16v56c0,54.29,26.32,87.22,48.4,105.29,23.71,19.39,47.44,26,48.44,26.29a12.1,12.1,0,0,0,6.32,0c1.35-.37,30-8.42,55.86-32.82l12.1,13.31a12,12,0,0,0,17.76-16.14ZM128,219.38a126.38,126.38,0,0,1-37.09-21.23C65.09,176.69,52,147.71,52,112V62.24L170.87,193A126,126,0,0,1,128,219.38ZM228,56v56a144,144,0,0,1-8.23,49.16,12,12,0,0,1-11.28,7.92,11.86,11.86,0,0,1-4.08-.72,12,12,0,0,1-7.2-15.37A120.31,120.31,0,0,0,204,112V60H109.33a12,12,0,1,1,0-24H208A20,20,0,0,1,228,56Z"}))],["duotone",e.createElement(e.Fragment,null,e.createElement("path",{d:"M216,56v56c0,96-88,120-88,120S40,208,40,112V56a8,8,0,0,1,8-8H208A8,8,0,0,1,216,56Z",opacity:"0.2"}),e.createElement("path",{d:"M53.92,34.62A8,8,0,0,0,40.26,42,16,16,0,0,0,32,56v56c0,52.72,25.52,84.67,46.93,102.19,23.06,18.86,46,25.27,47,25.53a8,8,0,0,0,4.2,0c1.36-.37,31.27-8.78,57.09-34.72l14.89,16.38a8,8,0,1,0,11.84-10.76Zm74.07,189a128.48,128.48,0,0,1-38.92-21.81C61.82,179.51,48,149.3,48,112l0-56h3.71L176.41,193.15A129.26,129.26,0,0,1,128,223.62ZM224,56v56c0,20.58-3.89,39.61-11.56,56.59A8,8,0,1,1,197.86,162c6.73-14.89,10.14-31.71,10.14-50V56L98.52,56a8,8,0,1,1,0-16H208A16,16,0,0,1,224,56Z"}))],["fill",e.createElement(e.Fragment,null,e.createElement("path",{d:"M224,56v56c0,25.24-5.85,45.72-14.3,62.14a4,4,0,0,1-6.53.87L86.52,46.69a4,4,0,0,1,3-6.69H208A16,16,0,0,1,224,56ZM53.92,34.62A8,8,0,0,0,40.26,42,16,16,0,0,0,32,56v56c0,52.72,25.52,84.67,46.93,102.19,23.06,18.86,46,25.27,47,25.53a8,8,0,0,0,4.2,0c1-.26,23.91-6.67,47-25.53A131.92,131.92,0,0,0,187.18,205l14.9,16.38a8,8,0,1,0,11.84-10.76Z"}))],["light",e.createElement(e.Fragment,null,e.createElement("path",{d:"M52.44,36a6,6,0,0,0-9.63,7A14,14,0,0,0,34,56v56c0,51.94,25.12,83.4,46.2,100.64,22.73,18.6,45.27,24.89,46.22,25.15a6,6,0,0,0,3.16,0c1.36-.37,31.91-8.95,57.67-35.7L203.56,220a6,6,0,0,0,8.88-8.08ZM128,225.72a130.83,130.83,0,0,1-40.56-22.66C59.94,180.39,46,149.75,46,112V56a2,2,0,0,1,2-2h4.6L179.16,193.19A130.68,130.68,0,0,1,128,225.72ZM222,56v56c0,20.29-3.83,39.05-11.38,55.77a6,6,0,0,1-5.47,3.53,5.86,5.86,0,0,1-2.47-.54,6,6,0,0,1-3-7.93C206.53,147.67,210,130.57,210,112V56a2,2,0,0,0-2-2H98.52a6,6,0,1,1,0-12H208A14,14,0,0,1,222,56Z"}))],["regular",e.createElement(e.Fragment,null,e.createElement("path",{d:"M53.92,34.62A8,8,0,0,0,40.26,42,16,16,0,0,0,32,56v56c0,52.72,25.52,84.67,46.93,102.19,23.06,18.86,46,25.27,47,25.53a8,8,0,0,0,4.2,0c1.36-.37,31.27-8.78,57.09-34.72l14.89,16.38a8,8,0,1,0,11.84-10.76Zm74.07,189a128.48,128.48,0,0,1-38.92-21.81C61.82,179.51,48,149.3,48,112l0-56h3.71L176.41,193.15A129.26,129.26,0,0,1,128,223.62ZM224,56v56c0,20.58-3.89,39.61-11.56,56.59A8,8,0,1,1,197.86,162c6.73-14.89,10.14-31.71,10.14-50V56L98.52,56a8,8,0,1,1,0-16H208A16,16,0,0,1,224,56Z"}))],["thin",e.createElement(e.Fragment,null,e.createElement("path",{d:"M51,37.31A4,4,0,0,0,45,42.69l1.31,1.44A12,12,0,0,0,36,56v56c0,51.16,24.73,82.12,45.47,99.1,22.4,18.32,44.55,24.5,45.48,24.76a4,4,0,0,0,2.1,0c1.37-.37,32.56-9.14,58.23-36.71L205,218.69a4,4,0,1,0,5.92-5.38Zm77,190.51a132.23,132.23,0,0,1-41.71-23.11C58.23,181.63,44,150.44,44,112V56a4,4,0,0,1,4-4H53.5L181.88,193.21C160.23,216.7,133.58,226.06,128,227.82ZM220,56v56c0,20-3.77,38.49-11.2,54.94a4,4,0,0,1-3.65,2.36,4.06,4.06,0,0,1-1.65-.36,4,4,0,0,1-2-5.29c7-15.41,10.49-32.79,10.49-51.65V56a4,4,0,0,0-4-4H98.52a4,4,0,1,1,0-8H208A12,12,0,0,1,220,56Z"}))]]),Be=new Map([["bold",e.createElement(e.Fragment,null,e.createElement("path",{d:"M116,132V96a12,12,0,0,1,24,0v36a12,12,0,0,1-24,0Zm12,56a16,16,0,1,0-16-16A16,16,0,0,0,128,188ZM228,56v56c0,54.29-26.32,87.22-48.4,105.29-23.71,19.39-47.44,26-48.44,26.29a12.1,12.1,0,0,1-6.32,0c-1-.28-24.73-6.9-48.44-26.29C54.32,199.22,28,166.29,28,112V56A20,20,0,0,1,48,36H208A20,20,0,0,1,228,56Zm-24,4H52v52c0,35.71,13.09,64.69,38.91,86.15A126.14,126.14,0,0,0,128,219.38a126.28,126.28,0,0,0,37.09-21.23C190.91,176.69,204,147.71,204,112Z"}))],["duotone",e.createElement(e.Fragment,null,e.createElement("path",{d:"M216,56v56c0,96-88,120-88,120S40,208,40,112V56a8,8,0,0,1,8-8H208A8,8,0,0,1,216,56Z",opacity:"0.2"}),e.createElement("path",{d:"M120,136V96a8,8,0,0,1,16,0v40a8,8,0,0,1-16,0Zm8,48a12,12,0,1,0-12-12A12,12,0,0,0,128,184ZM224,56v56c0,52.72-25.52,84.67-46.93,102.19-23.06,18.86-46,25.27-47,25.53a8,8,0,0,1-4.2,0c-1-.26-23.91-6.67-47-25.53C57.52,196.67,32,164.72,32,112V56A16,16,0,0,1,48,40H208A16,16,0,0,1,224,56Zm-16,0L48,56l0,56c0,37.3,13.82,67.51,41.07,89.81A128.25,128.25,0,0,0,128,223.62a129.3,129.3,0,0,0,39.41-22.2C194.34,179.16,208,149.07,208,112Z"}))],["fill",e.createElement(e.Fragment,null,e.createElement("path",{d:"M208,40H48A16,16,0,0,0,32,56v56c0,52.72,25.52,84.67,46.93,102.19,23.06,18.86,46,25.27,47,25.53a8,8,0,0,0,4.2,0c1-.26,23.91-6.67,47-25.53C198.48,196.67,224,164.72,224,112V56A16,16,0,0,0,208,40ZM120,96a8,8,0,0,1,16,0v40a8,8,0,0,1-16,0Zm8,88a12,12,0,1,1,12-12A12,12,0,0,1,128,184Z"}))],["light",e.createElement(e.Fragment,null,e.createElement("path",{d:"M122,136V96a6,6,0,0,1,12,0v40a6,6,0,0,1-12,0Zm6,26a10,10,0,1,0,10,10A10,10,0,0,0,128,162ZM222,56v56c0,51.94-25.12,83.4-46.2,100.64-22.73,18.6-45.27,24.89-46.22,25.15a6,6,0,0,1-3.16,0c-1-.26-23.49-6.55-46.22-25.15C59.12,195.4,34,163.94,34,112V56A14,14,0,0,1,48,42H208A14,14,0,0,1,222,56Zm-12,0a2,2,0,0,0-2-2H48a2,2,0,0,0-2,2v56c0,37.75,13.94,68.39,41.44,91.06A130.94,130.94,0,0,0,128,225.72a131.17,131.17,0,0,0,40.56-22.66C196.06,180.39,210,149.75,210,112Z"}))],["regular",e.createElement(e.Fragment,null,e.createElement("path",{d:"M120,136V96a8,8,0,0,1,16,0v40a8,8,0,0,1-16,0Zm8,48a12,12,0,1,0-12-12A12,12,0,0,0,128,184ZM224,56v56c0,52.72-25.52,84.67-46.93,102.19-23.06,18.86-46,25.27-47,25.53a8,8,0,0,1-4.2,0c-1-.26-23.91-6.67-47-25.53C57.52,196.67,32,164.72,32,112V56A16,16,0,0,1,48,40H208A16,16,0,0,1,224,56Zm-16,0L48,56l0,56c0,37.3,13.82,67.51,41.07,89.81A128.25,128.25,0,0,0,128,223.62a129.3,129.3,0,0,0,39.41-22.2C194.34,179.16,208,149.07,208,112Z"}))],["thin",e.createElement(e.Fragment,null,e.createElement("path",{d:"M124,136V96a4,4,0,0,1,8,0v40a4,4,0,0,1-8,0Zm4,28a8,8,0,1,0,8,8A8,8,0,0,0,128,164ZM220,56v56c0,51.16-24.73,82.12-45.47,99.1-22.4,18.32-44.55,24.5-45.48,24.76a4,4,0,0,1-2.1,0c-.93-.26-23.08-6.44-45.48-24.76C60.73,194.12,36,163.16,36,112V56A12,12,0,0,1,48,44H208A12,12,0,0,1,220,56Zm-8,0a4,4,0,0,0-4-4H48a4,4,0,0,0-4,4v56c0,38.44,14.23,69.63,42.29,92.71A132.23,132.23,0,0,0,128,227.82a132.45,132.45,0,0,0,41.71-23.11C197.77,181.63,212,150.44,212,112Z"}))]]),Qe=e.forwardRef((r,a)=>e.createElement(ee,{ref:a,...r,weights:Ke}));Qe.displayName="LockKeyOpenIcon";const ge=e.forwardRef((r,a)=>e.createElement(ee,{ref:a,...r,weights:Pe}));ge.displayName="ShieldSlashIcon";const pe=ge,ve=e.forwardRef((r,a)=>e.createElement(ee,{ref:a,...r,weights:Be}));ve.displayName="ShieldWarningIcon";const Y=ve;var We={VITE_API_HOST_URL:"https://modelworks.ai/api"};const F=We.VITE_API_HOST_URL;U([]);const Ge=async(r,a,l)=>{var u;try{const c=(await r.get(`${F}/secrets/circuits/by_circuit_version_uid/${l}`)).data.payload;return c?Object.keys(c).map(o=>({key:o,value:c[o],circuit_uid:a})):[]}catch(n){if(n instanceof T){if(((u=n.response)==null?void 0:u.status)===404)return[];throw n}else return console.error("Error fetching secrets:",n),"An unexpected error occurred"}},Ye=async(r,a,l,u)=>{var n;try{const o=(await r.post(`${F}/secrets/circuits/by_circuit_version_uid/${l}`,u)).data.payload;if(!o)return"No secret data returned from server";const f=Object.keys(o)[0];return{key:f,value:o[f],circuit_uid:a,is_secret_public:(n=o[f])==null?void 0:n.is_secret_public}}catch(c){return c instanceof T?q(c):(console.error("Error creating secret:",c),"An unexpected error occurred")}},Je=async(r,a,l,u)=>{var n;try{const o=(await r.put(`${F}/secrets/circuits/by_circuit_version_uid/${l}`,u)).data.payload;if(!o)return"No secret data returned from server";const f=Object.keys(o)[0];return{key:f,value:o[f],circuit_uid:a,is_secret_public:(n=o[f])==null?void 0:n.is_secret_public}}catch(c){return c instanceof T?q(c):(console.error("Error updating secret:",c),"An unexpected error occurred")}},Xe=async(r,a,l,u)=>{try{const c=(await r.delete(`${F}/secrets/circuits/by_circuit_version_uid/${l}`,{data:u})).data.payload;if(!c)return"No secret data returned from server";const o=Object.keys(c)[0];return{key:o,value:c[o],circuit_uid:a}}catch(n){return n instanceof T?q(n):(console.error("Error deleting secret:",n),"An unexpected error occurred")}},q=r=>{if(r.response)switch(r.response.status){case 400:return"Bad Request: Invalid circuit or circuit version UID";case 401:return"Unauthorized: Invalid session token";case 404:return"Not Found: The requested resource was not found";default:return`Error: ${r.response.statusText}`}else return console.error("Axios error:",r),"An unexpected error occurred"},Ue=async(r,a)=>{try{return(await r.get(`${F}/secrets/circuits/by_circuit_version_uid/${a}/check`)).data.payload}catch(l){return l instanceof T?q(l):(console.error("Error checking secrets:",l),"An unexpected error occurred")}},et=(r,a)=>{var N,_,H,M;const[l,u]=O(xe),n=fe(),c=Ne(),o=Ze({navigate:n,setState:u}),f=e.useMemo(()=>a?_e(r,a):null,[r,a]),p=e.useMemo(()=>a?He(r,a):null,[r,a]),k=e.useMemo(()=>U({circuitSecret:[],satisfied:[],missing:[],overrides:[]}),[]),V=e.useMemo(()=>U(null,()=>{}),[]),[y]=O(f||k),[,g]=O(p||V),S=["secrets",r,a],w=["checkSecrets",r,a],{data:v,isLoading:d,error:K,refetch:E}=de({queryKey:w,enabled:!!((_=(N=l.session)==null?void 0:N.disk)!=null&&_.sessionToken)&&!!a,queryFn:async()=>{if(!a)throw new Error("Missing required parameters");const s=await Ue(o,a);if(typeof s=="string")throw new Error(s);return g({satisfied:s.satisfied,missing:s.missing,overrides:s.overrides}),s}}),{data:C,isLoading:$,error:P}=de({queryKey:S,queryFn:async()=>{if(!r||!a)throw new Error("Circuit UID or circuit version UID is missing");const s=await Ge(o,r,a);if(typeof s=="string")throw new Error(s);return g({circuitSecret:s}),s},enabled:!!((M=(H=l.session)==null?void 0:H.disk)!=null&&M.sessionToken)&&!!r&&!!a}),Z=G({mutationFn:async s=>{if(!r||!a)throw new Error("Circuit UID or circuit version UID is missing");const m=await Ye(o,r,a,s);if(typeof m=="string")throw new Error(m);return m},onSuccess:async s=>{c.setQueryData(S,(m=[])=>[...m,s]),g({circuitSecret:[...y.circuitSecret||[],s]}),await E()}}),D=G({mutationFn:async s=>{if(!r||!a)throw new Error("Circuit UID or circuit version UID is missing");const m=await Je(o,r,a,s);if(typeof m=="string")throw new Error(m);return m},onSuccess:async s=>{var m;c.setQueryData(S,(x=[])=>x.map(b=>b.key===s.key?s:b)),g({circuitSecret:((m=y.circuitSecret)==null?void 0:m.map(x=>x.key===s.key?s:x))||[]}),await E()}}),L=G({mutationFn:async s=>{if(!r||!a)throw new Error("Circuit UID or circuit version UID is missing");return await Xe(o,r,a,{key:s,value:""}),s},onSuccess:async s=>{var m;c.setQueryData(S,(x=[])=>x.filter(b=>b.key!==s)),g({circuitSecret:((m=y.circuitSecret)==null?void 0:m.filter(x=>x.key!==s))||[]}),await E()}});return{secrets:C,secretCheck:v,secretData:y,refetchSecretCheck:E,isLoading:$,isCheckingSecrets:d,error:P,checkSecretsError:K,addSecret:Z.mutate,updateSecret:D.mutate,deleteSecret:L.mutate,isAddingSecret:Z.isPending,isUpdatingSecret:D.isPending,isDeletingSecret:L.isPending}},tt=({isOpen:r,onClose:a,secretName:l,secretValue:u,secretDescription:n,onChangeName:c,onChangeValue:o,onSubmit:f,isSubmitting:p,isNameEditable:k=!0,isAuthorMode:V=!1,shareAccess:y=!1,onChangeShareAccess:g})=>{const S=e.useMemo(()=>!!(l!=null&&l.trim())&&!!(u!=null&&u.trim())&&!p,[l,u,p]),w=()=>{f(l,u,y)},v=e.useRef(null);return e.useEffect(()=>{r&&v.current&&v.current.focus()},[r]),t.jsx(Me,{open:r,onOpenChange:d=>{d||a()},title:"Add Secret",subtitle:"Add a secret to this circuit that can be referenced in your JSON files.",maxWidth:"md",contentClassName:"relative",showCancel:!0,cancelText:"Cancel",onCancel:a,cancelDisabled:p,cancelVariant:"outline",actionText:p?"Adding…":"Add Secret",onAction:w,actionDisabled:!S,actionLoading:p,actionVariant:"default",buttonSize:"lg",children:t.jsxs("div",{className:"",children:[t.jsxs("div",{className:"",children:[t.jsx("label",{className:"text-xs font-medium text-zinc-300",children:"Secret Name"}),k?t.jsx(ke,{value:l,onChange:d=>c(d.target.value.trim()),onKeyDown:d=>{d.key===" "&&d.preventDefault()},placeholder:"Secret Name",disabled:p,className:"w-full border-zinc-800 bg-zinc-950 text-zinc-100 placeholder:text-zinc-500"}):t.jsx("div",{className:"mt-1 font-mono text-sm text-white bg-transparent",children:l}),n&&t.jsxs("div",{className:"mt-3",children:[t.jsx("label",{className:"text-xs font-medium text-zinc-300",children:"Description"}),t.jsx("div",{className:"mt-1 text-xs text-white bg-transparent whitespace-pre-wrap",children:n})]})]}),t.jsxs("div",{className:"mt-5 mb-5",children:[t.jsx("label",{className:"text-xs font-medium text-zinc-300",children:"Secret Value"}),t.jsx(Ve,{ref:v,value:u,onChange:d=>o(d.target.value),placeholder:"Secret Value",disabled:p,className:"mt-2 min-h-[110px] w-full resize-none border-zinc-800 bg-zinc-950 text-zinc-100 placeholder:text-zinc-500"})]}),V&&t.jsxs("div",{className:"mt-5",children:[t.jsx("label",{className:"text-xs font-medium text-zinc-300",children:"Access Mode"}),t.jsxs(ze,{value:y?"shared":"private",onValueChange:d=>{g&&g(d==="shared")},className:"flex flex-col gap-3 mt-2",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(ue,{value:"private",id:"keep-private",className:"mt-1 border-neutral-600"}),t.jsxs("div",{children:[t.jsx(me,{htmlFor:"keep-private",children:"Keep Private"}),t.jsx("p",{className:"text-xs text-zinc-500 mt-0.5",children:"Require users to provide their own key. The key is stored securely and never exposed."})]})]}),t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(ue,{value:"shared",id:"share-access",className:"mt-1 border-neutral-600"}),t.jsxs("div",{children:[t.jsx(me,{htmlFor:"share-access",children:"Share Access"}),t.jsx("p",{className:"text-xs text-zinc-500 mt-0.5",children:"Securely share this key with anyone who runs your circuit. The key is encrypted and never exposed to users. Earn money when others use your circuit."})]})]})]})]}),p?t.jsx("div",{className:"text-xs text-zinc-500",children:"Saving secret…"}):null]})})},rt=h.div`
  border: ${({$bordered:r})=>r?"1px solid #333":"none"};
  color: white;
  padding: ${({$bordered:r})=>r?"15px":"0"};
  border-radius: ${({$bordered:r})=>r?"5px":"0"};
  margin-top: ${({$bordered:r})=>r?"20px":"0"};
  font-size: 14px;
  font-weight: bold;
`,at=h.div`
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid #333;
  padding-bottom: 20px;
`,st=h.div`
  display: flex;
  align-items: center;
  gap: 12px;
`,nt=h.div`
  font-weight: bold;
  font-size: 18px;
  color: #ffffff;
`,ct=h.div`
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  font-size: 11px;
  color: #cccccc;
`,J=h.div`
  display: flex;
  align-items: center;
  gap: 6px;
`,X=h.span`
  font-size: 11px;
  color: #bbbbbb;
`,he=h.div`
  margin: 5px 0 15px 0px;
  font-size: 12px;
  color: white;
`,ot=h.div`
	display: flex;
	align-items: center;
	padding: 12px 0;
	position: relative;

	&:not(:last-child) {
		margin-bottom: 5px;
	}

	background-color: #090909;
`,it=h.div`
  margin-right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px; /* ensures space even if svg baseline acts weird */
  line-height: 0; /* prevents inline svg baseline quirks */
`,lt=h.div`
  display: flex;
  flex-direction: column;
  color: #ccc;
  flex-grow: 1;
`,dt=h.span`
	font-weight: bold;
`,ut=h.div`
  display: flex;
  align-items: center;
  margin-top: 4px;
`,mt=h.span`
	font-size: 12px;
	color: #ddd;
	font-family: "Courier New", Courier, monospace;
	font-weight: 600;
	overflow-wrap: anywhere;
`,pt=h.span`
	font-size: 14px;
	color: #888;
	margin-top: 2px;
	font-weight: normal;
`,ht=h.div`
  display: flex;
  align-items: center;
  margin-left: 16px;
`,_t=({circuit:r,circuitVersion:a,framed:l=!0,showHeader:u=!0})=>{const n=a.detected_secrets??[],c=n.filter(i=>i.is_root_circuit),o=n.filter(i=>!i.is_root_circuit),f=r.uid,{secrets:p,addSecret:k,updateSecret:V,deleteSecret:y,isAddingSecret:g,isUpdatingSecret:S,isDeletingSecret:w,refetchSecretCheck:v,secretData:d}=et(f,a.uid),[K]=O(xe),E=fe(),C=K.user.disk.currentUser,$=(C==null?void 0:C.uid)===r.user_uid,{useUserByUIDQuery:P}=Fe(),{data:Z}=P(r.user_uid,{enabled:!!r.user_uid}),D=(Z==null?void 0:Z.username)??"unknown",[L,N]=e.useState(!1),[_,H]=e.useState(""),[M,s]=e.useState(""),[m,x]=e.useState(""),[b,te]=e.useState(!1),[B,Q]=e.useState(null);e.useEffect(()=>{a.uid&&v()},[a.uid,v]);const ye=i=>{if(!C){E("/login");return}H(i.key),x(i.description||"");const A=p==null?void 0:p.find(j=>j.key===i.key);s((A==null?void 0:A.value)??""),N(!0)},re=()=>{N(!1),H(""),s(""),x(""),te(!1)},Ae=async()=>{const i=p==null?void 0:p.find(A=>A.key===_);i?await V({...i,value:M,is_secret_public:b}):await k({key:_,value:M,is_secret_public:b}),re(),await v()},Se=i=>{Q(i)},ae=()=>{Q(null)},we=async()=>{B&&(await y(B),Q(null),await v())},R=(i,A)=>t.jsxs(Re,{children:[t.jsx(Oe,{asChild:!0,children:t.jsx("span",{style:{display:"inline-flex",alignItems:"center"},children:A})}),t.jsx(qe,{className:"border-zinc-800 bg-zinc-950 text-zinc-100",children:i})]}),se=(i,A)=>{var ce,oe,ie;const j=i.key,be=((ce=d==null?void 0:d.satisfied)==null?void 0:ce.some(I=>I.key===j))??!1,ne=((oe=d==null?void 0:d.overrides)==null?void 0:oe.some(I=>I.key===j))??!1,je=((ie=d==null?void 0:d.missing)==null?void 0:ie.some(I=>I.key===j))??!1,Ee=!i.is_root_circuit,Ce=`${D}/${i.circuit_name}`;let z;return je?z=R("Secret is missing and must be provided",t.jsx(pe,{size:24,weight:"fill",color:"#ff4d4f"})):ne?z=R("You have provided an override for this secret",t.jsx(le,{size:24,weight:"regular",color:"#10b981"})):be?z=R("Secret is provided by the circuit or environment",t.jsx(Y,{size:24,weight:"fill",color:"#f4a623"})):z=R("Secret state unknown",t.jsx(Y,{size:24,weight:"duotone",color:"#999999"})),t.jsxs(ot,{children:[t.jsx(it,{children:z}),t.jsxs(lt,{children:[t.jsx(dt,{children:Ce}),t.jsx(ut,{children:t.jsx(mt,{children:j})}),i.description&&t.jsx(pt,{children:i.description})]}),t.jsx(ht,{children:Ee?t.jsx(W,{type:"button",variant:"secondary",className:"h-7 px-3 text-xs",onClick:()=>E(`/${D}/${i.circuit_name}`),children:"Go To Circuit"}):ne?t.jsx(W,{type:"button",variant:"destructive",className:"h-7 px-3 text-xs",onClick:()=>Se(j),children:$?"Remove":"Remove Override"}):t.jsx(W,{type:"button",variant:"secondary",className:"h-7 px-3 text-xs",onClick:()=>ye(i),children:"Provide"})})]},`${i.circuit_uid}-${i.circuit_version_uid}-${j}-${A}`)};return t.jsxs(t.Fragment,{children:[t.jsx(Le,{delayDuration:150,children:t.jsxs(rt,{$bordered:l,children:[u&&t.jsx(at,{children:t.jsxs(st,{children:[t.jsx(nt,{children:"Secrets Management"}),t.jsx($e,{variant:"secondary",className:"text-xs hover:!bg-neutral-700",children:"Only visible to you"})]})}),n.length>0&&t.jsxs(ct,{children:[t.jsxs(J,{children:[t.jsx(pe,{size:16,weight:"fill",color:"#ff4d4f"}),t.jsx(X,{children:"Missing & required"})]}),t.jsxs(J,{children:[t.jsx(Y,{size:16,weight:"fill",color:"#f4a623"}),t.jsx(X,{children:"Circuit / environment secret"})]}),t.jsxs(J,{children:[t.jsx(le,{size:16,weight:"regular",color:"#10b981"}),t.jsx(X,{children:"Your override"})]})]}),n.length===0?t.jsx("div",{style:{marginTop:8},children:t.jsx(Te,{title:"No Secrets Required",message:"This circuit version does not declare any secrets. You can use this circuit without configuring secrets.",phosphorIcon:De})}):t.jsxs(t.Fragment,{children:[c.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(he,{children:"Secrets for this Circuit"}),c.map(se)]}),o.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(he,{children:"Remote Embedded Secrets"}),o.map(se)]})]})]})}),t.jsx(tt,{isOpen:L,onClose:re,isNameEditable:!1,secretName:_,secretValue:M,secretDescription:m,onChangeName:H,onChangeValue:s,onSubmit:Ae,isSubmitting:g||S||w,isAuthorMode:$&&!r.is_private,shareAccess:b,onChangeShareAccess:te}),t.jsx(Ie,{open:B!==null,onOpenChange:i=>{i||ae()},title:"Delete secret",description:"Do you want to delete this secret?",confirmText:w?"Deleting…":"Delete",cancelText:"Cancel",confirmVariant:"destructive",confirmLoading:w,confirmDisabled:w,onConfirm:we,onCancel:ae,maxWidth:"sm"})]})};export{_t as S,Qe as o,et as u};