1import{v as e,n as a,r as t,bb as s,j as l,B as n,b9 as i,w as p,x as o,bc as r,bd as d,be as c,bf as m,bg as u,bh as x,bi as h,bj as b,bk as f,z as j,F as y,G as _,H as v,az as g,aj as A,a as N,ao as B,I as L,J as T}from"./index-Cu6nzwse.js";const C=({onBack:e})=>l.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[l.jsx(n,{variant:"ghost",size:"sm",onClick:e,className:"p-2",children:l.jsx(i,{className:"h-5 w-5"})}),l.jsxs("div",{children:[l.jsx("h1",{className:"text-2xl md:text-3xl font-bold text-[#434343]",children:"Edit Mini App"}),l.jsx("p",{className:"text-gray-600 mt-1",children:"Update your AI-powered application"})]})]}),S=({formData:e,setFormData:a,availableAppTypes:i,selectedAppType:A,loading:N,isAdmin:B,onSubmit:L,onClose:T})=>{var C;const[S,D]=t.useState({}),[O,w]=t.useState({}),[E,k]=t.useState("option-a");t.useEffect(()=>{var a;if(e.default_user_prompt&&(null==(a=null==A?void 0:A.input_schema)?void 0:a.properties))try{const a=JSON.parse(e.default_user_prompt);a.optionA&&a.optionB?(D(a.optionA),w(a.optionB)):(D(a),w({}))}catch{D({}),w({})}},[null==A?void 0:A.id]);const F=()=>{var e;if(null==(e=null==A?void 0:A.input_schema)?void 0:e.properties){const e=Object.keys(S).length>0&&Object.values(S).some(e=>null!=e&&""!==e),t=Object.keys(O).length>0&&Object.values(O).some(e=>null!=e&&""!==e);if(e&&t){const e={optionA:S,optionB:O};a(a=>({...a,default_user_prompt:JSON.stringify(e)}))}else a(e?e=>({...e,default_user_prompt:JSON.stringify(S)}):e=>({...e,default_user_prompt:""}))}};return l.jsx(p,{children:l.jsx(o,{className:"p-6",children:l.jsxs("form",{onSubmit:L,className:"space-y-6",children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx(r,{htmlFor:"name",children:"App Name *"}),l.jsx(d,{id:"name",value:e.name,onChange:e=>a(a=>({...a,name:e.target.value})),placeholder:"Enter app name...",required:!0})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(r,{htmlFor:"description",children:"Description"}),l.jsx(c,{id:"description",value:e.description,onChange:e=>a(a=>({...a,description:e.target.value})),placeholder:"Brief description of your app...",rows:3})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(r,{htmlFor:"app_type_name",children:"App Type *"}),l.jsxs(m,{value:e.app_type_name,onValueChange:e=>a(a=>({...a,app_type_name:e})),disabled:s(e),children:[l.jsx(u,{children:l.jsx(x,{placeholder:"Select an app type..."})}),l.jsx(h,{children:i.map(e=>l.jsx(b,{value:e.name,children:e.display_name},e.id))})]}),s(e)&&l.jsx("p",{className:"text-xs text-muted-foreground",children:"Agents keep their type â the archetype is set at creation."})]}),A&&l.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[l.jsxs("p",{className:"text-sm text-gray-600 mb-2",children:[l.jsx("strong",{children:"App Type:"})," ",A.display_name]}),A.description&&l.jsx("p",{className:"text-sm text-gray-500",children:A.description})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(r,{htmlFor:"button_text",children:"Custom Button Text"}),l.jsx(d,{id:"button_text",value:e.button_text,onChange:e=>a(a=>({...a,button_text:e.target.value})),placeholder:"e.g., Generate Story, Create Image..."}),l.jsx("p",{className:"text-xs text-gray-500",children:"Leave empty to use default button text"})]}),B&&l.jsxs("div",{className:"flex items-center space-x-2",children:[l.jsx(f,{id:"is_default",checked:e.is_default,onCheckedChange:e=>a(a=>({...a,is_default:!!e}))}),l.jsx(r,{htmlFor:"is_default",children:"Make this a default app (available to all users)"})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(r,{htmlFor:"system_prompt",children:"System Prompt *"}),l.jsx(c,{id:"system_prompt",value:e.system_prompt,onChange:e=>a(a=>({...a,system_prompt:e.target.value})),placeholder:"Enter system prompt...",rows:4,required:!0})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(r,{htmlFor:"optionALabel",children:"Option A Tab Label"}),l.jsx(d,{id:"optionALabel",value:e.optionALabel,onChange:e=>a(a=>({...a,optionALabel:e.target.value})),placeholder:"Example A"})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(r,{htmlFor:"optionBLabel",children:"Option B Tab Label"}),l.jsx(d,{id:"optionBLabel",value:e.optionBLabel,onChange:e=>a(a=>({...a,optionBLabel:e.target.value})),placeholder:"Example B"})]}),l.jsx("div",{className:"space-y-4",children:A&&(null==(C=A.input_schema)?void 0:C.properties)&&Object.keys(A.input_schema.properties).length>0?l.jsxs("div",{children:[l.jsx(r,{className:"text-sm font-medium text-gray-700",children:"Default User Inputs"}),l.jsx("p",{className:"text-sm text-gray-500",children:"Set up default values for your app. You can provide just Option A, or both Option A and Option B to give users a choice."}),l.jsxs(j,{value:E,onValueChange:k,children:[l.jsxs(y,{children:[l.jsx(_,{value:"option-a",children:e.optionALabel||"Example A"}),l.jsx(_,{value:"option-b",children:e.optionBLabel||"Example B"})]}),l.jsx(v,{value:"option-a",children:l.jsx(g,{appType:A,value:S,onChange:e=>{D(e),setTimeout(F,0)},label:"Default Values - Option A",ignoreRequired:!0})}),l.jsxs(v,{value:"option-b",children:[l.jsx("div",{className:"p-3 bg-blue-50 border border-blue-200 rounded-lg mb-4",children:l.jsxs("p",{className:"text-sm text-blue-800",children:[l.jsx("strong",{children:"Optional:"})," If you provide Option B, users will see tabs allowing them to choose between two different sets of default inputs."]})}),l.jsx(g,{appType:A,value:O,onChange:e=>{w(e),setTimeout(F,0)},label:"Default Values - Option B",ignoreRequired:!0})]})]})]}):l.jsx("div",{className:"p-4 bg-yellow-50 border border-yellow-200 rounded-lg",children:l.jsx("p",{className:"text-sm text-yellow-800",children:"This app type doesn't have an input schema defined. Please configure the app type's input schema first."})})}),l.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 pt-4",children:[l.jsx(n,{type:"button",variant:"outline",onClick:T,className:"flex-1",disabled:N,children:"Cancel"}),l.jsx(n,{type:"submit",className:"flex-1 bg-[#A493D9] hover:bg-[#A493D9]/90",disabled:N||!e.app_type_name,children:N?"Updating...":"Update App"})]})]})})})},D=()=>{const{id:i}
1=A(),p=N(),[o,r]=B.useState(!0),[d,c]=B.useState(null);B.useEffect(()=>{i&&(async()=>{r(!0);const{data:e,error:a}=await L.from("app_instances").select("*").eq("id",i).single();c(a?null:e),r(!1)})()},[i]);const{formData:m,setFormData:u,availableAppTypes:x,selectedAppType:h,loading:b,isAdmin:f,handleSubmit:j}=(l=>{const{profile:n}=e(),i=(null==n?void 0:n.is_admin)||!1,{appTypes:p,loading:o}=a(),[r,d]=t.useState({name:"",description:"",system_prompt:"",default_user_prompt:"",app_type_name:"",is_default:!1,button_text:"",optionALabel:"Example A",optionBLabel:"Example B"}),c=(i?p:p.filter(e=>e.is_enabled)).filter(e=>s(l)?"agent"===e.name:"agent"!==e.name),m=p.find(e=>e.name===r.app_type_name);return t.useEffect(()=>{var e,a,t;l&&d({name:l.name,description:l.description||"",system_prompt:l.system_prompt,default_user_prompt:l.default_user_prompt||"",app_type_name:l.app_type_name,is_default:l.is_default,button_text:(null==(e=l.configuration)?void 0:e.buttonText)||"",optionALabel:(null==(a=l.configuration)?void 0:a.exampleALabel)||"Example A",optionBLabel:(null==(t=l.configuration)?void 0:t.exampleBLabel)||"Example B"})},[l]),{formData:r,setFormData:d,availableAppTypes:c,selectedAppType:m,loading:o,isAdmin:i,handleSubmit:e=>a=>{var t;if(a.preventDefault(),!r.name.trim()||!r.app_type_name)return;const s={...l.configuration||{},...r.button_text?{buttonText:r.button_text}:{},exampleALabel:r.optionALabel||"Example A",...(null==(t=l.configuration)?void 0:t.exampleBLabel)||r.default_user_prompt&&(()=>{try{const e=JSON.parse(r.default_user_prompt);return e.optionB&&Object.keys(e.optionB).length>0}catch{return!1}})()?{exampleBLabel:r.optionBLabel||"Example B"}:{}};e({name:r.name,description:r.description,system_prompt:r.system_prompt,default_user_prompt:r.default_user_prompt,app_type_name:r.app_type_name,is_default:r.is_default,user_id:r.is_default?null:l.user_id,configuration:s,version:l.version||"1.0.0"})}}})(d);return o||b?l.jsx("div",{className:"min-h-screen flex items-center justify-center",children:l.jsx("div",{className:"animate-spin rounded-full h-32 w-32 border-b-2 border-[#A493D9]"})}):d?l.jsx("div",{className:"min-h-screen",children:l.jsxs("div",{className:"container mx-auto px-4 py-6 max-w-2xl",children:[l.jsx(C,{onBack:()=>p("/")}),l.jsx(S,{formData:m,setFormData:u,availableAppTypes:x,selectedAppType:h,loading:b,isAdmin:f,onSubmit:j(async e=>{try{const{error:a}=await L.from("app_instances").update(e).eq("id",d.id);if(a)throw a;T({title:"Success",description:"App updated successfully!"}),p("/")}catch(a){T({title:"Error",description:"Failed to update app",variant:"destructive"})}}),onClose:()=>p("/")})]})}):l.jsx("div",{className:"min-h-screen flex items-center justify-center",children:l.jsxs("div",{className:"text-center",children:[l.jsx("h2",{className:"text-2xl font-bold text-gray-800 mb-4",children:"App Not Found"}),l.jsx(n,{onClick:()=>p("/"),className:"bg-[#A493D9] hover:bg-[#A493D9]/90",children:"Back to Dashboard"})]})})};export{D as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.