import{r as d,j as e,L as h,S as A,n as L,p as R,q as B,s as I,bl as _,I as N,bH as z,cn as D,co as J,aT as $,cp as H,cq as M}from"./index-CfKY7XrC.js";function U(t,r){if(typeof t!="string"||!r||r.length===0)return t;const i=t.trim();if(r.includes(i))return i;try{const n=JSON.parse(i);if(typeof n=="string"&&r.includes(n))return n}catch{}return t}function K(t,r){if(!t)return{};const i=r?.properties;return i?Object.fromEntries(Object.entries(t).map(([n,j])=>[n,U(j,i[n]?.enum)])):{...t}}function F(t){return t.split(/[_-]/).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function Y({control:t}){const r=[t.set_by,t.set_at?z(t.set_at):null].filter(Boolean).join(" · ");return e.jsxs(D,{children:[e.jsx(J,{asChild:!0,children:e.jsxs($,{variant:"outline",className:"gap-1 border-emerald-500/30 bg-emerald-500/10 text-[10px] uppercase tracking-wide text-emerald-600 dark:text-emerald-400",children:[e.jsx(H,{className:"h-3 w-3"}),"You"]})}),e.jsxs(M,{className:"max-w-xs space-y-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Human-owned field"}),t.note?e.jsx("div",{className:"text-xs text-primary-foreground/90",children:t.note}):null,r?e.jsx("div",{className:"text-[11px] text-primary-foreground/70",children:r}):null]})]})}function G(t){const r={};for(const[i,n]of Object.entries(t))n==null||n===""||Array.isArray(n)&&n.length===0||(r[i]=n);return r}function Q({schema:t,initialValues:r={},onValuesChange:i,readonly:n=!1,fieldControls:j}){const b=t,p=b?.properties,T=new Set(b?.required??[]),C=JSON.stringify(r),g=d.useMemo(()=>{try{return K(JSON.parse(C),t)}catch{return{}}},[C,t]),[v,S]=d.useState(g),y=d.useRef(i);y.current=i,d.useEffect(()=>{S(g)},[g]),d.useEffect(()=>{y.current(G(v))},[v]);const o=d.useCallback((s,a)=>{S(c=>({...c,[s]:a}))},[]);return!p||Object.keys(p).length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"No additional fields required for this entity type."}):e.jsx("div",{className:"space-y-4",children:Object.entries(p).map(([s,a])=>{if("x-measure"in a||"x-dimension"in a)return null;const c=a.description||F(s),f=T.has(s),u=n||a.readOnly===!0,m=v[s],O=j?.[s],x=O?e.jsx(Y,{control:O}):null;if(a.enum&&Array.isArray(a.enum))return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(h,{htmlFor:s,className:"flex items-center gap-1.5",children:[e.jsxs("span",{children:[c,f&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),x]}),a.description&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.description}),e.jsxs(A,{value:m??"",onValueChange:l=>o(s,l||void 0),disabled:u,children:[e.jsx(L,{id:s,children:e.jsx(R,{placeholder:`Select ${c.toLowerCase()}`})}),e.jsx(B,{children:a.enum.map(l=>e.jsx(I,{value:l,children:F(l)},l))})]})]},s);if(a.type==="boolean")return e.jsxs("div",{className:"flex items-center space-x-2 py-1",children:[e.jsx(_,{id:s,checked:m??!1,onCheckedChange:l=>o(s,l),disabled:u}),e.jsxs(h,{htmlFor:s,className:"flex items-center gap-1.5 font-normal",children:[c,x]})]},s);if(a.type==="number"||a.type==="integer")return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(h,{htmlFor:s,className:"flex items-center gap-1.5",children:[e.jsxs("span",{children:[c,f&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),x]}),e.jsx(N,{id:s,type:"number",value:m??"",onChange:l=>o(s,l.target.value===""?void 0:Number(l.target.value)),placeholder:`Enter ${c.toLowerCase()}`,disabled:u})]},s);if(a.type==="array"&&a.items?.type==="string"){const l=m??[];return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(h,{htmlFor:s,className:"flex items-center gap-1.5",children:[e.jsxs("span",{children:[c,f&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),x]}),e.jsx(N,{id:s,value:l.join(", "),onChange:V=>{const E=V.target.value.split(",").map(q=>q.trim()).filter(Boolean);o(s,E.length>0?E:void 0)},placeholder:"Enter comma-separated values",disabled:u}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Separate values with commas"})]},s)}const w=a.format==="uri"||a.format==="url";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(h,{htmlFor:s,className:"flex items-center gap-1.5",children:[e.jsxs("span",{children:[c,f&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),x]}),a.description&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.description}),e.jsx(N,{id:s,type:w?"url":"text",value:m??"",onChange:l=>o(s,l.target.value||void 0),placeholder:w?"https://example.com":`Enter ${c.toLowerCase()}`,disabled:u})]},s)})})}export{Q as D,K as a,G as c,U as n};
