@dipusevilla/componentes-iu 1.1.22 → 1.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -89,14 +89,14 @@ attempted value: ${i}
89
89
  self.postMessage({ success: false, error: err.toString() });
90
90
  }
91
91
  };
92
- `,u=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(u),h=new Worker(f),p=setTimeout(()=>{h.terminate(),URL.revokeObjectURL(f),c(new Error("Timeout: La validación tardó demasiado."))},a);h.onmessage=m=>{clearTimeout(p),h.terminate(),URL.revokeObjectURL(f),m.data.success?i(m.data.result):(console.warn("Validation Script Error:",m.data.error),i("Error en script de validación"))},h.onerror=m=>{clearTimeout(p),h.terminate(),URL.revokeObjectURL(f),c(m)},h.postMessage({code:e,context:t,translations:o})})}const D$={ds:{fileUploader:{browse:"Document",dragDrop:"Drag your files here or click to browse",view:"View",remove:"Remove"},form:{fieldRequired:"Required field",invalidEmail:"Invalid email",submit:"Submit",sending:"Sending…",saveSuccess:"Saved successfully!",saveError:"There are errors in the form"},editor:{inspector:{field:"Field Inspector",tab:"Tab Inspector",section:"Section Inspector"},actions:{move:"Move",moveLeft:"Move left",moveRight:"Move right",add:"Add",addTab:"Tab to the right",addSection:"Add section",addRow:"Add row",addColumn:"Add column",delete:"Delete",deleteTab:"Delete tab",deleteColumn:"Remove last column",duplicate:"Duplicate",cancel:"Cancel"},confirmations:{deleteField:{title:"Delete field",message:"Are you sure you want to delete this field?"},deleteColumn:{title:"Delete column",message:"Are you sure you want to delete the last column? Fields it contains will be lost."},deleteRow:{title:"Delete row",message:"Are you sure you want to delete this row? All fields it contains will be lost."},deleteSection:{title:"Delete section",message:"Are you sure you want to delete this section? All fields it contains will be lost."}},title:"Form Schema Editor",context:"Context:",modes:{design:"Designer",preview:"Preview",code:"Code"},codeViewer:{copy:"Copy code",copied:"Copied",lines:"lines",format:"Format"},toolbar:{export:"Export",import:"Import JSON",shortcuts:"Shortcuts",showRelations:"Show relations",hideRelations:"Hide relations",toggleSidePanel:{open:"Open side panel",close:"Close side panel"}},importModal:{trigger:"Generate from object",triggerTitle:"Generate form from JSON or TypeScript",title:"Generate from JSON or TypeScript",labels:{formTitle:"Form Title",formId:"Form ID",layout:"Layout (cols)",input:"Input (paste JSON or TypeScript interface/type)"},placeholders:{layout:{auto:"Auto",col1:"1 column",col2:"2 columns",col3:"3 columns",col4:"4 columns"}},actions:{cancel:"Cancel",generate:"Generate Form",generating:"Generating..."},messages:{success:"Form generated successfully.",error:"Could not generate form."}}},fields:{defaults:{text:{label:"Text",placeholder:"Type…"},number:{label:"Number",placeholder:"0"},email:{label:"Email",placeholder:"user@domain.com"},password:{label:"Password",placeholder:"••••••••"},tel:{label:"Phone",placeholder:"600 000 000"},url:{label:"URL",placeholder:"https://example.com"},textarea:{label:"Comment",placeholder:"Write your comment…"},select:{label:"Select",placeholder:"Select an option"},checkbox:{label:"Checkbox"},date:{label:"Date"},file:{label:"File"},search:{label:"Search",placeholder:"Search..."}},validation:{required:"Required field",invalidEmail:"Invalid email",invalidUrl:"Invalid URL",invalidPhone:"Invalid phone",invalidID:"Invalid identity document",invalidIBAN:"Invalid IBAN",minLength:"Minimum {{count}} characters",maxLength:"Maximum {{count}} characters",pattern:"Invalid format",numberMin:"Must be greater than or equal to {{min}}",numberMax:"Must be less than or equal to {{max}}",step:"Must be a multiple of {{step}}",integerOnly:"Must be an integer",positiveOnly:"Must be a positive number",selectMin:"Select at least {{count}} options",selectMax:"Select at most {{count}} options",dateMin:"Date must be after {{date}}",dateMax:"Date must be before {{date}}",disallowPast:"Past dates are not allowed",disallowFuture:"Future dates are not allowed",number:"Must be a number",date:"Invalid date",invalidOption:"Invalid option",mustCheck:"You must check this box",invalidFile:"Invalid file",invalidFileType:"File type not allowed",fileMaxCount:"Max. {{count}} file(s)",fileMaxSize:"File must not exceed {{size}}MB",minItems:"Minimum {{count}} items",maxItems:"Maximum {{count}} items"}}}},S$={ds:{fileUploader:{browse:"Documento",dragDrop:"Arrastra tus archivos aquí o haz clic para buscarlos",view:"Ver",remove:"Eliminar"},form:{fieldRequired:"Campo obligatorio",invalidEmail:"Email inválido",submit:"Enviar",sending:"Enviando…",saveSuccess:"¡Guardado con éxito!",saveError:"Hay errores en el formulario"},editor:{inspector:{field:"Inspector de campo",tab:"Inspector de pestaña",section:"Inspector de sección"},actions:{move:"Mover",moveLeft:"Mover a la izquierda",moveRight:"Mover a la derecha",add:"Añadir",addTab:"Pestaña a la derecha",addSection:"Añadir sección",addRow:"Añadir fila",addColumn:"Añadir columna",delete:"Eliminar",deleteTab:"Eliminar pestaña",deleteColumn:"Quitar última columna",duplicate:"Duplicar",cancel:"Cancelar"},confirmations:{deleteField:{title:"Eliminar campo",message:"¿Estás seguro de que quieres eliminar este campo?"},deleteColumn:{title:"Eliminar columna",message:"¿Estás seguro de que quieres eliminar la última columna? Se perderán los campos que contiene."},deleteRow:{title:"Eliminar fila",message:"¿Estás seguro de que quieres eliminar esta fila? Se perderán todos los campos que contiene."},deleteSection:{title:"Eliminar sección",message:"¿Estás seguro de que quieres eliminar esta sección? Se perderán todos los campos que contiene."}},title:"Editor de Esquema de Formulario",context:"Contexto:",modes:{design:"Diseñar",preview:"Vista Previa",code:"Código"},codeViewer:{copy:"Copiar código",copied:"Copiado",lines:"líneas",format:"Formato"},toolbar:{export:"Exportar",import:"Importar JSON",shortcuts:"Configurar atajos",showRelations:"Mostrar relaciones",hideRelations:"Ocultar relaciones",toggleSidePanel:{open:"Abrir panel lateral",close:"Cerrar panel lateral"}},importModal:{trigger:"Generar desde objeto",triggerTitle:"Generar formulario desde JSON o TypeScript",title:"Generar desde JSON o TypeScript",labels:{formTitle:"Título del formulario",formId:"ID del formulario",layout:"Distribución (cols)",input:"Entrada (pega JSON o una interface/type de TypeScript)"},placeholders:{layout:{auto:"Auto",col1:"1 columna",col2:"2 columnas",col3:"3 columnas",col4:"4 columnas"}},actions:{cancel:"Cancelar",generate:"Generar formulario",generating:"Generando..."},messages:{success:"Formulario generado correctamente.",error:"No se pudo generar el formulario."}}},fields:{defaults:{text:{label:"Texto",placeholder:"Escribe…"},number:{label:"Número",placeholder:"0"},email:{label:"Email",placeholder:"usuario@dominio.com"},password:{label:"Contraseña",placeholder:"••••••••"},tel:{label:"Teléfono",placeholder:"600 000 000"},url:{label:"URL",placeholder:"https://ejemplo.com"},textarea:{label:"Comentario",placeholder:"Escribe tu comentario…"},select:{label:"Seleccionar",placeholder:"Seleccione una opción"},checkbox:{label:"Casilla"},date:{label:"Fecha"},file:{label:"Archivo"},search:{label:"Búsqueda",placeholder:"Buscar..."}},validation:{required:"Campo obligatorio",invalidEmail:"Email inválido",invalidUrl:"URL inválida",invalidPhone:"Teléfono inválido",invalidID:"Documento de identidad inválido",invalidIBAN:"IBAN inválido",minLength:"Mínimo {{count}} caracteres",maxLength:"Máximo {{count}} caracteres",pattern:"Formato inválido",numberMin:"Debe ser mayor o igual a {{min}}",numberMax:"Debe ser menor o igual a {{max}}",step:"Debe ser múltiplo de {{step}}",integerOnly:"Debe ser un número entero",positiveOnly:"Debe ser un número positivo",selectMin:"Selecciona al menos {{count}} opciones",selectMax:"Selecciona como máximo {{count}} opciones",dateMin:"La fecha debe ser posterior a {{date}}",dateMax:"La fecha debe ser anterior a {{date}}",disallowPast:"No se permiten fechas pasadas",disallowFuture:"No se permiten fechas futuras",number:"Debe ser un número",date:"Fecha inválida",invalidOption:"Opción inválida",mustCheck:"Debes marcar esta casilla",invalidFile:"Archivo inválido",invalidFileType:"Tipo de archivo no permitido",fileMaxCount:"Máx. {{count}} fichero(s)",fileMaxSize:"El archivo no debe superar {{size}}MB",minItems:"Mínimo {{count}} elementos",maxItems:"Máximo {{count}} elementos"}}}};qe.use(AT).init({resources:{en:{translation:D$},es:{translation:S$}},lng:"es",fallbackLng:"es",interpolation:{escapeValue:!1}});const A$=e=>{qe.changeLanguage(e)},D2="TRWAGMYFPDXBNJZSQVHLCKE",N$=["X","Y","Z"];function F$(e){if(!/^\d{8}[A-Z]$/.test(e))return!1;const t=parseInt(e.substring(0,8),10),r=e.charAt(8),n=D2.charAt(t%23);return r===n}function _$(e){if(!/^[XYZ]\d{7}[A-Z]$/.test(e))return!1;const t=e.charAt(0),n=N$.indexOf(t).toString()+e.substring(1),a=parseInt(n.substring(0,8),10),o=e.charAt(8),i=D2.charAt(a%23);return o===i}function M$(e){if(!/^[A-Z]\d{7}[A-Z0-9]$/.test(e))return!1;const t=e.charAt(0),r=e.substring(1,8),n=e.charAt(8);let a=0;for(let f=0;f<7;f++){const h=parseInt(r.charAt(f),10);if(f%2===0){const p=h*2;a+=Math.floor(p/10)+p%10}else a+=h}const o=a%10,i=o===0?0:10-o,c="JABCDEFGHI".charAt(i);return["A","B","E","H"].includes(t)?n===i.toString():n===c||n===i.toString()}function R$(e){if(!e||e.length<9)return!1;const t=e.toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"");return/^\d{8}[A-Z]$/.test(t)?F$(t):/^[XYZ]\d{7}[A-Z]$/.test(t)?_$(t):/^[A-Z]\d{7}[A-Z0-9]$/.test(t)?M$(t):!1}const O$=/^\s*(?:\+?\d{1,4}[\s-]*)?(?:\(?\d{2,4}\)?[\s-]*)?\d{3,4}[\s-]?\d{3,4}\s*$/;function S2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"")}function L$(e){const t=S2(e);if(t.length<15||t.length>34||!/^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(t))return!1;const r=t.slice(4)+t.slice(0,4);let n=0;for(const a of r){const o=a.charCodeAt(0);if(o>=65&&o<=90){const i=String(o-55);for(let c=0;c<i.length;c++)n=(n*10+(i.charCodeAt(c)-48))%97}else n=(n*10+(a.charCodeAt(0)-48))%97}return n===1}function T$(e){return e.validation??{}}function $$(e){return!!e.multiple}function I$(e){const t=e.maxFiles;return typeof t=="number"?t:void 0}function B$(e){const t=e.options;return Array.isArray(t)?t.map(r=>r==null?void 0:r.value).filter(r=>r!==void 0):[]}function P$(e){if(!e)return{exts:[],mimes:[]};const t=e.split(",").map(a=>a.trim().toLowerCase()).filter(Boolean),r=[],n=[];for(const a of t)a.startsWith(".")?r.push(a):a.includes("/")&&n.push(a);return{exts:r,mimes:n}}function vt(e,t){const r=typeof e=="string"?e:t;return qe.isInitialized&&(r.startsWith("forms.")||r.startsWith("ds."))?qe.t(r):r}function br(e,t){let r=e;return t.required&&(r=r.required(vt(t.requiredMessage||(typeof t.required=="string"?t.required:void 0),"ds.fields.validation.required"))),t.customFn&&(r=r.test({name:"custom-script-validation",message:"${path} no es válido",test:async function(n,a){if(n==null||n==="")return!0;const o=a.parent;let i={};try{if(qe.isInitialized){const c=qe.getResourceBundle(qe.language,"translation")||{},d=(u,f="")=>{for(const h of Object.keys(u)){const p=f?`${f}.${h}`:h,m=u[h];typeof m=="string"?i[p]=m:typeof m=="object"&&m!==null&&d(m,p)}};d(c)}}catch(c){console.warn("Error extracting translations for validation:",c)}try{const c=await j2(t.customFn,{value:n,form:o,customMessages:t.customMessages||{}},{translations:i});if(c===!0)return!0;if(typeof c=="string"){const d=qe.isInitialized&&c.startsWith("forms.")?qe.t(c):c;return this.createError({message:d})}return!1}catch(c){return console.error("Custom Validation Error",c),this.createError({message:"Error ejecutando validación: "+String(c)})}}})),r}function Hn(e,t){var n,a,o;let r=e;return((n=t.minLength)==null?void 0:n.value)!=null&&(r=r.min(t.minLength.value,vt(t.minLength.message,"ds.fields.validation.minLength"))),((a=t.maxLength)==null?void 0:a.value)!=null&&(r=r.max(t.maxLength.value,vt(t.maxLength.message,"ds.fields.validation.maxLength"))),((o=t.pattern)==null?void 0:o.value)instanceof RegExp&&(r=r.matches(t.pattern.value,vt(t.pattern.message,"ds.fields.validation.pattern"))),r}function V$(e,t){var n,a,o,i;let r=e;if(((n=t.numberMin)==null?void 0:n.value)!=null&&(r=r.min(t.numberMin.value,vt(t.numberMin.message,"ds.fields.validation.numberMin"))),((a=t.numberMax)==null?void 0:a.value)!=null&&(r=r.max(t.numberMax.value,vt(t.numberMax.message,"ds.fields.validation.numberMax"))),t.positiveOnly&&(r=r.moreThan(0,vt(t.positiveOnly,"ds.fields.validation.positiveOnly"))),t.integerOnly&&(r=r.integer(vt(t.integerOnly,"ds.fields.validation.integerOnly"))),((o=t.step)==null?void 0:o.value)!=null){const c=Number(t.step.value),d=t.step.message||"ds.fields.validation.step";r=r.test("step",d,u=>{if(u==null||Number.isNaN(u)||c===0)return!0;const f=u/c;return Math.abs(f-Math.round(f))<1e-9})}return((i=t.pattern)==null?void 0:i.value)instanceof RegExp&&(r=r.test("pattern-number",t.pattern.message||"ds.fields.validation.pattern",c=>c==null||t.pattern.value.test(String(c)))),r}function Z$(e,t){var n,a;let r=e;return(n=t.dateMin)!=null&&n.value&&(r=r.min(new Date(t.dateMin.value),vt(t.dateMin.message,"ds.fields.validation.dateMin"))),(a=t.dateMax)!=null&&a.value&&(r=r.max(new Date(t.dateMax.value),vt(t.dateMax.message,"ds.fields.validation.dateMax"))),t.disallowPast&&(r=r.min(new Date,vt(t.disallowPast,"ds.fields.validation.disallowPast"))),t.disallowFuture&&(r=r.max(new Date,vt(t.disallowFuture,"ds.fields.validation.disallowFuture"))),r}function z$(e){var r,n,a,o;const t=T$(e);switch(e.type){case"text":case"password":case"textarea":case"search":{let i=xn().trim();return i=Hn(i,t),br(i,t)}case"dni":{let i=xn().trim();return i=Hn(i,t),i=i.test("dni-valid",vt("ds.fields.validation.invalidID","Documento de identidad inválido"),c=>c==null||c===""?!0:R$(c)),br(i,t)}case"email":{let i=xn().trim().email(vt(t.emailMessage,"ds.fields.validation.invalidEmail"));return i=Hn(i,t),br(i,t)}case"url":{let i=xn().trim().url(vt(t.urlMessage,"ds.fields.validation.invalidUrl"));return i=Hn(i,t),br(i,t)}case"tel":{let i=xn().trim();return i=Hn(i,t),(r=t.pattern)!=null&&r.value||(i=i.matches(O$,vt(t.phoneMessage,"ds.fields.validation.invalidPhone"))),br(i,t)}case"iban":{let i=xn().transform((c,d)=>d===""||d===null||d===void 0?"":typeof d=="string"?S2(d):c);return i=Hn(i,t),i=i.test("iban-valid",vt("ds.fields.validation.invalidIBAN","IBAN inválido"),c=>c==null||c===""?!0:L$(String(c))),br(i,t)}case"number":{let i=m2().transform((c,d)=>{if(d===""||d===null||d===void 0)return;const u=typeof d=="string"?Number(d.replace(",",".")):c;return Number.isNaN(u)?NaN:u}).typeError(vt(t.typeError,"ds.fields.validation.number"));return i=V$(i,t),br(i,t)}case"date":{let i=od().nullable().typeError(vt(t.typeError,"ds.fields.validation.date")).transform((c,d)=>d?new Date(d):null);return i=Z$(i,t),br(i,t)}case"select":case"optionGroup":{const i=$$(e),c=B$(e);if(i){let d=id().of(c.length?So().oneOf(c,"ds.fields.validation.invalidOption"):So());return t.required&&(d=d.min(1,t.requiredMessage||(typeof t.required=="string"?t.required:"ds.fields.validation.required"))),d}else{let d=xn().trim();return d=Hn(d,t),c.length&&(d=d.oneOf(c,"ds.fields.validation.invalidOption")),br(d,t)}}case"checkbox":{let i=f2();return t.required&&(i=i.oneOf([!0],t.requiredMessage||"ds.fields.validation.mustCheck")),i}case"file":{const i=e,{exts:c,mimes:d}=P$(i.accept),u=I$(e);let f=So().test("file-shape","ds.fields.validation.invalidFile",h=>(h==null,!0));if((n=t.fileMaxSizeMB)!=null&&n.value){const h=Number(t.fileMaxSizeMB.value)*1024*1024,p=t.fileMaxSizeMB.message||"ds.fields.validation.fileMaxSize";f=f.test("file-max-size",p,m=>m?(Array.isArray(m)?m:typeof FileList<"u"&&m instanceof FileList?Array.from(m):[m].filter(Boolean)).every(g=>typeof(g==null?void 0:g.size)!="number"||g.size<=h):!0)}return(c.length||d.length)&&(f=f.test("file-accept","ds.fields.validation.invalidFileType",h=>h?(Array.isArray(h)?h:typeof FileList<"u"&&h instanceof FileList?Array.from(h):[h].filter(Boolean)).every(v=>{var y,E,k,j;const g=((E=(y=v==null?void 0:v.name)==null?void 0:y.toLowerCase)==null?void 0:E.call(y))||"",b=((j=(k=v==null?void 0:v.type)==null?void 0:k.toLowerCase)==null?void 0:j.call(k))||"",w=c.length===0||c.some(A=>g.endsWith(A)),x=d.length===0||d.includes(b);return w&&x}):!0)),typeof u=="number"&&(f=f.test("file-max-files","ds.fields.validation.fileMaxCount",h=>h?(Array.isArray(h)?h:typeof FileList<"u"&&h instanceof FileList?Array.from(h):[h].filter(Boolean)).length<=u:!0)),f=br(f,t),f}case"array":{const i=e,c=i.items||[],d=A2(c);let u=id().of(sd(d));t.required&&(u=u.min(1,t.requiredMessage||(typeof t.required=="string"?t.required:"ds.fields.validation.required")));const f=i.validation;return(a=f==null?void 0:f.min)!=null&&a.value&&(u=u.min(f.min.value,f.min.message||"ds.fields.validation.minItems")),(o=f==null?void 0:f.max)!=null&&o.value&&(u=u.max(f.max.value,f.max.message||"ds.fields.validation.maxItems")),u}default:{const i=So();return br(i,t)}}}function A2(e){const t={};for(const r of e){const n=r;n!=null&&n.name&&(t[n.name]=z$(n))}return t}function ld(e){const t=A2(e.fields);return sd(t)}const N2=e=>{let t;const r=new Set,n=(u,f)=>{const h=typeof u=="function"?u(t):u;if(!Object.is(h,t)){const p=t;t=f??(typeof h!="object"||h===null)?h:Object.assign({},t,h),r.forEach(m=>m(t,p))}},a=()=>t,c={setState:n,getState:a,getInitialState:()=>d,subscribe:u=>(r.add(u),()=>r.delete(u))},d=t=e(n,a,c);return c},H$=(e=>e?N2(e):N2),W$=e=>e;function U$(e,t=W$){const r=C.useSyncExternalStore(e.subscribe,C.useCallback(()=>t(e.getState()),[e,t]),C.useCallback(()=>t(e.getInitialState()),[e,t]));return C.useDebugValue(r),r}const F2=e=>{const t=H$(e),r=n=>U$(t,n);return Object.assign(r,t),r},_2=(e=>e?F2(e):F2),Wn=_2(e=>({isActive:!1,formValues:{},systemContext:{},setRuntimeState:t=>e(r=>({...r,...t})),reset:()=>e({isActive:!1,formValues:{},systemContext:{}})}));function cd(e,t){return e?typeof e!="string"?String(e):e.replace(/\{\{([^}]+)\}\}/g,(r,n)=>{let o=n.trim().split(".").reduce((i,c)=>{if(!i)return;if(i[c]!==void 0)return i[c];const d=c.toLowerCase(),u=Object.keys(i).find(f=>f.toLowerCase()===d);return u?i[u]:void 0},t);return o!=null?String(o):r}):""}function zr({options:e,value:t,onChange:r,children:n,className:a,contentClassName:o}){const i=C.useRef(null),[c,d]=C.useState({left:0,width:0}),[u,f]=C.useState(!1),[h,p]=C.useState(!1),m=()=>{if(i.current){const{scrollLeft:g,scrollWidth:b,clientWidth:w}=i.current;f(g>0),p(g<b-w-1)}};C.useLayoutEffect(()=>{const g=i.current;if(!g)return;const b=()=>{const w=g.querySelector(`[data-value="${t}"]`);w&&d({left:w.offsetLeft,width:w.offsetWidth})};return b(),m(),window.addEventListener("resize",b),window.addEventListener("resize",m),()=>{window.removeEventListener("resize",b),window.removeEventListener("resize",m)}},[t,e]);const v=g=>{i.current&&i.current.scrollBy({left:g==="left"?-200:200,behavior:"smooth"})};return l.jsxs("div",{className:a,children:[l.jsxs("div",{className:"relative border-b border-[var(--color-ds-border-default-50)] group",children:[u&&l.jsx("div",{className:"absolute left-0 top-0 bottom-0 z-20 flex items-center bg-gradient-to-r from-[var(--color-ds-background-page)] to-transparent pr-4 pl-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:l.jsx("button",{type:"button",onClick:()=>v("left"),className:"p-1 rounded-full bg-[var(--color-ds-background-surface)] shadow-sm border border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-button-hover-bg)] hover:text-white transition-colors",children:l.jsx(x1,{className:"w-4 h-4"})})}),l.jsx("div",{ref:i,onScroll:m,className:"overflow-x-auto scrollbar-hidden flex items-center w-full relative",style:{scrollBehavior:"smooth"},children:l.jsxs("div",{className:"relative flex min-w-full px-1",children:[e.map(g=>{const b=g.value===t;return l.jsxs("button",{"data-value":g.value,role:"tab","aria-selected":b,onClick:()=>!g.disabled&&r(g.value),type:"button",className:ve("relative z-10 whitespace-nowrap px-4 py-2 transition-colors duration-150 ease-in-out font-medium text-sm focus:outline-none",b?"text-[var(--color-ds-background-accent)]":"text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]",g.disabled&&"opacity-50 cursor-not-allowed"),disabled:g.disabled,children:[g.icon&&l.jsx("span",{className:"mr-2 -ml-1 inline-block align-text-bottom",children:g.icon}),g.label]},g.value)}),l.jsx("span",{className:"absolute bottom-0 h-0.5 bg-[var(--color-ds-background-accent)] transition-all duration-200 ease-in-out z-20",style:{left:c.left,width:c.width}})]})}),h&&l.jsx("div",{className:"absolute right-0 top-0 bottom-0 z-20 flex items-center bg-gradient-to-l from-[var(--color-ds-background-page)] to-transparent pl-4 pr-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:l.jsx("button",{type:"button",onClick:()=>v("right"),className:"p-1 rounded-full bg-[var(--color-ds-background-surface)] shadow-sm border border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-button-hover-bg)] hover:text-white transition-colors",children:l.jsx(Ps,{className:"w-4 h-4"})})})]}),l.jsx("div",{className:ve("mt-4",o),children:n[t]})]})}const _a={sm:"text-ds-sm",md:"text-ds-md",lg:"text-ds-lg"},vi={sm:"h-5",md:"h-10",lg:"h-12"},bi={sm:"px-2",md:"px-2.5",lg:"px-3"},wi={sm:"1.5rem",md:"2.5rem",lg:"3rem"},xi={sm:"pr-9",md:"pr-11",lg:"pr-12"},q$={sm:"h-6 w-6",md:"h-8 w-8",lg:"h-10 w-10"};function yi({id:e,size:t,disabled:r,error:n,reserveErrorSpace:a,className:o,suffixButton:i,children:c,showDropdownIndicator:d}){var u;return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:ve("relative w-full",o),children:[c,d&&!i&&l.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-2 flex items-center",children:l.jsx(fr,{className:"h-4 w-4 text-[var(--color-ds-text-secondary)]"})}),i&&l.jsx("div",{className:"pointer-events-none absolute flex items-center",style:{top:2,bottom:2,right:4},children:l.jsx("div",{className:"pointer-events-auto",children:C.isValidElement(i)?C.cloneElement(i,{className:ve(q$[t],(u=i.props)==null?void 0:u.className)}):i})})]}),a?l.jsx("div",{className:"h-[1em]",children:n!=null&&n.message?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:n.message}):l.jsx("span",{"aria-hidden":"true",children:" "})}):n!=null&&n.message?l.jsx("div",{className:"pt-1",children:l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:n.message})}):null]})}function M2(e,t){C.useEffect(()=>{const r=n=>{e.current&&(e.current.contains(n.target)||t())};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[t,e])}function Xe(e){const{control:t,name:r,rules:n,defaultValue:a,options:o=[],loadOptions:i,reloadDeps:c=[],value:d,onChange:u,size:f="sm",width:h="100%",label:p,labelHidden:m=!1,info:v,infoHeader:g,hasError:b=!1,errorMessage:w="",reserveErrorSpace:x,disableErrorPlaceholder:y,disabled:E=!1,className:k,suffixButton:j,loading:A=!1,coerceFirstValid:S=!0,mode:_="menu",renderTrigger:O,renderOption:B,popupWidth:R,triggerClassName:I,onBlur:F,searchable:Z=!1,searchPlaceholder:ee="Buscar...",noOptionsText:Y="No se encontraron resultados"}=e,te=C.useId(),ae=r||te,[q,N]=C.useState(o),[L,ne]=C.useState(!!i);C.useEffect(()=>{if(!i){N(o);return}ne(!0),i().then(be=>N(be)).finally(()=>ne(!1))},[i,...c]),C.useEffect(()=>{i||N(o)},[o,i]);const K=be=>be.find(fe=>fe.value!==""&&fe.value!==void 0)??be[0],Q=(be,fe)=>{const xe=fe.trim().toLowerCase();return xe?be.filter(D=>String(D.label).toLowerCase().includes(xe)||String(D.value).toLowerCase().includes(xe)):be},he=typeof x=="boolean"?x:!!t,ie=h&&(h.includes(" ")||h.startsWith("w-")||h.startsWith("max-w-")||h.startsWith("min-w-")),me=ie?{maxWidth:"100%"}:{width:h,maxWidth:"100%"},ce=ve("flex flex-col",ie&&h,k);if(t&&r){const{field:be,fieldState:fe}=a5({name:r,control:t,rules:n,defaultValue:a});C.useEffect(()=>{if(!L&&q.length>0&&S){const D=be.value,G=q.some(re=>String(re.value)===String(D));(D===void 0||!G)&&be.onChange(K(q).value)}},[q,L,be,S]);const xe=p&&!m&&l.jsx(gr,{id:ae,text:p,size:f,info:v,infoHeader:g});if((_??"native")==="menu"){const[D,G]=C.useState(!1),[re,W]=C.useState(""),H=C.useRef(null);M2(H,()=>{G(!1),W("")});const X=q.find(V=>String(V.value)===String(be.value)),M=Z?Q(q,re):q;return l.jsxs("div",{className:ce,style:me,children:[xe,A||L?l.jsx(Pr,{width:"100%",height:wi[f],variant:"rect",className:"rounded-lg"}):l.jsx(yi,{id:ae,size:f,disabled:E,error:fe.error,reserveErrorSpace:typeof y=="boolean"?!y:he,className:k,suffixButton:j,showDropdownIndicator:!0,children:l.jsxs("div",{className:"relative w-full",ref:H,children:[l.jsx("button",{type:"button",onClick:()=>{E||G(V=>{const T=!V;return T||W(""),T})},onBlur:()=>{be.onBlur(),F==null||F()},className:ve("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none text-left flex items-center",_a[f],vi[f],bi[f],j&&xi[f],fe.error?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default-hover)]",I),"aria-haspopup":"listbox","aria-expanded":D,children:O?O(X):(X==null?void 0:X.label)??"—"}),D&&l.jsxs("div",{role:"listbox",className:"custom-scroll absolute z-50 mt-1 rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-xl p-1 max-h-72 overflow-auto",style:{width:R??"100%"},children:[Z&&l.jsx("div",{className:"sticky top-0 z-10 bg-[var(--color-ds-background-page)] p-1",children:l.jsx("input",{type:"text",value:re,onChange:V=>W(V.target.value),onClick:V=>V.stopPropagation(),placeholder:ee,className:"w-full rounded-lg border border-[var(--color-ds-border-default)] bg-[var(--color-ds-background-page)] px-2 py-2 text-sm outline-none"})}),M.length>0?M.map(V=>{const T=String(V.value)===String(be.value);return l.jsx("button",{role:"option","aria-selected":T,type:"button",onClick:()=>{be.onChange(V.value),G(!1),W("")},className:ve("w-full rounded-lg px-2 py-1.5 text-left transition-all duration-200",_a[f],T?"bg-[var(--color-ds-background-neutral)] font-medium text-[var(--color-ds-text-primary)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)] hover:pl-3"),children:B?B(V,T):V.label},V.value)}):l.jsx("div",{className:"px-2 py-2 text-sm text-[var(--color-ds-text-secondary)]",children:Y})]})]})})]})}return l.jsxs("div",{className:ce,style:me,children:[xe,A||L?l.jsx(Pr,{width:"100%",height:wi[f],variant:"rect",className:"rounded-lg"}):l.jsx(yi,{id:ae,size:f,disabled:E,error:fe.error,reserveErrorSpace:typeof y=="boolean"?!y:he,className:k,suffixButton:j,showDropdownIndicator:!0,children:l.jsx("select",{id:ae,value:be.value,onChange:D=>be.onChange(D.target.value),onBlur:()=>{be.onBlur(),F==null||F()},disabled:E,className:ve("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none leading-none",_a[f],vi[f],bi[f],j&&xi[f],fe.error?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)]",I),children:q.map(D=>l.jsx("option",{value:D.value,className:"bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-primary)]",children:D.label},D.value))})})]})}C.useEffect(()=>{if(!t&&q.length>0&&S){const be=q.some(xe=>String(xe.value)===String(d));(d===void 0||d===""||!be)&&u&&u(K(q).value)}},[q,d,u,t,S]);const le=p&&!m&&l.jsx(gr,{id:ae,text:p,size:f,info:v,infoHeader:g});if((_??"native")==="menu"){const[be,fe]=C.useState(!1),[xe,D]=C.useState(""),G=C.useRef(null);M2(G,()=>{fe(!1),D("")});const re=q.find(H=>String(H.value)===String(d)),W=Z?Q(q,xe):q;return l.jsxs("div",{className:ce,style:me,children:[le,A||L?l.jsx(Pr,{width:"100%",height:wi[f],variant:"rect",className:"rounded-lg"}):l.jsx(yi,{id:ae,size:f,disabled:E,error:b?{message:w}:void 0,reserveErrorSpace:typeof y=="boolean"?!y:!!(x??!1),className:k,suffixButton:j,showDropdownIndicator:!0,children:l.jsxs("div",{className:"relative w-full",ref:G,children:[l.jsx("button",{type:"button",onClick:()=>{E||fe(H=>{const X=!H;return X||D(""),X})},onBlur:F,className:ve("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none text-left flex items-center",_a[f],vi[f],bi[f],j&&xi[f],b?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default-hover)]",I),"aria-haspopup":"listbox","aria-expanded":be,children:O?O(re):(re==null?void 0:re.label)??"—"}),be&&l.jsxs("div",{role:"listbox",className:"custom-scroll absolute z-50 mt-1 rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-xl p-1 max-h-72 overflow-auto",style:{width:R??"100%"},children:[Z&&l.jsx("div",{className:"sticky top-0 z-10 bg-[var(--color-ds-background-page)] p-1",children:l.jsx("input",{type:"text",value:xe,onChange:H=>D(H.target.value),onClick:H=>H.stopPropagation(),placeholder:ee,className:"w-full rounded-lg border border-[var(--color-ds-border-default)] bg-[var(--color-ds-background-page)] px-2 py-2 text-sm outline-none"})}),W.length>0?W.map(H=>{const X=String(H.value)===String(d);return l.jsx("button",{role:"option","aria-selected":X,type:"button",onClick:()=>{u==null||u(H.value),fe(!1),D("")},className:ve("w-full rounded-lg px-2 py-1.5 text-left transition-all duration-200",_a[f],X?"bg-[var(--color-ds-background-neutral)] font-medium text-[var(--color-ds-text-primary)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)] hover:pl-3"),children:B?B(H,X):H.label},H.value)}):l.jsx("div",{className:"px-2 py-2 text-sm text-[var(--color-ds-text-secondary)]",children:Y})]})]})})]})}return l.jsxs("div",{className:ce,style:me,children:[le,A||L?l.jsx(Pr,{width:"100%",height:wi[f],variant:"rect",className:"rounded-lg"}):l.jsx(yi,{id:ae,size:f,disabled:E,error:b?{message:w}:void 0,reserveErrorSpace:typeof y=="boolean"?!y:!!(x??!1),className:k,suffixButton:j,showDropdownIndicator:!0,children:l.jsx("select",{id:ae,value:d,onChange:be=>u==null?void 0:u(be.target.value),onBlur:F,disabled:E,className:ve("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none leading-none",_a[f],vi[f],bi[f],j&&xi[f],b?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)]"),children:q.map(be=>l.jsx("option",{value:be.value,className:"bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-primary)]",children:be.label},be.value))})})]})}const R2={sm:"text-ds-sm",md:"text-ds-md",lg:"text-ds-lg"};function O2(e){var t;e.preventDefault(),e.stopPropagation(),(t=e.nativeEvent)!=null&&t.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()}function dd({groupLabel:e,inputs:t=[],separator:r=l.jsx("span",{className:"px-1 select-none",children:"/"}),useSeparator:n=!1,className:a,showVisibleLabel:o=!1,size:i="sm",width:c,respectChildWidths:d=!1}){const u=t.length,f=c&&(c.includes(" ")||c.startsWith("w-")||c.startsWith("max-w-")||c.startsWith("min-w-")),h=f?void 0:c?{width:c}:void 0;return l.jsxs("div",{"data-input-group-root":!0,role:"group",className:ve("flex flex-col w-full",f&&c,a),style:h,onDoubleClick:O2,onDoubleClickCapture:O2,onClickCapture:p=>{var g;const m=p.target;!!((g=m==null?void 0:m.closest)!=null&&g.call(m,'input,select,textarea,button,[data-interactive="true"]'))||p.stopPropagation()},children:[l.jsx("label",{className:ve("sr-only pb-2",R2[i]),children:e}),o&&l.jsx("label",{className:ve("pb-2",R2[i]),children:e}),l.jsx("div",{className:"flex items-stretch flex-nowrap w-full min-w-0",children:t.map((p,m)=>{const{width:v,className:g,options:b,loadOptions:w,info:x,infoHeader:y,...E}=p,k=Array.isArray(b)||typeof w=="function";let j="rounded-lg";!n&&u>1&&(m===0?j="rounded-l-lg rounded-r-none":m===u-1?j="rounded-r-lg rounded-l-none !rounded-l-none":j="rounded-none !rounded-l-none !rounded-r-none");const A=d?v:void 0,S=typeof A=="string"&&A.split(/\s+/).some(R=>R.startsWith("w-")||R.includes(":w-")),_=ve("inline-flex items-stretch",A?"flex-shrink-0":"flex-1 min-w-0",typeof A=="string"&&S?A:void 0,!n&&u>1&&m>0?"-ml-px focus-within:z-10 relative":void 0),O=A?typeof A=="string"&&S?void 0:{width:A}:void 0,B=ve(g,"w-full",j);return l.jsxs(C.Fragment,{children:[l.jsx("div",{className:_,style:O,children:k?l.jsx(Xe,{...E,size:i,className:g,triggerClassName:ve("w-full",j),options:b,loadOptions:w,"data-interactive":"true",info:x,infoHeader:y,mode:"menu",searchable:!0,searchPlaceholder:B5("common.search"),noOptionsText:B5("common.noMatches")}):l.jsx(je,{...E,size:i,className:B,"data-interactive":"true",info:x,infoHeader:y})}),n&&m<u-1&&l.jsx("div",{className:"flex items-center flex-shrink-0 px-1 select-none",children:r})]},m)})})]})}const G$={sm:"w-4 h-4",md:"w-5 h-5",lg:"w-6 h-6"},K$={sm:"w-3 h-3",md:"w-3.5 h-3.5",lg:"w-4 h-4"};function ki({groupLabel:e,options:t,control:r,name:n,rules:a,defaultValue:o,multiple:i=!0,size:c="sm",vertical:d=!0,className:u,showVisibleLabel:f=!0,disabled:h=!1,hasError:p=!1,errorMessage:m}){return l.jsx(Et,{name:n,control:r,rules:a,defaultValue:o,render:({field:v,fieldState:g})=>{const{value:b,onChange:w}=v,x=g.error,y=A=>{var S;return i?Array.isArray(b)&&((S=b==null?void 0:b.includes)==null?void 0:S.call(b,A)):b===A},E=A=>{if(!h)if(i){const S=Array.isArray(b)?[...b]:[],_=S.indexOf(A);_>=0?S.splice(_,1):S.push(A),w(S)}else w(A)},k=p||!!x,j=(x==null?void 0:x.message)||m;return l.jsxs("fieldset",{className:ve("w-full flex flex-col gap-1",u),"aria-invalid":k||void 0,disabled:h,children:[e&&l.jsx("legend",{className:ve("mb-1 text-ds-sm text-[var(--color-ds-text-primary)]",!f&&"sr-only"),children:e}),l.jsx("div",{className:ve(d?"flex flex-col gap-2":"flex flex-wrap gap-2"),children:t.map(A=>{const S=y(A.value),_=h||!!(A!=null&&A.disabled),O=ve("inline-flex items-center justify-center border transition-all duration-150",i?"rounded-[6px]":"rounded-full",G$[c],"bg-[var(--color-ds-background-page)]","border-[var(--color-ds-border-default-50)]","shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-default)20%,transparent)]","peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--color-ds-border-default)]","hover:border-[var(--color-ds-border-default)]",i&&S&&"bg-[var(--color-ds-button-primary-bg)] border-[var(--color-ds-button-primary-bg)]",!i&&S&&"border-[var(--color-ds-button-primary-bg)]",k&&"border-[var(--color-ds-border-error)] shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-error)30%,transparent)]",_&&"opacity-60 cursor-not-allowed"),B=ve("text-ds-sm text-[var(--color-ds-text-primary)]",_&&"text-[var(--color-ds-text-secondary)]"),R=ve(K$[c],"text-[var(--color-ds-button-primary-text)] transition-all duration-150",S?"opacity-100 scale-100":"opacity-0 scale-75"),I=ve(c==="sm"?"w-2 h-2":c==="md"?"w-2.5 h-2.5":"w-3 h-3","rounded-full bg-[var(--color-ds-button-primary-bg)] transition-all duration-150",S?"opacity-100 scale-100":"opacity-0 scale-0");return l.jsxs("label",{className:ve("inline-flex items-center gap-2 cursor-pointer select-none rounded-md px-1 py-1","hover:bg-[color-mix(in_srgb,var(--color-ds-border-default)6%,transparent)]",_&&"cursor-not-allowed hover:bg-transparent"),children:[l.jsxs("span",{className:"relative inline-flex items-center justify-center",children:[l.jsx("input",{type:i?"checkbox":"radio",name:n,value:A.value,checked:S,onChange:()=>E(A.value),disabled:_,className:"peer sr-only"}),l.jsx("span",{"aria-hidden":!0,className:O,children:i?l.jsx(Bc,{className:R}):l.jsx("span",{className:I})})]}),l.jsx("span",{className:B,children:A.label})]},String(A.value))})}),k&&!!j&&l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] mt-1",children:j})]})}})}function J$(e){function t(i){var c,d;for(const u of Object.keys(i)){if((c=i[u])!=null&&c.types||(d=i[u])!=null&&d.message)return u;if(typeof i[u]=="object"){const f=t(i[u]);if(f)return`${u}.${f}`}}return null}const r=t(e);if(!r)return;const n=`[name="${r}"]`,a=`[name^="${r}["], [name^="${r}."]`,o=document.querySelector(n)??document.querySelector(a);o&&(o.scrollIntoView({behavior:"smooth",block:"center"}),o.focus({preventScroll:!0}))}const Y$={success:"bg-green-100 border-green-500 text-green-800",error:"bg-red-100 border-red-500 text-red-800",info:"bg-blue-100 border-blue-500 text-blue-800",warning:"bg-yellow-100 border-yellow-500 text-yellow-800"},L2=({id:e,message:t,variant:r="info",duration:n=5e3,onClose:a})=>(C.useEffect(()=>{const o=setTimeout(()=>a(e),n);return()=>clearTimeout(o)},[e,n,a]),l.jsxs("div",{className:ve("w-80 max-w-full border-l-4 rounded shadow-md p-4 mb-2 flex justify-between items-start",Y$[r]),role:"alert","aria-live":"assertive",children:[l.jsx("span",{className:"flex-1",children:t}),l.jsx("button",{onClick:()=>a(e),className:"ml-4 text-xl font-bold leading-none focus:outline-none",children:"×"})]})),Ct=[];for(let e=0;e<256;++e)Ct.push((e+256).toString(16).slice(1));function X$(e,t=0){return(Ct[e[t+0]]+Ct[e[t+1]]+Ct[e[t+2]]+Ct[e[t+3]]+"-"+Ct[e[t+4]]+Ct[e[t+5]]+"-"+Ct[e[t+6]]+Ct[e[t+7]]+"-"+Ct[e[t+8]]+Ct[e[t+9]]+"-"+Ct[e[t+10]]+Ct[e[t+11]]+Ct[e[t+12]]+Ct[e[t+13]]+Ct[e[t+14]]+Ct[e[t+15]]).toLowerCase()}let ud;const Q$=new Uint8Array(16);function eI(){if(!ud){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ud=crypto.getRandomValues.bind(crypto)}return ud(Q$)}const T2={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function tI(e,t,r){var a;e=e||{};const n=e.random??((a=e.rng)==null?void 0:a.call(e))??eI();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,X$(n)}function rI(e,t,r){return T2.randomUUID&&!e?T2.randomUUID():tI(e)}const $2=C.createContext(null),yn=()=>{const e=C.useContext($2);if(!e)throw new Error("useToast debe usarse dentro de <ToastProvider>");return e},nI=({children:e})=>{const[t,r]=C.useState([]),n=(o,i="info",c=5e3)=>{const d=rI();r(u=>[...u,{id:d,message:o,variant:i,duration:c}])},a=o=>{r(i=>i.filter(c=>c.id!==o))};return l.jsxs($2.Provider,{value:{show:n},children:[e,l.jsx("div",{className:"fixed top-4 right-4 z-50 flex flex-col items-end",children:t.map(o=>l.jsx(L2,{id:o.id,message:o.message,variant:o.variant,duration:o.duration,onClose:a},o.id))})]})},aI=e=>e.type==="inputGroup",oI=e=>e.type==="button",sI=e=>!aI(e)&&!oI(e);function I2(e){const t=Array.isArray(e)?e:[];return C.useMemo(()=>{const r={};for(const n of t)sI(n)&&n.name&&(r[n.name]=n);return r},[t])}const B2=C.createContext(null);function P2({children:e,value:t}){return l.jsx(B2.Provider,{value:t,children:e})}function Zt(){const e=C.useContext(B2);if(!e)throw new Error("useAdapters debe usarse dentro de <AdaptersProvider />");return e}const iI=e=>!!e&&typeof e.then=="function";function lI(e){return Array.isArray(e)?e.length>0&&typeof e[0]=="object"&&e[0]!==null?e.map(t=>{var a;if("label"in t&&"value"in t)return t;const n=(a=Object.entries(t)[0])==null?void 0:a[1];return{label:String(n??JSON.stringify(t)),value:String(n??"")}}):e.map(t=>({label:String(t),value:t})):[]}function V2(e){const{services:t}=Zt(),[r,n]=C.useState({}),[a,o]=C.useState(0),i=C.useRef(!0);C.useEffect(()=>(i.current=!0,()=>{i.current=!1}),[]);const c=C.useMemo(()=>e.filter(d=>d.type==="select"&&!d.options&&typeof d.optionSource=="string"&&d.name),[e]);return C.useEffect(()=>{if(c.length===0)return;let d=!1;return(async()=>{o(u=>u+1);try{const u=await Promise.all(c.map(async f=>{var b;const h=f.name,p=f.optionSource,m=(b=t==null?void 0:t.registry)==null?void 0:b[p];if(!m)return[h,[]];const v=iI(m)?await m:await m(),g=lI(v);return[h,g]}));if(d||!i.current)return;n(f=>{const h={...f};for(const[p,m]of u)h[p]=[...m];return h})}finally{!d&&i.current&&o(u=>Math.max(0,u-1))}})(),()=>{d=!0}},[c,t==null?void 0:t.registry]),{optionsMap:r,loadingCount:a}}const cI=e=>e.type==="inputGroup",dI=e=>e.type==="button",uI=e=>!cI(e)&&!dI(e);function fI(e){return typeof e=="object"&&e!==null}const hI=e=>{const t=e.disabledWhen;if(!fI(t))return!1;const r="watchField"in t,n="rule"in t;return r&&!n};function Z2(e,t){const r=Array.isArray(e)?e:[],n=C.useMemo(()=>r.filter(uI).filter(hI),[r]),a=C.useMemo(()=>n.map(d=>d.disabledWhen.watchField),[n]),o=Ec({control:t,name:a,compute:d=>d}),i=Array.isArray(o)?o:[],c={};return n.forEach((d,u)=>{const f=i[u];c[d.name??`__unnamed_${u}`]=f===d.disabledWhen.watchValue}),c}const pI={sm:"text-ds-sm",md:"text-ds-sm",lg:"text-ds-sm"},mI={sm:"px-2 py-1.5",md:"px-3 py-2",lg:"px-4 py-3"};function Dr({control:e,name:t,rules:r,defaultValue:n,size:a="sm",width:o="100%",label:i,labelHidden:c=!1,hasError:d=!1,errorMessage:u="",maxLength:f,showCounter:h=!1,className:p,suffixButton:m,labelPrefixIcon:v,labelSuffixIcon:g,info:b,infoHeader:w,infoAriaLabel:x,prefixIcon:y,suffixIcon:E,reserveErrorSpace:k,disableErrorPlaceholder:j,id:A,...S}){const _=C.useId(),O=A||_,[B,R]=C.useState(String(n??S.value??"")),I=typeof k=="boolean"?k:typeof j=="boolean"?!j:!!e,F=ve("box-border bg-[var(--color-ds-background-page)] w-full rounded-lg border outline-none transition","placeholder-[var(--color-ds-text-secondary)] text-[var(--color-ds-text-primary)]",pI[a],mI[a],d?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",S.disabled&&"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-secondary)] cursor-not-allowed"),Z=y?"pl-9":"",ee=E?"pr-9":"",Y=N=>{var L;typeof f=="number"&&N.target.value.length>f||(R(N.target.value),(L=S.onChange)==null||L.call(S,N))},te=o&&(o.includes(" ")||o.startsWith("w-")||o.startsWith("max-w-")||o.startsWith("min-w-")),ae=te?void 0:{width:o},q=ve("flex flex-col",te&&o,p);return C.useEffect(()=>{n!==void 0&&R(String(n??""))},[n]),e&&t?l.jsx(Et,{name:t,control:e,rules:r,defaultValue:n??"",render:({field:N,fieldState:L})=>{var ne;return l.jsxs("div",{className:q,style:ae,children:[!c&&i&&l.jsx(gr,{id:O,text:i,size:a,prefixIcon:v,suffixIcon:g,info:b,infoHeader:w,infoAriaLabel:x}),l.jsxs("div",{className:"flex items-stretch gap-2",children:[l.jsxs("div",{className:"relative w-full",children:[y&&l.jsx("span",{className:"absolute left-2 top-2.5",children:l.jsx(Ft,{component:y,size:a,className:"text-[var(--color-ds-text-secondary)]"})}),l.jsx("textarea",{id:O,"aria-invalid":!!L.error,className:ve(F,Z,ee),maxLength:f,...N,placeholder:S.disabled?"":S.placeholder,onChange:K=>{N.onChange(K),h&&R(K.target.value)}}),E&&l.jsx("span",{className:"absolute right-2 top-2.5",children:l.jsx(Ft,{component:E,size:a,className:"text-[var(--color-ds-text-secondary)]"})})]}),m?l.jsx("div",{className:"shrink-0",children:m}):null]}),l.jsxs("div",{className:"flex justify-between pt-1 h-[1em]",children:[I?L.error?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:L.error.message}):l.jsx("span",{"aria-hidden":"true",children:" "}):L.error?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:L.error.message}):l.jsx("span",{"aria-hidden":"true",children:" "}),h&&typeof f=="number"&&l.jsxs("span",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:[((ne=N.value)==null?void 0:ne.length)??0,"/",f]})]})]})}}):l.jsxs("div",{className:q,style:ae,children:[!c&&i&&l.jsx(gr,{id:O,text:i,size:a,prefixIcon:v,suffixIcon:g,info:b,infoHeader:w,infoAriaLabel:x}),l.jsxs("div",{className:"flex items-stretch gap-2",children:[l.jsxs("div",{className:"relative w-full",children:[y&&l.jsx("span",{className:"absolute left-2 top-2.5",children:l.jsx(Ft,{component:y,size:a,className:"text-[var(--color-ds-text-secondary)]"})}),l.jsx("textarea",{id:O,className:ve(F,Z,ee),value:B,onChange:Y,maxLength:f,...S,placeholder:S.disabled?"":S.placeholder}),E&&l.jsx("span",{className:"absolute right-2 top-2.5",children:l.jsx(Ft,{component:E,size:a,className:"text-[var(--color-ds-text-secondary)]"})})]}),m?l.jsx("div",{className:"shrink-0",children:m}):null]}),l.jsxs("div",{className:"flex justify-between pt-1 h-[1em]",children:[I?d&&u?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:u}):l.jsx("span",{"aria-hidden":"true",children:" "}):d&&u?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:u}):l.jsx("span",{"aria-hidden":"true",children:" "}),h&&typeof f=="number"&&l.jsxs("span",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:[B.length,"/",f]})]})]})}const gI={sm:"w-4 h-4",md:"w-5 h-5",lg:"w-6 h-6"},vI={sm:"w-3 h-3",md:"w-3.5 h-3.5",lg:"w-4 h-4"};function it({control:e=null,name:t,rules:r,defaultValue:n=!1,label:a,labelHidden:o=!1,disabled:i=!1,size:c="sm",className:d,hasError:u=!1,errorMessage:f="",reserveErrorSpace:h,disableErrorPlaceholder:p,checked:m,indeterminate:v,onChange:g}){const b=ve("text-[var(--color-ds-text-primary)] text-ds-sm",i&&"text-[var(--color-ds-text-secondary)]",o&&"sr-only"),w=typeof h=="boolean"?h:typeof p=="boolean"?!p:!!e,x=(y,E,k)=>{const j=u||!!k,A=(k==null?void 0:k.message)||f,S=ve("inline-flex items-center justify-center rounded-[6px] border transition-all duration-150",gI[c],"bg-[var(--color-ds-background-page)]","border-[var(--color-ds-border-default-50)]","shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-default)20%,transparent)]","peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--color-ds-border-default)]","hover:border-[var(--color-ds-border-default)]",(y||v)&&"bg-[var(--color-ds-button-primary-bg)] border-[var(--color-ds-button-primary-bg)]",j&&"border-[var(--color-ds-border-error)] shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-error)30%,transparent)]",i&&"opacity-60 cursor-not-allowed"),_=ve(vI[c],"text-[var(--color-ds-button-primary-text)]","transition-all duration-150",y||v?"opacity-100 scale-100":"opacity-0 scale-75");return l.jsxs("div",{className:ve("flex flex-col gap-1",d),children:[C.createElement(typeof a=="string"?"label":"div",{className:ve("inline-flex items-center gap-2 cursor-pointer select-none",i&&"cursor-not-allowed")},l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"relative inline-flex items-center justify-center",children:[l.jsx("input",{id:t,type:"checkbox",className:"peer sr-only",checked:y,ref:O=>{O&&(O.indeterminate=!!v)},onChange:O=>E(O.target.checked),disabled:i}),l.jsx("span",{"aria-hidden":!0,className:S,children:v?l.jsx("div",{className:"bg-white h-0.5 w-[60%] rounded-full"}):l.jsx(Bc,{className:_})})]}),a&&l.jsx("span",{className:b,children:a})]})),w?l.jsx("div",{className:"h-[1em]",children:j&&A?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:A}):l.jsx("span",{"aria-hidden":"true",children:" "})}):j&&A?l.jsx("div",{className:"pt-1",children:l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:A})}):null]})};return e?l.jsx(Et,{name:t||"",control:e,rules:r,defaultValue:n,render:({field:y,fieldState:E})=>{const k=E.error;return x(!!y.value,j=>y.onChange(j),k)}}):x(!!m,y=>g==null?void 0:g(y))}function fd({name:e,control:t,searchFn:r,resolveByValue:n,label:a,size:o="sm",width:i="100%",disabled:c=!1,searchMode:d="button",minChars:u=3,debounceMs:f=600,labelPrefixIcon:h,labelSuffixIcon:p,prefixIcon:m,suffixIcon:v,reserveErrorSpace:g,disableErrorPlaceholder:b}){const w=gn(),{watch:x,getValues:y,setValue:E}=w,k=Ec({control:t,name:e}),[j,A]=C.useState([]),[S,_]=C.useState(!1),[O,B]=C.useState(!1),[R,I]=C.useState(""),F=C.useRef(null),Z=C.useRef(null),ee=C.useRef(!1),Y=C.useRef(!1),te=C.useRef(!0),ae=C.useMemo(()=>{const ce=new Map;for(const le of j)ce.set(String(le.value).trim(),le.label??"");return ce},[j]),q=async ce=>{const le=(ce??"").trim();if(!le){A([]),B(!1);return}_(!0);try{const be=await r(le,{watch:x,getValues:y});A(be??[]),B(!0)}finally{_(!1)}};C.useEffect(()=>{function ce(le){F.current&&!F.current.contains(le.target)&&B(!1)}if(O)return document.addEventListener("mousedown",ce),()=>document.removeEventListener("mousedown",ce)},[O]);const[N,L]=C.useState({});C.useEffect(()=>{if(ee.current)return;const le=(k?String(k):"").trim();if(!le){R!==""&&I(""),B(!1);return}const be=ae.get(le);if(be){R!==be&&(I(be),te.current=!0);return}const fe=N[le];if(fe){R!==fe&&(I(fe),te.current=!0);return}let xe=!1;return n?(R!==le&&I(le),(async()=>{try{const D=await n(le,{watch:x,getValues:y});if(xe)return;if(D){const G=D.label??String(D.value);L(re=>{const W={...re,[le]:G};return I(G),te.current=!0,W})}else R!==le&&(I(le),te.current=!0)}catch{!xe&&R!==le&&(I(le),te.current=!0)}})()):R!==le&&(I(le),te.current=!0),()=>{xe=!0}},[k,ae,N,n,x,y]),C.useEffect(()=>{if(d!=="debounced"||c)return;if(te.current){te.current=!1;return}if(!Y.current)return;Z.current&&(window.clearTimeout(Z.current),Z.current=null);const ce=(R||"").trim();return ce.length>=u?Z.current=window.setTimeout(()=>{q(ce)},f):(A([]),B(!1)),()=>{Z.current&&(window.clearTimeout(Z.current),Z.current=null)}},[R,d,u,f,c]);const ne=o==="sm"?"text-ds-sm":o==="md"?"text-ds-md":"text-ds-lg",K=o==="sm"?"h-6":o==="md"?"h-10":"h-12",Q=ce=>{if(c)return;const le=(R||"").trim();ce.key==="Enter"&&(ce.preventDefault(),d==="debounced"?le.length>=u&&q(le):q(le)),ce.key==="Escape"&&B(!1)},he=i&&(i.includes(" ")||i.startsWith("w-")||i.startsWith("max-w-")||i.startsWith("min-w-")),ie=he?void 0:{width:i},me=`relative flex flex-col ${he?i:""}`;return l.jsx(Et,{name:e,control:t,render:({field:ce,fieldState:le})=>{var be;return l.jsxs("div",{ref:F,className:me,style:ie,children:[a&&l.jsx(gr,{id:e,text:a,size:o,prefixIcon:h,suffixIcon:p}),l.jsx(je,{className:d==="button"?"rounded-r-none":void 0,type:"text",size:o,width:"100%",value:R,prefixIcon:m,suffixIcon:v,onChange:fe=>{const xe=fe.target.value;ee.current=!0,Y.current=!0,I(xe),(k?String(k):"").trim()&&E(e,"",{shouldDirty:!0})},onKeyDown:Q,onBlur:()=>{ee.current=!1},disabled:c,hasError:le.invalid,errorMessage:(be=le.error)==null?void 0:be.message,reserveErrorSpace:g,disableErrorPlaceholder:b,onFocus:()=>{if(ee.current=!0,d==="button"&&Y.current){const fe=(R||"").trim();fe&&q(fe)}},suffixButton:d==="button"?l.jsx(pe,{type:"button",className:"!rounded-l-none",size:o,variant:"primary",onClick:()=>q((R||"").trim()),disabled:c,children:"Buscar"}):void 0}),S&&l.jsx("div",{className:"absolute top-14 left-0 right-0 z-10",children:l.jsx(Pr,{width:"100%",height:o==="sm"?"1.5rem":o==="md"?"2.5rem":"3rem",variant:"rect",className:"rounded-lg"})}),O&&!S&&j.length>0&&l.jsx("ul",{className:`
92
+ `,u=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(u),h=new Worker(f),p=setTimeout(()=>{h.terminate(),URL.revokeObjectURL(f),c(new Error("Timeout: La validación tardó demasiado."))},a);h.onmessage=m=>{clearTimeout(p),h.terminate(),URL.revokeObjectURL(f),m.data.success?i(m.data.result):(console.warn("Validation Script Error:",m.data.error),i("Error en script de validación"))},h.onerror=m=>{clearTimeout(p),h.terminate(),URL.revokeObjectURL(f),c(m)},h.postMessage({code:e,context:t,translations:o})})}const D$={ds:{fileUploader:{browse:"Document",dragDrop:"Drag your files here or click to browse",view:"View",remove:"Remove"},form:{fieldRequired:"Required field",invalidEmail:"Invalid email",submit:"Submit",sending:"Sending…",saveSuccess:"Saved successfully!",saveError:"There are errors in the form"},editor:{inspector:{field:"Field Inspector",tab:"Tab Inspector",section:"Section Inspector"},actions:{move:"Move",moveLeft:"Move left",moveRight:"Move right",add:"Add",addTab:"Tab to the right",addSection:"Add section",addRow:"Add row",addColumn:"Add column",delete:"Delete",deleteTab:"Delete tab",deleteColumn:"Remove last column",duplicate:"Duplicate",cancel:"Cancel"},confirmations:{deleteField:{title:"Delete field",message:"Are you sure you want to delete this field?"},deleteColumn:{title:"Delete column",message:"Are you sure you want to delete the last column? Fields it contains will be lost."},deleteRow:{title:"Delete row",message:"Are you sure you want to delete this row? All fields it contains will be lost."},deleteSection:{title:"Delete section",message:"Are you sure you want to delete this section? All fields it contains will be lost."}},title:"Form Schema Editor",context:"Context:",modes:{design:"Designer",preview:"Preview",code:"Code"},codeViewer:{copy:"Copy code",copied:"Copied",lines:"lines",format:"Format"},toolbar:{export:"Export",import:"Import JSON",shortcuts:"Shortcuts",showRelations:"Show relations",hideRelations:"Hide relations",toggleSidePanel:{open:"Open side panel",close:"Close side panel"}},importModal:{trigger:"Generate from object",triggerTitle:"Generate form from JSON or TypeScript",title:"Generate from JSON or TypeScript",labels:{formTitle:"Form Title",formId:"Form ID",layout:"Layout (cols)",input:"Input (paste JSON or TypeScript interface/type)"},placeholders:{layout:{auto:"Auto",col1:"1 column",col2:"2 columns",col3:"3 columns",col4:"4 columns"}},actions:{cancel:"Cancel",generate:"Generate Form",generating:"Generating..."},messages:{success:"Form generated successfully.",error:"Could not generate form."}}},fields:{defaults:{text:{label:"Text",placeholder:"Type…"},number:{label:"Number",placeholder:"0"},email:{label:"Email",placeholder:"user@domain.com"},password:{label:"Password",placeholder:"••••••••"},tel:{label:"Phone",placeholder:"600 000 000"},url:{label:"URL",placeholder:"https://example.com"},textarea:{label:"Comment",placeholder:"Write your comment…"},select:{label:"Select",placeholder:"Select an option"},checkbox:{label:"Checkbox"},date:{label:"Date"},file:{label:"File"},search:{label:"Search",placeholder:"Search...",noMatches:"No matches found"}},validation:{required:"Required field",invalidEmail:"Invalid email",invalidUrl:"Invalid URL",invalidPhone:"Invalid phone",invalidID:"Invalid identity document",invalidIBAN:"Invalid IBAN",minLength:"Minimum {{count}} characters",maxLength:"Maximum {{count}} characters",pattern:"Invalid format",numberMin:"Must be greater than or equal to {{min}}",numberMax:"Must be less than or equal to {{max}}",step:"Must be a multiple of {{step}}",integerOnly:"Must be an integer",positiveOnly:"Must be a positive number",selectMin:"Select at least {{count}} options",selectMax:"Select at most {{count}} options",dateMin:"Date must be after {{date}}",dateMax:"Date must be before {{date}}",disallowPast:"Past dates are not allowed",disallowFuture:"Future dates are not allowed",number:"Must be a number",date:"Invalid date",invalidOption:"Invalid option",mustCheck:"You must check this box",invalidFile:"Invalid file",invalidFileType:"File type not allowed",fileMaxCount:"Max. {{count}} file(s)",fileMaxSize:"File must not exceed {{size}}MB",minItems:"Minimum {{count}} items",maxItems:"Maximum {{count}} items"}}}},S$={ds:{fileUploader:{browse:"Documento",dragDrop:"Arrastra tus archivos aquí o haz clic para buscarlos",view:"Ver",remove:"Eliminar"},form:{fieldRequired:"Campo obligatorio",invalidEmail:"Email inválido",submit:"Enviar",sending:"Enviando…",saveSuccess:"¡Guardado con éxito!",saveError:"Hay errores en el formulario"},editor:{inspector:{field:"Inspector de campo",tab:"Inspector de pestaña",section:"Inspector de sección"},actions:{move:"Mover",moveLeft:"Mover a la izquierda",moveRight:"Mover a la derecha",add:"Añadir",addTab:"Pestaña a la derecha",addSection:"Añadir sección",addRow:"Añadir fila",addColumn:"Añadir columna",delete:"Eliminar",deleteTab:"Eliminar pestaña",deleteColumn:"Quitar última columna",duplicate:"Duplicar",cancel:"Cancelar"},confirmations:{deleteField:{title:"Eliminar campo",message:"¿Estás seguro de que quieres eliminar este campo?"},deleteColumn:{title:"Eliminar columna",message:"¿Estás seguro de que quieres eliminar la última columna? Se perderán los campos que contiene."},deleteRow:{title:"Eliminar fila",message:"¿Estás seguro de que quieres eliminar esta fila? Se perderán todos los campos que contiene."},deleteSection:{title:"Eliminar sección",message:"¿Estás seguro de que quieres eliminar esta sección? Se perderán todos los campos que contiene."}},title:"Editor de Esquema de Formulario",context:"Contexto:",modes:{design:"Diseñar",preview:"Vista Previa",code:"Código"},codeViewer:{copy:"Copiar código",copied:"Copiado",lines:"líneas",format:"Formato"},toolbar:{export:"Exportar",import:"Importar JSON",shortcuts:"Configurar atajos",showRelations:"Mostrar relaciones",hideRelations:"Ocultar relaciones",toggleSidePanel:{open:"Abrir panel lateral",close:"Cerrar panel lateral"}},importModal:{trigger:"Generar desde objeto",triggerTitle:"Generar formulario desde JSON o TypeScript",title:"Generar desde JSON o TypeScript",labels:{formTitle:"Título del formulario",formId:"ID del formulario",layout:"Distribución (cols)",input:"Entrada (pega JSON o una interface/type de TypeScript)"},placeholders:{layout:{auto:"Auto",col1:"1 columna",col2:"2 columnas",col3:"3 columnas",col4:"4 columnas"}},actions:{cancel:"Cancelar",generate:"Generar formulario",generating:"Generando..."},messages:{success:"Formulario generado correctamente.",error:"No se pudo generar el formulario."}}},fields:{defaults:{text:{label:"Texto",placeholder:"Escribe…"},number:{label:"Número",placeholder:"0"},email:{label:"Email",placeholder:"usuario@dominio.com"},password:{label:"Contraseña",placeholder:"••••••••"},tel:{label:"Teléfono",placeholder:"600 000 000"},url:{label:"URL",placeholder:"https://ejemplo.com"},textarea:{label:"Comentario",placeholder:"Escribe tu comentario…"},select:{label:"Seleccionar",placeholder:"Seleccione una opción"},checkbox:{label:"Casilla"},date:{label:"Fecha"},file:{label:"Archivo"},search:{label:"Búsqueda",placeholder:"Buscar...",noMatches:"No hay coincidencias"}},validation:{required:"Campo obligatorio",invalidEmail:"Email inválido",invalidUrl:"URL inválida",invalidPhone:"Teléfono inválido",invalidID:"Documento de identidad inválido",invalidIBAN:"IBAN inválido",minLength:"Mínimo {{count}} caracteres",maxLength:"Máximo {{count}} caracteres",pattern:"Formato inválido",numberMin:"Debe ser mayor o igual a {{min}}",numberMax:"Debe ser menor o igual a {{max}}",step:"Debe ser múltiplo de {{step}}",integerOnly:"Debe ser un número entero",positiveOnly:"Debe ser un número positivo",selectMin:"Selecciona al menos {{count}} opciones",selectMax:"Selecciona como máximo {{count}} opciones",dateMin:"La fecha debe ser posterior a {{date}}",dateMax:"La fecha debe ser anterior a {{date}}",disallowPast:"No se permiten fechas pasadas",disallowFuture:"No se permiten fechas futuras",number:"Debe ser un número",date:"Fecha inválida",invalidOption:"Opción inválida",mustCheck:"Debes marcar esta casilla",invalidFile:"Archivo inválido",invalidFileType:"Tipo de archivo no permitido",fileMaxCount:"Máx. {{count}} fichero(s)",fileMaxSize:"El archivo no debe superar {{size}}MB",minItems:"Mínimo {{count}} elementos",maxItems:"Máximo {{count}} elementos"}}}};qe.use(AT).init({resources:{en:{translation:D$},es:{translation:S$}},lng:"es",fallbackLng:"es",interpolation:{escapeValue:!1}});const A$=e=>{qe.changeLanguage(e)},D2="TRWAGMYFPDXBNJZSQVHLCKE",N$=["X","Y","Z"];function F$(e){if(!/^\d{8}[A-Z]$/.test(e))return!1;const t=parseInt(e.substring(0,8),10),r=e.charAt(8),n=D2.charAt(t%23);return r===n}function _$(e){if(!/^[XYZ]\d{7}[A-Z]$/.test(e))return!1;const t=e.charAt(0),n=N$.indexOf(t).toString()+e.substring(1),a=parseInt(n.substring(0,8),10),o=e.charAt(8),i=D2.charAt(a%23);return o===i}function M$(e){if(!/^[A-Z]\d{7}[A-Z0-9]$/.test(e))return!1;const t=e.charAt(0),r=e.substring(1,8),n=e.charAt(8);let a=0;for(let f=0;f<7;f++){const h=parseInt(r.charAt(f),10);if(f%2===0){const p=h*2;a+=Math.floor(p/10)+p%10}else a+=h}const o=a%10,i=o===0?0:10-o,c="JABCDEFGHI".charAt(i);return["A","B","E","H"].includes(t)?n===i.toString():n===c||n===i.toString()}function R$(e){if(!e||e.length<9)return!1;const t=e.toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"");return/^\d{8}[A-Z]$/.test(t)?F$(t):/^[XYZ]\d{7}[A-Z]$/.test(t)?_$(t):/^[A-Z]\d{7}[A-Z0-9]$/.test(t)?M$(t):!1}const O$=/^\s*(?:\+?\d{1,4}[\s-]*)?(?:\(?\d{2,4}\)?[\s-]*)?\d{3,4}[\s-]?\d{3,4}\s*$/;function S2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"")}function L$(e){const t=S2(e);if(t.length<15||t.length>34||!/^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(t))return!1;const r=t.slice(4)+t.slice(0,4);let n=0;for(const a of r){const o=a.charCodeAt(0);if(o>=65&&o<=90){const i=String(o-55);for(let c=0;c<i.length;c++)n=(n*10+(i.charCodeAt(c)-48))%97}else n=(n*10+(a.charCodeAt(0)-48))%97}return n===1}function T$(e){return e.validation??{}}function $$(e){return!!e.multiple}function I$(e){const t=e.maxFiles;return typeof t=="number"?t:void 0}function B$(e){const t=e.options;return Array.isArray(t)?t.map(r=>r==null?void 0:r.value).filter(r=>r!==void 0):[]}function P$(e){if(!e)return{exts:[],mimes:[]};const t=e.split(",").map(a=>a.trim().toLowerCase()).filter(Boolean),r=[],n=[];for(const a of t)a.startsWith(".")?r.push(a):a.includes("/")&&n.push(a);return{exts:r,mimes:n}}function vt(e,t){const r=typeof e=="string"?e:t;return qe.isInitialized&&(r.startsWith("forms.")||r.startsWith("ds."))?qe.t(r):r}function br(e,t){let r=e;return t.required&&(r=r.required(vt(t.requiredMessage||(typeof t.required=="string"?t.required:void 0),"ds.fields.validation.required"))),t.customFn&&(r=r.test({name:"custom-script-validation",message:"${path} no es válido",test:async function(n,a){if(n==null||n==="")return!0;const o=a.parent;let i={};try{if(qe.isInitialized){const c=qe.getResourceBundle(qe.language,"translation")||{},d=(u,f="")=>{for(const h of Object.keys(u)){const p=f?`${f}.${h}`:h,m=u[h];typeof m=="string"?i[p]=m:typeof m=="object"&&m!==null&&d(m,p)}};d(c)}}catch(c){console.warn("Error extracting translations for validation:",c)}try{const c=await j2(t.customFn,{value:n,form:o,customMessages:t.customMessages||{}},{translations:i});if(c===!0)return!0;if(typeof c=="string"){const d=qe.isInitialized&&c.startsWith("forms.")?qe.t(c):c;return this.createError({message:d})}return!1}catch(c){return console.error("Custom Validation Error",c),this.createError({message:"Error ejecutando validación: "+String(c)})}}})),r}function Hn(e,t){var n,a,o;let r=e;return((n=t.minLength)==null?void 0:n.value)!=null&&(r=r.min(t.minLength.value,vt(t.minLength.message,"ds.fields.validation.minLength"))),((a=t.maxLength)==null?void 0:a.value)!=null&&(r=r.max(t.maxLength.value,vt(t.maxLength.message,"ds.fields.validation.maxLength"))),((o=t.pattern)==null?void 0:o.value)instanceof RegExp&&(r=r.matches(t.pattern.value,vt(t.pattern.message,"ds.fields.validation.pattern"))),r}function V$(e,t){var n,a,o,i;let r=e;if(((n=t.numberMin)==null?void 0:n.value)!=null&&(r=r.min(t.numberMin.value,vt(t.numberMin.message,"ds.fields.validation.numberMin"))),((a=t.numberMax)==null?void 0:a.value)!=null&&(r=r.max(t.numberMax.value,vt(t.numberMax.message,"ds.fields.validation.numberMax"))),t.positiveOnly&&(r=r.moreThan(0,vt(t.positiveOnly,"ds.fields.validation.positiveOnly"))),t.integerOnly&&(r=r.integer(vt(t.integerOnly,"ds.fields.validation.integerOnly"))),((o=t.step)==null?void 0:o.value)!=null){const c=Number(t.step.value),d=t.step.message||"ds.fields.validation.step";r=r.test("step",d,u=>{if(u==null||Number.isNaN(u)||c===0)return!0;const f=u/c;return Math.abs(f-Math.round(f))<1e-9})}return((i=t.pattern)==null?void 0:i.value)instanceof RegExp&&(r=r.test("pattern-number",t.pattern.message||"ds.fields.validation.pattern",c=>c==null||t.pattern.value.test(String(c)))),r}function Z$(e,t){var n,a;let r=e;return(n=t.dateMin)!=null&&n.value&&(r=r.min(new Date(t.dateMin.value),vt(t.dateMin.message,"ds.fields.validation.dateMin"))),(a=t.dateMax)!=null&&a.value&&(r=r.max(new Date(t.dateMax.value),vt(t.dateMax.message,"ds.fields.validation.dateMax"))),t.disallowPast&&(r=r.min(new Date,vt(t.disallowPast,"ds.fields.validation.disallowPast"))),t.disallowFuture&&(r=r.max(new Date,vt(t.disallowFuture,"ds.fields.validation.disallowFuture"))),r}function z$(e){var r,n,a,o;const t=T$(e);switch(e.type){case"text":case"password":case"textarea":case"search":{let i=xn().trim();return i=Hn(i,t),br(i,t)}case"dni":{let i=xn().trim();return i=Hn(i,t),i=i.test("dni-valid",vt("ds.fields.validation.invalidID","Documento de identidad inválido"),c=>c==null||c===""?!0:R$(c)),br(i,t)}case"email":{let i=xn().trim().email(vt(t.emailMessage,"ds.fields.validation.invalidEmail"));return i=Hn(i,t),br(i,t)}case"url":{let i=xn().trim().url(vt(t.urlMessage,"ds.fields.validation.invalidUrl"));return i=Hn(i,t),br(i,t)}case"tel":{let i=xn().trim();return i=Hn(i,t),(r=t.pattern)!=null&&r.value||(i=i.matches(O$,vt(t.phoneMessage,"ds.fields.validation.invalidPhone"))),br(i,t)}case"iban":{let i=xn().transform((c,d)=>d===""||d===null||d===void 0?"":typeof d=="string"?S2(d):c);return i=Hn(i,t),i=i.test("iban-valid",vt("ds.fields.validation.invalidIBAN","IBAN inválido"),c=>c==null||c===""?!0:L$(String(c))),br(i,t)}case"number":{let i=m2().transform((c,d)=>{if(d===""||d===null||d===void 0)return;const u=typeof d=="string"?Number(d.replace(",",".")):c;return Number.isNaN(u)?NaN:u}).typeError(vt(t.typeError,"ds.fields.validation.number"));return i=V$(i,t),br(i,t)}case"date":{let i=od().nullable().typeError(vt(t.typeError,"ds.fields.validation.date")).transform((c,d)=>d?new Date(d):null);return i=Z$(i,t),br(i,t)}case"select":case"optionGroup":{const i=$$(e),c=B$(e);if(i){let d=id().of(c.length?So().oneOf(c,"ds.fields.validation.invalidOption"):So());return t.required&&(d=d.min(1,t.requiredMessage||(typeof t.required=="string"?t.required:"ds.fields.validation.required"))),d}else{let d=xn().trim();return d=Hn(d,t),c.length&&(d=d.oneOf(c,"ds.fields.validation.invalidOption")),br(d,t)}}case"checkbox":{let i=f2();return t.required&&(i=i.oneOf([!0],t.requiredMessage||"ds.fields.validation.mustCheck")),i}case"file":{const i=e,{exts:c,mimes:d}=P$(i.accept),u=I$(e);let f=So().test("file-shape","ds.fields.validation.invalidFile",h=>(h==null,!0));if((n=t.fileMaxSizeMB)!=null&&n.value){const h=Number(t.fileMaxSizeMB.value)*1024*1024,p=t.fileMaxSizeMB.message||"ds.fields.validation.fileMaxSize";f=f.test("file-max-size",p,m=>m?(Array.isArray(m)?m:typeof FileList<"u"&&m instanceof FileList?Array.from(m):[m].filter(Boolean)).every(g=>typeof(g==null?void 0:g.size)!="number"||g.size<=h):!0)}return(c.length||d.length)&&(f=f.test("file-accept","ds.fields.validation.invalidFileType",h=>h?(Array.isArray(h)?h:typeof FileList<"u"&&h instanceof FileList?Array.from(h):[h].filter(Boolean)).every(v=>{var y,E,k,j;const g=((E=(y=v==null?void 0:v.name)==null?void 0:y.toLowerCase)==null?void 0:E.call(y))||"",b=((j=(k=v==null?void 0:v.type)==null?void 0:k.toLowerCase)==null?void 0:j.call(k))||"",w=c.length===0||c.some(A=>g.endsWith(A)),x=d.length===0||d.includes(b);return w&&x}):!0)),typeof u=="number"&&(f=f.test("file-max-files","ds.fields.validation.fileMaxCount",h=>h?(Array.isArray(h)?h:typeof FileList<"u"&&h instanceof FileList?Array.from(h):[h].filter(Boolean)).length<=u:!0)),f=br(f,t),f}case"array":{const i=e,c=i.items||[],d=A2(c);let u=id().of(sd(d));t.required&&(u=u.min(1,t.requiredMessage||(typeof t.required=="string"?t.required:"ds.fields.validation.required")));const f=i.validation;return(a=f==null?void 0:f.min)!=null&&a.value&&(u=u.min(f.min.value,f.min.message||"ds.fields.validation.minItems")),(o=f==null?void 0:f.max)!=null&&o.value&&(u=u.max(f.max.value,f.max.message||"ds.fields.validation.maxItems")),u}default:{const i=So();return br(i,t)}}}function A2(e){const t={};for(const r of e){const n=r;n!=null&&n.name&&(t[n.name]=z$(n))}return t}function ld(e){const t=A2(e.fields);return sd(t)}const N2=e=>{let t;const r=new Set,n=(u,f)=>{const h=typeof u=="function"?u(t):u;if(!Object.is(h,t)){const p=t;t=f??(typeof h!="object"||h===null)?h:Object.assign({},t,h),r.forEach(m=>m(t,p))}},a=()=>t,c={setState:n,getState:a,getInitialState:()=>d,subscribe:u=>(r.add(u),()=>r.delete(u))},d=t=e(n,a,c);return c},H$=(e=>e?N2(e):N2),W$=e=>e;function U$(e,t=W$){const r=C.useSyncExternalStore(e.subscribe,C.useCallback(()=>t(e.getState()),[e,t]),C.useCallback(()=>t(e.getInitialState()),[e,t]));return C.useDebugValue(r),r}const F2=e=>{const t=H$(e),r=n=>U$(t,n);return Object.assign(r,t),r},_2=(e=>e?F2(e):F2),Wn=_2(e=>({isActive:!1,formValues:{},systemContext:{},setRuntimeState:t=>e(r=>({...r,...t})),reset:()=>e({isActive:!1,formValues:{},systemContext:{}})}));function cd(e,t){return e?typeof e!="string"?String(e):e.replace(/\{\{([^}]+)\}\}/g,(r,n)=>{let o=n.trim().split(".").reduce((i,c)=>{if(!i)return;if(i[c]!==void 0)return i[c];const d=c.toLowerCase(),u=Object.keys(i).find(f=>f.toLowerCase()===d);return u?i[u]:void 0},t);return o!=null?String(o):r}):""}function zr({options:e,value:t,onChange:r,children:n,className:a,contentClassName:o}){const i=C.useRef(null),[c,d]=C.useState({left:0,width:0}),[u,f]=C.useState(!1),[h,p]=C.useState(!1),m=()=>{if(i.current){const{scrollLeft:g,scrollWidth:b,clientWidth:w}=i.current;f(g>0),p(g<b-w-1)}};C.useLayoutEffect(()=>{const g=i.current;if(!g)return;const b=()=>{const w=g.querySelector(`[data-value="${t}"]`);w&&d({left:w.offsetLeft,width:w.offsetWidth})};return b(),m(),window.addEventListener("resize",b),window.addEventListener("resize",m),()=>{window.removeEventListener("resize",b),window.removeEventListener("resize",m)}},[t,e]);const v=g=>{i.current&&i.current.scrollBy({left:g==="left"?-200:200,behavior:"smooth"})};return l.jsxs("div",{className:a,children:[l.jsxs("div",{className:"relative border-b border-[var(--color-ds-border-default-50)] group",children:[u&&l.jsx("div",{className:"absolute left-0 top-0 bottom-0 z-20 flex items-center bg-gradient-to-r from-[var(--color-ds-background-page)] to-transparent pr-4 pl-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:l.jsx("button",{type:"button",onClick:()=>v("left"),className:"p-1 rounded-full bg-[var(--color-ds-background-surface)] shadow-sm border border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-button-hover-bg)] hover:text-white transition-colors",children:l.jsx(x1,{className:"w-4 h-4"})})}),l.jsx("div",{ref:i,onScroll:m,className:"overflow-x-auto scrollbar-hidden flex items-center w-full relative",style:{scrollBehavior:"smooth"},children:l.jsxs("div",{className:"relative flex min-w-full px-1",children:[e.map(g=>{const b=g.value===t;return l.jsxs("button",{"data-value":g.value,role:"tab","aria-selected":b,onClick:()=>!g.disabled&&r(g.value),type:"button",className:ve("relative z-10 whitespace-nowrap px-4 py-2 transition-colors duration-150 ease-in-out font-medium text-sm focus:outline-none",b?"text-[var(--color-ds-background-accent)]":"text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]",g.disabled&&"opacity-50 cursor-not-allowed"),disabled:g.disabled,children:[g.icon&&l.jsx("span",{className:"mr-2 -ml-1 inline-block align-text-bottom",children:g.icon}),g.label]},g.value)}),l.jsx("span",{className:"absolute bottom-0 h-0.5 bg-[var(--color-ds-background-accent)] transition-all duration-200 ease-in-out z-20",style:{left:c.left,width:c.width}})]})}),h&&l.jsx("div",{className:"absolute right-0 top-0 bottom-0 z-20 flex items-center bg-gradient-to-l from-[var(--color-ds-background-page)] to-transparent pl-4 pr-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:l.jsx("button",{type:"button",onClick:()=>v("right"),className:"p-1 rounded-full bg-[var(--color-ds-background-surface)] shadow-sm border border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-button-hover-bg)] hover:text-white transition-colors",children:l.jsx(Ps,{className:"w-4 h-4"})})})]}),l.jsx("div",{className:ve("mt-4",o),children:n[t]})]})}const _a={sm:"text-ds-sm",md:"text-ds-md",lg:"text-ds-lg"},vi={sm:"h-5",md:"h-10",lg:"h-12"},bi={sm:"px-2",md:"px-2.5",lg:"px-3"},wi={sm:"1.5rem",md:"2.5rem",lg:"3rem"},xi={sm:"pr-9",md:"pr-11",lg:"pr-12"},q$={sm:"h-6 w-6",md:"h-8 w-8",lg:"h-10 w-10"};function yi({id:e,size:t,disabled:r,error:n,reserveErrorSpace:a,className:o,suffixButton:i,children:c,showDropdownIndicator:d}){var u;return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:ve("relative w-full",o),children:[c,d&&!i&&l.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-2 flex items-center",children:l.jsx(fr,{className:"h-4 w-4 text-[var(--color-ds-text-secondary)]"})}),i&&l.jsx("div",{className:"pointer-events-none absolute flex items-center",style:{top:2,bottom:2,right:4},children:l.jsx("div",{className:"pointer-events-auto",children:C.isValidElement(i)?C.cloneElement(i,{className:ve(q$[t],(u=i.props)==null?void 0:u.className)}):i})})]}),a?l.jsx("div",{className:"h-[1em]",children:n!=null&&n.message?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:n.message}):l.jsx("span",{"aria-hidden":"true",children:" "})}):n!=null&&n.message?l.jsx("div",{className:"pt-1",children:l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:n.message})}):null]})}function M2(e,t){C.useEffect(()=>{const r=n=>{e.current&&(e.current.contains(n.target)||t())};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[t,e])}function Xe(e){const{control:t,name:r,rules:n,defaultValue:a,options:o=[],loadOptions:i,reloadDeps:c=[],value:d,onChange:u,size:f="sm",width:h="100%",label:p,labelHidden:m=!1,info:v,infoHeader:g,hasError:b=!1,errorMessage:w="",reserveErrorSpace:x,disableErrorPlaceholder:y,disabled:E=!1,className:k,suffixButton:j,loading:A=!1,coerceFirstValid:S=!0,mode:_="menu",renderTrigger:O,renderOption:B,popupWidth:R,triggerClassName:I,onBlur:F,searchable:Z=!1,searchPlaceholder:ee="Buscar...",noOptionsText:Y="No se encontraron resultados"}=e,te=C.useId(),ae=r||te,[q,N]=C.useState(o),[L,ne]=C.useState(!!i);C.useEffect(()=>{if(!i){N(o);return}ne(!0),i().then(be=>N(be)).finally(()=>ne(!1))},[i,...c]),C.useEffect(()=>{i||N(o)},[o,i]);const K=be=>be.find(fe=>fe.value!==""&&fe.value!==void 0)??be[0],Q=(be,fe)=>{const xe=fe.trim().toLowerCase();return xe?be.filter(D=>String(D.label).toLowerCase().includes(xe)||String(D.value).toLowerCase().includes(xe)):be},he=typeof x=="boolean"?x:!!t,ie=h&&(h.includes(" ")||h.startsWith("w-")||h.startsWith("max-w-")||h.startsWith("min-w-")),me=ie?{maxWidth:"100%"}:{width:h,maxWidth:"100%"},ce=ve("flex flex-col",ie&&h,k);if(t&&r){const{field:be,fieldState:fe}=a5({name:r,control:t,rules:n,defaultValue:a});C.useEffect(()=>{if(!L&&q.length>0&&S){const D=be.value,G=q.some(re=>String(re.value)===String(D));(D===void 0||!G)&&be.onChange(K(q).value)}},[q,L,be,S]);const xe=p&&!m&&l.jsx(gr,{id:ae,text:p,size:f,info:v,infoHeader:g});if((_??"native")==="menu"){const[D,G]=C.useState(!1),[re,W]=C.useState(""),H=C.useRef(null);M2(H,()=>{G(!1),W("")});const X=q.find(V=>String(V.value)===String(be.value)),M=Z?Q(q,re):q;return l.jsxs("div",{className:ce,style:me,children:[xe,A||L?l.jsx(Pr,{width:"100%",height:wi[f],variant:"rect",className:"rounded-lg"}):l.jsx(yi,{id:ae,size:f,disabled:E,error:fe.error,reserveErrorSpace:typeof y=="boolean"?!y:he,className:k,suffixButton:j,showDropdownIndicator:!0,children:l.jsxs("div",{className:"relative w-full",ref:H,children:[l.jsx("button",{type:"button",onClick:()=>{E||G(V=>{const T=!V;return T||W(""),T})},onBlur:()=>{be.onBlur(),F==null||F()},className:ve("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none text-left flex items-center",_a[f],vi[f],bi[f],j&&xi[f],fe.error?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default-hover)]",I),"aria-haspopup":"listbox","aria-expanded":D,children:O?O(X):(X==null?void 0:X.label)??"—"}),D&&l.jsxs("div",{role:"listbox",className:"custom-scroll absolute z-50 mt-1 rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-xl p-1 max-h-72 overflow-auto",style:{width:R??"100%"},children:[Z&&l.jsx("div",{className:"sticky top-0 z-10 bg-[var(--color-ds-background-page)] p-1",children:l.jsx("input",{type:"text",value:re,onChange:V=>W(V.target.value),onClick:V=>V.stopPropagation(),placeholder:ee,className:"w-full rounded-lg border border-[var(--color-ds-border-default)] bg-[var(--color-ds-background-page)] px-2 py-2 text-sm outline-none"})}),M.length>0?M.map(V=>{const T=String(V.value)===String(be.value);return l.jsx("button",{role:"option","aria-selected":T,type:"button",onClick:()=>{be.onChange(V.value),G(!1),W("")},className:ve("w-full rounded-lg px-2 py-1.5 text-left transition-all duration-200",_a[f],T?"bg-[var(--color-ds-background-neutral)] font-medium text-[var(--color-ds-text-primary)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)] hover:pl-3"),children:B?B(V,T):V.label},V.value)}):l.jsx("div",{className:"px-2 py-2 text-sm text-[var(--color-ds-text-secondary)]",children:Y})]})]})})]})}return l.jsxs("div",{className:ce,style:me,children:[xe,A||L?l.jsx(Pr,{width:"100%",height:wi[f],variant:"rect",className:"rounded-lg"}):l.jsx(yi,{id:ae,size:f,disabled:E,error:fe.error,reserveErrorSpace:typeof y=="boolean"?!y:he,className:k,suffixButton:j,showDropdownIndicator:!0,children:l.jsx("select",{id:ae,value:be.value,onChange:D=>be.onChange(D.target.value),onBlur:()=>{be.onBlur(),F==null||F()},disabled:E,className:ve("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none leading-none",_a[f],vi[f],bi[f],j&&xi[f],fe.error?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)]",I),children:q.map(D=>l.jsx("option",{value:D.value,className:"bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-primary)]",children:D.label},D.value))})})]})}C.useEffect(()=>{if(!t&&q.length>0&&S){const be=q.some(xe=>String(xe.value)===String(d));(d===void 0||d===""||!be)&&u&&u(K(q).value)}},[q,d,u,t,S]);const le=p&&!m&&l.jsx(gr,{id:ae,text:p,size:f,info:v,infoHeader:g});if((_??"native")==="menu"){const[be,fe]=C.useState(!1),[xe,D]=C.useState(""),G=C.useRef(null);M2(G,()=>{fe(!1),D("")});const re=q.find(H=>String(H.value)===String(d)),W=Z?Q(q,xe):q;return l.jsxs("div",{className:ce,style:me,children:[le,A||L?l.jsx(Pr,{width:"100%",height:wi[f],variant:"rect",className:"rounded-lg"}):l.jsx(yi,{id:ae,size:f,disabled:E,error:b?{message:w}:void 0,reserveErrorSpace:typeof y=="boolean"?!y:!!(x??!1),className:k,suffixButton:j,showDropdownIndicator:!0,children:l.jsxs("div",{className:"relative w-full",ref:G,children:[l.jsx("button",{type:"button",onClick:()=>{E||fe(H=>{const X=!H;return X||D(""),X})},onBlur:F,className:ve("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none text-left flex items-center",_a[f],vi[f],bi[f],j&&xi[f],b?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default-hover)]",I),"aria-haspopup":"listbox","aria-expanded":be,children:O?O(re):(re==null?void 0:re.label)??"—"}),be&&l.jsxs("div",{role:"listbox",className:"custom-scroll absolute z-50 mt-1 rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-xl p-1 max-h-72 overflow-auto",style:{width:R??"100%"},children:[Z&&l.jsx("div",{className:"sticky top-0 z-10 bg-[var(--color-ds-background-page)] p-1",children:l.jsx("input",{type:"text",value:xe,onChange:H=>D(H.target.value),onClick:H=>H.stopPropagation(),placeholder:ee,className:"w-full rounded-lg border border-[var(--color-ds-border-default)] bg-[var(--color-ds-background-page)] px-2 py-2 text-sm outline-none"})}),W.length>0?W.map(H=>{const X=String(H.value)===String(d);return l.jsx("button",{role:"option","aria-selected":X,type:"button",onClick:()=>{u==null||u(H.value),fe(!1),D("")},className:ve("w-full rounded-lg px-2 py-1.5 text-left transition-all duration-200",_a[f],X?"bg-[var(--color-ds-background-neutral)] font-medium text-[var(--color-ds-text-primary)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)] hover:pl-3"),children:B?B(H,X):H.label},H.value)}):l.jsx("div",{className:"px-2 py-2 text-sm text-[var(--color-ds-text-secondary)]",children:Y})]})]})})]})}return l.jsxs("div",{className:ce,style:me,children:[le,A||L?l.jsx(Pr,{width:"100%",height:wi[f],variant:"rect",className:"rounded-lg"}):l.jsx(yi,{id:ae,size:f,disabled:E,error:b?{message:w}:void 0,reserveErrorSpace:typeof y=="boolean"?!y:!!(x??!1),className:k,suffixButton:j,showDropdownIndicator:!0,children:l.jsx("select",{id:ae,value:d,onChange:be=>u==null?void 0:u(be.target.value),onBlur:F,disabled:E,className:ve("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none leading-none",_a[f],vi[f],bi[f],j&&xi[f],b?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)]"),children:q.map(be=>l.jsx("option",{value:be.value,className:"bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-primary)]",children:be.label},be.value))})})]})}const R2={sm:"text-ds-sm",md:"text-ds-md",lg:"text-ds-lg"};function O2(e){var t;e.preventDefault(),e.stopPropagation(),(t=e.nativeEvent)!=null&&t.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()}function dd({groupLabel:e,inputs:t=[],separator:r=l.jsx("span",{className:"px-1 select-none",children:"/"}),useSeparator:n=!1,className:a,showVisibleLabel:o=!1,size:i="sm",width:c,respectChildWidths:d=!1}){const u=t.length,f=c&&(c.includes(" ")||c.startsWith("w-")||c.startsWith("max-w-")||c.startsWith("min-w-")),h=f?void 0:c?{width:c}:void 0;return l.jsxs("div",{"data-input-group-root":!0,role:"group",className:ve("flex flex-col w-full",f&&c,a),style:h,onDoubleClick:O2,onDoubleClickCapture:O2,onClickCapture:p=>{var g;const m=p.target;!!((g=m==null?void 0:m.closest)!=null&&g.call(m,'input,select,textarea,button,[data-interactive="true"]'))||p.stopPropagation()},children:[l.jsx("label",{className:ve("sr-only pb-2",R2[i]),children:e}),o&&l.jsx("label",{className:ve("pb-2",R2[i]),children:e}),l.jsx("div",{className:"flex items-stretch flex-nowrap w-full min-w-0",children:t.map((p,m)=>{const{width:v,className:g,options:b,loadOptions:w,info:x,infoHeader:y,...E}=p,k=Array.isArray(b)||typeof w=="function";let j="rounded-lg";!n&&u>1&&(m===0?j="rounded-l-lg rounded-r-none":m===u-1?j="rounded-r-lg rounded-l-none !rounded-l-none":j="rounded-none !rounded-l-none !rounded-r-none");const A=d?v:void 0,S=typeof A=="string"&&A.split(/\s+/).some(R=>R.startsWith("w-")||R.includes(":w-")),_=ve("inline-flex items-stretch",A?"flex-shrink-0":"flex-1 min-w-0",typeof A=="string"&&S?A:void 0,!n&&u>1&&m>0?"-ml-px focus-within:z-10 relative":void 0),O=A?typeof A=="string"&&S?void 0:{width:A}:void 0,B=ve(g,"w-full",j);return l.jsxs(C.Fragment,{children:[l.jsx("div",{className:_,style:O,children:k?l.jsx(Xe,{...E,size:i,className:g,triggerClassName:ve("w-full",j),options:b,loadOptions:w,"data-interactive":"true",info:x,infoHeader:y,mode:"menu",searchable:!0,searchPlaceholder:B5("ds.fields.defaults.search.placeholder"),noOptionsText:B5("ds.fields.defaults.search.noMatches")}):l.jsx(je,{...E,size:i,className:B,"data-interactive":"true",info:x,infoHeader:y})}),n&&m<u-1&&l.jsx("div",{className:"flex items-center flex-shrink-0 px-1 select-none",children:r})]},m)})})]})}const G$={sm:"w-4 h-4",md:"w-5 h-5",lg:"w-6 h-6"},K$={sm:"w-3 h-3",md:"w-3.5 h-3.5",lg:"w-4 h-4"};function ki({groupLabel:e,options:t,control:r,name:n,rules:a,defaultValue:o,multiple:i=!0,size:c="sm",vertical:d=!0,className:u,showVisibleLabel:f=!0,disabled:h=!1,hasError:p=!1,errorMessage:m}){return l.jsx(Et,{name:n,control:r,rules:a,defaultValue:o,render:({field:v,fieldState:g})=>{const{value:b,onChange:w}=v,x=g.error,y=A=>{var S;return i?Array.isArray(b)&&((S=b==null?void 0:b.includes)==null?void 0:S.call(b,A)):b===A},E=A=>{if(!h)if(i){const S=Array.isArray(b)?[...b]:[],_=S.indexOf(A);_>=0?S.splice(_,1):S.push(A),w(S)}else w(A)},k=p||!!x,j=(x==null?void 0:x.message)||m;return l.jsxs("fieldset",{className:ve("w-full flex flex-col gap-1",u),"aria-invalid":k||void 0,disabled:h,children:[e&&l.jsx("legend",{className:ve("mb-1 text-ds-sm text-[var(--color-ds-text-primary)]",!f&&"sr-only"),children:e}),l.jsx("div",{className:ve(d?"flex flex-col gap-2":"flex flex-wrap gap-2"),children:t.map(A=>{const S=y(A.value),_=h||!!(A!=null&&A.disabled),O=ve("inline-flex items-center justify-center border transition-all duration-150",i?"rounded-[6px]":"rounded-full",G$[c],"bg-[var(--color-ds-background-page)]","border-[var(--color-ds-border-default-50)]","shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-default)20%,transparent)]","peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--color-ds-border-default)]","hover:border-[var(--color-ds-border-default)]",i&&S&&"bg-[var(--color-ds-button-primary-bg)] border-[var(--color-ds-button-primary-bg)]",!i&&S&&"border-[var(--color-ds-button-primary-bg)]",k&&"border-[var(--color-ds-border-error)] shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-error)30%,transparent)]",_&&"opacity-60 cursor-not-allowed"),B=ve("text-ds-sm text-[var(--color-ds-text-primary)]",_&&"text-[var(--color-ds-text-secondary)]"),R=ve(K$[c],"text-[var(--color-ds-button-primary-text)] transition-all duration-150",S?"opacity-100 scale-100":"opacity-0 scale-75"),I=ve(c==="sm"?"w-2 h-2":c==="md"?"w-2.5 h-2.5":"w-3 h-3","rounded-full bg-[var(--color-ds-button-primary-bg)] transition-all duration-150",S?"opacity-100 scale-100":"opacity-0 scale-0");return l.jsxs("label",{className:ve("inline-flex items-center gap-2 cursor-pointer select-none rounded-md px-1 py-1","hover:bg-[color-mix(in_srgb,var(--color-ds-border-default)6%,transparent)]",_&&"cursor-not-allowed hover:bg-transparent"),children:[l.jsxs("span",{className:"relative inline-flex items-center justify-center",children:[l.jsx("input",{type:i?"checkbox":"radio",name:n,value:A.value,checked:S,onChange:()=>E(A.value),disabled:_,className:"peer sr-only"}),l.jsx("span",{"aria-hidden":!0,className:O,children:i?l.jsx(Bc,{className:R}):l.jsx("span",{className:I})})]}),l.jsx("span",{className:B,children:A.label})]},String(A.value))})}),k&&!!j&&l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] mt-1",children:j})]})}})}function J$(e){function t(i){var c,d;for(const u of Object.keys(i)){if((c=i[u])!=null&&c.types||(d=i[u])!=null&&d.message)return u;if(typeof i[u]=="object"){const f=t(i[u]);if(f)return`${u}.${f}`}}return null}const r=t(e);if(!r)return;const n=`[name="${r}"]`,a=`[name^="${r}["], [name^="${r}."]`,o=document.querySelector(n)??document.querySelector(a);o&&(o.scrollIntoView({behavior:"smooth",block:"center"}),o.focus({preventScroll:!0}))}const Y$={success:"bg-green-100 border-green-500 text-green-800",error:"bg-red-100 border-red-500 text-red-800",info:"bg-blue-100 border-blue-500 text-blue-800",warning:"bg-yellow-100 border-yellow-500 text-yellow-800"},L2=({id:e,message:t,variant:r="info",duration:n=5e3,onClose:a})=>(C.useEffect(()=>{const o=setTimeout(()=>a(e),n);return()=>clearTimeout(o)},[e,n,a]),l.jsxs("div",{className:ve("w-80 max-w-full border-l-4 rounded shadow-md p-4 mb-2 flex justify-between items-start",Y$[r]),role:"alert","aria-live":"assertive",children:[l.jsx("span",{className:"flex-1",children:t}),l.jsx("button",{onClick:()=>a(e),className:"ml-4 text-xl font-bold leading-none focus:outline-none",children:"×"})]})),Ct=[];for(let e=0;e<256;++e)Ct.push((e+256).toString(16).slice(1));function X$(e,t=0){return(Ct[e[t+0]]+Ct[e[t+1]]+Ct[e[t+2]]+Ct[e[t+3]]+"-"+Ct[e[t+4]]+Ct[e[t+5]]+"-"+Ct[e[t+6]]+Ct[e[t+7]]+"-"+Ct[e[t+8]]+Ct[e[t+9]]+"-"+Ct[e[t+10]]+Ct[e[t+11]]+Ct[e[t+12]]+Ct[e[t+13]]+Ct[e[t+14]]+Ct[e[t+15]]).toLowerCase()}let ud;const Q$=new Uint8Array(16);function eI(){if(!ud){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ud=crypto.getRandomValues.bind(crypto)}return ud(Q$)}const T2={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function tI(e,t,r){var a;e=e||{};const n=e.random??((a=e.rng)==null?void 0:a.call(e))??eI();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,X$(n)}function rI(e,t,r){return T2.randomUUID&&!e?T2.randomUUID():tI(e)}const $2=C.createContext(null),yn=()=>{const e=C.useContext($2);if(!e)throw new Error("useToast debe usarse dentro de <ToastProvider>");return e},nI=({children:e})=>{const[t,r]=C.useState([]),n=(o,i="info",c=5e3)=>{const d=rI();r(u=>[...u,{id:d,message:o,variant:i,duration:c}])},a=o=>{r(i=>i.filter(c=>c.id!==o))};return l.jsxs($2.Provider,{value:{show:n},children:[e,l.jsx("div",{className:"fixed top-4 right-4 z-50 flex flex-col items-end",children:t.map(o=>l.jsx(L2,{id:o.id,message:o.message,variant:o.variant,duration:o.duration,onClose:a},o.id))})]})},aI=e=>e.type==="inputGroup",oI=e=>e.type==="button",sI=e=>!aI(e)&&!oI(e);function I2(e){const t=Array.isArray(e)?e:[];return C.useMemo(()=>{const r={};for(const n of t)sI(n)&&n.name&&(r[n.name]=n);return r},[t])}const B2=C.createContext(null);function P2({children:e,value:t}){return l.jsx(B2.Provider,{value:t,children:e})}function Zt(){const e=C.useContext(B2);if(!e)throw new Error("useAdapters debe usarse dentro de <AdaptersProvider />");return e}const iI=e=>!!e&&typeof e.then=="function";function lI(e){return Array.isArray(e)?e.length>0&&typeof e[0]=="object"&&e[0]!==null?e.map(t=>{var a;if("label"in t&&"value"in t)return t;const n=(a=Object.entries(t)[0])==null?void 0:a[1];return{label:String(n??JSON.stringify(t)),value:String(n??"")}}):e.map(t=>({label:String(t),value:t})):[]}function V2(e){const{services:t}=Zt(),[r,n]=C.useState({}),[a,o]=C.useState(0),i=C.useRef(!0);C.useEffect(()=>(i.current=!0,()=>{i.current=!1}),[]);const c=C.useMemo(()=>e.filter(d=>d.type==="select"&&!d.options&&typeof d.optionSource=="string"&&d.name),[e]);return C.useEffect(()=>{if(c.length===0)return;let d=!1;return(async()=>{o(u=>u+1);try{const u=await Promise.all(c.map(async f=>{var b;const h=f.name,p=f.optionSource,m=(b=t==null?void 0:t.registry)==null?void 0:b[p];if(!m)return[h,[]];const v=iI(m)?await m:await m(),g=lI(v);return[h,g]}));if(d||!i.current)return;n(f=>{const h={...f};for(const[p,m]of u)h[p]=[...m];return h})}finally{!d&&i.current&&o(u=>Math.max(0,u-1))}})(),()=>{d=!0}},[c,t==null?void 0:t.registry]),{optionsMap:r,loadingCount:a}}const cI=e=>e.type==="inputGroup",dI=e=>e.type==="button",uI=e=>!cI(e)&&!dI(e);function fI(e){return typeof e=="object"&&e!==null}const hI=e=>{const t=e.disabledWhen;if(!fI(t))return!1;const r="watchField"in t,n="rule"in t;return r&&!n};function Z2(e,t){const r=Array.isArray(e)?e:[],n=C.useMemo(()=>r.filter(uI).filter(hI),[r]),a=C.useMemo(()=>n.map(d=>d.disabledWhen.watchField),[n]),o=Ec({control:t,name:a,compute:d=>d}),i=Array.isArray(o)?o:[],c={};return n.forEach((d,u)=>{const f=i[u];c[d.name??`__unnamed_${u}`]=f===d.disabledWhen.watchValue}),c}const pI={sm:"text-ds-sm",md:"text-ds-sm",lg:"text-ds-sm"},mI={sm:"px-2 py-1.5",md:"px-3 py-2",lg:"px-4 py-3"};function Dr({control:e,name:t,rules:r,defaultValue:n,size:a="sm",width:o="100%",label:i,labelHidden:c=!1,hasError:d=!1,errorMessage:u="",maxLength:f,showCounter:h=!1,className:p,suffixButton:m,labelPrefixIcon:v,labelSuffixIcon:g,info:b,infoHeader:w,infoAriaLabel:x,prefixIcon:y,suffixIcon:E,reserveErrorSpace:k,disableErrorPlaceholder:j,id:A,...S}){const _=C.useId(),O=A||_,[B,R]=C.useState(String(n??S.value??"")),I=typeof k=="boolean"?k:typeof j=="boolean"?!j:!!e,F=ve("box-border bg-[var(--color-ds-background-page)] w-full rounded-lg border outline-none transition","placeholder-[var(--color-ds-text-secondary)] text-[var(--color-ds-text-primary)]",pI[a],mI[a],d?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",S.disabled&&"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-secondary)] cursor-not-allowed"),Z=y?"pl-9":"",ee=E?"pr-9":"",Y=N=>{var L;typeof f=="number"&&N.target.value.length>f||(R(N.target.value),(L=S.onChange)==null||L.call(S,N))},te=o&&(o.includes(" ")||o.startsWith("w-")||o.startsWith("max-w-")||o.startsWith("min-w-")),ae=te?void 0:{width:o},q=ve("flex flex-col",te&&o,p);return C.useEffect(()=>{n!==void 0&&R(String(n??""))},[n]),e&&t?l.jsx(Et,{name:t,control:e,rules:r,defaultValue:n??"",render:({field:N,fieldState:L})=>{var ne;return l.jsxs("div",{className:q,style:ae,children:[!c&&i&&l.jsx(gr,{id:O,text:i,size:a,prefixIcon:v,suffixIcon:g,info:b,infoHeader:w,infoAriaLabel:x}),l.jsxs("div",{className:"flex items-stretch gap-2",children:[l.jsxs("div",{className:"relative w-full",children:[y&&l.jsx("span",{className:"absolute left-2 top-2.5",children:l.jsx(Ft,{component:y,size:a,className:"text-[var(--color-ds-text-secondary)]"})}),l.jsx("textarea",{id:O,"aria-invalid":!!L.error,className:ve(F,Z,ee),maxLength:f,...N,placeholder:S.disabled?"":S.placeholder,onChange:K=>{N.onChange(K),h&&R(K.target.value)}}),E&&l.jsx("span",{className:"absolute right-2 top-2.5",children:l.jsx(Ft,{component:E,size:a,className:"text-[var(--color-ds-text-secondary)]"})})]}),m?l.jsx("div",{className:"shrink-0",children:m}):null]}),l.jsxs("div",{className:"flex justify-between pt-1 h-[1em]",children:[I?L.error?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:L.error.message}):l.jsx("span",{"aria-hidden":"true",children:" "}):L.error?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:L.error.message}):l.jsx("span",{"aria-hidden":"true",children:" "}),h&&typeof f=="number"&&l.jsxs("span",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:[((ne=N.value)==null?void 0:ne.length)??0,"/",f]})]})]})}}):l.jsxs("div",{className:q,style:ae,children:[!c&&i&&l.jsx(gr,{id:O,text:i,size:a,prefixIcon:v,suffixIcon:g,info:b,infoHeader:w,infoAriaLabel:x}),l.jsxs("div",{className:"flex items-stretch gap-2",children:[l.jsxs("div",{className:"relative w-full",children:[y&&l.jsx("span",{className:"absolute left-2 top-2.5",children:l.jsx(Ft,{component:y,size:a,className:"text-[var(--color-ds-text-secondary)]"})}),l.jsx("textarea",{id:O,className:ve(F,Z,ee),value:B,onChange:Y,maxLength:f,...S,placeholder:S.disabled?"":S.placeholder}),E&&l.jsx("span",{className:"absolute right-2 top-2.5",children:l.jsx(Ft,{component:E,size:a,className:"text-[var(--color-ds-text-secondary)]"})})]}),m?l.jsx("div",{className:"shrink-0",children:m}):null]}),l.jsxs("div",{className:"flex justify-between pt-1 h-[1em]",children:[I?d&&u?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:u}):l.jsx("span",{"aria-hidden":"true",children:" "}):d&&u?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:u}):l.jsx("span",{"aria-hidden":"true",children:" "}),h&&typeof f=="number"&&l.jsxs("span",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:[B.length,"/",f]})]})]})}const gI={sm:"w-4 h-4",md:"w-5 h-5",lg:"w-6 h-6"},vI={sm:"w-3 h-3",md:"w-3.5 h-3.5",lg:"w-4 h-4"};function it({control:e=null,name:t,rules:r,defaultValue:n=!1,label:a,labelHidden:o=!1,disabled:i=!1,size:c="sm",className:d,hasError:u=!1,errorMessage:f="",reserveErrorSpace:h,disableErrorPlaceholder:p,checked:m,indeterminate:v,onChange:g}){const b=ve("text-[var(--color-ds-text-primary)] text-ds-sm",i&&"text-[var(--color-ds-text-secondary)]",o&&"sr-only"),w=typeof h=="boolean"?h:typeof p=="boolean"?!p:!!e,x=(y,E,k)=>{const j=u||!!k,A=(k==null?void 0:k.message)||f,S=ve("inline-flex items-center justify-center rounded-[6px] border transition-all duration-150",gI[c],"bg-[var(--color-ds-background-page)]","border-[var(--color-ds-border-default-50)]","shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-default)20%,transparent)]","peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--color-ds-border-default)]","hover:border-[var(--color-ds-border-default)]",(y||v)&&"bg-[var(--color-ds-button-primary-bg)] border-[var(--color-ds-button-primary-bg)]",j&&"border-[var(--color-ds-border-error)] shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-error)30%,transparent)]",i&&"opacity-60 cursor-not-allowed"),_=ve(vI[c],"text-[var(--color-ds-button-primary-text)]","transition-all duration-150",y||v?"opacity-100 scale-100":"opacity-0 scale-75");return l.jsxs("div",{className:ve("flex flex-col gap-1",d),children:[C.createElement(typeof a=="string"?"label":"div",{className:ve("inline-flex items-center gap-2 cursor-pointer select-none",i&&"cursor-not-allowed")},l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"relative inline-flex items-center justify-center",children:[l.jsx("input",{id:t,type:"checkbox",className:"peer sr-only",checked:y,ref:O=>{O&&(O.indeterminate=!!v)},onChange:O=>E(O.target.checked),disabled:i}),l.jsx("span",{"aria-hidden":!0,className:S,children:v?l.jsx("div",{className:"bg-white h-0.5 w-[60%] rounded-full"}):l.jsx(Bc,{className:_})})]}),a&&l.jsx("span",{className:b,children:a})]})),w?l.jsx("div",{className:"h-[1em]",children:j&&A?l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:A}):l.jsx("span",{"aria-hidden":"true",children:" "})}):j&&A?l.jsx("div",{className:"pt-1",children:l.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:A})}):null]})};return e?l.jsx(Et,{name:t||"",control:e,rules:r,defaultValue:n,render:({field:y,fieldState:E})=>{const k=E.error;return x(!!y.value,j=>y.onChange(j),k)}}):x(!!m,y=>g==null?void 0:g(y))}function fd({name:e,control:t,searchFn:r,resolveByValue:n,label:a,size:o="sm",width:i="100%",disabled:c=!1,searchMode:d="button",minChars:u=3,debounceMs:f=600,labelPrefixIcon:h,labelSuffixIcon:p,prefixIcon:m,suffixIcon:v,reserveErrorSpace:g,disableErrorPlaceholder:b}){const w=gn(),{watch:x,getValues:y,setValue:E}=w,k=Ec({control:t,name:e}),[j,A]=C.useState([]),[S,_]=C.useState(!1),[O,B]=C.useState(!1),[R,I]=C.useState(""),F=C.useRef(null),Z=C.useRef(null),ee=C.useRef(!1),Y=C.useRef(!1),te=C.useRef(!0),ae=C.useMemo(()=>{const ce=new Map;for(const le of j)ce.set(String(le.value).trim(),le.label??"");return ce},[j]),q=async ce=>{const le=(ce??"").trim();if(!le){A([]),B(!1);return}_(!0);try{const be=await r(le,{watch:x,getValues:y});A(be??[]),B(!0)}finally{_(!1)}};C.useEffect(()=>{function ce(le){F.current&&!F.current.contains(le.target)&&B(!1)}if(O)return document.addEventListener("mousedown",ce),()=>document.removeEventListener("mousedown",ce)},[O]);const[N,L]=C.useState({});C.useEffect(()=>{if(ee.current)return;const le=(k?String(k):"").trim();if(!le){R!==""&&I(""),B(!1);return}const be=ae.get(le);if(be){R!==be&&(I(be),te.current=!0);return}const fe=N[le];if(fe){R!==fe&&(I(fe),te.current=!0);return}let xe=!1;return n?(R!==le&&I(le),(async()=>{try{const D=await n(le,{watch:x,getValues:y});if(xe)return;if(D){const G=D.label??String(D.value);L(re=>{const W={...re,[le]:G};return I(G),te.current=!0,W})}else R!==le&&(I(le),te.current=!0)}catch{!xe&&R!==le&&(I(le),te.current=!0)}})()):R!==le&&(I(le),te.current=!0),()=>{xe=!0}},[k,ae,N,n,x,y]),C.useEffect(()=>{if(d!=="debounced"||c)return;if(te.current){te.current=!1;return}if(!Y.current)return;Z.current&&(window.clearTimeout(Z.current),Z.current=null);const ce=(R||"").trim();return ce.length>=u?Z.current=window.setTimeout(()=>{q(ce)},f):(A([]),B(!1)),()=>{Z.current&&(window.clearTimeout(Z.current),Z.current=null)}},[R,d,u,f,c]);const ne=o==="sm"?"text-ds-sm":o==="md"?"text-ds-md":"text-ds-lg",K=o==="sm"?"h-6":o==="md"?"h-10":"h-12",Q=ce=>{if(c)return;const le=(R||"").trim();ce.key==="Enter"&&(ce.preventDefault(),d==="debounced"?le.length>=u&&q(le):q(le)),ce.key==="Escape"&&B(!1)},he=i&&(i.includes(" ")||i.startsWith("w-")||i.startsWith("max-w-")||i.startsWith("min-w-")),ie=he?void 0:{width:i},me=`relative flex flex-col ${he?i:""}`;return l.jsx(Et,{name:e,control:t,render:({field:ce,fieldState:le})=>{var be;return l.jsxs("div",{ref:F,className:me,style:ie,children:[a&&l.jsx(gr,{id:e,text:a,size:o,prefixIcon:h,suffixIcon:p}),l.jsx(je,{className:d==="button"?"rounded-r-none":void 0,type:"text",size:o,width:"100%",value:R,prefixIcon:m,suffixIcon:v,onChange:fe=>{const xe=fe.target.value;ee.current=!0,Y.current=!0,I(xe),(k?String(k):"").trim()&&E(e,"",{shouldDirty:!0})},onKeyDown:Q,onBlur:()=>{ee.current=!1},disabled:c,hasError:le.invalid,errorMessage:(be=le.error)==null?void 0:be.message,reserveErrorSpace:g,disableErrorPlaceholder:b,onFocus:()=>{if(ee.current=!0,d==="button"&&Y.current){const fe=(R||"").trim();fe&&q(fe)}},suffixButton:d==="button"?l.jsx(pe,{type:"button",className:"!rounded-l-none",size:o,variant:"primary",onClick:()=>q((R||"").trim()),disabled:c,children:"Buscar"}):void 0}),S&&l.jsx("div",{className:"absolute top-14 left-0 right-0 z-10",children:l.jsx(Pr,{width:"100%",height:o==="sm"?"1.5rem":o==="md"?"2.5rem":"3rem",variant:"rect",className:"rounded-lg"})}),O&&!S&&j.length>0&&l.jsx("ul",{className:`
93
93
  absolute top-14 left-0 right-0
94
94
  border-[var(--color-ds-border-default)]
95
95
  rounded-lg bg-[var(--color-ds-background-page)]
96
96
  shadow-lg ${ne} max-h-48 overflow-auto z-10
97
97
  `,children:j.map(fe=>l.jsx("li",{className:`px-2 ${K} flex items-center cursor-pointer
98
98
  text-[var(--color-ds-text-primary)]
99
- hover:bg-[var(--color-ds-background-surface)]`,onClick:()=>{const xe=String(fe.value).trim();E(e,xe,{shouldDirty:!0,shouldValidate:!0}),I(fe.label??xe),ee.current=!1,Y.current=!1,B(!1)},children:fe.label},String(fe.value)))})]})}})}const No=(e,t)=>e[t],z2=e=>e instanceof Date?e.getTime():e;function bI(e,t,r){const n=z2(e),a=z2(t);return typeof n=="number"&&typeof a=="number"||typeof n=="string"&&typeof a=="string"?r==="gt"?n>a:r==="gte"?n>=a:r==="lt"?n<a:n<=a:!1}function Ei(e,t){if(!e)return!1;switch(e.op){case"eq":return No(t,e.field)===e.value;case"neq":return No(t,e.field)!==e.value;case"in":return e.values.includes(No(t,e.field));case"notIn":return!e.values.includes(No(t,e.field));case"gt":case"gte":case"lt":case"lte":return bI(No(t,e.field),e.value,e.op);case"and":return e.rules.every(r=>Ei(r,t));case"or":return e.rules.some(r=>Ei(r,t));case"always":return!!e.value;default:return!1}}function hd(e){return!!e&&(typeof e=="function"||typeof e=="object")}function Ma(e,t){const r=t==="outline"?ba:Da,n=r==null?void 0:r[e];return hd(n)?n:null}const wI=Object.entries(ba).filter(([e,t])=>e.endsWith("Icon")&&hd(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),xI=Object.entries(Da).filter(([e,t])=>e.endsWith("Icon")&&hd(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),yI=dc||cc||(e=>l.jsx("svg",{...e})),Un=({value:e,onChange:t,buttonLabel:r,disabled:n,className:a})=>{const[o,i]=C.useState(!1),[c,d]=C.useState(""),[u,f]=C.useState((e==null?void 0:e.style)??"outline"),h=e&&Ma(e.name,e.style)||yI,p=C.useCallback((v,g)=>{const b=Ma(v,g);t==null||t({name:v,style:g},b),i(!1)},[t]),m=C.useCallback(()=>{t==null||t(void 0,void 0),i(!1)},[t]);return l.jsxs(l.Fragment,{children:[l.jsx(pe,{size:"sm",variant:"outline",shape:"circle",className:`rounded-full p-0 w-8 h-8 inline-flex items-center justify-center ${a??""}`,disabled:n,onClick:()=>i(!0),ariaLabel:"Elegir icono",title:r||"Elegir icono",children:l.jsx(h,{className:"h-4 w-4"})}),l.jsx(Bt,{isOpen:o,onClose:()=>i(!1),title:"Seleccionar icono",children:l.jsxs("div",{className:"space-y-3",children:[l.jsx(je,{labelHidden:!0,placeholder:"Buscar icono (p. ej. 'user', 'arrow', 'calendar'...)",value:c,onChange:v=>d(v.target.value)}),l.jsx(zr,{options:[{label:"Outline",value:"outline"},{label:"Solid",value:"solid"}],value:u,onChange:v=>f(v),children:{outline:l.jsx(H2,{items:wI,query:c,onPick:v=>p(v,"outline"),onClear:m}),solid:l.jsx(H2,{items:xI,query:c,onPick:v=>p(v,"solid"),onClear:m})}})]})})]})},H2=({items:e,query:t,onPick:r,onClear:n})=>{const a=C.useMemo(()=>{if(!t.trim())return e;const i=t.trim().toLowerCase().replace(/\s+/g,"");return e.filter(c=>c.name.toLowerCase().includes(i))},[e,t]),o=st;return l.jsx("div",{className:"custom-scroll max-h-[60vh] overflow-y-auto",children:l.jsxs("div",{className:"grid gap-2 grid-cols-3 sm:grid-cols-4 md:grid-cols-6",children:[l.jsxs("button",{type:"button",onClick:n,className:"group w-full aspect-square border border-[var(--color-ds-border-default-50)] rounded-lg p-1 bg-[var(--color-ds-background-page)] hover:bg-[var(--color-ds-background-accent)]/5 hover:border-[var(--color-ds-border-default)] transition focus:outline-none",title:"Ninguno","aria-label":"Quitar icono",children:[l.jsx("div",{className:"h-full w-full flex items-center justify-center",children:o?l.jsx(o,{className:"w-6 h-6"}):l.jsx("span",{className:"text-ds-lg",children:"×"})}),l.jsx("div",{className:"mt-1 text-center",children:l.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:"Ninguno"})})]}),(a.length===0?e:a).map(({name:i,Icon:c})=>l.jsxs("button",{type:"button",onClick:()=>r(i),className:"group w-full aspect-square border border-[var(--color-ds-border-default-50)] rounded-lg p-1 bg-[var(--color-ds-background-page)] hover:bg-[var(--color-ds-background-accent)]/5 hover:border-[var(--color-ds-border-default)] transition focus:outline-none",title:i,"aria-label":`Elegir ${i}`,children:[l.jsx("div",{className:"h-full w-full flex items-center justify-center",children:l.jsx(c,{className:"w-6 h-6 text-[var(--color-ds-text-primary)]"})}),l.jsx("div",{className:"mt-1 text-center",children:l.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:i.replace(/Icon$/,"")})})]},i))]})})};function mt(e,t,r=""){if(!t)return r;if(typeof t=="object"&&t!==null){if(t.type==="complex"){const a=[];return t.header&&a.push(`<strong>${t.header}</strong>`),t.template&&a.push(t.template),a.join("<br/>")||r}return r}return e(t,{defaultValue:t})}const kI=({schema:e,renderField:t})=>{var g,b,w;const{control:r}=gn(),{fields:n,append:a,remove:o}=HE({control:r,name:e.name}),{label:i,addLabel:c="Añadir",items:d,disabled:u,validation:f,className:h}=e,{formState:{errors:p}}=gn(),m=((b=(g=p[e.name])==null?void 0:g.root)==null?void 0:b.message)||((w=p[e.name])==null?void 0:w.message),v=typeof m=="string"?m:void 0;return l.jsxs("div",{className:ve("space-y-3",h),children:[i&&l.jsx("div",{className:"flex items-center justify-between",children:l.jsx("label",{className:"block text-ds-sm font-medium text-[var(--color-ds-text-primary)]",children:i})}),l.jsx("div",{className:"space-y-4",children:n.map((x,y)=>{const E=`${e.name}.${y}`;return l.jsxs("div",{className:"relative rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-4 group",children:[!u&&l.jsx("div",{className:"absolute top-2 right-2",children:l.jsx(pe,{size:"xs",variant:"ghost",className:"text-[var(--color-ds-text-error)] hover:bg-[var(--color-ds-background-error-hover)]",onClick:()=>o(y),title:"Eliminar fila",ariaLabel:"Eliminar fila",children:l.jsx(Dt,{className:"w-4 h-4"})})}),l.jsx("div",{className:"grid grid-cols-1 gap-4",children:d.map((k,j)=>l.jsx(C.Fragment,{children:t(k,E)},j))})]},x.id)})}),n.length===0&&l.jsx("div",{className:"text-ds-sm text-[var(--color-ds-text-secondary)] italic p-2 border border-dashed border-[var(--color-ds-border-default-50)] rounded bg-[var(--color-ds-background-subtle)]",children:"No hay elementos."}),v&&l.jsx("p",{className:"text-xs text-[var(--color-ds-text-error)]",children:v}),!u&&l.jsxs(pe,{type:"button",variant:"outline",size:"sm",onClick:()=>{a({})},children:[l.jsx(hr,{className:"w-4 h-4 mr-1"}),c]})]})};function W2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function EI(e){return e.replace(/(.{4})/g,"$1 ").trim()}function Ci({label:e,labelHidden:t,placeholder:r="ES00 0000 0000 0000 0000 0000",size:n="sm",value:a,onChange:o,onBlur:i,disabled:c,required:d,reserveErrorSpace:u=!0,error:f,errorMessage:h,hasError:p,id:m,name:v,className:g,"aria-label":b}){const w=C.useMemo(()=>W2(a),[a]),x=C.useMemo(()=>EI(w),[w]),y=E=>{const k=W2(E.target.value);o(k)};return l.jsx(je,{id:m,name:v,label:e,labelHidden:t,placeholder:r,size:n,value:x,onChange:y,onBlur:i,disabled:c,required:d,hasError:p||!!f||!!h,errorMessage:h||f,reserveErrorSpace:u,prefixIcon:Wl,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1})}function U2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,9)}function Eee(e){return e}function pd({label:e,labelHidden:t,placeholder:r="12345678A",size:n="sm",value:a,onChange:o,onBlur:i,disabled:c,required:d,reserveErrorSpace:u=!0,error:f,errorMessage:h,hasError:p,id:m,name:v,className:g,"aria-label":b}){const{t:w}=At(),x=C.useMemo(()=>U2(a),[a]),y=C.useMemo(()=>x,[x]),E=k=>{const j=U2(k.target.value);o(j)};return l.jsx(je,{id:m,name:v,label:e,labelHidden:t,placeholder:r,size:n,value:y,onChange:E,onBlur:i,disabled:c,required:d,hasError:p||!!f||!!h,errorMessage:h||f,prefixIcon:nc,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1,reserveErrorSpace:u})}function q2(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function CI(e,t){var r;return Array.isArray(e)?e.length&&typeof e[0]=="object"&&"value"in e[0]?t?e.map(n=>n.value):((r=e[0])==null?void 0:r.value)??"":t?e:e[0]??"":e&&typeof e=="object"&&"value"in e?e.value:e??(t?[]:"")}const jI=e=>e.type!=="inputGroup"&&e.type!=="button";function DI(){try{return Zt()??void 0}catch{return}}function Kt(e){if(!e||typeof e!="object")return;const t=e.name,r=e.style;if(!(!t||!r))return Ma(t,r)||void 0}function G2({schema:e,resolver:t,serviceRegistry:r,activeVariantId:n}){var X;const{layout:a,fields:o=[],onSubmit:i,successMessage:c,errorMessage:d,footerButtons:u,defaultValues:f,loadDefaultValues:h,validationSchema:p}=e,{show:m}=yn(),{t:v}=At(),g=DI(),b=r??((X=g==null?void 0:g.services)==null?void 0:X.registry)??void 0,w=C.useMemo(()=>{if(t)return t;try{const M=p??ld(e);return Xc(M)}catch{return}},[t,e,p]),x=Ic({resolver:w,mode:"onBlur",reValidateMode:"onChange",defaultValues:f??{}}),y=Wn(M=>M.setRuntimeState),E=Wn(M=>M.systemContext),k=Wn(M=>M.formValues);C.useEffect(()=>{y({isActive:!0});let M=!1;return(async()=>{const V=e.defaultSource,T=e.onloadEndpoint;let $={};if(e.variables&&Array.isArray(e.variables)&&(e.variables.forEach(z=>{z.type==="constant"&&($[z.key]=z.value)}),e.variables.forEach(z=>{if(z.type==="computed"&&z.value)try{const U=new Function("ctx",`return (${z.value});`);$[z.key]=U($)}catch(U){console.warn(`[FormRenderer] Error evaluating computed variable "${z.key}":`,U),$[z.key]=null}})),V)try{const z=b==null?void 0:b[V];if(z){const U=typeof z=="function"?await z():z;U&&typeof U=="object"&&($={...$,...U})}}catch{}y({systemContext:{...$}});const P=[];if(T&&P.push(T),e.onloadEndpoints&&Array.isArray(e.onloadEndpoints)&&P.push(...e.onloadEndpoints),P.length>0){const z=async J=>{if(!J)return{};try{const oe=b==null?void 0:b[J.key];if(!oe)return console.warn("[FormRenderer] Provider not found for key:",J.key),{};const de=bn(J.parameters,(()=>({})),{...$,ACTIVE_VARIANT:e.activeVariantId});console.log(`[FormRenderer] Calling ${J.key} with params:`,de);const ge=await Promise.resolve(oe(de,{getValues:(()=>({})),watch:(()=>{}),params:de,...$}));let we=ge;if(typeof ge=="string")try{we=JSON.parse(ge)}catch(Ce){console.warn("[FormRenderer] Failed to parse onload response string",Ce)}return we&&typeof we=="object"?we:(console.warn("[FormRenderer] OnLoad response is not an object:",we),{})}catch(oe){return console.error("Error in onloadEndpoint",oe),{}}};(await Promise.all(P.map(z))).forEach(J=>{J&&typeof J=="object"&&($={...$,...J})}),M||y({systemContext:{...$}})}if(!M&&Object.keys($).length>0){const z={...e.defaultValues??{}};Object.assign(z,$);const U=e.fields.map(J=>J.name);Object.keys($).forEach(J=>{const oe=J.toLowerCase(),de=U.find(ge=>ge.toLowerCase()===oe);de&&(z[de]===void 0||z[de]==="")&&(z[de]=$[J])}),x.reset(z)}})(),()=>{M=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,b,x.reset]);const{control:j,reset:A,handleSubmit:S,formState:{errors:_,isSubmitting:O}}=x,[B,R]=C.useState(!1);C.useEffect(()=>{h&&(R(!0),h().then(M=>A(M)).finally(()=>R(!1)))},[h,A]);const I=C.useMemo(()=>(o??[]).filter(jI),[o]),{loadingCount:F,optionsMap:Z}=V2(I),[ee,Y]=C.useState({}),[te,ae]=C.useState(0);C.useEffect(()=>{let M;const V=x.watch(()=>{clearTimeout(M),M=setTimeout(()=>{ae(T=>T+1)},500)});return()=>{V.unsubscribe(),clearTimeout(M)}},[x.watch]);const q=C.useRef(b);C.useEffect(()=>{q.current=b},[b]);const N=C.useRef({});C.useEffect(()=>{let M=!0;return(async()=>{const T=await Promise.all(I.filter(P=>P.type==="select"&&(P.optionSource||P.endpointConfig)).map(async P=>{var we;const z=P.name,U=li(P.optionSource,P.endpointConfig);if(!U)return[z,[]];const J=P.endpointConfig?bn(P.endpointConfig.parameters,x.getValues,E):{...E,...x.getValues()},oe=q2(P.adapterCtx??P.optionAdapterCtx),de=JSON.stringify({key:U,resolvedParams:J,ctx:oe});N.current[z],N.current[z]=de;const ge=(we=q.current)==null?void 0:we[U];if(typeof ge!="function")return[z,[]];try{const Ce=await Promise.resolve(ge(J,{getValues:x.getValues,watch:x.watch,ctx:oe,params:J,...E})),ke=Array.isArray(Ce)?Ce:[];return[z,ke]}catch{return[z,[]]}}));if(!M)return;const $={};for(const[P,z]of T)$[P]=z;Y(P=>Object.entries($).some(([U,J])=>{const oe=P[U];return!oe||oe.length!==J.length?!0:JSON.stringify(oe)!==JSON.stringify(J)})?$:P)})(),()=>{M=!1}},[te,JSON.stringify(I.map(M=>({n:M.name,os:M.optionSource??null,ec:M.endpointConfig??null,ctx:M.adapterCtx??M.optionAdapterCtx??null}))),E]),C.useEffect(()=>{let M=!0;return(async()=>{for(const T of I){if(T.type!=="select")continue;const $=T.name,P=T.defaultSource;if(!P)continue;const z=x.getValues($);if(!(z==null||(Array.isArray(z)?z.length===0:z==="")))continue;const J=b==null?void 0:b[P];if(typeof J=="function")try{const oe=q2(T.adapterCtx??T.optionAdapterCtx),de=await Promise.resolve(J("",{getValues:x.getValues,watch:x.watch,ctx:oe}));if(!M)return;const ge=CI(de,!!T.multiple);x.setValue($,ge,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{M=!1}},[b,x.getValues,x.setValue,JSON.stringify(I.map(M=>({n:M.name,ds:M.defaultSource??null,mult:!!M.multiple})))]);const L=I2(o),ne=Z2(o,j),K=C.useMemo(()=>{const M={};return a.forEach((V,T)=>{V.type==="tabs"&&(M[T]=V.tabs[0].key)}),M},[a]),[Q,he]=C.useState(K),[ie,me]=C.useState({}),[ce,le]=C.useState({}),be=C.useRef({}),fe=C.useCallback(async()=>{const M={},V=o.filter($=>{var z,U,J;const P=$;return((z=P.visibleWhen)==null?void 0:z.endpoint)||((U=P.disabledWhen)==null?void 0:U.endpoint)||((J=P.clearWhen)==null?void 0:J.endpoint)});if(V.length===0)return;(await Promise.all(V.map(async $=>{const P=$,z=P.name,U={};for(const J of["visibleWhen","disabledWhen","clearWhen"]){const oe=P[J];if(oe!=null&&oe.enabled&&oe.endpoint){const de=oe.endpoint.key,ge=b==null?void 0:b[de];if(typeof ge=="function")try{const we=bn(oe.endpoint.parameters,x.getValues,E),Ce=await Promise.resolve(ge(we,{getValues:x.getValues,watch:x.watch,params:we,...E}));U[J]=typeof Ce=="object"&&Ce!==null?!!Ce.ok:!!Ce}catch(we){console.error(`Error evaluando regla backend para ${z}.${J}:`,we),U[J]=!1}}}return{fieldName:z,res:U}}))).forEach(({fieldName:$,res:P})=>{Object.keys(P).length>0&&(M[$]=P)}),me(M)},[o,b,x,E]),xe=C.useCallback(async M=>{var U;const V=M,T=V.name,$=V.asyncValidation.endpoint,P=$.key,z=b==null?void 0:b[P];if(typeof z=="function"){le(J=>({...J,[T]:{...J[T],loading:!0}}));try{const J=bn($.parameters,x.getValues,E),oe=await Promise.resolve(z(J,{getValues:x.getValues,watch:x.watch,params:J,...E})),de=typeof oe=="object"&&oe!==null?!!oe.ok:!!oe,ge=typeof oe=="object"&&oe!==null?oe.message:void 0;le(we=>({...we,[T]:{ok:de,message:ge,loading:!1}})),de?((U=x.formState.errors[T])==null?void 0:U.type)==="manual"&&x.clearErrors(T):x.setError(T,{type:"manual",message:ge||"Validación externa fallida"})}catch{le(oe=>({...oe,[T]:{ok:!1,message:"Error de conexión",loading:!1}}))}}},[b,x,E]),D=C.useCallback(async(M,V,T)=>{const $=o.filter(P=>{var oe,de;const z=P,U=(oe=z.asyncValidation)==null?void 0:oe.endpoint;if(!U)return!1;const J=U.trigger||z.asyncValidation.trigger||"onBlur";if(T&&J!==T&&!(J==="auto"&&T==="onChange"))return!1;if(V&&T!=="onSubmit"){const ge=z.name===V,we=Object.values(U.parameters||{}).some(ke=>ke.fieldRef===V),Ce=(de=U.triggerFields)==null?void 0:de.includes(V);if(!ge&&!we&&!Ce)return!1}return!0});for(const P of $){const z=P,U=z.name,J=z.asyncValidation.endpoint;if(T==="onChange"&&J.trigger==="debounced"){be.current[U]&&clearTimeout(be.current[U]),be.current[U]=setTimeout(()=>xe(P),J.debounceMs||300);continue}await xe(P)}},[o,xe]);C.useEffect(()=>{fe();const M=x.watch((V,{name:T})=>{fe(),T&&D(V,T,"onChange")});return()=>{M.unsubscribe(),Object.values(be.current).forEach(V=>V&&clearTimeout(V))}},[fe,D,x]);const G=C.useCallback((M,V,T,$)=>{var z;if(!(M!=null&&M.enabled))return V;let P=!0;if(M.rule)try{const U={...x.getValues(),...E,ACTIVE_VARIANT:n};P=!!Ei(M.rule,U)}catch{P=V}if(P&&T&&$&&M.endpoint){const U=(z=ie[T])==null?void 0:z[$];if(U===void 0)return!1;P=U}return P},[x,ie,n]),re=C.useMemo(()=>o.map(M=>M).filter(M=>{var V;return((V=M.clearWhen)==null?void 0:V.enabled)&&(M.clearWhen.rule||M.clearWhen.endpoint)}).map(M=>({name:M.name,container:M.clearWhen})),[o]);C.useEffect(()=>{if(!re.length)return;const M=T=>{re.forEach(({name:$,container:P})=>{try{if(G(P,!1,$,"clearWhen")){const U=P.clearTo??"";T[$]!==U&&x.setValue($,U,{shouldDirty:!0,shouldValidate:!0})}}catch{}})};M(x.getValues());const V=x.watch(()=>M(x.getValues()));return()=>{var T;return(T=V==null?void 0:V.unsubscribe)==null?void 0:T.call(V)}},[x,re,G]);const W=C.useCallback(M=>{const V=mt(v,M);if(!V)return"";const T={...E,...k,sys:E,form:k};return cd(V,T)},[v,E,k]),H=C.useCallback((M,V)=>{var Re,Ve,Ge,ft;let T;if(typeof M=="string"){if(T=L[M],!T){const Ne=(o??[]).find(Fe=>(Fe==null?void 0:Fe.name)===M);if(Ne)T=Ne;else return null}}else T=M;const $=T.name,P=$?V?`${V}.${$}`:$:void 0,z=T.visibleWhen;if(!G(z,!0,$,"visibleWhen"))return null;let J=!!T.disabled;const oe=T.disabledWhen,de=G(oe,!1,$,"disabledWhen");if(oe!=null&&oe.enabled&&(J=de),!(oe!=null&&oe.enabled)&&$&&ne[$]&&(J=!0),T.type==="search"){const Ne=typeof T.searchFn=="function",Fe=li(T.searchSource,T.endpointConfig),Me=async Tt=>{if(Ne)return T.searchFn(Tt,{getValues:x.getValues,watch:x.watch});if(Fe){const ze=T.endpointConfig?bn(T.endpointConfig.parameters,x.getValues,E):{...E,...x.getValues()},Ye=b==null?void 0:b[Fe];if(typeof Ye=="function")return await Ye(Tt,{getValues:x.getValues,watch:x.watch,params:ze,...E});if(Array.isArray(Ye))return Ye}return[]},_e={};T.searchMode&&(_e.searchMode=T.searchMode),T.minChars&&(_e.minChars=T.minChars),T.debounceMs&&(_e.debounceMs=T.debounceMs),T.resolveByValue&&(_e.resolveByValue=T.resolveByValue);const Te=Kt(T.labelIconLeft??T.labelPrefixIcon),Ze=Kt(T.labelIconRight??T.labelSuffixIcon),He=Kt(T.prefixIcon),Ue=Kt(T.suffixIcon);return l.jsx(fd,{name:P,control:j,searchFn:Me,label:W(T.label),size:T.size,width:T.width,disabled:J||O,labelPrefixIcon:Te,labelSuffixIcon:Ze,prefixIcon:He,suffixIcon:Ue,..._e},P)}if(T.type==="inputGroup"){const Ne=T,Fe=(Ne.inputs??[]).map(Me=>{var Ln,Er;const _e=typeof Me=="string"?L[Me]??(o??[]).find(cn=>(cn==null?void 0:cn.name)===Me):Me;if(!_e)return null;const Te=_e.name,Ze=V?`${V}.${Te}`:Te,He=_e.disabledWhen;let Ue=!!_e.disabled;const Tt=G(He,!1,Te,"disabledWhen");He!=null&&He.enabled&&(Ue=Tt),!(He!=null&&He.enabled)&&ne[Te]&&(Ue=!0);const ze=Kt(_e.labelIconLeft??_e.labelPrefixIcon),Ye=Kt(_e.labelIconRight??_e.labelSuffixIcon),Ke=Kt(_e.prefixIcon),ht=Kt(_e.suffixIcon),$r={name:Ze,control:j,label:W(_e.label),size:_e.size,width:_e.width,placeholder:W(_e.placeholder),hasError:!!(_[Ze]||V&&((Ln=_[V])!=null&&Ln[Te])),errorMessage:mt(v,(Er=_[Ze])==null?void 0:Er.message),loading:B,disabled:Ue||O,suffixButton:_e.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:ze,labelSuffixIcon:Ye,prefixIcon:Ke,suffixIcon:ht};return _e.type==="select"?{...$r,options:_e.options??ee[Te]??Z[Te]??[],loadOptions:_e.options||_e.optionSource?void 0:_e.loadOptions}:{...$r,type:_e.type}}).filter(Boolean);return l.jsx(dd,{groupLabel:mt(v,Ne.groupLabel),inputs:Fe,separator:Ne.separator,useSeparator:Ne.useSeparator,className:Ne.className,showVisibleLabel:Ne.showVisibleLabel,size:Ne.size},`inputGroup_${P??Ne.groupLabel??"group"}`)}if(T.type==="button"){const Ne=T,Fe=Ne.icon,Me=Fe&&typeof Fe=="object"&&Fe.name&&Fe.style?Kt(Fe):void 0;return l.jsx("div",{className:"self-center",children:l.jsx(pe,{type:"button",variant:Ne.variant,size:Ne.size,width:Ne.width,icon:Me,iconPosition:Ne.iconPosition,ariaLabel:W(Ne.ariaLabel),onClick:Ne.onClick,disabled:J||O,children:W(Ne.label)})},P??Ne.label)}if(T.type==="array"){const Ne=T;return l.jsx(kI,{schema:{...Ne,name:P},renderField:H},P)}const ge=T.suffixButton,we=typeof ge=="string"?H(ge):ge,Ce=Kt(T.labelIconLeft??T.labelPrefixIcon),ke=Kt(T.labelIconRight??T.labelSuffixIcon),Ie=Kt(T.prefixIcon),Le=Kt(T.suffixIcon),De={name:P,control:j,disabled:J||O,label:W(T.label),size:T.size,width:T.width,placeholder:W(T.placeholder),info:mt(v,T.info),suffixButton:we,labelPrefixIcon:Ce,labelSuffixIcon:ke,prefixIcon:Ie,suffixIcon:Le,onBlur:()=>{D(x.getValues(),$,"onBlur"),o.filter(Fe=>{const Me=Fe;return["visibleWhen","disabledWhen","clearWhen"].some(_e=>{var Ze;const Te=(Ze=Me[_e])==null?void 0:Ze.endpoint;return(Te==null?void 0:Te.trigger)==="onBlur"&&Object.values(Te.parameters||{}).some(He=>He.fieldRef===$)})}).length>0&&fe()}};switch(T.type){case"select":{const Ne=T.options??ee[$]??Z[$]??[],Fe=Array.isArray(Ne)&&Ne.length?`${Ne.length}:${Ne.map(_e=>String((_e==null?void 0:_e.value)??"")).join("|")}`:"0",Me=!T.options&&!T.optionSource&&T.loadOptions;return l.jsx(Et,{name:P,control:j,render:({field:_e})=>{var Te;return l.jsx(Xe,{...De,value:_e.value,onChange:_e.onChange,options:Ne,loadOptions:Me||void 0,hasError:!!_[P],errorMessage:mt(v,(Te=_[P])==null?void 0:Te.message),suffixButton:we,mode:"menu",searchable:!0,searchPlaceholder:v("common.search"),noOptionsText:v("common.noMatches")})}},`${P}:${Fe}`)}case"textarea":return l.jsx(Et,{name:P,control:j,render:({field:Ne,fieldState:Fe})=>{var Me;return l.jsx(Dr,{...De,value:Ne.value,onChange:Ne.onChange,maxLength:T.maxLength,showCounter:!!T.showCounter,hasError:!!Fe.error,errorMessage:mt(v,(Me=Fe.error)==null?void 0:Me.message)})}},P);case"file":return l.jsx(Yc,{...De,defaultValue:[],maxFiles:T.maxFiles,accept:T.accept,hideDropZone:T.hideDropZone,hasError:!!_[P],errorMessage:mt(v,(Re=_[P])==null?void 0:Re.message)},P);case"checkbox":return l.jsx(it,{...De,defaultValue:!1,hasError:!!_[P],errorMessage:mt(v,(Ve=_[P])==null?void 0:Ve.message),name:P},P);case"date":return l.jsx(Sa,{...De,defaultValue:"",showTime:!!T.showTime,hasError:!!_[P],errorMessage:mt(v,(Ge=_[P])==null?void 0:Ge.message)},P);case"optionGroup":return l.jsx(ki,{...De,options:T.options||[],multiple:T.multiple,vertical:T.vertical,groupLabel:T.groupLabel,defaultValue:T.defaultValue,className:T.width?void 0:"w-full",name:P},P);case"iban":return l.jsx(Et,{name:P,control:j,render:({field:Ne,fieldState:Fe})=>{var Me;return l.jsx(Ci,{label:W(T.label),placeholder:W(T.placeholder),size:T.size,disabled:J||O,value:Ne.value??"",onChange:Ne.onChange,onBlur:Ne.onBlur,hasError:!!Fe.error,errorMessage:mt(v,(Me=Fe.error)==null?void 0:Me.message),name:P})}},P);case"dni":return l.jsx(Et,{name:P,control:j,render:({field:Ne,fieldState:Fe})=>{var Me;return l.jsx(pd,{label:W(T.label),placeholder:W(T.placeholder),size:T.size,disabled:J||O,value:Ne.value??"",onChange:Ne.onChange,onBlur:Ne.onBlur,hasError:!!Fe.error,errorMessage:mt(v,(Me=Fe.error)==null?void 0:Me.message),name:P})}},P);default:return l.jsx(ii,{...De,type:T.type,loadingDefaults:B,hasError:!!_[P],errorMessage:mt(v,(ft=_[P])==null?void 0:ft.message),suffixButton:we,name:P},P)}},[o,L,j,_,O,B,Z,ee,G,ne,x.getValues,x.watch,b,v]);return l.jsx(xc,{...x,children:l.jsxs("form",{noValidate:!0,onSubmit:S(async M=>{await D(M,void 0,"onSubmit"),!(Object.keys(x.formState.errors).length>0)&&(await i(M),m(c??v("ds.form.saveSuccess"),"success"))},M=>{J$(M),m(d??v("ds.form.saveError"),"error")}),className:"space-y-6",children:[a.map((M,V)=>M.type==="rows"?l.jsx(C.Fragment,{children:M.sections.map((T,$)=>l.jsx("div",{children:l.jsx(lt,{title:W(T.sectionTitle),defaultOpen:T.defaultOpen,children:T.rows.map((P,z)=>l.jsxs("div",{children:[P.title&&l.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:W(P.title)}),l.jsx("div",{className:"flex flex-wrap -mx-2",children:P.columns.map((U,J)=>{var oe;return l.jsx("div",{className:`${U.width} px-2 flex flex-col`,children:l.jsx("div",{className:"",children:U.fields?U.fields.map(de=>H(de)):(oe=U.rows)==null?void 0:oe.map((de,ge)=>l.jsx("div",{className:"mb-1",children:l.jsx("div",{className:"flex flex-wrap -mx-2",children:de.columns.map((we,Ce)=>{var ke;return l.jsx("div",{className:`${we.width} px-2`,children:(ke=we.fields)==null?void 0:ke.map(Ie=>H(Ie))},Ce)})})},ge))})},J)})})]},z))})},$))},V):l.jsx(zr,{options:M.tabs.map(T=>{const $=T.icon?Ma(T.icon.name,T.icon.style):null;return{label:W(T.label),value:T.key,disabled:T.disabled,icon:$?l.jsx($,{className:"w-4 h-4"}):null}}),value:Q[V],onChange:T=>he($=>({...$,[V]:T})),children:Object.fromEntries(M.tabs.map(T=>[T.key,l.jsx("div",{className:"space-y-6",children:T.sections.map(($,P)=>l.jsx("div",{className:"mb-6",children:l.jsx(lt,{title:W($.sectionTitle),defaultOpen:$.defaultOpen,children:$.rows.map((z,U)=>l.jsx("div",{children:l.jsx("div",{className:"flex flex-wrap -mx-2",children:z.columns.map((J,oe)=>{var de;return l.jsx("div",{className:`${J.width??"flex-1"} px-2 flex flex-col`,children:l.jsx("div",{className:"space-y-4",children:(de=J.fields)==null?void 0:de.map((ge,we)=>l.jsx(C.Fragment,{children:H(ge)},we))})},oe)})})},U))})},P))},T.key)]))},V)),l.jsx("footer",{className:"py-4 w-full flex justify-center space-x-4",children:u??l.jsx(pe,{type:"submit",variant:"primary",icon:Tn,size:"sm",disabled:O||B||F>0,children:v(O?"ds.form.sending":"ds.form.submit")})})]})})}function K2({dark:e,onToggle:t}){return l.jsx("button",{type:"button","aria-pressed":e,"aria-label":e?"Cambiar a modo claro":"Cambiar a modo oscuro",onClick:t,className:ve("relative inline-flex items-center transition-colors focus:outline-none duration-200 ease-in-out","bg-[var(--color-ds-background-accent)]","h-6 w-12 rounded-full"),children:l.jsxs("div",{className:ve("absolute bg-[var(--color-ds-background-page)] flex items-center justify-center rounded-full transition-transform duration-200 ease-in-out","h-5 w-5",e?"translate-x-6":"translate-x-1"),children:[l.jsx(Ft,{component:uc,size:"sm",className:ve("absolute transition-opacity duration-200 ease-in-out",e?"opacity-0":"opacity-100 text-[var(--color-ds-background-accent)]")}),l.jsx(Ft,{component:oc,size:"sm",className:ve("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const J2="licytal:ui:theme",Y2=C.createContext({theme:"light",dark:!1,toggle:()=>{}});function SI({children:e}){const[t,r]=C.useState(!1),[n,a]=C.useState("light");C.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(J2);i==="light"||i==="dark"?a(i):window.matchMedia("(prefers-color-scheme: dark)").matches&&a("dark"),r(!0)},[]),C.useEffect(()=>{t&&(document.documentElement.classList.toggle("dark",n==="dark"),localStorage.setItem(J2,n))},[n,t]);const o=()=>a(i=>i==="light"?"dark":"light");return t?l.jsx(Y2.Provider,{value:{theme:n,dark:n==="dark",toggle:o},children:e}):null}const md=()=>C.useContext(Y2),Fo={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},X2=({pinnedPages:e,onRemovePinned:t,onBack:r,dark:n,locale:a,languageOptions:o,onChangeLocale:i,profile:c="",profileOptions:d=[],onChangeProfile:u,logoSrc:f,logoAlt:h="Logo aplicación"})=>{e.slice(0,3);const{toggle:p}=md(),m=g=>{try{localStorage.setItem(Fo.locale,g)}catch{}i==null||i(g)},v=()=>{const g=!n;try{localStorage.setItem(Fo.theme,g?"dark":"light")}catch{}p()};return C.useEffect(()=>{try{const g=localStorage.getItem(Fo.locale);g&&g!==a&&(i==null||i(g))}catch{}},[]),C.useEffect(()=>{if(a)try{localStorage.setItem(Fo.locale,a)}catch{}},[a]),C.useEffect(()=>{try{const g=localStorage.getItem(Fo.theme);if(!g)return;g==="dark"!==n&&p()}catch{}},[]),l.jsxs("header",{className:"flex items-center justify-between bg-[var(--color-ds-background-page)] py-2 px-4 min-h-[88px]",children:[l.jsx("div",{className:"flex items-center",children:f&&l.jsx("img",{src:f,alt:h,className:"h-24 w-auto object-contain"})}),l.jsxs("div",{className:"flex items-center space-x-2",children:[l.jsx(Xe,{size:"sm",width:"auto",options:o,value:a,onChange:m,disableErrorPlaceholder:!0,label:"Idioma",labelHidden:!0}),!!d.length&&l.jsx(Xe,{size:"sm",width:"auto",options:d,value:c,onChange:g=>u==null?void 0:u(g),disableErrorPlaceholder:!0,label:"Perfil",labelHidden:!0}),l.jsx(K2,{dark:n,onToggle:v})]})]})},AI={sm:"h-8 w-8",md:"h-10 w-10",lg:"h-12 w-12"};function Jt({icon:e,size:t="md",ariaLabel:r,disabled:n=!1,onClick:a,className:o,...i}){return l.jsx("button",{type:"button","aria-label":r,disabled:n,onClick:a,className:ve("inline-flex items-center justify-center","rounded-full","bg-transparent","text-[var(--color-ds-text-primary)]","transition-transform","focus:outline-none",AI[t],n?"opacity-50 cursor-not-allowed":["hover:scale-110","hover:animate-pulse","hover:bg-[var(--color-ds-background-neutral-hover)]"],o),...i,children:l.jsx(e,{className:ve(t==="sm"?"h-4 w-4":t==="md"?"h-5 w-5":"h-6 w-6")})})}const NI=({loading:e=!1,ariaLabel:t="Cargando..."})=>e?l.jsxs("div",{className:`\r
99
+ hover:bg-[var(--color-ds-background-surface)]`,onClick:()=>{const xe=String(fe.value).trim();E(e,xe,{shouldDirty:!0,shouldValidate:!0}),I(fe.label??xe),ee.current=!1,Y.current=!1,B(!1)},children:fe.label},String(fe.value)))})]})}})}const No=(e,t)=>e[t],z2=e=>e instanceof Date?e.getTime():e;function bI(e,t,r){const n=z2(e),a=z2(t);return typeof n=="number"&&typeof a=="number"||typeof n=="string"&&typeof a=="string"?r==="gt"?n>a:r==="gte"?n>=a:r==="lt"?n<a:n<=a:!1}function Ei(e,t){if(!e)return!1;switch(e.op){case"eq":return No(t,e.field)===e.value;case"neq":return No(t,e.field)!==e.value;case"in":return e.values.includes(No(t,e.field));case"notIn":return!e.values.includes(No(t,e.field));case"gt":case"gte":case"lt":case"lte":return bI(No(t,e.field),e.value,e.op);case"and":return e.rules.every(r=>Ei(r,t));case"or":return e.rules.some(r=>Ei(r,t));case"always":return!!e.value;default:return!1}}function hd(e){return!!e&&(typeof e=="function"||typeof e=="object")}function Ma(e,t){const r=t==="outline"?ba:Da,n=r==null?void 0:r[e];return hd(n)?n:null}const wI=Object.entries(ba).filter(([e,t])=>e.endsWith("Icon")&&hd(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),xI=Object.entries(Da).filter(([e,t])=>e.endsWith("Icon")&&hd(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),yI=dc||cc||(e=>l.jsx("svg",{...e})),Un=({value:e,onChange:t,buttonLabel:r,disabled:n,className:a})=>{const[o,i]=C.useState(!1),[c,d]=C.useState(""),[u,f]=C.useState((e==null?void 0:e.style)??"outline"),h=e&&Ma(e.name,e.style)||yI,p=C.useCallback((v,g)=>{const b=Ma(v,g);t==null||t({name:v,style:g},b),i(!1)},[t]),m=C.useCallback(()=>{t==null||t(void 0,void 0),i(!1)},[t]);return l.jsxs(l.Fragment,{children:[l.jsx(pe,{size:"sm",variant:"outline",shape:"circle",className:`rounded-full p-0 w-8 h-8 inline-flex items-center justify-center ${a??""}`,disabled:n,onClick:()=>i(!0),ariaLabel:"Elegir icono",title:r||"Elegir icono",children:l.jsx(h,{className:"h-4 w-4"})}),l.jsx(Bt,{isOpen:o,onClose:()=>i(!1),title:"Seleccionar icono",children:l.jsxs("div",{className:"space-y-3",children:[l.jsx(je,{labelHidden:!0,placeholder:"Buscar icono (p. ej. 'user', 'arrow', 'calendar'...)",value:c,onChange:v=>d(v.target.value)}),l.jsx(zr,{options:[{label:"Outline",value:"outline"},{label:"Solid",value:"solid"}],value:u,onChange:v=>f(v),children:{outline:l.jsx(H2,{items:wI,query:c,onPick:v=>p(v,"outline"),onClear:m}),solid:l.jsx(H2,{items:xI,query:c,onPick:v=>p(v,"solid"),onClear:m})}})]})})]})},H2=({items:e,query:t,onPick:r,onClear:n})=>{const a=C.useMemo(()=>{if(!t.trim())return e;const i=t.trim().toLowerCase().replace(/\s+/g,"");return e.filter(c=>c.name.toLowerCase().includes(i))},[e,t]),o=st;return l.jsx("div",{className:"custom-scroll max-h-[60vh] overflow-y-auto",children:l.jsxs("div",{className:"grid gap-2 grid-cols-3 sm:grid-cols-4 md:grid-cols-6",children:[l.jsxs("button",{type:"button",onClick:n,className:"group w-full aspect-square border border-[var(--color-ds-border-default-50)] rounded-lg p-1 bg-[var(--color-ds-background-page)] hover:bg-[var(--color-ds-background-accent)]/5 hover:border-[var(--color-ds-border-default)] transition focus:outline-none",title:"Ninguno","aria-label":"Quitar icono",children:[l.jsx("div",{className:"h-full w-full flex items-center justify-center",children:o?l.jsx(o,{className:"w-6 h-6"}):l.jsx("span",{className:"text-ds-lg",children:"×"})}),l.jsx("div",{className:"mt-1 text-center",children:l.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:"Ninguno"})})]}),(a.length===0?e:a).map(({name:i,Icon:c})=>l.jsxs("button",{type:"button",onClick:()=>r(i),className:"group w-full aspect-square border border-[var(--color-ds-border-default-50)] rounded-lg p-1 bg-[var(--color-ds-background-page)] hover:bg-[var(--color-ds-background-accent)]/5 hover:border-[var(--color-ds-border-default)] transition focus:outline-none",title:i,"aria-label":`Elegir ${i}`,children:[l.jsx("div",{className:"h-full w-full flex items-center justify-center",children:l.jsx(c,{className:"w-6 h-6 text-[var(--color-ds-text-primary)]"})}),l.jsx("div",{className:"mt-1 text-center",children:l.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:i.replace(/Icon$/,"")})})]},i))]})})};function mt(e,t,r=""){if(!t)return r;if(typeof t=="object"&&t!==null){if(t.type==="complex"){const a=[];return t.header&&a.push(`<strong>${t.header}</strong>`),t.template&&a.push(t.template),a.join("<br/>")||r}return r}return e(t,{defaultValue:t})}const kI=({schema:e,renderField:t})=>{var g,b,w;const{control:r}=gn(),{fields:n,append:a,remove:o}=HE({control:r,name:e.name}),{label:i,addLabel:c="Añadir",items:d,disabled:u,validation:f,className:h}=e,{formState:{errors:p}}=gn(),m=((b=(g=p[e.name])==null?void 0:g.root)==null?void 0:b.message)||((w=p[e.name])==null?void 0:w.message),v=typeof m=="string"?m:void 0;return l.jsxs("div",{className:ve("space-y-3",h),children:[i&&l.jsx("div",{className:"flex items-center justify-between",children:l.jsx("label",{className:"block text-ds-sm font-medium text-[var(--color-ds-text-primary)]",children:i})}),l.jsx("div",{className:"space-y-4",children:n.map((x,y)=>{const E=`${e.name}.${y}`;return l.jsxs("div",{className:"relative rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-4 group",children:[!u&&l.jsx("div",{className:"absolute top-2 right-2",children:l.jsx(pe,{size:"xs",variant:"ghost",className:"text-[var(--color-ds-text-error)] hover:bg-[var(--color-ds-background-error-hover)]",onClick:()=>o(y),title:"Eliminar fila",ariaLabel:"Eliminar fila",children:l.jsx(Dt,{className:"w-4 h-4"})})}),l.jsx("div",{className:"grid grid-cols-1 gap-4",children:d.map((k,j)=>l.jsx(C.Fragment,{children:t(k,E)},j))})]},x.id)})}),n.length===0&&l.jsx("div",{className:"text-ds-sm text-[var(--color-ds-text-secondary)] italic p-2 border border-dashed border-[var(--color-ds-border-default-50)] rounded bg-[var(--color-ds-background-subtle)]",children:"No hay elementos."}),v&&l.jsx("p",{className:"text-xs text-[var(--color-ds-text-error)]",children:v}),!u&&l.jsxs(pe,{type:"button",variant:"outline",size:"sm",onClick:()=>{a({})},children:[l.jsx(hr,{className:"w-4 h-4 mr-1"}),c]})]})};function W2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function EI(e){return e.replace(/(.{4})/g,"$1 ").trim()}function Ci({label:e,labelHidden:t,placeholder:r="ES00 0000 0000 0000 0000 0000",size:n="sm",value:a,onChange:o,onBlur:i,disabled:c,required:d,reserveErrorSpace:u=!0,error:f,errorMessage:h,hasError:p,id:m,name:v,className:g,"aria-label":b}){const w=C.useMemo(()=>W2(a),[a]),x=C.useMemo(()=>EI(w),[w]),y=E=>{const k=W2(E.target.value);o(k)};return l.jsx(je,{id:m,name:v,label:e,labelHidden:t,placeholder:r,size:n,value:x,onChange:y,onBlur:i,disabled:c,required:d,hasError:p||!!f||!!h,errorMessage:h||f,reserveErrorSpace:u,prefixIcon:Wl,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1})}function U2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,9)}function Eee(e){return e}function pd({label:e,labelHidden:t,placeholder:r="12345678A",size:n="sm",value:a,onChange:o,onBlur:i,disabled:c,required:d,reserveErrorSpace:u=!0,error:f,errorMessage:h,hasError:p,id:m,name:v,className:g,"aria-label":b}){const{t:w}=At(),x=C.useMemo(()=>U2(a),[a]),y=C.useMemo(()=>x,[x]),E=k=>{const j=U2(k.target.value);o(j)};return l.jsx(je,{id:m,name:v,label:e,labelHidden:t,placeholder:r,size:n,value:y,onChange:E,onBlur:i,disabled:c,required:d,hasError:p||!!f||!!h,errorMessage:h||f,prefixIcon:nc,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1,reserveErrorSpace:u})}function q2(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function CI(e,t){var r;return Array.isArray(e)?e.length&&typeof e[0]=="object"&&"value"in e[0]?t?e.map(n=>n.value):((r=e[0])==null?void 0:r.value)??"":t?e:e[0]??"":e&&typeof e=="object"&&"value"in e?e.value:e??(t?[]:"")}const jI=e=>e.type!=="inputGroup"&&e.type!=="button";function DI(){try{return Zt()??void 0}catch{return}}function Kt(e){if(!e||typeof e!="object")return;const t=e.name,r=e.style;if(!(!t||!r))return Ma(t,r)||void 0}function G2({schema:e,resolver:t,serviceRegistry:r,activeVariantId:n}){var X;const{layout:a,fields:o=[],onSubmit:i,successMessage:c,errorMessage:d,footerButtons:u,defaultValues:f,loadDefaultValues:h,validationSchema:p}=e,{show:m}=yn(),{t:v}=At(),g=DI(),b=r??((X=g==null?void 0:g.services)==null?void 0:X.registry)??void 0,w=C.useMemo(()=>{if(t)return t;try{const M=p??ld(e);return Xc(M)}catch{return}},[t,e,p]),x=Ic({resolver:w,mode:"onBlur",reValidateMode:"onChange",defaultValues:f??{}}),y=Wn(M=>M.setRuntimeState),E=Wn(M=>M.systemContext),k=Wn(M=>M.formValues);C.useEffect(()=>{y({isActive:!0});let M=!1;return(async()=>{const V=e.defaultSource,T=e.onloadEndpoint;let $={};if(e.variables&&Array.isArray(e.variables)&&(e.variables.forEach(z=>{z.type==="constant"&&($[z.key]=z.value)}),e.variables.forEach(z=>{if(z.type==="computed"&&z.value)try{const U=new Function("ctx",`return (${z.value});`);$[z.key]=U($)}catch(U){console.warn(`[FormRenderer] Error evaluating computed variable "${z.key}":`,U),$[z.key]=null}})),V)try{const z=b==null?void 0:b[V];if(z){const U=typeof z=="function"?await z():z;U&&typeof U=="object"&&($={...$,...U})}}catch{}y({systemContext:{...$}});const P=[];if(T&&P.push(T),e.onloadEndpoints&&Array.isArray(e.onloadEndpoints)&&P.push(...e.onloadEndpoints),P.length>0){const z=async J=>{if(!J)return{};try{const oe=b==null?void 0:b[J.key];if(!oe)return console.warn("[FormRenderer] Provider not found for key:",J.key),{};const de=bn(J.parameters,(()=>({})),{...$,ACTIVE_VARIANT:e.activeVariantId});console.log(`[FormRenderer] Calling ${J.key} with params:`,de);const ge=await Promise.resolve(oe(de,{getValues:(()=>({})),watch:(()=>{}),params:de,...$}));let we=ge;if(typeof ge=="string")try{we=JSON.parse(ge)}catch(Ce){console.warn("[FormRenderer] Failed to parse onload response string",Ce)}return we&&typeof we=="object"?we:(console.warn("[FormRenderer] OnLoad response is not an object:",we),{})}catch(oe){return console.error("Error in onloadEndpoint",oe),{}}};(await Promise.all(P.map(z))).forEach(J=>{J&&typeof J=="object"&&($={...$,...J})}),M||y({systemContext:{...$}})}if(!M&&Object.keys($).length>0){const z={...e.defaultValues??{}};Object.assign(z,$);const U=e.fields.map(J=>J.name);Object.keys($).forEach(J=>{const oe=J.toLowerCase(),de=U.find(ge=>ge.toLowerCase()===oe);de&&(z[de]===void 0||z[de]==="")&&(z[de]=$[J])}),x.reset(z)}})(),()=>{M=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,b,x.reset]);const{control:j,reset:A,handleSubmit:S,formState:{errors:_,isSubmitting:O}}=x,[B,R]=C.useState(!1);C.useEffect(()=>{h&&(R(!0),h().then(M=>A(M)).finally(()=>R(!1)))},[h,A]);const I=C.useMemo(()=>(o??[]).filter(jI),[o]),{loadingCount:F,optionsMap:Z}=V2(I),[ee,Y]=C.useState({}),[te,ae]=C.useState(0);C.useEffect(()=>{let M;const V=x.watch(()=>{clearTimeout(M),M=setTimeout(()=>{ae(T=>T+1)},500)});return()=>{V.unsubscribe(),clearTimeout(M)}},[x.watch]);const q=C.useRef(b);C.useEffect(()=>{q.current=b},[b]);const N=C.useRef({});C.useEffect(()=>{let M=!0;return(async()=>{const T=await Promise.all(I.filter(P=>P.type==="select"&&(P.optionSource||P.endpointConfig)).map(async P=>{var we;const z=P.name,U=li(P.optionSource,P.endpointConfig);if(!U)return[z,[]];const J=P.endpointConfig?bn(P.endpointConfig.parameters,x.getValues,E):{...E,...x.getValues()},oe=q2(P.adapterCtx??P.optionAdapterCtx),de=JSON.stringify({key:U,resolvedParams:J,ctx:oe});N.current[z],N.current[z]=de;const ge=(we=q.current)==null?void 0:we[U];if(typeof ge!="function")return[z,[]];try{const Ce=await Promise.resolve(ge(J,{getValues:x.getValues,watch:x.watch,ctx:oe,params:J,...E})),ke=Array.isArray(Ce)?Ce:[];return[z,ke]}catch{return[z,[]]}}));if(!M)return;const $={};for(const[P,z]of T)$[P]=z;Y(P=>Object.entries($).some(([U,J])=>{const oe=P[U];return!oe||oe.length!==J.length?!0:JSON.stringify(oe)!==JSON.stringify(J)})?$:P)})(),()=>{M=!1}},[te,JSON.stringify(I.map(M=>({n:M.name,os:M.optionSource??null,ec:M.endpointConfig??null,ctx:M.adapterCtx??M.optionAdapterCtx??null}))),E]),C.useEffect(()=>{let M=!0;return(async()=>{for(const T of I){if(T.type!=="select")continue;const $=T.name,P=T.defaultSource;if(!P)continue;const z=x.getValues($);if(!(z==null||(Array.isArray(z)?z.length===0:z==="")))continue;const J=b==null?void 0:b[P];if(typeof J=="function")try{const oe=q2(T.adapterCtx??T.optionAdapterCtx),de=await Promise.resolve(J("",{getValues:x.getValues,watch:x.watch,ctx:oe}));if(!M)return;const ge=CI(de,!!T.multiple);x.setValue($,ge,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{M=!1}},[b,x.getValues,x.setValue,JSON.stringify(I.map(M=>({n:M.name,ds:M.defaultSource??null,mult:!!M.multiple})))]);const L=I2(o),ne=Z2(o,j),K=C.useMemo(()=>{const M={};return a.forEach((V,T)=>{V.type==="tabs"&&(M[T]=V.tabs[0].key)}),M},[a]),[Q,he]=C.useState(K),[ie,me]=C.useState({}),[ce,le]=C.useState({}),be=C.useRef({}),fe=C.useCallback(async()=>{const M={},V=o.filter($=>{var z,U,J;const P=$;return((z=P.visibleWhen)==null?void 0:z.endpoint)||((U=P.disabledWhen)==null?void 0:U.endpoint)||((J=P.clearWhen)==null?void 0:J.endpoint)});if(V.length===0)return;(await Promise.all(V.map(async $=>{const P=$,z=P.name,U={};for(const J of["visibleWhen","disabledWhen","clearWhen"]){const oe=P[J];if(oe!=null&&oe.enabled&&oe.endpoint){const de=oe.endpoint.key,ge=b==null?void 0:b[de];if(typeof ge=="function")try{const we=bn(oe.endpoint.parameters,x.getValues,E),Ce=await Promise.resolve(ge(we,{getValues:x.getValues,watch:x.watch,params:we,...E}));U[J]=typeof Ce=="object"&&Ce!==null?!!Ce.ok:!!Ce}catch(we){console.error(`Error evaluando regla backend para ${z}.${J}:`,we),U[J]=!1}}}return{fieldName:z,res:U}}))).forEach(({fieldName:$,res:P})=>{Object.keys(P).length>0&&(M[$]=P)}),me(M)},[o,b,x,E]),xe=C.useCallback(async M=>{var U;const V=M,T=V.name,$=V.asyncValidation.endpoint,P=$.key,z=b==null?void 0:b[P];if(typeof z=="function"){le(J=>({...J,[T]:{...J[T],loading:!0}}));try{const J=bn($.parameters,x.getValues,E),oe=await Promise.resolve(z(J,{getValues:x.getValues,watch:x.watch,params:J,...E})),de=typeof oe=="object"&&oe!==null?!!oe.ok:!!oe,ge=typeof oe=="object"&&oe!==null?oe.message:void 0;le(we=>({...we,[T]:{ok:de,message:ge,loading:!1}})),de?((U=x.formState.errors[T])==null?void 0:U.type)==="manual"&&x.clearErrors(T):x.setError(T,{type:"manual",message:ge||"Validación externa fallida"})}catch{le(oe=>({...oe,[T]:{ok:!1,message:"Error de conexión",loading:!1}}))}}},[b,x,E]),D=C.useCallback(async(M,V,T)=>{const $=o.filter(P=>{var oe,de;const z=P,U=(oe=z.asyncValidation)==null?void 0:oe.endpoint;if(!U)return!1;const J=U.trigger||z.asyncValidation.trigger||"onBlur";if(T&&J!==T&&!(J==="auto"&&T==="onChange"))return!1;if(V&&T!=="onSubmit"){const ge=z.name===V,we=Object.values(U.parameters||{}).some(ke=>ke.fieldRef===V),Ce=(de=U.triggerFields)==null?void 0:de.includes(V);if(!ge&&!we&&!Ce)return!1}return!0});for(const P of $){const z=P,U=z.name,J=z.asyncValidation.endpoint;if(T==="onChange"&&J.trigger==="debounced"){be.current[U]&&clearTimeout(be.current[U]),be.current[U]=setTimeout(()=>xe(P),J.debounceMs||300);continue}await xe(P)}},[o,xe]);C.useEffect(()=>{fe();const M=x.watch((V,{name:T})=>{fe(),T&&D(V,T,"onChange")});return()=>{M.unsubscribe(),Object.values(be.current).forEach(V=>V&&clearTimeout(V))}},[fe,D,x]);const G=C.useCallback((M,V,T,$)=>{var z;if(!(M!=null&&M.enabled))return V;let P=!0;if(M.rule)try{const U={...x.getValues(),...E,ACTIVE_VARIANT:n};P=!!Ei(M.rule,U)}catch{P=V}if(P&&T&&$&&M.endpoint){const U=(z=ie[T])==null?void 0:z[$];if(U===void 0)return!1;P=U}return P},[x,ie,n]),re=C.useMemo(()=>o.map(M=>M).filter(M=>{var V;return((V=M.clearWhen)==null?void 0:V.enabled)&&(M.clearWhen.rule||M.clearWhen.endpoint)}).map(M=>({name:M.name,container:M.clearWhen})),[o]);C.useEffect(()=>{if(!re.length)return;const M=T=>{re.forEach(({name:$,container:P})=>{try{if(G(P,!1,$,"clearWhen")){const U=P.clearTo??"";T[$]!==U&&x.setValue($,U,{shouldDirty:!0,shouldValidate:!0})}}catch{}})};M(x.getValues());const V=x.watch(()=>M(x.getValues()));return()=>{var T;return(T=V==null?void 0:V.unsubscribe)==null?void 0:T.call(V)}},[x,re,G]);const W=C.useCallback(M=>{const V=mt(v,M);if(!V)return"";const T={...E,...k,sys:E,form:k};return cd(V,T)},[v,E,k]),H=C.useCallback((M,V)=>{var Re,Ve,Ge,ft;let T;if(typeof M=="string"){if(T=L[M],!T){const Ne=(o??[]).find(Fe=>(Fe==null?void 0:Fe.name)===M);if(Ne)T=Ne;else return null}}else T=M;const $=T.name,P=$?V?`${V}.${$}`:$:void 0,z=T.visibleWhen;if(!G(z,!0,$,"visibleWhen"))return null;let J=!!T.disabled;const oe=T.disabledWhen,de=G(oe,!1,$,"disabledWhen");if(oe!=null&&oe.enabled&&(J=de),!(oe!=null&&oe.enabled)&&$&&ne[$]&&(J=!0),T.type==="search"){const Ne=typeof T.searchFn=="function",Fe=li(T.searchSource,T.endpointConfig),Me=async Tt=>{if(Ne)return T.searchFn(Tt,{getValues:x.getValues,watch:x.watch});if(Fe){const ze=T.endpointConfig?bn(T.endpointConfig.parameters,x.getValues,E):{...E,...x.getValues()},Ye=b==null?void 0:b[Fe];if(typeof Ye=="function")return await Ye(Tt,{getValues:x.getValues,watch:x.watch,params:ze,...E});if(Array.isArray(Ye))return Ye}return[]},_e={};T.searchMode&&(_e.searchMode=T.searchMode),T.minChars&&(_e.minChars=T.minChars),T.debounceMs&&(_e.debounceMs=T.debounceMs),T.resolveByValue&&(_e.resolveByValue=T.resolveByValue);const Te=Kt(T.labelIconLeft??T.labelPrefixIcon),Ze=Kt(T.labelIconRight??T.labelSuffixIcon),He=Kt(T.prefixIcon),Ue=Kt(T.suffixIcon);return l.jsx(fd,{name:P,control:j,searchFn:Me,label:W(T.label),size:T.size,width:T.width,disabled:J||O,labelPrefixIcon:Te,labelSuffixIcon:Ze,prefixIcon:He,suffixIcon:Ue,..._e},P)}if(T.type==="inputGroup"){const Ne=T,Fe=(Ne.inputs??[]).map(Me=>{var Ln,Er;const _e=typeof Me=="string"?L[Me]??(o??[]).find(cn=>(cn==null?void 0:cn.name)===Me):Me;if(!_e)return null;const Te=_e.name,Ze=V?`${V}.${Te}`:Te,He=_e.disabledWhen;let Ue=!!_e.disabled;const Tt=G(He,!1,Te,"disabledWhen");He!=null&&He.enabled&&(Ue=Tt),!(He!=null&&He.enabled)&&ne[Te]&&(Ue=!0);const ze=Kt(_e.labelIconLeft??_e.labelPrefixIcon),Ye=Kt(_e.labelIconRight??_e.labelSuffixIcon),Ke=Kt(_e.prefixIcon),ht=Kt(_e.suffixIcon),$r={name:Ze,control:j,label:W(_e.label),size:_e.size,width:_e.width,placeholder:W(_e.placeholder),hasError:!!(_[Ze]||V&&((Ln=_[V])!=null&&Ln[Te])),errorMessage:mt(v,(Er=_[Ze])==null?void 0:Er.message),loading:B,disabled:Ue||O,suffixButton:_e.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:ze,labelSuffixIcon:Ye,prefixIcon:Ke,suffixIcon:ht};return _e.type==="select"?{...$r,options:_e.options??ee[Te]??Z[Te]??[],loadOptions:_e.options||_e.optionSource?void 0:_e.loadOptions}:{...$r,type:_e.type}}).filter(Boolean);return l.jsx(dd,{groupLabel:mt(v,Ne.groupLabel),inputs:Fe,separator:Ne.separator,useSeparator:Ne.useSeparator,className:Ne.className,showVisibleLabel:Ne.showVisibleLabel,size:Ne.size},`inputGroup_${P??Ne.groupLabel??"group"}`)}if(T.type==="button"){const Ne=T,Fe=Ne.icon,Me=Fe&&typeof Fe=="object"&&Fe.name&&Fe.style?Kt(Fe):void 0;return l.jsx("div",{className:"self-center",children:l.jsx(pe,{type:"button",variant:Ne.variant,size:Ne.size,width:Ne.width,icon:Me,iconPosition:Ne.iconPosition,ariaLabel:W(Ne.ariaLabel),onClick:Ne.onClick,disabled:J||O,children:W(Ne.label)})},P??Ne.label)}if(T.type==="array"){const Ne=T;return l.jsx(kI,{schema:{...Ne,name:P},renderField:H},P)}const ge=T.suffixButton,we=typeof ge=="string"?H(ge):ge,Ce=Kt(T.labelIconLeft??T.labelPrefixIcon),ke=Kt(T.labelIconRight??T.labelSuffixIcon),Ie=Kt(T.prefixIcon),Le=Kt(T.suffixIcon),De={name:P,control:j,disabled:J||O,label:W(T.label),size:T.size,width:T.width,placeholder:W(T.placeholder),info:mt(v,T.info),suffixButton:we,labelPrefixIcon:Ce,labelSuffixIcon:ke,prefixIcon:Ie,suffixIcon:Le,onBlur:()=>{D(x.getValues(),$,"onBlur"),o.filter(Fe=>{const Me=Fe;return["visibleWhen","disabledWhen","clearWhen"].some(_e=>{var Ze;const Te=(Ze=Me[_e])==null?void 0:Ze.endpoint;return(Te==null?void 0:Te.trigger)==="onBlur"&&Object.values(Te.parameters||{}).some(He=>He.fieldRef===$)})}).length>0&&fe()}};switch(T.type){case"select":{const Ne=T.options??ee[$]??Z[$]??[],Fe=Array.isArray(Ne)&&Ne.length?`${Ne.length}:${Ne.map(_e=>String((_e==null?void 0:_e.value)??"")).join("|")}`:"0",Me=!T.options&&!T.optionSource&&T.loadOptions;return l.jsx(Et,{name:P,control:j,render:({field:_e})=>{var Te;return l.jsx(Xe,{...De,value:_e.value,onChange:_e.onChange,options:Ne,loadOptions:Me||void 0,hasError:!!_[P],errorMessage:mt(v,(Te=_[P])==null?void 0:Te.message),suffixButton:we,mode:"menu",searchable:!0,searchPlaceholder:v("ds.fields.defaults.search.placeholder"),noOptionsText:v("ds.fields.defaults.search.noMatches")})}},`${P}:${Fe}`)}case"textarea":return l.jsx(Et,{name:P,control:j,render:({field:Ne,fieldState:Fe})=>{var Me;return l.jsx(Dr,{...De,value:Ne.value,onChange:Ne.onChange,maxLength:T.maxLength,showCounter:!!T.showCounter,hasError:!!Fe.error,errorMessage:mt(v,(Me=Fe.error)==null?void 0:Me.message)})}},P);case"file":return l.jsx(Yc,{...De,defaultValue:[],maxFiles:T.maxFiles,accept:T.accept,hideDropZone:T.hideDropZone,hasError:!!_[P],errorMessage:mt(v,(Re=_[P])==null?void 0:Re.message)},P);case"checkbox":return l.jsx(it,{...De,defaultValue:!1,hasError:!!_[P],errorMessage:mt(v,(Ve=_[P])==null?void 0:Ve.message),name:P},P);case"date":return l.jsx(Sa,{...De,defaultValue:"",showTime:!!T.showTime,hasError:!!_[P],errorMessage:mt(v,(Ge=_[P])==null?void 0:Ge.message)},P);case"optionGroup":return l.jsx(ki,{...De,options:T.options||[],multiple:T.multiple,vertical:T.vertical,groupLabel:T.groupLabel,defaultValue:T.defaultValue,className:T.width?void 0:"w-full",name:P},P);case"iban":return l.jsx(Et,{name:P,control:j,render:({field:Ne,fieldState:Fe})=>{var Me;return l.jsx(Ci,{label:W(T.label),placeholder:W(T.placeholder),size:T.size,disabled:J||O,value:Ne.value??"",onChange:Ne.onChange,onBlur:Ne.onBlur,hasError:!!Fe.error,errorMessage:mt(v,(Me=Fe.error)==null?void 0:Me.message),name:P})}},P);case"dni":return l.jsx(Et,{name:P,control:j,render:({field:Ne,fieldState:Fe})=>{var Me;return l.jsx(pd,{label:W(T.label),placeholder:W(T.placeholder),size:T.size,disabled:J||O,value:Ne.value??"",onChange:Ne.onChange,onBlur:Ne.onBlur,hasError:!!Fe.error,errorMessage:mt(v,(Me=Fe.error)==null?void 0:Me.message),name:P})}},P);default:return l.jsx(ii,{...De,type:T.type,loadingDefaults:B,hasError:!!_[P],errorMessage:mt(v,(ft=_[P])==null?void 0:ft.message),suffixButton:we,name:P},P)}},[o,L,j,_,O,B,Z,ee,G,ne,x.getValues,x.watch,b,v]);return l.jsx(xc,{...x,children:l.jsxs("form",{noValidate:!0,onSubmit:S(async M=>{await D(M,void 0,"onSubmit"),!(Object.keys(x.formState.errors).length>0)&&(await i(M),m(c??v("ds.form.saveSuccess"),"success"))},M=>{J$(M),m(d??v("ds.form.saveError"),"error")}),className:"space-y-6",children:[a.map((M,V)=>M.type==="rows"?l.jsx(C.Fragment,{children:M.sections.map((T,$)=>l.jsx("div",{children:l.jsx(lt,{title:W(T.sectionTitle),defaultOpen:T.defaultOpen,children:T.rows.map((P,z)=>l.jsxs("div",{children:[P.title&&l.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:W(P.title)}),l.jsx("div",{className:"flex flex-wrap -mx-2",children:P.columns.map((U,J)=>{var oe;return l.jsx("div",{className:`${U.width} px-2 flex flex-col`,children:l.jsx("div",{className:"",children:U.fields?U.fields.map(de=>H(de)):(oe=U.rows)==null?void 0:oe.map((de,ge)=>l.jsx("div",{className:"mb-1",children:l.jsx("div",{className:"flex flex-wrap -mx-2",children:de.columns.map((we,Ce)=>{var ke;return l.jsx("div",{className:`${we.width} px-2`,children:(ke=we.fields)==null?void 0:ke.map(Ie=>H(Ie))},Ce)})})},ge))})},J)})})]},z))})},$))},V):l.jsx(zr,{options:M.tabs.map(T=>{const $=T.icon?Ma(T.icon.name,T.icon.style):null;return{label:W(T.label),value:T.key,disabled:T.disabled,icon:$?l.jsx($,{className:"w-4 h-4"}):null}}),value:Q[V],onChange:T=>he($=>({...$,[V]:T})),children:Object.fromEntries(M.tabs.map(T=>[T.key,l.jsx("div",{className:"space-y-6",children:T.sections.map(($,P)=>l.jsx("div",{className:"mb-6",children:l.jsx(lt,{title:W($.sectionTitle),defaultOpen:$.defaultOpen,children:$.rows.map((z,U)=>l.jsx("div",{children:l.jsx("div",{className:"flex flex-wrap -mx-2",children:z.columns.map((J,oe)=>{var de;return l.jsx("div",{className:`${J.width??"flex-1"} px-2 flex flex-col`,children:l.jsx("div",{className:"space-y-4",children:(de=J.fields)==null?void 0:de.map((ge,we)=>l.jsx(C.Fragment,{children:H(ge)},we))})},oe)})})},U))})},P))},T.key)]))},V)),l.jsx("footer",{className:"py-4 w-full flex justify-center space-x-4",children:u??l.jsx(pe,{type:"submit",variant:"primary",icon:Tn,size:"sm",disabled:O||B||F>0,children:v(O?"ds.form.sending":"ds.form.submit")})})]})})}function K2({dark:e,onToggle:t}){return l.jsx("button",{type:"button","aria-pressed":e,"aria-label":e?"Cambiar a modo claro":"Cambiar a modo oscuro",onClick:t,className:ve("relative inline-flex items-center transition-colors focus:outline-none duration-200 ease-in-out","bg-[var(--color-ds-background-accent)]","h-6 w-12 rounded-full"),children:l.jsxs("div",{className:ve("absolute bg-[var(--color-ds-background-page)] flex items-center justify-center rounded-full transition-transform duration-200 ease-in-out","h-5 w-5",e?"translate-x-6":"translate-x-1"),children:[l.jsx(Ft,{component:uc,size:"sm",className:ve("absolute transition-opacity duration-200 ease-in-out",e?"opacity-0":"opacity-100 text-[var(--color-ds-background-accent)]")}),l.jsx(Ft,{component:oc,size:"sm",className:ve("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const J2="licytal:ui:theme",Y2=C.createContext({theme:"light",dark:!1,toggle:()=>{}});function SI({children:e}){const[t,r]=C.useState(!1),[n,a]=C.useState("light");C.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(J2);i==="light"||i==="dark"?a(i):window.matchMedia("(prefers-color-scheme: dark)").matches&&a("dark"),r(!0)},[]),C.useEffect(()=>{t&&(document.documentElement.classList.toggle("dark",n==="dark"),localStorage.setItem(J2,n))},[n,t]);const o=()=>a(i=>i==="light"?"dark":"light");return t?l.jsx(Y2.Provider,{value:{theme:n,dark:n==="dark",toggle:o},children:e}):null}const md=()=>C.useContext(Y2),Fo={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},X2=({pinnedPages:e,onRemovePinned:t,onBack:r,dark:n,locale:a,languageOptions:o,onChangeLocale:i,profile:c="",profileOptions:d=[],onChangeProfile:u,logoSrc:f,logoAlt:h="Logo aplicación"})=>{e.slice(0,3);const{toggle:p}=md(),m=g=>{try{localStorage.setItem(Fo.locale,g)}catch{}i==null||i(g)},v=()=>{const g=!n;try{localStorage.setItem(Fo.theme,g?"dark":"light")}catch{}p()};return C.useEffect(()=>{try{const g=localStorage.getItem(Fo.locale);g&&g!==a&&(i==null||i(g))}catch{}},[]),C.useEffect(()=>{if(a)try{localStorage.setItem(Fo.locale,a)}catch{}},[a]),C.useEffect(()=>{try{const g=localStorage.getItem(Fo.theme);if(!g)return;g==="dark"!==n&&p()}catch{}},[]),l.jsxs("header",{className:"flex items-center justify-between bg-[var(--color-ds-background-page)] py-2 px-4 min-h-[88px]",children:[l.jsx("div",{className:"flex items-center",children:f&&l.jsx("img",{src:f,alt:h,className:"h-24 w-auto object-contain"})}),l.jsxs("div",{className:"flex items-center space-x-2",children:[l.jsx(Xe,{size:"sm",width:"auto",options:o,value:a,onChange:m,disableErrorPlaceholder:!0,label:"Idioma",labelHidden:!0}),!!d.length&&l.jsx(Xe,{size:"sm",width:"auto",options:d,value:c,onChange:g=>u==null?void 0:u(g),disableErrorPlaceholder:!0,label:"Perfil",labelHidden:!0}),l.jsx(K2,{dark:n,onToggle:v})]})]})},AI={sm:"h-8 w-8",md:"h-10 w-10",lg:"h-12 w-12"};function Jt({icon:e,size:t="md",ariaLabel:r,disabled:n=!1,onClick:a,className:o,...i}){return l.jsx("button",{type:"button","aria-label":r,disabled:n,onClick:a,className:ve("inline-flex items-center justify-center","rounded-full","bg-transparent","text-[var(--color-ds-text-primary)]","transition-transform","focus:outline-none",AI[t],n?"opacity-50 cursor-not-allowed":["hover:scale-110","hover:animate-pulse","hover:bg-[var(--color-ds-background-neutral-hover)]"],o),...i,children:l.jsx(e,{className:ve(t==="sm"?"h-4 w-4":t==="md"?"h-5 w-5":"h-6 w-6")})})}const NI=({loading:e=!1,ariaLabel:t="Cargando..."})=>e?l.jsxs("div",{className:`\r
100
100
  fixed inset-0\r
101
101
  flex items-center justify-center\r
102
102
  bg-[var(--color-ds-background-surface)]/90\r
@@ -409,7 +409,7 @@ ${A.join(`
409
409
  `)}`,"error");return}n(c),m("Configuración de shortcuts guardada","success")},w=()=>{if(window.confirm("¿Restaurar shortcuts a valores por defecto?")){const j=LH();d(j),m("Shortcuts restaurados a valores por defecto","info")}},x=j=>{d(A=>({...A,[j]:{...A[j],enabled:!A[j].enabled}}))},y=j=>{f(j),p(!0)},E=j=>{if(!h||!u||(j.preventDefault(),j.stopPropagation(),["Control","Shift","Alt","Meta"].includes(j.key)))return;const A={...c[u],key:j.key,ctrl:j.ctrlKey||j.metaKey,shift:j.shiftKey,alt:j.altKey};d(S=>({...S,[u]:A})),p(!1),f(null)};if(C.useEffect(()=>{d(r)},[r]),C.useEffect(()=>{if(h)return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[h,u,c]),C.useEffect(()=>{e||(p(!1),f(null),d(r),i("general"))},[e,r]),!e)return null;const k=[{id:"general",label:a("ds.editor.settings.general","General"),icon:$n},{id:"appearance",label:a("ds.editor.settings.appearance","Apariencia"),icon:M1},{id:"shortcuts",label:a("ds.editor.settings.shortcuts","Atajos"),icon:fa}];return l.jsxs(Bt,{isOpen:e,onClose:t,title:a("ds.editor.settings.title","Configuración del Editor"),maxWidth:"max-w-4xl",children:[l.jsxs("div",{className:"flex h-[60vh] gap-6",children:[l.jsx("div",{className:"w-48 flex-shrink-0 flex flex-col gap-1 border-r border-[var(--color-ds-border-default-50)] pr-4",children:k.map(j=>l.jsxs("button",{onClick:()=>i(j.id),className:ve("flex items-center gap-2 px-3 py-2 text-sm font-medium rounded-lg transition-colors text-left",o===j.id?"bg-[var(--color-ds-button-primary-bg)] text-[var(--color-ds-button-primary-text)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)]"),children:[l.jsx(j.icon,{className:"w-4 h-4"}),j.label]},j.id))}),l.jsxs("div",{className:"flex-1 overflow-y-auto pr-2",children:[o==="general"&&l.jsx("div",{className:"space-y-6",children:l.jsxs("div",{className:"space-y-4",children:[l.jsx("h4",{className:"text-sm font-semibold text-[var(--color-ds-text-primary)] border-b border-[var(--color-ds-border-default-50)] pb-2",children:"Comportamiento"}),l.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)]",children:[l.jsx(it,{checked:v.confirmDelete,onChange:j=>g({confirmDelete:j}),size:"md",disableErrorPlaceholder:!0}),l.jsxs("div",{children:[l.jsx("div",{className:"text-sm font-medium text-[var(--color-ds-text-primary)]",children:"Confirmar eliminación"}),l.jsx("div",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:"Solicitar confirmación antes de eliminar campos o secciones."})]})]}),l.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)]",children:[l.jsx(it,{checked:v.showGrid,onChange:j=>g({showGrid:j}),size:"md",disableErrorPlaceholder:!0}),l.jsxs("div",{children:[l.jsx("div",{className:"text-sm font-medium text-[var(--color-ds-text-primary)]",children:"Mostrar rejilla de diseño"}),l.jsx("div",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:"Visualizar guías de columnas y filas en el editor."})]})]})]})}),o==="appearance"&&l.jsx("div",{className:"space-y-6",children:l.jsxs("div",{className:"space-y-4",children:[l.jsx("h4",{className:"text-sm font-semibold text-[var(--color-ds-text-primary)] border-b border-[var(--color-ds-border-default-50)] pb-2",children:"Tema del Editor"}),l.jsxs("div",{className:"p-4 rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] flex items-center justify-between",children:[l.jsxs("div",{children:[l.jsx("div",{className:"text-sm font-medium text-[var(--color-ds-text-primary)] mb-1",children:"Preferencia de color"}),l.jsx("div",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:"Elige entre modo claro, oscuro o sincronizar con el sistema."})]}),l.jsx(_o,{value:v.theme,onChange:j=>g({theme:j}),size:"lg",variant:"rounded",items:[{id:"light",label:"Claro",icon:uc},{id:"system",label:"Sistema",icon:Jl},{id:"dark",label:"Oscuro",icon:oc}]})]})]})}),o==="shortcuts"&&l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"flex justify-between items-center mb-2",children:[l.jsx("div",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:"Personaliza los atajos de teclado para mejorar tu productividad."}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(pe,{variant:"ghost",size:"xs",onClick:w,children:"Restaurar"}),l.jsx(pe,{variant:"primary",size:"xs",onClick:b,children:"Guardar Atajos"})]})]}),l.jsx("div",{className:"space-y-2",children:Object.entries(c).map(([j,A])=>l.jsxs("div",{className:ve("flex items-center justify-between p-3 rounded-xl transition-colors border","border-[var(--color-ds-border-muted)] hover:border-[var(--color-ds-border-default)]","bg-[var(--color-ds-background-surface)] hover:bg-[var(--color-ds-background-surface-hover)]"),children:[l.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[l.jsx(it,{checked:A.enabled,onChange:()=>x(j),size:"sm",disableErrorPlaceholder:!0}),l.jsx("div",{className:"cursor-pointer",onClick:()=>x(j),children:l.jsx("div",{className:ve("font-medium text-sm",!A.enabled&&"opacity-50 line-through"),children:A.description})})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("div",{className:ve("px-2 py-1 rounded border font-mono text-[10px] min-w-[60px] text-center",h&&u===j?"bg-blue-100 text-blue-700 border-blue-300 animate-pulse":"bg-[var(--color-ds-background-page)] border-[var(--color-ds-border-muted)]",!A.enabled&&"opacity-40"),children:h&&u===j?"...":os(A)}),l.jsx(pe,{size:"xs",variant:"ghost",onClick:S=>{S.stopPropagation(),y(j)},disabled:!A.enabled||h,children:l.jsx(Zs,{className:"w-3 h-3"})})]})]},j))})]})]})]}),l.jsx("div",{className:"flex justify-end pt-4 border-t border-[var(--color-ds-border-default)] mt-2",children:l.jsx(pe,{variant:"outline",onClick:t,children:"Cerrar"})})]})};function Eu(e,t){const r=new Blob([t],{type:"text/plain;charset=utf-8"}),n=URL.createObjectURL(r),a=document.createElement("a");a.href=n,a.download=e,a.click(),URL.revokeObjectURL(n)}const Cu=e=>e.toLowerCase().endsWith(".json")?e:`${e}.json`,Ap=(e,t)=>`${e.replace(/\/+$/,"")}/${t.replace(/^\/+/,"")}`,Np=()=>l.jsx("div",{className:"w-px h-6 bg-[var(--color-ds-border-default-50)] mx-2"});function PH(){var X;const{t:e,i18n:t}=At(),r=se(M=>M.schema),n=se(M=>M.undo),a=se(M=>M.redo),o=se(M=>M.setSchema),i=se(M=>M.resetHistory),c=se(M=>M.past.length),d=se(M=>M.future.length),u=se(M=>M.selection),f=se(M=>M.removeField),h=se(M=>M.duplicateField),p=se(M=>M.editorSettings),m=se(M=>M.showRelations??!1),v=se(M=>M.toggleRelations),g=se(M=>M.setShowRelations),b=se(M=>M.mode),w=se(M=>M.setMode),[x,y]=C.useState(!1),[E,k]=C.useState(!1),[j,A]=C.useState(!1),[S,_]=C.useState(!1),[O,B]=C.useState(!1),[R,I]=C.useState(!1),F=()=>{typeof v=="function"?v():typeof g=="function"&&g(!m)},Z=C.useRef(null),ee=C.useRef(null),{show:Y}=yn(),{fs:te,baseDir:ae,translations:q,services:N,setServices:L}=Zt(),ne=((X=r.title)==null?void 0:X.toString().trim().replace(/\s+/g,"-").toLowerCase())||"form-schema",K=()=>{Eu(`${ne}.json`,JSON.stringify(r,null,2)),Y("Esquema exportado como JSON.","success")},Q=()=>{try{const M=bu(r,"validationSchema");Eu(`${ne}.validation.ts`,M),Y("Yup exportado como TypeScript.","success")}catch(M){console.error(M),Y("No se pudo generar el Yup.","error")}},he=()=>{try{const M=wu(r,q,t),V=`${ne}.translations.json`;Eu(V,JSON.stringify(M,null,2)),Y("Traducciones exportadas como JSON.","success")}catch(M){console.error(M),Y("No se pudo generar el JSON de traducciones.","error")}},ie=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(r,null,2)),Y("JSON copiado al portapapeles.","success")}catch{Y("No se pudo copiar al portapapeles.","error")}},me=()=>{var M;return(M=Z.current)==null?void 0:M.click()},ce=()=>{var M;return(M=ee.current)==null?void 0:M.click()},le=M=>{var P;const V=(P=M.target.files)==null?void 0:P[0];if(!V)return;if(!window.confirm("Vas a reemplazar el esquema actual. ¿Continuar?")){M.currentTarget.value="";return}const $=new FileReader;$.onload=()=>{try{const z=JSON.parse(String($.result));if(!Array.isArray(z.layout)||!Array.isArray(z.fields)){Y("JSON inválido: faltan layout/fields.","error");return}o(z),i(),Y("Esquema importado correctamente.","success")}catch{Y("No se pudo parsear el JSON.","error")}},$.readAsText(V),M.currentTarget.value=""},be=async M=>{var P;const V=M.target,T=(P=V.files)==null?void 0:P[0];if(!T)return;if(!window.confirm("Al importar un proyecto ZIP se reemplazará el esquema actual, los servicios y las traducciones. ¿Continuar?")){V.value="";return}try{await jH({file:T,setSchema:z=>{o(z),i()},setServices:L,translationAdapter:q}),Y("Proyecto importado correctamente.","success")}catch(z){console.error(z),Y(z.message||"Error al importar ZIP","error")}V.value=""},fe=()=>{window.confirm("Crear un esquema nuevo vacío (perderás cambios no guardados). ¿Continuar?")&&(o(V=>{V.layout=[{type:"rows",sections:[{sectionTitle:"Sección 1",defaultOpen:!0,rows:[{title:"",columns:[{width:"w-full",fields:[]}]}]}]}],V.fields=[],V.successMessage="Guardado",V.errorMessage="Error",V.onSubmit=async()=>{}}),i(),Y("Esquema nuevo creado.","info"))},xe=async()=>{try{const M=Ap(ae,Cu(`${ne}.json`));await te.write(M,JSON.stringify(r,null,2)),Y(`Guardado rápido en ${M}`,"success")}catch(M){console.error(M),Y("Guardado rápido fallido.","error")}},D=async()=>{try{const M=Cu(`${ne}.json`),V=window.prompt("Guardar como (archivo en baseDir):",M);if(!V)return;const T=Ap(ae,Cu(V));await te.write(T,JSON.stringify(r,null,2)),Y(`Guardado en ${T}`,"success")}catch(M){console.error(M),Y("No se pudo guardar el archivo.","error")}},{config:G,updateConfig:re}=IH({undo:()=>{c>0&&n()},redo:()=>{d>0&&a()},save:()=>{xe()},saveAs:()=>{D()},toggleRelations:()=>{F()},togglePreview:()=>{w(b==="design"?"preview":b==="preview"?"code":"design")},deleteField:()=>{u.kind==="field"&&(!p.confirmDelete||window.confirm(`¿Eliminar el campo "${u.name}"?`))&&(f(u.name),Y("Campo eliminado","success"))},duplicateField:()=>{u.kind==="field"&&(h(u.name),Y("Campo duplicado","success"))},copy:()=>{ie()},newSchema:()=>{fe()},importSchema:()=>{me()},exportSchema:()=>{K()}}),W=[{label:"Nuevo esquema",icon:S1,onSelect:fe},{label:"Importar JSON...",icon:N1,onSelect:me},{label:"Importar Proyecto (ZIP)...",icon:o1,onSelect:ce},{label:"Generar desde DTO...",icon:fa,onSelect:()=>k(!0)},{label:"Gestionar Servicios...",icon:fa,onSelect:()=>_(!0)},{label:"Generar desde BD...",icon:po,onSelect:()=>A(!0)},{label:"Guardar",icon:zl,onSelect:xe},{label:"Guardar como...",icon:zl,onSelect:D}],H=[{label:"Exportar JSON",icon:ha,onSelect:K},{label:"Exportar Yup (.ts)",icon:ar,onSelect:Q},{label:"Exportar Traducciones",icon:Vs,onSelect:he},{label:"Copiar JSON",icon:mo,onSelect:ie},{label:"Exportar Proyecto (ZIP)",icon:Kl,onSelect:()=>{const M=(N==null?void 0:N.registry)||{};console.log("Services Registry for Export:",M),RH({schema:r,translationsAdapter:q,i18n:t,servicesRegistry:M,baseName:ne}),Y("Proyecto exportado correctamente","success")}}];return l.jsxs("div",{className:"pb-1 bg-[var(--color-ds-background-page)]",children:[l.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-sm px-3 py-2",children:[l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx(Jt,{icon:h1,size:"sm",onClick:n,disabled:c===0,ariaLabel:`Deshacer (${os(G.undo)})`,title:`Deshacer (${os(G.undo)})`}),l.jsx(Jt,{icon:p1,size:"sm",onClick:a,disabled:d===0,ariaLabel:`Rehacer (${os(G.redo)})`,title:`Rehacer (${os(G.redo)})`}),l.jsx(Np,{}),l.jsx(gH,{}),l.jsx(Np,{}),l.jsx(ko,{trigger:l.jsxs("span",{className:"flex items-center gap-1 px-2 py-1.5 text-sm font-medium text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-neutral-hover)] rounded-md transition-colors",children:["Archivo",l.jsx(fr,{className:"w-3 h-3 opacity-50"})]}),items:W}),l.jsx(ko,{trigger:l.jsxs("span",{className:"flex items-center gap-1 px-2 py-1.5 text-sm font-medium text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-neutral-hover)] rounded-md transition-colors",children:[e("ds.editor.toolbar.export"),l.jsx(fr,{className:"w-3 h-3 opacity-50"})]}),items:H}),l.jsx(pe,{variant:"subtle",size:"sm",onClick:()=>_(!0),icon:Kl,ariaLabel:"Importar/Gestionar Servicios OpenAPI",className:"ml-1 text-[var(--color-ds-primary-700)] bg-[var(--color-ds-primary-50)] hover:bg-[var(--color-ds-primary-100)] ring-[var(--color-ds-primary-200)]",children:"Servicios"}),l.jsx(pe,{variant:"subtle",size:"sm",onClick:()=>B(!0),icon:po,ariaLabel:"Configurar carga inicial de datos",className:"ml-1 text-[var(--color-ds-primary-700)] bg-[var(--color-ds-primary-50)] hover:bg-[var(--color-ds-primary-100)] ring-[var(--color-ds-primary-200)]",children:"Pre-carga"}),l.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>I(!0),icon:fa,ariaLabel:"Ver variables de sistema",title:"Variables de sistema",className:"ml-1 text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]"}),l.jsx("input",{ref:Z,type:"file",accept:"application/json",className:"hidden",onChange:le,"aria-label":e("ds.editor.toolbar.import")}),l.jsx("input",{ref:ee,type:"file",accept:".zip,application/zip,application/x-zip-compressed",className:"hidden",onChange:be,"aria-label":"Importar Proyecto ZIP"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Jt,{icon:m?ec:In,size:"sm",onClick:F,ariaLabel:e(m?"ds.editor.toolbar.hideRelations":"ds.editor.toolbar.showRelations"),title:e(m?"ds.editor.toolbar.hideRelations":"ds.editor.toolbar.showRelations"),className:"text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]"}),l.jsx(Jt,{icon:$n,size:"sm",onClick:()=>y(!0),ariaLabel:e("ds.editor.toolbar.shortcuts"),title:e("ds.editor.toolbar.shortcuts")}),l.jsx("div",{className:"w-px h-6 bg-[var(--color-ds-border-default-50)] mx-1"}),l.jsx(_o,{value:b,onChange:M=>w(M),size:"sm",variant:"square",items:[{id:"design",label:e("ds.editor.modes.design"),icon:ma},{id:"preview",label:e("ds.editor.modes.preview"),icon:In},{id:"code",label:e("ds.editor.modes.code"),icon:ar}]})]})]}),l.jsx(BH,{isOpen:x,onClose:()=>y(!1),config:G,onSaveShortcuts:re}),l.jsx(Hz,{open:E,onClose:()=>k(!1)}),l.jsx(Kz,{open:j,onClose:()=>A(!1)}),l.jsx(cH,{isOpen:S,onClose:()=>_(!1)}),O&&l.jsx(dH,{isOpen:!0,onClose:()=>B(!1)}),l.jsx(mH,{isOpen:R,onClose:()=>I(!1)})]})}const il="application/x-ds-field-template",Fp="application/x-ds-layout-kind";function ju(e){return e.layout.find(t=>(t==null?void 0:t.type)==="rows")}function VH({className:e,children:t}){var x;const r=se(y=>y.schema),n=se(y=>y.addFieldAndPlace),a=se(y=>y.addRowsBlockAt),o=se(y=>y.addSection),i=se(y=>y.addRowToSection),c=se(y=>y.setRowColumns),d=se(y=>y.moveField),[u,f]=C.useState(!1),h=C.useMemo(()=>{var k;const y=ju(r);if(!y)return[];const E=[];return(k=y.sections)==null||k.forEach((j,A)=>{var S;(S=j.rows)==null||S.forEach((_,O)=>{(_.columns??[]).forEach((B,R)=>{var Z;const I=((Z=B.fields)==null?void 0:Z.length)??0,F=Math.max(1,I+1);for(let ee=0;ee<F;ee++)E.push({kind:"field-slot",sectionIdx:A,rowIdx:O,colIdx:R,insertIdx:ee,key:`s${A}-r${O}-c${R}-i${ee}`})})})}),E},[r]),p=C.useCallback(()=>{var j,A;const y=r.layout.findIndex(S=>(S==null?void 0:S.type)==="rows"),E=r.layout[y];return E?(j=E.sections)!=null&&j.length?(A=E.sections[0].rows)!=null&&A.length?((E.sections[0].rows[0].columns??[]).length||c==null||c(y,0,0,1),{s:0,r:0,c:0}):(i==null||i(y,0),{s:0,r:0,c:0}):(o==null||o("Sección 1"),{s:0,r:0,c:0}):(a==null||a(r.layout.length??0,"Sección 1"),{s:0,r:0,c:0})},[r,a,o,i,c]),m=C.useCallback(y=>{var k;const E=((k=y.dataTransfer)==null?void 0:k.types)||[];(E.includes(il)||E.includes(Fp))&&(y.preventDefault(),y.dataTransfer.dropEffect="copy",f(E.includes(il)?"field":"layout"))},[]),v=C.useCallback(()=>f(!1),[]),g=C.useCallback(y=>{var A;const E=y.dataTransfer.getData(Fp);if(!E)return!1;const{kind:k}=JSON.parse(E),j=((A=r==null?void 0:r.layout)==null?void 0:A.length)??0;return k==="section-layout"&&(a==null||a(j,"Nueva sección")),!0},[(x=r==null?void 0:r.layout)==null?void 0:x.length,a]),b=C.useCallback((y,E)=>{const k=E.dataTransfer.getData(il);if(!k)return!1;const{fieldTemplate:j}=JSON.parse(k);return n(j,y.sectionIdx,y.rowIdx,y.colIdx),queueMicrotask(()=>{var B;const A=se.getState().schema,O=(((B=ju(A).sections[y.sectionIdx].rows[y.rowIdx].columns[y.colIdx].fields)==null?void 0:B.length)??1)-1;y.insertIdx>=0&&y.insertIdx<O&&d({s:y.sectionIdx,r:y.rowIdx,c:y.colIdx,idx:O},{s:y.sectionIdx,r:y.rowIdx,c:y.colIdx,idx:y.insertIdx})}),!0},[n,d]),w=C.useCallback(y=>{if(y.preventDefault(),y.stopPropagation(),g(y)){f(!1);return}const E=y.dataTransfer.getData(il);if(E){const{fieldTemplate:k}=JSON.parse(E),j=p();n(k,j.s,j.r,j.c)}f(!1)},[g,p,n]);return l.jsxs("div",{className:["relative",e].filter(Boolean).join(" "),onDragOver:m,onDragLeave:v,onDrop:w,children:[t,u&&l.jsxs("div",{className:"absolute inset-0 z-40",children:[l.jsx("div",{className:"absolute inset-0 bg-black/5 pointer-events-none"}),l.jsx("div",{className:"absolute inset-0 px-4 py-4 overflow-auto space-y-4",children:(()=>{var k;const y=ju(r);if(!y||!((k=y.sections)!=null&&k.length)){const j=p(),A={kind:"field-slot",sectionIdx:j.s,rowIdx:j.r,colIdx:j.c,insertIdx:0,key:"init"};return l.jsx("div",{className:"min-h-[220px] border-2 border-dashed rounded-2xl bg-white/70 flex items-center justify-center text-ds-sm",onDragOver:S=>S.preventDefault(),onDrop:S=>{S.preventDefault(),S.stopPropagation(),b(A,S),f(!1)},children:"Suelta aquí para empezar"})}const E=[];return y.sections.forEach((j,A)=>{var S;(S=j.rows)==null||S.forEach((_,O)=>{const B=[];(_.columns??[]).forEach((R,I)=>{const F=h.filter(Z=>Z.sectionIdx===A&&Z.rowIdx===O&&Z.colIdx===I);B.push(F)}),E.push({key:`s${A}-r${O}`,cols:B})})}),E.map(j=>l.jsx("div",{className:"grid gap-3 pointer-events-none",style:{gridTemplateColumns:`repeat(${j.cols.length||1}, minmax(0,1fr))`},children:j.cols.map((A,S)=>{const _=A.length===1;return l.jsx("div",{className:"pointer-events-auto",children:l.jsx("div",{className:["rounded-xl border-2 border-dashed bg-white/60",_?"min-h-[160px]":"py-2"].join(" "),children:l.jsx("div",{className:"flex flex-col gap-2",children:A.map(O=>l.jsx("div",{className:"h-7 rounded-md border border-transparent hover:border-[var(--color-ds-border-default)] hover:bg-white/80 flex items-center justify-center text-ds-sm text-[var(--color-ds-text-secondary)]",onDragOver:B=>B.preventDefault(),onDrop:B=>{B.preventDefault(),B.stopPropagation(),b(O,B),f(!1)},title:`Insertar en Col ${O.colIdx+1}, posición ${O.insertIdx+1}`,children:_?"Soltar aquí":O.insertIdx===A.length-1?"Añadir al final":"Insertar aquí"},O.key))})})},`${j.key}-c${S}`)})},j.key))})()})]})]})}function ZH({nodeIdx:e,insertAt:t}){const r={scope:"rows-section",nodeIdx:e,insertAt:t},{setNodeRef:n,isOver:a}=Sr({id:`rows-section:drop:${e}:${t}`,data:r});return l.jsx("div",{ref:n,className:["h-2 my-1 w-full rounded-sm transition relative mx-1 px-1",a?"bg-[var(--color-ds-border-default)]/30 ring-1 ring-[var(--color-ds-border-default)]":"bg-transparent"].join(" "),"aria-label":`Insertar sección en posición ${t+1}`})}function zH({nodeIdx:e,sIdx:t}){const r=`rows-section:drag:${e}:${t}`,n={kind:"rows-section",nodeIdx:e,sIdx:t},{attributes:a,listeners:o,setNodeRef:i,isDragging:c}=Jn({id:r,data:n});return l.jsx("div",{ref:i,...a,...o,role:"button",title:"Arrastrar sección","aria-grabbed":c,className:"shrink-0 w-6 h-6 grid place-items-center cursor-grab active:cursor-grabbing rounded text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-muted)]",children:"⇅"})}function _p(e){const r={...e.scope==="rows-column"?{scope:"rows-column",s:e.s,r:e.r,c:e.c,rowsNodeIdx:e.rowsNodeIdx}:{scope:"tabs-column",tabKey:e.tabKey,s:e.s,r:e.r,c:e.c},insertAt:Number.MAX_SAFE_INTEGER},{setNodeRef:n,isOver:a}=Sr({id:JSON.stringify(r),data:r});return l.jsx("div",{ref:n,className:a?"ring-5 ring-[var(--color-ds-border-default)] rounded-md":"","aria-dropeffect":a?"copy":void 0,"data-drop-scope":e.scope,children:e.children})}function HH(e,t=44){if(!e)return t;const r=e.previousElementSibling,n=e.nextElementSibling,a=c=>{var d;return((d=c==null?void 0:c.querySelector)==null?void 0:d.call(c,"[data-sortable-item]"))||c},o=a(r)??a(n)??null,i=(o==null?void 0:o.getBoundingClientRect().height)??0;return Math.max(32,Math.min(96,Math.round(i||t)))}function WH(e){var h,p,m,v,g,b,w,x;if(!e)return null;const t=e.kind??e.scope??e.type,r=e.s??((h=e.path)==null?void 0:h.s),n=e.r??((p=e.path)==null?void 0:p.r),a=e.c??((m=e.path)==null?void 0:m.c),o=e.idx??((v=e.path)==null?void 0:v.idx),i=e.index,c=e.rowsNodeIdx??e.nodeIdx??((g=e.path)==null?void 0:g.rowsNodeIdx),d=e.tabKey??((b=e.path)==null?void 0:b.tabKey),u=e.groupName??((w=e.path)==null?void 0:w.groupName),f=e.arrayName??((x=e.path)==null?void 0:x.arrayName);return{kind:t,s:r,r:n,c:a,idx:o,index:i,rowsNodeIdx:c,tabKey:d,groupName:u,arrayName:f}}function UH(e,t){if(!t)return!1;const r=n=>typeof n=="number"&&(e.insertAt===n||e.insertAt===n+1);if(e.scope==="rows-column"){if((t.kind==="field-in-rows"||t.kind==="rows-column")&&t.rowsNodeIdx===e.rowsNodeIdx&&t.s===e.s&&t.r===e.r&&t.c===e.c&&r(t.idx))return!0}else if(e.scope==="tabs-column"){if((t.kind==="field-in-tabs"||t.kind==="tabs-column")&&t.tabKey===e.tabKey&&t.s===e.s&&t.r===e.r&&t.c===e.c&&r(t.idx))return!0}else if(e.scope==="input-group"){if((t.kind==="field-in-inputgroup"||t.kind==="input-group")&&t.groupName===e.groupName&&r(t.idx))return!0}else if(e.scope==="array-items"&&(t.kind==="field-in-array"||t.kind==="array-items")&&t.arrayName===e.arrayName&&r(t.index))return!0;return!1}function Fr(e){let t;e.scope==="rows-column"?t={scope:"rows-column",rowsNodeIdx:e.rowsNodeIdx,s:e.s,r:e.r,c:e.c,insertAt:e.insertAt}:e.scope==="tabs-column"?t={scope:"tabs-column",tabKey:e.tabKey,s:e.s,r:e.r,c:e.c,insertAt:e.insertAt}:e.scope==="input-group"?t={scope:"input-group",groupName:e.groupName,insertAt:e.insertAt}:t={scope:"array-items",arrayName:e.arrayName,insertAt:e.insertAt};const r=C.useRef(null),{setNodeRef:n,isOver:a}=Sr({id:JSON.stringify(t),data:t}),[o,i]=C.useState(44),c=e.scope==="input-group"?6:8,[d,u]=C.useState(null);zo({onDragStart:g=>{var b,w;return u(((w=(b=g.active)==null?void 0:b.data)==null?void 0:w.current)??null)},onDragCancel:()=>u(null),onDragEnd:()=>u(null)});const f=UH(e,WH(d)),h=!!e.suppressAll||f;if(C.useEffect(()=>{if(!a||h)return;const g=HH(r.current,e.scope==="input-group"?36:44);i(g)},[a,e.scope,h]),h)return l.jsx("div",{ref:g=>{r.current=g,n(g)},style:{position:"absolute",inset:0,pointerEvents:"none"},role:"button","aria-dropeffect":a?"copy":void 0,"aria-label":`Soltar aquí (posición ${e.insertAt+1})`,"data-drop-scope":e.scope,"data-insert-at":e.insertAt});const p=e.insertAt===0,m={height:a?o:0,margin:a?`${c}px 0`:"0px",transition:"height 120ms ease, margin 120ms ease, opacity 80ms ease",opacity:a?1:0},v=e.scope==="input-group"?"w-full inline-flex":"w-full block";return l.jsx("div",{ref:g=>{r.current=g,n(g)},role:"button","aria-dropeffect":a?"copy":void 0,"aria-label":`Soltar aquí (posición ${e.insertAt+1})`,"data-drop-scope":e.scope,"data-insert-at":e.insertAt,className:v,style:m,children:a&&l.jsx("div",{"aria-hidden":!0,className:["w-full","rounded-md","border","border-dashed","border-[var(--color-ds-border-default-50)]",e.scope==="input-group"?"bg-[var(--color-ds-background-surface)]/70":"bg-[var(--color-ds-background)]/60","relative"].join(" "),style:{height:o,boxShadow:"inset 0 0 0 1px color-mix(in srgb, var(--color-ds-border-default-50) 30%, transparent)"},children:!e.suppressHint&&l.jsxs("div",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[11px] leading-none",style:{background:"var(--color-ds-background-elevated)",color:"var(--color-ds-text-secondary)",border:"1px solid var(--color-ds-border-default-50)"},children:["Soltar aquí",""]})})})}function Nn(e){const t=e.kind==="field-in-tabs"?`${e.kind}:${e.tabKey}:${e.name}:${e.path.s}-${e.path.r}-${e.path.c}-${e.path.idx}`:e.kind==="field-in-rows"?`${e.kind}:${e.rowsNodeIdx}:${e.name}:${e.path.s}-${e.path.r}-${e.path.c}-${e.path.idx}`:e.kind==="field-in-inputgroup"?`${e.kind}:${e.groupName}:${e.name}:${e.path.idx}`:`${e.kind}:${e.arrayName}:${e.name}:${e.index}`,r=e.kind==="field-in-rows"?{kind:e.kind,name:e.name,path:e.path,rowsNodeIdx:e.rowsNodeIdx}:e.kind==="field-in-tabs"?{kind:e.kind,name:e.name,path:e.path,tabKey:e.tabKey}:e.kind==="field-in-inputgroup"?{kind:e.kind,name:e.name,path:e.path,groupName:e.groupName}:{kind:e.kind,name:e.name,arrayName:e.arrayName,index:e.index},{attributes:n,listeners:a,setNodeRef:o,isDragging:i}=Jn({id:t,data:r}),c=e.disableSelect?l.jsxs("span",{className:"text-[var(--color-ds-text-primary)] text-ds-sm text-left truncate inline-flex items-center gap-1",children:[e.icon?l.jsx("span",{"aria-hidden":!0,className:"shrink-0 text-[var(--color-ds-text-secondary)]",children:e.icon}):null,l.jsx("span",{className:"truncate",children:e.name})]}):l.jsxs("button",{type:"button",className:"text-[var(--color-ds-text-primary)] text-ds-sm hover:underline text-left truncate inline-flex items-center gap-1",onClick:d=>{d.stopPropagation(),e.onSelect()},children:[e.icon?l.jsx("span",{"aria-hidden":!0,className:"shrink-0 text-[var(--color-ds-text-secondary)]",children:e.icon}):null,l.jsx("span",{className:"truncate",children:e.name})]});return l.jsxs("div",{ref:o,className:["text-[var(--color-ds-text-primary)] group flex items-center justify-between rounded-md py-1 w-full","overflow-visible",i?"opacity-50":"opacity-100"].join(" "),"data-field-name":e.name,children:[c,l.jsx("div",{...a,...n,role:"button","aria-grabbed":i,"aria-label":`Arrastrar campo ${e.name}`,className:["text-[var(--color-ds-text-primary)] text-[11px] select-none cursor-grab active:cursor-grabbing","px-1 py-0.5 rounded-sm","hover:bg-[var(--color-ds-background-muted)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]"].join(" "),title:"Arrastra para reordenar",children:"⇅"})]})}function Mp(e){return se(C.useCallback(t=>{if(e)return t.schema.fields.find(r=>r.name===e)},[e]))}const qH=C.memo(({fieldOrName:e,groupName:t,index:r,onRemove:n,setSelection:a,confirmDelete:o})=>{const i=typeof e=="string"?e:e.name,d=Mp(i)||(typeof e=="object"?e:void 0),u=d==null?void 0:d.name,f=(d==null?void 0:d.type)??"text";let h;d&&("label"in d?h=d.label:"groupLabel"in d&&(h=d.groupLabel));const p=Ur(f),m=kr(f);return l.jsxs("div",{className:"flex items-center justify-between w-full gap-2 rounded-md border bg-[var(--color-ds-background-page)] px-2 py-1",style:{borderColor:"var(--color-ds-border-default-50)",borderLeft:`4px solid ${p}`,boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${p} 18%, transparent)`},children:[u?l.jsx(Nn,{kind:"field-in-inputgroup",groupName:t,name:u,path:{idx:r},onSelect:()=>a({kind:"field",name:u}),icon:m}):l.jsx("div",{className:"text-ds-sm opacity-80",children:h??"(inline sin nombre)"}),u?l.jsx(pe,{size:"xs",variant:"danger",onClick:()=>o("Eliminar campo","¿Estás seguro de que quieres eliminar este campo del grupo?",n),title:"Quitar del grupo",shape:"circle",icon:st}):null]})}),GH=C.memo(function({field:t,index:r,nodeIdx:n,sIdx:a,rIdx:o,cIdx:i,parentType:c,tabKey:d,onDelete:u,confirmDelete:f}){const h=typeof t=="string"?t:t==null?void 0:t.name,m=Mp(h)||(typeof t=="object"?t:void 0),v=se(Z=>Z.setSelection),g=se(Z=>Z.removeFieldFromInputGroup),b=se(Z=>Z.removeFieldFromArray),w=(m==null?void 0:m.name)??h,x=(m==null?void 0:m.type)??"text",y=kr(x),E=Ur(x),k=()=>c==="rows"?l.jsx(Nn,{kind:"field-in-rows",rowsNodeIdx:n,name:w,path:{s:a,r:o,c:i,idx:r},onSelect:()=>v({kind:"field",name:w}),icon:y}):l.jsx(Nn,{kind:"field-in-tabs",tabKey:d,name:w,path:{s:a,r:o,c:i,idx:r},onSelect:()=>v({kind:"field",name:w}),icon:y}),j=(Z,ee)=>c==="rows"?l.jsx(Fr,{scope:"rows-column",rowsNodeIdx:n,s:a,r:o,c:i,insertAt:Z,suppressAll:ee}):l.jsx(Fr,{scope:"tabs-column",tabKey:d,s:a,r:o,c:i,insertAt:Z,suppressAll:ee}),A=se(Z=>Z.activeVariantId),S=se(Z=>Z.schema.variants),_=C.useMemo(()=>S==null?void 0:S.find(Z=>Z.key===A),[S,A]),O=C.useMemo(()=>{var Z;return(Z=_==null?void 0:_.overrides)==null?void 0:Z[w]},[_,w]),B=O==null?void 0:O.hidden,R=O==null?void 0:O.disabled,I=B?{opacity:.4,filter:"grayscale(100%)"}:{},F=()=>B||R?l.jsxs("div",{className:"flex gap-1 absolute top-0 right-8 -mt-2",children:[B&&l.jsx("span",{className:"bg-gray-500 text-white text-[9px] px-1 rounded shadow-sm",children:"Hidden"}),R&&l.jsx("span",{className:"bg-amber-500 text-white text-[9px] px-1 rounded shadow-sm",children:"Disabled"})]}):null;if(x==="inputGroup"){const Z=m,ee=(Z==null?void 0:Z.type)==="inputGroup"&&Array.isArray(Z==null?void 0:Z.inputs)?Z.inputs:[],Y=(Z==null?void 0:Z.type)!=="inputGroup"&&Array.isArray(Z==null?void 0:Z.inputs)?Z.inputs:[],te=ee.length>0,ae=!te&&Y.length>0;return l.jsxs(C.Fragment,{children:[l.jsxs("div",{"data-field-name":w,className:"rounded-md border bg-[var(--color-ds-background-page)] relative",style:{borderColor:"var(--color-ds-border-default-50)",boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${Ur("inputGroup")} 18%, transparent)`,...I},children:[l.jsx(F,{}),l.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 py-1 bg-[var(--color-ds-background-surface)] border-b border-[var(--color-ds-border-default-50)]",children:[c==="rows"?l.jsx(Nn,{kind:"field-in-rows",rowsNodeIdx:n,name:w,path:{s:a,r:o,c:i,idx:r},onSelect:()=>v({kind:"field",name:w}),icon:kr("inputGroup"),disableSelect:!0}):l.jsx(Nn,{kind:"field-in-tabs",tabKey:d,name:w,path:{s:a,r:o,c:i,idx:r},onSelect:()=>v({kind:"field",name:w}),icon:kr("inputGroup"),disableSelect:!0}),l.jsx(pe,{size:"xs",variant:"danger",onClick:u,title:"Quitar grupo del layout",shape:"circle",icon:st})]}),l.jsx("div",{className:"p-2",children:l.jsxs("div",{className:"flex flex-row gap-2 flex-wrap relative",children:[l.jsx(Fr,{scope:"input-group",groupName:w,insertAt:0,suppressAll:!te}),te&&ee.map((q,N)=>{const L=typeof q=="string"?q:q.name??N;return l.jsxs(C.Fragment,{children:[l.jsx(qH,{fieldOrName:q,groupName:w,index:N,onRemove:()=>g(w,N),setSelection:v,confirmDelete:f}),l.jsx(Fr,{scope:"input-group",groupName:w,insertAt:N+1,suppressAll:!te})]},`${w}-child-${L}`)}),!te&&ae&&Y.map((q,N)=>l.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-dashed bg-[var(--color-ds-background-surface)] px-2 py-1 opacity-80",title:"Definido en FieldSchema.inputs (vista previa).",children:[l.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded-full border",children:(q==null?void 0:q.label)??(q==null?void 0:q.name)??"Input"}),l.jsx("span",{className:"text-[var(--color-ds-text-secondary)] text-ds-sm",children:"(solo vista)"})]},`${w}-ui-${(q==null?void 0:q.name)??N}`)),!te&&!ae&&l.jsx("div",{className:"text-center text-[12px] text-[var(--color-ds-text-secondary)] border border-dashed border-[var(--color-ds-border-default-50)] rounded-md py-3 w-full",children:"Suelta inputs dentro del grupo"})]})})]}),j(r+1,!1)]})}if(x==="array"){const Z=m,ee=Array.isArray(Z==null?void 0:Z.items)?Z.items:[];return l.jsxs(C.Fragment,{children:[l.jsxs("div",{"data-field-name":w,className:"rounded-md border bg-[var(--color-ds-background-page)] relative",style:{borderColor:"var(--color-ds-border-default-50)",boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${Ur("array")} 18%, transparent)`,...I},children:[l.jsx(F,{}),l.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 py-1 bg-[var(--color-ds-background-surface)] border-b border-[var(--color-ds-border-default-50)]",children:[c==="rows"?l.jsx(Nn,{kind:"field-in-rows",rowsNodeIdx:n,name:w,path:{s:a,r:o,c:i,idx:r},onSelect:()=>v({kind:"field",name:w}),icon:kr("array"),disableSelect:!0}):l.jsx(Nn,{kind:"field-in-tabs",tabKey:d,name:w,path:{s:a,r:o,c:i,idx:r},onSelect:()=>v({kind:"field",name:w}),icon:kr("array"),disableSelect:!0}),l.jsx(pe,{size:"xs",variant:"danger",onClick:u,title:"Quitar repeater",shape:"circle",icon:st})]}),l.jsxs("div",{className:"p-3 bg-[var(--color-ds-background-subtle)] rounded-b-md",children:[l.jsx("div",{className:"text-[10px] uppercase font-bold tracking-wider text-[var(--color-ds-text-tertiary)] mb-2 pl-1 select-none",children:"Plantilla de Item"}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(Fr,{scope:"array-items",arrayName:w,insertAt:0,suppressAll:ee.length===0}),ee.length===0&&l.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 text-center text-[12px] text-[var(--color-ds-text-secondary)] border-2 border-dashed border-[var(--color-ds-border-default-50)] rounded-lg py-6 bg-[var(--color-ds-background-page)] transition-colors hover:border-[var(--color-ds-border-default)] hover:bg-[var(--color-ds-background-surface)]",children:[l.jsx("div",{className:"p-2 rounded-full bg-[var(--color-ds-background-subtle)]",children:l.jsx(hr,{className:"w-5 h-5 opacity-50"})}),l.jsx("span",{className:"font-medium",children:"Arrastra campos aquí"}),l.jsx("span",{className:"text-[11px] opacity-70 max-w-[180px]",children:"Define qué campos tendrá cada elemento de la lista"})]}),ee.map((Y,te)=>{const ae=Y.name,q=Y.type,N=kr(q),L=Ur(q);return l.jsxs(C.Fragment,{children:[l.jsxs("div",{className:"flex items-center justify-between gap-2 rounded border bg-[var(--color-ds-background-page)] px-2 py-1",style:{borderLeft:`3px solid ${L}`},children:[l.jsx(Nn,{kind:"field-in-array",arrayName:w,name:ae,index:te,path:{idx:te},onSelect:()=>v({kind:"field",name:ae}),icon:N}),l.jsx(pe,{size:"xs",variant:"danger",onClick:()=>b(w,te),title:"Eliminar campo del template",shape:"circle",icon:st})]}),l.jsx(Fr,{scope:"array-items",arrayName:w,insertAt:te+1,suppressAll:ee.length===0})]},`${w}-item-${te}`)})]})]})]}),j(r+1,!1)]})}return l.jsxs(C.Fragment,{children:[l.jsxs("div",{"data-field-name":w,className:"flex items-center justify-between gap-2 w-full rounded-md border bg-[var(--color-ds-background-page)] px-2 py-1 relative",style:{borderColor:"var(--color-ds-border-default-50)",borderLeft:`4px solid ${E}`,boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${E} 18%, transparent)`,...I},children:[l.jsx(F,{}),k(),l.jsx(pe,{size:"xs",variant:"danger",onClick:u,title:"Quitar del layout",shape:"circle",icon:st})]}),j(r+1,!1)]})}),KH=C.memo(function({col:t,widthClass:r,nodeIdx:n,sIdx:a,rIdx:o,cIdx:i,parentType:c,tabKey:d,confirmDelete:u}){const f=se(k=>k.removeColumn),h=se(k=>k.removeTabColumn),p=se(k=>k.placeFieldInColumn),m=se(k=>k.placeFieldInTabColumn),v=se(k=>k.removeFieldFromLayout),g=se(k=>k.removeFieldFromTabLayout),b=t.fields??[],w=se(C.useCallback(k=>{const j=k.schema.fields;for(let A=j.length-1;A>=0;A--){const S=j[A];if(S.type!=="inputGroup"&&S.type!=="button")return S.name}},[])),x=()=>{u("Eliminar columna","¿Estás seguro de que quieres eliminar esta columna? Se perderán los campos que contiene.",()=>{c==="rows"?f(n,a,o,i):h(d,a,o,i)})},y=()=>{w&&(c==="rows"?p(w,n,a,o,i):m(w,d,a,o,i))},E=()=>l.jsxs("div",{className:"bg-[var(--color-ds-background-page)] overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-[var(--color-ds-background-surface)]",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs("span",{className:"inline-flex items-center justify-center text-[11px] leading-none px-1.5 py-0.5 rounded-full border text-[var(--color-ds-text-primary)] border-[var(--color-ds-border-default-50)]",children:["Col ",i+1]}),l.jsx("span",{className:"text-[11px] leading-none text-[var(--color-ds-text-secondary)]",children:t.width||r||"flex-1"})]}),l.jsx("div",{className:"flex items-center gap-1",children:l.jsx(pe,{size:"xs",variant:"danger",onClick:x,title:"Eliminar columna",shape:"circle",icon:st})})]}),l.jsxs("div",{className:"p-2 relative",children:[l.jsxs("div",{className:"space-y-2",children:[c==="rows"?l.jsx(Fr,{scope:"rows-column",rowsNodeIdx:n,s:a,r:o,c:i,insertAt:0,suppressAll:b.length===0}):l.jsx(Fr,{scope:"tabs-column",tabKey:d,s:a,r:o,c:i,insertAt:0,suppressAll:b.length===0}),b.length===0&&l.jsx("div",{className:"text-center text-[12px] text-[var(--color-ds-text-secondary)] border border-dashed border-[var(--color-ds-border-default-50)] rounded-md py-4",children:"Suelta campos aquí"}),b.map((k,j)=>l.jsx(GH,{field:k,index:j,nodeIdx:n,sIdx:a,rIdx:o,cIdx:i,parentType:c,tabKey:d,onDelete:()=>{u("Eliminar campo","¿Estás seguro de que quieres eliminar este campo?",()=>{c==="rows"?v({nodeIdx:n,s:a,r:o,c:i,idx:j}):g({tabKey:d,s:a,r:o,c:i,idx:j})})},confirmDelete:u},`${typeof k=="string"?k:k.name}-${j}`))]}),l.jsx("div",{className:"mt-2 text-center",children:l.jsx(pe,{size:"xs",variant:"outline",onClick:y,title:"Colocar el último campo creado en esta columna",children:"Colocar último campo"})})]})]});return c==="rows"?l.jsx(_p,{scope:"rows-column",rowsNodeIdx:n,s:a,r:o,c:i,children:E()}):l.jsx(_p,{scope:"tabs-column",tabKey:d,s:a,r:o,c:i,children:E()})}),Du=({value:e,onChange:t,placeholder:r="Click to edit",className:n,inputClassName:a,autoFocus:o=!1})=>{const[i,c]=C.useState(o),[d,u]=C.useState(e),f=C.useRef(null);C.useEffect(()=>{u(e)},[e]),C.useEffect(()=>{i&&f.current&&(f.current.focus(),f.current.select())},[i]);const h=()=>{c(!1),d.trim()!==e&&t(d)},p=m=>{m.key==="Enter"?(m.preventDefault(),h()):m.key==="Escape"&&(u(e),c(!1))};return i?l.jsx("input",{ref:f,value:d,onChange:m=>u(m.target.value),onBlur:h,onKeyDown:p,placeholder:r,className:ve("bg-transparent border border-transparent focus:border-gray-400 dark:focus:border-gray-500 rounded px-0.5 -ml-0.5 outline-none w-full min-w-[20px] leading-inherit font-inherit text-inherit","focus:ring-2 focus:ring-gray-200 dark:focus:ring-gray-700",a,n),onClick:m=>m.stopPropagation(),onPointerDown:m=>m.stopPropagation(),onMouseDown:m=>m.stopPropagation()}):l.jsxs("span",{onDoubleClick:m=>{m.preventDefault(),m.stopPropagation(),c(!0)},onClick:m=>{m.preventDefault()},className:ve("group cursor-text hover:bg-gray-100 dark:hover:bg-white/5 rounded px-0.5 -mx-0.5 border border-transparent hover:border-dashed hover:border-gray-400 truncate min-w-[20px] inline-flex items-center gap-1",!e&&"text-gray-400 italic",n),title:"Double click to edit",children:[l.jsx("span",{className:"truncate",children:e||r}),l.jsx("span",{role:"button",onClick:m=>{m.stopPropagation(),m.preventDefault(),c(!0)},className:"opacity-0 group-hover:opacity-100 transition-opacity text-gray-400 hover:text-blue-500 cursor-pointer",title:"Edit",children:l.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"w-3 h-3",children:[l.jsx("path",{d:"M5.433 13.917l1.262-3.155A4 4 0 017.58 9.42l6.92-6.918a2.121 2.121 0 013 3l-6.92 6.918c-.383.383-.84.685-1.343.886l-3.154 1.262a.5.5 0 01-.65-.65z"}),l.jsx("path",{d:"M3.5 5.75c0-.69.56-1.25 1.25-1.25H10A.75.75 0 0010 3H4.75A2.75 2.75 0 002 5.75v9.5A2.75 2.75 0 004.75 18h9.5A2.75 2.75 0 0017 15.25V10a.75.75 0 00-1.5 0v5.25c0 .69-.56 1.25-1.25 1.25h-9.5c-.69 0-1.25-.56-1.25-1.25v-9.5z"})]})})]})},JH=e=>e<=1?["w-full"]:e===2?["w-1/2","w-1/2"]:e===3?["w-1/3","w-1/3","w-1/3"]:Array.from({length:e},()=>"flex-1"),YH=[1,2,3,4],XH=C.memo(function({row:t,nodeIdx:r,sIdx:n,rIdx:a,parentType:o,tabKey:i,confirmDelete:c}){const d=se(_=>_.setRowColumns),u=se(_=>_.removeRowFromSection),f=se(_=>_.addRowToSectionAt),h=se(_=>_.setRowTitle),p=se(_=>_.setTabRowColumns),m=se(_=>_.removeTabRow),v=se(_=>_.addRowToTabSectionAt),g=se(_=>_.setTabRowTitle),[b,w]=C.useState(!!t.title),x=t.columns??[],y=x.length===0,E=JH(x.length),k=_=>{o==="rows"?d(r,n,a,_):p(i,n,a,_)},j=()=>{c("Eliminar fila","¿Estás seguro de que quieres eliminar esta fila? Se perderán todos los campos que contiene.",()=>{o==="rows"?u(r,n,a):m(i,n,a)})},A=_=>{o==="rows"?h(r,n,a,_):g(i,n,a,_),_.trim()||w(!1)},S=()=>{w(!0)};return l.jsxs("div",{className:"space-y-0",children:[(b||t.title)&&l.jsx("div",{className:"px-3 py-2 bg-[var(--color-ds-background-elevated)] border-b border-[var(--color-ds-border-default-50)]",children:l.jsx(Du,{value:t.title||"",onChange:A,placeholder:"Título de la fila (opcional)",className:"text-sm font-medium text-[var(--color-ds-text-primary)]"})}),l.jsxs("div",{className:"px-3 py-2 flex items-center gap-1 bg-[var(--color-ds-background)] border-b border-[var(--color-ds-border-default-50)]",children:[l.jsxs("div",{className:"flex items-center gap-2 flex-wrap flex-1 min-w-0",children:[l.jsxs("span",{className:"text-[11px] leading-none uppercase tracking-wide text-[var(--color-ds-text-secondary)]",children:["Fila ",a+1]}),!b&&!t.title&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"h-3 w-px bg-[var(--color-ds-border-default-50)]"}),l.jsx(pe,{size:"xs",variant:"ghost",onClick:S,title:"Añadir título a la fila",icon:Zs,className:"text-[10px] text-[var(--color-ds-text-secondary)]",children:"Título"})]}),l.jsx("div",{className:"h-3 w-px bg-[var(--color-ds-border-default-50)]"}),l.jsx("div",{className:"flex gap-1 flex-wrap",children:YH.map(_=>l.jsx(pe,{size:"xs",variant:"outline",className:"rounded-full px-2 py-0.5",onClick:()=>k(_),title:`${_} columna(s)`,children:_},_))})]}),l.jsx(pe,{size:"xs",variant:"danger",onClick:j,title:"Eliminar fila",shape:"circle",icon:st})]}),y?l.jsx("div",{className:"rounded-md border border-dashed p-6 text-center border-[var(--color-ds-border-default-50)] text-[var(--color-ds-text-secondary)]",children:'No hay columnas. Usa "+ columna".'}):l.jsx("div",{children:x.map((_,O)=>l.jsx(KH,{col:_,widthClass:E[O],nodeIdx:r,sIdx:n,rIdx:a,cIdx:O,parentType:o,tabKey:i,confirmDelete:c},`${o==="rows"?"col":"tcol"}-${r}-${n}-${a}-${O}`))}),l.jsx("div",{className:"flex justify-center p-1 bg-[var(--color-ds-background-surface)] border-t border-[var(--color-ds-border-default-50)]",children:l.jsx(pe,{size:"xs",variant:"ghost",className:"w-full justify-center text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]",onClick:()=>{o==="rows"?f(r,n,a+1):v(i,n,a+1)},title:"Añadir fila debajo",children:"+ Añadir fila debajo"})})]})});function QH({nodeIdx:e,tabKey:t,insertAt:r}){const n={scope:"tab-section",nodeIdx:e,tabKey:t,insertAt:r},{setNodeRef:a,isOver:o}=Sr({id:`tab-section:${e}:${t}:${r}`,data:n});return l.jsx("div",{ref:a,className:["h-2 my-1 w-full rounded-sm transition relative -mx-1 px-1",o?"bg-[var(--color-ds-border-default)]/30 ring-1 ring-[var(--color-ds-border-default)]":"bg-transparent"].join(" "),"aria-label":`Insertar sección de pestaña en posición ${r+1}`})}function eW({nodeIdx:e,tabKey:t,sIdx:r}){const n=`tab-section:${e}:${t}:${r}`,a={kind:"tab-section",nodeIdx:e,tabKey:t,sIdx:r},{attributes:o,listeners:i,setNodeRef:c,isDragging:d}=Jn({id:n,data:a});return l.jsx("div",{ref:c,...o,...i,title:"Arrastrar sección de pestaña","aria-grabbed":d,className:"shrink-0 w-6 h-6 grid place-items-center cursor-grab active:cursor-grabbing rounded text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-muted)]",children:"⇅"})}function Rp({expanded:e,onClick:t,labelExpanded:r,labelCollapsed:n,titleExpanded:a,titleCollapsed:o,className:i=""}){return l.jsx(pe,{size:"xs",variant:"ghost","aria-expanded":e,"aria-label":e?r:n,onClick:t,title:e?a??"Colapsar":o??"Expandir",className:`shrink-0 w-8 h-8 p-0 grid place-items-center ${i}`,children:l.jsx(fr,{className:`w-4 h-4 text-[var(--color-ds-text-primary)] transition-transform duration-150 ${e?"rotate-180":""}`})})}function tW({section:e,onChange:t,formId:r,parentType:n,sectionIndex:a,tabKey:o}){const{translations:i}=Zt(),{t:c}=At(),[d,u]=C.useState("");C.useEffect(()=>{const p=e.sectionTitle,m=p&&(p.startsWith("forms.")||p.startsWith("ds."));if(i&&m){const v=i.getTranslation(p);u(v!==p?v:p)}else u(mt(c,p))},[e.sectionTitle,i,c]);const f=async()=>{const p=e.sectionTitle||"";if(d===(i&&p.startsWith("forms.")?i.getTranslation(p):mt(c,p)))return;if(!i){t(d);return}if((p.startsWith("forms.")||p.startsWith("ds."))&&!p.startsWith("ds."))await i.updateTranslation(p,d);else{const v=r||"defaultForm",g=Date.now().toString(36);let b="";n==="tabs"&&o?b=`forms.${v}.tabs.${o}.sections.s_${g}.title`:b=`forms.${v}.sections.s_${g}.title`,console.log("Generating section key",b,d),await i.updateTranslation(b,d),t(b)}},h=p=>{p.key==="Enter"&&p.currentTarget.blur()};return l.jsx("input",{type:"text",value:d,onChange:p=>u(p.target.value),onBlur:f,onKeyDown:h,className:"bg-transparent font-medium text-[var(--color-ds-text-primary)] placeholder-[var(--color-ds-text-tertiary)] outline-none border-b border-transparent focus:border-[var(--color-ds-border-accent)] transition-colors w-full",placeholder:"Sección sin título"})}const Op=C.memo(function({section:t,nodeIdx:r,sIdx:n,parentType:a,tabKey:o,confirmDelete:i}){const{t:c}=At(),[d,u]=C.useState(!1),f=se(w=>{var x,y;return((x=w.schema)==null?void 0:x.formId)||((y=w.schema)==null?void 0:y.id)}),h=se(w=>w.renameSectionAt),p=se(w=>w.removeSectionAt),m=se(w=>w.removeTabSection),v=se(w=>w.renameTabSection),g=w=>{a==="rows"?h(r,n,w):v(o,n,w)},b=()=>{i("Eliminar sección","¿Estás seguro de que quieres eliminar esta sección? Se perderán todos los campos que contiene.",()=>{a==="tabs"&&o?m(o,n):p(r,n)})};return l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] overflow-hidden",children:[l.jsx("div",{className:"pr-3 bg-[var(--color-ds-background-surface)] border-b border-[var(--color-ds-border-default-50)]",children:l.jsxs("div",{className:"flex items-center gap-2 min-h-9 py-1",children:[l.jsx(Rp,{expanded:!d,onClick:()=>u(!d),labelExpanded:"Colapsar sección",labelCollapsed:"Expandir sección",className:a==="tabs"?"ml-2":""}),l.jsx("div",{className:"flex-1 min-w-0 px-2 font-medium text-[var(--color-ds-text-primary)]",children:l.jsx(tW,{section:t,onChange:g,formId:f,parentType:a,sectionIndex:n,tabKey:o})}),a==="rows"?l.jsx(zH,{nodeIdx:r,sIdx:n}):l.jsx(eW,{nodeIdx:r,tabKey:o,sIdx:n}),l.jsx("div",{className:"flex flex-wrap gap-1 ml-auto",children:l.jsx(pe,{size:"xs",variant:"danger",onClick:b,title:"Eliminar sección",shape:"circle",icon:st})})]})}),!d&&l.jsx("div",{className:"bg-[var(--color-ds-background-page)]",children:t.rows.map((w,x)=>l.jsx(XH,{row:w,nodeIdx:r,sIdx:n,rIdx:x,parentType:a,tabKey:o,confirmDelete:i},`${a==="rows"?"row":"trow"}-${a==="tabs"?o:r}-${x}`))})]})});function Lp({nodeIdx:e,insertAt:t}){const r={scope:"tabs-tab",nodeIdx:e,insertAt:t},{setNodeRef:n,isOver:a}=Sr({id:`tabs-tab:${e}:${t}`,data:r});return l.jsx("div",{ref:n,className:["w-1 h-5 rounded-md transition",a?"bg-[var(--color-ds-border-default)]/30 ring-1 ring-[var(--color-ds-border-default)]":"bg-transparent"].join(" "),title:`Insertar pestaña en posición ${t+1}`})}function rW({className:e=""}){return l.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",className:e,fill:"currentColor",children:[1,5].map(t=>[1,4,7].map((r,n)=>l.jsx("circle",{cx:t,cy:r,r:"1"},`${t}-${r}-${n}`)))})}function nW({nodeIdx:e,index:t,tabKey:r,label:n,onRename:a}){const o=`tabs-tab:${e}:${t}:${r}`,i={kind:"tabs-tab",nodeIdx:e,index:t,tabKey:r},{attributes:c,listeners:d,setNodeRef:u,isDragging:f}=Jn({id:o,data:i});return l.jsxs("div",{ref:u,...c,...d,tabIndex:0,"aria-grabbed":f,"aria-label":`Arrastrar pestaña "${n}"`,title:`Arrastrar pestaña "${n}"`,className:["inline-flex items-center gap-1 select-none","h-6 px-1.5 rounded-full","text-[11px] leading-none","border border-[var(--color-ds-border-default-50)]","bg-[var(--color-ds-background-surface)]","text-[var(--color-ds-text-primary)]","cursor-grab active:cursor-grabbing","hover:bg-[color-mix(in_srgb,var(--color-ds-background-surface)_85%,black_15%)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-ds-border-default)]",f?"opacity-60":"opacity-100","transition-colors"].join(" "),children:[l.jsx(rW,{className:"text-[var(--color-ds-text-primary)]"}),a?l.jsx(Du,{value:n,onChange:a,className:"max-w-[10rem]",inputClassName:"w-20 text-[11px]"}):l.jsx("span",{className:"truncate max-w-[10rem]",children:n})]})}function aW({tab:e,onChange:t,formId:r}){const{translations:n}=Zt(),{t:a}=At(),[o,i]=C.useState("");C.useEffect(()=>{const u=e.label,f=u&&(u.startsWith("forms.")||u.startsWith("ds."));if(n&&f){const h=n.getTranslation(u);i(h!==u?h:u)}else i(mt(a,u))},[e.label,n,a]);const c=async()=>{const u=e.label||"";if(o===(n&&u.startsWith("forms.")?n.getTranslation(u):mt(a,u)))return;if(!n){t(o);return}if((u.startsWith("forms.")||u.startsWith("ds."))&&!u.startsWith("ds."))await n.updateTranslation(u,o);else{const p=`forms.${r||"defaultForm"}.tabs.${e.key}.label`;await n.updateTranslation(p,o),t(p)}},d=u=>{u.key==="Enter"&&u.currentTarget.blur()};return l.jsx("input",{type:"text",value:o,onChange:u=>i(u.target.value),onBlur:c,onKeyDown:d,className:"bg-transparent text-lg font-bold text-[var(--color-ds-text-primary)] placeholder-[var(--color-ds-text-tertiary)] outline-none border-b border-transparent focus:border-[var(--color-ds-border-accent)] transition-colors flex-1 w-auto min-w-[60px]",placeholder:"Pestaña sin título"})}const oW=C.memo(function({node:t,nodeIdx:r,draggedTabSection:n,confirmDelete:a}){var x;const{t:o}=At(),[i,c]=C.useState(!1),[d,u]=C.useState(((x=t.tabs[0])==null?void 0:x.key)??""),f=se(y=>y.removeLayoutNode),h=se(y=>y.renameTab),p=se(y=>y.updateTab),m=se(y=>y.addTabAfter),v=se(y=>y.removeTab),g=se(y=>y.addSectionToTab);se(y=>y.renameTabSection);const b=se(y=>{var E,k;return((E=y.schema)==null?void 0:E.formId)||((k=y.schema)==null?void 0:k.id)}),w=t.tabs.map(y=>{const E=y.icon?Ma(y.icon.name,y.icon.style):null;return{label:mt(o,y.label),value:y.key,disabled:!1,icon:E?l.jsx(E,{className:"w-4 h-4"}):null}});return C.useEffect(()=>{d===""&&t.tabs.length>0&&u(t.tabs[0].key)},[t.tabs,d]),l.jsx("div",{className:"space-y-2",children:l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] overflow-hidden",children:[l.jsx("div",{className:"bg-[var(--color-ds-background-surface)] border-b border-[var(--color-ds-border-default-50)]",children:l.jsxs("div",{className:"flex items-center gap-2 min-h-9 py-1 pr-2",children:[l.jsx(Rp,{expanded:!i,onClick:()=>c(!i),labelExpanded:"Colapsar pestañas",labelCollapsed:"Expandir pestañas"}),l.jsx("span",{className:"text-[11px] leading-none uppercase tracking-wide text-[var(--color-ds-text-secondary)]",children:"Pestañas"}),l.jsx("div",{className:"ml-auto",children:l.jsx(pe,{size:"xs",variant:"danger",onClick:()=>a("Eliminar bloque de pestañas","¿Estás seguro de que quieres eliminar este bloque de pestañas? Se perderá todo su contenido.",()=>f(r)),title:"Eliminar bloque",shape:"circle",icon:st})})]})}),!i&&l.jsxs("div",{className:"bg-[var(--color-ds-background)]",children:[l.jsx("div",{className:"px-3 py-2 border-b border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface-soft)]",children:l.jsxs("span",{className:"text-[10px] uppercase tracking-wider font-medium text-[var(--color-ds-text-tertiary)] flex items-center gap-2",children:["Reordenar pestañas ",l.jsx("span",{className:"text-[var(--color-ds-text-tertiary)]/50 text-[9px] font-normal normal-case",children:"(Arrastrar para ordenar)"})]})}),l.jsx("div",{className:"custom-scroll scrollbar-hidden overflow-x-auto overflow-y-hidden bg-[var(--color-ds-background-surface-soft)]/30 border-b border-[var(--color-ds-border-default-50)]",children:l.jsxs("div",{className:"px-2 py-2 inline-flex items-center gap-1 whitespace-nowrap min-h-[2rem]",role:"list","aria-label":"Reordenar pestañas",children:[l.jsx(Lp,{nodeIdx:r,insertAt:0}),t.tabs.map((y,E)=>l.jsxs(C.Fragment,{children:[l.jsx(nW,{nodeIdx:r,index:E,tabKey:y.key,label:y.label,onRename:k=>h==null?void 0:h(y.key,k)}),l.jsx(Lp,{nodeIdx:r,insertAt:E+1})]},`tabchip-${r}-${y.key}`))]})}),l.jsx("div",{children:l.jsx(zr,{options:w,value:d,onChange:y=>u(y),children:t.tabs.reduce((y,E)=>(y[E.key]=l.jsxs("div",{className:"space-y-3",children:[d===E.key&&l.jsxs("div",{className:"flex flex-wrap items-center justify-between px-3 pt-3 pb-1 mb-1 gap-y-2",children:[l.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-[150px]",children:[l.jsx("div",{className:"flex-shrink-0",children:l.jsx(Un,{value:E.icon,onChange:k=>p==null?void 0:p(E.key,{icon:k})})}),l.jsx(aW,{tab:E,onChange:k=>p==null?void 0:p(E.key,{label:k}),formId:b})]}),l.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0 ml-auto",children:[l.jsxs("button",{onClick:()=>p==null?void 0:p(E.key,{disabled:!E.disabled}),className:`
410
410
  flex items-center gap-1.5 px-2 py-1 rounded-full text-[10px] font-medium transition-colors border
411
411
  ${E.disabled?"bg-red-50 text-red-700 border-red-200 hover:bg-red-100":"bg-[var(--color-ds-background-surface)] text-[var(--color-ds-text-tertiary)] border-[var(--color-ds-border-default-50)] hover:text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default)]"}
412
- `,title:E.disabled?"Click para habilitar":"Click para deshabilitar",children:[E.disabled?l.jsx(vo,{className:"w-3 h-3"}):l.jsx(_1,{className:"w-3 h-3"}),l.jsx("span",{className:E.disabled?"inline":"hidden sm:inline",children:E.disabled?"Deshabilitada":"Habilitada"})]}),l.jsx("div",{className:"h-4 w-px bg-[var(--color-ds-border-default-50)]"}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx(pe,{icon:ga,size:"sm",variant:"primary",shape:"circle",onClick:()=>g==null?void 0:g(E.key,"Nueva sección"),title:"Añadir nueva sección",className:"shadow-sm"}),l.jsx(ko,{align:"right",trigger:l.jsx("div",{className:"p-1.5 rounded-md hover:bg-[var(--color-ds-background-surface-soft)] text-[var(--color-ds-text-secondary)] transition-colors cursor-pointer",children:l.jsx(A1,{className:"w-5 h-5"})}),items:[{label:"Añadir Pestaña",icon:cc,onSelect:()=>m==null?void 0:m(E.key)},{separator:!0},{label:"Eliminar Pestaña",icon:Dt,variant:"danger",disabled:t.tabs.length<=1,onSelect:()=>a("Eliminar pestaña","¿Estás seguro de que quieres eliminar esta pestaña? Se perderá todo su contenido.",()=>v==null?void 0:v(E.key))}]})]})]})]}),Array.from({length:E.sections.length+1}).map((k,j)=>{const A=j,S=E.sections[A],_=(n==null?void 0:n.nodeIdx)===r&&(n==null?void 0:n.tabKey)===E.key&&j===n.sIdx+1;return l.jsxs(C.Fragment,{children:[l.jsx("div",{className:"px-2",children:!_&&l.jsx(QH,{nodeIdx:r,tabKey:E.key,insertAt:j})}),A<E.sections.length&&l.jsx(Op,{section:S,nodeIdx:r,sIdx:A,parentType:"tabs",tabKey:E.key,confirmDelete:a})]},`tsec-${E.key}-${j}`)})]}),y),{})})})]})]})})});function sW(){const e=se(h=>h.schema.layout),t=se(h=>h.editorSettings),[r,n]=C.useState(null),[a,o]=C.useState(null),[i,c]=C.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}});zo({onDragStart:h=>{const{active:p}=h,m=p.data.current;m&&m.kind==="rows-section"&&n(m.sIdx),m&&m.kind==="tab-section"&&o({nodeIdx:m.nodeIdx,tabKey:m.tabKey,sIdx:m.sIdx})},onDragEnd:()=>{n(null),o(null)},onDragCancel:()=>{n(null),o(null)}});const d=C.useCallback((h,p,m)=>{if(!t.confirmDelete){m();return}c({isOpen:!0,title:h,message:p,onConfirm:m})},[t.confirmDelete]),u=()=>{i.onConfirm(),c(h=>({...h,isOpen:!1}))},f=()=>{c(h=>({...h,isOpen:!1}))};return l.jsxs("div",{id:"designer-canvas-root",className:"space-y-3 relative",children:[e.map((h,p)=>{if(h.type==="rows"){const m=h.sections;return l.jsx("div",{className:"space-y-3",children:Array.from({length:m.length+1}).map((v,g)=>{const b=g,w=m[b];return l.jsxs(C.Fragment,{children:[!(r!==null&&g===r+1)&&l.jsx(ZH,{nodeIdx:p,insertAt:g}),b<m.length&&l.jsx(Op,{section:w,nodeIdx:p,sIdx:b,parentType:"rows",confirmDelete:d})]},`rows-slot-sec-${p}-${g}`)})},`rows-${p}`)}return h.type==="tabs"?l.jsx(oW,{node:h,nodeIdx:p,draggedTabSection:a,confirmDelete:d},`tabs-${p}`):null}),l.jsx(Bt,{isOpen:i.isOpen,onClose:f,title:i.title,footer:l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx(pe,{variant:"outline",onClick:f,children:"Cancelar"}),l.jsx(pe,{variant:"danger",onClick:u,children:"Eliminar"})]}),children:l.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:i.message})})]})}const Tp=(e,t,r)=>Math.max(t,Math.min(r,e));function $p(e){const t=[`li:${e.li}`];return e.tabIdx!=null&&t.push(`t:${e.tabIdx}`),t.push(`s:${e.sectionIdx}`,`r:${e.rowIdx}`,`c:${e.colIdx}`,`f:${e.fieldIdx}`),t.join("|")}function ss(e){const t=Object.fromEntries(e.split("|").map(r=>r.split(":")));return{li:Number(t.li),tabIdx:t.t!=null?Number(t.t):void 0,sectionIdx:Number(t.s),rowIdx:Number(t.r),colIdx:Number(t.c),fieldIdx:Number(t.f)}}function Ip(e,t){var n,a,o,i,c,d,u;const r=e[t.li];if(!r)return null;if(r.type==="rows"){const f=(n=r.sections)==null?void 0:n[t.sectionIdx],h=(a=f==null?void 0:f.rows)==null?void 0:a[t.rowIdx];return((o=h==null?void 0:h.columns)==null?void 0:o[t.colIdx])??null}if(r.type==="tabs"){const f=(i=r.tabs)==null?void 0:i[t.tabIdx??0],h=(c=f==null?void 0:f.sections)==null?void 0:c[t.sectionIdx],p=(d=h==null?void 0:h.rows)==null?void 0:d[t.rowIdx];return((u=p==null?void 0:p.columns)==null?void 0:u[t.colIdx])??null}return null}function iW(e,t,r){if(t.li===r.li&&(t.tabIdx??-1)===(r.tabIdx??-1)&&t.sectionIdx===r.sectionIdx&&t.rowIdx===r.rowIdx&&t.colIdx===r.colIdx&&t.fieldIdx===r.fieldIdx)return e;const n=JSON.parse(JSON.stringify(e.layout)),a=Ip(n,{li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx}),o=Ip(n,{li:r.li,tabIdx:r.tabIdx,sectionIdx:r.sectionIdx,rowIdx:r.rowIdx,colIdx:r.colIdx});if(!a||!Array.isArray(a.fields)||!o||!Array.isArray(o.fields))return e;const i=[...a.fields];if(t.fieldIdx<0||t.fieldIdx>=i.length)return e;const[c]=i.splice(t.fieldIdx,1);a.fields=i;const d=[...o.fields],u=Tp(r.fieldIdx??d.length,0,d.length);return d.splice(u,0,c),o.fields=d,{...e,layout:n}}function lW(e,t){const r=JSON.parse(JSON.stringify(e.layout)),a=(d=>{var f,h,p,m,v,g,b,w,x,y,E,k;const u=r[d.li];return u?u.type==="rows"?((v=(m=(p=(h=(f=u.sections)==null?void 0:f[d.sectionIdx])==null?void 0:h.rows)==null?void 0:p[d.rowIdx])==null?void 0:m.columns)==null?void 0:v[d.colIdx])??null:u.type==="tabs"?((k=(E=(y=(x=(w=(b=(g=u.tabs)==null?void 0:g[d.tabIdx??0])==null?void 0:b.sections)==null?void 0:w[d.sectionIdx])==null?void 0:x.rows)==null?void 0:y[d.rowIdx])==null?void 0:E.columns)==null?void 0:k[d.colIdx])??null:null:null})({li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx});if(!a||!Array.isArray(a.fields))return e;const o=[...a.fields];if(t.fieldIdx<0||t.fieldIdx>=o.length)return e;const[i]=o.splice(t.fieldIdx,1);a.fields=o;const c=[...e.fields||[]];if(i){let d=0;const u=f=>{Array.isArray(f)&&f.includes(i)&&d++};if(r.forEach(f=>{var h,p;f.type==="rows"?(h=f.sections)==null||h.forEach(m=>{var v;return(v=m.rows)==null?void 0:v.forEach(g=>{var b;return(b=g.columns)==null?void 0:b.forEach(w=>u(w.fields))})}):f.type==="tabs"&&((p=f.tabs)==null||p.forEach(m=>{var v;return(v=m.sections)==null?void 0:v.forEach(g=>{var b;return(b=g.rows)==null?void 0:b.forEach(w=>{var x;return(x=w.columns)==null?void 0:x.forEach(y=>u(y.fields))})})}))}),d===0){const f=c.findIndex(h=>h.name===i);f!==-1&&c.splice(f,1)}}return{...e,layout:r,fields:c}}function cW(e,t){const r=new Set(e.map(o=>o.name));let n=1,a=`${t}_${n}`;for(;r.has(a);)n++,a=`${t}_${n}`;return a}function dW(e,t,r){const n=cW(e.fields||[],t.type||"field"),a={...t,name:n},o=[...e.fields||[],a],i=JSON.parse(JSON.stringify(e.layout)),d=(f=>{var p,m,v,g,b,w,x,y,E,k,j,A;const h=i[f.li];return h?h.type==="rows"?((b=(g=(v=(m=(p=h.sections)==null?void 0:p[f.sectionIdx])==null?void 0:m.rows)==null?void 0:v[f.rowIdx])==null?void 0:g.columns)==null?void 0:b[f.colIdx])??null:h.type==="tabs"?((A=(j=(k=(E=(y=(x=(w=h.tabs)==null?void 0:w[f.tabIdx??0])==null?void 0:x.sections)==null?void 0:y[f.sectionIdx])==null?void 0:E.rows)==null?void 0:k[f.rowIdx])==null?void 0:j.columns)==null?void 0:A[f.colIdx])??null:null:null})({li:r.li,tabIdx:r.tabIdx,sectionIdx:r.sectionIdx,rowIdx:r.rowIdx,colIdx:r.colIdx});if(!d)return{...e,fields:o};Array.isArray(d.fields)||(d.fields=[]);const u=Tp(r.fieldIdx??d.fields.length,0,d.fields.length);return d.fields.splice(u,0,n),{...e,fields:o,layout:i}}const Bp=C.createContext(null),Pp=()=>{const e=C.useContext(Bp);if(!e)throw new Error("useRelations must be used inside <RelationsProvider>");return e},uW=e=>{const{registerFieldEl:t}=Pp();return C.useCallback(r=>{e&&t(e,r)},[e,t])},fW=({children:e})=>{const[t,r]=C.useState(!1),[n,a]=C.useState(null),[o,i]=C.useState({}),c=C.useRef({}),d=m=>r(v=>typeof m=="boolean"?m:!v),u=C.useCallback((m,v)=>{c.current[m]=v},[]);C.useEffect(()=>{let m=!0,v;const b=(async()=>{try{const{useEditorStore:w}=await Promise.resolve().then(()=>tB),y=w.getState().showRelations??!1;return v=y,m&&r(y),w.subscribe(k=>{const j=k.showRelations??!1;m&&j!==v&&(v=j,r(j))})}catch(w){return console.error("Failed to sync with store:",w),()=>{}}})();return()=>{m=!1,b.then(w=>w())}},[]);const f=C.useRef(null),h=C.useRef({});C.useEffect(()=>{if(!t)return;const m=()=>{const x=f.current;if(!x)return;const y=x.getBoundingClientRect(),E={};for(const[S,_]of Object.entries(c.current)){if(!_)continue;const O=_.getBoundingClientRect();E[S]={x:Math.round(O.left-y.left+O.width/2),y:Math.round(O.top-y.top+O.height/2),w:Math.round(O.width),h:Math.round(O.height)}}const k=h.current;let j=!1;const A=new Set([...Object.keys(E),...Object.keys(k)]);for(const S of A){const _=E[S],O=k[S];if(!_||!O||_.x!==O.x||_.y!==O.y||_.w!==O.w||_.h!==O.h){j=!0;break}}j&&(h.current=E,i(E))},v=()=>requestAnimationFrame(m),g=new ResizeObserver(v);f.current&&g.observe(f.current);const b=new MutationObserver(v);f.current&&b.observe(f.current,{childList:!0,subtree:!0}),window.addEventListener("resize",v,{passive:!0}),document.addEventListener("scroll",v,{passive:!0,capture:!0});const w=new ResizeObserver(v);return Object.values(c.current).forEach(x=>x&&w.observe(x)),v(),()=>{g.disconnect(),b.disconnect(),w.disconnect(),window.removeEventListener("resize",v),document.removeEventListener("scroll",v,{capture:!0})}},[t]);const p=C.useMemo(()=>({enabled:t,toggle:d,registerFieldEl:u,anchors:o,schema:n,setSchema:a}),[t,u,o,n]);return l.jsx(Bp.Provider,{value:p,children:l.jsx("div",{ref:f,className:"relative",children:e})})};function ll(e){return e?e.op==="and"||e.op==="or"?(e.rules??[]).flatMap(ll):e.op==="always"?[]:[e.field]:[]}function Su(e){return e!=null&&e.parameters?Object.values(e.parameters).filter(t=>t.type==="field"&&t.fieldRef).map(t=>t.fieldRef):[]}function hW(e){var a,o,i,c,d,u;const t=[];for(const f of e.fields){const h=f.name;if(!h)continue;const p=(a=f.visibleWhen)==null?void 0:a.rule,m=(o=f.disabledWhen)==null?void 0:o.rule,v=(i=f.clearWhen)==null?void 0:i.rule;for(const x of ll(p))t.push({from:x,to:h,kind:"visibleWhen"});for(const x of ll(m))t.push({from:x,to:h,kind:"disabledWhen"});for(const x of ll(v))t.push({from:x,to:h,kind:"clearWhen"});const g=(c=f.visibleWhen)==null?void 0:c.endpoint,b=(d=f.disabledWhen)==null?void 0:d.endpoint,w=(u=f.clearWhen)==null?void 0:u.endpoint;for(const x of Su(g))t.push({from:x,to:h,kind:"visibleWhen"});for(const x of Su(b))t.push({from:x,to:h,kind:"disabledWhen"});for(const x of Su(w))t.push({from:x,to:h,kind:"clearWhen"})}const r=f=>`${f.from}->${f.to}:${f.kind}`,n=new Set;return t.filter(f=>n.has(r(f))?!1:(n.add(r(f)),!0))}const Au={visibleWhen:"var(--color-success-500, #22c55e)",disabledWhen:"var(--color-warning-500, #f59e0b)",clearWhen:"var(--color-info-500, #0ea5e9)"};function Vp(e){return{left:e.x-e.w/2,right:e.x+e.w/2,top:e.y-e.h/2,bottom:e.y+e.h/2,cx:e.x,cy:e.y,w:e.w,h:e.h}}function Zp(e,t,r=20,n=0){const a=Vp(e),o=Vp(t),i=1,c=1,d=o.cx-a.cx,u=o.cy-a.cy,h=Math.min(a.bottom,o.bottom)-Math.max(a.top,o.top)>0||Math.abs(d)>Math.abs(u);let p,m,v=[];if(h)if(d>0?(p={x:a.right+i,y:a.cy},m={x:o.left-c,y:o.cy}):(p={x:a.left-i,y:a.cy},m={x:o.right+c,y:o.cy}),Math.abs(p.y-m.y)<5)v=[p,m];else{const w=(p.x+m.x)/2;if(d>0&&p.x>m.x||d<0&&p.x<m.x){const x=Math.max(a.bottom,o.bottom)+r;v=[p,{x:p.x+(d>0?10:-10),y:p.y},{x:p.x+(d>0?10:-10),y:x},{x:m.x-(d>0?10:-10),y:x},{x:m.x-(d>0?10:-10),y:m.y},m]}else v=[p,{x:w,y:p.y},{x:w,y:m.y},m]}else if(u>0?(p={x:a.cx,y:a.bottom+i},m={x:o.cx,y:o.top-c}):(p={x:a.right+i,y:a.cy},m={x:o.right+c,y:o.cy}),u>0&&Math.abs(p.x-m.x)<5)v=[p,m];else if(u>0){const w=(p.y+m.y)/2;v=[p,{x:p.x,y:w},{x:m.x,y:w},m]}else{const w=Math.max(a.right,o.right)+r;v=[p,{x:w,y:p.y},{x:w,y:m.y},m]}n!==0&&(v=v.map(w=>h?{x:w.x,y:w.y+n}:{x:w.x+n,y:w.y}));let g=`M ${v[0].x},${v[0].y}`;for(let w=1;w<v.length;w++)g+=` L ${v[w].x},${v[w].y}`;let b={x:0,y:0};if(v.length===2)b={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2};else{const w=Math.floor((v.length-1)/2),x=v[w],y=v[w+1];b={x:(x.x+y.x)/2,y:(x.y+y.y)/2}}return{d:g,label:b}}const pW=({enabled:e=!0,anchors:t,schema:r})=>{const n=C.useMemo(()=>r?hW(r):[],[r]),[a,o]=C.useState(null),i=se(f=>f.setSelection),c=se(f=>f.selection),d=(c==null?void 0:c.kind)==="field"?c.name:null,u=C.useMemo(()=>{const f=new Map;return n.forEach(h=>{const p=`${h.from}->${h.to}`;f.has(p)||f.set(p,[]),f.get(p).push(h)}),Array.from(f.entries())},[n]);return!e||!r||n.length===0?null:l.jsxs("svg",{className:"pointer-events-none absolute inset-0 z-50",width:"100%",height:"100%",children:[l.jsxs("defs",{children:[l.jsx("marker",{id:"arrow-head-visibleWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:l.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-success-500, #22c55e)"})}),l.jsx("marker",{id:"arrow-head-disabledWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:l.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-warning-500, #f59e0b)"})}),l.jsx("marker",{id:"arrow-head-clearWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:l.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-info-500, #0ea5e9)"})}),l.jsx("marker",{id:"circle-start-visibleWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:l.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-success-500, #22c55e)"})}),l.jsx("marker",{id:"circle-start-disabledWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:l.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-warning-500, #f59e0b)"})}),l.jsx("marker",{id:"circle-start-clearWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:l.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-info-500, #0ea5e9)"})})]}),u.map(([f,h])=>{const p=h[0],m=t[p.from],v=t[p.to];if(!m||!v)return null;const g=`${f}`,b=a===g,w=!!d&&h.some(I=>I.from===d||I.to===d),x=h[0].kind,y=Au[x];let E=1;b?E=1:a?E=w?.4:.15:d&&(E=w?1:.2);const k=Zp(m,v),{label:j}=k,A=h.length>1?h.map(I=>{const F=I.kind.replace("When","");return F.charAt(0).toUpperCase()+F.slice(1)}).join(" + "):p.kind,S=Math.max(80,A.length*6+20),_=()=>{i({kind:"field",name:p.to})},O=h.length,B=3,R=h.map((I,F)=>(F-(O-1)/2)*B);return l.jsxs("g",{style:{opacity:E,transition:"opacity 0.2s"},onMouseEnter:()=>o(g),onMouseLeave:()=>o(null),onClick:_,className:"pointer-events-auto cursor-pointer",children:[h.map((I,F)=>{const Z=Au[I.kind],{d:ee}=Zp(m,v,20,R[F]),Y=!!d&&(I.from===d||I.to===d),te=b||Y?1.75:1,ae=`url(#arrow-head-${I.kind})`,q=`url(#circle-start-${I.kind})`;return l.jsxs("g",{children:[l.jsx("path",{d:ee,stroke:"transparent",strokeWidth:18,fill:"none"}),l.jsx("path",{d:ee,stroke:Z,strokeWidth:te,fill:"none",markerEnd:ae,markerStart:q,strokeLinejoin:"round",strokeDasharray:I.kind==="disabledWhen"?"5 5":void 0})]},`${g}-${I.kind}-${F}`)}),l.jsxs("g",{transform:`translate(${j.x}, ${j.y})`,children:[l.jsx("rect",{x:-S/2,y:-10,width:S,height:20,rx:4,ry:4,fill:"var(--color-ds-background-page, #f8fafc)",stroke:y,strokeWidth:1,className:"shadow-sm"}),l.jsx("text",{x:0,y:4,textAnchor:"middle",fontSize:10,fontWeight:600,fill:"var(--color-ds-text-primary, #0f172a)",style:{pointerEvents:"none"},children:A}),h.length>1&&l.jsx("g",{transform:"translate(0, 15)",children:h.map((I,F)=>{const Z=Au[I.kind],ee=(F-(h.length-1)/2)*20;return l.jsx("circle",{cx:ee,cy:0,r:3,fill:Z,stroke:"white",strokeWidth:1},F)})})]})]},g)})]})};function zp(e,t){if(!e||!t)return;const r=t==="outline"?ba:Da;let n=r==null?void 0:r[e];return!n&&(r!=null&&r.default)&&(n=r.default[e]),n||console.warn(`[IconResolver] Icon "${e}" (${t}) no encontrado en @heroicons/react/24/${t}. Revisa tu versión o el nombre. Exports disponibles (outline):`,Object.keys(t==="outline"?ba:Da)),console.log(n),n||void 0}function Kr(e){if(!(!e||typeof e!="object"))return console.log(zp(e.name,e.style)),zp(e.name,e.style)}function mW(e){const{fields:t,fieldsByName:r,control:n,errors:a,isSubmitting:o,loadingDefaults:i,asyncOptionsMap:c,adapterOptionsMap:d,evalContainer:u,disabledMap:f,registry:h,methods:p,translateFn:m,onUpdateField:v,isDesignMode:g,systemContext:b={}}=e,w=()=>se.getState().fieldPick,x=E=>se.getState().completeFieldPick(E),y=(E,k)=>{if(!k)return E;const j=w(),A=j.armed,S=A&&j.forField===k,_=A&&!S,O=I=>{A&&(I.preventDefault(),I.stopPropagation(),!S&&x(k))},B=I=>{A&&_&&(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),I.stopPropagation(),x(k))},R=A?S?"opacity-40 cursor-not-allowed":"cursor-pointer transition-all rounded border border-[color-mix(in_srgb,var(--color-ds-border-default)_40%,transparent)] hover:border-[color-mix(in_srgb,var(--color-ds-border-default)_70%,transparent)] hover:bg-[color-mix(in_srgb,var(--color-ds-background-accent)_5%,transparent)]":"";return l.jsx("div",{onClick:O,onKeyDown:B,tabIndex:_?0:-1,className:R,role:_?"button":void 0,"aria-label":_?`Seleccionar campo ${k}`:void 0,children:E})};return function E(k){var ee,Y,te,ae,q;let j;if(typeof k=="string"){if(j=r[k],j||(j=(t??[]).find(N=>(N==null?void 0:N.name)===k)),!j)return null}else j=k;j.visibleWhen;let A=!!j.disabled;const S=j.disabledWhen,_=u(S,!1);S!=null&&S.enabled&&(A=_),!(S!=null&&S.enabled)&&"name"in j&&j.name&&f[j.name]&&(A=!0);const O=j==null?void 0:j.name;if(j.type==="search"){const N=typeof j.searchFn=="function",L=li(j.searchSource,j.endpointConfig),ne=async he=>{if(N)return j.searchFn(he,{getValues:p.getValues,watch:p.watch});if(L){const ie=j.endpointConfig?bn(j.endpointConfig.parameters,p.getValues,b):{},me=h==null?void 0:h[L];if(typeof me=="function")return await me(he,{getValues:p.getValues,watch:p.watch,params:ie,...b});if(Array.isArray(me))return me}return[]},K={};j.searchMode&&(K.searchMode=j.searchMode),j.minChars&&(K.minChars=j.minChars),j.debounceMs&&(K.debounceMs=j.debounceMs),j.resolveByValue&&(K.resolveByValue=j.resolveByValue);const Q=l.jsx(fd,{name:j.name,control:n,searchFn:ne,label:m(j.label),size:j.size,width:j.width,disabled:A||o,...K},j.name);return y(Q,O)}if(j.type==="inputGroup"){const N=j,L=(N.inputs??[]).map(K=>{var le;const Q=typeof K=="string"?r[K]??(t??[]).find(be=>(be==null?void 0:be.name)===K):K;if(!Q)return null;const he=Q.disabledWhen;let ie=!!Q.disabled;const me=u(he,!1);he!=null&&he.enabled&&(ie=me),!(he!=null&&he.enabled)&&f[Q.name]&&(ie=!0);const ce={name:Q.name,control:n,label:m(Q.label),size:Q.size,width:Q.width,placeholder:m(Q.placeholder),hasError:!!a[Q.name],errorMessage:m((le=a[Q.name])==null?void 0:le.message),loading:!1,disabled:ie||o,suffixButton:Q.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:Kr(Q.labelPrefixIcon),labelSuffixIcon:Kr(Q.labelSuffixIcon),prefixIcon:Kr(Q.prefixIcon),suffixIcon:Kr(Q.suffixIcon)};return Q.type==="select"?{...ce,options:Q.options??d[Q.name]??c[Q.name]??[],loadOptions:Q.options||Q.optionSource||Q.endpointConfig?void 0:Q.loadOptions}:{...ce,type:Q.type}}).filter(Boolean),ne=l.jsx(dd,{groupLabel:m(N.groupLabel),inputs:L,separator:N.separator,useSeparator:N.useSeparator,className:N.className,showVisibleLabel:N.showVisibleLabel,size:N.size},`inputGroup_${N.name??N.groupLabel??"group"}`);return y(ne,N.name)}if(j.type==="button"){const N=j,L=N.icon,ne=L&&typeof L=="object"&&L.name&&L.style?Kr(L):void 0,K=l.jsx("div",{className:"self-center",children:l.jsx(pe,{type:"button",variant:N.variant,size:N.size,width:N.width,icon:ne,iconPosition:N.iconPosition,ariaLabel:m(N.ariaLabel),onClick:N.onClick,disabled:A||o,children:m(N.label)})},N.name);return y(K,O)}const B=j.suffixButton,R=typeof B=="string"?E(B):B,I=m(j.label),F=g&&v&&j.name?l.jsx(Du,{value:I,onChange:N=>{const L=se.getState().schema.formId||"defaultForm",ne=j.name,K=`forms.${L}.fields.${ne}.label`;Mo.updateTranslation(K,N),v(ne,{label:K})},placeholder:"Sin etiqueta",className:"font-medium"}):I,Z={name:j.name,control:n,disabled:A||o,label:F,size:j.size,width:j.width,placeholder:m(j.placeholder),info:(()=>{const N=j.info;return N&&typeof N=="object"&&(N.type==="complex"||"header"in N||"template"in N)?N.template?m(N.template):"":m(N)})(),infoHeader:(()=>{const N=j.info;if(N&&typeof N=="object"&&(N.type==="complex"||"header"in N||"template"in N))return N.header||void 0})(),suffixButton:R,labelPrefixIcon:Kr(j.labelPrefixIcon),labelSuffixIcon:Kr(j.labelSuffixIcon),prefixIcon:Kr(j.prefixIcon),suffixIcon:Kr(j.suffixIcon)};switch(j.type){case"select":{const N=j.name,L=j.options??d[N]??c[N]??[],ne=!j.options&&!j.optionSource&&!j.endpointConfig&&j.loadOptions,K=l.jsx(Et,{name:N,control:n,render:({field:Q})=>{var he;return l.jsx(Xe,{...Z,value:Q.value,onChange:Q.onChange,options:L,onBlur:Q.onBlur,loadOptions:ne||void 0,hasError:!!a[N],errorMessage:m((he=a[N])==null?void 0:he.message),suffixButton:R,mode:"menu",searchable:!0,searchPlaceholder:m("common.search"),noOptionsText:m("common.noMatches")})}},`${N}`);return y(K,O)}case"iban":{const N=j.name;return y(l.jsx(Et,{name:N,control:n,render:({field:ne,fieldState:K})=>{var Q;return l.jsx(Ci,{...Z,value:ne.value??"",onChange:ne.onChange,onBlur:ne.onBlur,hasError:!!a[N],error:m((Q=a[N])==null?void 0:Q.message),reserveErrorSpace:!0})}},N),O)}case"dni":{const N=j.name;return y(l.jsx(Et,{name:N,control:n,render:({field:ne,fieldState:K})=>{var Q;return l.jsx(pd,{...Z,value:ne.value??"",onChange:ne.onChange,onBlur:ne.onBlur,hasError:!!a[N],error:m((Q=a[N])==null?void 0:Q.message),reserveErrorSpace:!0})}},N),O)}case"textarea":{const N=l.jsx(Et,{name:j.name,control:n,render:({field:L,fieldState:ne})=>{var K;return l.jsx(Dr,{...Z,value:L.value,onChange:L.onChange,onBlur:L.onBlur,maxLength:j.maxLength,showCounter:!!j.showCounter,hasError:!!a[j.name],errorMessage:m((K=a[j.name])==null?void 0:K.message)})}},j.name);return y(N,O)}case"file":{const N=l.jsx(Yc,{...Z,defaultValue:[],maxFiles:j.maxFiles,accept:j.accept,hideDropZone:j.hideDropZone,hasError:!!a[j.name],errorMessage:m((ee=a[j.name])==null?void 0:ee.message)},j.name);return y(N,O)}case"checkbox":{const N=l.jsx(it,{...Z,defaultValue:!1,hasError:!!a[j.name],errorMessage:m((Y=a[j.name])==null?void 0:Y.message),name:j.name},j.name);return y(N,O)}case"date":{const N=l.jsx(Sa,{...Z,defaultValue:"",showTime:!!j.showTime,hasError:!!a[j.name],errorMessage:m((te=a[j.name])==null?void 0:te.message)},j.name);return y(N,O)}case"optionGroup":{const N=l.jsx(ki,{...Z,options:j.options||[],multiple:j.multiple,vertical:j.vertical,groupLabel:j.groupLabel,defaultValue:j.defaultValue,className:j.width?void 0:"w-full",name:j.name},j.name);return y(N,O)}case"toggle":{const N=l.jsx(vd,{...Z,checked:j.defaultValue??!1,errorMessage:m((ae=a[j.name])==null?void 0:ae.message),name:j.name},j.name);return y(N,O)}case"table":{const N=j.columns??[],L=j.endpointConfig;let ne;L&&(ne=async()=>{const Q=L.key;if(!Q)return[];const he=bn(L.parameters,p.getValues,b),ie=h==null?void 0:h[Q];return typeof ie=="function"?await ie(he):(console.warn(`Provider factory for key "${Q}" not found in registry.`),[])});const K=l.jsx(ef,{columns:N,loadData:ne,idAccessor:j.idAccessor||"id",className:j.className},j.name);return y(K,O)}default:{const N=l.jsx(ii,{...Z,type:j.type,loadingDefaults:i,hasError:!!a[j.name],errorMessage:m((q=a[j.name])==null?void 0:q.message),suffixButton:R,name:j.name},j.name);return y(N,O)}}}}function gW(e){var r;return e?!!((r=e.closest)!=null&&r.call(e,'button,[role="button"],a[href],input,select,textarea,[contenteditable="true"],[data-interactive="true"]')):!1}function vW(e){var r;return e?!!((r=e.closest)!=null&&r.call(e,'[data-input-group-root],[data-input-group],[data-role="input-group"],.input-group,.InputGroup')):!1}function is(e){var t;e.preventDefault(),e.stopPropagation(),(t=e.nativeEvent)!=null&&t.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()}function bW({id:e,children:t,onDelete:r,fieldName:n,chromeDisabled:a=!1}){const{attributes:o,listeners:i,setNodeRef:c,transform:d,transition:u,isDragging:f}=Gh({id:e,disabled:a}),h=se(b=>b.setSelection),p={transform:Wr.Transform.toString(d),transition:u},m="opacity-0 scale-95 group-hover:opacity-100 group-hover:scale-100 group-focus-within:opacity-100 group-focus-within:scale-100",v=b=>{const w=b.target;gW(w)||vW(w)||n&&(b.stopPropagation(),h({kind:"field",name:n}))},g=b=>{is(b)};return l.jsxs("div",{ref:c,style:p,className:["relative",a?"":"group",f?"z-30":"z-0"].filter(Boolean).join(" "),onClickCapture:v,onDoubleClick:g,onDoubleClickCapture:g,children:[!a&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:["pointer-events-none absolute -inset-0.5 rounded-lg","bg-[var(--color-ds-background-surface)]/80","border border-dashed border-[var(--color-ds-border-default-50)]","transition-all duration-150 ease-out",m,f?"opacity-100 scale-100":""].join(" ")}),l.jsxs("div",{className:["pointer-events-none absolute -top-3 right-2 flex gap-1 z-40","transition-all duration-150 ease-out",m,f?"opacity-100 scale-100":""].join(" "),children:[r&&l.jsx("button",{type:"button","aria-label":"Eliminar campo",className:["pointer-events-auto inline-flex items-center justify-center","w-7 h-7 rounded-full","bg-[var(--color-ds-background-surface)]","border border-[var(--color-ds-border-default-50)]","text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-danger)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-ds-border-default-50)]","transition-colors"].join(" "),onClick:b=>{b.preventDefault(),b.stopPropagation(),r==null||r(e)},onDoubleClick:is,onDoubleClickCapture:is,children:l.jsx(Dt,{className:"w-4 h-4"})}),l.jsx("button",{type:"button","aria-label":"Mover campo","data-drag-handle":!0,className:["pointer-events-auto inline-flex items-center justify-center","w-8 h-8 rounded-full cursor-grab active:cursor-grabbing touch-none","bg-[var(--color-ds-background-surface)]","border border-[var(--color-ds-border-default-50)]","text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-ds-border-default-50)]","transition-colors"].join(" "),...o,...i,onDoubleClick:is,onDoubleClickCapture:is,children:l.jsx(Hl,{className:"w-4 h-4"})})]})]}),l.jsx("div",{className:"relative z-10",children:t})]})}function wW(e,t){if(!t||t.kind!=="row-in-section"&&t.kind!=="row-in-tab-section")return!1;const r=n=>e.insertAt===n||e.insertAt===n+1;if(e.scope==="row-slot"){if(t.kind==="row-in-section"&&t.li===e.li&&t.sIdx===e.sIdx&&r(t.rIdx))return!0}else if(e.scope==="tab-row-slot"&&t.kind==="row-in-tab-section"&&t.li===e.li&&t.tabKey===e.tabKey&&t.sIdx===e.sIdx&&r(t.rIdx))return!0;return!1}function cl(e){const t=e.scope==="row-slot"?{scope:"row-slot",li:e.li,sIdx:e.sIdx,insertAt:e.insertAt}:{scope:"tab-row-slot",li:e.li,tabKey:e.tabKey,sIdx:e.sIdx,insertAt:e.insertAt},r=e.scope==="row-slot"?`row-slot|li:${e.li}|s:${e.sIdx}|i:${e.insertAt}`:`tab-row-slot|li:${e.li}|t:${e.tabKey}|s:${e.sIdx}|i:${e.insertAt}`,{setNodeRef:n,isOver:a}=Sr({id:r,data:t}),[o,i]=C.useState(void 0);return zo({onDragStart:u=>{i(u.active.data.current)},onDragEnd:()=>i(void 0),onDragCancel:()=>i(void 0)}),wW(e,o)?l.jsx("div",{ref:n,style:{display:"none"}}):l.jsx("div",{className:"w-full relative transition-all duration-200 ease-in-out",style:{height:a?60:0,pointerEvents:"none",zIndex:a?10:0},children:l.jsx("div",{ref:n,className:"absolute left-0 right-0",style:{top:a?0:-12,height:a?"100%":24,zIndex:a?10:2,pointerEvents:"auto"},children:a&&l.jsx("div",{className:"w-full h-full rounded-md border border-dashed border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background)]/60 relative",style:{boxShadow:"inset 0 0 0 1px color-mix(in srgb, var(--color-ds-border-default-50) 30%, transparent)"},children:l.jsx("div",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[11px] leading-none",style:{background:"var(--color-ds-background-elevated)",color:"var(--color-ds-text-secondary)",border:"1px solid var(--color-ds-border-default-50)"},children:"Soltar fila aquí"})})})})}function Hp(e){const t=e.kind==="row-in-section"?{kind:"row-in-section",li:e.li,sIdx:e.sIdx,rIdx:e.rIdx}:{kind:"row-in-tab-section",li:e.li,tabKey:e.tabKey,sIdx:e.sIdx,rIdx:e.rIdx},r=e.kind==="row-in-section"?`row|li:${e.li}|s:${e.sIdx}|r:${e.rIdx}`:`tab-row|li:${e.li}|t:${e.tabKey}|s:${e.sIdx}|r:${e.rIdx}`,{attributes:n,listeners:a,setNodeRef:o,isDragging:i}=Jn({id:r,data:t});return l.jsx("div",{ref:o,"aria-label":"Handle de arrastre de fila",style:{position:"absolute",left:"50%",top:-14,transform:"translateX(-50%)",zIndex:2147483647,pointerEvents:e.visible?"auto":"none",opacity:e.visible?1:0,transition:"opacity .12s ease"},...a,...n,children:l.jsx("div",{className:"flex items-center justify-center bg-[var(--color-ds-background-elevated)]/85 backdrop-blur-sm px-1 py-0.5 rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm",children:l.jsx("div",{title:"Mover fila (arrastrar)",className:"flex items-center justify-center rounded hover:bg-[var(--color-ds-background-muted)] transition-colors",style:{cursor:i?"grabbing":"grab",touchAction:"none",padding:"2px 6px"},children:l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",className:"w-4 h-4 text-[var(--color-ds-text-secondary)]",children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 9h16.5m-16.5 6.75h16.5"})})})})})}function xW(e){const r={text:()=>({label:"ds.fields.defaults.text.label",type:"text",width:"w-full",placeholder:"ds.fields.defaults.text.placeholder",size:"sm"}),number:()=>({label:"ds.fields.defaults.number.label",type:"number",width:"w-full",placeholder:"ds.fields.defaults.number.placeholder",size:"sm",validation:{required:!1}}),email:()=>({label:"ds.fields.defaults.email.label",type:"email",width:"w-full",placeholder:"ds.fields.defaults.email.placeholder",size:"sm"}),password:()=>({label:"ds.fields.defaults.password.label",type:"password",width:"w-full",placeholder:"ds.fields.defaults.password.placeholder",size:"sm",validation:{minLength:8}}),tel:()=>({label:"ds.fields.defaults.tel.label",type:"tel",width:"w-full",placeholder:"ds.fields.defaults.tel.placeholder",size:"sm"}),url:()=>({label:"ds.fields.defaults.url.label",type:"url",width:"w-full",placeholder:"ds.fields.defaults.url.placeholder",size:"sm"}),select:()=>({label:"ds.fields.defaults.select.label",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}),checkbox:()=>({label:"ds.fields.defaults.checkbox.label",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}),textarea:()=>({label:"ds.fields.defaults.textarea.label",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"ds.fields.defaults.textarea.placeholder"}),date:()=>({label:"ds.fields.defaults.date.label",type:"date",width:"w-full",size:"sm",showTime:!1}),file:()=>({label:"ds.fields.defaults.file.label",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}),inputGroup:()=>({label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}),search:()=>({label:"ds.fields.defaults.search.label",type:"search",width:"w-full",placeholder:"ds.fields.defaults.search.placeholder",size:"sm",searchMode:"button"}),optionGroup:()=>({label:"Selecciona opciones",type:"optionGroup",width:"w-full",size:"sm",multiple:!0,vertical:!0,options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}]}),array:()=>({label:"Lista repetible",type:"array",width:"w-full",items:[]}),button:()=>({label:"Botón",type:"button",width:"w-auto",variant:"primary",size:"sm"}),iban:()=>({label:"ds.fields.defaults.iban.label",type:"iban",width:"w-full",placeholder:"ds.fields.defaults.iban.placeholder",size:"sm",validation:{required:!1}}),table:()=>({label:"Tabla de Datos",type:"table",width:"w-full",size:"sm",columns:[{header:"ID",accessor:"id",width:"w-16"},{header:"Nombre",accessor:"name",width:"w-auto"}]})}[e];return r?r():{type:e}}function yW(e){return typeof e=="function"}function ls(e,t){if(!e||!t)return null;const r=t==="outline"?ba:Da,n=r==null?void 0:r[e];return yW(n)?n:null}function Nu(e){var c,d,u,f,h,p,m,v;if(!e||typeof e!="object")return e;if(e.type==="inputGroup"){const g=e,b={...g};return Array.isArray(g.inputs)&&(b.inputs=g.inputs.map(w=>typeof w=="string"?w:Nu(w))),b}const t=e,r={...t},n=ls((c=t.labelPrefixIcon)==null?void 0:c.name,(d=t.labelPrefixIcon)==null?void 0:d.style),a=ls((u=t.labelSuffixIcon)==null?void 0:u.name,(f=t.labelSuffixIcon)==null?void 0:f.style),o=ls((h=t.prefixIcon)==null?void 0:h.name,(p=t.prefixIcon)==null?void 0:p.style),i=ls((m=t.suffixIcon)==null?void 0:m.name,(v=t.suffixIcon)==null?void 0:v.style);return n&&(r.labelPrefixIcon=n),a&&(r.labelSuffixIcon=a),o&&(r.prefixIcon=o),i&&(r.suffixIcon=i),r}function kW({name:e,children:t}){const r=uW(e);return l.jsx("div",{ref:r,"data-field":e,style:{position:"relative"},children:t})}function Wp(e){return e.startsWith("row|")?Object.fromEntries(e.slice(4).split(";").map(r=>r.split(":"))):{}}function EW(e,t){const r=Wp(e),n=Wp(t);return r.ctx===n.ctx&&r.li===n.li&&r.s===n.s&&(r.t??"")===(n.t??"")}function Up(e,t){if(!e.startsWith("col|"))return ss(e);const r=Object.fromEntries(e.slice(4).split(";").map(i=>i.split(":"))),n=r.ctx==="rows"?`rows|li:${r.li}|s:${r.s}|r:${r.r}|c:${r.c}`:`tabs|li:${r.li}|t:${r.t}|s:${r.s}|r:${r.r}|c:${r.c}`,a=(t[n]??[]).length,o=Object.prototype.hasOwnProperty.call(r,"insertAt");return{li:Number(r.li),tabIdx:r.t?Number(r.t):void 0,sectionIdx:Number(r.s),rowIdx:Number(r.r),colIdx:Number(r.c),fieldIdx:o?Number(r.insertAt):a}}function CW(e,t){const r=Array.from(e.querySelectorAll("[data-sortable-item]"));if(!r.length)return{insertAt:0,yAbs:e.getBoundingClientRect().top+8};let n=r.length,a=r[r.length-1].getBoundingClientRect().bottom;for(let o=0;o<r.length;o++){const i=r[o].getBoundingClientRect(),c=(i.top+i.bottom)/2;if(t<c){n=o,a=i.top;break}}return{insertAt:n,yAbs:a}}function jW(e){C.useEffect(()=>{if(!e)return;let t=0;const r=()=>{const n=document.getElementById("form-renderer-root");if(!n){t=requestAnimationFrame(r);return}const a=n.getBoundingClientRect(),o=window.__lastPointerY,i=80,c=14;typeof o=="number"&&(o<a.top+i?window.scrollBy({top:-c}):o>a.bottom-i&&window.scrollBy({top:c})),t=requestAnimationFrame(r)};return t=requestAnimationFrame(r),()=>cancelAnimationFrame(t)},[e])}function DW(e){const t=e.replaceAll("|",";");return t.startsWith("rows;")?`col|ctx:rows;${t.slice(5)}`:t.startsWith("tabs;")?`col|ctx:tabs;${t.slice(5)}`:`col|${t}`}function SW({droppableId:e,children:t,className:r,scope:n,li:a,tabIdx:o,sectionIdx:i,rowIdx:c,colIdx:d}){const u=n?{scope:n,...n==="rows-column"?{rowsNodeIdx:a}:{tabKey:`tab-${o}`},s:i,r:c,c:d,insertAt:0}:void 0,{isOver:f,setNodeRef:h}=Sr({id:e,data:u});return l.jsx("div",{ref:h,className:["relative min-h-[28px] h-full overflow-visible transition-[box-shadow,border-color] duration-100",f?"ring-1 ring-[var(--color-ds-border-default-50)] rounded":"",r??""].join(" "),style:{isolation:"isolate"},"data-droppable-col":!0,children:t})}function AW(e,t){var n,a,o,i,c,d,u,f,h;const r=e.layout[t.li];if(r)return r.type==="rows"?(i=(o=(a=(n=r.sections[t.sectionIdx])==null?void 0:n.rows[t.rowIdx])==null?void 0:a.columns[t.colIdx])==null?void 0:o.fields)==null?void 0:i[t.fieldIdx]:(h=(f=(u=(d=(c=r.tabs[t.tabIdx])==null?void 0:c.sections[t.sectionIdx])==null?void 0:d.rows[t.rowIdx])==null?void 0:u.columns[t.colIdx])==null?void 0:f.fields)==null?void 0:h[t.fieldIdx]}function qp({ctx:e,visible:t}){const{t:r}=At(),n=se(k=>k.addColumnToRow),a=se(k=>k.setRowColumns),o=se(k=>k.removeLastColumn),i=se(k=>k.addRowToSectionAt),c=se(k=>k.addColumnToTabRow),d=se(k=>k.setTabRowColumns),u=se(k=>k.removeLastTabColumn),f=se(k=>k.addRowToTabSectionAt),h=()=>e.kind==="rows"?n==null?void 0:n(e.sectionIdx,e.rowIdx):c==null?void 0:c(e.tabKey,e.sectionIdx,e.rowIdx),p=()=>e.kind==="rows"?o==null?void 0:o(e.sectionIdx,e.rowIdx):u==null?void 0:u(e.tabKey,e.sectionIdx,e.rowIdx),m=k=>e.kind==="rows"?a==null?void 0:a(e.sectionIdx,e.rowIdx,k):d==null?void 0:d(e.tabKey,e.sectionIdx,e.rowIdx,k),v=()=>e.kind==="rows"?i==null?void 0:i(e.sectionIdx,e.rowIdx):f==null?void 0:f(e.tabKey,e.sectionIdx,e.rowIdx),g=()=>e.kind==="rows"?i==null?void 0:i(e.sectionIdx,e.rowIdx+1):f==null?void 0:f(e.tabKey,e.sectionIdx,e.rowIdx+1),[b,w]=C.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}}),x=(k,j,A)=>{w({isOpen:!0,title:k,message:j,onConfirm:A})},y=()=>{b.onConfirm(),w(k=>({...k,isOpen:!1}))},E=()=>{w(k=>({...k,isOpen:!1}))};return l.jsxs("div",{"aria-label":"Acciones de fila",style:{position:"absolute",insetInlineEnd:6,insetBlockStart:-25,zIndex:2147483646,pointerEvents:t?"auto":"none",opacity:t?1:0,transition:"opacity .12s ease"},className:"flex items-center gap-1",children:[l.jsxs("div",{className:"flex items-center gap-1 bg-[var(--color-ds-background-elevated)]/85 backdrop-blur-sm px-1.5 py-1 rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm",children:[l.jsx(pe,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addRow"),onClick:v,children:"↑"}),l.jsx(pe,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addRow"),onClick:g,children:"↓"}),l.jsx("span",{className:"w-px h-4 bg-[var(--color-ds-border-default-50)] mx-1","aria-hidden":!0}),l.jsx(pe,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addColumn"),onClick:h,children:"+"}),l.jsx(pe,{size:"xs",variant:"ghost",title:r("ds.editor.actions.deleteColumn"),onClick:()=>x(r("ds.editor.confirmations.deleteColumn.title"),r("ds.editor.confirmations.deleteColumn.message"),p),children:"−"}),l.jsx("span",{className:"w-px h-4 bg-[var(--color-ds-border-default-50)] mx-1","aria-hidden":!0}),[1,2,3,4].map(k=>l.jsx(pe,{size:"xs",variant:"ghost",title:`Distribuir en ${k} columna(s)`,onClick:()=>m(k),children:k},k))]}),l.jsx(Bt,{isOpen:b.isOpen,onClose:E,title:b.title,footer:l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx(pe,{variant:"outline",onClick:E,children:r("ds.editor.actions.cancel")}),l.jsx(pe,{variant:"danger",onClick:y,children:r("ds.editor.actions.delete")})]}),children:l.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:b.message})})]})}function NW({schema:e,onSchemaChange:t,deps:r,layoutEditMode:n=!1}){const{t:a}=At(),o=se(U=>U.updateField),i=se(U=>U.mode),c=Wn(U=>U.setRuntimeState),d=Wn(U=>U.systemContext);C.useEffect(()=>{if(!e.variables)return;const U={};e.variables.forEach(J=>{J.type==="constant"&&(U[J.key]=J.value)}),e.variables.forEach(J=>{if(J.type==="computed"&&J.value)try{const oe=new Function("ctx",`return (${J.value});`);U[J.key]=oe(U)}catch(oe){console.warn(`[FormRendererDnd] Error evaluating computed variable "${J.key}":`,oe),U[J.key]=null}}),Object.keys(U).length>0&&c({systemContext:U})},[e.variables,c]);const u=C.useMemo(()=>({...r,translateFn:(U,J)=>{const oe=mt(a,U,J);return oe?cd(oe,d):""},onUpdateField:(U,J)=>{o(U,oe=>{Object.assign(oe,J)})},isDesignMode:i==="design"}),[r,a,o,i,d]),f=C.useCallback((U,J)=>{const oe=mt(a,U,J);return oe?cd(oe,d):""},[a,d]),h=C.useMemo(()=>mW(u),[u]),p=se(U=>U.selection),m=(p==null?void 0:p.kind)==="field"?p.name:void 0,g=se(U=>U.fieldPick).armed,{enabled:b,anchors:w,setSchema:x}=Pp();C.useEffect(()=>{x(e)},[e,x]);const[y,E]=C.useState(null),[k,j]=C.useState(null),A=C.useRef({}),S=C.useCallback(U=>J=>{A.current[U]=J},[]),_=C.useRef(null),O=C.useRef(null),B=C.useRef(null),R=U=>{O.current==null&&(O.current=requestAnimationFrame(()=>{O.current=null;const J=B.current;JSON.stringify(J)!==JSON.stringify(U)&&(B.current=U,j(U))}))},I=C.useMemo(()=>{const U={};return e.layout.forEach((J,oe)=>{J.type==="tabs"&&(U[oe]=J.tabs[0].key)}),U},[e.layout]),[F,Z]=C.useState(I),[ee,Y]=C.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}}),te=(U,J,oe)=>{Y({isOpen:!0,title:U,message:J,onConfirm:oe})},ae=()=>{ee.onConfirm(),Y(U=>({...U,isOpen:!1}))},q=()=>{Y(U=>({...U,isOpen:!1}))},N=C.useMemo(()=>{const U={};return e.layout.forEach((J,oe)=>{J.type==="rows"?J.sections.forEach((de,ge)=>{de.rows.forEach((we,Ce)=>{we.columns.forEach((ke,Ie)=>{const Le=`rows|li:${oe}|s:${ge}|r:${Ce}|c:${Ie}`;U[Le]=(ke.fields??[]).map((De,Re)=>$p({li:oe,sectionIdx:ge,rowIdx:Ce,colIdx:Ie,fieldIdx:Re}))})})}):J.type==="tabs"&&J.tabs.forEach((de,ge)=>{de.sections.forEach((we,Ce)=>{we.rows.forEach((ke,Ie)=>{ke.columns.forEach((Le,De)=>{const Re=`tabs|li:${oe}|t:${ge}|s:${Ce}|r:${Ie}|c:${De}`;U[Re]=(Le.fields??[]).map((Ve,Ge)=>$p({li:oe,tabIdx:ge,sectionIdx:Ce,rowIdx:Ie,colIdx:De,fieldIdx:Ge}))})})})})}),U},[e]),L=C.useMemo(()=>{const U={};return Object.entries(N).forEach(([J,oe])=>oe.forEach(de=>U[de]=J)),U},[N]),ne=Bd(Ba(Uo,{activationConstraint:{distance:6}}),Ba(Wo,{coordinateGetter:Kh})),K="__phantom__",[Q,he]=C.useState(!1),[ie,me]=C.useState(null),[ce,le]=C.useState(null),[be,fe]=C.useState(40),[xe,D]=C.useState(null),[G,re]=C.useState(null),W=C.useCallback(U=>{if(!U)return!1;if(typeof U=="string"){const J=r.fieldsByName[U];return!!J&&J.type==="inputGroup"}return(U==null?void 0:U.type)==="inputGroup"},[r.fieldsByName]),H=U=>{var Ce;const J=String(((Ce=U.active)==null?void 0:Ce.id)??""),oe=zd(U),de=oe[0],ge=de?String(de.id):null;if(ge&&L[ge]&&L[J]&&L[ge]===L[J])return oe;const we=xB(U);if(J.startsWith("row|")||J.startsWith("tab-row|")){const ke=we.filter(Ie=>String(Ie.id).startsWith("row-slot|")||String(Ie.id).startsWith("tab-row-slot|"));if(ke.length)return ke}else{const ke=we.filter(Ie=>String(Ie.id).startsWith("col|"));if(ke.length)return ke}return oe};zo({onDragStart:U=>{var de,ge,we,Ce,ke,Ie;he(!0);const J=String(U.active.id??"");me(J),le(L[J]??null),_.current=J.startsWith("row|")?"row":"field";const oe=((ge=(de=U.active.rect.current)==null?void 0:de.translated)==null?void 0:ge.height)??((Ce=(we=U.active.rect.current)==null?void 0:we.initial)==null?void 0:Ce.height)??40;if(fe(Math.max(24,Math.floor(oe))),_.current==="field"&&!J.startsWith("col|")&&!J.startsWith("palette:"))try{const Le=ss(J),De=(ke=e.layout)==null?void 0:ke[Le.li],Ve=(Ie=((De==null?void 0:De.type)==="rows"?De.sections[Le.sectionIdx].rows[Le.rowIdx].columns[Le.colIdx]:De.tabs[Le.tabIdx].sections[Le.sectionIdx].rows[Le.rowIdx].columns[Le.colIdx]).fields)==null?void 0:Ie[Le.fieldIdx??0],Ge=Ve&&Nu(Ve);D(Ge?h(Ge):null)}catch{D(null)}else D(null)},onDragOver:U=>{var Ie,Le;const J=String(((Ie=U.over)==null?void 0:Ie.id)??""),oe=String(((Le=U.active)==null?void 0:Le.id)??""),de=U.activatorEvent;if(de&&typeof de.clientY=="number"&&(window.__lastPointerY=de.clientY),_.current==="row"){if(J.startsWith("row|")&&oe.startsWith("row|"))if(EW(oe,J)&&oe!==J){const De=A.current[J],Re=(de==null?void 0:de.clientY)??0;if(De&&Re){const Ve=De.getBoundingClientRect(),Ge=Re<Ve.top+Ve.height/2?"before":"after";R({rid:J,pos:Ge})}else R(null)}else R(null);else R(null);re(null);return}if(!J.startsWith("col|")){re(null);return}const ge=Object.fromEntries(J.slice(4).split(";").map(De=>De.split(":"))),we=ge.ctx==="rows"?`rows|li:${ge.li}|s:${ge.s}|r:${ge.r}|c:${ge.c}`:`tabs|li:${ge.li}|t:${ge.t}|s:${ge.s}|r:${ge.r}|c:${ge.c}`,Ce=document.querySelector(`[data-col-key="${we}"]`),ke=(de==null?void 0:de.clientY)??0;if(Ce&&ke){const{insertAt:De,yAbs:Re}=CW(Ce,ke),Ve=Ce.getBoundingClientRect().top;re({overId:J,keyId:we,insertAt:De,yRel:Re-Ve})}else re(null)},onDragCancel:U=>{he(!1),me(null),le(null),fe(40),D(null),re(null),j(null),_.current=null,O.current&&(cancelAnimationFrame(O.current),O.current=null),B.current=null},onDragEnd:()=>{he(!1),me(null),le(null),fe(40),D(null),j(null),_.current=null,O.current&&(cancelAnimationFrame(O.current),O.current=null),B.current=null}}),jW(Q);const X=C.useCallback(U=>{const{active:J,over:oe}=U;if(!(J!=null&&J.id)||!(oe!=null&&oe.id)){re(null),j(null);return}const de=J.data.current,ge=oe.data.current;if(((de==null?void 0:de.kind)==="row-in-section"||(de==null?void 0:de.kind)==="row-in-tab-section")&&((ge==null?void 0:ge.scope)==="row-slot"||(ge==null?void 0:ge.scope)==="tab-row-slot")){const De=de.li,Re=de.sIdx,Ve=de.rIdx,Ge=ge.li,ft=ge.sIdx,Ne=ge.insertAt,Fe={...e,layout:[...e.layout]},Me={...Fe.layout[De]};Fe.layout[De]=Me;let _e=null,Te=null,Ze=null;if(de.kind==="row-in-section"&&Me.type==="rows")Me.sections=[...Me.sections],Te={...Me.sections[Re]},Me.sections[Re]=Te,Te.rows=[...Te.rows],_e=Te.rows;else if(de.kind==="row-in-tab-section"&&Me.type==="tabs"){Me.tabs=[...Me.tabs];const Ye=Me.tabs.findIndex(Ke=>Ke.key===de.tabKey);Ye>=0&&(Ze={...Me.tabs[Ye]},Me.tabs[Ye]=Ze,Ze.sections=[...Ze.sections],Te={...Ze.sections[Re]},Ze.sections[Re]=Te,Te.rows=[...Te.rows],_e=Te.rows)}if(!_e)return;let He=null,Ue=null;if(De===Ge?Ue=Me:(Ue={...Fe.layout[Ge]},Fe.layout[Ge]=Ue),ge.scope==="row-slot"&&Ue.type==="rows")if(Ue.sections===Me.sections||(Ue.sections=[...Ue.sections]),De===Ge&&Re===ft&&de.kind==="row-in-section")He=_e;else{const Ye={...Ue.sections[ft]};Ue.sections[ft]=Ye,Ye.rows=[...Ye.rows],He=Ye.rows}else if(ge.scope==="tab-row-slot"&&Ue.type==="tabs"){Ue.tabs===Me.tabs||(Ue.tabs=[...Ue.tabs]);const Ye=Ue.tabs.findIndex(Ke=>Ke.key===ge.tabKey);if(Ye>=0){let Ke=Ue.tabs[Ye];if(De===Ge&&de.kind==="row-in-tab-section"&&de.tabKey===ge.tabKey?Ke=Ze:(Ke={...Ke},Ue.tabs[Ye]=Ke),Ke.sections===(Ze==null?void 0:Ze.sections)||(Ke.sections=[...Ke.sections]),De===Ge&&Re===ft&&de.kind==="row-in-tab-section"&&de.tabKey===ge.tabKey)He=_e;else{const ht={...Ke.sections[ft]};Ke.sections[ft]=ht,ht.rows=[...ht.rows],He=ht.rows}}}if(!He)return;const[Tt]=_e.splice(Ve,1);let ze=Ne;_e===He&&Ve<Ne&&(ze-=1),He.splice(ze,0,Tt),t(Fe),re(null),j(null);return}if((de==null?void 0:de.kind)==="palette-field"){const De=String(oe.id);if(!De.startsWith("col|")){re(null),j(null);return}const Re=Object.fromEntries(De.slice(4).split(";").map(Me=>Me.split(":"))),Ve=G&&G.overId===De?G.insertAt:Re.insertAt?Number(Re.insertAt):0,Ge={li:Number(Re.li),tabIdx:Re.t!=null?Number(Re.t):void 0,sectionIdx:Number(Re.s),rowIdx:Number(Re.r),colIdx:Number(Re.c),fieldIdx:Ve},ft=de.factoryKind,Ne=xW(ft),Fe=dW(e,Ne,Ge);re(null),j(null),t(Fe);return}const we=String(J.id),Ce=String(oe.id);if(we.startsWith("row|")&&Ce.startsWith("row|"),we.startsWith("palette:")){re(null),j(null);return}const ke=ss(we);let Ie;if(Ce.startsWith("col|")&&G&&G.overId===Ce){const De=Object.fromEntries(Ce.slice(4).split(";").map(Ve=>Ve.split(":"))),Re=`col|${Object.entries(De).filter(([Ve])=>Ve!=="insertAt").map(([Ve,Ge])=>`${Ve}:${Ge}`).join(";")};insertAt:${G.insertAt}`;Ie=Up(Re,N)}else Ie=Up(Ce,N);const Le=iW(e,ke,Ie);re(null),j(null),t(Le)},[e,t,N,G]);function M(U,J){let oe=U;if(ie&&ce&&ce!==J&&(oe=oe.filter(de=>de!==ie)),Q&&G&&G.keyId===J){const de=Math.max(0,Math.min(G.insertAt,oe.length)),ge=oe.slice();return ge.splice(de,0,K),ge}return oe}const V=({keyId:U,ids:J,className:oe,tabKey:de})=>{const ge=DW(U),we=M(J,U),Ce=Object.fromEntries(U.split("|").map(Ne=>Ne.split(":"))),ke=U.startsWith("rows|"),Ie=ke?"rows-column":"tabs-column",Le=Number(Ce.li),De=Ce.t!=null?Number(Ce.t):void 0,Re=Number(Ce.s),Ve=Number(Ce.r),Ge=Number(Ce.c),ft=J.length;return l.jsx(SW,{droppableId:ge,className:oe,scope:Ie,li:Le,tabIdx:De,sectionIdx:Re,rowIdx:Ve,colIdx:Ge,children:l.jsxs("div",{"data-col-key":U,className:"relative",children:[ke?l.jsx(Fr,{scope:"rows-column",rowsNodeIdx:Le,s:Re,r:Ve,c:Ge,insertAt:0,suppressAll:ft===0}):de?l.jsx(Fr,{scope:"tabs-column",tabKey:de,s:Re,r:Ve,c:Ge,insertAt:0,suppressAll:ft===0}):null,Q&&G&&G.overId===ge?l.jsx("div",{"aria-hidden":!0,style:{position:"absolute",left:0,right:0,top:Math.max(0,G.yRel-1),height:2,background:"var(--color-ds-border-default)",borderRadius:2}}):null,l.jsx(Uh,{items:we,strategy:zh,children:l.jsx("div",{children:we.map((Ne,Fe)=>{if(Ne===K)return l.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0,style:{height:be,border:"1px dashed var(--color-ds-border-default-50)",borderRadius:8,background:"color-mix(in srgb, var(--color-ds-border-default-50) 8%, transparent)"}},`${U}-ph-${Fe}`);const Me=ss(String(Ne)),_e=AW(e,Me);if(!_e)return l.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0},`${U}-miss-${Fe}`);const Te=Nu(_e),Ze=typeof Te=="string"?Te:(Te==null?void 0:Te.name)??"",He=!!m&&!!Ze&&m===Ze,Ue=h(Te),Tt=W(Te),ze=Ke=>{var ht;Ke.preventDefault(),Ke.stopPropagation(),(ht=Ke.nativeEvent)!=null&&ht.stopImmediatePropagation&&Ke.nativeEvent.stopImmediatePropagation()},Ye=Tt?{onDoubleClick:ze,onDoubleClickCapture:ze,onClick:ze,onClickCapture:ze,onMouseDown:ze,onMouseDownCapture:ze,onMouseUp:ze,onMouseUpCapture:ze,onPointerDown:ze,onPointerDownCapture:ze,onPointerUp:ze,onPointerUpCapture:ze,onContextMenu:ze}:{};return l.jsx("div",{"data-sortable-item":!0,children:l.jsx(bW,{id:String(Ne),fieldName:Ze,onDelete:Ke=>{const ht=ss(Ke);te("Eliminar campo","¿Estás seguro de que quieres eliminar este campo?",()=>{const $r=lW(e,ht);t($r)})},chromeDisabled:g,children:l.jsx(kW,{name:Ze,children:l.jsx("div",{className:He?"selected-field":void 0,"data-field-name":Ze,"aria-selected":He||void 0,...Ye,children:Ue})})})},String(Ne))})})})]})})},T=Q&&_.current==="row",$=(U,J)=>l.jsx(l.Fragment,{children:U.sections.map((oe,de)=>l.jsx("div",{className:"mb-6",children:l.jsx(lt,{title:f(oe.sectionTitle),defaultOpen:oe.defaultOpen,forceOpen:T,children:l.jsxs("div",{className:"flex flex-col",children:[l.jsx(cl,{scope:"row-slot",li:J,sIdx:de,insertAt:0}),oe.rows.map((ge,we)=>{const Ce=`row|li:${J}|s:${de}|r:${we}`,ke=n&&y===Ce,Ie=ie===Ce;return l.jsxs(C.Fragment,{children:[l.jsxs("div",{ref:S(Ce),className:`relative transition-all duration-200 ${Ie?"opacity-40 ring-1 ring-dashed ring-[var(--color-ds-border-default)] bg-[var(--color-ds-background-muted)]":n&&ke?"ring-1 ring-[var(--color-ds-border-default-50)]":""}`,onMouseEnter:()=>E(Ce),onMouseLeave:()=>E(Le=>Le===Ce?null:Le),style:{borderRadius:8},children:[n&&l.jsxs(l.Fragment,{children:[l.jsx(qp,{ctx:{kind:"rows",li:J,sectionIdx:de,rowIdx:we},visible:!!ke&&!g}),l.jsx(Hp,{kind:"row-in-section",li:J,sIdx:de,rIdx:we,visible:!!ke&&!g})]}),ge.title&&l.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:f(ge.title)}),l.jsx("div",{className:"flex flex-wrap -mx-2 items-stretch",children:ge.columns.map((Le,De)=>{const Re=`rows|li:${J}|s:${de}|r:${we}|c:${De}`,Ve=N[Re]??[];return l.jsx("div",{className:`${Le.width} px-2 flex flex-col`,children:l.jsx(V,{keyId:Re,ids:Ve})},`col-${J}-${de}-${we}-${De}`)})})]}),l.jsx(cl,{scope:"row-slot",li:J,sIdx:de,insertAt:we+1})]},`rowwrap-${Ce}`)})]})})},`sec-${J}-${de}`))}),P=(U,J)=>{var de;const oe=F[J]??((de=U.tabs[0])==null?void 0:de.key);return l.jsx(zr,{options:U.tabs.map(ge=>{const we=ge.icon?ls(ge.icon.name,ge.icon.style):null;return{label:f(ge.label),value:ge.key,disabled:ge.disabled,icon:we?l.jsx(we,{className:"w-4 h-4"}):null}}),value:oe,onChange:ge=>Z(we=>({...we,[J]:ge})),children:Object.fromEntries(U.tabs.map((ge,we)=>[ge.key,l.jsx("div",{className:"space-y-6",children:ge.sections.map((Ce,ke)=>l.jsx("div",{className:"mb-6",children:l.jsx(lt,{title:f(Ce.sectionTitle),defaultOpen:Ce.defaultOpen,forceOpen:T,children:l.jsxs("div",{className:"flex flex-col",children:[l.jsx(cl,{scope:"tab-row-slot",li:J,tabKey:ge.key,sIdx:ke,insertAt:0}),Ce.rows.map((Ie,Le)=>{const De=`tab-row|li:${J}|t:${ge.key}|s:${ke}|r:${Le}`,Re=n&&y===De,Ve=ie===De;return l.jsxs(C.Fragment,{children:[l.jsxs("div",{ref:S(De),className:`relative transition-all duration-200 ${Ve?"opacity-40 ring-1 ring-dashed ring-[var(--color-ds-border-default)] bg-[var(--color-ds-background-muted)]":n&&Re?"ring-1 ring-[var(--color-ds-border-default-50)]":""}`,onMouseEnter:()=>E(De),onMouseLeave:()=>E(Ge=>Ge===De?null:Ge),style:{borderRadius:8},children:[n&&l.jsxs(l.Fragment,{children:[l.jsx(qp,{ctx:{kind:"tabs",li:J,tabKey:ge.key,tabIdx:we,sectionIdx:ke,rowIdx:Le},visible:!!Re&&!g}),l.jsx(Hp,{kind:"row-in-tab-section",li:J,tabKey:ge.key,sIdx:ke,rIdx:Le,visible:!!Re&&!g})]}),Ie.title&&l.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:f(Ie.title)}),l.jsx("div",{className:"flex flex-wrap -mx-2 items-stretch",children:Ie.columns.map((Ge,ft)=>{const Ne=`tabs|li:${J}|t:${we}|s:${ke}|r:${Le}|c:${ft}`,Fe=N[Ne]??[];return l.jsx("div",{className:`${Ge.width??"flex-1"} px-2 flex flex-col`,children:l.jsx(V,{keyId:Ne,ids:Fe,tabKey:ge.key})},`col-${J}-${we}-${ke}-${Le}-${ft}`)})})]}),l.jsx(cl,{scope:"tab-row-slot",li:J,tabKey:ge.key,sIdx:ke,insertAt:Le+1})]},`rowwrap-${De}`)})]})})},`sec-${J}-${we}-${ke}`))},`tabpanel-${J}-${we}`)]))},`tabs-${J}`)},z=se(U=>U.setSelection);return l.jsxs(xc,{...r.methods,children:[l.jsxs(Qd,{sensors:ne,collisionDetection:H,onDragEnd:X,children:[l.jsxs("div",{id:"form-renderer-root",className:"relative overflow-visible",onDoubleClick:U=>{z({kind:"none"})},children:[l.jsx("div",{className:"space-y-6 ",children:e.layout.map((U,J)=>U.type==="rows"?l.jsx(C.Fragment,{children:$(U,J)},`rows-${J}`):l.jsx(C.Fragment,{children:P(U,J)},`tabs-${J}`))}),l.jsx(pW,{schema:e,anchors:w,enabled:b})]}),l.jsx(th,{dropAnimation:null,children:xe?l.jsx("div",{style:{pointerEvents:"none",opacity:.9},children:xe}):null})]}),l.jsx(Bt,{isOpen:ee.isOpen,onClose:q,title:ee.title,footer:l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx(pe,{variant:"outline",onClick:q,children:"Cancelar"}),l.jsx(pe,{variant:"danger",onClick:ae,children:"Eliminar"})]}),children:l.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:ee.message})})]})}function FW(e,t,r,n){var k;const{fields:a=[],layout:o,validationSchema:i}=e,c=_W(),d=((k=c==null?void 0:c.services)==null?void 0:k.registry)??void 0,u=Wn(j=>j.systemContext),f=C.useMemo(()=>{if(t)return t;try{const j=i??ld(e);return Xc(j)}catch{return}},[t,e,i]),h=Ic({resolver:f,mode:"onBlur",reValidateMode:"onChange",defaultValues:e.defaultValues??{}}),p=C.useMemo(()=>(a??[]).filter(j=>j.type!=="inputGroup"&&j.type!=="button"),[a]),{optionsMap:m}=V2(p),v=I2(a),g=Z2(a,h.control),[b,w]=C.useState({}),[x,y]=C.useState(0);C.useEffect(()=>{let j;const A=h.watch(()=>{clearTimeout(j),j=setTimeout(()=>{y(S=>S+1)},500)});return()=>{A.unsubscribe(),clearTimeout(j)}},[h.watch]),C.useEffect(()=>{let j=!0;return(async()=>{const S=await Promise.all(p.filter(O=>O.type==="select"&&(O.optionSource||O.endpointConfig)).map(async O=>{const B=O.name,R=li(O.optionSource,O.endpointConfig);if(!R)return[B,[]];const I=O.endpointConfig?bn(O.endpointConfig.parameters,h.getValues,{...u,ACTIVE_VARIANT:n}):{},F=d==null?void 0:d[R];if(typeof F!="function")return[B,[]];try{const Z=await Promise.resolve(F("",{getValues:h.getValues,watch:h.watch,params:I,...u})),ee=Array.isArray(Z)?Z:[];return[B,ee]}catch{return[B,[]]}}));if(!j)return;const _={};for(const[O,B]of S)_[O]=B;w(_)})(),()=>{j=!1}},[d,h.getValues,h.watch,JSON.stringify(p.map(j=>({n:j.name,os:j.optionSource??null,ec:j.endpointConfig??null}))),n,x]);const E=C.useCallback((j,A)=>{if(!(j!=null&&j.enabled)||!j.rule)return A;try{const S={...h.getValues(),ACTIVE_VARIANT:n};return!!Ei(j.rule,S)}catch{return A}},[h,n]);return{methods:h,control:h.control,formState:h.formState,fields:a,fieldsByName:v,asyncOptionsMap:m,adapterOptionsMap:b,disabledMap:g,evalContainer:E,registry:d,layout:o,systemContext:u}}function _W(){try{return Zt()??void 0}catch{return}}function MW(e,t,r){const n={...e};return t.top+e.y<=r.top?n.y=r.top-t.top:t.bottom+e.y>=r.top+r.height&&(n.y=r.top+r.height-t.bottom),t.left+e.x<=r.left?n.x=r.left-t.left:t.right+e.x>=r.left+r.width&&(n.x=r.left+r.width-t.right),n}const RW=e=>{let{transform:t,draggingNodeRect:r,windowRect:n}=e;return!r||!n?t:MW(t,r,n)};function Ga(e){const r={text:()=>({label:"ds.fields.defaults.text.label",type:"text",width:"w-full",placeholder:"ds.fields.defaults.text.placeholder",size:"sm"}),number:()=>({label:"ds.fields.defaults.number.label",type:"number",width:"w-full",placeholder:"ds.fields.defaults.number.placeholder",size:"sm",validation:{required:!1}}),email:()=>({label:"ds.fields.defaults.email.label",type:"email",width:"w-full",placeholder:"ds.fields.defaults.email.placeholder",size:"sm"}),password:()=>({label:"ds.fields.defaults.password.label",type:"password",width:"w-full",placeholder:"ds.fields.defaults.password.placeholder",size:"sm",validation:{minLength:8}}),tel:()=>({label:"ds.fields.defaults.tel.label",type:"tel",width:"w-full",placeholder:"ds.fields.defaults.tel.placeholder",size:"sm"}),url:()=>({label:"ds.fields.defaults.url.label",type:"url",width:"w-full",placeholder:"ds.fields.defaults.url.placeholder",size:"sm"}),select:()=>({label:"ds.fields.defaults.select.label",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}),checkbox:()=>({label:"ds.fields.defaults.checkbox.label",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}),textarea:()=>({label:"ds.fields.defaults.textarea.label",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"ds.fields.defaults.textarea.placeholder"}),date:()=>({label:"ds.fields.defaults.date.label",type:"date",width:"w-full",size:"sm",showTime:!1}),file:()=>({label:"ds.fields.defaults.file.label",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}),inputGroup:()=>({label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}),search:()=>({label:"ds.fields.defaults.search.label",type:"search",width:"w-full",placeholder:"ds.fields.defaults.search.placeholder",size:"sm",searchMode:"button"}),optionGroup:()=>({label:"Selecciona opciones",type:"optionGroup",width:"w-full",size:"sm",multiple:!0,vertical:!0,options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}]}),array:()=>({label:"Lista repetible",type:"array",width:"w-full",items:[]})}[e];return r?r():{type:e}}function OW(e){if(!e)return null;const t=e.data;if(t.kind==="palette-field"){const r=t.factoryKind,n=GP[r];if(n)return l.jsx("div",{className:"pointer-events-none opacity-95",children:l.jsx("div",{className:`\r
412
+ `,title:E.disabled?"Click para habilitar":"Click para deshabilitar",children:[E.disabled?l.jsx(vo,{className:"w-3 h-3"}):l.jsx(_1,{className:"w-3 h-3"}),l.jsx("span",{className:E.disabled?"inline":"hidden sm:inline",children:E.disabled?"Deshabilitada":"Habilitada"})]}),l.jsx("div",{className:"h-4 w-px bg-[var(--color-ds-border-default-50)]"}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx(pe,{icon:ga,size:"sm",variant:"primary",shape:"circle",onClick:()=>g==null?void 0:g(E.key,"Nueva sección"),title:"Añadir nueva sección",className:"shadow-sm"}),l.jsx(ko,{align:"right",trigger:l.jsx("div",{className:"p-1.5 rounded-md hover:bg-[var(--color-ds-background-surface-soft)] text-[var(--color-ds-text-secondary)] transition-colors cursor-pointer",children:l.jsx(A1,{className:"w-5 h-5"})}),items:[{label:"Añadir Pestaña",icon:cc,onSelect:()=>m==null?void 0:m(E.key)},{separator:!0},{label:"Eliminar Pestaña",icon:Dt,variant:"danger",disabled:t.tabs.length<=1,onSelect:()=>a("Eliminar pestaña","¿Estás seguro de que quieres eliminar esta pestaña? Se perderá todo su contenido.",()=>v==null?void 0:v(E.key))}]})]})]})]}),Array.from({length:E.sections.length+1}).map((k,j)=>{const A=j,S=E.sections[A],_=(n==null?void 0:n.nodeIdx)===r&&(n==null?void 0:n.tabKey)===E.key&&j===n.sIdx+1;return l.jsxs(C.Fragment,{children:[l.jsx("div",{className:"px-2",children:!_&&l.jsx(QH,{nodeIdx:r,tabKey:E.key,insertAt:j})}),A<E.sections.length&&l.jsx(Op,{section:S,nodeIdx:r,sIdx:A,parentType:"tabs",tabKey:E.key,confirmDelete:a})]},`tsec-${E.key}-${j}`)})]}),y),{})})})]})]})})});function sW(){const e=se(h=>h.schema.layout),t=se(h=>h.editorSettings),[r,n]=C.useState(null),[a,o]=C.useState(null),[i,c]=C.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}});zo({onDragStart:h=>{const{active:p}=h,m=p.data.current;m&&m.kind==="rows-section"&&n(m.sIdx),m&&m.kind==="tab-section"&&o({nodeIdx:m.nodeIdx,tabKey:m.tabKey,sIdx:m.sIdx})},onDragEnd:()=>{n(null),o(null)},onDragCancel:()=>{n(null),o(null)}});const d=C.useCallback((h,p,m)=>{if(!t.confirmDelete){m();return}c({isOpen:!0,title:h,message:p,onConfirm:m})},[t.confirmDelete]),u=()=>{i.onConfirm(),c(h=>({...h,isOpen:!1}))},f=()=>{c(h=>({...h,isOpen:!1}))};return l.jsxs("div",{id:"designer-canvas-root",className:"space-y-3 relative",children:[e.map((h,p)=>{if(h.type==="rows"){const m=h.sections;return l.jsx("div",{className:"space-y-3",children:Array.from({length:m.length+1}).map((v,g)=>{const b=g,w=m[b];return l.jsxs(C.Fragment,{children:[!(r!==null&&g===r+1)&&l.jsx(ZH,{nodeIdx:p,insertAt:g}),b<m.length&&l.jsx(Op,{section:w,nodeIdx:p,sIdx:b,parentType:"rows",confirmDelete:d})]},`rows-slot-sec-${p}-${g}`)})},`rows-${p}`)}return h.type==="tabs"?l.jsx(oW,{node:h,nodeIdx:p,draggedTabSection:a,confirmDelete:d},`tabs-${p}`):null}),l.jsx(Bt,{isOpen:i.isOpen,onClose:f,title:i.title,footer:l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx(pe,{variant:"outline",onClick:f,children:"Cancelar"}),l.jsx(pe,{variant:"danger",onClick:u,children:"Eliminar"})]}),children:l.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:i.message})})]})}const Tp=(e,t,r)=>Math.max(t,Math.min(r,e));function $p(e){const t=[`li:${e.li}`];return e.tabIdx!=null&&t.push(`t:${e.tabIdx}`),t.push(`s:${e.sectionIdx}`,`r:${e.rowIdx}`,`c:${e.colIdx}`,`f:${e.fieldIdx}`),t.join("|")}function ss(e){const t=Object.fromEntries(e.split("|").map(r=>r.split(":")));return{li:Number(t.li),tabIdx:t.t!=null?Number(t.t):void 0,sectionIdx:Number(t.s),rowIdx:Number(t.r),colIdx:Number(t.c),fieldIdx:Number(t.f)}}function Ip(e,t){var n,a,o,i,c,d,u;const r=e[t.li];if(!r)return null;if(r.type==="rows"){const f=(n=r.sections)==null?void 0:n[t.sectionIdx],h=(a=f==null?void 0:f.rows)==null?void 0:a[t.rowIdx];return((o=h==null?void 0:h.columns)==null?void 0:o[t.colIdx])??null}if(r.type==="tabs"){const f=(i=r.tabs)==null?void 0:i[t.tabIdx??0],h=(c=f==null?void 0:f.sections)==null?void 0:c[t.sectionIdx],p=(d=h==null?void 0:h.rows)==null?void 0:d[t.rowIdx];return((u=p==null?void 0:p.columns)==null?void 0:u[t.colIdx])??null}return null}function iW(e,t,r){if(t.li===r.li&&(t.tabIdx??-1)===(r.tabIdx??-1)&&t.sectionIdx===r.sectionIdx&&t.rowIdx===r.rowIdx&&t.colIdx===r.colIdx&&t.fieldIdx===r.fieldIdx)return e;const n=JSON.parse(JSON.stringify(e.layout)),a=Ip(n,{li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx}),o=Ip(n,{li:r.li,tabIdx:r.tabIdx,sectionIdx:r.sectionIdx,rowIdx:r.rowIdx,colIdx:r.colIdx});if(!a||!Array.isArray(a.fields)||!o||!Array.isArray(o.fields))return e;const i=[...a.fields];if(t.fieldIdx<0||t.fieldIdx>=i.length)return e;const[c]=i.splice(t.fieldIdx,1);a.fields=i;const d=[...o.fields],u=Tp(r.fieldIdx??d.length,0,d.length);return d.splice(u,0,c),o.fields=d,{...e,layout:n}}function lW(e,t){const r=JSON.parse(JSON.stringify(e.layout)),a=(d=>{var f,h,p,m,v,g,b,w,x,y,E,k;const u=r[d.li];return u?u.type==="rows"?((v=(m=(p=(h=(f=u.sections)==null?void 0:f[d.sectionIdx])==null?void 0:h.rows)==null?void 0:p[d.rowIdx])==null?void 0:m.columns)==null?void 0:v[d.colIdx])??null:u.type==="tabs"?((k=(E=(y=(x=(w=(b=(g=u.tabs)==null?void 0:g[d.tabIdx??0])==null?void 0:b.sections)==null?void 0:w[d.sectionIdx])==null?void 0:x.rows)==null?void 0:y[d.rowIdx])==null?void 0:E.columns)==null?void 0:k[d.colIdx])??null:null:null})({li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx});if(!a||!Array.isArray(a.fields))return e;const o=[...a.fields];if(t.fieldIdx<0||t.fieldIdx>=o.length)return e;const[i]=o.splice(t.fieldIdx,1);a.fields=o;const c=[...e.fields||[]];if(i){let d=0;const u=f=>{Array.isArray(f)&&f.includes(i)&&d++};if(r.forEach(f=>{var h,p;f.type==="rows"?(h=f.sections)==null||h.forEach(m=>{var v;return(v=m.rows)==null?void 0:v.forEach(g=>{var b;return(b=g.columns)==null?void 0:b.forEach(w=>u(w.fields))})}):f.type==="tabs"&&((p=f.tabs)==null||p.forEach(m=>{var v;return(v=m.sections)==null?void 0:v.forEach(g=>{var b;return(b=g.rows)==null?void 0:b.forEach(w=>{var x;return(x=w.columns)==null?void 0:x.forEach(y=>u(y.fields))})})}))}),d===0){const f=c.findIndex(h=>h.name===i);f!==-1&&c.splice(f,1)}}return{...e,layout:r,fields:c}}function cW(e,t){const r=new Set(e.map(o=>o.name));let n=1,a=`${t}_${n}`;for(;r.has(a);)n++,a=`${t}_${n}`;return a}function dW(e,t,r){const n=cW(e.fields||[],t.type||"field"),a={...t,name:n},o=[...e.fields||[],a],i=JSON.parse(JSON.stringify(e.layout)),d=(f=>{var p,m,v,g,b,w,x,y,E,k,j,A;const h=i[f.li];return h?h.type==="rows"?((b=(g=(v=(m=(p=h.sections)==null?void 0:p[f.sectionIdx])==null?void 0:m.rows)==null?void 0:v[f.rowIdx])==null?void 0:g.columns)==null?void 0:b[f.colIdx])??null:h.type==="tabs"?((A=(j=(k=(E=(y=(x=(w=h.tabs)==null?void 0:w[f.tabIdx??0])==null?void 0:x.sections)==null?void 0:y[f.sectionIdx])==null?void 0:E.rows)==null?void 0:k[f.rowIdx])==null?void 0:j.columns)==null?void 0:A[f.colIdx])??null:null:null})({li:r.li,tabIdx:r.tabIdx,sectionIdx:r.sectionIdx,rowIdx:r.rowIdx,colIdx:r.colIdx});if(!d)return{...e,fields:o};Array.isArray(d.fields)||(d.fields=[]);const u=Tp(r.fieldIdx??d.fields.length,0,d.fields.length);return d.fields.splice(u,0,n),{...e,fields:o,layout:i}}const Bp=C.createContext(null),Pp=()=>{const e=C.useContext(Bp);if(!e)throw new Error("useRelations must be used inside <RelationsProvider>");return e},uW=e=>{const{registerFieldEl:t}=Pp();return C.useCallback(r=>{e&&t(e,r)},[e,t])},fW=({children:e})=>{const[t,r]=C.useState(!1),[n,a]=C.useState(null),[o,i]=C.useState({}),c=C.useRef({}),d=m=>r(v=>typeof m=="boolean"?m:!v),u=C.useCallback((m,v)=>{c.current[m]=v},[]);C.useEffect(()=>{let m=!0,v;const b=(async()=>{try{const{useEditorStore:w}=await Promise.resolve().then(()=>tB),y=w.getState().showRelations??!1;return v=y,m&&r(y),w.subscribe(k=>{const j=k.showRelations??!1;m&&j!==v&&(v=j,r(j))})}catch(w){return console.error("Failed to sync with store:",w),()=>{}}})();return()=>{m=!1,b.then(w=>w())}},[]);const f=C.useRef(null),h=C.useRef({});C.useEffect(()=>{if(!t)return;const m=()=>{const x=f.current;if(!x)return;const y=x.getBoundingClientRect(),E={};for(const[S,_]of Object.entries(c.current)){if(!_)continue;const O=_.getBoundingClientRect();E[S]={x:Math.round(O.left-y.left+O.width/2),y:Math.round(O.top-y.top+O.height/2),w:Math.round(O.width),h:Math.round(O.height)}}const k=h.current;let j=!1;const A=new Set([...Object.keys(E),...Object.keys(k)]);for(const S of A){const _=E[S],O=k[S];if(!_||!O||_.x!==O.x||_.y!==O.y||_.w!==O.w||_.h!==O.h){j=!0;break}}j&&(h.current=E,i(E))},v=()=>requestAnimationFrame(m),g=new ResizeObserver(v);f.current&&g.observe(f.current);const b=new MutationObserver(v);f.current&&b.observe(f.current,{childList:!0,subtree:!0}),window.addEventListener("resize",v,{passive:!0}),document.addEventListener("scroll",v,{passive:!0,capture:!0});const w=new ResizeObserver(v);return Object.values(c.current).forEach(x=>x&&w.observe(x)),v(),()=>{g.disconnect(),b.disconnect(),w.disconnect(),window.removeEventListener("resize",v),document.removeEventListener("scroll",v,{capture:!0})}},[t]);const p=C.useMemo(()=>({enabled:t,toggle:d,registerFieldEl:u,anchors:o,schema:n,setSchema:a}),[t,u,o,n]);return l.jsx(Bp.Provider,{value:p,children:l.jsx("div",{ref:f,className:"relative",children:e})})};function ll(e){return e?e.op==="and"||e.op==="or"?(e.rules??[]).flatMap(ll):e.op==="always"?[]:[e.field]:[]}function Su(e){return e!=null&&e.parameters?Object.values(e.parameters).filter(t=>t.type==="field"&&t.fieldRef).map(t=>t.fieldRef):[]}function hW(e){var a,o,i,c,d,u;const t=[];for(const f of e.fields){const h=f.name;if(!h)continue;const p=(a=f.visibleWhen)==null?void 0:a.rule,m=(o=f.disabledWhen)==null?void 0:o.rule,v=(i=f.clearWhen)==null?void 0:i.rule;for(const x of ll(p))t.push({from:x,to:h,kind:"visibleWhen"});for(const x of ll(m))t.push({from:x,to:h,kind:"disabledWhen"});for(const x of ll(v))t.push({from:x,to:h,kind:"clearWhen"});const g=(c=f.visibleWhen)==null?void 0:c.endpoint,b=(d=f.disabledWhen)==null?void 0:d.endpoint,w=(u=f.clearWhen)==null?void 0:u.endpoint;for(const x of Su(g))t.push({from:x,to:h,kind:"visibleWhen"});for(const x of Su(b))t.push({from:x,to:h,kind:"disabledWhen"});for(const x of Su(w))t.push({from:x,to:h,kind:"clearWhen"})}const r=f=>`${f.from}->${f.to}:${f.kind}`,n=new Set;return t.filter(f=>n.has(r(f))?!1:(n.add(r(f)),!0))}const Au={visibleWhen:"var(--color-success-500, #22c55e)",disabledWhen:"var(--color-warning-500, #f59e0b)",clearWhen:"var(--color-info-500, #0ea5e9)"};function Vp(e){return{left:e.x-e.w/2,right:e.x+e.w/2,top:e.y-e.h/2,bottom:e.y+e.h/2,cx:e.x,cy:e.y,w:e.w,h:e.h}}function Zp(e,t,r=20,n=0){const a=Vp(e),o=Vp(t),i=1,c=1,d=o.cx-a.cx,u=o.cy-a.cy,h=Math.min(a.bottom,o.bottom)-Math.max(a.top,o.top)>0||Math.abs(d)>Math.abs(u);let p,m,v=[];if(h)if(d>0?(p={x:a.right+i,y:a.cy},m={x:o.left-c,y:o.cy}):(p={x:a.left-i,y:a.cy},m={x:o.right+c,y:o.cy}),Math.abs(p.y-m.y)<5)v=[p,m];else{const w=(p.x+m.x)/2;if(d>0&&p.x>m.x||d<0&&p.x<m.x){const x=Math.max(a.bottom,o.bottom)+r;v=[p,{x:p.x+(d>0?10:-10),y:p.y},{x:p.x+(d>0?10:-10),y:x},{x:m.x-(d>0?10:-10),y:x},{x:m.x-(d>0?10:-10),y:m.y},m]}else v=[p,{x:w,y:p.y},{x:w,y:m.y},m]}else if(u>0?(p={x:a.cx,y:a.bottom+i},m={x:o.cx,y:o.top-c}):(p={x:a.right+i,y:a.cy},m={x:o.right+c,y:o.cy}),u>0&&Math.abs(p.x-m.x)<5)v=[p,m];else if(u>0){const w=(p.y+m.y)/2;v=[p,{x:p.x,y:w},{x:m.x,y:w},m]}else{const w=Math.max(a.right,o.right)+r;v=[p,{x:w,y:p.y},{x:w,y:m.y},m]}n!==0&&(v=v.map(w=>h?{x:w.x,y:w.y+n}:{x:w.x+n,y:w.y}));let g=`M ${v[0].x},${v[0].y}`;for(let w=1;w<v.length;w++)g+=` L ${v[w].x},${v[w].y}`;let b={x:0,y:0};if(v.length===2)b={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2};else{const w=Math.floor((v.length-1)/2),x=v[w],y=v[w+1];b={x:(x.x+y.x)/2,y:(x.y+y.y)/2}}return{d:g,label:b}}const pW=({enabled:e=!0,anchors:t,schema:r})=>{const n=C.useMemo(()=>r?hW(r):[],[r]),[a,o]=C.useState(null),i=se(f=>f.setSelection),c=se(f=>f.selection),d=(c==null?void 0:c.kind)==="field"?c.name:null,u=C.useMemo(()=>{const f=new Map;return n.forEach(h=>{const p=`${h.from}->${h.to}`;f.has(p)||f.set(p,[]),f.get(p).push(h)}),Array.from(f.entries())},[n]);return!e||!r||n.length===0?null:l.jsxs("svg",{className:"pointer-events-none absolute inset-0 z-50",width:"100%",height:"100%",children:[l.jsxs("defs",{children:[l.jsx("marker",{id:"arrow-head-visibleWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:l.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-success-500, #22c55e)"})}),l.jsx("marker",{id:"arrow-head-disabledWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:l.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-warning-500, #f59e0b)"})}),l.jsx("marker",{id:"arrow-head-clearWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:l.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-info-500, #0ea5e9)"})}),l.jsx("marker",{id:"circle-start-visibleWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:l.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-success-500, #22c55e)"})}),l.jsx("marker",{id:"circle-start-disabledWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:l.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-warning-500, #f59e0b)"})}),l.jsx("marker",{id:"circle-start-clearWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:l.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-info-500, #0ea5e9)"})})]}),u.map(([f,h])=>{const p=h[0],m=t[p.from],v=t[p.to];if(!m||!v)return null;const g=`${f}`,b=a===g,w=!!d&&h.some(I=>I.from===d||I.to===d),x=h[0].kind,y=Au[x];let E=1;b?E=1:a?E=w?.4:.15:d&&(E=w?1:.2);const k=Zp(m,v),{label:j}=k,A=h.length>1?h.map(I=>{const F=I.kind.replace("When","");return F.charAt(0).toUpperCase()+F.slice(1)}).join(" + "):p.kind,S=Math.max(80,A.length*6+20),_=()=>{i({kind:"field",name:p.to})},O=h.length,B=3,R=h.map((I,F)=>(F-(O-1)/2)*B);return l.jsxs("g",{style:{opacity:E,transition:"opacity 0.2s"},onMouseEnter:()=>o(g),onMouseLeave:()=>o(null),onClick:_,className:"pointer-events-auto cursor-pointer",children:[h.map((I,F)=>{const Z=Au[I.kind],{d:ee}=Zp(m,v,20,R[F]),Y=!!d&&(I.from===d||I.to===d),te=b||Y?1.75:1,ae=`url(#arrow-head-${I.kind})`,q=`url(#circle-start-${I.kind})`;return l.jsxs("g",{children:[l.jsx("path",{d:ee,stroke:"transparent",strokeWidth:18,fill:"none"}),l.jsx("path",{d:ee,stroke:Z,strokeWidth:te,fill:"none",markerEnd:ae,markerStart:q,strokeLinejoin:"round",strokeDasharray:I.kind==="disabledWhen"?"5 5":void 0})]},`${g}-${I.kind}-${F}`)}),l.jsxs("g",{transform:`translate(${j.x}, ${j.y})`,children:[l.jsx("rect",{x:-S/2,y:-10,width:S,height:20,rx:4,ry:4,fill:"var(--color-ds-background-page, #f8fafc)",stroke:y,strokeWidth:1,className:"shadow-sm"}),l.jsx("text",{x:0,y:4,textAnchor:"middle",fontSize:10,fontWeight:600,fill:"var(--color-ds-text-primary, #0f172a)",style:{pointerEvents:"none"},children:A}),h.length>1&&l.jsx("g",{transform:"translate(0, 15)",children:h.map((I,F)=>{const Z=Au[I.kind],ee=(F-(h.length-1)/2)*20;return l.jsx("circle",{cx:ee,cy:0,r:3,fill:Z,stroke:"white",strokeWidth:1},F)})})]})]},g)})]})};function zp(e,t){if(!e||!t)return;const r=t==="outline"?ba:Da;let n=r==null?void 0:r[e];return!n&&(r!=null&&r.default)&&(n=r.default[e]),n||console.warn(`[IconResolver] Icon "${e}" (${t}) no encontrado en @heroicons/react/24/${t}. Revisa tu versión o el nombre. Exports disponibles (outline):`,Object.keys(t==="outline"?ba:Da)),console.log(n),n||void 0}function Kr(e){if(!(!e||typeof e!="object"))return console.log(zp(e.name,e.style)),zp(e.name,e.style)}function mW(e){const{fields:t,fieldsByName:r,control:n,errors:a,isSubmitting:o,loadingDefaults:i,asyncOptionsMap:c,adapterOptionsMap:d,evalContainer:u,disabledMap:f,registry:h,methods:p,translateFn:m,onUpdateField:v,isDesignMode:g,systemContext:b={}}=e,w=()=>se.getState().fieldPick,x=E=>se.getState().completeFieldPick(E),y=(E,k)=>{if(!k)return E;const j=w(),A=j.armed,S=A&&j.forField===k,_=A&&!S,O=I=>{A&&(I.preventDefault(),I.stopPropagation(),!S&&x(k))},B=I=>{A&&_&&(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),I.stopPropagation(),x(k))},R=A?S?"opacity-40 cursor-not-allowed":"cursor-pointer transition-all rounded border border-[color-mix(in_srgb,var(--color-ds-border-default)_40%,transparent)] hover:border-[color-mix(in_srgb,var(--color-ds-border-default)_70%,transparent)] hover:bg-[color-mix(in_srgb,var(--color-ds-background-accent)_5%,transparent)]":"";return l.jsx("div",{onClick:O,onKeyDown:B,tabIndex:_?0:-1,className:R,role:_?"button":void 0,"aria-label":_?`Seleccionar campo ${k}`:void 0,children:E})};return function E(k){var ee,Y,te,ae,q;let j;if(typeof k=="string"){if(j=r[k],j||(j=(t??[]).find(N=>(N==null?void 0:N.name)===k)),!j)return null}else j=k;j.visibleWhen;let A=!!j.disabled;const S=j.disabledWhen,_=u(S,!1);S!=null&&S.enabled&&(A=_),!(S!=null&&S.enabled)&&"name"in j&&j.name&&f[j.name]&&(A=!0);const O=j==null?void 0:j.name;if(j.type==="search"){const N=typeof j.searchFn=="function",L=li(j.searchSource,j.endpointConfig),ne=async he=>{if(N)return j.searchFn(he,{getValues:p.getValues,watch:p.watch});if(L){const ie=j.endpointConfig?bn(j.endpointConfig.parameters,p.getValues,b):{},me=h==null?void 0:h[L];if(typeof me=="function")return await me(he,{getValues:p.getValues,watch:p.watch,params:ie,...b});if(Array.isArray(me))return me}return[]},K={};j.searchMode&&(K.searchMode=j.searchMode),j.minChars&&(K.minChars=j.minChars),j.debounceMs&&(K.debounceMs=j.debounceMs),j.resolveByValue&&(K.resolveByValue=j.resolveByValue);const Q=l.jsx(fd,{name:j.name,control:n,searchFn:ne,label:m(j.label),size:j.size,width:j.width,disabled:A||o,...K},j.name);return y(Q,O)}if(j.type==="inputGroup"){const N=j,L=(N.inputs??[]).map(K=>{var le;const Q=typeof K=="string"?r[K]??(t??[]).find(be=>(be==null?void 0:be.name)===K):K;if(!Q)return null;const he=Q.disabledWhen;let ie=!!Q.disabled;const me=u(he,!1);he!=null&&he.enabled&&(ie=me),!(he!=null&&he.enabled)&&f[Q.name]&&(ie=!0);const ce={name:Q.name,control:n,label:m(Q.label),size:Q.size,width:Q.width,placeholder:m(Q.placeholder),hasError:!!a[Q.name],errorMessage:m((le=a[Q.name])==null?void 0:le.message),loading:!1,disabled:ie||o,suffixButton:Q.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:Kr(Q.labelPrefixIcon),labelSuffixIcon:Kr(Q.labelSuffixIcon),prefixIcon:Kr(Q.prefixIcon),suffixIcon:Kr(Q.suffixIcon)};return Q.type==="select"?{...ce,options:Q.options??d[Q.name]??c[Q.name]??[],loadOptions:Q.options||Q.optionSource||Q.endpointConfig?void 0:Q.loadOptions}:{...ce,type:Q.type}}).filter(Boolean),ne=l.jsx(dd,{groupLabel:m(N.groupLabel),inputs:L,separator:N.separator,useSeparator:N.useSeparator,className:N.className,showVisibleLabel:N.showVisibleLabel,size:N.size},`inputGroup_${N.name??N.groupLabel??"group"}`);return y(ne,N.name)}if(j.type==="button"){const N=j,L=N.icon,ne=L&&typeof L=="object"&&L.name&&L.style?Kr(L):void 0,K=l.jsx("div",{className:"self-center",children:l.jsx(pe,{type:"button",variant:N.variant,size:N.size,width:N.width,icon:ne,iconPosition:N.iconPosition,ariaLabel:m(N.ariaLabel),onClick:N.onClick,disabled:A||o,children:m(N.label)})},N.name);return y(K,O)}const B=j.suffixButton,R=typeof B=="string"?E(B):B,I=m(j.label),F=g&&v&&j.name?l.jsx(Du,{value:I,onChange:N=>{const L=se.getState().schema.formId||"defaultForm",ne=j.name,K=`forms.${L}.fields.${ne}.label`;Mo.updateTranslation(K,N),v(ne,{label:K})},placeholder:"Sin etiqueta",className:"font-medium"}):I,Z={name:j.name,control:n,disabled:A||o,label:F,size:j.size,width:j.width,placeholder:m(j.placeholder),info:(()=>{const N=j.info;return N&&typeof N=="object"&&(N.type==="complex"||"header"in N||"template"in N)?N.template?m(N.template):"":m(N)})(),infoHeader:(()=>{const N=j.info;if(N&&typeof N=="object"&&(N.type==="complex"||"header"in N||"template"in N))return N.header||void 0})(),suffixButton:R,labelPrefixIcon:Kr(j.labelPrefixIcon),labelSuffixIcon:Kr(j.labelSuffixIcon),prefixIcon:Kr(j.prefixIcon),suffixIcon:Kr(j.suffixIcon)};switch(j.type){case"select":{const N=j.name,L=j.options??d[N]??c[N]??[],ne=!j.options&&!j.optionSource&&!j.endpointConfig&&j.loadOptions,K=l.jsx(Et,{name:N,control:n,render:({field:Q})=>{var he;return l.jsx(Xe,{...Z,value:Q.value,onChange:Q.onChange,options:L,onBlur:Q.onBlur,loadOptions:ne||void 0,hasError:!!a[N],errorMessage:m((he=a[N])==null?void 0:he.message),suffixButton:R,mode:"menu",searchable:!0,searchPlaceholder:m("ds.fields.defaults.search.placeholder"),noOptionsText:m("ds.fields.defaults.search.noMatches")})}},`${N}`);return y(K,O)}case"iban":{const N=j.name;return y(l.jsx(Et,{name:N,control:n,render:({field:ne,fieldState:K})=>{var Q;return l.jsx(Ci,{...Z,value:ne.value??"",onChange:ne.onChange,onBlur:ne.onBlur,hasError:!!a[N],error:m((Q=a[N])==null?void 0:Q.message),reserveErrorSpace:!0})}},N),O)}case"dni":{const N=j.name;return y(l.jsx(Et,{name:N,control:n,render:({field:ne,fieldState:K})=>{var Q;return l.jsx(pd,{...Z,value:ne.value??"",onChange:ne.onChange,onBlur:ne.onBlur,hasError:!!a[N],error:m((Q=a[N])==null?void 0:Q.message),reserveErrorSpace:!0})}},N),O)}case"textarea":{const N=l.jsx(Et,{name:j.name,control:n,render:({field:L,fieldState:ne})=>{var K;return l.jsx(Dr,{...Z,value:L.value,onChange:L.onChange,onBlur:L.onBlur,maxLength:j.maxLength,showCounter:!!j.showCounter,hasError:!!a[j.name],errorMessage:m((K=a[j.name])==null?void 0:K.message)})}},j.name);return y(N,O)}case"file":{const N=l.jsx(Yc,{...Z,defaultValue:[],maxFiles:j.maxFiles,accept:j.accept,hideDropZone:j.hideDropZone,hasError:!!a[j.name],errorMessage:m((ee=a[j.name])==null?void 0:ee.message)},j.name);return y(N,O)}case"checkbox":{const N=l.jsx(it,{...Z,defaultValue:!1,hasError:!!a[j.name],errorMessage:m((Y=a[j.name])==null?void 0:Y.message),name:j.name},j.name);return y(N,O)}case"date":{const N=l.jsx(Sa,{...Z,defaultValue:"",showTime:!!j.showTime,hasError:!!a[j.name],errorMessage:m((te=a[j.name])==null?void 0:te.message)},j.name);return y(N,O)}case"optionGroup":{const N=l.jsx(ki,{...Z,options:j.options||[],multiple:j.multiple,vertical:j.vertical,groupLabel:j.groupLabel,defaultValue:j.defaultValue,className:j.width?void 0:"w-full",name:j.name},j.name);return y(N,O)}case"toggle":{const N=l.jsx(vd,{...Z,checked:j.defaultValue??!1,errorMessage:m((ae=a[j.name])==null?void 0:ae.message),name:j.name},j.name);return y(N,O)}case"table":{const N=j.columns??[],L=j.endpointConfig;let ne;L&&(ne=async()=>{const Q=L.key;if(!Q)return[];const he=bn(L.parameters,p.getValues,b),ie=h==null?void 0:h[Q];return typeof ie=="function"?await ie(he):(console.warn(`Provider factory for key "${Q}" not found in registry.`),[])});const K=l.jsx(ef,{columns:N,loadData:ne,idAccessor:j.idAccessor||"id",className:j.className},j.name);return y(K,O)}default:{const N=l.jsx(ii,{...Z,type:j.type,loadingDefaults:i,hasError:!!a[j.name],errorMessage:m((q=a[j.name])==null?void 0:q.message),suffixButton:R,name:j.name},j.name);return y(N,O)}}}}function gW(e){var r;return e?!!((r=e.closest)!=null&&r.call(e,'button,[role="button"],a[href],input,select,textarea,[contenteditable="true"],[data-interactive="true"]')):!1}function vW(e){var r;return e?!!((r=e.closest)!=null&&r.call(e,'[data-input-group-root],[data-input-group],[data-role="input-group"],.input-group,.InputGroup')):!1}function is(e){var t;e.preventDefault(),e.stopPropagation(),(t=e.nativeEvent)!=null&&t.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()}function bW({id:e,children:t,onDelete:r,fieldName:n,chromeDisabled:a=!1}){const{attributes:o,listeners:i,setNodeRef:c,transform:d,transition:u,isDragging:f}=Gh({id:e,disabled:a}),h=se(b=>b.setSelection),p={transform:Wr.Transform.toString(d),transition:u},m="opacity-0 scale-95 group-hover:opacity-100 group-hover:scale-100 group-focus-within:opacity-100 group-focus-within:scale-100",v=b=>{const w=b.target;gW(w)||vW(w)||n&&(b.stopPropagation(),h({kind:"field",name:n}))},g=b=>{is(b)};return l.jsxs("div",{ref:c,style:p,className:["relative",a?"":"group",f?"z-30":"z-0"].filter(Boolean).join(" "),onClickCapture:v,onDoubleClick:g,onDoubleClickCapture:g,children:[!a&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:["pointer-events-none absolute -inset-0.5 rounded-lg","bg-[var(--color-ds-background-surface)]/80","border border-dashed border-[var(--color-ds-border-default-50)]","transition-all duration-150 ease-out",m,f?"opacity-100 scale-100":""].join(" ")}),l.jsxs("div",{className:["pointer-events-none absolute -top-3 right-2 flex gap-1 z-40","transition-all duration-150 ease-out",m,f?"opacity-100 scale-100":""].join(" "),children:[r&&l.jsx("button",{type:"button","aria-label":"Eliminar campo",className:["pointer-events-auto inline-flex items-center justify-center","w-7 h-7 rounded-full","bg-[var(--color-ds-background-surface)]","border border-[var(--color-ds-border-default-50)]","text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-danger)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-ds-border-default-50)]","transition-colors"].join(" "),onClick:b=>{b.preventDefault(),b.stopPropagation(),r==null||r(e)},onDoubleClick:is,onDoubleClickCapture:is,children:l.jsx(Dt,{className:"w-4 h-4"})}),l.jsx("button",{type:"button","aria-label":"Mover campo","data-drag-handle":!0,className:["pointer-events-auto inline-flex items-center justify-center","w-8 h-8 rounded-full cursor-grab active:cursor-grabbing touch-none","bg-[var(--color-ds-background-surface)]","border border-[var(--color-ds-border-default-50)]","text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-ds-border-default-50)]","transition-colors"].join(" "),...o,...i,onDoubleClick:is,onDoubleClickCapture:is,children:l.jsx(Hl,{className:"w-4 h-4"})})]})]}),l.jsx("div",{className:"relative z-10",children:t})]})}function wW(e,t){if(!t||t.kind!=="row-in-section"&&t.kind!=="row-in-tab-section")return!1;const r=n=>e.insertAt===n||e.insertAt===n+1;if(e.scope==="row-slot"){if(t.kind==="row-in-section"&&t.li===e.li&&t.sIdx===e.sIdx&&r(t.rIdx))return!0}else if(e.scope==="tab-row-slot"&&t.kind==="row-in-tab-section"&&t.li===e.li&&t.tabKey===e.tabKey&&t.sIdx===e.sIdx&&r(t.rIdx))return!0;return!1}function cl(e){const t=e.scope==="row-slot"?{scope:"row-slot",li:e.li,sIdx:e.sIdx,insertAt:e.insertAt}:{scope:"tab-row-slot",li:e.li,tabKey:e.tabKey,sIdx:e.sIdx,insertAt:e.insertAt},r=e.scope==="row-slot"?`row-slot|li:${e.li}|s:${e.sIdx}|i:${e.insertAt}`:`tab-row-slot|li:${e.li}|t:${e.tabKey}|s:${e.sIdx}|i:${e.insertAt}`,{setNodeRef:n,isOver:a}=Sr({id:r,data:t}),[o,i]=C.useState(void 0);return zo({onDragStart:u=>{i(u.active.data.current)},onDragEnd:()=>i(void 0),onDragCancel:()=>i(void 0)}),wW(e,o)?l.jsx("div",{ref:n,style:{display:"none"}}):l.jsx("div",{className:"w-full relative transition-all duration-200 ease-in-out",style:{height:a?60:0,pointerEvents:"none",zIndex:a?10:0},children:l.jsx("div",{ref:n,className:"absolute left-0 right-0",style:{top:a?0:-12,height:a?"100%":24,zIndex:a?10:2,pointerEvents:"auto"},children:a&&l.jsx("div",{className:"w-full h-full rounded-md border border-dashed border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background)]/60 relative",style:{boxShadow:"inset 0 0 0 1px color-mix(in srgb, var(--color-ds-border-default-50) 30%, transparent)"},children:l.jsx("div",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[11px] leading-none",style:{background:"var(--color-ds-background-elevated)",color:"var(--color-ds-text-secondary)",border:"1px solid var(--color-ds-border-default-50)"},children:"Soltar fila aquí"})})})})}function Hp(e){const t=e.kind==="row-in-section"?{kind:"row-in-section",li:e.li,sIdx:e.sIdx,rIdx:e.rIdx}:{kind:"row-in-tab-section",li:e.li,tabKey:e.tabKey,sIdx:e.sIdx,rIdx:e.rIdx},r=e.kind==="row-in-section"?`row|li:${e.li}|s:${e.sIdx}|r:${e.rIdx}`:`tab-row|li:${e.li}|t:${e.tabKey}|s:${e.sIdx}|r:${e.rIdx}`,{attributes:n,listeners:a,setNodeRef:o,isDragging:i}=Jn({id:r,data:t});return l.jsx("div",{ref:o,"aria-label":"Handle de arrastre de fila",style:{position:"absolute",left:"50%",top:-14,transform:"translateX(-50%)",zIndex:2147483647,pointerEvents:e.visible?"auto":"none",opacity:e.visible?1:0,transition:"opacity .12s ease"},...a,...n,children:l.jsx("div",{className:"flex items-center justify-center bg-[var(--color-ds-background-elevated)]/85 backdrop-blur-sm px-1 py-0.5 rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm",children:l.jsx("div",{title:"Mover fila (arrastrar)",className:"flex items-center justify-center rounded hover:bg-[var(--color-ds-background-muted)] transition-colors",style:{cursor:i?"grabbing":"grab",touchAction:"none",padding:"2px 6px"},children:l.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",className:"w-4 h-4 text-[var(--color-ds-text-secondary)]",children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 9h16.5m-16.5 6.75h16.5"})})})})})}function xW(e){const r={text:()=>({label:"ds.fields.defaults.text.label",type:"text",width:"w-full",placeholder:"ds.fields.defaults.text.placeholder",size:"sm"}),number:()=>({label:"ds.fields.defaults.number.label",type:"number",width:"w-full",placeholder:"ds.fields.defaults.number.placeholder",size:"sm",validation:{required:!1}}),email:()=>({label:"ds.fields.defaults.email.label",type:"email",width:"w-full",placeholder:"ds.fields.defaults.email.placeholder",size:"sm"}),password:()=>({label:"ds.fields.defaults.password.label",type:"password",width:"w-full",placeholder:"ds.fields.defaults.password.placeholder",size:"sm",validation:{minLength:8}}),tel:()=>({label:"ds.fields.defaults.tel.label",type:"tel",width:"w-full",placeholder:"ds.fields.defaults.tel.placeholder",size:"sm"}),url:()=>({label:"ds.fields.defaults.url.label",type:"url",width:"w-full",placeholder:"ds.fields.defaults.url.placeholder",size:"sm"}),select:()=>({label:"ds.fields.defaults.select.label",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}),checkbox:()=>({label:"ds.fields.defaults.checkbox.label",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}),textarea:()=>({label:"ds.fields.defaults.textarea.label",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"ds.fields.defaults.textarea.placeholder"}),date:()=>({label:"ds.fields.defaults.date.label",type:"date",width:"w-full",size:"sm",showTime:!1}),file:()=>({label:"ds.fields.defaults.file.label",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}),inputGroup:()=>({label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}),search:()=>({label:"ds.fields.defaults.search.label",type:"search",width:"w-full",placeholder:"ds.fields.defaults.search.placeholder",size:"sm",searchMode:"button"}),optionGroup:()=>({label:"Selecciona opciones",type:"optionGroup",width:"w-full",size:"sm",multiple:!0,vertical:!0,options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}]}),array:()=>({label:"Lista repetible",type:"array",width:"w-full",items:[]}),button:()=>({label:"Botón",type:"button",width:"w-auto",variant:"primary",size:"sm"}),iban:()=>({label:"ds.fields.defaults.iban.label",type:"iban",width:"w-full",placeholder:"ds.fields.defaults.iban.placeholder",size:"sm",validation:{required:!1}}),table:()=>({label:"Tabla de Datos",type:"table",width:"w-full",size:"sm",columns:[{header:"ID",accessor:"id",width:"w-16"},{header:"Nombre",accessor:"name",width:"w-auto"}]})}[e];return r?r():{type:e}}function yW(e){return typeof e=="function"}function ls(e,t){if(!e||!t)return null;const r=t==="outline"?ba:Da,n=r==null?void 0:r[e];return yW(n)?n:null}function Nu(e){var c,d,u,f,h,p,m,v;if(!e||typeof e!="object")return e;if(e.type==="inputGroup"){const g=e,b={...g};return Array.isArray(g.inputs)&&(b.inputs=g.inputs.map(w=>typeof w=="string"?w:Nu(w))),b}const t=e,r={...t},n=ls((c=t.labelPrefixIcon)==null?void 0:c.name,(d=t.labelPrefixIcon)==null?void 0:d.style),a=ls((u=t.labelSuffixIcon)==null?void 0:u.name,(f=t.labelSuffixIcon)==null?void 0:f.style),o=ls((h=t.prefixIcon)==null?void 0:h.name,(p=t.prefixIcon)==null?void 0:p.style),i=ls((m=t.suffixIcon)==null?void 0:m.name,(v=t.suffixIcon)==null?void 0:v.style);return n&&(r.labelPrefixIcon=n),a&&(r.labelSuffixIcon=a),o&&(r.prefixIcon=o),i&&(r.suffixIcon=i),r}function kW({name:e,children:t}){const r=uW(e);return l.jsx("div",{ref:r,"data-field":e,style:{position:"relative"},children:t})}function Wp(e){return e.startsWith("row|")?Object.fromEntries(e.slice(4).split(";").map(r=>r.split(":"))):{}}function EW(e,t){const r=Wp(e),n=Wp(t);return r.ctx===n.ctx&&r.li===n.li&&r.s===n.s&&(r.t??"")===(n.t??"")}function Up(e,t){if(!e.startsWith("col|"))return ss(e);const r=Object.fromEntries(e.slice(4).split(";").map(i=>i.split(":"))),n=r.ctx==="rows"?`rows|li:${r.li}|s:${r.s}|r:${r.r}|c:${r.c}`:`tabs|li:${r.li}|t:${r.t}|s:${r.s}|r:${r.r}|c:${r.c}`,a=(t[n]??[]).length,o=Object.prototype.hasOwnProperty.call(r,"insertAt");return{li:Number(r.li),tabIdx:r.t?Number(r.t):void 0,sectionIdx:Number(r.s),rowIdx:Number(r.r),colIdx:Number(r.c),fieldIdx:o?Number(r.insertAt):a}}function CW(e,t){const r=Array.from(e.querySelectorAll("[data-sortable-item]"));if(!r.length)return{insertAt:0,yAbs:e.getBoundingClientRect().top+8};let n=r.length,a=r[r.length-1].getBoundingClientRect().bottom;for(let o=0;o<r.length;o++){const i=r[o].getBoundingClientRect(),c=(i.top+i.bottom)/2;if(t<c){n=o,a=i.top;break}}return{insertAt:n,yAbs:a}}function jW(e){C.useEffect(()=>{if(!e)return;let t=0;const r=()=>{const n=document.getElementById("form-renderer-root");if(!n){t=requestAnimationFrame(r);return}const a=n.getBoundingClientRect(),o=window.__lastPointerY,i=80,c=14;typeof o=="number"&&(o<a.top+i?window.scrollBy({top:-c}):o>a.bottom-i&&window.scrollBy({top:c})),t=requestAnimationFrame(r)};return t=requestAnimationFrame(r),()=>cancelAnimationFrame(t)},[e])}function DW(e){const t=e.replaceAll("|",";");return t.startsWith("rows;")?`col|ctx:rows;${t.slice(5)}`:t.startsWith("tabs;")?`col|ctx:tabs;${t.slice(5)}`:`col|${t}`}function SW({droppableId:e,children:t,className:r,scope:n,li:a,tabIdx:o,sectionIdx:i,rowIdx:c,colIdx:d}){const u=n?{scope:n,...n==="rows-column"?{rowsNodeIdx:a}:{tabKey:`tab-${o}`},s:i,r:c,c:d,insertAt:0}:void 0,{isOver:f,setNodeRef:h}=Sr({id:e,data:u});return l.jsx("div",{ref:h,className:["relative min-h-[28px] h-full overflow-visible transition-[box-shadow,border-color] duration-100",f?"ring-1 ring-[var(--color-ds-border-default-50)] rounded":"",r??""].join(" "),style:{isolation:"isolate"},"data-droppable-col":!0,children:t})}function AW(e,t){var n,a,o,i,c,d,u,f,h;const r=e.layout[t.li];if(r)return r.type==="rows"?(i=(o=(a=(n=r.sections[t.sectionIdx])==null?void 0:n.rows[t.rowIdx])==null?void 0:a.columns[t.colIdx])==null?void 0:o.fields)==null?void 0:i[t.fieldIdx]:(h=(f=(u=(d=(c=r.tabs[t.tabIdx])==null?void 0:c.sections[t.sectionIdx])==null?void 0:d.rows[t.rowIdx])==null?void 0:u.columns[t.colIdx])==null?void 0:f.fields)==null?void 0:h[t.fieldIdx]}function qp({ctx:e,visible:t}){const{t:r}=At(),n=se(k=>k.addColumnToRow),a=se(k=>k.setRowColumns),o=se(k=>k.removeLastColumn),i=se(k=>k.addRowToSectionAt),c=se(k=>k.addColumnToTabRow),d=se(k=>k.setTabRowColumns),u=se(k=>k.removeLastTabColumn),f=se(k=>k.addRowToTabSectionAt),h=()=>e.kind==="rows"?n==null?void 0:n(e.sectionIdx,e.rowIdx):c==null?void 0:c(e.tabKey,e.sectionIdx,e.rowIdx),p=()=>e.kind==="rows"?o==null?void 0:o(e.sectionIdx,e.rowIdx):u==null?void 0:u(e.tabKey,e.sectionIdx,e.rowIdx),m=k=>e.kind==="rows"?a==null?void 0:a(e.sectionIdx,e.rowIdx,k):d==null?void 0:d(e.tabKey,e.sectionIdx,e.rowIdx,k),v=()=>e.kind==="rows"?i==null?void 0:i(e.sectionIdx,e.rowIdx):f==null?void 0:f(e.tabKey,e.sectionIdx,e.rowIdx),g=()=>e.kind==="rows"?i==null?void 0:i(e.sectionIdx,e.rowIdx+1):f==null?void 0:f(e.tabKey,e.sectionIdx,e.rowIdx+1),[b,w]=C.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}}),x=(k,j,A)=>{w({isOpen:!0,title:k,message:j,onConfirm:A})},y=()=>{b.onConfirm(),w(k=>({...k,isOpen:!1}))},E=()=>{w(k=>({...k,isOpen:!1}))};return l.jsxs("div",{"aria-label":"Acciones de fila",style:{position:"absolute",insetInlineEnd:6,insetBlockStart:-25,zIndex:2147483646,pointerEvents:t?"auto":"none",opacity:t?1:0,transition:"opacity .12s ease"},className:"flex items-center gap-1",children:[l.jsxs("div",{className:"flex items-center gap-1 bg-[var(--color-ds-background-elevated)]/85 backdrop-blur-sm px-1.5 py-1 rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm",children:[l.jsx(pe,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addRow"),onClick:v,children:"↑"}),l.jsx(pe,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addRow"),onClick:g,children:"↓"}),l.jsx("span",{className:"w-px h-4 bg-[var(--color-ds-border-default-50)] mx-1","aria-hidden":!0}),l.jsx(pe,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addColumn"),onClick:h,children:"+"}),l.jsx(pe,{size:"xs",variant:"ghost",title:r("ds.editor.actions.deleteColumn"),onClick:()=>x(r("ds.editor.confirmations.deleteColumn.title"),r("ds.editor.confirmations.deleteColumn.message"),p),children:"−"}),l.jsx("span",{className:"w-px h-4 bg-[var(--color-ds-border-default-50)] mx-1","aria-hidden":!0}),[1,2,3,4].map(k=>l.jsx(pe,{size:"xs",variant:"ghost",title:`Distribuir en ${k} columna(s)`,onClick:()=>m(k),children:k},k))]}),l.jsx(Bt,{isOpen:b.isOpen,onClose:E,title:b.title,footer:l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx(pe,{variant:"outline",onClick:E,children:r("ds.editor.actions.cancel")}),l.jsx(pe,{variant:"danger",onClick:y,children:r("ds.editor.actions.delete")})]}),children:l.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:b.message})})]})}function NW({schema:e,onSchemaChange:t,deps:r,layoutEditMode:n=!1}){const{t:a}=At(),o=se(U=>U.updateField),i=se(U=>U.mode),c=Wn(U=>U.setRuntimeState),d=Wn(U=>U.systemContext);C.useEffect(()=>{if(!e.variables)return;const U={};e.variables.forEach(J=>{J.type==="constant"&&(U[J.key]=J.value)}),e.variables.forEach(J=>{if(J.type==="computed"&&J.value)try{const oe=new Function("ctx",`return (${J.value});`);U[J.key]=oe(U)}catch(oe){console.warn(`[FormRendererDnd] Error evaluating computed variable "${J.key}":`,oe),U[J.key]=null}}),Object.keys(U).length>0&&c({systemContext:U})},[e.variables,c]);const u=C.useMemo(()=>({...r,translateFn:(U,J)=>{const oe=mt(a,U,J);return oe?cd(oe,d):""},onUpdateField:(U,J)=>{o(U,oe=>{Object.assign(oe,J)})},isDesignMode:i==="design"}),[r,a,o,i,d]),f=C.useCallback((U,J)=>{const oe=mt(a,U,J);return oe?cd(oe,d):""},[a,d]),h=C.useMemo(()=>mW(u),[u]),p=se(U=>U.selection),m=(p==null?void 0:p.kind)==="field"?p.name:void 0,g=se(U=>U.fieldPick).armed,{enabled:b,anchors:w,setSchema:x}=Pp();C.useEffect(()=>{x(e)},[e,x]);const[y,E]=C.useState(null),[k,j]=C.useState(null),A=C.useRef({}),S=C.useCallback(U=>J=>{A.current[U]=J},[]),_=C.useRef(null),O=C.useRef(null),B=C.useRef(null),R=U=>{O.current==null&&(O.current=requestAnimationFrame(()=>{O.current=null;const J=B.current;JSON.stringify(J)!==JSON.stringify(U)&&(B.current=U,j(U))}))},I=C.useMemo(()=>{const U={};return e.layout.forEach((J,oe)=>{J.type==="tabs"&&(U[oe]=J.tabs[0].key)}),U},[e.layout]),[F,Z]=C.useState(I),[ee,Y]=C.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}}),te=(U,J,oe)=>{Y({isOpen:!0,title:U,message:J,onConfirm:oe})},ae=()=>{ee.onConfirm(),Y(U=>({...U,isOpen:!1}))},q=()=>{Y(U=>({...U,isOpen:!1}))},N=C.useMemo(()=>{const U={};return e.layout.forEach((J,oe)=>{J.type==="rows"?J.sections.forEach((de,ge)=>{de.rows.forEach((we,Ce)=>{we.columns.forEach((ke,Ie)=>{const Le=`rows|li:${oe}|s:${ge}|r:${Ce}|c:${Ie}`;U[Le]=(ke.fields??[]).map((De,Re)=>$p({li:oe,sectionIdx:ge,rowIdx:Ce,colIdx:Ie,fieldIdx:Re}))})})}):J.type==="tabs"&&J.tabs.forEach((de,ge)=>{de.sections.forEach((we,Ce)=>{we.rows.forEach((ke,Ie)=>{ke.columns.forEach((Le,De)=>{const Re=`tabs|li:${oe}|t:${ge}|s:${Ce}|r:${Ie}|c:${De}`;U[Re]=(Le.fields??[]).map((Ve,Ge)=>$p({li:oe,tabIdx:ge,sectionIdx:Ce,rowIdx:Ie,colIdx:De,fieldIdx:Ge}))})})})})}),U},[e]),L=C.useMemo(()=>{const U={};return Object.entries(N).forEach(([J,oe])=>oe.forEach(de=>U[de]=J)),U},[N]),ne=Bd(Ba(Uo,{activationConstraint:{distance:6}}),Ba(Wo,{coordinateGetter:Kh})),K="__phantom__",[Q,he]=C.useState(!1),[ie,me]=C.useState(null),[ce,le]=C.useState(null),[be,fe]=C.useState(40),[xe,D]=C.useState(null),[G,re]=C.useState(null),W=C.useCallback(U=>{if(!U)return!1;if(typeof U=="string"){const J=r.fieldsByName[U];return!!J&&J.type==="inputGroup"}return(U==null?void 0:U.type)==="inputGroup"},[r.fieldsByName]),H=U=>{var Ce;const J=String(((Ce=U.active)==null?void 0:Ce.id)??""),oe=zd(U),de=oe[0],ge=de?String(de.id):null;if(ge&&L[ge]&&L[J]&&L[ge]===L[J])return oe;const we=xB(U);if(J.startsWith("row|")||J.startsWith("tab-row|")){const ke=we.filter(Ie=>String(Ie.id).startsWith("row-slot|")||String(Ie.id).startsWith("tab-row-slot|"));if(ke.length)return ke}else{const ke=we.filter(Ie=>String(Ie.id).startsWith("col|"));if(ke.length)return ke}return oe};zo({onDragStart:U=>{var de,ge,we,Ce,ke,Ie;he(!0);const J=String(U.active.id??"");me(J),le(L[J]??null),_.current=J.startsWith("row|")?"row":"field";const oe=((ge=(de=U.active.rect.current)==null?void 0:de.translated)==null?void 0:ge.height)??((Ce=(we=U.active.rect.current)==null?void 0:we.initial)==null?void 0:Ce.height)??40;if(fe(Math.max(24,Math.floor(oe))),_.current==="field"&&!J.startsWith("col|")&&!J.startsWith("palette:"))try{const Le=ss(J),De=(ke=e.layout)==null?void 0:ke[Le.li],Ve=(Ie=((De==null?void 0:De.type)==="rows"?De.sections[Le.sectionIdx].rows[Le.rowIdx].columns[Le.colIdx]:De.tabs[Le.tabIdx].sections[Le.sectionIdx].rows[Le.rowIdx].columns[Le.colIdx]).fields)==null?void 0:Ie[Le.fieldIdx??0],Ge=Ve&&Nu(Ve);D(Ge?h(Ge):null)}catch{D(null)}else D(null)},onDragOver:U=>{var Ie,Le;const J=String(((Ie=U.over)==null?void 0:Ie.id)??""),oe=String(((Le=U.active)==null?void 0:Le.id)??""),de=U.activatorEvent;if(de&&typeof de.clientY=="number"&&(window.__lastPointerY=de.clientY),_.current==="row"){if(J.startsWith("row|")&&oe.startsWith("row|"))if(EW(oe,J)&&oe!==J){const De=A.current[J],Re=(de==null?void 0:de.clientY)??0;if(De&&Re){const Ve=De.getBoundingClientRect(),Ge=Re<Ve.top+Ve.height/2?"before":"after";R({rid:J,pos:Ge})}else R(null)}else R(null);else R(null);re(null);return}if(!J.startsWith("col|")){re(null);return}const ge=Object.fromEntries(J.slice(4).split(";").map(De=>De.split(":"))),we=ge.ctx==="rows"?`rows|li:${ge.li}|s:${ge.s}|r:${ge.r}|c:${ge.c}`:`tabs|li:${ge.li}|t:${ge.t}|s:${ge.s}|r:${ge.r}|c:${ge.c}`,Ce=document.querySelector(`[data-col-key="${we}"]`),ke=(de==null?void 0:de.clientY)??0;if(Ce&&ke){const{insertAt:De,yAbs:Re}=CW(Ce,ke),Ve=Ce.getBoundingClientRect().top;re({overId:J,keyId:we,insertAt:De,yRel:Re-Ve})}else re(null)},onDragCancel:U=>{he(!1),me(null),le(null),fe(40),D(null),re(null),j(null),_.current=null,O.current&&(cancelAnimationFrame(O.current),O.current=null),B.current=null},onDragEnd:()=>{he(!1),me(null),le(null),fe(40),D(null),j(null),_.current=null,O.current&&(cancelAnimationFrame(O.current),O.current=null),B.current=null}}),jW(Q);const X=C.useCallback(U=>{const{active:J,over:oe}=U;if(!(J!=null&&J.id)||!(oe!=null&&oe.id)){re(null),j(null);return}const de=J.data.current,ge=oe.data.current;if(((de==null?void 0:de.kind)==="row-in-section"||(de==null?void 0:de.kind)==="row-in-tab-section")&&((ge==null?void 0:ge.scope)==="row-slot"||(ge==null?void 0:ge.scope)==="tab-row-slot")){const De=de.li,Re=de.sIdx,Ve=de.rIdx,Ge=ge.li,ft=ge.sIdx,Ne=ge.insertAt,Fe={...e,layout:[...e.layout]},Me={...Fe.layout[De]};Fe.layout[De]=Me;let _e=null,Te=null,Ze=null;if(de.kind==="row-in-section"&&Me.type==="rows")Me.sections=[...Me.sections],Te={...Me.sections[Re]},Me.sections[Re]=Te,Te.rows=[...Te.rows],_e=Te.rows;else if(de.kind==="row-in-tab-section"&&Me.type==="tabs"){Me.tabs=[...Me.tabs];const Ye=Me.tabs.findIndex(Ke=>Ke.key===de.tabKey);Ye>=0&&(Ze={...Me.tabs[Ye]},Me.tabs[Ye]=Ze,Ze.sections=[...Ze.sections],Te={...Ze.sections[Re]},Ze.sections[Re]=Te,Te.rows=[...Te.rows],_e=Te.rows)}if(!_e)return;let He=null,Ue=null;if(De===Ge?Ue=Me:(Ue={...Fe.layout[Ge]},Fe.layout[Ge]=Ue),ge.scope==="row-slot"&&Ue.type==="rows")if(Ue.sections===Me.sections||(Ue.sections=[...Ue.sections]),De===Ge&&Re===ft&&de.kind==="row-in-section")He=_e;else{const Ye={...Ue.sections[ft]};Ue.sections[ft]=Ye,Ye.rows=[...Ye.rows],He=Ye.rows}else if(ge.scope==="tab-row-slot"&&Ue.type==="tabs"){Ue.tabs===Me.tabs||(Ue.tabs=[...Ue.tabs]);const Ye=Ue.tabs.findIndex(Ke=>Ke.key===ge.tabKey);if(Ye>=0){let Ke=Ue.tabs[Ye];if(De===Ge&&de.kind==="row-in-tab-section"&&de.tabKey===ge.tabKey?Ke=Ze:(Ke={...Ke},Ue.tabs[Ye]=Ke),Ke.sections===(Ze==null?void 0:Ze.sections)||(Ke.sections=[...Ke.sections]),De===Ge&&Re===ft&&de.kind==="row-in-tab-section"&&de.tabKey===ge.tabKey)He=_e;else{const ht={...Ke.sections[ft]};Ke.sections[ft]=ht,ht.rows=[...ht.rows],He=ht.rows}}}if(!He)return;const[Tt]=_e.splice(Ve,1);let ze=Ne;_e===He&&Ve<Ne&&(ze-=1),He.splice(ze,0,Tt),t(Fe),re(null),j(null);return}if((de==null?void 0:de.kind)==="palette-field"){const De=String(oe.id);if(!De.startsWith("col|")){re(null),j(null);return}const Re=Object.fromEntries(De.slice(4).split(";").map(Me=>Me.split(":"))),Ve=G&&G.overId===De?G.insertAt:Re.insertAt?Number(Re.insertAt):0,Ge={li:Number(Re.li),tabIdx:Re.t!=null?Number(Re.t):void 0,sectionIdx:Number(Re.s),rowIdx:Number(Re.r),colIdx:Number(Re.c),fieldIdx:Ve},ft=de.factoryKind,Ne=xW(ft),Fe=dW(e,Ne,Ge);re(null),j(null),t(Fe);return}const we=String(J.id),Ce=String(oe.id);if(we.startsWith("row|")&&Ce.startsWith("row|"),we.startsWith("palette:")){re(null),j(null);return}const ke=ss(we);let Ie;if(Ce.startsWith("col|")&&G&&G.overId===Ce){const De=Object.fromEntries(Ce.slice(4).split(";").map(Ve=>Ve.split(":"))),Re=`col|${Object.entries(De).filter(([Ve])=>Ve!=="insertAt").map(([Ve,Ge])=>`${Ve}:${Ge}`).join(";")};insertAt:${G.insertAt}`;Ie=Up(Re,N)}else Ie=Up(Ce,N);const Le=iW(e,ke,Ie);re(null),j(null),t(Le)},[e,t,N,G]);function M(U,J){let oe=U;if(ie&&ce&&ce!==J&&(oe=oe.filter(de=>de!==ie)),Q&&G&&G.keyId===J){const de=Math.max(0,Math.min(G.insertAt,oe.length)),ge=oe.slice();return ge.splice(de,0,K),ge}return oe}const V=({keyId:U,ids:J,className:oe,tabKey:de})=>{const ge=DW(U),we=M(J,U),Ce=Object.fromEntries(U.split("|").map(Ne=>Ne.split(":"))),ke=U.startsWith("rows|"),Ie=ke?"rows-column":"tabs-column",Le=Number(Ce.li),De=Ce.t!=null?Number(Ce.t):void 0,Re=Number(Ce.s),Ve=Number(Ce.r),Ge=Number(Ce.c),ft=J.length;return l.jsx(SW,{droppableId:ge,className:oe,scope:Ie,li:Le,tabIdx:De,sectionIdx:Re,rowIdx:Ve,colIdx:Ge,children:l.jsxs("div",{"data-col-key":U,className:"relative",children:[ke?l.jsx(Fr,{scope:"rows-column",rowsNodeIdx:Le,s:Re,r:Ve,c:Ge,insertAt:0,suppressAll:ft===0}):de?l.jsx(Fr,{scope:"tabs-column",tabKey:de,s:Re,r:Ve,c:Ge,insertAt:0,suppressAll:ft===0}):null,Q&&G&&G.overId===ge?l.jsx("div",{"aria-hidden":!0,style:{position:"absolute",left:0,right:0,top:Math.max(0,G.yRel-1),height:2,background:"var(--color-ds-border-default)",borderRadius:2}}):null,l.jsx(Uh,{items:we,strategy:zh,children:l.jsx("div",{children:we.map((Ne,Fe)=>{if(Ne===K)return l.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0,style:{height:be,border:"1px dashed var(--color-ds-border-default-50)",borderRadius:8,background:"color-mix(in srgb, var(--color-ds-border-default-50) 8%, transparent)"}},`${U}-ph-${Fe}`);const Me=ss(String(Ne)),_e=AW(e,Me);if(!_e)return l.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0},`${U}-miss-${Fe}`);const Te=Nu(_e),Ze=typeof Te=="string"?Te:(Te==null?void 0:Te.name)??"",He=!!m&&!!Ze&&m===Ze,Ue=h(Te),Tt=W(Te),ze=Ke=>{var ht;Ke.preventDefault(),Ke.stopPropagation(),(ht=Ke.nativeEvent)!=null&&ht.stopImmediatePropagation&&Ke.nativeEvent.stopImmediatePropagation()},Ye=Tt?{onDoubleClick:ze,onDoubleClickCapture:ze,onClick:ze,onClickCapture:ze,onMouseDown:ze,onMouseDownCapture:ze,onMouseUp:ze,onMouseUpCapture:ze,onPointerDown:ze,onPointerDownCapture:ze,onPointerUp:ze,onPointerUpCapture:ze,onContextMenu:ze}:{};return l.jsx("div",{"data-sortable-item":!0,children:l.jsx(bW,{id:String(Ne),fieldName:Ze,onDelete:Ke=>{const ht=ss(Ke);te("Eliminar campo","¿Estás seguro de que quieres eliminar este campo?",()=>{const $r=lW(e,ht);t($r)})},chromeDisabled:g,children:l.jsx(kW,{name:Ze,children:l.jsx("div",{className:He?"selected-field":void 0,"data-field-name":Ze,"aria-selected":He||void 0,...Ye,children:Ue})})})},String(Ne))})})})]})})},T=Q&&_.current==="row",$=(U,J)=>l.jsx(l.Fragment,{children:U.sections.map((oe,de)=>l.jsx("div",{className:"mb-6",children:l.jsx(lt,{title:f(oe.sectionTitle),defaultOpen:oe.defaultOpen,forceOpen:T,children:l.jsxs("div",{className:"flex flex-col",children:[l.jsx(cl,{scope:"row-slot",li:J,sIdx:de,insertAt:0}),oe.rows.map((ge,we)=>{const Ce=`row|li:${J}|s:${de}|r:${we}`,ke=n&&y===Ce,Ie=ie===Ce;return l.jsxs(C.Fragment,{children:[l.jsxs("div",{ref:S(Ce),className:`relative transition-all duration-200 ${Ie?"opacity-40 ring-1 ring-dashed ring-[var(--color-ds-border-default)] bg-[var(--color-ds-background-muted)]":n&&ke?"ring-1 ring-[var(--color-ds-border-default-50)]":""}`,onMouseEnter:()=>E(Ce),onMouseLeave:()=>E(Le=>Le===Ce?null:Le),style:{borderRadius:8},children:[n&&l.jsxs(l.Fragment,{children:[l.jsx(qp,{ctx:{kind:"rows",li:J,sectionIdx:de,rowIdx:we},visible:!!ke&&!g}),l.jsx(Hp,{kind:"row-in-section",li:J,sIdx:de,rIdx:we,visible:!!ke&&!g})]}),ge.title&&l.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:f(ge.title)}),l.jsx("div",{className:"flex flex-wrap -mx-2 items-stretch",children:ge.columns.map((Le,De)=>{const Re=`rows|li:${J}|s:${de}|r:${we}|c:${De}`,Ve=N[Re]??[];return l.jsx("div",{className:`${Le.width} px-2 flex flex-col`,children:l.jsx(V,{keyId:Re,ids:Ve})},`col-${J}-${de}-${we}-${De}`)})})]}),l.jsx(cl,{scope:"row-slot",li:J,sIdx:de,insertAt:we+1})]},`rowwrap-${Ce}`)})]})})},`sec-${J}-${de}`))}),P=(U,J)=>{var de;const oe=F[J]??((de=U.tabs[0])==null?void 0:de.key);return l.jsx(zr,{options:U.tabs.map(ge=>{const we=ge.icon?ls(ge.icon.name,ge.icon.style):null;return{label:f(ge.label),value:ge.key,disabled:ge.disabled,icon:we?l.jsx(we,{className:"w-4 h-4"}):null}}),value:oe,onChange:ge=>Z(we=>({...we,[J]:ge})),children:Object.fromEntries(U.tabs.map((ge,we)=>[ge.key,l.jsx("div",{className:"space-y-6",children:ge.sections.map((Ce,ke)=>l.jsx("div",{className:"mb-6",children:l.jsx(lt,{title:f(Ce.sectionTitle),defaultOpen:Ce.defaultOpen,forceOpen:T,children:l.jsxs("div",{className:"flex flex-col",children:[l.jsx(cl,{scope:"tab-row-slot",li:J,tabKey:ge.key,sIdx:ke,insertAt:0}),Ce.rows.map((Ie,Le)=>{const De=`tab-row|li:${J}|t:${ge.key}|s:${ke}|r:${Le}`,Re=n&&y===De,Ve=ie===De;return l.jsxs(C.Fragment,{children:[l.jsxs("div",{ref:S(De),className:`relative transition-all duration-200 ${Ve?"opacity-40 ring-1 ring-dashed ring-[var(--color-ds-border-default)] bg-[var(--color-ds-background-muted)]":n&&Re?"ring-1 ring-[var(--color-ds-border-default-50)]":""}`,onMouseEnter:()=>E(De),onMouseLeave:()=>E(Ge=>Ge===De?null:Ge),style:{borderRadius:8},children:[n&&l.jsxs(l.Fragment,{children:[l.jsx(qp,{ctx:{kind:"tabs",li:J,tabKey:ge.key,tabIdx:we,sectionIdx:ke,rowIdx:Le},visible:!!Re&&!g}),l.jsx(Hp,{kind:"row-in-tab-section",li:J,tabKey:ge.key,sIdx:ke,rIdx:Le,visible:!!Re&&!g})]}),Ie.title&&l.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:f(Ie.title)}),l.jsx("div",{className:"flex flex-wrap -mx-2 items-stretch",children:Ie.columns.map((Ge,ft)=>{const Ne=`tabs|li:${J}|t:${we}|s:${ke}|r:${Le}|c:${ft}`,Fe=N[Ne]??[];return l.jsx("div",{className:`${Ge.width??"flex-1"} px-2 flex flex-col`,children:l.jsx(V,{keyId:Ne,ids:Fe,tabKey:ge.key})},`col-${J}-${we}-${ke}-${Le}-${ft}`)})})]}),l.jsx(cl,{scope:"tab-row-slot",li:J,tabKey:ge.key,sIdx:ke,insertAt:Le+1})]},`rowwrap-${De}`)})]})})},`sec-${J}-${we}-${ke}`))},`tabpanel-${J}-${we}`)]))},`tabs-${J}`)},z=se(U=>U.setSelection);return l.jsxs(xc,{...r.methods,children:[l.jsxs(Qd,{sensors:ne,collisionDetection:H,onDragEnd:X,children:[l.jsxs("div",{id:"form-renderer-root",className:"relative overflow-visible",onDoubleClick:U=>{z({kind:"none"})},children:[l.jsx("div",{className:"space-y-6 ",children:e.layout.map((U,J)=>U.type==="rows"?l.jsx(C.Fragment,{children:$(U,J)},`rows-${J}`):l.jsx(C.Fragment,{children:P(U,J)},`tabs-${J}`))}),l.jsx(pW,{schema:e,anchors:w,enabled:b})]}),l.jsx(th,{dropAnimation:null,children:xe?l.jsx("div",{style:{pointerEvents:"none",opacity:.9},children:xe}):null})]}),l.jsx(Bt,{isOpen:ee.isOpen,onClose:q,title:ee.title,footer:l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx(pe,{variant:"outline",onClick:q,children:"Cancelar"}),l.jsx(pe,{variant:"danger",onClick:ae,children:"Eliminar"})]}),children:l.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:ee.message})})]})}function FW(e,t,r,n){var k;const{fields:a=[],layout:o,validationSchema:i}=e,c=_W(),d=((k=c==null?void 0:c.services)==null?void 0:k.registry)??void 0,u=Wn(j=>j.systemContext),f=C.useMemo(()=>{if(t)return t;try{const j=i??ld(e);return Xc(j)}catch{return}},[t,e,i]),h=Ic({resolver:f,mode:"onBlur",reValidateMode:"onChange",defaultValues:e.defaultValues??{}}),p=C.useMemo(()=>(a??[]).filter(j=>j.type!=="inputGroup"&&j.type!=="button"),[a]),{optionsMap:m}=V2(p),v=I2(a),g=Z2(a,h.control),[b,w]=C.useState({}),[x,y]=C.useState(0);C.useEffect(()=>{let j;const A=h.watch(()=>{clearTimeout(j),j=setTimeout(()=>{y(S=>S+1)},500)});return()=>{A.unsubscribe(),clearTimeout(j)}},[h.watch]),C.useEffect(()=>{let j=!0;return(async()=>{const S=await Promise.all(p.filter(O=>O.type==="select"&&(O.optionSource||O.endpointConfig)).map(async O=>{const B=O.name,R=li(O.optionSource,O.endpointConfig);if(!R)return[B,[]];const I=O.endpointConfig?bn(O.endpointConfig.parameters,h.getValues,{...u,ACTIVE_VARIANT:n}):{},F=d==null?void 0:d[R];if(typeof F!="function")return[B,[]];try{const Z=await Promise.resolve(F("",{getValues:h.getValues,watch:h.watch,params:I,...u})),ee=Array.isArray(Z)?Z:[];return[B,ee]}catch{return[B,[]]}}));if(!j)return;const _={};for(const[O,B]of S)_[O]=B;w(_)})(),()=>{j=!1}},[d,h.getValues,h.watch,JSON.stringify(p.map(j=>({n:j.name,os:j.optionSource??null,ec:j.endpointConfig??null}))),n,x]);const E=C.useCallback((j,A)=>{if(!(j!=null&&j.enabled)||!j.rule)return A;try{const S={...h.getValues(),ACTIVE_VARIANT:n};return!!Ei(j.rule,S)}catch{return A}},[h,n]);return{methods:h,control:h.control,formState:h.formState,fields:a,fieldsByName:v,asyncOptionsMap:m,adapterOptionsMap:b,disabledMap:g,evalContainer:E,registry:d,layout:o,systemContext:u}}function _W(){try{return Zt()??void 0}catch{return}}function MW(e,t,r){const n={...e};return t.top+e.y<=r.top?n.y=r.top-t.top:t.bottom+e.y>=r.top+r.height&&(n.y=r.top+r.height-t.bottom),t.left+e.x<=r.left?n.x=r.left-t.left:t.right+e.x>=r.left+r.width&&(n.x=r.left+r.width-t.right),n}const RW=e=>{let{transform:t,draggingNodeRect:r,windowRect:n}=e;return!r||!n?t:MW(t,r,n)};function Ga(e){const r={text:()=>({label:"ds.fields.defaults.text.label",type:"text",width:"w-full",placeholder:"ds.fields.defaults.text.placeholder",size:"sm"}),number:()=>({label:"ds.fields.defaults.number.label",type:"number",width:"w-full",placeholder:"ds.fields.defaults.number.placeholder",size:"sm",validation:{required:!1}}),email:()=>({label:"ds.fields.defaults.email.label",type:"email",width:"w-full",placeholder:"ds.fields.defaults.email.placeholder",size:"sm"}),password:()=>({label:"ds.fields.defaults.password.label",type:"password",width:"w-full",placeholder:"ds.fields.defaults.password.placeholder",size:"sm",validation:{minLength:8}}),tel:()=>({label:"ds.fields.defaults.tel.label",type:"tel",width:"w-full",placeholder:"ds.fields.defaults.tel.placeholder",size:"sm"}),url:()=>({label:"ds.fields.defaults.url.label",type:"url",width:"w-full",placeholder:"ds.fields.defaults.url.placeholder",size:"sm"}),select:()=>({label:"ds.fields.defaults.select.label",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}),checkbox:()=>({label:"ds.fields.defaults.checkbox.label",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}),textarea:()=>({label:"ds.fields.defaults.textarea.label",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"ds.fields.defaults.textarea.placeholder"}),date:()=>({label:"ds.fields.defaults.date.label",type:"date",width:"w-full",size:"sm",showTime:!1}),file:()=>({label:"ds.fields.defaults.file.label",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}),inputGroup:()=>({label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}),search:()=>({label:"ds.fields.defaults.search.label",type:"search",width:"w-full",placeholder:"ds.fields.defaults.search.placeholder",size:"sm",searchMode:"button"}),optionGroup:()=>({label:"Selecciona opciones",type:"optionGroup",width:"w-full",size:"sm",multiple:!0,vertical:!0,options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}]}),array:()=>({label:"Lista repetible",type:"array",width:"w-full",items:[]})}[e];return r?r():{type:e}}function OW(e){if(!e)return null;const t=e.data;if(t.kind==="palette-field"){const r=t.factoryKind,n=GP[r];if(n)return l.jsx("div",{className:"pointer-events-none opacity-95",children:l.jsx("div",{className:`\r
413
413
  w-[320px]\r
414
414
  max-w-[80vw]\r
415
415
  rounded-xl \r