import{r as x,j as s,B as b,F as p,x as C,c3 as w,aT as N,b as v}from"./index-BeDhuS24.js";import{C as V}from"./CheckboxField-BhwpagjA.js";import{I as $}from"./InputField-E2g5qJCn.js";import{N as S}from"./NumberField-CH6-YRbT.js";import{S as h}from"./SelectField-CgXiODUe.js";const A=x.memo(a=>{const{defaultValues:n,label:r,detail:c,type:i,onSubmit:f}=a,[t,o]=x.useState(n||[]);x.useEffect(()=>{o(n||[])},[n]);const d=x.useCallback(()=>{t.length>0?o([...t,""]):o([""])},[t]),e=x.useCallback(()=>f(i==="number"?t.filter(l=>typeof l=="number"):t.filter(l=>!!l)),[i,t,f]);return s.jsxs("fieldset",{className:"fieldset gap-2",children:[r&&s.jsx("legend",{className:"fieldset-legend",children:r}),s.jsx("div",{className:"flex flex-row flex-wrap gap-2",children:t.map((l,m)=>s.jsxs("div",{className:"join min-w-xs",children:[s.jsx("input",{className:"input join-item",onBlur:u=>{const j=Array.from(t);j[m]=i==="number"?u.target.value?u.target.valueAsNumber:"":u.target.value,o(j)},type:i,defaultValue:Number.isNaN(l)?"":l}),s.jsx(b,{className:"btn btn-error btn-outline join-item",onClick:()=>{const u=Array.from(t);u.splice(m,1),o(u)},children:s.jsx(p,{icon:C})})]},`${l}-${m}`))}),s.jsxs("div",{className:"flex flex-row flex-wrap gap-2 items-center mt-1",children:[s.jsx(b,{onClick:d,className:"btn btn-sm btn-square btn-success ms-2",children:s.jsx(p,{icon:w})}),s.jsx(b,{onClick:e,className:"btn btn-sm btn-square btn-primary",children:s.jsx(p,{icon:N})}),c&&s.jsx("p",{className:"label",children:c})]})]})}),F=x.memo(a=>{const{names:n,label:r,detail:c,defaultsChecked:i,onSubmit:f}=a,[t,o]=x.useState(i||[]);x.useEffect(()=>{o(i||[])},[i]);const d=x.useCallback(l=>{let m=Array.from(t);l.target.checked?m.push(l.target.name):m=m.filter(u=>u!==l.target.name),o(m)},[t]),e=x.useCallback(()=>f(t),[t,f]);return s.jsxs("fieldset",{className:"fieldset gap-2",children:[r&&s.jsx("legend",{className:"fieldset-legend",children:r}),s.jsx("div",{className:"flex flex-row flex-wrap gap-2",children:n.map(l=>s.jsxs("label",{className:"label",children:[s.jsx("input",{name:l,className:"checkbox",type:"checkbox",onChange:d,checked:t.includes(l)}),l]},l))}),s.jsxs("div",{className:"flex flex-row flex-wrap gap-2 items-center mt-1",children:[s.jsx(b,{onClick:e,className:"btn btn-sm btn-square btn-primary",children:s.jsx(p,{icon:N})}),s.jsx("span",{className:"label",children:c})]})]})}),E=(a,n,r,c,i,f,t)=>{let o=n.type;if(Array.isArray(o))o=o.find(e=>e!=="null");else if(n.oneOf)return;const d=`${i}-${a}-${n.type}-${n.title}`;switch(o){case"boolean":return s.jsx(V,{name:a,label:a,detail:t,onChange:e=>!e.target.validationMessage&&c({[a]:e.target.checked}),required:f,defaultChecked:r??!1},d);case"integer":case"number":return n.enum?s.jsxs(h,{name:a,label:a,detail:t,onChange:e=>!e.target.validationMessage&&c({[a]:Number.parseInt(e.target.value,10)}),required:f,defaultValue:r??"",children:[s.jsx("option",{value:"",disabled:!0,children:"-"}),n.enum.map(e=>s.jsx("option",{value:e,children:e},e))]},d):s.jsx(S,{name:a,label:a,detail:t,onSubmit:(e,l)=>l&&c({[a]:e===""?null:e}),min:n.minimum,max:n.maximum,required:f,defaultValue:r??""},d);case"string":return n.enum?s.jsxs(h,{name:a,label:a,detail:t,onChange:e=>!e.target.validationMessage&&c({[a]:e.target.value}),required:f,defaultValue:r??"",children:[s.jsx("option",{value:"",disabled:!0,children:"-"}),n.enum.map(e=>s.jsx("option",{value:e,children:e},e))]},d):s.jsx($,{name:a,label:a,detail:t,type:"text",onBlur:e=>!e.target.validationMessage&&c({[a]:e.target.value}),required:f,defaultValue:r??""},d);case"array":{const e=n.items;if(e&&typeof e=="object"&&"type"in e){if(e.enum)return s.jsx(F,{names:e.enum,label:a,detail:t,onSubmit:l=>c({[a]:l}),defaultsChecked:r??[]});if(e.type==="string"||e.type==="number")return s.jsx(A,{defaultValues:r??[],label:a,detail:t,onSubmit:l=>c({[a]:l}),type:e.type})}}}},g=(a,n,r,c,i,f=[],t=!1)=>{const o=[],d=[];for(const e in n){const l=n[e];if(!(typeof l=="boolean"||l.readOnly))if(l.properties)t||d.push(s.jsxs("div",{className:"list",children:[s.jsx("h3",{className:"list-row p-3 text-lg",children:l.title||e}),g(a,l.properties,r[e]||{},async m=>c({[e]:m}),i+1,l.required)]},`${i}-${e}`));else{const m=l.oneOf?.find(u=>typeof u=="object"&&u.properties);if(m)(e!=="log_syslog"||r.log_output.includes("syslog"))&&d.push(s.jsxs("div",{className:"list",children:[s.jsx("h3",{className:"list-row p-3 text-lg",children:m.title||l.title||e}),g(a,m.properties,r[e]||{},async u=>c({[e]:u}),i+1,m.required)]},`${i}-${e}`));else{const u=E(e,l,r[e],c,i,f.includes(e),l.description?a(l.description,{defaultValue:l.description}):void 0);u&&o.push(s.jsx("div",{className:`list-row p-3 ${i!==0?` ps-${4+i*4}`:""}`,children:u},`${i}-${e}`))}}}return d.length>0?o.concat(d):o};function y({schema:a,data:n,set:r,rootOnly:c}){const{t:i}=v("settingsSchemaDescriptions");return s.jsx("div",{className:"list bg-base-100",children:a.properties&&g(i,a.properties,n,r,0,a.required,c)})}export{y as S};
