@dipusevilla/componentes-iu 1.1.25 → 1.1.26

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
@@ -96,7 +96,7 @@ attempted value: ${i}
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],q2=e=>e instanceof Date?e.getTime():e;function jI(e,t,r){const n=q2(e),a=q2(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 jI(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 fd(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 fd(n)?n:null}const DI=Object.entries(ba).filter(([e,t])=>e.endsWith("Icon")&&fd(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),SI=Object.entries(Da).filter(([e,t])=>e.endsWith("Icon")&&fd(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),AI=cc||lc||(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)||AI,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(G2,{items:DI,query:c,onPick:v=>p(v,"outline"),onClear:m}),solid:l.jsx(G2,{items:SI,query:c,onPick:v=>p(v,"solid"),onClear:m})}})]})})]})},G2=({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 NI=({schema:e,renderField:t})=>{var g,b,w;const{control:r}=gn(),{fields:n,append:a,remove:o}=GE({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 K2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function FI(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(()=>K2(a),[a]),x=C.useMemo(()=>FI(w),[w]),y=E=>{const k=K2(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 J2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,9)}function Fee(e){return e}function hd({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(()=>J2(a),[a]),y=C.useMemo(()=>x,[x]),E=k=>{const j=J2(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:rc,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1,reserveErrorSpace:u})}function Y2(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function _I(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 MI=e=>e.type!=="inputGroup"&&e.type!=="button";function RI(){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 X2({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=RI(),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 O=p??id(e);return Yc(O)}catch{return}},[t,e,p]),x=$c({resolver:w,mode:"onBlur",reValidateMode:"onChange",defaultValues:f??{}}),y=Wn(O=>O.setRuntimeState),E=Wn(O=>O.systemContext),k=Wn(O=>O.formValues);C.useEffect(()=>{y({isActive:!0});let O=!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})}),O||y({systemContext:{...$}})}if(!O&&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)}})(),()=>{O=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,b,x.reset]);const{control:j,reset:A,handleSubmit:S,formState:{errors:_,isSubmitting:M}}=x,[B,R]=C.useState(!1);C.useEffect(()=>{h&&(R(!0),h().then(O=>A(O)).finally(()=>R(!1)))},[h,A]);const I=C.useMemo(()=>(o??[]).filter(MI),[o]),{loadingCount:F,optionsMap:Z}=W2(I),[ee,Y]=C.useState({}),[te,ae]=C.useState(0);C.useEffect(()=>{let O;const V=x.watch(()=>{clearTimeout(O),O=setTimeout(()=>{ae(T=>T+1)},500)});return()=>{V.unsubscribe(),clearTimeout(O)}},[x.watch]);const q=C.useRef(b);C.useEffect(()=>{q.current=b},[b]);const N=C.useRef({});C.useEffect(()=>{let O=!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=Y2(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(!O)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)})(),()=>{O=!1}},[te,JSON.stringify(I.map(O=>({n:O.name,os:O.optionSource??null,ec:O.endpointConfig??null,ctx:O.adapterCtx??O.optionAdapterCtx??null}))),E]),C.useEffect(()=>{let O=!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=Y2(T.adapterCtx??T.optionAdapterCtx),de=await Promise.resolve(J("",{getValues:x.getValues,watch:x.watch,ctx:oe}));if(!O)return;const ge=_I(de,!!T.multiple);x.setValue($,ge,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{O=!1}},[b,x.getValues,x.setValue,JSON.stringify(I.map(O=>({n:O.name,ds:O.defaultSource??null,mult:!!O.multiple})))]);const L=Z2(o),ne=U2(o,j),K=C.useMemo(()=>{const O={};return a.forEach((V,T)=>{V.type==="tabs"&&(O[T]=V.tabs[0].key)}),O},[a]),[Q,he]=C.useState(K),[ie,me]=C.useState({}),[ce,le]=C.useState({}),be=C.useRef({}),fe=C.useCallback(async()=>{const O={},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&&(O[$]=P)}),me(O)},[o,b,x,E]),xe=C.useCallback(async O=>{var U;const V=O,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(O,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 O=x.watch((V,{name:T})=>{fe(),T&&D(V,T,"onChange")});return()=>{O.unsubscribe(),Object.values(be.current).forEach(V=>V&&clearTimeout(V))}},[fe,D,x]);const G=C.useCallback((O,V,T,$)=>{var z;if(!(O!=null&&O.enabled))return V;let P=!0;if(O.rule)try{const U={...x.getValues(),...E,ACTIVE_VARIANT:n};P=!!Ei(O.rule,U)}catch{P=V}if(P&&T&&$&&O.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(O=>O).filter(O=>{var V;return((V=O.clearWhen)==null?void 0:V.enabled)&&(O.clearWhen.rule||O.clearWhen.endpoint)}).map(O=>({name:O.name,container:O.clearWhen})),[o]);C.useEffect(()=>{if(!re.length)return;const O=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{}})};O(x.getValues());const V=x.watch(()=>O(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(O=>{const V=mt(v,O);if(!V)return"";const T={...E,...k,sys:E,form:k};return ld(V,T)},[v,E,k]),H=C.useCallback((O,V)=>{var Re,Ve,Ge,ft;let T;if(typeof O=="string"){if(T=L[O],!T){const Ne=(o??[]).find(Fe=>(Fe==null?void 0:Fe.name)===O);if(Ne)T=Ne;else return null}}else T=O;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(ud,{name:P,control:j,searchFn:Me,label:W(T.label),size:T.size,width:T.width,disabled:J||M,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||M,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(cd,{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||M,children:W(Ne.label)})},P??Ne.label)}if(T.type==="array"){const Ne=T;return l.jsx(NI,{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||M,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(Jc,{...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||M,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(hd,{label:W(T.label),placeholder:W(T.placeholder),size:T.size,disabled:J||M,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,_,M,B,Z,ee,G,ne,x.getValues,x.watch,b,v]);return l.jsx(wc,{...x,children:l.jsxs("form",{noValidate:!0,onSubmit:S(async O=>{await D(O,void 0,"onSubmit"),!(Object.keys(x.formState.errors).length>0)&&(await i(O),m(c??v("ds.form.saveSuccess"),"success"))},O=>{nI(O),m(d??v("ds.form.saveError"),"error")}),className:"space-y-6",children:[a.map((O,V)=>O.type==="rows"?l.jsx(C.Fragment,{children:O.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:O.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(O.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:M||B||F>0,children:v(M?"ds.form.sending":"ds.form.submit")})})]})})}function Q2({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:dc,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:ac,size:"sm",className:ve("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const ef="licytal:ui:theme",tf=C.createContext({theme:"light",dark:!1,toggle:()=>{}});function OI({children:e}){const[t,r]=C.useState(!1),[n,a]=C.useState("light");C.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(ef);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(ef,n))},[n,t]);const o=()=>a(i=>i==="light"?"dark":"light");return t?l.jsx(tf.Provider,{value:{theme:n,dark:n==="dark",toggle:o},children:e}):null}const pd=()=>C.useContext(tf),Fo={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},rf=({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}=pd(),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(Q2,{dark:n,onToggle:v})]})]})},LI={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",LI[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 TI=({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],q2=e=>e instanceof Date?e.getTime():e;function jI(e,t,r){const n=q2(e),a=q2(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 jI(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 fd(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 fd(n)?n:null}const DI=Object.entries(ba).filter(([e,t])=>e.endsWith("Icon")&&fd(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),SI=Object.entries(Da).filter(([e,t])=>e.endsWith("Icon")&&fd(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),AI=cc||lc||(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)||AI,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(G2,{items:DI,query:c,onPick:v=>p(v,"outline"),onClear:m}),solid:l.jsx(G2,{items:SI,query:c,onPick:v=>p(v,"solid"),onClear:m})}})]})})]})},G2=({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 NI=({schema:e,renderField:t})=>{var g,b,w;const{control:r}=gn(),{fields:n,append:a,remove:o}=GE({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 K2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function FI(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(()=>K2(a),[a]),x=C.useMemo(()=>FI(w),[w]),y=E=>{const k=K2(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 J2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,9)}function Fee(e){return e}function hd({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(()=>J2(a),[a]),y=C.useMemo(()=>x,[x]),E=k=>{const j=J2(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:rc,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1,reserveErrorSpace:u})}function Y2(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function _I(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 MI=e=>e.type!=="inputGroup"&&e.type!=="button";function RI(){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 X2({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=RI(),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 O=p??id(e);return Yc(O)}catch{return}},[t,e,p]),x=$c({resolver:w,mode:"onBlur",reValidateMode:"onChange",defaultValues:f??{}}),y=Wn(O=>O.setRuntimeState),E=Wn(O=>O.systemContext),k=Wn(O=>O.formValues);C.useEffect(()=>{y({isActive:!0});let O=!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})}),O||y({systemContext:{...$}})}if(!O&&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)}})(),()=>{O=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,b,x.reset]);const{control:j,reset:A,handleSubmit:S,formState:{errors:_,isSubmitting:M}}=x,[B,R]=C.useState(!1);C.useEffect(()=>{h&&(R(!0),h().then(O=>A(O)).finally(()=>R(!1)))},[h,A]);const I=C.useMemo(()=>(o??[]).filter(MI),[o]),{loadingCount:F,optionsMap:Z}=W2(I),[ee,Y]=C.useState({}),[te,ae]=C.useState(0);C.useEffect(()=>{let O;const V=x.watch(()=>{clearTimeout(O),O=setTimeout(()=>{ae(T=>T+1)},500)});return()=>{V.unsubscribe(),clearTimeout(O)}},[x.watch]);const q=C.useRef(b);C.useEffect(()=>{q.current=b},[b]);const N=C.useRef({});C.useEffect(()=>{let O=!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=Y2(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(!O)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)})(),()=>{O=!1}},[te,JSON.stringify(I.map(O=>({n:O.name,os:O.optionSource??null,ec:O.endpointConfig??null,ctx:O.adapterCtx??O.optionAdapterCtx??null}))),E]),C.useEffect(()=>{let O=!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=Y2(T.adapterCtx??T.optionAdapterCtx),de=await Promise.resolve(J("",{getValues:x.getValues,watch:x.watch,ctx:oe}));if(!O)return;const ge=_I(de,!!T.multiple);x.setValue($,ge,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{O=!1}},[b,x.getValues,x.setValue,JSON.stringify(I.map(O=>({n:O.name,ds:O.defaultSource??null,mult:!!O.multiple})))]);const L=Z2(o),ne=U2(o,j),K=C.useMemo(()=>{const O={};return a.forEach((V,T)=>{V.type==="tabs"&&(O[T]=V.tabs[0].key)}),O},[a]),[Q,he]=C.useState(K),[ie,me]=C.useState({}),[ce,le]=C.useState({}),be=C.useRef({}),fe=C.useCallback(async()=>{const O={},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&&(O[$]=P)}),me(O)},[o,b,x,E]),xe=C.useCallback(async O=>{var U;const V=O,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(O,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 O=x.watch((V,{name:T})=>{fe(),T&&D(V,T,"onChange")});return()=>{O.unsubscribe(),Object.values(be.current).forEach(V=>V&&clearTimeout(V))}},[fe,D,x]);const G=C.useCallback((O,V,T,$)=>{var z;if(!(O!=null&&O.enabled))return V;let P=!0;if(O.rule)try{const U={...x.getValues(),...E,ACTIVE_VARIANT:n};P=!!Ei(O.rule,U)}catch{P=V}if(P&&T&&$&&O.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(O=>O).filter(O=>{var V;return((V=O.clearWhen)==null?void 0:V.enabled)&&(O.clearWhen.rule||O.clearWhen.endpoint)}).map(O=>({name:O.name,container:O.clearWhen})),[o]);C.useEffect(()=>{if(!re.length)return;const O=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{}})};O(x.getValues());const V=x.watch(()=>O(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(O=>{const V=mt(v,O);if(!V)return"";const T={...E,...k,sys:E,form:k};return ld(V,T)},[v,E,k]),H=C.useCallback((O,V)=>{var Re,Ve,Ge,ft;let T;if(typeof O=="string"){if(T=L[O],!T){const Ne=(o??[]).find(Fe=>(Fe==null?void 0:Fe.name)===O);if(Ne)T=Ne;else return null}}else T=O;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({q:Tt,...Ze},{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(ud,{name:P,control:j,searchFn:Me,label:W(T.label),size:T.size,width:T.width,disabled:J||M,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||M,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(cd,{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||M,children:W(Ne.label)})},P??Ne.label)}if(T.type==="array"){const Ne=T;return l.jsx(NI,{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||M,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(Jc,{...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||M,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(hd,{label:W(T.label),placeholder:W(T.placeholder),size:T.size,disabled:J||M,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,_,M,B,Z,ee,G,ne,x.getValues,x.watch,b,v]);return l.jsx(wc,{...x,children:l.jsxs("form",{noValidate:!0,onSubmit:S(async O=>{await D(O,void 0,"onSubmit"),!(Object.keys(x.formState.errors).length>0)&&(await i(O),m(c??v("ds.form.saveSuccess"),"success"))},O=>{nI(O),m(d??v("ds.form.saveError"),"error")}),className:"space-y-6",children:[a.map((O,V)=>O.type==="rows"?l.jsx(C.Fragment,{children:O.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:O.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(O.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:M||B||F>0,children:v(M?"ds.form.sending":"ds.form.submit")})})]})})}function Q2({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:dc,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:ac,size:"sm",className:ve("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const ef="licytal:ui:theme",tf=C.createContext({theme:"light",dark:!1,toggle:()=>{}});function OI({children:e}){const[t,r]=C.useState(!1),[n,a]=C.useState("light");C.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(ef);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(ef,n))},[n,t]);const o=()=>a(i=>i==="light"?"dark":"light");return t?l.jsx(tf.Provider,{value:{theme:n,dark:n==="dark",toggle:o},children:e}):null}const pd=()=>C.useContext(tf),Fo={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},rf=({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}=pd(),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(Q2,{dark:n,onToggle:v})]})]})},LI={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",LI[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 TI=({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
@@ -115,7 +115,7 @@ attempted value: ${i}
115
115
  To pick up a draggable item, press the space bar.
116
116
  While dragging, use the arrow keys to move the item.
117
117
  Press space again to drop the item in its new position, or press escape to cancel.
118
- `},xB={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:r}=e;return r?"Draggable item "+t.id+" was moved over droppable area "+r.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:r}=e;return r?"Draggable item "+t.id+" was dropped over droppable area "+r.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function yB(e){let{announcements:t=xB,container:r,hiddenTextDescribedById:n,screenReaderInstructions:a=wB}=e;const{announce:o,announcement:i}=vB(),c=Vo("DndLiveRegion"),[d,u]=C.useState(!1);if(C.useEffect(()=>{u(!0)},[]),zo(C.useMemo(()=>({onDragStart(h){let{active:p}=h;o(t.onDragStart({active:p}))},onDragMove(h){let{active:p,over:m}=h;t.onDragMove&&o(t.onDragMove({active:p,over:m}))},onDragOver(h){let{active:p,over:m}=h;o(t.onDragOver({active:p,over:m}))},onDragEnd(h){let{active:p,over:m}=h;o(t.onDragEnd({active:p,over:m}))},onDragCancel(h){let{active:p,over:m}=h;o(t.onDragCancel({active:p,over:m}))}}),[o,t])),!d)return null;const f=C.createElement(C.Fragment,null,C.createElement(mB,{id:n,value:a.draggable}),C.createElement(gB,{id:c,announcement:i}));return r?at.createPortal(f,r):f}var bt;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(bt||(bt={}));function Bi(){}function Ba(e,t){return C.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function Id(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return C.useMemo(()=>[...t].filter(n=>n!=null),[...t])}const yr=Object.freeze({x:0,y:0});function Bd(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function kB(e,t){const r=Ii(e);if(!r)return"0 0";const n={x:(r.x-t.left)/t.width*100,y:(r.y-t.top)/t.height*100};return n.x+"% "+n.y+"%"}function Pd(e,t){let{data:{value:r}}=e,{data:{value:n}}=t;return r-n}function EB(e,t){let{data:{value:r}}=e,{data:{value:n}}=t;return n-r}function Vd(e){let{left:t,top:r,height:n,width:a}=e;return[{x:t,y:r},{x:t+a,y:r},{x:t,y:r+n},{x:t+a,y:r+n}]}function Nf(e,t){if(!e||e.length===0)return null;const[r]=e;return r[t]}function Ff(e,t,r){return t===void 0&&(t=e.left),r===void 0&&(r=e.top),{x:t+e.width*.5,y:r+e.height*.5}}const Zd=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:n}=e;const a=Ff(t,t.left,t.top),o=[];for(const i of n){const{id:c}=i,d=r.get(c);if(d){const u=Bd(Ff(d),a);o.push({id:c,data:{droppableContainer:i,value:u}})}}return o.sort(Pd)},CB=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:n}=e;const a=Vd(t),o=[];for(const i of n){const{id:c}=i,d=r.get(c);if(d){const u=Vd(d),f=a.reduce((p,m,v)=>p+Bd(u[v],m),0),h=Number((f/4).toFixed(4));o.push({id:c,data:{droppableContainer:i,value:h}})}}return o.sort(Pd)};function jB(e,t){const r=Math.max(t.top,e.top),n=Math.max(t.left,e.left),a=Math.min(t.left+t.width,e.left+e.width),o=Math.min(t.top+t.height,e.top+e.height),i=a-n,c=o-r;if(n<a&&r<o){const d=t.width*t.height,u=e.width*e.height,f=i*c,h=f/(d+u-f);return Number(h.toFixed(4))}return 0}const _f=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:n}=e;const a=[];for(const o of n){const{id:i}=o,c=r.get(i);if(c){const d=jB(c,t);d>0&&a.push({id:i,data:{droppableContainer:o,value:d}})}}return a.sort(EB)};function DB(e,t){const{top:r,left:n,bottom:a,right:o}=t;return r<=e.y&&e.y<=a&&n<=e.x&&e.x<=o}const SB=e=>{let{droppableContainers:t,droppableRects:r,pointerCoordinates:n}=e;if(!n)return[];const a=[];for(const o of t){const{id:i}=o,c=r.get(i);if(c&&DB(n,c)){const u=Vd(c).reduce((h,p)=>h+Bd(n,p),0),f=Number((u/4).toFixed(4));a.push({id:i,data:{droppableContainer:o,value:f}})}}return a.sort(Pd)};function AB(e,t,r){return{...e,scaleX:t&&r?t.width/r.width:1,scaleY:t&&r?t.height/r.height:1}}function Mf(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:yr}function NB(e){return function(r){for(var n=arguments.length,a=new Array(n>1?n-1:0),o=1;o<n;o++)a[o-1]=arguments[o];return a.reduce((i,c)=>({...i,top:i.top+e*c.y,bottom:i.bottom+e*c.y,left:i.left+e*c.x,right:i.right+e*c.x}),{...r})}}const FB=NB(1);function Rf(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function _B(e,t,r){const n=Rf(t);if(!n)return e;const{scaleX:a,scaleY:o,x:i,y:c}=n,d=e.left-i-(1-a)*parseFloat(r),u=e.top-c-(1-o)*parseFloat(r.slice(r.indexOf(" ")+1)),f=a?e.width/a:e.width,h=o?e.height/o:e.height;return{width:f,height:h,top:u,right:d+f,bottom:u+h,left:d}}const MB={ignoreTransform:!1};function Pa(e,t){t===void 0&&(t=MB);let r=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:f}=Ot(e).getComputedStyle(e);u&&(r=_B(r,u,f))}const{top:n,left:a,width:o,height:i,bottom:c,right:d}=r;return{top:n,left:a,width:o,height:i,bottom:c,right:d}}function Of(e){return Pa(e,{ignoreTransform:!0})}function RB(e){const t=e.innerWidth,r=e.innerHeight;return{top:0,left:0,right:t,bottom:r,width:t,height:r}}function OB(e,t){return t===void 0&&(t=Ot(e).getComputedStyle(e)),t.position==="fixed"}function LB(e,t){t===void 0&&(t=Ot(e).getComputedStyle(e));const r=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(a=>{const o=t[a];return typeof o=="string"?r.test(o):!1})}function Pi(e,t){const r=[];function n(a){if(t!=null&&r.length>=t||!a)return r;if(Td(a)&&a.scrollingElement!=null&&!r.includes(a.scrollingElement))return r.push(a.scrollingElement),r;if(!Io(a)||jf(a)||r.includes(a))return r;const o=Ot(e).getComputedStyle(a);return a!==e&&LB(a,o)&&r.push(a),OB(a,o)?r:n(a.parentNode)}return e?n(e):r}function Lf(e){const[t]=Pi(e,1);return t??null}function zd(e){return!Ri||!e?null:Ta(e)?e:Ld(e)?Td(e)||e===$a(e).scrollingElement?window:Io(e)?e:null:null}function Tf(e){return Ta(e)?e.scrollX:e.scrollLeft}function $f(e){return Ta(e)?e.scrollY:e.scrollTop}function Hd(e){return{x:Tf(e),y:$f(e)}}var yt;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(yt||(yt={}));function If(e){return!Ri||!e?!1:e===document.scrollingElement}function Bf(e){const t={x:0,y:0},r=If(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},n={x:e.scrollWidth-r.width,y:e.scrollHeight-r.height},a=e.scrollTop<=t.y,o=e.scrollLeft<=t.x,i=e.scrollTop>=n.y,c=e.scrollLeft>=n.x;return{isTop:a,isLeft:o,isBottom:i,isRight:c,maxScroll:n,minScroll:t}}const TB={x:.2,y:.2};function $B(e,t,r,n,a){let{top:o,left:i,right:c,bottom:d}=r;n===void 0&&(n=10),a===void 0&&(a=TB);const{isTop:u,isBottom:f,isLeft:h,isRight:p}=Bf(e),m={x:0,y:0},v={x:0,y:0},g={height:t.height*a.y,width:t.width*a.x};return!u&&o<=t.top+g.height?(m.y=yt.Backward,v.y=n*Math.abs((t.top+g.height-o)/g.height)):!f&&d>=t.bottom-g.height&&(m.y=yt.Forward,v.y=n*Math.abs((t.bottom-g.height-d)/g.height)),!p&&c>=t.right-g.width?(m.x=yt.Forward,v.x=n*Math.abs((t.right-g.width-c)/g.width)):!h&&i<=t.left+g.width&&(m.x=yt.Backward,v.x=n*Math.abs((t.left+g.width-i)/g.width)),{direction:m,speed:v}}function IB(e){if(e===document.scrollingElement){const{innerWidth:o,innerHeight:i}=window;return{top:0,left:0,right:o,bottom:i,width:o,height:i}}const{top:t,left:r,right:n,bottom:a}=e.getBoundingClientRect();return{top:t,left:r,right:n,bottom:a,width:e.clientWidth,height:e.clientHeight}}function Pf(e){return e.reduce((t,r)=>Ia(t,Hd(r)),yr)}function BB(e){return e.reduce((t,r)=>t+Tf(r),0)}function PB(e){return e.reduce((t,r)=>t+$f(r),0)}function Vf(e,t){if(t===void 0&&(t=Pa),!e)return;const{top:r,left:n,bottom:a,right:o}=t(e);Lf(e)&&(a<=0||o<=0||r>=window.innerHeight||n>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const VB=[["x",["left","right"],BB],["y",["top","bottom"],PB]];class Wd{constructor(t,r){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const n=Pi(r),a=Pf(n);this.rect={...t},this.width=t.width,this.height=t.height;for(const[o,i,c]of VB)for(const d of i)Object.defineProperty(this,d,{get:()=>{const u=c(n),f=a[o]-u;return this.rect[d]+f},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class Ho{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(r=>{var n;return(n=this.target)==null?void 0:n.removeEventListener(...r)})},this.target=t}add(t,r,n){var a;(a=this.target)==null||a.addEventListener(t,r,n),this.listeners.push([t,r,n])}}function ZB(e){const{EventTarget:t}=Ot(e);return e instanceof t?e:$a(e)}function Ud(e,t){const r=Math.abs(e.x),n=Math.abs(e.y);return typeof t=="number"?Math.sqrt(r**2+n**2)>t:"x"in t&&"y"in t?r>t.x&&n>t.y:"x"in t?r>t.x:"y"in t?n>t.y:!1}var sr;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(sr||(sr={}));function Zf(e){e.preventDefault()}function zB(e){e.stopPropagation()}var We;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(We||(We={}));const zf={start:[We.Space,We.Enter],cancel:[We.Esc],end:[We.Space,We.Enter,We.Tab]},HB=(e,t)=>{let{currentCoordinates:r}=t;switch(e.code){case We.Right:return{...r,x:r.x+25};case We.Left:return{...r,x:r.x-25};case We.Down:return{...r,y:r.y+25};case We.Up:return{...r,y:r.y-25}}};class Wo{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:r}}=t;this.props=t,this.listeners=new Ho($a(r)),this.windowListeners=new Ho(Ot(r)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(sr.Resize,this.handleCancel),this.windowListeners.add(sr.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(sr.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:r}=this.props,n=t.node.current;n&&Vf(n),r(yr)}handleKeyDown(t){if($i(t)){const{active:r,context:n,options:a}=this.props,{keyboardCodes:o=zf,coordinateGetter:i=HB,scrollBehavior:c="smooth"}=a,{code:d}=t;if(o.end.includes(d)){this.handleEnd(t);return}if(o.cancel.includes(d)){this.handleCancel(t);return}const{collisionRect:u}=n.current,f=u?{x:u.left,y:u.top}:yr;this.referenceCoordinates||(this.referenceCoordinates=f);const h=i(t,{active:r,context:n.current,currentCoordinates:f});if(h){const p=Zo(h,f),m={x:0,y:0},{scrollableAncestors:v}=n.current;for(const g of v){const b=t.code,{isTop:w,isRight:x,isLeft:y,isBottom:E,maxScroll:k,minScroll:j}=Bf(g),A=IB(g),S={x:Math.min(b===We.Right?A.right-A.width/2:A.right,Math.max(b===We.Right?A.left:A.left+A.width/2,h.x)),y:Math.min(b===We.Down?A.bottom-A.height/2:A.bottom,Math.max(b===We.Down?A.top:A.top+A.height/2,h.y))},_=b===We.Right&&!x||b===We.Left&&!y,M=b===We.Down&&!E||b===We.Up&&!w;if(_&&S.x!==h.x){const B=g.scrollLeft+p.x,R=b===We.Right&&B<=k.x||b===We.Left&&B>=j.x;if(R&&!p.y){g.scrollTo({left:B,behavior:c});return}R?m.x=g.scrollLeft-B:m.x=b===We.Right?g.scrollLeft-k.x:g.scrollLeft-j.x,m.x&&g.scrollBy({left:-m.x,behavior:c});break}else if(M&&S.y!==h.y){const B=g.scrollTop+p.y,R=b===We.Down&&B<=k.y||b===We.Up&&B>=j.y;if(R&&!p.x){g.scrollTo({top:B,behavior:c});return}R?m.y=g.scrollTop-B:m.y=b===We.Down?g.scrollTop-k.y:g.scrollTop-j.y,m.y&&g.scrollBy({top:-m.y,behavior:c});break}}this.handleMove(t,Ia(Zo(h,this.referenceCoordinates),m))}}}handleMove(t,r){const{onMove:n}=this.props;t.preventDefault(),n(r)}handleEnd(t){const{onEnd:r}=this.props;t.preventDefault(),this.detach(),r()}handleCancel(t){const{onCancel:r}=this.props;t.preventDefault(),this.detach(),r()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}Wo.activators=[{eventName:"onKeyDown",handler:(e,t,r)=>{let{keyboardCodes:n=zf,onActivation:a}=t,{active:o}=r;const{code:i}=e.nativeEvent;if(n.start.includes(i)){const c=o.activatorNode.current;return c&&e.target!==c?!1:(e.preventDefault(),a==null||a({event:e.nativeEvent}),!0)}return!1}}];function Hf(e){return!!(e&&"distance"in e)}function Wf(e){return!!(e&&"delay"in e)}class qd{constructor(t,r,n){var a;n===void 0&&(n=ZB(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=r;const{event:o}=t,{target:i}=o;this.props=t,this.events=r,this.document=$a(i),this.documentListeners=new Ho(this.document),this.listeners=new Ho(n),this.windowListeners=new Ho(Ot(i)),this.initialCoordinates=(a=Ii(o))!=null?a:yr,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:r,bypassActivationConstraint:n}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(sr.Resize,this.handleCancel),this.windowListeners.add(sr.DragStart,Zf),this.windowListeners.add(sr.VisibilityChange,this.handleCancel),this.windowListeners.add(sr.ContextMenu,Zf),this.documentListeners.add(sr.Keydown,this.handleKeydown),r){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(Wf(r)){this.timeoutId=setTimeout(this.handleStart,r.delay),this.handlePending(r);return}if(Hf(r)){this.handlePending(r);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,r){const{active:n,onPending:a}=this.props;a(n,t,this.initialCoordinates,r)}handleStart(){const{initialCoordinates:t}=this,{onStart:r}=this.props;t&&(this.activated=!0,this.documentListeners.add(sr.Click,zB,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(sr.SelectionChange,this.removeTextSelection),r(t))}handleMove(t){var r;const{activated:n,initialCoordinates:a,props:o}=this,{onMove:i,options:{activationConstraint:c}}=o;if(!a)return;const d=(r=Ii(t))!=null?r:yr,u=Zo(a,d);if(!n&&c){if(Hf(c)){if(c.tolerance!=null&&Ud(u,c.tolerance))return this.handleCancel();if(Ud(u,c.distance))return this.handleStart()}if(Wf(c)&&Ud(u,c.tolerance))return this.handleCancel();this.handlePending(c,u);return}t.cancelable&&t.preventDefault(),i(d)}handleEnd(){const{onAbort:t,onEnd:r}=this.props;this.detach(),this.activated||t(this.props.active),r()}handleCancel(){const{onAbort:t,onCancel:r}=this.props;this.detach(),this.activated||t(this.props.active),r()}handleKeydown(t){t.code===We.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const WB={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Uo extends qd{constructor(t){const{event:r}=t,n=$a(r.target);super(t,WB,n)}}Uo.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:n}=t;return!r.isPrimary||r.button!==0?!1:(n==null||n({event:r}),!0)}}];const UB={move:{name:"mousemove"},end:{name:"mouseup"}};var Gd;(function(e){e[e.RightClick=2]="RightClick"})(Gd||(Gd={}));class qB extends qd{constructor(t){super(t,UB,$a(t.event.target))}}qB.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:n}=t;return r.button===Gd.RightClick?!1:(n==null||n({event:r}),!0)}}];const Kd={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class GB extends qd{constructor(t){super(t,Kd)}static setup(){return window.addEventListener(Kd.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(Kd.move.name,t)};function t(){}}}GB.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:n}=t;const{touches:a}=r;return a.length>1?!1:(n==null||n({event:r}),!0)}}];var qo;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(qo||(qo={}));var Vi;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(Vi||(Vi={}));function KB(e){let{acceleration:t,activator:r=qo.Pointer,canScroll:n,draggingRect:a,enabled:o,interval:i=5,order:c=Vi.TreeOrder,pointerCoordinates:d,scrollableAncestors:u,scrollableAncestorRects:f,delta:h,threshold:p}=e;const m=YB({delta:h,disabled:!o}),[v,g]=dB(),b=C.useRef({x:0,y:0}),w=C.useRef({x:0,y:0}),x=C.useMemo(()=>{switch(r){case qo.Pointer:return d?{top:d.y,bottom:d.y,left:d.x,right:d.x}:null;case qo.DraggableRect:return a}},[r,a,d]),y=C.useRef(null),E=C.useCallback(()=>{const j=y.current;if(!j)return;const A=b.current.x*w.current.x,S=b.current.y*w.current.y;j.scrollBy(A,S)},[]),k=C.useMemo(()=>c===Vi.TreeOrder?[...u].reverse():u,[c,u]);C.useEffect(()=>{if(!o||!u.length||!x){g();return}for(const j of k){if((n==null?void 0:n(j))===!1)continue;const A=u.indexOf(j),S=f[A];if(!S)continue;const{direction:_,speed:M}=$B(j,S,x,t,p);for(const B of["x","y"])m[B][_[B]]||(M[B]=0,_[B]=0);if(M.x>0||M.y>0){g(),y.current=j,v(E,i),b.current=M,w.current=_;return}}b.current={x:0,y:0},w.current={x:0,y:0},g()},[t,E,n,g,o,i,JSON.stringify(x),JSON.stringify(m),v,u,k,f,JSON.stringify(p)])}const JB={x:{[yt.Backward]:!1,[yt.Forward]:!1},y:{[yt.Backward]:!1,[yt.Forward]:!1}};function YB(e){let{delta:t,disabled:r}=e;const n=Ti(t);return Po(a=>{if(r||!n||!a)return JB;const o={x:Math.sign(t.x-n.x),y:Math.sign(t.y-n.y)};return{x:{[yt.Backward]:a.x[yt.Backward]||o.x===-1,[yt.Forward]:a.x[yt.Forward]||o.x===1},y:{[yt.Backward]:a.y[yt.Backward]||o.y===-1,[yt.Forward]:a.y[yt.Forward]||o.y===1}}},[r,t,n])}function XB(e,t){const r=t!=null?e.get(t):void 0,n=r?r.node.current:null;return Po(a=>{var o;return t==null?null:(o=n??a)!=null?o:null},[n,t])}function QB(e,t){return C.useMemo(()=>e.reduce((r,n)=>{const{sensor:a}=n,o=a.activators.map(i=>({eventName:i.eventName,handler:t(i.handler,n)}));return[...r,...o]},[]),[e,t])}var Go;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Go||(Go={}));var Jd;(function(e){e.Optimized="optimized"})(Jd||(Jd={}));const Uf=new Map;function eP(e,t){let{dragging:r,dependencies:n,config:a}=t;const[o,i]=C.useState(null),{frequency:c,measure:d,strategy:u}=a,f=C.useRef(e),h=b(),p=Bo(h),m=C.useCallback(function(w){w===void 0&&(w=[]),!p.current&&i(x=>x===null?w:x.concat(w.filter(y=>!x.includes(y))))},[p]),v=C.useRef(null),g=Po(w=>{if(h&&!r)return Uf;if(!w||w===Uf||f.current!==e||o!=null){const x=new Map;for(let y of e){if(!y)continue;if(o&&o.length>0&&!o.includes(y.id)&&y.rect.current){x.set(y.id,y.rect.current);continue}const E=y.node.current,k=E?new Wd(d(E),E):null;y.rect.current=k,k&&x.set(y.id,k)}return x}return w},[e,o,r,h,d]);return C.useEffect(()=>{f.current=e},[e]),C.useEffect(()=>{h||m()},[r,h]),C.useEffect(()=>{o&&o.length>0&&i(null)},[JSON.stringify(o)]),C.useEffect(()=>{h||typeof c!="number"||v.current!==null||(v.current=setTimeout(()=>{m(),v.current=null},c))},[c,h,m,...n]),{droppableRects:g,measureDroppableContainers:m,measuringScheduled:o!=null};function b(){switch(u){case Go.Always:return!1;case Go.BeforeDragging:return r;default:return!r}}}function Yd(e,t){return Po(r=>e?r||(typeof t=="function"?t(e):e):null,[t,e])}function tP(e,t){return Yd(e,t)}function rP(e){let{callback:t,disabled:r}=e;const n=Oi(t),a=C.useMemo(()=>{if(r||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(n)},[n,r]);return C.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function Zi(e){let{callback:t,disabled:r}=e;const n=Oi(t),a=C.useMemo(()=>{if(r||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(n)},[r]);return C.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function nP(e){return new Wd(Pa(e),e)}function qf(e,t,r){t===void 0&&(t=nP);const[n,a]=C.useState(null);function o(){a(d=>{if(!e)return null;if(e.isConnected===!1){var u;return(u=d??r)!=null?u:null}const f=t(e);return JSON.stringify(d)===JSON.stringify(f)?d:f})}const i=rP({callback(d){if(e)for(const u of d){const{type:f,target:h}=u;if(f==="childList"&&h instanceof HTMLElement&&h.contains(e)){o();break}}}}),c=Zi({callback:o});return xr(()=>{o(),e?(c==null||c.observe(e),i==null||i.observe(document.body,{childList:!0,subtree:!0})):(c==null||c.disconnect(),i==null||i.disconnect())},[e]),n}function aP(e){const t=Yd(e);return Mf(e,t)}const Gf=[];function oP(e){const t=C.useRef(e),r=Po(n=>e?n&&n!==Gf&&e&&t.current&&e.parentNode===t.current.parentNode?n:Pi(e):Gf,[e]);return C.useEffect(()=>{t.current=e},[e]),r}function sP(e){const[t,r]=C.useState(null),n=C.useRef(e),a=C.useCallback(o=>{const i=zd(o.target);i&&r(c=>c?(c.set(i,Hd(i)),new Map(c)):null)},[]);return C.useEffect(()=>{const o=n.current;if(e!==o){i(o);const c=e.map(d=>{const u=zd(d);return u?(u.addEventListener("scroll",a,{passive:!0}),[u,Hd(u)]):null}).filter(d=>d!=null);r(c.length?new Map(c):null),n.current=e}return()=>{i(e),i(o)};function i(c){c.forEach(d=>{const u=zd(d);u==null||u.removeEventListener("scroll",a)})}},[a,e]),C.useMemo(()=>e.length?t?Array.from(t.values()).reduce((o,i)=>Ia(o,i),yr):Pf(e):yr,[e,t])}function Kf(e,t){t===void 0&&(t=[]);const r=C.useRef(null);return C.useEffect(()=>{r.current=null},t),C.useEffect(()=>{const n=e!==yr;n&&!r.current&&(r.current=e),!n&&r.current&&(r.current=null)},[e]),r.current?Zo(e,r.current):yr}function iP(e){C.useEffect(()=>{if(!Ri)return;const t=e.map(r=>{let{sensor:n}=r;return n.setup==null?void 0:n.setup()});return()=>{for(const r of t)r==null||r()}},e.map(t=>{let{sensor:r}=t;return r}))}function lP(e,t){return C.useMemo(()=>e.reduce((r,n)=>{let{eventName:a,handler:o}=n;return r[a]=i=>{o(i,t)},r},{}),[e,t])}function Jf(e){return C.useMemo(()=>e?RB(e):null,[e])}const Yf=[];function cP(e,t){t===void 0&&(t=Pa);const[r]=e,n=Jf(r?Ot(r):null),[a,o]=C.useState(Yf);function i(){o(()=>e.length?e.map(d=>If(d)?n:new Wd(t(d),d)):Yf)}const c=Zi({callback:i});return xr(()=>{c==null||c.disconnect(),i(),e.forEach(d=>c==null?void 0:c.observe(d))},[e]),a}function Xf(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Io(t)?t:e}function dP(e){let{measure:t}=e;const[r,n]=C.useState(null),a=C.useCallback(u=>{for(const{target:f}of u)if(Io(f)){n(h=>{const p=t(f);return h?{...h,width:p.width,height:p.height}:p});break}},[t]),o=Zi({callback:a}),i=C.useCallback(u=>{const f=Xf(u);o==null||o.disconnect(),f&&(o==null||o.observe(f)),n(f?t(f):null)},[t,o]),[c,d]=Li(i);return C.useMemo(()=>({nodeRef:c,rect:r,setRef:d}),[r,c,d])}const uP=[{sensor:Uo,options:{}},{sensor:Wo,options:{}}],fP={current:{}},zi={draggable:{measure:Of},droppable:{measure:Of,strategy:Go.WhileDragging,frequency:Jd.Optimized},dragOverlay:{measure:Pa}};class Ko extends Map{get(t){var r;return t!=null&&(r=super.get(t))!=null?r:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:r}=t;return!r})}getNodeFor(t){var r,n;return(r=(n=this.get(t))==null?void 0:n.node.current)!=null?r:void 0}}const hP={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Ko,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Bi},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:zi,measureDroppableContainers:Bi,windowRect:null,measuringScheduled:!1},Qf={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Bi,draggableNodes:new Map,over:null,measureDroppableContainers:Bi},Jo=C.createContext(Qf),eh=C.createContext(hP);function pP(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Ko}}}function mP(e,t){switch(t.type){case bt.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case bt.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case bt.DragEnd:case bt.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case bt.RegisterDroppable:{const{element:r}=t,{id:n}=r,a=new Ko(e.droppable.containers);return a.set(n,r),{...e,droppable:{...e.droppable,containers:a}}}case bt.SetDroppableDisabled:{const{id:r,key:n,disabled:a}=t,o=e.droppable.containers.get(r);if(!o||n!==o.key)return e;const i=new Ko(e.droppable.containers);return i.set(r,{...o,disabled:a}),{...e,droppable:{...e.droppable,containers:i}}}case bt.UnregisterDroppable:{const{id:r,key:n}=t,a=e.droppable.containers.get(r);if(!a||n!==a.key)return e;const o=new Ko(e.droppable.containers);return o.delete(r),{...e,droppable:{...e.droppable,containers:o}}}default:return e}}function gP(e){let{disabled:t}=e;const{active:r,activatorEvent:n,draggableNodes:a}=C.useContext(Jo),o=Ti(n),i=Ti(r==null?void 0:r.id);return C.useEffect(()=>{if(!t&&!n&&o&&i!=null){if(!$i(o)||document.activeElement===o.target)return;const c=a.get(i);if(!c)return;const{activatorNode:d,node:u}=c;if(!d.current&&!u.current)return;requestAnimationFrame(()=>{for(const f of[d.current,u.current]){if(!f)continue;const h=hB(f);if(h){h.focus();break}}})}},[n,t,a,i,o]),null}function th(e,t){let{transform:r,...n}=t;return e!=null&&e.length?e.reduce((a,o)=>o({transform:a,...n}),r):r}function vP(e){return C.useMemo(()=>({draggable:{...zi.draggable,...e==null?void 0:e.draggable},droppable:{...zi.droppable,...e==null?void 0:e.droppable},dragOverlay:{...zi.dragOverlay,...e==null?void 0:e.dragOverlay}}),[e==null?void 0:e.draggable,e==null?void 0:e.droppable,e==null?void 0:e.dragOverlay])}function bP(e){let{activeNode:t,measure:r,initialRect:n,config:a=!0}=e;const o=C.useRef(!1),{x:i,y:c}=typeof a=="boolean"?{x:a,y:a}:a;xr(()=>{if(!i&&!c||!t){o.current=!1;return}if(o.current||!n)return;const u=t==null?void 0:t.node.current;if(!u||u.isConnected===!1)return;const f=r(u),h=Mf(f,n);if(i||(h.x=0),c||(h.y=0),o.current=!0,Math.abs(h.x)>0||Math.abs(h.y)>0){const p=Lf(u);p&&p.scrollBy({top:h.y,left:h.x})}},[t,i,c,n,r])}const Hi=C.createContext({...yr,scaleX:1,scaleY:1});var kn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(kn||(kn={}));const Xd=C.memo(function(t){var r,n,a,o;let{id:i,accessibility:c,autoScroll:d=!0,children:u,sensors:f=uP,collisionDetection:h=_f,measuring:p,modifiers:m,...v}=t;const g=C.useReducer(mP,void 0,pP),[b,w]=g,[x,y]=bB(),[E,k]=C.useState(kn.Uninitialized),j=E===kn.Initialized,{draggable:{active:A,nodes:S,translate:_},droppable:{containers:M}}=b,B=A!=null?S.get(A):null,R=C.useRef({initial:null,translated:null}),I=C.useMemo(()=>{var Fe;return A!=null?{id:A,data:(Fe=B==null?void 0:B.data)!=null?Fe:fP,rect:R}:null},[A,B]),F=C.useRef(null),[Z,ee]=C.useState(null),[Y,te]=C.useState(null),ae=Bo(v,Object.values(v)),q=Vo("DndDescribedBy",i),N=C.useMemo(()=>M.getEnabled(),[M]),L=vP(p),{droppableRects:ne,measureDroppableContainers:K,measuringScheduled:Q}=eP(N,{dragging:j,dependencies:[_.x,_.y],config:L.droppable}),he=XB(S,A),ie=C.useMemo(()=>Y?Ii(Y):null,[Y]),me=Ne(),ce=tP(he,L.draggable.measure);bP({activeNode:A!=null?S.get(A):null,config:me.layoutShiftCompensation,initialRect:ce,measure:L.draggable.measure});const le=qf(he,L.draggable.measure,ce),be=qf(he?he.parentElement:null),fe=C.useRef({activatorEvent:null,active:null,activeNode:he,collisionRect:null,collisions:null,droppableRects:ne,draggableNodes:S,draggingNode:null,draggingNodeRect:null,droppableContainers:M,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),xe=M.getNodeFor((r=fe.current.over)==null?void 0:r.id),D=dP({measure:L.dragOverlay.measure}),G=(n=D.nodeRef.current)!=null?n:he,re=j?(a=D.rect)!=null?a:le:null,W=!!(D.nodeRef.current&&D.rect),H=aP(W?null:le),X=Jf(G?Ot(G):null),O=oP(j?xe??he:null),V=cP(O),T=th(m,{transform:{x:_.x-H.x,y:_.y-H.y,scaleX:1,scaleY:1},activatorEvent:Y,active:I,activeNodeRect:le,containerNodeRect:be,draggingNodeRect:re,over:fe.current.over,overlayNodeRect:D.rect,scrollableAncestors:O,scrollableAncestorRects:V,windowRect:X}),$=ie?Ia(ie,_):null,P=sP(O),z=Kf(P),U=Kf(P,[le]),J=Ia(T,z),oe=re?FB(re,T):null,de=I&&oe?h({active:I,collisionRect:oe,droppableRects:ne,droppableContainers:N,pointerCoordinates:$}):null,ge=Nf(de,"id"),[we,Ce]=C.useState(null),ke=W?T:Ia(T,U),Ie=AB(ke,(o=we==null?void 0:we.rect)!=null?o:null,le),Le=C.useRef(null),De=C.useCallback((Fe,Me)=>{let{sensor:_e,options:Te}=Me;if(F.current==null)return;const Ze=S.get(F.current);if(!Ze)return;const He=Fe.nativeEvent,Ue=new _e({active:F.current,activeNode:Ze,event:He,options:Te,context:fe,onAbort(ze){if(!S.get(ze))return;const{onDragAbort:Ke}=ae.current,ht={id:ze};Ke==null||Ke(ht),x({type:"onDragAbort",event:ht})},onPending(ze,Ye,Ke,ht){if(!S.get(ze))return;const{onDragPending:Ln}=ae.current,Er={id:ze,constraint:Ye,initialCoordinates:Ke,offset:ht};Ln==null||Ln(Er),x({type:"onDragPending",event:Er})},onStart(ze){const Ye=F.current;if(Ye==null)return;const Ke=S.get(Ye);if(!Ke)return;const{onDragStart:ht}=ae.current,$r={activatorEvent:He,active:{id:Ye,data:Ke.data,rect:R}};at.unstable_batchedUpdates(()=>{ht==null||ht($r),k(kn.Initializing),w({type:bt.DragStart,initialCoordinates:ze,active:Ye}),x({type:"onDragStart",event:$r}),ee(Le.current),te(He)})},onMove(ze){w({type:bt.DragMove,coordinates:ze})},onEnd:Tt(bt.DragEnd),onCancel:Tt(bt.DragCancel)});Le.current=Ue;function Tt(ze){return async function(){const{active:Ke,collisions:ht,over:$r,scrollAdjustedTranslate:Ln}=fe.current;let Er=null;if(Ke&&Ln){const{cancelDrop:cn}=ae.current;Er={activatorEvent:He,active:Ke,collisions:ht,delta:Ln,over:$r},ze===bt.DragEnd&&typeof cn=="function"&&await Promise.resolve(cn(Er))&&(ze=bt.DragCancel)}F.current=null,at.unstable_batchedUpdates(()=>{w({type:ze}),k(kn.Uninitialized),Ce(null),ee(null),te(null),Le.current=null;const cn=ze===bt.DragEnd?"onDragEnd":"onDragCancel";if(Er){const q0=ae.current[cn];q0==null||q0(Er),x({type:cn,event:Er})}})}}},[S]),Re=C.useCallback((Fe,Me)=>(_e,Te)=>{const Ze=_e.nativeEvent,He=S.get(Te);if(F.current!==null||!He||Ze.dndKit||Ze.defaultPrevented)return;const Ue={active:He};Fe(_e,Me.options,Ue)===!0&&(Ze.dndKit={capturedBy:Me.sensor},F.current=Te,De(_e,Me))},[S,De]),Ve=QB(f,Re);iP(f),xr(()=>{le&&E===kn.Initializing&&k(kn.Initialized)},[le,E]),C.useEffect(()=>{const{onDragMove:Fe}=ae.current,{active:Me,activatorEvent:_e,collisions:Te,over:Ze}=fe.current;if(!Me||!_e)return;const He={active:Me,activatorEvent:_e,collisions:Te,delta:{x:J.x,y:J.y},over:Ze};at.unstable_batchedUpdates(()=>{Fe==null||Fe(He),x({type:"onDragMove",event:He})})},[J.x,J.y]),C.useEffect(()=>{const{active:Fe,activatorEvent:Me,collisions:_e,droppableContainers:Te,scrollAdjustedTranslate:Ze}=fe.current;if(!Fe||F.current==null||!Me||!Ze)return;const{onDragOver:He}=ae.current,Ue=Te.get(ge),Tt=Ue&&Ue.rect.current?{id:Ue.id,rect:Ue.rect.current,data:Ue.data,disabled:Ue.disabled}:null,ze={active:Fe,activatorEvent:Me,collisions:_e,delta:{x:Ze.x,y:Ze.y},over:Tt};at.unstable_batchedUpdates(()=>{Ce(Tt),He==null||He(ze),x({type:"onDragOver",event:ze})})},[ge]),xr(()=>{fe.current={activatorEvent:Y,active:I,activeNode:he,collisionRect:oe,collisions:de,droppableRects:ne,draggableNodes:S,draggingNode:G,draggingNodeRect:re,droppableContainers:M,over:we,scrollableAncestors:O,scrollAdjustedTranslate:J},R.current={initial:re,translated:oe}},[I,he,de,oe,S,G,re,ne,M,we,O,J]),KB({...me,delta:_,draggingRect:oe,pointerCoordinates:$,scrollableAncestors:O,scrollableAncestorRects:V});const Ge=C.useMemo(()=>({active:I,activeNode:he,activeNodeRect:le,activatorEvent:Y,collisions:de,containerNodeRect:be,dragOverlay:D,draggableNodes:S,droppableContainers:M,droppableRects:ne,over:we,measureDroppableContainers:K,scrollableAncestors:O,scrollableAncestorRects:V,measuringConfiguration:L,measuringScheduled:Q,windowRect:X}),[I,he,le,Y,de,be,D,S,M,ne,we,K,O,V,L,Q,X]),ft=C.useMemo(()=>({activatorEvent:Y,activators:Ve,active:I,activeNodeRect:le,ariaDescribedById:{draggable:q},dispatch:w,draggableNodes:S,over:we,measureDroppableContainers:K}),[Y,Ve,I,le,w,q,S,we,K]);return C.createElement(Af.Provider,{value:y},C.createElement(Jo.Provider,{value:ft},C.createElement(eh.Provider,{value:Ge},C.createElement(Hi.Provider,{value:Ie},u)),C.createElement(gP,{disabled:(c==null?void 0:c.restoreFocus)===!1})),C.createElement(yB,{...c,hiddenTextDescribedById:q}));function Ne(){const Fe=(Z==null?void 0:Z.autoScrollEnabled)===!1,Me=typeof d=="object"?d.enabled===!1:d===!1,_e=j&&!Fe&&!Me;return typeof d=="object"?{...d,enabled:_e}:{enabled:_e}}}),wP=C.createContext(null),rh="button",xP="Draggable";function Jn(e){let{id:t,data:r,disabled:n=!1,attributes:a}=e;const o=Vo(xP),{activators:i,activatorEvent:c,active:d,activeNodeRect:u,ariaDescribedById:f,draggableNodes:h,over:p}=C.useContext(Jo),{role:m=rh,roleDescription:v="draggable",tabIndex:g=0}=a??{},b=(d==null?void 0:d.id)===t,w=C.useContext(b?Hi:wP),[x,y]=Li(),[E,k]=Li(),j=lP(i,t),A=Bo(r);xr(()=>(h.set(t,{id:t,key:o,node:x,activatorNode:E,data:A}),()=>{const _=h.get(t);_&&_.key===o&&h.delete(t)}),[h,t]);const S=C.useMemo(()=>({role:m,tabIndex:g,"aria-disabled":n,"aria-pressed":b&&m===rh?!0:void 0,"aria-roledescription":v,"aria-describedby":f.draggable}),[n,m,g,b,v,f.draggable]);return{active:d,activatorEvent:c,activeNodeRect:u,attributes:S,isDragging:b,listeners:n?void 0:j,node:x,over:p,setNodeRef:y,setActivatorNodeRef:k,transform:w}}function nh(){return C.useContext(eh)}const yP="Droppable",kP={timeout:25};function Sr(e){let{data:t,disabled:r=!1,id:n,resizeObserverConfig:a}=e;const o=Vo(yP),{active:i,dispatch:c,over:d,measureDroppableContainers:u}=C.useContext(Jo),f=C.useRef({disabled:r}),h=C.useRef(!1),p=C.useRef(null),m=C.useRef(null),{disabled:v,updateMeasurementsFor:g,timeout:b}={...kP,...a},w=Bo(g??n),x=C.useCallback(()=>{if(!h.current){h.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{u(Array.isArray(w.current)?w.current:[w.current]),m.current=null},b)},[b]),y=Zi({callback:x,disabled:v||!i}),E=C.useCallback((S,_)=>{y&&(_&&(y.unobserve(_),h.current=!1),S&&y.observe(S))},[y]),[k,j]=Li(E),A=Bo(t);return C.useEffect(()=>{!y||!k.current||(y.disconnect(),h.current=!1,y.observe(k.current))},[k,y]),C.useEffect(()=>(c({type:bt.RegisterDroppable,element:{id:n,key:o,disabled:r,node:k,rect:p,data:A}}),()=>c({type:bt.UnregisterDroppable,key:o,id:n})),[n]),C.useEffect(()=>{r!==f.current.disabled&&(c({type:bt.SetDroppableDisabled,id:n,key:o,disabled:r}),f.current.disabled=r)},[n,o,r,c]),{active:i,rect:p,isOver:(d==null?void 0:d.id)===n,node:k,over:d,setNodeRef:j}}function EP(e){let{animation:t,children:r}=e;const[n,a]=C.useState(null),[o,i]=C.useState(null),c=Ti(r);return!r&&!n&&c&&a(c),xr(()=>{if(!o)return;const d=n==null?void 0:n.key,u=n==null?void 0:n.props.id;if(d==null||u==null){a(null);return}Promise.resolve(t(u,o)).then(()=>{a(null)})},[t,n,o]),C.createElement(C.Fragment,null,r,n?C.cloneElement(n,{ref:i}):null)}const CP={x:0,y:0,scaleX:1,scaleY:1};function jP(e){let{children:t}=e;return C.createElement(Jo.Provider,{value:Qf},C.createElement(Hi.Provider,{value:CP},t))}const DP={position:"fixed",touchAction:"none"},SP=e=>$i(e)?"transform 250ms ease":void 0,AP=C.forwardRef((e,t)=>{let{as:r,activatorEvent:n,adjustScale:a,children:o,className:i,rect:c,style:d,transform:u,transition:f=SP}=e;if(!c)return null;const h=a?u:{...u,scaleX:1,scaleY:1},p={...DP,width:c.width,height:c.height,top:c.top,left:c.left,transform:Wr.Transform.toString(h),transformOrigin:a&&n?kB(n,c):void 0,transition:typeof f=="function"?f(n):f,...d};return C.createElement(r,{className:i,style:p,ref:t},o)}),NP={duration:250,easing:"ease",keyframes:e=>{let{transform:{initial:t,final:r}}=e;return[{transform:Wr.Transform.toString(t)},{transform:Wr.Transform.toString(r)}]},sideEffects:(e=>t=>{let{active:r,dragOverlay:n}=t;const a={},{styles:o,className:i}=e;if(o!=null&&o.active)for(const[c,d]of Object.entries(o.active))d!==void 0&&(a[c]=r.node.style.getPropertyValue(c),r.node.style.setProperty(c,d));if(o!=null&&o.dragOverlay)for(const[c,d]of Object.entries(o.dragOverlay))d!==void 0&&n.node.style.setProperty(c,d);return i!=null&&i.active&&r.node.classList.add(i.active),i!=null&&i.dragOverlay&&n.node.classList.add(i.dragOverlay),function(){for(const[d,u]of Object.entries(a))r.node.style.setProperty(d,u);i!=null&&i.active&&r.node.classList.remove(i.active)}})({styles:{active:{opacity:"0"}}})};function FP(e){let{config:t,draggableNodes:r,droppableContainers:n,measuringConfiguration:a}=e;return Oi((o,i)=>{if(t===null)return;const c=r.get(o);if(!c)return;const d=c.node.current;if(!d)return;const u=Xf(i);if(!u)return;const{transform:f}=Ot(i).getComputedStyle(i),h=Rf(f);if(!h)return;const p=typeof t=="function"?t:_P(t);return Vf(d,a.draggable.measure),p({active:{id:o,data:c.data,node:d,rect:a.draggable.measure(d)},draggableNodes:r,dragOverlay:{node:i,rect:a.dragOverlay.measure(u)},droppableContainers:n,measuringConfiguration:a,transform:h})})}function _P(e){const{duration:t,easing:r,sideEffects:n,keyframes:a}={...NP,...e};return o=>{let{active:i,dragOverlay:c,transform:d,...u}=o;if(!t)return;const f={x:c.rect.left-i.rect.left,y:c.rect.top-i.rect.top},h={scaleX:d.scaleX!==1?i.rect.width*d.scaleX/c.rect.width:1,scaleY:d.scaleY!==1?i.rect.height*d.scaleY/c.rect.height:1},p={x:d.x-f.x,y:d.y-f.y,...h},m=a({...u,active:i,dragOverlay:c,transform:{initial:d,final:p}}),[v]=m,g=m[m.length-1];if(JSON.stringify(v)===JSON.stringify(g))return;const b=n==null?void 0:n({active:i,dragOverlay:c,...u}),w=c.node.animate(m,{duration:t,easing:r,fill:"forwards"});return new Promise(x=>{w.onfinish=()=>{b==null||b(),x()}})}}let ah=0;function MP(e){return C.useMemo(()=>{if(e!=null)return ah++,ah},[e])}const oh=C.memo(e=>{let{adjustScale:t=!1,children:r,dropAnimation:n,style:a,transition:o,modifiers:i,wrapperElement:c="div",className:d,zIndex:u=999}=e;const{activatorEvent:f,active:h,activeNodeRect:p,containerNodeRect:m,draggableNodes:v,droppableContainers:g,dragOverlay:b,over:w,measuringConfiguration:x,scrollableAncestors:y,scrollableAncestorRects:E,windowRect:k}=nh(),j=C.useContext(Hi),A=MP(h==null?void 0:h.id),S=th(i,{activatorEvent:f,active:h,activeNodeRect:p,containerNodeRect:m,draggingNodeRect:b.rect,over:w,overlayNodeRect:b.rect,scrollableAncestors:y,scrollableAncestorRects:E,transform:j,windowRect:k}),_=Yd(p),M=FP({config:n,draggableNodes:v,droppableContainers:g,measuringConfiguration:x}),B=_?b.setRef:void 0;return C.createElement(jP,null,C.createElement(EP,{animation:M},h&&A?C.createElement(AP,{key:A,id:h.id,ref:B,as:c,activatorEvent:f,adjustScale:t,className:d,transition:o,rect:_,style:{zIndex:u,...a},transform:S},r):null))}),RP={text:"var(--comp-text)",number:"var(--comp-number)",email:"var(--comp-email)",password:"var(--comp-password, var(--comp-text))",tel:"var(--comp-tel, var(--comp-text))",url:"var(--comp-url, var(--comp-text))",select:"var(--comp-select)",checkbox:"var(--comp-checkbox)",optionGroup:"var(--comp-checkbox)",textarea:"var(--comp-textarea)",date:"var(--comp-date)",file:"var(--comp-file)",search:"var(--comp-search, var(--comp-text))","section-layout":"var(--comp-section)","tabs-layout":"var(--comp-tabs)",inputGroup:"var(--comp-text)",array:"var(--comp-section)",button:"var(--comp-button, var(--color-ds-button-primary-bg))",iban:"var(--comp-iban, var(--comp-text))",dni:"var(--comp-dni, var(--comp-text))",table:"var(--comp-section)"};function Ur(e){return e?RP[e]??"var(--comp-file)":"var(--comp-file)"}function kr(e){const t="w-4 h-4",r={color:Ur(e)};switch(e){case"text":return l.jsx(ma,{className:t,style:r});case"number":return l.jsx(N1,{className:t,style:r});case"email":return l.jsx(Xl,{className:t,style:r});case"password":return l.jsx(vo,{className:t,style:r});case"tel":return l.jsx(oc,{className:t,style:r});case"url":return l.jsx(nc,{className:t,style:r});case"select":return l.jsx(go,{className:t,style:r});case"checkbox":return l.jsx(fn,{className:t,style:r});case"optionGroup":return l.jsx(fn,{className:t,style:r});case"textarea":return l.jsx(ha,{className:t,style:r});case"date":return l.jsx(g1,{className:t,style:r});case"file":return l.jsx(j1,{className:t,style:r});case"search":return l.jsx(bo,{className:t,style:r});case"section-layout":return l.jsx(sc,{className:t,style:r});case"tabs-layout":return l.jsx(cc,{className:t,style:r});case"inputGroup":return l.jsx(sc,{className:t,style:r});case"array":return l.jsx(R1,{className:t,style:r});case"button":return l.jsx(hn,{className:t,style:r});case"iban":return l.jsx(Wl,{className:t,style:r});case"dni":return l.jsx(rc,{className:t,style:r});case"table":return l.jsx(O1,{className:t,style:r});default:return l.jsx(hr,{className:t,style:r})}}const OP=[{value:"text",label:"Texto"},{value:"number",label:"Número"},{value:"email",label:"Email"},{value:"password",label:"Password"},{value:"tel",label:"Teléfono"},{value:"iban",label:"Cuenta Bancaria"},{value:"dni",label:"DNI/NIE/CIF"},{value:"url",label:"URL"},{value:"textarea",label:"Textarea"},{value:"select",label:"Select"},{value:"checkbox",label:"Checkbox"},{value:"optionGroup",label:"Option Group"},{value:"date",label:"Fecha"},{value:"file",label:"Archivo"},{value:"search",label:"Búsqueda"},{value:"array",label:"Lista Repetible"},{value:"button",label:"Botón"},{value:"table",label:"Tabla"}];function LP(){return{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"}]}}const sh=()=>l.jsxs("div",{className:"w-full border rounded text-xs p-2 bg-[var(--color-ds-background-surface)] opacity-70",children:[l.jsxs("div",{className:"flex border-b pb-1 mb-1 font-bold",children:[l.jsx("div",{className:"w-1/3",children:"H1"}),l.jsx("div",{className:"w-1/3",children:"H2"})]}),l.jsxs("div",{className:"space-y-1",children:[l.jsx("div",{className:"h-2 bg-gray-200 rounded w-3/4"}),l.jsx("div",{className:"h-2 bg-gray-200 rounded w-1/2"})]})]});function TP(){return{label:"Cuenta Bancaria",type:"iban",width:"w-full",placeholder:"ES00 0000 0000 0000 0000 0000",size:"sm"}}function $P(){return{label:"DNI/NIE",type:"dni",width:"w-full",placeholder:"12345678A",size:"sm"}}function IP(){return{label:"Texto",type:"text",width:"w-full",placeholder:"Escribe…",size:"sm"}}function BP(){return{label:"Número",type:"number",width:"w-full",placeholder:"0",size:"sm",validation:{required:!1}}}function PP(){return{label:"Email",type:"email",width:"w-full",placeholder:"usuario@dominio.com",size:"sm"}}function VP(){return{label:"Contraseña",type:"password",width:"w-full",placeholder:"••••••••",size:"sm",validation:{minLength:8}}}function ZP(){return{label:"Teléfono",type:"tel",width:"w-full",placeholder:"600 000 000",size:"sm"}}function zP(){return{label:"URL",type:"url",width:"w-full",placeholder:"https://ejemplo.com",size:"sm"}}function HP(){return{label:"Selecciona una opción",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}}function WP(){return{label:"Aceptar condiciones",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}}function UP(){return{label:"Comentario",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"Escribe tu comentario…"}}function qP(){return{label:"Fecha",type:"date",width:"w-full",size:"sm",showTime:!1}}function GP(){return{label:"Documento",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}}function KP(){return{label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}}function JP(){return{label:"Búsqueda",type:"search",width:"w-full",placeholder:"Buscar...",size:"sm",searchMode:"button"}}function YP(){return{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"}]}}function XP(){return{label:"Lista repetible",type:"array",width:"w-full",items:[]}}function QP(){return{label:"Botón",type:"button",width:"w-auto",variant:"primary",size:"sm"}}const eV={text:IP,number:BP,email:PP,password:VP,tel:ZP,iban:TP,dni:$P,table:LP,url:zP,select:HP,checkbox:WP,optionGroup:YP,textarea:UP,date:qP,file:GP,search:JP,inputGroup:KP,array:XP,button:QP},ih=()=>l.jsx(je,{label:"Texto",placeholder:"Escribe…",size:"sm",reserveErrorSpace:!1}),lh=()=>l.jsx(je,{type:"number",label:"Número",placeholder:"0",size:"sm",reserveErrorSpace:!1}),ch=()=>l.jsx(je,{type:"email",label:"Email",placeholder:"usuario@dominio.com",size:"sm",reserveErrorSpace:!1}),dh=()=>l.jsx(je,{type:"password",label:"Contraseña",placeholder:"••••••••",size:"sm",reserveErrorSpace:!1}),uh=()=>l.jsx(je,{type:"tel",label:"Teléfono",placeholder:"600 000 000",size:"sm",reserveErrorSpace:!1}),fh=()=>l.jsx(Ci,{label:"Cuenta Bancaria",placeholder:"ES00 0000 0000 0000 0000 0000",size:"sm",reserveErrorSpace:!1,value:"",onChange:()=>{}}),hh=()=>l.jsx(hd,{label:"DNI/NIE",placeholder:"12345678A",size:"sm",reserveErrorSpace:!1,value:"",onChange:()=>{}}),ph=()=>l.jsx(je,{type:"url",label:"URL",placeholder:"https://ejemplo.com",size:"sm",reserveErrorSpace:!1}),mh=()=>l.jsx(Xe,{label:"Select",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}],size:"sm"}),gh=()=>l.jsx(it,{label:"Aceptar condiciones",defaultValue:!1,name:"__prev_checkbox__"}),vh=()=>l.jsx(Dr,{label:"Comentario",placeholder:"Escribe tu comentario…",size:"sm",maxLength:120,showCounter:!0}),bh=()=>l.jsx(Sa,{label:"Fecha",defaultValue:"",showTime:!1,name:"__prev_date__"}),wh=()=>l.jsxs("div",{children:[l.jsx("label",{className:"text-ds-sm mb-1 block opacity-80",children:"Documento"}),l.jsx("div",{className:"w-full rounded-xl border border-dashed p-4 text-ds-sm opacity-70",children:"Arrastra o selecciona archivo…"})]}),xh=()=>l.jsx(je,{label:"Búsqueda",placeholder:"Buscar...",size:"sm",reserveErrorSpace:!1,suffixButton:l.jsx(pe,{size:"sm",variant:"primary",className:"!rounded-l-none",children:"Buscar"})}),yh=()=>{const e=$c({defaultValues:{__prev_optiongroup__:[]}});return l.jsx(wc,{...e,children:l.jsx(ki,{groupLabel:"Selecciona opciones",options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}],control:e.control,name:"__prev_optiongroup__",multiple:!0,vertical:!0,size:"sm"})})},kh=()=>l.jsx("div",{className:"p-2 rounded-md bg-[var(--color-ds-background-surface)]",children:l.jsx(zr,{options:[{label:"Tab 1",value:"t1"},{label:"Tab 2",value:"t2"}],value:"t1",onChange:()=>{},children:{t1:l.jsx("div",{className:"text-ds-sm opacity-80",children:"Contenido ejemplo 1"}),t2:l.jsx("div",{className:"text-ds-sm opacity-80",children:"Contenido ejemplo 2"})}})}),Eh=()=>l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)]",children:[l.jsx("div",{className:"px-3 py-2 border-b border-[var(--color-ds-border-default-50)] text-ds-sm",children:"Sección"}),l.jsx("div",{className:"p-3 text-ds-sm opacity-70",children:"Fila con 1 columna (w-full). Modifícala desde el lienzo."})]}),Ch=()=>l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-3",children:[l.jsx("div",{className:"text-ds-sm mb-2 opacity-70",children:"Grupo"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(je,{size:"sm",placeholder:"Campo A",reserveErrorSpace:!1}),l.jsx(je,{size:"sm",placeholder:"Campo B",reserveErrorSpace:!1})]})]}),jh=()=>l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-3",children:[l.jsx("div",{className:"text-ds-sm mb-2 opacity-70",children:"Repeater (Array)"}),l.jsx("div",{className:"border border-dashed border-[var(--color-ds-border-default-50)] rounded p-2 text-center text-ds-sm opacity-60",children:"Arrastra campos aquí"})]}),Dh=()=>l.jsxs("div",{className:"flex flex-wrap gap-2",children:[l.jsx(pe,{size:"sm",variant:"primary",children:"Primario"}),l.jsx(pe,{size:"sm",variant:"outline",children:"Outline"}),l.jsx(pe,{size:"sm",variant:"ghost",children:"Ghost"})]}),tV={text:l.jsx(ih,{}),number:l.jsx(lh,{}),email:l.jsx(ch,{}),password:l.jsx(dh,{}),tel:l.jsx(uh,{}),url:l.jsx(ph,{}),select:l.jsx(mh,{}),checkbox:l.jsx(gh,{}),optionGroup:l.jsx(yh,{}),textarea:l.jsx(vh,{}),date:l.jsx(bh,{}),file:l.jsx(wh,{}),search:l.jsx(xh,{}),inputGroup:l.jsx(Ch,{}),array:l.jsx(jh,{}),button:l.jsx(Dh,{}),iban:l.jsx(fh,{}),dni:l.jsx(hh,{}),table:l.jsx(sh,{}),"section-layout":l.jsx(Eh,{}),"tabs-layout":l.jsx(kh,{})},Wi=[{kind:"table",title:"Tabla",category:"content",renderPreview:l.jsx(sh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Tabla de datos."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Muestra datos tabulares."}),l.jsx("li",{children:"Configurable con columnas y origen de datos."})]})]})},{kind:"text",title:"Texto",category:"basics",renderPreview:l.jsx(ih,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo de texto de una sola línea."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Ideal para nombres, títulos o datos cortos."}),l.jsx("li",{children:"Soporta validaciones de longitud y patrones (Regex)."})]})]})},{kind:"number",title:"Número",category:"basics",renderPreview:l.jsx(lh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Entrada numérica controlada."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Útil para edades, cantidades o importes."}),l.jsx("li",{children:"Permite definir mínimos, máximos y pasos (decimales)."})]})]})},{kind:"email",title:"Email",category:"basics",renderPreview:l.jsx(ch,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo optimizado para correos electrónicos."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Valida automáticamente el formato de email."}),l.jsx("li",{children:"Activa el teclado de correo en móviles."})]})]})},{kind:"password",title:"Clave",category:"basics",renderPreview:l.jsx(dh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo seguro para contraseñas."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Oculta los caracteres por seguridad."}),l.jsx("li",{children:"Incluye botón para mostrar/ocultar contraseña."})]})]})},{kind:"tel",title:"Teléfono",category:"basics",renderPreview:l.jsx(uh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo para números telefónicos."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Activa el teclado numérico en dispositivos móviles."}),l.jsx("li",{children:"Compatible con validaciones por patrón."})]})]})},{kind:"iban",title:"IBAN",category:"basics",renderPreview:l.jsx(fh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo para cuentas bancarias en formato IBAN."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Formatea automáticamente en grupos de 4 para mejorar la lectura."}),l.jsx("li",{children:"Normaliza a mayúsculas y elimina espacios/caracteres no válidos."}),l.jsx("li",{children:"Se valida por algoritmo Módulo 97."})]})]})},{kind:"dni",title:"DNI/NIE",category:"basics",renderPreview:l.jsx(hh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo para documentos de identidad (DNI, NIE, CIF)."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Normaliza a mayúsculas y elimina espacios."}),l.jsx("li",{children:"Validación de formato básico."}),l.jsx("li",{children:"Máximo 9 caracteres alfanuméricos."})]})]})},{kind:"url",title:"URL",category:"basics",renderPreview:l.jsx(ph,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo para direcciones web."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Valida formato de URL (http/https)."}),l.jsx("li",{children:"Útil para enlaces a sitios web o recursos externos."})]})]})},{kind:"select",title:"Select",category:"basics",renderPreview:l.jsx(mh,{}),hint:"Admite optionSource",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Desplegable de selección única o múltiple."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Recomendado para listas largas de opciones."}),l.jsx("li",{children:"Puede cargar datos dinámicos desde servicios externos."})]})]})},{kind:"checkbox",title:"Check",category:"basics",renderPreview:l.jsx(gh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Casilla de verificación simple."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Para respuestas binarias (Sí/No)."}),l.jsx("li",{children:'Ideal para "Aceptar términos" o confirmaciones.'})]})]})},{kind:"optionGroup",title:"Opciones",category:"basics",renderPreview:l.jsx(yh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Grupo de opciones visibles (Radio o Checkbox)."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Muestra todas las opciones a la vez."}),l.jsx("li",{children:"Mejor UX que un Select cuando hay pocas opciones (2-5)."})]})]})},{kind:"date",title:"Fecha",category:"basics",renderPreview:l.jsx(bh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Selector de fecha completo."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Incluye calendario desplegable."}),l.jsx("li",{children:"Opcionalmente permite seleccionar hora."}),l.jsx("li",{children:"Soporta límites (min/max) y deshabilitar días."})]})]})},{kind:"textarea",title:"Textarea",category:"content",renderPreview:l.jsx(vh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Área de texto multilínea."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Para observaciones, descripciones o notas largas."}),l.jsx("li",{children:"Incluye contador de caracteres configurable."})]})]})},{kind:"file",title:"Archivo",category:"content",renderPreview:l.jsx(wh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Widget de subida de ficheros."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Soporta Arrastrar y Soltar (Drag & Drop)."}),l.jsx("li",{children:"Configurable por tipo de archivo y tamaño máximo."})]})]})},{kind:"search",title:"Búsqueda",category:"content",renderPreview:l.jsx(xh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo de búsqueda especializado."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Incluye botón de acción integrado."}),l.jsx("li",{children:"Ideal para buscadores, filtros o consultas a APIs."})]})]})},{kind:"section-layout",title:"Sección",category:"layout",renderPreview:l.jsx(Eh,{}),isLayout:!0,hint:"Contenedor de layout",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Bloque contenedor colapsable."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Agrupa campos visualmente bajo un título."}),l.jsx("li",{children:"Permite organizar el formulario en bloques lógicos."})]})]})},{kind:"tabs-layout",title:"Pestañas",category:"layout",renderPreview:l.jsx(kh,{}),isLayout:!0,hint:"Contenedor de layout (no es un campo)",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Contenedor de pestañas."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Organiza gran cantidad de información en vistas separadas."}),l.jsx("li",{children:"Cada pestaña tiene su propio contenido independiente."})]})]})},{kind:"inputGroup",title:"Grupo",category:"content",renderPreview:l.jsx(Ch,{}),hint:"Contenedor de varios inputs en una fila",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Agrupador horizontal de campos."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Coloca múltiples inputs en una sola fila (inline)."}),l.jsx("li",{children:"Útil para datos relacionados (ej. Nombre + Apellidos)."})]})]})},{kind:"array",title:"Lista",category:"content",renderPreview:l.jsx(jh,{}),hint:"Lista repetible de campos",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Lista repetible (Repeater)."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Permite al usuario añadir múltiples registros."}),l.jsx("li",{children:"Define una plantilla de campos que se repetirá por fila."})]})]})},{kind:"button",title:"Botón",category:"content",renderPreview:l.jsx(Dh,{}),hint:"Botón de acción",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Botón interactivo para ejecutar acciones."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Ejecuta acciones personalizadas al hacer click."}),l.jsx("li",{children:"Múltiples variantes: primario, outline, ghost, subtle, danger."}),l.jsx("li",{children:"Soporta iconos y diferentes tamaños."})]})]})}];function Sh({title:e,onAdd:t,onInfo:r,dragging:n=!1,icon:a,kind:o,dragRef:i,dragProps:c}){const d=Ur(o),[u,f]=C.useState(!1);C.useEffect(()=>{if(!n&&u){const p=setTimeout(()=>f(!1),50);return()=>clearTimeout(p)}},[n,u]);const h=p=>{if(u){p.preventDefault(),p.stopPropagation();return}t()};return l.jsxs("div",{className:["relative group",n?"opacity-70":""].join(" "),children:[l.jsxs(pe,{ref:i,...c,onPointerUp:()=>n&&f(!0),onClick:h,size:"sm",variant:"outline",className:["w-full rounded-xl p-2 text-left justify-start","border-dashed ring-1 ring-inset","cursor-grab active:cursor-grabbing","flex items-center gap-2 pr-11","touch-none select-none"].join(" "),title:`Añadir ${e}`,"aria-label":`Añadir ${e}`,style:{boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${d} 35%, transparent)`},type:"button",children:[l.jsx("span",{"aria-hidden":!0,className:"shrink-0 flex items-center gap-1",children:l.jsx("span",{className:"text-[var(--color-ds-text-secondary)]",style:{color:d},children:a})}),l.jsx("div",{className:"text-ds-sm",children:e})]}),l.jsx("div",{className:"absolute top-3/4 -translate-y-3/4 right-1",children:l.jsx(Pc,{size:"sm",position:"right",ariaLabel:`Más info de ${e}`,onClick:r,children:l.jsxs("div",{className:"max-w-[240px]",children:["Pulsa para ver un ejemplo y detalles de ",l.jsx("strong",{children:e}),"."]})})})]})}function Ah({kind:e,title:t,onAdd:r,onInfo:n}){const{attributes:a,listeners:o,setNodeRef:i,isDragging:c}=Jn({id:`palette:${e}:${t}`,data:{kind:"palette-field",factoryKind:e}}),{role:d,tabIndex:u}=a,f={...o,...d?{role:d}:{},...u!==void 0?{tabIndex:u}:{}};return l.jsx(Sh,{kind:e,title:t,onAdd:r,onInfo:n,dragging:c,icon:kr(e),dragRef:i,dragProps:f})}function rV(){var g;const e=se(b=>b.addField),t=se(b=>b.addTabsContainerAt),r=se(b=>b.addRowsBlockAt),n=se(b=>b.schema),{show:a}=yn(),[o,i]=C.useState(""),[c,d]=C.useState(null),u=C.useMemo(()=>Wi.filter(b=>b.category==="basics"&&b.title.toLowerCase().includes(o.toLowerCase())),[o]),f=C.useMemo(()=>Wi.filter(b=>b.category==="content"&&b.title.toLowerCase().includes(o.toLowerCase())),[o]),h=C.useMemo(()=>Wi.filter(b=>b.category==="layout"&&b.title.toLowerCase().includes(o.toLowerCase())),[o]),p=C.useMemo(()=>Wi.find(b=>b.kind===c)??null,[c]),m=C.useCallback(b=>{const w=eV[b];if(!w){a("Tipo de campo no soportado.","warning");return}const x=w();e(x),a(`Añadido “${x.label}”. Ahora arrástralo al formulario o usa “Colocar último campo”.`,"success")},[e,a]),v=C.useCallback(b=>{var x;const w=((x=n==null?void 0:n.layout)==null?void 0:x.length)??0;if(b==="section-layout"){typeof r=="function"?(r(w,"Nueva sección"),a("Sección añadida al layout.","success")):a("Acción addRowsBlockAt no disponible en el store.","warning");return}if(b==="tabs-layout"){typeof t=="function"?(t(w),a("Contenedor de pestañas añadido al layout.","success")):a("Acción addTabsContainerAt no disponible en el store.","warning");return}a("Tipo de layout no soportado.","warning")},[(g=n==null?void 0:n.layout)==null?void 0:g.length,r,t,a]);if(p){const b=!!p.isLayout;return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"px-1 border-b border-[var(--color-ds-border-default-50)] flex items-center h-[32px] mb-2",children:[l.jsx("strong",{className:"text-[var(--color-ds-text-primary)] flex-1 truncate text-sm",children:p.title}),l.jsx(pe,{size:"xs",variant:"ghost",onClick:()=>d(null),children:"← Volver"})]}),l.jsx("div",{className:"border border-[var(--color-ds-border-default-50)] p-4 bg-[var(--color-ds-background-surface)] rounded-xl",children:p.renderPreview}),l.jsxs("div",{className:"p-3 rounded-xl bg-[var(--color-ds-background-page)] border border-[var(--color-ds-border-default-50)] shadow-sm",children:[l.jsxs("div",{className:"flex flex-col items-center gap-2 mb-4",children:[l.jsx(pe,{size:"sm",variant:"primary",className:"w-full",onClick:()=>b?v(p.kind):m(p.kind),children:"Añadir al lienzo"}),l.jsx("span",{className:"text-ds-sm opacity-70",children:"o arrastra al formulario"})]}),l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] p-3 space-y-2",children:[l.jsxs("div",{className:"text-ds-sm font-medium text-[var(--color-ds-text-primary)]",children:["Acerca de ",p.title]}),l.jsxs("div",{className:"text-ds-sm space-y-2 text-[var(--color-ds-text-secondary)]",children:[p.hint&&l.jsx("div",{className:"font-medium",children:p.hint}),p.detail]})]})]})]})}return l.jsxs("div",{className:"space-y-6",children:[l.jsx("div",{className:"pb-2",children:l.jsx(je,{size:"sm",placeholder:"Buscar componente…",value:o,onChange:b=>i(b.target.value),reserveErrorSpace:!1,label:"Buscar",labelHidden:!0,"aria-label":"Buscar componente en la paleta"})}),l.jsxs("section",{className:"space-y-3",children:[l.jsx("div",{className:"text-[var(--color-ds-text-secondary)] text-ds-sm font-semibold uppercase tracking-wider",children:"Inputs básicos"}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[u.map(b=>l.jsx(Ah,{kind:b.kind,title:b.title,onAdd:()=>m(b.kind),onInfo:()=>d(b.kind)},b.kind)),u.length===0&&l.jsx("div",{className:"col-span-2 text-ds-sm opacity-60 text-center py-4",children:"Sin resultados"})]})]}),l.jsxs("section",{className:"space-y-3",children:[l.jsx("div",{className:"text-[var(--color-ds-text-secondary)] text-ds-sm font-semibold uppercase tracking-wider",children:"Contenido"}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[f.map(b=>l.jsx(Ah,{kind:b.kind,title:b.title,onAdd:()=>m(b.kind),onInfo:()=>d(b.kind)},b.kind)),f.length===0&&l.jsx("div",{className:"col-span-2 text-ds-sm opacity-60 text-center py-4",children:"Sin resultados"})]})]}),l.jsxs("section",{className:"space-y-3",children:[l.jsx("div",{className:"text-[var(--color-ds-text-secondary)] text-ds-sm font-semibold uppercase tracking-wider",children:"Layout"}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[h.map(b=>l.jsx(Sh,{kind:b.kind,title:b.title,onAdd:()=>b.isLayout?v(b.kind):m(b.kind),onInfo:()=>d(b.kind),icon:kr(b.kind)},b.kind)),h.length===0&&l.jsx("div",{className:"col-span-2 text-ds-sm opacity-60 text-center py-4",children:"Sin resultados"})]})]})]})}const Yn=[{op:"eq",label:"es igual a",inputType:"single",placeholder:"valor exacto"},{op:"neq",label:"es distinto de",inputType:"single",placeholder:"valor a excluir"},{op:"isEmpty",label:"está vacío",inputType:"none",description:"Campo sin valor",compile:e=>({op:"eq",field:e,value:""})},{op:"isNotEmpty",label:"tiene valor",inputType:"none",description:"Campo con cualquier valor",compile:e=>({op:"neq",field:e,value:""})},{op:"contains",label:"contiene",inputType:"single",placeholder:"texto a buscar",description:"El campo contiene este texto"},{op:"notContains",label:"no contiene",inputType:"single",placeholder:"texto a excluir"},{op:"startsWith",label:"empieza con",inputType:"single",placeholder:"prefijo"},{op:"endsWith",label:"termina con",inputType:"single",placeholder:"sufijo"},{op:"in",label:"es uno de",inputType:"multi",placeholder:"opción1, opción2, opción3"},{op:"notIn",label:"no es ninguno de",inputType:"multi",placeholder:"valor1, valor2, valor3"},{op:"matches",label:"coincide con patrón",inputType:"pattern",placeholder:"^[A-Z]{3}\\d{4}$",description:"Expresión regular"}],nV=[{op:"eq",label:"igual a",inputType:"single",placeholder:"123"},{op:"neq",label:"distinto de",inputType:"single",placeholder:"0"},{op:"gt",label:"mayor que",inputType:"single",placeholder:"0"},{op:"gte",label:"mayor o igual",inputType:"single",placeholder:"1"},{op:"lt",label:"menor que",inputType:"single",placeholder:"100"},{op:"lte",label:"menor o igual",inputType:"single",placeholder:"99"},{op:"inRange",label:"entre",inputType:"range",placeholder:"min,max",description:"Valor entre un rango",compile:(e,t)=>{const[r,n]=t.split(",").map(a=>parseFloat(a.trim()));return{op:"and",rules:[{op:"gte",field:e,value:r},{op:"lte",field:e,value:n}]}}},{op:"isEmpty",label:"sin valor",inputType:"none",compile:e=>({op:"eq",field:e,value:null})},{op:"in",label:"es uno de",inputType:"multi",placeholder:"1, 2, 3, 5, 8"}],aV=[{op:"isTrue",label:"está marcado",inputType:"none",compile:e=>({op:"eq",field:e,value:!0})},{op:"isFalse",label:"está desmarcado",inputType:"none",compile:e=>({op:"eq",field:e,value:!1})},{op:"eq",label:"es igual a",inputType:"single",placeholder:"true/false"}],Nh=[{op:"eq",label:"es igual a",inputType:"single",placeholder:"valor seleccionado"},{op:"neq",label:"es distinto de",inputType:"single",placeholder:"valor"},{op:"isEmpty",label:"sin selección",inputType:"none",compile:e=>({op:"eq",field:e,value:""})},{op:"isNotEmpty",label:"tiene selección",inputType:"none",compile:e=>({op:"neq",field:e,value:""})},{op:"in",label:"es uno de",inputType:"multi",placeholder:"opción1, opción2"},{op:"notIn",label:"no es ninguno de",inputType:"multi",placeholder:"valor1, valor2"}],oV=[{op:"eq",label:"es exactamente",inputType:"single",placeholder:"2025-01-15"},{op:"neq",label:"no es",inputType:"single",placeholder:"2025-01-01"},{op:"gt",label:"después de",inputType:"single",placeholder:"2025-01-01"},{op:"gte",label:"desde (inclusive)",inputType:"single",placeholder:"2025-01-01"},{op:"lt",label:"antes de",inputType:"single",placeholder:"2025-12-31"},{op:"lte",label:"hasta (inclusive)",inputType:"single",placeholder:"2025-12-31"},{op:"today",label:"es hoy",inputType:"none",description:"La fecha es hoy",compile:e=>{const t=new Date().toISOString().split("T")[0];return{op:"eq",field:e,value:t}}},{op:"inPast",label:"es en el pasado",inputType:"none",compile:e=>{const t=new Date().toISOString().split("T")[0];return{op:"lt",field:e,value:t}}},{op:"inFuture",label:"es en el futuro",inputType:"none",compile:e=>{const t=new Date().toISOString().split("T")[0];return{op:"gt",field:e,value:t}}},{op:"inRange",label:"entre fechas",inputType:"range",placeholder:"2025-01-01,2025-12-31",compile:(e,t)=>{const[r,n]=t.split(",").map(a=>a.trim());return{op:"and",rules:[{op:"gte",field:e,value:r},{op:"lte",field:e,value:n}]}}},{op:"isEmpty",label:"sin fecha",inputType:"none",compile:e=>({op:"eq",field:e,value:null})}],sV=[{op:"isEmpty",label:"está vacío",inputType:"none",compile:e=>({op:"eq",field:e,value:""})},{op:"isNotEmpty",label:"tiene contenido",inputType:"none",compile:e=>({op:"neq",field:e,value:""})},{op:"contains",label:"contiene",inputType:"single",placeholder:"palabra clave"},{op:"notContains",label:"no contiene",inputType:"single"},{op:"eq",label:"es igual a",inputType:"single"},{op:"neq",label:"es distinto de",inputType:"single"}],iV=[{op:"hasAnyValue",label:"tiene archivo",inputType:"none",description:"Se ha cargado al menos un archivo",compile:e=>({op:"neq",field:e,value:null})},{op:"hasNoValue",label:"sin archivo",inputType:"none",compile:e=>({op:"eq",field:e,value:null})},{op:"eq",label:"nombre es",inputType:"single",placeholder:"documento.pdf",description:"Nombre exacto del archivo"},{op:"contains",label:"nombre contiene",inputType:"single",placeholder:"factura"}],lV=[{op:"hasAnyValue",label:"tiene items",inputType:"none",description:"El repeater tiene al menos un elemento",compile:e=>({op:"gt",field:`${e}.length`,value:0})},{op:"hasNoValue",label:"está vacío",inputType:"none",description:"El repeater no tiene elementos",compile:e=>({op:"eq",field:`${e}.length`,value:0})}],Fh={table:{fieldType:"table",operators:[],defaultOperator:"eq",defaultPlaceholder:"",helpText:"Reglas no soportadas para campos tipo tabla."},text:{fieldType:"text",operators:Yn,defaultOperator:"eq",defaultPlaceholder:"valor del texto",helpText:"Compara el valor del campo de texto"},email:{fieldType:"email",operators:[...Yn,{op:"matches",label:"es email válido",inputType:"none",compile:e=>({op:"matches",field:e,value:/^[^\s@]+@[^\s@]+\.[^\s@]+$/})}],defaultOperator:"eq",defaultPlaceholder:"email@ejemplo.com",helpText:"Valida o compara direcciones de email"},url:{fieldType:"url",operators:[...Yn,{op:"startsWith",label:"protocolo es",inputType:"single",placeholder:"https://"}],defaultOperator:"eq",defaultPlaceholder:"https://ejemplo.com"},tel:{fieldType:"tel",operators:Yn,defaultOperator:"eq",defaultPlaceholder:"+34 600 000 000",helpText:"Compara números de teléfono"},iban:{fieldType:"iban",operators:Yn,defaultOperator:"eq",defaultPlaceholder:"ES00 0000 0000 0000 0000 0000",helpText:"Compara códigos IBAN"},dni:{fieldType:"dni",operators:Yn,defaultOperator:"eq",defaultPlaceholder:"12345678A",helpText:"Compara números de DNI/NIF"},number:{fieldType:"number",operators:nV,defaultOperator:"eq",defaultPlaceholder:"0",helpText:"Comparaciones numéricas",validateValue:(e,t)=>{if(["isEmpty","isNotEmpty"].includes(e))return{valid:!0};if(e==="inRange"){const r=String(t).split(",");if(r.length!==2)return{valid:!1,message:"Formato: min,max"};const[n,a]=r.map(o=>parseFloat(o.trim()));return isNaN(n)||isNaN(a)?{valid:!1,message:"Valores deben ser números"}:n>=a?{valid:!1,message:"Min debe ser menor que Max"}:{valid:!0}}return isNaN(Number(t))?{valid:!1,message:"Debe ser un número válido"}:{valid:!0}}},password:{fieldType:"password",operators:[{op:"isEmpty",label:"sin contraseña",inputType:"none",compile:e=>({op:"eq",field:e,value:""})},{op:"isNotEmpty",label:"tiene contraseña",inputType:"none",compile:e=>({op:"neq",field:e,value:""})}],defaultOperator:"isEmpty",helpText:"Por seguridad, solo se puede validar si existe"},select:{fieldType:"select",operators:Nh,defaultOperator:"eq",defaultPlaceholder:"valor seleccionado",helpText:"Compara el valor seleccionado"},date:{fieldType:"date",operators:oV,defaultOperator:"eq",defaultPlaceholder:"2025-01-01",helpText:"Comparaciones de fechas",validateValue:(e,t)=>["isEmpty","today","inPast","inFuture"].includes(e)?{valid:!0}:e==="inRange"?String(t).split(",").length!==2?{valid:!1,message:"Formato: YYYY-MM-DD,YYYY-MM-DD"}:{valid:!0}:/^\d{4}-\d{2}-\d{2}$/.test(String(t))?{valid:!0}:{valid:!1,message:"Formato: YYYY-MM-DD"}},checkbox:{fieldType:"checkbox",operators:aV,defaultOperator:"isTrue",helpText:"Valida el estado del checkbox"},textarea:{fieldType:"textarea",operators:sV,defaultOperator:"isEmpty",defaultPlaceholder:"contenido del texto",helpText:"Analiza el contenido del textarea"},file:{fieldType:"file",operators:iV,defaultOperator:"hasAnyValue",helpText:"Valida si se ha cargado un archivo"},search:{fieldType:"search",operators:Yn,defaultOperator:"contains",defaultPlaceholder:"término de búsqueda"},optionGroup:{fieldType:"optionGroup",operators:Nh,defaultOperator:"eq"},button:{fieldType:"button",operators:[],defaultOperator:"eq",helpText:"Los botones no tienen valor para reglas"},inputGroup:{fieldType:"inputGroup",operators:[],defaultOperator:"eq",helpText:"Use los campos individuales del grupo"},array:{fieldType:"array",operators:lV,defaultOperator:"hasAnyValue",helpText:"Valida si el repeater tiene elementos"}};function Va(e){return Fh[e]||Fh.text}function En(e,t){return Va(e).operators.find(n=>n.op===t)}function Za(e,t,r,n){const a=En(n,e);if(a!=null&&a.compile)return a.compile(t,r);if(["eq","neq","in","notIn","gt","gte","lt","lte"].includes(e)){let o;if(e==="in"||e==="notIn"){const i=Array.isArray(r)?r:String(r).split(",").map(c=>c.trim());o={op:e,field:t,values:i}}else o={op:e,field:t,value:r};return o._originalOp=e,o}switch(e){case"isEmpty":return{op:"eq",field:t,value:""};case"isNotEmpty":return{op:"neq",field:t,value:""};case"isTrue":return{op:"eq",field:t,value:!0};case"isFalse":return{op:"eq",field:t,value:!1};case"hasAnyValue":return{op:"neq",field:t,value:null};case"hasNoValue":return{op:"eq",field:t,value:null};case"contains":case"notContains":case"startsWith":case"endsWith":case"matches":return{op:"eq",field:t,value:r,_originalOp:e};case"inRange":const o=String(r).split(",");if(o.length===2){const[c,d]=o.map(u=>u.trim());return{op:"and",rules:[{op:"gte",field:t,value:n==="number"?parseFloat(c):c},{op:"lte",field:t,value:n==="number"?parseFloat(d):d}],_originalOp:"inRange"}}return{op:"eq",field:t,value:r,_originalOp:e};case"today":case"inPast":case"inFuture":const i=new Date().toISOString().split("T")[0];if(e==="today")return{op:"eq",field:t,value:i,_originalOp:"today"};if(e==="inPast")return{op:"lt",field:t,value:i,_originalOp:"inPast"};if(e==="inFuture")return{op:"gt",field:t,value:i,_originalOp:"inFuture"};break}return console.warn(`Operador no implementado: ${e}, usando eq como fallback`),{op:"eq",field:t,value:r}}function cV(e,t,r){const n=Va(e);if(n.validateValue)return n.validateValue(t,r);const a=En(e,t);return a?a.inputType==="none"?{valid:!0}:a.inputType==="single"&&!r&&r!==0&&r!==!1?{valid:!1,message:"El valor no puede estar vacío"}:{valid:!0}:["isEmpty","isNotEmpty","contains","notContains","startsWith","endsWith","matches","isTrue","isFalse","hasAnyValue","hasNoValue","inRange","today","inPast","inFuture"].includes(t)?["isEmpty","isNotEmpty","isTrue","isFalse","hasAnyValue","hasNoValue","today","inPast","inFuture"].includes(t)?{valid:!0}:!r&&r!==0&&r!==!1?{valid:!1,message:"El valor no puede estar vacío"}:{valid:!0}:{valid:!1,message:"Operador no soportado para este tipo de campo"}}function Ar(e){return typeof e=="boolean"?e?"true":"false":typeof e=="number"?String(e):typeof e=="string"?e:e==null?"":String(e)}function Ui(e){if(!e)return"eq";if("_originalOp"in e)return e._originalOp;const t=e.op;if(t==="and"||t==="or")return"_originalOp"in e?e._originalOp:"eq";if(t==="eq"){const r=e.value;if(r==="")return"isEmpty";if(r===!0)return"isTrue";if(r===!1)return"isFalse";if(r===null)return"isEmpty"}if(t==="neq"){const r=e.value;if(r==="")return"isNotEmpty";if(r===null)return"hasAnyValue"}return t}const dV=({value:e,fieldOptions:t,fieldTypes:r,onChange:n,onRemove:a,fieldPickerSuffix:o,disabled:i})=>{const c=Ui(e),d="field"in e?e.field:"",u=r[d]||"text",f=Va(u),h=w=>{if(w.field&&w.field!==d){const x=r[w.field]||"text",E=Va(x).defaultOperator,k=Za(E,w.field,"",x);n(k);return}if(w.op&&w.op!==c){let x="";"value"in e?x=Ar(e.value):"values"in e&&(x=e.values.map(Ar).join(","));try{const y=Za(w.op,d,x,u);n(y)}catch(y){console.error(y)}return}if(w.rawInputValue!==void 0){try{const x=Za(c,d,w.rawInputValue,u);n(x)}catch(x){console.error(x)}return}},p=f.operators.map(w=>({label:w.label,value:w.op}));let m="";"value"in e?m=Ar(e.value):"values"in e&&(m=e.values.map(Ar).join(", "));const v=En(u,c),g=["isEmpty","isNotEmpty","isTrue","isFalse","hasAnyValue","hasNoValue","today","inPast","inFuture"],b=(v==null?void 0:v.inputType)!=="none"&&!g.includes(c);return l.jsxs("div",{className:"flex flex-wrap items-start gap-2 p-2 bg-[var(--color-ds-background-page)] rounded border border-[var(--color-ds-border-default-50)]",children:[l.jsx("div",{className:"flex-1 min-w-[120px]",children:l.jsx(Xe,{value:d,onChange:w=>h({field:w}),options:t,size:"sm",labelHidden:!0,disabled:i})}),l.jsx("div",{className:"w-[140px]",children:l.jsx(Xe,{value:c,onChange:w=>h({op:w}),options:p,size:"sm",labelHidden:!0,disabled:i})}),b&&l.jsx("div",{className:"flex-1 min-w-[120px]",children:l.jsx(je,{size:"sm",value:m,onChange:w=>h({rawInputValue:w.target.value}),reserveErrorSpace:!1,placeholder:"Valor",disabled:i})}),a&&l.jsx("button",{onClick:a,disabled:i,className:"p-1 text-[var(--color-ds-text-secondary)] hover:text-red-500 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:l.jsx(Dt,{className:"w-4 h-4"})})]})},_h=({rule:e,onChange:t,onRemove:r,fieldOptions:n,fieldTypes:a,depth:o=0,disabled:i=!1})=>{var b;const c=e.op==="and",d=()=>{t({...e,op:c?"or":"and"})},u=()=>{var x;const w={op:"eq",field:String(((x=n[0])==null?void 0:x.value)||""),value:""};t({...e,rules:[...e.rules||[],w]})},f=()=>{var x;const w={op:"and",rules:[{op:"eq",field:String(((x=n[0])==null?void 0:x.value)||""),value:""}]};t({...e,rules:[...e.rules||[],w]})},h=(w,x)=>{const y=[...e.rules||[]];y[w]=x,t({...e,rules:y})},p=w=>{const x=[...e.rules||[]];x.splice(w,1),t({...e,rules:x})},m=c?"bg-blue-50 border-r border-blue-200 text-blue-700 hover:bg-blue-100":"bg-orange-50 border-r border-orange-200 text-orange-700 hover:bg-orange-100",v=c?"AND":"OR";return l.jsxs("div",{className:"flex rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm bg-[var(--color-ds-background-page)] overflow-hidden transition-all",children:[l.jsxs("div",{onClick:i?void 0:d,className:`w-10 relative flex flex-col items-center transition-colors rounded-l-lg ${m} ${i?"pointer-events-none opacity-60":""}`,title:i?void 0:"Click para cambiar (Y / O)",children:[l.jsx("div",{className:`absolute top-2 bottom-10 w-0.5 rounded-full ${c?"bg-blue-200":"bg-orange-200"}`}),l.jsx("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-10",children:l.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center text-[10px] font-bold border shadow-sm bg-[var(--color-ds-background-page)] ${c?"border-blue-300":"border-orange-300"}`,children:v})}),r&&l.jsx("button",{onClick:w=>{w.stopPropagation(),r()},disabled:i,className:"absolute bottom-2 z-20 p-1 rounded-full hover:bg-red-100 text-[var(--color-ds-text-secondary)] hover:text-red-500 transition-colors disabled:opacity-50 disabled:cursor-not-allowed bg-[var(--color-ds-background-page)] border border-transparent hover:border-red-200 shadow-sm",title:"Eliminar este grupo",children:l.jsx(Dt,{className:"w-3.5 h-3.5"})})]}),l.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[l.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[(b=e.rules)==null?void 0:b.map((w,x)=>l.jsx("div",{className:"relative group/item",children:l.jsx("div",{className:"",children:"rules"in w?l.jsx(_h,{rule:w,onChange:y=>h(x,y),onRemove:()=>p(x),fieldOptions:n,fieldTypes:a,depth:o+1,disabled:i}):l.jsx(dV,{value:w,onChange:y=>h(x,y),onRemove:()=>p(x),fieldOptions:n,fieldTypes:a,disabled:i})})},x)),(!e.rules||e.rules.length===0)&&l.jsx("div",{className:"text-center py-8 border-2 border-dashed border-[var(--color-ds-border-default-50)] rounded-lg m-1",children:l.jsx("span",{className:"text-xs text-[var(--color-ds-text-secondary)] block mb-2 opacity-70",children:"Grupo vacío"})})]}),l.jsxs("div",{className:"flex items-center gap-2 p-2 bg-[var(--color-ds-background-neutral)]/30 border-t border-[var(--color-ds-border-default-50)]/50",children:[l.jsxs("button",{onClick:u,disabled:i,className:"px-2 py-1 rounded text-xs font-medium text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-surface-hover)] border border-transparent hover:border-[var(--color-ds-border-default-50)] transition-all flex items-center gap-1.5 disabled:opacity-50",children:[l.jsx(hr,{className:"w-3.5 h-3.5 text-[var(--color-ds-text-secondary)]"}),"Añadir Regla"]}),l.jsxs("button",{onClick:f,disabled:i,className:"px-2 py-1 rounded text-xs font-medium text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-surface-hover)] border border-transparent hover:border-[var(--color-ds-border-default-50)] transition-all flex items-center gap-1.5 disabled:opacity-50",children:[l.jsx(Hs,{className:"w-3.5 h-3.5 text-[var(--color-ds-text-secondary)]"}),"Añadir Sub-grupo"]}),l.jsx("div",{className:"flex-1"}),o>0&&l.jsxs("span",{className:"text-[9px] text-[var(--color-ds-text-secondary)] opacity-50 px-2",children:["Nivel ",o+1]})]})]})]})};function uV({value:e,fieldOptions:t,fieldTypes:r,onChange:n,fieldPickerSuffix:a,showHelp:o=!0,disabled:i=!1}){const c=e&&"op"in e&&(e.op==="and"||e.op==="or"),d=e&&"op"in e&&e.op==="always",u=()=>{var p;const h=e&&e.op!=="always"?e:{op:"eq",field:String(((p=t[0])==null?void 0:p.value)||""),value:""};n({op:"and",rules:[h]})},f=h=>{n(h?{op:"always",value:!0}:void 0)};return d?l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"flex items-center gap-4 bg-[var(--color-ds-background-neutral)]/30 p-3 rounded-lg border border-[var(--color-ds-border-default-50)]",children:[l.jsx("span",{className:"text-sm font-medium text-[var(--color-ds-text-primary)]",children:"Modo:"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>f(!1),disabled:i,className:"px-3 py-1.5 rounded text-xs font-medium bg-[var(--color-ds-background-page)] border border-[var(--color-ds-border-default-50)] text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)] transition-colors",children:"Condicional"}),l.jsx("button",{disabled:!0,className:"px-3 py-1.5 rounded text-xs font-medium bg-amber-100 text-amber-800 border border-amber-200",children:"Siempre Activo"})]})]}),l.jsxs("div",{className:"flex items-center gap-3 p-4 bg-amber-50 border border-amber-100 rounded-lg text-amber-800 text-sm",children:[l.jsx(fn,{className:"w-5 h-5 flex-shrink-0"}),l.jsxs("span",{children:["Esta regla se aplicará ",l.jsx("strong",{children:"SIEMPRE"}),", incondicionalmente."]})]})]}):c?l.jsx("div",{className:"space-y-2",children:l.jsx(_h,{rule:e,onChange:n,fieldOptions:t,fieldTypes:r,depth:0,disabled:i})}):l.jsxs("div",{className:"space-y-3",children:[l.jsx("div",{className:"flex justify-end mb-2",children:l.jsx("button",{onClick:()=>f(!0),className:"text-xs text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-primary-700)] underline decoration-dotted underline-offset-2 transition-colors",disabled:i,children:'Cambiar a "Siempre activo"'})}),l.jsxs("div",{className:"bg-[var(--color-ds-background-neutral)]/20 p-3 rounded-xl border border-[var(--color-ds-border-default-50)] shadow-sm space-y-3 relative group",children:[l.jsx(fV,{value:e,fieldOptions:t,fieldTypes:r,onChange:n,fieldPickerSuffix:a,showHelp:o,disabled:i}),l.jsx("div",{className:"flex justify-end border-t border-[var(--color-ds-border-default-50)]/50 pt-2 mt-2",children:l.jsxs("button",{onClick:u,disabled:i,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium text-[var(--color-ds-primary-700)] hover:bg-[var(--color-ds-primary-50)] transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Permite añadir múltiples condiciones (AND/OR)",children:[l.jsx(Hs,{className:"w-4 h-4"}),"Convertir a Grupo Avanzado"]})})]})]})}function fV({value:e,fieldOptions:t,fieldTypes:r,onChange:n,fieldPickerSuffix:a,showHelp:o=!0,disabled:i=!1}){const[c,d]=C.useState(()=>e&&"field"in e?e.field:""),[u,f]=C.useState(()=>Ui(e)),[h,p]=C.useState(()=>e?"value"in e?Ar(e.value):"values"in e?e.values.map(Ar).join(", "):"":""),m=C.useRef(null),v=C.useRef(!0);C.useEffect(()=>{if(!v.current||(v.current=!1,!e))return;"field"in e&&d(e.field);const B=Ui(e);f(B),"value"in e?p(Ar(e.value)):"values"in e&&p(e.values.map(Ar).join(", "))},[]),C.useEffect(()=>{if(!e||"op"in e&&(e.op==="and"||e.op==="or"))return;"field"in e&&d(e.field);const B=Ui(e);f(B),"value"in e?p(Ar(e.value)):"values"in e&&p(e.values.map(Ar).join(", "))},[e]);const g=C.useMemo(()=>c&&r[c]||"text",[c,r]),b=C.useMemo(()=>Va(g),[g]),w=C.useMemo(()=>b.operators.map(B=>({value:B.op,label:B.label})),[b.operators]),x=C.useMemo(()=>{if(!c)return{valid:!1,message:"Selecciona"};const B=En(g,u);return(B==null?void 0:B.inputType)==="none"?{valid:!0}:cV(g,u,h)},[c,g,u,h]),y=B=>{if(d(B),B){const R=r[B]||"text",I=Va(R);f(I.defaultOperator),p("");try{const F=Za(I.defaultOperator,B,"",R);n(F)}catch(F){console.error("Error:",F)}}else n(void 0)},E=B=>{f(B);const R=En(g,B);(R==null?void 0:R.inputType)==="none"&&p("");try{const I=Za(B,c,h,g);n(I)}catch(I){console.error("Error:",I)}},k=B=>{p(B),m.current&&clearTimeout(m.current),m.current=window.setTimeout(()=>{if(c)try{const R=Za(u,c,B,g);n(R)}catch(R){console.error("Error:",R)}},300)};C.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]);const j=()=>{const B=En(g,u),R=["isEmpty","isNotEmpty","isTrue","isFalse","hasAnyValue","hasNoValue","today","inPast","inFuture"];if((B==null?void 0:B.inputType)==="none"||R.includes(u))return l.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md bg-[var(--color-ds-background-page)] border border-[var(--color-ds-border-default-50)] text-[var(--color-ds-text-secondary)] text-sm",children:[l.jsx(pa,{className:"w-4 h-4"}),l.jsx("span",{className:"text-xs",children:(B==null?void 0:B.description)||"No requiere valor"})]});if((B==null?void 0:B.inputType)==="range"||u==="inRange")return l.jsx(je,{size:"sm",label:"Rango",placeholder:(B==null?void 0:B.placeholder)||"min,max",value:h,onChange:F=>k(F.target.value),reserveErrorSpace:!1,hasError:!x.valid,errorMessage:x.message,disabled:i});if((B==null?void 0:B.inputType)==="multi"||u==="in"||u==="notIn")return l.jsx(je,{size:"sm",label:"Valores",placeholder:(B==null?void 0:B.placeholder)||"valor1, valor2, valor3",value:h,onChange:F=>k(F.target.value),reserveErrorSpace:!1,hasError:!x.valid,errorMessage:x.message,disabled:i});if((B==null?void 0:B.inputType)==="pattern"||u==="matches")return l.jsx(je,{size:"sm",label:"Patrón",placeholder:(B==null?void 0:B.placeholder)||"^patrón$",value:h,onChange:F=>k(F.target.value),reserveErrorSpace:!1,hasError:!x.valid,errorMessage:x.message});let I="text";return g==="number"&&(I="number"),g==="date"&&(I="date"),g==="email"&&(I="email"),g==="url"&&(I="url"),g==="tel"&&(I="tel"),l.jsx(je,{size:"sm",type:I,label:"Valor",placeholder:(B==null?void 0:B.placeholder)||b.defaultPlaceholder||"valor",value:h,onChange:F=>k(F.target.value),reserveErrorSpace:!1,hasError:!x.valid,errorMessage:x.message,disabled:i})},A=()=>c?l.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-mono bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-secondary)] border border-[var(--color-ds-border-default-50)]",children:g}):null,S=()=>{if(!o||!c)return null;const B=En(g,u),R=(B==null?void 0:B.description)||b.helpText;return R?l.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md bg-[color-mix(in_srgb,var(--color-ds-background-accent)_10%,transparent)] border border-[var(--color-ds-border-default-50)]",children:[l.jsx(F1,{className:"w-4 h-4 text-[var(--color-ds-text-secondary)] flex-shrink-0 mt-0.5"}),l.jsx("span",{className:"text-xs text-[var(--color-ds-text-secondary)] leading-relaxed",children:R})]}):null},_=()=>{if(!c)return null;const B=En(g,u),R=["isEmpty","isNotEmpty","isTrue","isFalse","hasAnyValue","hasNoValue","today","inPast","inFuture"];return(B==null?void 0:B.inputType)==="none"||R.includes(u)?null:l.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:x.valid?l.jsxs(l.Fragment,{children:[l.jsx(fn,{className:"w-4 h-4 text-[var(--color-ds-text-primary)]"}),l.jsx("span",{className:"text-[var(--color-ds-text-primary)]",children:"Válido"})]}):l.jsxs(l.Fragment,{children:[l.jsx(Ql,{className:"w-4 h-4 text-[var(--color-ds-text-primary)]"}),l.jsx("span",{className:"text-[var(--color-ds-text-primary)]",children:x.message||"Inválido"})]})})},M=C.useMemo(()=>[{label:"— Campo —",value:""},...t],[t]);return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"grid grid-cols-2 gap-3 items-start",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("span",{className:"text-[10px] uppercase font-bold text-[var(--color-ds-text-secondary)] tracking-wider",children:"Campo"}),A()]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx(Xe,{value:c,onChange:B=>y(B),options:M,size:"sm",coerceFirstValid:!1,reserveErrorSpace:!1,className:"flex-1 w-full",labelHidden:!0,disabled:i}),a&&l.jsx("div",{className:"flex-shrink-0",children:a})]})]}),l.jsxs("div",{className:"space-y-1",children:[l.jsx("span",{className:"text-[10px] uppercase font-bold text-[var(--color-ds-text-secondary)] tracking-wider",children:"Operador"}),c&&w.length>0?l.jsx(Xe,{value:u,onChange:B=>E(B),options:w,size:"sm",coerceFirstValid:!1,reserveErrorSpace:!1,labelHidden:!0,disabled:i}):l.jsx("div",{className:"h-8 w-full bg-[var(--color-ds-background-disabled)] rounded border border-[var(--color-ds-border-muted)] opacity-50"})]})]}),c&&l.jsxs("div",{className:"space-y-2 pt-1 border-t border-[var(--color-ds-border-default-50)]/50",children:[l.jsx("div",{className:"pt-2",children:j()}),S(),l.jsx("div",{className:"flex justify-end",children:_()})]})]})}let Yo={};function Qd(e){Yo={...Yo,...e}}function Cn(e){return Yo[e]}function hV(){const e={};for(const t of Object.values(Yo))e[t.controller]||(e[t.controller]=[]),e[t.controller].push(t);return e}function pV(e){return Object.values(Yo).filter(t=>t.type===e)}const eu=({filterType:e,selectedKey:t,onSelect:r})=>{const[n,a]=C.useState(""),o=C.useMemo(()=>{const u=hV();if(e){const f={};for(const[h,p]of Object.entries(u)){const m=p.filter(v=>v.type===e);m.length>0&&(f[h]=m)}return f}return u},[e]),i=C.useMemo(()=>{if(!n.trim())return o;const u=n.toLowerCase(),f={};for(const[h,p]of Object.entries(o)){const m=p.filter(v=>{var g;return v.name.toLowerCase().includes(u)||v.key.toLowerCase().includes(u)||((g=v.description)==null?void 0:g.toLowerCase().includes(u))||h.toLowerCase().includes(u)});m.length>0&&(f[h]=m)}return f},[o,n]),c=u=>u==="validation"?ic:u==="options"?k1:bo,d=u=>u==="validation"?"var(--color-ds-text-error)":u==="options"?"var(--color-ds-text-info)":"var(--color-ds-text-success)";return l.jsxs("div",{className:"h-full flex flex-col",children:[l.jsx("div",{className:"p-3 border-b border-[var(--color-ds-border-default-50)]",children:l.jsx(je,{size:"sm",placeholder:"Buscar endpoints...",value:n,onChange:u=>a(u.target.value),prefixIcon:bo})}),l.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:Object.keys(i).length===0?l.jsx("div",{className:"text-center py-8 text-[var(--color-ds-text-secondary)] text-sm",children:n.trim()?"No se encontraron endpoints":"No hay endpoints disponibles"}):Object.entries(i).map(([u,f])=>l.jsx(lt,{title:`${u} (${f.length})`,type:"plain",defaultOpen:Object.keys(i).length<=3||n.trim().length>0,children:l.jsx("div",{className:"space-y-1 pt-1",children:f.map(h=>{const p=h.key===t,m=c(h.type);d(h.type);const v=g=>{let b="--comp-text";switch(g==null?void 0:g.toUpperCase()){case"GET":b="--comp-email";break;case"POST":b="--comp-text";break;case"PUT":b="--comp-checkbox";break;case"DELETE":b="--comp-number";break;default:b="--color-ds-text-secondary";break}return{color:`var(${b})`,backgroundColor:`color-mix(in srgb, var(${b}) 10%, transparent)`,borderColor:`color-mix(in srgb, var(${b}) 20%, transparent)`}};return l.jsx("button",{onClick:()=>r(h),className:`
118
+ `},xB={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:r}=e;return r?"Draggable item "+t.id+" was moved over droppable area "+r.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:r}=e;return r?"Draggable item "+t.id+" was dropped over droppable area "+r.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function yB(e){let{announcements:t=xB,container:r,hiddenTextDescribedById:n,screenReaderInstructions:a=wB}=e;const{announce:o,announcement:i}=vB(),c=Vo("DndLiveRegion"),[d,u]=C.useState(!1);if(C.useEffect(()=>{u(!0)},[]),zo(C.useMemo(()=>({onDragStart(h){let{active:p}=h;o(t.onDragStart({active:p}))},onDragMove(h){let{active:p,over:m}=h;t.onDragMove&&o(t.onDragMove({active:p,over:m}))},onDragOver(h){let{active:p,over:m}=h;o(t.onDragOver({active:p,over:m}))},onDragEnd(h){let{active:p,over:m}=h;o(t.onDragEnd({active:p,over:m}))},onDragCancel(h){let{active:p,over:m}=h;o(t.onDragCancel({active:p,over:m}))}}),[o,t])),!d)return null;const f=C.createElement(C.Fragment,null,C.createElement(mB,{id:n,value:a.draggable}),C.createElement(gB,{id:c,announcement:i}));return r?at.createPortal(f,r):f}var bt;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(bt||(bt={}));function Bi(){}function Ba(e,t){return C.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function Id(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return C.useMemo(()=>[...t].filter(n=>n!=null),[...t])}const yr=Object.freeze({x:0,y:0});function Bd(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function kB(e,t){const r=Ii(e);if(!r)return"0 0";const n={x:(r.x-t.left)/t.width*100,y:(r.y-t.top)/t.height*100};return n.x+"% "+n.y+"%"}function Pd(e,t){let{data:{value:r}}=e,{data:{value:n}}=t;return r-n}function EB(e,t){let{data:{value:r}}=e,{data:{value:n}}=t;return n-r}function Vd(e){let{left:t,top:r,height:n,width:a}=e;return[{x:t,y:r},{x:t+a,y:r},{x:t,y:r+n},{x:t+a,y:r+n}]}function Nf(e,t){if(!e||e.length===0)return null;const[r]=e;return r[t]}function Ff(e,t,r){return t===void 0&&(t=e.left),r===void 0&&(r=e.top),{x:t+e.width*.5,y:r+e.height*.5}}const Zd=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:n}=e;const a=Ff(t,t.left,t.top),o=[];for(const i of n){const{id:c}=i,d=r.get(c);if(d){const u=Bd(Ff(d),a);o.push({id:c,data:{droppableContainer:i,value:u}})}}return o.sort(Pd)},CB=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:n}=e;const a=Vd(t),o=[];for(const i of n){const{id:c}=i,d=r.get(c);if(d){const u=Vd(d),f=a.reduce((p,m,v)=>p+Bd(u[v],m),0),h=Number((f/4).toFixed(4));o.push({id:c,data:{droppableContainer:i,value:h}})}}return o.sort(Pd)};function jB(e,t){const r=Math.max(t.top,e.top),n=Math.max(t.left,e.left),a=Math.min(t.left+t.width,e.left+e.width),o=Math.min(t.top+t.height,e.top+e.height),i=a-n,c=o-r;if(n<a&&r<o){const d=t.width*t.height,u=e.width*e.height,f=i*c,h=f/(d+u-f);return Number(h.toFixed(4))}return 0}const _f=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:n}=e;const a=[];for(const o of n){const{id:i}=o,c=r.get(i);if(c){const d=jB(c,t);d>0&&a.push({id:i,data:{droppableContainer:o,value:d}})}}return a.sort(EB)};function DB(e,t){const{top:r,left:n,bottom:a,right:o}=t;return r<=e.y&&e.y<=a&&n<=e.x&&e.x<=o}const SB=e=>{let{droppableContainers:t,droppableRects:r,pointerCoordinates:n}=e;if(!n)return[];const a=[];for(const o of t){const{id:i}=o,c=r.get(i);if(c&&DB(n,c)){const u=Vd(c).reduce((h,p)=>h+Bd(n,p),0),f=Number((u/4).toFixed(4));a.push({id:i,data:{droppableContainer:o,value:f}})}}return a.sort(Pd)};function AB(e,t,r){return{...e,scaleX:t&&r?t.width/r.width:1,scaleY:t&&r?t.height/r.height:1}}function Mf(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:yr}function NB(e){return function(r){for(var n=arguments.length,a=new Array(n>1?n-1:0),o=1;o<n;o++)a[o-1]=arguments[o];return a.reduce((i,c)=>({...i,top:i.top+e*c.y,bottom:i.bottom+e*c.y,left:i.left+e*c.x,right:i.right+e*c.x}),{...r})}}const FB=NB(1);function Rf(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function _B(e,t,r){const n=Rf(t);if(!n)return e;const{scaleX:a,scaleY:o,x:i,y:c}=n,d=e.left-i-(1-a)*parseFloat(r),u=e.top-c-(1-o)*parseFloat(r.slice(r.indexOf(" ")+1)),f=a?e.width/a:e.width,h=o?e.height/o:e.height;return{width:f,height:h,top:u,right:d+f,bottom:u+h,left:d}}const MB={ignoreTransform:!1};function Pa(e,t){t===void 0&&(t=MB);let r=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:f}=Ot(e).getComputedStyle(e);u&&(r=_B(r,u,f))}const{top:n,left:a,width:o,height:i,bottom:c,right:d}=r;return{top:n,left:a,width:o,height:i,bottom:c,right:d}}function Of(e){return Pa(e,{ignoreTransform:!0})}function RB(e){const t=e.innerWidth,r=e.innerHeight;return{top:0,left:0,right:t,bottom:r,width:t,height:r}}function OB(e,t){return t===void 0&&(t=Ot(e).getComputedStyle(e)),t.position==="fixed"}function LB(e,t){t===void 0&&(t=Ot(e).getComputedStyle(e));const r=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(a=>{const o=t[a];return typeof o=="string"?r.test(o):!1})}function Pi(e,t){const r=[];function n(a){if(t!=null&&r.length>=t||!a)return r;if(Td(a)&&a.scrollingElement!=null&&!r.includes(a.scrollingElement))return r.push(a.scrollingElement),r;if(!Io(a)||jf(a)||r.includes(a))return r;const o=Ot(e).getComputedStyle(a);return a!==e&&LB(a,o)&&r.push(a),OB(a,o)?r:n(a.parentNode)}return e?n(e):r}function Lf(e){const[t]=Pi(e,1);return t??null}function zd(e){return!Ri||!e?null:Ta(e)?e:Ld(e)?Td(e)||e===$a(e).scrollingElement?window:Io(e)?e:null:null}function Tf(e){return Ta(e)?e.scrollX:e.scrollLeft}function $f(e){return Ta(e)?e.scrollY:e.scrollTop}function Hd(e){return{x:Tf(e),y:$f(e)}}var yt;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(yt||(yt={}));function If(e){return!Ri||!e?!1:e===document.scrollingElement}function Bf(e){const t={x:0,y:0},r=If(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},n={x:e.scrollWidth-r.width,y:e.scrollHeight-r.height},a=e.scrollTop<=t.y,o=e.scrollLeft<=t.x,i=e.scrollTop>=n.y,c=e.scrollLeft>=n.x;return{isTop:a,isLeft:o,isBottom:i,isRight:c,maxScroll:n,minScroll:t}}const TB={x:.2,y:.2};function $B(e,t,r,n,a){let{top:o,left:i,right:c,bottom:d}=r;n===void 0&&(n=10),a===void 0&&(a=TB);const{isTop:u,isBottom:f,isLeft:h,isRight:p}=Bf(e),m={x:0,y:0},v={x:0,y:0},g={height:t.height*a.y,width:t.width*a.x};return!u&&o<=t.top+g.height?(m.y=yt.Backward,v.y=n*Math.abs((t.top+g.height-o)/g.height)):!f&&d>=t.bottom-g.height&&(m.y=yt.Forward,v.y=n*Math.abs((t.bottom-g.height-d)/g.height)),!p&&c>=t.right-g.width?(m.x=yt.Forward,v.x=n*Math.abs((t.right-g.width-c)/g.width)):!h&&i<=t.left+g.width&&(m.x=yt.Backward,v.x=n*Math.abs((t.left+g.width-i)/g.width)),{direction:m,speed:v}}function IB(e){if(e===document.scrollingElement){const{innerWidth:o,innerHeight:i}=window;return{top:0,left:0,right:o,bottom:i,width:o,height:i}}const{top:t,left:r,right:n,bottom:a}=e.getBoundingClientRect();return{top:t,left:r,right:n,bottom:a,width:e.clientWidth,height:e.clientHeight}}function Pf(e){return e.reduce((t,r)=>Ia(t,Hd(r)),yr)}function BB(e){return e.reduce((t,r)=>t+Tf(r),0)}function PB(e){return e.reduce((t,r)=>t+$f(r),0)}function Vf(e,t){if(t===void 0&&(t=Pa),!e)return;const{top:r,left:n,bottom:a,right:o}=t(e);Lf(e)&&(a<=0||o<=0||r>=window.innerHeight||n>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const VB=[["x",["left","right"],BB],["y",["top","bottom"],PB]];class Wd{constructor(t,r){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const n=Pi(r),a=Pf(n);this.rect={...t},this.width=t.width,this.height=t.height;for(const[o,i,c]of VB)for(const d of i)Object.defineProperty(this,d,{get:()=>{const u=c(n),f=a[o]-u;return this.rect[d]+f},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class Ho{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(r=>{var n;return(n=this.target)==null?void 0:n.removeEventListener(...r)})},this.target=t}add(t,r,n){var a;(a=this.target)==null||a.addEventListener(t,r,n),this.listeners.push([t,r,n])}}function ZB(e){const{EventTarget:t}=Ot(e);return e instanceof t?e:$a(e)}function Ud(e,t){const r=Math.abs(e.x),n=Math.abs(e.y);return typeof t=="number"?Math.sqrt(r**2+n**2)>t:"x"in t&&"y"in t?r>t.x&&n>t.y:"x"in t?r>t.x:"y"in t?n>t.y:!1}var sr;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(sr||(sr={}));function Zf(e){e.preventDefault()}function zB(e){e.stopPropagation()}var We;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(We||(We={}));const zf={start:[We.Space,We.Enter],cancel:[We.Esc],end:[We.Space,We.Enter,We.Tab]},HB=(e,t)=>{let{currentCoordinates:r}=t;switch(e.code){case We.Right:return{...r,x:r.x+25};case We.Left:return{...r,x:r.x-25};case We.Down:return{...r,y:r.y+25};case We.Up:return{...r,y:r.y-25}}};class Wo{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:r}}=t;this.props=t,this.listeners=new Ho($a(r)),this.windowListeners=new Ho(Ot(r)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(sr.Resize,this.handleCancel),this.windowListeners.add(sr.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(sr.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:r}=this.props,n=t.node.current;n&&Vf(n),r(yr)}handleKeyDown(t){if($i(t)){const{active:r,context:n,options:a}=this.props,{keyboardCodes:o=zf,coordinateGetter:i=HB,scrollBehavior:c="smooth"}=a,{code:d}=t;if(o.end.includes(d)){this.handleEnd(t);return}if(o.cancel.includes(d)){this.handleCancel(t);return}const{collisionRect:u}=n.current,f=u?{x:u.left,y:u.top}:yr;this.referenceCoordinates||(this.referenceCoordinates=f);const h=i(t,{active:r,context:n.current,currentCoordinates:f});if(h){const p=Zo(h,f),m={x:0,y:0},{scrollableAncestors:v}=n.current;for(const g of v){const b=t.code,{isTop:w,isRight:x,isLeft:y,isBottom:E,maxScroll:k,minScroll:j}=Bf(g),A=IB(g),S={x:Math.min(b===We.Right?A.right-A.width/2:A.right,Math.max(b===We.Right?A.left:A.left+A.width/2,h.x)),y:Math.min(b===We.Down?A.bottom-A.height/2:A.bottom,Math.max(b===We.Down?A.top:A.top+A.height/2,h.y))},_=b===We.Right&&!x||b===We.Left&&!y,M=b===We.Down&&!E||b===We.Up&&!w;if(_&&S.x!==h.x){const B=g.scrollLeft+p.x,R=b===We.Right&&B<=k.x||b===We.Left&&B>=j.x;if(R&&!p.y){g.scrollTo({left:B,behavior:c});return}R?m.x=g.scrollLeft-B:m.x=b===We.Right?g.scrollLeft-k.x:g.scrollLeft-j.x,m.x&&g.scrollBy({left:-m.x,behavior:c});break}else if(M&&S.y!==h.y){const B=g.scrollTop+p.y,R=b===We.Down&&B<=k.y||b===We.Up&&B>=j.y;if(R&&!p.x){g.scrollTo({top:B,behavior:c});return}R?m.y=g.scrollTop-B:m.y=b===We.Down?g.scrollTop-k.y:g.scrollTop-j.y,m.y&&g.scrollBy({top:-m.y,behavior:c});break}}this.handleMove(t,Ia(Zo(h,this.referenceCoordinates),m))}}}handleMove(t,r){const{onMove:n}=this.props;t.preventDefault(),n(r)}handleEnd(t){const{onEnd:r}=this.props;t.preventDefault(),this.detach(),r()}handleCancel(t){const{onCancel:r}=this.props;t.preventDefault(),this.detach(),r()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}Wo.activators=[{eventName:"onKeyDown",handler:(e,t,r)=>{let{keyboardCodes:n=zf,onActivation:a}=t,{active:o}=r;const{code:i}=e.nativeEvent;if(n.start.includes(i)){const c=o.activatorNode.current;return c&&e.target!==c?!1:(e.preventDefault(),a==null||a({event:e.nativeEvent}),!0)}return!1}}];function Hf(e){return!!(e&&"distance"in e)}function Wf(e){return!!(e&&"delay"in e)}class qd{constructor(t,r,n){var a;n===void 0&&(n=ZB(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=r;const{event:o}=t,{target:i}=o;this.props=t,this.events=r,this.document=$a(i),this.documentListeners=new Ho(this.document),this.listeners=new Ho(n),this.windowListeners=new Ho(Ot(i)),this.initialCoordinates=(a=Ii(o))!=null?a:yr,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:r,bypassActivationConstraint:n}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(sr.Resize,this.handleCancel),this.windowListeners.add(sr.DragStart,Zf),this.windowListeners.add(sr.VisibilityChange,this.handleCancel),this.windowListeners.add(sr.ContextMenu,Zf),this.documentListeners.add(sr.Keydown,this.handleKeydown),r){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(Wf(r)){this.timeoutId=setTimeout(this.handleStart,r.delay),this.handlePending(r);return}if(Hf(r)){this.handlePending(r);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,r){const{active:n,onPending:a}=this.props;a(n,t,this.initialCoordinates,r)}handleStart(){const{initialCoordinates:t}=this,{onStart:r}=this.props;t&&(this.activated=!0,this.documentListeners.add(sr.Click,zB,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(sr.SelectionChange,this.removeTextSelection),r(t))}handleMove(t){var r;const{activated:n,initialCoordinates:a,props:o}=this,{onMove:i,options:{activationConstraint:c}}=o;if(!a)return;const d=(r=Ii(t))!=null?r:yr,u=Zo(a,d);if(!n&&c){if(Hf(c)){if(c.tolerance!=null&&Ud(u,c.tolerance))return this.handleCancel();if(Ud(u,c.distance))return this.handleStart()}if(Wf(c)&&Ud(u,c.tolerance))return this.handleCancel();this.handlePending(c,u);return}t.cancelable&&t.preventDefault(),i(d)}handleEnd(){const{onAbort:t,onEnd:r}=this.props;this.detach(),this.activated||t(this.props.active),r()}handleCancel(){const{onAbort:t,onCancel:r}=this.props;this.detach(),this.activated||t(this.props.active),r()}handleKeydown(t){t.code===We.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const WB={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Uo extends qd{constructor(t){const{event:r}=t,n=$a(r.target);super(t,WB,n)}}Uo.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:n}=t;return!r.isPrimary||r.button!==0?!1:(n==null||n({event:r}),!0)}}];const UB={move:{name:"mousemove"},end:{name:"mouseup"}};var Gd;(function(e){e[e.RightClick=2]="RightClick"})(Gd||(Gd={}));class qB extends qd{constructor(t){super(t,UB,$a(t.event.target))}}qB.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:n}=t;return r.button===Gd.RightClick?!1:(n==null||n({event:r}),!0)}}];const Kd={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class GB extends qd{constructor(t){super(t,Kd)}static setup(){return window.addEventListener(Kd.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(Kd.move.name,t)};function t(){}}}GB.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:n}=t;const{touches:a}=r;return a.length>1?!1:(n==null||n({event:r}),!0)}}];var qo;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(qo||(qo={}));var Vi;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(Vi||(Vi={}));function KB(e){let{acceleration:t,activator:r=qo.Pointer,canScroll:n,draggingRect:a,enabled:o,interval:i=5,order:c=Vi.TreeOrder,pointerCoordinates:d,scrollableAncestors:u,scrollableAncestorRects:f,delta:h,threshold:p}=e;const m=YB({delta:h,disabled:!o}),[v,g]=dB(),b=C.useRef({x:0,y:0}),w=C.useRef({x:0,y:0}),x=C.useMemo(()=>{switch(r){case qo.Pointer:return d?{top:d.y,bottom:d.y,left:d.x,right:d.x}:null;case qo.DraggableRect:return a}},[r,a,d]),y=C.useRef(null),E=C.useCallback(()=>{const j=y.current;if(!j)return;const A=b.current.x*w.current.x,S=b.current.y*w.current.y;j.scrollBy(A,S)},[]),k=C.useMemo(()=>c===Vi.TreeOrder?[...u].reverse():u,[c,u]);C.useEffect(()=>{if(!o||!u.length||!x){g();return}for(const j of k){if((n==null?void 0:n(j))===!1)continue;const A=u.indexOf(j),S=f[A];if(!S)continue;const{direction:_,speed:M}=$B(j,S,x,t,p);for(const B of["x","y"])m[B][_[B]]||(M[B]=0,_[B]=0);if(M.x>0||M.y>0){g(),y.current=j,v(E,i),b.current=M,w.current=_;return}}b.current={x:0,y:0},w.current={x:0,y:0},g()},[t,E,n,g,o,i,JSON.stringify(x),JSON.stringify(m),v,u,k,f,JSON.stringify(p)])}const JB={x:{[yt.Backward]:!1,[yt.Forward]:!1},y:{[yt.Backward]:!1,[yt.Forward]:!1}};function YB(e){let{delta:t,disabled:r}=e;const n=Ti(t);return Po(a=>{if(r||!n||!a)return JB;const o={x:Math.sign(t.x-n.x),y:Math.sign(t.y-n.y)};return{x:{[yt.Backward]:a.x[yt.Backward]||o.x===-1,[yt.Forward]:a.x[yt.Forward]||o.x===1},y:{[yt.Backward]:a.y[yt.Backward]||o.y===-1,[yt.Forward]:a.y[yt.Forward]||o.y===1}}},[r,t,n])}function XB(e,t){const r=t!=null?e.get(t):void 0,n=r?r.node.current:null;return Po(a=>{var o;return t==null?null:(o=n??a)!=null?o:null},[n,t])}function QB(e,t){return C.useMemo(()=>e.reduce((r,n)=>{const{sensor:a}=n,o=a.activators.map(i=>({eventName:i.eventName,handler:t(i.handler,n)}));return[...r,...o]},[]),[e,t])}var Go;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Go||(Go={}));var Jd;(function(e){e.Optimized="optimized"})(Jd||(Jd={}));const Uf=new Map;function eP(e,t){let{dragging:r,dependencies:n,config:a}=t;const[o,i]=C.useState(null),{frequency:c,measure:d,strategy:u}=a,f=C.useRef(e),h=b(),p=Bo(h),m=C.useCallback(function(w){w===void 0&&(w=[]),!p.current&&i(x=>x===null?w:x.concat(w.filter(y=>!x.includes(y))))},[p]),v=C.useRef(null),g=Po(w=>{if(h&&!r)return Uf;if(!w||w===Uf||f.current!==e||o!=null){const x=new Map;for(let y of e){if(!y)continue;if(o&&o.length>0&&!o.includes(y.id)&&y.rect.current){x.set(y.id,y.rect.current);continue}const E=y.node.current,k=E?new Wd(d(E),E):null;y.rect.current=k,k&&x.set(y.id,k)}return x}return w},[e,o,r,h,d]);return C.useEffect(()=>{f.current=e},[e]),C.useEffect(()=>{h||m()},[r,h]),C.useEffect(()=>{o&&o.length>0&&i(null)},[JSON.stringify(o)]),C.useEffect(()=>{h||typeof c!="number"||v.current!==null||(v.current=setTimeout(()=>{m(),v.current=null},c))},[c,h,m,...n]),{droppableRects:g,measureDroppableContainers:m,measuringScheduled:o!=null};function b(){switch(u){case Go.Always:return!1;case Go.BeforeDragging:return r;default:return!r}}}function Yd(e,t){return Po(r=>e?r||(typeof t=="function"?t(e):e):null,[t,e])}function tP(e,t){return Yd(e,t)}function rP(e){let{callback:t,disabled:r}=e;const n=Oi(t),a=C.useMemo(()=>{if(r||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(n)},[n,r]);return C.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function Zi(e){let{callback:t,disabled:r}=e;const n=Oi(t),a=C.useMemo(()=>{if(r||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(n)},[r]);return C.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function nP(e){return new Wd(Pa(e),e)}function qf(e,t,r){t===void 0&&(t=nP);const[n,a]=C.useState(null);function o(){a(d=>{if(!e)return null;if(e.isConnected===!1){var u;return(u=d??r)!=null?u:null}const f=t(e);return JSON.stringify(d)===JSON.stringify(f)?d:f})}const i=rP({callback(d){if(e)for(const u of d){const{type:f,target:h}=u;if(f==="childList"&&h instanceof HTMLElement&&h.contains(e)){o();break}}}}),c=Zi({callback:o});return xr(()=>{o(),e?(c==null||c.observe(e),i==null||i.observe(document.body,{childList:!0,subtree:!0})):(c==null||c.disconnect(),i==null||i.disconnect())},[e]),n}function aP(e){const t=Yd(e);return Mf(e,t)}const Gf=[];function oP(e){const t=C.useRef(e),r=Po(n=>e?n&&n!==Gf&&e&&t.current&&e.parentNode===t.current.parentNode?n:Pi(e):Gf,[e]);return C.useEffect(()=>{t.current=e},[e]),r}function sP(e){const[t,r]=C.useState(null),n=C.useRef(e),a=C.useCallback(o=>{const i=zd(o.target);i&&r(c=>c?(c.set(i,Hd(i)),new Map(c)):null)},[]);return C.useEffect(()=>{const o=n.current;if(e!==o){i(o);const c=e.map(d=>{const u=zd(d);return u?(u.addEventListener("scroll",a,{passive:!0}),[u,Hd(u)]):null}).filter(d=>d!=null);r(c.length?new Map(c):null),n.current=e}return()=>{i(e),i(o)};function i(c){c.forEach(d=>{const u=zd(d);u==null||u.removeEventListener("scroll",a)})}},[a,e]),C.useMemo(()=>e.length?t?Array.from(t.values()).reduce((o,i)=>Ia(o,i),yr):Pf(e):yr,[e,t])}function Kf(e,t){t===void 0&&(t=[]);const r=C.useRef(null);return C.useEffect(()=>{r.current=null},t),C.useEffect(()=>{const n=e!==yr;n&&!r.current&&(r.current=e),!n&&r.current&&(r.current=null)},[e]),r.current?Zo(e,r.current):yr}function iP(e){C.useEffect(()=>{if(!Ri)return;const t=e.map(r=>{let{sensor:n}=r;return n.setup==null?void 0:n.setup()});return()=>{for(const r of t)r==null||r()}},e.map(t=>{let{sensor:r}=t;return r}))}function lP(e,t){return C.useMemo(()=>e.reduce((r,n)=>{let{eventName:a,handler:o}=n;return r[a]=i=>{o(i,t)},r},{}),[e,t])}function Jf(e){return C.useMemo(()=>e?RB(e):null,[e])}const Yf=[];function cP(e,t){t===void 0&&(t=Pa);const[r]=e,n=Jf(r?Ot(r):null),[a,o]=C.useState(Yf);function i(){o(()=>e.length?e.map(d=>If(d)?n:new Wd(t(d),d)):Yf)}const c=Zi({callback:i});return xr(()=>{c==null||c.disconnect(),i(),e.forEach(d=>c==null?void 0:c.observe(d))},[e]),a}function Xf(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Io(t)?t:e}function dP(e){let{measure:t}=e;const[r,n]=C.useState(null),a=C.useCallback(u=>{for(const{target:f}of u)if(Io(f)){n(h=>{const p=t(f);return h?{...h,width:p.width,height:p.height}:p});break}},[t]),o=Zi({callback:a}),i=C.useCallback(u=>{const f=Xf(u);o==null||o.disconnect(),f&&(o==null||o.observe(f)),n(f?t(f):null)},[t,o]),[c,d]=Li(i);return C.useMemo(()=>({nodeRef:c,rect:r,setRef:d}),[r,c,d])}const uP=[{sensor:Uo,options:{}},{sensor:Wo,options:{}}],fP={current:{}},zi={draggable:{measure:Of},droppable:{measure:Of,strategy:Go.WhileDragging,frequency:Jd.Optimized},dragOverlay:{measure:Pa}};class Ko extends Map{get(t){var r;return t!=null&&(r=super.get(t))!=null?r:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:r}=t;return!r})}getNodeFor(t){var r,n;return(r=(n=this.get(t))==null?void 0:n.node.current)!=null?r:void 0}}const hP={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Ko,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Bi},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:zi,measureDroppableContainers:Bi,windowRect:null,measuringScheduled:!1},Qf={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Bi,draggableNodes:new Map,over:null,measureDroppableContainers:Bi},Jo=C.createContext(Qf),eh=C.createContext(hP);function pP(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Ko}}}function mP(e,t){switch(t.type){case bt.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case bt.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case bt.DragEnd:case bt.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case bt.RegisterDroppable:{const{element:r}=t,{id:n}=r,a=new Ko(e.droppable.containers);return a.set(n,r),{...e,droppable:{...e.droppable,containers:a}}}case bt.SetDroppableDisabled:{const{id:r,key:n,disabled:a}=t,o=e.droppable.containers.get(r);if(!o||n!==o.key)return e;const i=new Ko(e.droppable.containers);return i.set(r,{...o,disabled:a}),{...e,droppable:{...e.droppable,containers:i}}}case bt.UnregisterDroppable:{const{id:r,key:n}=t,a=e.droppable.containers.get(r);if(!a||n!==a.key)return e;const o=new Ko(e.droppable.containers);return o.delete(r),{...e,droppable:{...e.droppable,containers:o}}}default:return e}}function gP(e){let{disabled:t}=e;const{active:r,activatorEvent:n,draggableNodes:a}=C.useContext(Jo),o=Ti(n),i=Ti(r==null?void 0:r.id);return C.useEffect(()=>{if(!t&&!n&&o&&i!=null){if(!$i(o)||document.activeElement===o.target)return;const c=a.get(i);if(!c)return;const{activatorNode:d,node:u}=c;if(!d.current&&!u.current)return;requestAnimationFrame(()=>{for(const f of[d.current,u.current]){if(!f)continue;const h=hB(f);if(h){h.focus();break}}})}},[n,t,a,i,o]),null}function th(e,t){let{transform:r,...n}=t;return e!=null&&e.length?e.reduce((a,o)=>o({transform:a,...n}),r):r}function vP(e){return C.useMemo(()=>({draggable:{...zi.draggable,...e==null?void 0:e.draggable},droppable:{...zi.droppable,...e==null?void 0:e.droppable},dragOverlay:{...zi.dragOverlay,...e==null?void 0:e.dragOverlay}}),[e==null?void 0:e.draggable,e==null?void 0:e.droppable,e==null?void 0:e.dragOverlay])}function bP(e){let{activeNode:t,measure:r,initialRect:n,config:a=!0}=e;const o=C.useRef(!1),{x:i,y:c}=typeof a=="boolean"?{x:a,y:a}:a;xr(()=>{if(!i&&!c||!t){o.current=!1;return}if(o.current||!n)return;const u=t==null?void 0:t.node.current;if(!u||u.isConnected===!1)return;const f=r(u),h=Mf(f,n);if(i||(h.x=0),c||(h.y=0),o.current=!0,Math.abs(h.x)>0||Math.abs(h.y)>0){const p=Lf(u);p&&p.scrollBy({top:h.y,left:h.x})}},[t,i,c,n,r])}const Hi=C.createContext({...yr,scaleX:1,scaleY:1});var kn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(kn||(kn={}));const Xd=C.memo(function(t){var r,n,a,o;let{id:i,accessibility:c,autoScroll:d=!0,children:u,sensors:f=uP,collisionDetection:h=_f,measuring:p,modifiers:m,...v}=t;const g=C.useReducer(mP,void 0,pP),[b,w]=g,[x,y]=bB(),[E,k]=C.useState(kn.Uninitialized),j=E===kn.Initialized,{draggable:{active:A,nodes:S,translate:_},droppable:{containers:M}}=b,B=A!=null?S.get(A):null,R=C.useRef({initial:null,translated:null}),I=C.useMemo(()=>{var Fe;return A!=null?{id:A,data:(Fe=B==null?void 0:B.data)!=null?Fe:fP,rect:R}:null},[A,B]),F=C.useRef(null),[Z,ee]=C.useState(null),[Y,te]=C.useState(null),ae=Bo(v,Object.values(v)),q=Vo("DndDescribedBy",i),N=C.useMemo(()=>M.getEnabled(),[M]),L=vP(p),{droppableRects:ne,measureDroppableContainers:K,measuringScheduled:Q}=eP(N,{dragging:j,dependencies:[_.x,_.y],config:L.droppable}),he=XB(S,A),ie=C.useMemo(()=>Y?Ii(Y):null,[Y]),me=Ne(),ce=tP(he,L.draggable.measure);bP({activeNode:A!=null?S.get(A):null,config:me.layoutShiftCompensation,initialRect:ce,measure:L.draggable.measure});const le=qf(he,L.draggable.measure,ce),be=qf(he?he.parentElement:null),fe=C.useRef({activatorEvent:null,active:null,activeNode:he,collisionRect:null,collisions:null,droppableRects:ne,draggableNodes:S,draggingNode:null,draggingNodeRect:null,droppableContainers:M,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),xe=M.getNodeFor((r=fe.current.over)==null?void 0:r.id),D=dP({measure:L.dragOverlay.measure}),G=(n=D.nodeRef.current)!=null?n:he,re=j?(a=D.rect)!=null?a:le:null,W=!!(D.nodeRef.current&&D.rect),H=aP(W?null:le),X=Jf(G?Ot(G):null),O=oP(j?xe??he:null),V=cP(O),T=th(m,{transform:{x:_.x-H.x,y:_.y-H.y,scaleX:1,scaleY:1},activatorEvent:Y,active:I,activeNodeRect:le,containerNodeRect:be,draggingNodeRect:re,over:fe.current.over,overlayNodeRect:D.rect,scrollableAncestors:O,scrollableAncestorRects:V,windowRect:X}),$=ie?Ia(ie,_):null,P=sP(O),z=Kf(P),U=Kf(P,[le]),J=Ia(T,z),oe=re?FB(re,T):null,de=I&&oe?h({active:I,collisionRect:oe,droppableRects:ne,droppableContainers:N,pointerCoordinates:$}):null,ge=Nf(de,"id"),[we,Ce]=C.useState(null),ke=W?T:Ia(T,U),Ie=AB(ke,(o=we==null?void 0:we.rect)!=null?o:null,le),Le=C.useRef(null),De=C.useCallback((Fe,Me)=>{let{sensor:_e,options:Te}=Me;if(F.current==null)return;const ze=S.get(F.current);if(!ze)return;const He=Fe.nativeEvent,Ue=new _e({active:F.current,activeNode:ze,event:He,options:Te,context:fe,onAbort(Ze){if(!S.get(Ze))return;const{onDragAbort:Ke}=ae.current,ht={id:Ze};Ke==null||Ke(ht),x({type:"onDragAbort",event:ht})},onPending(Ze,Ye,Ke,ht){if(!S.get(Ze))return;const{onDragPending:Ln}=ae.current,Er={id:Ze,constraint:Ye,initialCoordinates:Ke,offset:ht};Ln==null||Ln(Er),x({type:"onDragPending",event:Er})},onStart(Ze){const Ye=F.current;if(Ye==null)return;const Ke=S.get(Ye);if(!Ke)return;const{onDragStart:ht}=ae.current,$r={activatorEvent:He,active:{id:Ye,data:Ke.data,rect:R}};at.unstable_batchedUpdates(()=>{ht==null||ht($r),k(kn.Initializing),w({type:bt.DragStart,initialCoordinates:Ze,active:Ye}),x({type:"onDragStart",event:$r}),ee(Le.current),te(He)})},onMove(Ze){w({type:bt.DragMove,coordinates:Ze})},onEnd:Tt(bt.DragEnd),onCancel:Tt(bt.DragCancel)});Le.current=Ue;function Tt(Ze){return async function(){const{active:Ke,collisions:ht,over:$r,scrollAdjustedTranslate:Ln}=fe.current;let Er=null;if(Ke&&Ln){const{cancelDrop:cn}=ae.current;Er={activatorEvent:He,active:Ke,collisions:ht,delta:Ln,over:$r},Ze===bt.DragEnd&&typeof cn=="function"&&await Promise.resolve(cn(Er))&&(Ze=bt.DragCancel)}F.current=null,at.unstable_batchedUpdates(()=>{w({type:Ze}),k(kn.Uninitialized),Ce(null),ee(null),te(null),Le.current=null;const cn=Ze===bt.DragEnd?"onDragEnd":"onDragCancel";if(Er){const q0=ae.current[cn];q0==null||q0(Er),x({type:cn,event:Er})}})}}},[S]),Re=C.useCallback((Fe,Me)=>(_e,Te)=>{const ze=_e.nativeEvent,He=S.get(Te);if(F.current!==null||!He||ze.dndKit||ze.defaultPrevented)return;const Ue={active:He};Fe(_e,Me.options,Ue)===!0&&(ze.dndKit={capturedBy:Me.sensor},F.current=Te,De(_e,Me))},[S,De]),Ve=QB(f,Re);iP(f),xr(()=>{le&&E===kn.Initializing&&k(kn.Initialized)},[le,E]),C.useEffect(()=>{const{onDragMove:Fe}=ae.current,{active:Me,activatorEvent:_e,collisions:Te,over:ze}=fe.current;if(!Me||!_e)return;const He={active:Me,activatorEvent:_e,collisions:Te,delta:{x:J.x,y:J.y},over:ze};at.unstable_batchedUpdates(()=>{Fe==null||Fe(He),x({type:"onDragMove",event:He})})},[J.x,J.y]),C.useEffect(()=>{const{active:Fe,activatorEvent:Me,collisions:_e,droppableContainers:Te,scrollAdjustedTranslate:ze}=fe.current;if(!Fe||F.current==null||!Me||!ze)return;const{onDragOver:He}=ae.current,Ue=Te.get(ge),Tt=Ue&&Ue.rect.current?{id:Ue.id,rect:Ue.rect.current,data:Ue.data,disabled:Ue.disabled}:null,Ze={active:Fe,activatorEvent:Me,collisions:_e,delta:{x:ze.x,y:ze.y},over:Tt};at.unstable_batchedUpdates(()=>{Ce(Tt),He==null||He(Ze),x({type:"onDragOver",event:Ze})})},[ge]),xr(()=>{fe.current={activatorEvent:Y,active:I,activeNode:he,collisionRect:oe,collisions:de,droppableRects:ne,draggableNodes:S,draggingNode:G,draggingNodeRect:re,droppableContainers:M,over:we,scrollableAncestors:O,scrollAdjustedTranslate:J},R.current={initial:re,translated:oe}},[I,he,de,oe,S,G,re,ne,M,we,O,J]),KB({...me,delta:_,draggingRect:oe,pointerCoordinates:$,scrollableAncestors:O,scrollableAncestorRects:V});const Ge=C.useMemo(()=>({active:I,activeNode:he,activeNodeRect:le,activatorEvent:Y,collisions:de,containerNodeRect:be,dragOverlay:D,draggableNodes:S,droppableContainers:M,droppableRects:ne,over:we,measureDroppableContainers:K,scrollableAncestors:O,scrollableAncestorRects:V,measuringConfiguration:L,measuringScheduled:Q,windowRect:X}),[I,he,le,Y,de,be,D,S,M,ne,we,K,O,V,L,Q,X]),ft=C.useMemo(()=>({activatorEvent:Y,activators:Ve,active:I,activeNodeRect:le,ariaDescribedById:{draggable:q},dispatch:w,draggableNodes:S,over:we,measureDroppableContainers:K}),[Y,Ve,I,le,w,q,S,we,K]);return C.createElement(Af.Provider,{value:y},C.createElement(Jo.Provider,{value:ft},C.createElement(eh.Provider,{value:Ge},C.createElement(Hi.Provider,{value:Ie},u)),C.createElement(gP,{disabled:(c==null?void 0:c.restoreFocus)===!1})),C.createElement(yB,{...c,hiddenTextDescribedById:q}));function Ne(){const Fe=(Z==null?void 0:Z.autoScrollEnabled)===!1,Me=typeof d=="object"?d.enabled===!1:d===!1,_e=j&&!Fe&&!Me;return typeof d=="object"?{...d,enabled:_e}:{enabled:_e}}}),wP=C.createContext(null),rh="button",xP="Draggable";function Jn(e){let{id:t,data:r,disabled:n=!1,attributes:a}=e;const o=Vo(xP),{activators:i,activatorEvent:c,active:d,activeNodeRect:u,ariaDescribedById:f,draggableNodes:h,over:p}=C.useContext(Jo),{role:m=rh,roleDescription:v="draggable",tabIndex:g=0}=a??{},b=(d==null?void 0:d.id)===t,w=C.useContext(b?Hi:wP),[x,y]=Li(),[E,k]=Li(),j=lP(i,t),A=Bo(r);xr(()=>(h.set(t,{id:t,key:o,node:x,activatorNode:E,data:A}),()=>{const _=h.get(t);_&&_.key===o&&h.delete(t)}),[h,t]);const S=C.useMemo(()=>({role:m,tabIndex:g,"aria-disabled":n,"aria-pressed":b&&m===rh?!0:void 0,"aria-roledescription":v,"aria-describedby":f.draggable}),[n,m,g,b,v,f.draggable]);return{active:d,activatorEvent:c,activeNodeRect:u,attributes:S,isDragging:b,listeners:n?void 0:j,node:x,over:p,setNodeRef:y,setActivatorNodeRef:k,transform:w}}function nh(){return C.useContext(eh)}const yP="Droppable",kP={timeout:25};function Sr(e){let{data:t,disabled:r=!1,id:n,resizeObserverConfig:a}=e;const o=Vo(yP),{active:i,dispatch:c,over:d,measureDroppableContainers:u}=C.useContext(Jo),f=C.useRef({disabled:r}),h=C.useRef(!1),p=C.useRef(null),m=C.useRef(null),{disabled:v,updateMeasurementsFor:g,timeout:b}={...kP,...a},w=Bo(g??n),x=C.useCallback(()=>{if(!h.current){h.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{u(Array.isArray(w.current)?w.current:[w.current]),m.current=null},b)},[b]),y=Zi({callback:x,disabled:v||!i}),E=C.useCallback((S,_)=>{y&&(_&&(y.unobserve(_),h.current=!1),S&&y.observe(S))},[y]),[k,j]=Li(E),A=Bo(t);return C.useEffect(()=>{!y||!k.current||(y.disconnect(),h.current=!1,y.observe(k.current))},[k,y]),C.useEffect(()=>(c({type:bt.RegisterDroppable,element:{id:n,key:o,disabled:r,node:k,rect:p,data:A}}),()=>c({type:bt.UnregisterDroppable,key:o,id:n})),[n]),C.useEffect(()=>{r!==f.current.disabled&&(c({type:bt.SetDroppableDisabled,id:n,key:o,disabled:r}),f.current.disabled=r)},[n,o,r,c]),{active:i,rect:p,isOver:(d==null?void 0:d.id)===n,node:k,over:d,setNodeRef:j}}function EP(e){let{animation:t,children:r}=e;const[n,a]=C.useState(null),[o,i]=C.useState(null),c=Ti(r);return!r&&!n&&c&&a(c),xr(()=>{if(!o)return;const d=n==null?void 0:n.key,u=n==null?void 0:n.props.id;if(d==null||u==null){a(null);return}Promise.resolve(t(u,o)).then(()=>{a(null)})},[t,n,o]),C.createElement(C.Fragment,null,r,n?C.cloneElement(n,{ref:i}):null)}const CP={x:0,y:0,scaleX:1,scaleY:1};function jP(e){let{children:t}=e;return C.createElement(Jo.Provider,{value:Qf},C.createElement(Hi.Provider,{value:CP},t))}const DP={position:"fixed",touchAction:"none"},SP=e=>$i(e)?"transform 250ms ease":void 0,AP=C.forwardRef((e,t)=>{let{as:r,activatorEvent:n,adjustScale:a,children:o,className:i,rect:c,style:d,transform:u,transition:f=SP}=e;if(!c)return null;const h=a?u:{...u,scaleX:1,scaleY:1},p={...DP,width:c.width,height:c.height,top:c.top,left:c.left,transform:Wr.Transform.toString(h),transformOrigin:a&&n?kB(n,c):void 0,transition:typeof f=="function"?f(n):f,...d};return C.createElement(r,{className:i,style:p,ref:t},o)}),NP={duration:250,easing:"ease",keyframes:e=>{let{transform:{initial:t,final:r}}=e;return[{transform:Wr.Transform.toString(t)},{transform:Wr.Transform.toString(r)}]},sideEffects:(e=>t=>{let{active:r,dragOverlay:n}=t;const a={},{styles:o,className:i}=e;if(o!=null&&o.active)for(const[c,d]of Object.entries(o.active))d!==void 0&&(a[c]=r.node.style.getPropertyValue(c),r.node.style.setProperty(c,d));if(o!=null&&o.dragOverlay)for(const[c,d]of Object.entries(o.dragOverlay))d!==void 0&&n.node.style.setProperty(c,d);return i!=null&&i.active&&r.node.classList.add(i.active),i!=null&&i.dragOverlay&&n.node.classList.add(i.dragOverlay),function(){for(const[d,u]of Object.entries(a))r.node.style.setProperty(d,u);i!=null&&i.active&&r.node.classList.remove(i.active)}})({styles:{active:{opacity:"0"}}})};function FP(e){let{config:t,draggableNodes:r,droppableContainers:n,measuringConfiguration:a}=e;return Oi((o,i)=>{if(t===null)return;const c=r.get(o);if(!c)return;const d=c.node.current;if(!d)return;const u=Xf(i);if(!u)return;const{transform:f}=Ot(i).getComputedStyle(i),h=Rf(f);if(!h)return;const p=typeof t=="function"?t:_P(t);return Vf(d,a.draggable.measure),p({active:{id:o,data:c.data,node:d,rect:a.draggable.measure(d)},draggableNodes:r,dragOverlay:{node:i,rect:a.dragOverlay.measure(u)},droppableContainers:n,measuringConfiguration:a,transform:h})})}function _P(e){const{duration:t,easing:r,sideEffects:n,keyframes:a}={...NP,...e};return o=>{let{active:i,dragOverlay:c,transform:d,...u}=o;if(!t)return;const f={x:c.rect.left-i.rect.left,y:c.rect.top-i.rect.top},h={scaleX:d.scaleX!==1?i.rect.width*d.scaleX/c.rect.width:1,scaleY:d.scaleY!==1?i.rect.height*d.scaleY/c.rect.height:1},p={x:d.x-f.x,y:d.y-f.y,...h},m=a({...u,active:i,dragOverlay:c,transform:{initial:d,final:p}}),[v]=m,g=m[m.length-1];if(JSON.stringify(v)===JSON.stringify(g))return;const b=n==null?void 0:n({active:i,dragOverlay:c,...u}),w=c.node.animate(m,{duration:t,easing:r,fill:"forwards"});return new Promise(x=>{w.onfinish=()=>{b==null||b(),x()}})}}let ah=0;function MP(e){return C.useMemo(()=>{if(e!=null)return ah++,ah},[e])}const oh=C.memo(e=>{let{adjustScale:t=!1,children:r,dropAnimation:n,style:a,transition:o,modifiers:i,wrapperElement:c="div",className:d,zIndex:u=999}=e;const{activatorEvent:f,active:h,activeNodeRect:p,containerNodeRect:m,draggableNodes:v,droppableContainers:g,dragOverlay:b,over:w,measuringConfiguration:x,scrollableAncestors:y,scrollableAncestorRects:E,windowRect:k}=nh(),j=C.useContext(Hi),A=MP(h==null?void 0:h.id),S=th(i,{activatorEvent:f,active:h,activeNodeRect:p,containerNodeRect:m,draggingNodeRect:b.rect,over:w,overlayNodeRect:b.rect,scrollableAncestors:y,scrollableAncestorRects:E,transform:j,windowRect:k}),_=Yd(p),M=FP({config:n,draggableNodes:v,droppableContainers:g,measuringConfiguration:x}),B=_?b.setRef:void 0;return C.createElement(jP,null,C.createElement(EP,{animation:M},h&&A?C.createElement(AP,{key:A,id:h.id,ref:B,as:c,activatorEvent:f,adjustScale:t,className:d,transition:o,rect:_,style:{zIndex:u,...a},transform:S},r):null))}),RP={text:"var(--comp-text)",number:"var(--comp-number)",email:"var(--comp-email)",password:"var(--comp-password, var(--comp-text))",tel:"var(--comp-tel, var(--comp-text))",url:"var(--comp-url, var(--comp-text))",select:"var(--comp-select)",checkbox:"var(--comp-checkbox)",optionGroup:"var(--comp-checkbox)",textarea:"var(--comp-textarea)",date:"var(--comp-date)",file:"var(--comp-file)",search:"var(--comp-search, var(--comp-text))","section-layout":"var(--comp-section)","tabs-layout":"var(--comp-tabs)",inputGroup:"var(--comp-text)",array:"var(--comp-section)",button:"var(--comp-button, var(--color-ds-button-primary-bg))",iban:"var(--comp-iban, var(--comp-text))",dni:"var(--comp-dni, var(--comp-text))",table:"var(--comp-section)"};function Ur(e){return e?RP[e]??"var(--comp-file)":"var(--comp-file)"}function kr(e){const t="w-4 h-4",r={color:Ur(e)};switch(e){case"text":return l.jsx(ma,{className:t,style:r});case"number":return l.jsx(N1,{className:t,style:r});case"email":return l.jsx(Xl,{className:t,style:r});case"password":return l.jsx(vo,{className:t,style:r});case"tel":return l.jsx(oc,{className:t,style:r});case"url":return l.jsx(nc,{className:t,style:r});case"select":return l.jsx(go,{className:t,style:r});case"checkbox":return l.jsx(fn,{className:t,style:r});case"optionGroup":return l.jsx(fn,{className:t,style:r});case"textarea":return l.jsx(ha,{className:t,style:r});case"date":return l.jsx(g1,{className:t,style:r});case"file":return l.jsx(j1,{className:t,style:r});case"search":return l.jsx(bo,{className:t,style:r});case"section-layout":return l.jsx(sc,{className:t,style:r});case"tabs-layout":return l.jsx(cc,{className:t,style:r});case"inputGroup":return l.jsx(sc,{className:t,style:r});case"array":return l.jsx(R1,{className:t,style:r});case"button":return l.jsx(hn,{className:t,style:r});case"iban":return l.jsx(Wl,{className:t,style:r});case"dni":return l.jsx(rc,{className:t,style:r});case"table":return l.jsx(O1,{className:t,style:r});default:return l.jsx(hr,{className:t,style:r})}}const OP=[{value:"text",label:"Texto"},{value:"number",label:"Número"},{value:"email",label:"Email"},{value:"password",label:"Password"},{value:"tel",label:"Teléfono"},{value:"iban",label:"Cuenta Bancaria"},{value:"dni",label:"DNI/NIE/CIF"},{value:"url",label:"URL"},{value:"textarea",label:"Textarea"},{value:"select",label:"Select"},{value:"checkbox",label:"Checkbox"},{value:"optionGroup",label:"Option Group"},{value:"date",label:"Fecha"},{value:"file",label:"Archivo"},{value:"search",label:"Búsqueda"},{value:"array",label:"Lista Repetible"},{value:"button",label:"Botón"},{value:"table",label:"Tabla"}];function LP(){return{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"}]}}const sh=()=>l.jsxs("div",{className:"w-full border rounded text-xs p-2 bg-[var(--color-ds-background-surface)] opacity-70",children:[l.jsxs("div",{className:"flex border-b pb-1 mb-1 font-bold",children:[l.jsx("div",{className:"w-1/3",children:"H1"}),l.jsx("div",{className:"w-1/3",children:"H2"})]}),l.jsxs("div",{className:"space-y-1",children:[l.jsx("div",{className:"h-2 bg-gray-200 rounded w-3/4"}),l.jsx("div",{className:"h-2 bg-gray-200 rounded w-1/2"})]})]});function TP(){return{label:"Cuenta Bancaria",type:"iban",width:"w-full",placeholder:"ES00 0000 0000 0000 0000 0000",size:"sm"}}function $P(){return{label:"DNI/NIE",type:"dni",width:"w-full",placeholder:"12345678A",size:"sm"}}function IP(){return{label:"Texto",type:"text",width:"w-full",placeholder:"Escribe…",size:"sm"}}function BP(){return{label:"Número",type:"number",width:"w-full",placeholder:"0",size:"sm",validation:{required:!1}}}function PP(){return{label:"Email",type:"email",width:"w-full",placeholder:"usuario@dominio.com",size:"sm"}}function VP(){return{label:"Contraseña",type:"password",width:"w-full",placeholder:"••••••••",size:"sm",validation:{minLength:8}}}function ZP(){return{label:"Teléfono",type:"tel",width:"w-full",placeholder:"600 000 000",size:"sm"}}function zP(){return{label:"URL",type:"url",width:"w-full",placeholder:"https://ejemplo.com",size:"sm"}}function HP(){return{label:"Selecciona una opción",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}}function WP(){return{label:"Aceptar condiciones",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}}function UP(){return{label:"Comentario",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"Escribe tu comentario…"}}function qP(){return{label:"Fecha",type:"date",width:"w-full",size:"sm",showTime:!1}}function GP(){return{label:"Documento",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}}function KP(){return{label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}}function JP(){return{label:"Búsqueda",type:"search",width:"w-full",placeholder:"Buscar...",size:"sm",searchMode:"button"}}function YP(){return{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"}]}}function XP(){return{label:"Lista repetible",type:"array",width:"w-full",items:[]}}function QP(){return{label:"Botón",type:"button",width:"w-auto",variant:"primary",size:"sm"}}const eV={text:IP,number:BP,email:PP,password:VP,tel:ZP,iban:TP,dni:$P,table:LP,url:zP,select:HP,checkbox:WP,optionGroup:YP,textarea:UP,date:qP,file:GP,search:JP,inputGroup:KP,array:XP,button:QP},ih=()=>l.jsx(je,{label:"Texto",placeholder:"Escribe…",size:"sm",reserveErrorSpace:!1}),lh=()=>l.jsx(je,{type:"number",label:"Número",placeholder:"0",size:"sm",reserveErrorSpace:!1}),ch=()=>l.jsx(je,{type:"email",label:"Email",placeholder:"usuario@dominio.com",size:"sm",reserveErrorSpace:!1}),dh=()=>l.jsx(je,{type:"password",label:"Contraseña",placeholder:"••••••••",size:"sm",reserveErrorSpace:!1}),uh=()=>l.jsx(je,{type:"tel",label:"Teléfono",placeholder:"600 000 000",size:"sm",reserveErrorSpace:!1}),fh=()=>l.jsx(Ci,{label:"Cuenta Bancaria",placeholder:"ES00 0000 0000 0000 0000 0000",size:"sm",reserveErrorSpace:!1,value:"",onChange:()=>{}}),hh=()=>l.jsx(hd,{label:"DNI/NIE",placeholder:"12345678A",size:"sm",reserveErrorSpace:!1,value:"",onChange:()=>{}}),ph=()=>l.jsx(je,{type:"url",label:"URL",placeholder:"https://ejemplo.com",size:"sm",reserveErrorSpace:!1}),mh=()=>l.jsx(Xe,{label:"Select",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}],size:"sm"}),gh=()=>l.jsx(it,{label:"Aceptar condiciones",defaultValue:!1,name:"__prev_checkbox__"}),vh=()=>l.jsx(Dr,{label:"Comentario",placeholder:"Escribe tu comentario…",size:"sm",maxLength:120,showCounter:!0}),bh=()=>l.jsx(Sa,{label:"Fecha",defaultValue:"",showTime:!1,name:"__prev_date__"}),wh=()=>l.jsxs("div",{children:[l.jsx("label",{className:"text-ds-sm mb-1 block opacity-80",children:"Documento"}),l.jsx("div",{className:"w-full rounded-xl border border-dashed p-4 text-ds-sm opacity-70",children:"Arrastra o selecciona archivo…"})]}),xh=()=>l.jsx(je,{label:"Búsqueda",placeholder:"Buscar...",size:"sm",reserveErrorSpace:!1,suffixButton:l.jsx(pe,{size:"sm",variant:"primary",className:"!rounded-l-none",children:"Buscar"})}),yh=()=>{const e=$c({defaultValues:{__prev_optiongroup__:[]}});return l.jsx(wc,{...e,children:l.jsx(ki,{groupLabel:"Selecciona opciones",options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}],control:e.control,name:"__prev_optiongroup__",multiple:!0,vertical:!0,size:"sm"})})},kh=()=>l.jsx("div",{className:"p-2 rounded-md bg-[var(--color-ds-background-surface)]",children:l.jsx(zr,{options:[{label:"Tab 1",value:"t1"},{label:"Tab 2",value:"t2"}],value:"t1",onChange:()=>{},children:{t1:l.jsx("div",{className:"text-ds-sm opacity-80",children:"Contenido ejemplo 1"}),t2:l.jsx("div",{className:"text-ds-sm opacity-80",children:"Contenido ejemplo 2"})}})}),Eh=()=>l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)]",children:[l.jsx("div",{className:"px-3 py-2 border-b border-[var(--color-ds-border-default-50)] text-ds-sm",children:"Sección"}),l.jsx("div",{className:"p-3 text-ds-sm opacity-70",children:"Fila con 1 columna (w-full). Modifícala desde el lienzo."})]}),Ch=()=>l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-3",children:[l.jsx("div",{className:"text-ds-sm mb-2 opacity-70",children:"Grupo"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(je,{size:"sm",placeholder:"Campo A",reserveErrorSpace:!1}),l.jsx(je,{size:"sm",placeholder:"Campo B",reserveErrorSpace:!1})]})]}),jh=()=>l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-3",children:[l.jsx("div",{className:"text-ds-sm mb-2 opacity-70",children:"Repeater (Array)"}),l.jsx("div",{className:"border border-dashed border-[var(--color-ds-border-default-50)] rounded p-2 text-center text-ds-sm opacity-60",children:"Arrastra campos aquí"})]}),Dh=()=>l.jsxs("div",{className:"flex flex-wrap gap-2",children:[l.jsx(pe,{size:"sm",variant:"primary",children:"Primario"}),l.jsx(pe,{size:"sm",variant:"outline",children:"Outline"}),l.jsx(pe,{size:"sm",variant:"ghost",children:"Ghost"})]}),tV={text:l.jsx(ih,{}),number:l.jsx(lh,{}),email:l.jsx(ch,{}),password:l.jsx(dh,{}),tel:l.jsx(uh,{}),url:l.jsx(ph,{}),select:l.jsx(mh,{}),checkbox:l.jsx(gh,{}),optionGroup:l.jsx(yh,{}),textarea:l.jsx(vh,{}),date:l.jsx(bh,{}),file:l.jsx(wh,{}),search:l.jsx(xh,{}),inputGroup:l.jsx(Ch,{}),array:l.jsx(jh,{}),button:l.jsx(Dh,{}),iban:l.jsx(fh,{}),dni:l.jsx(hh,{}),table:l.jsx(sh,{}),"section-layout":l.jsx(Eh,{}),"tabs-layout":l.jsx(kh,{})},Wi=[{kind:"table",title:"Tabla",category:"content",renderPreview:l.jsx(sh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Tabla de datos."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Muestra datos tabulares."}),l.jsx("li",{children:"Configurable con columnas y origen de datos."})]})]})},{kind:"text",title:"Texto",category:"basics",renderPreview:l.jsx(ih,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo de texto de una sola línea."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Ideal para nombres, títulos o datos cortos."}),l.jsx("li",{children:"Soporta validaciones de longitud y patrones (Regex)."})]})]})},{kind:"number",title:"Número",category:"basics",renderPreview:l.jsx(lh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Entrada numérica controlada."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Útil para edades, cantidades o importes."}),l.jsx("li",{children:"Permite definir mínimos, máximos y pasos (decimales)."})]})]})},{kind:"email",title:"Email",category:"basics",renderPreview:l.jsx(ch,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo optimizado para correos electrónicos."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Valida automáticamente el formato de email."}),l.jsx("li",{children:"Activa el teclado de correo en móviles."})]})]})},{kind:"password",title:"Clave",category:"basics",renderPreview:l.jsx(dh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo seguro para contraseñas."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Oculta los caracteres por seguridad."}),l.jsx("li",{children:"Incluye botón para mostrar/ocultar contraseña."})]})]})},{kind:"tel",title:"Teléfono",category:"basics",renderPreview:l.jsx(uh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo para números telefónicos."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Activa el teclado numérico en dispositivos móviles."}),l.jsx("li",{children:"Compatible con validaciones por patrón."})]})]})},{kind:"iban",title:"IBAN",category:"basics",renderPreview:l.jsx(fh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo para cuentas bancarias en formato IBAN."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Formatea automáticamente en grupos de 4 para mejorar la lectura."}),l.jsx("li",{children:"Normaliza a mayúsculas y elimina espacios/caracteres no válidos."}),l.jsx("li",{children:"Se valida por algoritmo Módulo 97."})]})]})},{kind:"dni",title:"DNI/NIE",category:"basics",renderPreview:l.jsx(hh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo para documentos de identidad (DNI, NIE, CIF)."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Normaliza a mayúsculas y elimina espacios."}),l.jsx("li",{children:"Validación de formato básico."}),l.jsx("li",{children:"Máximo 9 caracteres alfanuméricos."})]})]})},{kind:"url",title:"URL",category:"basics",renderPreview:l.jsx(ph,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo para direcciones web."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Valida formato de URL (http/https)."}),l.jsx("li",{children:"Útil para enlaces a sitios web o recursos externos."})]})]})},{kind:"select",title:"Select",category:"basics",renderPreview:l.jsx(mh,{}),hint:"Admite optionSource",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Desplegable de selección única o múltiple."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Recomendado para listas largas de opciones."}),l.jsx("li",{children:"Puede cargar datos dinámicos desde servicios externos."})]})]})},{kind:"checkbox",title:"Check",category:"basics",renderPreview:l.jsx(gh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Casilla de verificación simple."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Para respuestas binarias (Sí/No)."}),l.jsx("li",{children:'Ideal para "Aceptar términos" o confirmaciones.'})]})]})},{kind:"optionGroup",title:"Opciones",category:"basics",renderPreview:l.jsx(yh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Grupo de opciones visibles (Radio o Checkbox)."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Muestra todas las opciones a la vez."}),l.jsx("li",{children:"Mejor UX que un Select cuando hay pocas opciones (2-5)."})]})]})},{kind:"date",title:"Fecha",category:"basics",renderPreview:l.jsx(bh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Selector de fecha completo."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Incluye calendario desplegable."}),l.jsx("li",{children:"Opcionalmente permite seleccionar hora."}),l.jsx("li",{children:"Soporta límites (min/max) y deshabilitar días."})]})]})},{kind:"textarea",title:"Textarea",category:"content",renderPreview:l.jsx(vh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Área de texto multilínea."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Para observaciones, descripciones o notas largas."}),l.jsx("li",{children:"Incluye contador de caracteres configurable."})]})]})},{kind:"file",title:"Archivo",category:"content",renderPreview:l.jsx(wh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Widget de subida de ficheros."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Soporta Arrastrar y Soltar (Drag & Drop)."}),l.jsx("li",{children:"Configurable por tipo de archivo y tamaño máximo."})]})]})},{kind:"search",title:"Búsqueda",category:"content",renderPreview:l.jsx(xh,{}),detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Campo de búsqueda especializado."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Incluye botón de acción integrado."}),l.jsx("li",{children:"Ideal para buscadores, filtros o consultas a APIs."})]})]})},{kind:"section-layout",title:"Sección",category:"layout",renderPreview:l.jsx(Eh,{}),isLayout:!0,hint:"Contenedor de layout",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Bloque contenedor colapsable."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Agrupa campos visualmente bajo un título."}),l.jsx("li",{children:"Permite organizar el formulario en bloques lógicos."})]})]})},{kind:"tabs-layout",title:"Pestañas",category:"layout",renderPreview:l.jsx(kh,{}),isLayout:!0,hint:"Contenedor de layout (no es un campo)",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Contenedor de pestañas."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Organiza gran cantidad de información en vistas separadas."}),l.jsx("li",{children:"Cada pestaña tiene su propio contenido independiente."})]})]})},{kind:"inputGroup",title:"Grupo",category:"content",renderPreview:l.jsx(Ch,{}),hint:"Contenedor de varios inputs en una fila",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Agrupador horizontal de campos."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Coloca múltiples inputs en una sola fila (inline)."}),l.jsx("li",{children:"Útil para datos relacionados (ej. Nombre + Apellidos)."})]})]})},{kind:"array",title:"Lista",category:"content",renderPreview:l.jsx(jh,{}),hint:"Lista repetible de campos",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Lista repetible (Repeater)."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Permite al usuario añadir múltiples registros."}),l.jsx("li",{children:"Define una plantilla de campos que se repetirá por fila."})]})]})},{kind:"button",title:"Botón",category:"content",renderPreview:l.jsx(Dh,{}),hint:"Botón de acción",detail:l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsx("p",{children:"Botón interactivo para ejecutar acciones."}),l.jsxs("ul",{className:"list-disc pl-4 opacity-80",children:[l.jsx("li",{children:"Ejecuta acciones personalizadas al hacer click."}),l.jsx("li",{children:"Múltiples variantes: primario, outline, ghost, subtle, danger."}),l.jsx("li",{children:"Soporta iconos y diferentes tamaños."})]})]})}];function Sh({title:e,onAdd:t,onInfo:r,dragging:n=!1,icon:a,kind:o,dragRef:i,dragProps:c}){const d=Ur(o),[u,f]=C.useState(!1);C.useEffect(()=>{if(!n&&u){const p=setTimeout(()=>f(!1),50);return()=>clearTimeout(p)}},[n,u]);const h=p=>{if(u){p.preventDefault(),p.stopPropagation();return}t()};return l.jsxs("div",{className:["relative group",n?"opacity-70":""].join(" "),children:[l.jsxs(pe,{ref:i,...c,onPointerUp:()=>n&&f(!0),onClick:h,size:"sm",variant:"outline",className:["w-full rounded-xl p-2 text-left justify-start","border-dashed ring-1 ring-inset","cursor-grab active:cursor-grabbing","flex items-center gap-2 pr-11","touch-none select-none"].join(" "),title:`Añadir ${e}`,"aria-label":`Añadir ${e}`,style:{boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${d} 35%, transparent)`},type:"button",children:[l.jsx("span",{"aria-hidden":!0,className:"shrink-0 flex items-center gap-1",children:l.jsx("span",{className:"text-[var(--color-ds-text-secondary)]",style:{color:d},children:a})}),l.jsx("div",{className:"text-ds-sm",children:e})]}),l.jsx("div",{className:"absolute top-3/4 -translate-y-3/4 right-1",children:l.jsx(Pc,{size:"sm",position:"right",ariaLabel:`Más info de ${e}`,onClick:r,children:l.jsxs("div",{className:"max-w-[240px]",children:["Pulsa para ver un ejemplo y detalles de ",l.jsx("strong",{children:e}),"."]})})})]})}function Ah({kind:e,title:t,onAdd:r,onInfo:n}){const{attributes:a,listeners:o,setNodeRef:i,isDragging:c}=Jn({id:`palette:${e}:${t}`,data:{kind:"palette-field",factoryKind:e}}),{role:d,tabIndex:u}=a,f={...o,...d?{role:d}:{},...u!==void 0?{tabIndex:u}:{}};return l.jsx(Sh,{kind:e,title:t,onAdd:r,onInfo:n,dragging:c,icon:kr(e),dragRef:i,dragProps:f})}function rV(){var g;const e=se(b=>b.addField),t=se(b=>b.addTabsContainerAt),r=se(b=>b.addRowsBlockAt),n=se(b=>b.schema),{show:a}=yn(),[o,i]=C.useState(""),[c,d]=C.useState(null),u=C.useMemo(()=>Wi.filter(b=>b.category==="basics"&&b.title.toLowerCase().includes(o.toLowerCase())),[o]),f=C.useMemo(()=>Wi.filter(b=>b.category==="content"&&b.title.toLowerCase().includes(o.toLowerCase())),[o]),h=C.useMemo(()=>Wi.filter(b=>b.category==="layout"&&b.title.toLowerCase().includes(o.toLowerCase())),[o]),p=C.useMemo(()=>Wi.find(b=>b.kind===c)??null,[c]),m=C.useCallback(b=>{const w=eV[b];if(!w){a("Tipo de campo no soportado.","warning");return}const x=w();e(x),a(`Añadido “${x.label}”. Ahora arrástralo al formulario o usa “Colocar último campo”.`,"success")},[e,a]),v=C.useCallback(b=>{var x;const w=((x=n==null?void 0:n.layout)==null?void 0:x.length)??0;if(b==="section-layout"){typeof r=="function"?(r(w,"Nueva sección"),a("Sección añadida al layout.","success")):a("Acción addRowsBlockAt no disponible en el store.","warning");return}if(b==="tabs-layout"){typeof t=="function"?(t(w),a("Contenedor de pestañas añadido al layout.","success")):a("Acción addTabsContainerAt no disponible en el store.","warning");return}a("Tipo de layout no soportado.","warning")},[(g=n==null?void 0:n.layout)==null?void 0:g.length,r,t,a]);if(p){const b=!!p.isLayout;return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"px-1 border-b border-[var(--color-ds-border-default-50)] flex items-center h-[32px] mb-2",children:[l.jsx("strong",{className:"text-[var(--color-ds-text-primary)] flex-1 truncate text-sm",children:p.title}),l.jsx(pe,{size:"xs",variant:"ghost",onClick:()=>d(null),children:"← Volver"})]}),l.jsx("div",{className:"border border-[var(--color-ds-border-default-50)] p-4 bg-[var(--color-ds-background-surface)] rounded-xl",children:p.renderPreview}),l.jsxs("div",{className:"p-3 rounded-xl bg-[var(--color-ds-background-page)] border border-[var(--color-ds-border-default-50)] shadow-sm",children:[l.jsxs("div",{className:"flex flex-col items-center gap-2 mb-4",children:[l.jsx(pe,{size:"sm",variant:"primary",className:"w-full",onClick:()=>b?v(p.kind):m(p.kind),children:"Añadir al lienzo"}),l.jsx("span",{className:"text-ds-sm opacity-70",children:"o arrastra al formulario"})]}),l.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] p-3 space-y-2",children:[l.jsxs("div",{className:"text-ds-sm font-medium text-[var(--color-ds-text-primary)]",children:["Acerca de ",p.title]}),l.jsxs("div",{className:"text-ds-sm space-y-2 text-[var(--color-ds-text-secondary)]",children:[p.hint&&l.jsx("div",{className:"font-medium",children:p.hint}),p.detail]})]})]})]})}return l.jsxs("div",{className:"space-y-6",children:[l.jsx("div",{className:"pb-2",children:l.jsx(je,{size:"sm",placeholder:"Buscar componente…",value:o,onChange:b=>i(b.target.value),reserveErrorSpace:!1,label:"Buscar",labelHidden:!0,"aria-label":"Buscar componente en la paleta"})}),l.jsxs("section",{className:"space-y-3",children:[l.jsx("div",{className:"text-[var(--color-ds-text-secondary)] text-ds-sm font-semibold uppercase tracking-wider",children:"Inputs básicos"}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[u.map(b=>l.jsx(Ah,{kind:b.kind,title:b.title,onAdd:()=>m(b.kind),onInfo:()=>d(b.kind)},b.kind)),u.length===0&&l.jsx("div",{className:"col-span-2 text-ds-sm opacity-60 text-center py-4",children:"Sin resultados"})]})]}),l.jsxs("section",{className:"space-y-3",children:[l.jsx("div",{className:"text-[var(--color-ds-text-secondary)] text-ds-sm font-semibold uppercase tracking-wider",children:"Contenido"}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[f.map(b=>l.jsx(Ah,{kind:b.kind,title:b.title,onAdd:()=>m(b.kind),onInfo:()=>d(b.kind)},b.kind)),f.length===0&&l.jsx("div",{className:"col-span-2 text-ds-sm opacity-60 text-center py-4",children:"Sin resultados"})]})]}),l.jsxs("section",{className:"space-y-3",children:[l.jsx("div",{className:"text-[var(--color-ds-text-secondary)] text-ds-sm font-semibold uppercase tracking-wider",children:"Layout"}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[h.map(b=>l.jsx(Sh,{kind:b.kind,title:b.title,onAdd:()=>b.isLayout?v(b.kind):m(b.kind),onInfo:()=>d(b.kind),icon:kr(b.kind)},b.kind)),h.length===0&&l.jsx("div",{className:"col-span-2 text-ds-sm opacity-60 text-center py-4",children:"Sin resultados"})]})]})]})}const Yn=[{op:"eq",label:"es igual a",inputType:"single",placeholder:"valor exacto"},{op:"neq",label:"es distinto de",inputType:"single",placeholder:"valor a excluir"},{op:"isEmpty",label:"está vacío",inputType:"none",description:"Campo sin valor",compile:e=>({op:"eq",field:e,value:""})},{op:"isNotEmpty",label:"tiene valor",inputType:"none",description:"Campo con cualquier valor",compile:e=>({op:"neq",field:e,value:""})},{op:"contains",label:"contiene",inputType:"single",placeholder:"texto a buscar",description:"El campo contiene este texto"},{op:"notContains",label:"no contiene",inputType:"single",placeholder:"texto a excluir"},{op:"startsWith",label:"empieza con",inputType:"single",placeholder:"prefijo"},{op:"endsWith",label:"termina con",inputType:"single",placeholder:"sufijo"},{op:"in",label:"es uno de",inputType:"multi",placeholder:"opción1, opción2, opción3"},{op:"notIn",label:"no es ninguno de",inputType:"multi",placeholder:"valor1, valor2, valor3"},{op:"matches",label:"coincide con patrón",inputType:"pattern",placeholder:"^[A-Z]{3}\\d{4}$",description:"Expresión regular"}],nV=[{op:"eq",label:"igual a",inputType:"single",placeholder:"123"},{op:"neq",label:"distinto de",inputType:"single",placeholder:"0"},{op:"gt",label:"mayor que",inputType:"single",placeholder:"0"},{op:"gte",label:"mayor o igual",inputType:"single",placeholder:"1"},{op:"lt",label:"menor que",inputType:"single",placeholder:"100"},{op:"lte",label:"menor o igual",inputType:"single",placeholder:"99"},{op:"inRange",label:"entre",inputType:"range",placeholder:"min,max",description:"Valor entre un rango",compile:(e,t)=>{const[r,n]=t.split(",").map(a=>parseFloat(a.trim()));return{op:"and",rules:[{op:"gte",field:e,value:r},{op:"lte",field:e,value:n}]}}},{op:"isEmpty",label:"sin valor",inputType:"none",compile:e=>({op:"eq",field:e,value:null})},{op:"in",label:"es uno de",inputType:"multi",placeholder:"1, 2, 3, 5, 8"}],aV=[{op:"isTrue",label:"está marcado",inputType:"none",compile:e=>({op:"eq",field:e,value:!0})},{op:"isFalse",label:"está desmarcado",inputType:"none",compile:e=>({op:"eq",field:e,value:!1})},{op:"eq",label:"es igual a",inputType:"single",placeholder:"true/false"}],Nh=[{op:"eq",label:"es igual a",inputType:"single",placeholder:"valor seleccionado"},{op:"neq",label:"es distinto de",inputType:"single",placeholder:"valor"},{op:"isEmpty",label:"sin selección",inputType:"none",compile:e=>({op:"eq",field:e,value:""})},{op:"isNotEmpty",label:"tiene selección",inputType:"none",compile:e=>({op:"neq",field:e,value:""})},{op:"in",label:"es uno de",inputType:"multi",placeholder:"opción1, opción2"},{op:"notIn",label:"no es ninguno de",inputType:"multi",placeholder:"valor1, valor2"}],oV=[{op:"eq",label:"es exactamente",inputType:"single",placeholder:"2025-01-15"},{op:"neq",label:"no es",inputType:"single",placeholder:"2025-01-01"},{op:"gt",label:"después de",inputType:"single",placeholder:"2025-01-01"},{op:"gte",label:"desde (inclusive)",inputType:"single",placeholder:"2025-01-01"},{op:"lt",label:"antes de",inputType:"single",placeholder:"2025-12-31"},{op:"lte",label:"hasta (inclusive)",inputType:"single",placeholder:"2025-12-31"},{op:"today",label:"es hoy",inputType:"none",description:"La fecha es hoy",compile:e=>{const t=new Date().toISOString().split("T")[0];return{op:"eq",field:e,value:t}}},{op:"inPast",label:"es en el pasado",inputType:"none",compile:e=>{const t=new Date().toISOString().split("T")[0];return{op:"lt",field:e,value:t}}},{op:"inFuture",label:"es en el futuro",inputType:"none",compile:e=>{const t=new Date().toISOString().split("T")[0];return{op:"gt",field:e,value:t}}},{op:"inRange",label:"entre fechas",inputType:"range",placeholder:"2025-01-01,2025-12-31",compile:(e,t)=>{const[r,n]=t.split(",").map(a=>a.trim());return{op:"and",rules:[{op:"gte",field:e,value:r},{op:"lte",field:e,value:n}]}}},{op:"isEmpty",label:"sin fecha",inputType:"none",compile:e=>({op:"eq",field:e,value:null})}],sV=[{op:"isEmpty",label:"está vacío",inputType:"none",compile:e=>({op:"eq",field:e,value:""})},{op:"isNotEmpty",label:"tiene contenido",inputType:"none",compile:e=>({op:"neq",field:e,value:""})},{op:"contains",label:"contiene",inputType:"single",placeholder:"palabra clave"},{op:"notContains",label:"no contiene",inputType:"single"},{op:"eq",label:"es igual a",inputType:"single"},{op:"neq",label:"es distinto de",inputType:"single"}],iV=[{op:"hasAnyValue",label:"tiene archivo",inputType:"none",description:"Se ha cargado al menos un archivo",compile:e=>({op:"neq",field:e,value:null})},{op:"hasNoValue",label:"sin archivo",inputType:"none",compile:e=>({op:"eq",field:e,value:null})},{op:"eq",label:"nombre es",inputType:"single",placeholder:"documento.pdf",description:"Nombre exacto del archivo"},{op:"contains",label:"nombre contiene",inputType:"single",placeholder:"factura"}],lV=[{op:"hasAnyValue",label:"tiene items",inputType:"none",description:"El repeater tiene al menos un elemento",compile:e=>({op:"gt",field:`${e}.length`,value:0})},{op:"hasNoValue",label:"está vacío",inputType:"none",description:"El repeater no tiene elementos",compile:e=>({op:"eq",field:`${e}.length`,value:0})}],Fh={table:{fieldType:"table",operators:[],defaultOperator:"eq",defaultPlaceholder:"",helpText:"Reglas no soportadas para campos tipo tabla."},text:{fieldType:"text",operators:Yn,defaultOperator:"eq",defaultPlaceholder:"valor del texto",helpText:"Compara el valor del campo de texto"},email:{fieldType:"email",operators:[...Yn,{op:"matches",label:"es email válido",inputType:"none",compile:e=>({op:"matches",field:e,value:/^[^\s@]+@[^\s@]+\.[^\s@]+$/})}],defaultOperator:"eq",defaultPlaceholder:"email@ejemplo.com",helpText:"Valida o compara direcciones de email"},url:{fieldType:"url",operators:[...Yn,{op:"startsWith",label:"protocolo es",inputType:"single",placeholder:"https://"}],defaultOperator:"eq",defaultPlaceholder:"https://ejemplo.com"},tel:{fieldType:"tel",operators:Yn,defaultOperator:"eq",defaultPlaceholder:"+34 600 000 000",helpText:"Compara números de teléfono"},iban:{fieldType:"iban",operators:Yn,defaultOperator:"eq",defaultPlaceholder:"ES00 0000 0000 0000 0000 0000",helpText:"Compara códigos IBAN"},dni:{fieldType:"dni",operators:Yn,defaultOperator:"eq",defaultPlaceholder:"12345678A",helpText:"Compara números de DNI/NIF"},number:{fieldType:"number",operators:nV,defaultOperator:"eq",defaultPlaceholder:"0",helpText:"Comparaciones numéricas",validateValue:(e,t)=>{if(["isEmpty","isNotEmpty"].includes(e))return{valid:!0};if(e==="inRange"){const r=String(t).split(",");if(r.length!==2)return{valid:!1,message:"Formato: min,max"};const[n,a]=r.map(o=>parseFloat(o.trim()));return isNaN(n)||isNaN(a)?{valid:!1,message:"Valores deben ser números"}:n>=a?{valid:!1,message:"Min debe ser menor que Max"}:{valid:!0}}return isNaN(Number(t))?{valid:!1,message:"Debe ser un número válido"}:{valid:!0}}},password:{fieldType:"password",operators:[{op:"isEmpty",label:"sin contraseña",inputType:"none",compile:e=>({op:"eq",field:e,value:""})},{op:"isNotEmpty",label:"tiene contraseña",inputType:"none",compile:e=>({op:"neq",field:e,value:""})}],defaultOperator:"isEmpty",helpText:"Por seguridad, solo se puede validar si existe"},select:{fieldType:"select",operators:Nh,defaultOperator:"eq",defaultPlaceholder:"valor seleccionado",helpText:"Compara el valor seleccionado"},date:{fieldType:"date",operators:oV,defaultOperator:"eq",defaultPlaceholder:"2025-01-01",helpText:"Comparaciones de fechas",validateValue:(e,t)=>["isEmpty","today","inPast","inFuture"].includes(e)?{valid:!0}:e==="inRange"?String(t).split(",").length!==2?{valid:!1,message:"Formato: YYYY-MM-DD,YYYY-MM-DD"}:{valid:!0}:/^\d{4}-\d{2}-\d{2}$/.test(String(t))?{valid:!0}:{valid:!1,message:"Formato: YYYY-MM-DD"}},checkbox:{fieldType:"checkbox",operators:aV,defaultOperator:"isTrue",helpText:"Valida el estado del checkbox"},textarea:{fieldType:"textarea",operators:sV,defaultOperator:"isEmpty",defaultPlaceholder:"contenido del texto",helpText:"Analiza el contenido del textarea"},file:{fieldType:"file",operators:iV,defaultOperator:"hasAnyValue",helpText:"Valida si se ha cargado un archivo"},search:{fieldType:"search",operators:Yn,defaultOperator:"contains",defaultPlaceholder:"término de búsqueda"},optionGroup:{fieldType:"optionGroup",operators:Nh,defaultOperator:"eq"},button:{fieldType:"button",operators:[],defaultOperator:"eq",helpText:"Los botones no tienen valor para reglas"},inputGroup:{fieldType:"inputGroup",operators:[],defaultOperator:"eq",helpText:"Use los campos individuales del grupo"},array:{fieldType:"array",operators:lV,defaultOperator:"hasAnyValue",helpText:"Valida si el repeater tiene elementos"}};function Va(e){return Fh[e]||Fh.text}function En(e,t){return Va(e).operators.find(n=>n.op===t)}function Za(e,t,r,n){const a=En(n,e);if(a!=null&&a.compile)return a.compile(t,r);if(["eq","neq","in","notIn","gt","gte","lt","lte"].includes(e)){let o;if(e==="in"||e==="notIn"){const i=Array.isArray(r)?r:String(r).split(",").map(c=>c.trim());o={op:e,field:t,values:i}}else o={op:e,field:t,value:r};return o._originalOp=e,o}switch(e){case"isEmpty":return{op:"eq",field:t,value:""};case"isNotEmpty":return{op:"neq",field:t,value:""};case"isTrue":return{op:"eq",field:t,value:!0};case"isFalse":return{op:"eq",field:t,value:!1};case"hasAnyValue":return{op:"neq",field:t,value:null};case"hasNoValue":return{op:"eq",field:t,value:null};case"contains":case"notContains":case"startsWith":case"endsWith":case"matches":return{op:"eq",field:t,value:r,_originalOp:e};case"inRange":const o=String(r).split(",");if(o.length===2){const[c,d]=o.map(u=>u.trim());return{op:"and",rules:[{op:"gte",field:t,value:n==="number"?parseFloat(c):c},{op:"lte",field:t,value:n==="number"?parseFloat(d):d}],_originalOp:"inRange"}}return{op:"eq",field:t,value:r,_originalOp:e};case"today":case"inPast":case"inFuture":const i=new Date().toISOString().split("T")[0];if(e==="today")return{op:"eq",field:t,value:i,_originalOp:"today"};if(e==="inPast")return{op:"lt",field:t,value:i,_originalOp:"inPast"};if(e==="inFuture")return{op:"gt",field:t,value:i,_originalOp:"inFuture"};break}return console.warn(`Operador no implementado: ${e}, usando eq como fallback`),{op:"eq",field:t,value:r}}function cV(e,t,r){const n=Va(e);if(n.validateValue)return n.validateValue(t,r);const a=En(e,t);return a?a.inputType==="none"?{valid:!0}:a.inputType==="single"&&!r&&r!==0&&r!==!1?{valid:!1,message:"El valor no puede estar vacío"}:{valid:!0}:["isEmpty","isNotEmpty","contains","notContains","startsWith","endsWith","matches","isTrue","isFalse","hasAnyValue","hasNoValue","inRange","today","inPast","inFuture"].includes(t)?["isEmpty","isNotEmpty","isTrue","isFalse","hasAnyValue","hasNoValue","today","inPast","inFuture"].includes(t)?{valid:!0}:!r&&r!==0&&r!==!1?{valid:!1,message:"El valor no puede estar vacío"}:{valid:!0}:{valid:!1,message:"Operador no soportado para este tipo de campo"}}function Ar(e){return typeof e=="boolean"?e?"true":"false":typeof e=="number"?String(e):typeof e=="string"?e:e==null?"":String(e)}function Ui(e){if(!e)return"eq";if("_originalOp"in e)return e._originalOp;const t=e.op;if(t==="and"||t==="or")return"_originalOp"in e?e._originalOp:"eq";if(t==="eq"){const r=e.value;if(r==="")return"isEmpty";if(r===!0)return"isTrue";if(r===!1)return"isFalse";if(r===null)return"isEmpty"}if(t==="neq"){const r=e.value;if(r==="")return"isNotEmpty";if(r===null)return"hasAnyValue"}return t}const dV=({value:e,fieldOptions:t,fieldTypes:r,onChange:n,onRemove:a,fieldPickerSuffix:o,disabled:i})=>{const c=Ui(e),d="field"in e?e.field:"",u=r[d]||"text",f=Va(u),h=w=>{if(w.field&&w.field!==d){const x=r[w.field]||"text",E=Va(x).defaultOperator,k=Za(E,w.field,"",x);n(k);return}if(w.op&&w.op!==c){let x="";"value"in e?x=Ar(e.value):"values"in e&&(x=e.values.map(Ar).join(","));try{const y=Za(w.op,d,x,u);n(y)}catch(y){console.error(y)}return}if(w.rawInputValue!==void 0){try{const x=Za(c,d,w.rawInputValue,u);n(x)}catch(x){console.error(x)}return}},p=f.operators.map(w=>({label:w.label,value:w.op}));let m="";"value"in e?m=Ar(e.value):"values"in e&&(m=e.values.map(Ar).join(", "));const v=En(u,c),g=["isEmpty","isNotEmpty","isTrue","isFalse","hasAnyValue","hasNoValue","today","inPast","inFuture"],b=(v==null?void 0:v.inputType)!=="none"&&!g.includes(c);return l.jsxs("div",{className:"flex flex-wrap items-start gap-2 p-2 bg-[var(--color-ds-background-page)] rounded border border-[var(--color-ds-border-default-50)]",children:[l.jsx("div",{className:"flex-1 min-w-[120px]",children:l.jsx(Xe,{value:d,onChange:w=>h({field:w}),options:t,size:"sm",labelHidden:!0,disabled:i})}),l.jsx("div",{className:"w-[140px]",children:l.jsx(Xe,{value:c,onChange:w=>h({op:w}),options:p,size:"sm",labelHidden:!0,disabled:i})}),b&&l.jsx("div",{className:"flex-1 min-w-[120px]",children:l.jsx(je,{size:"sm",value:m,onChange:w=>h({rawInputValue:w.target.value}),reserveErrorSpace:!1,placeholder:"Valor",disabled:i})}),a&&l.jsx("button",{onClick:a,disabled:i,className:"p-1 text-[var(--color-ds-text-secondary)] hover:text-red-500 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:l.jsx(Dt,{className:"w-4 h-4"})})]})},_h=({rule:e,onChange:t,onRemove:r,fieldOptions:n,fieldTypes:a,depth:o=0,disabled:i=!1})=>{var b;const c=e.op==="and",d=()=>{t({...e,op:c?"or":"and"})},u=()=>{var x;const w={op:"eq",field:String(((x=n[0])==null?void 0:x.value)||""),value:""};t({...e,rules:[...e.rules||[],w]})},f=()=>{var x;const w={op:"and",rules:[{op:"eq",field:String(((x=n[0])==null?void 0:x.value)||""),value:""}]};t({...e,rules:[...e.rules||[],w]})},h=(w,x)=>{const y=[...e.rules||[]];y[w]=x,t({...e,rules:y})},p=w=>{const x=[...e.rules||[]];x.splice(w,1),t({...e,rules:x})},m=c?"bg-blue-50 border-r border-blue-200 text-blue-700 hover:bg-blue-100":"bg-orange-50 border-r border-orange-200 text-orange-700 hover:bg-orange-100",v=c?"AND":"OR";return l.jsxs("div",{className:"flex rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm bg-[var(--color-ds-background-page)] overflow-hidden transition-all",children:[l.jsxs("div",{onClick:i?void 0:d,className:`w-10 relative flex flex-col items-center transition-colors rounded-l-lg ${m} ${i?"pointer-events-none opacity-60":""}`,title:i?void 0:"Click para cambiar (Y / O)",children:[l.jsx("div",{className:`absolute top-2 bottom-10 w-0.5 rounded-full ${c?"bg-blue-200":"bg-orange-200"}`}),l.jsx("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-10",children:l.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center text-[10px] font-bold border shadow-sm bg-[var(--color-ds-background-page)] ${c?"border-blue-300":"border-orange-300"}`,children:v})}),r&&l.jsx("button",{onClick:w=>{w.stopPropagation(),r()},disabled:i,className:"absolute bottom-2 z-20 p-1 rounded-full hover:bg-red-100 text-[var(--color-ds-text-secondary)] hover:text-red-500 transition-colors disabled:opacity-50 disabled:cursor-not-allowed bg-[var(--color-ds-background-page)] border border-transparent hover:border-red-200 shadow-sm",title:"Eliminar este grupo",children:l.jsx(Dt,{className:"w-3.5 h-3.5"})})]}),l.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[l.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[(b=e.rules)==null?void 0:b.map((w,x)=>l.jsx("div",{className:"relative group/item",children:l.jsx("div",{className:"",children:"rules"in w?l.jsx(_h,{rule:w,onChange:y=>h(x,y),onRemove:()=>p(x),fieldOptions:n,fieldTypes:a,depth:o+1,disabled:i}):l.jsx(dV,{value:w,onChange:y=>h(x,y),onRemove:()=>p(x),fieldOptions:n,fieldTypes:a,disabled:i})})},x)),(!e.rules||e.rules.length===0)&&l.jsx("div",{className:"text-center py-8 border-2 border-dashed border-[var(--color-ds-border-default-50)] rounded-lg m-1",children:l.jsx("span",{className:"text-xs text-[var(--color-ds-text-secondary)] block mb-2 opacity-70",children:"Grupo vacío"})})]}),l.jsxs("div",{className:"flex items-center gap-2 p-2 bg-[var(--color-ds-background-neutral)]/30 border-t border-[var(--color-ds-border-default-50)]/50",children:[l.jsxs("button",{onClick:u,disabled:i,className:"px-2 py-1 rounded text-xs font-medium text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-surface-hover)] border border-transparent hover:border-[var(--color-ds-border-default-50)] transition-all flex items-center gap-1.5 disabled:opacity-50",children:[l.jsx(hr,{className:"w-3.5 h-3.5 text-[var(--color-ds-text-secondary)]"}),"Añadir Regla"]}),l.jsxs("button",{onClick:f,disabled:i,className:"px-2 py-1 rounded text-xs font-medium text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-surface-hover)] border border-transparent hover:border-[var(--color-ds-border-default-50)] transition-all flex items-center gap-1.5 disabled:opacity-50",children:[l.jsx(Hs,{className:"w-3.5 h-3.5 text-[var(--color-ds-text-secondary)]"}),"Añadir Sub-grupo"]}),l.jsx("div",{className:"flex-1"}),o>0&&l.jsxs("span",{className:"text-[9px] text-[var(--color-ds-text-secondary)] opacity-50 px-2",children:["Nivel ",o+1]})]})]})]})};function uV({value:e,fieldOptions:t,fieldTypes:r,onChange:n,fieldPickerSuffix:a,showHelp:o=!0,disabled:i=!1}){const c=e&&"op"in e&&(e.op==="and"||e.op==="or"),d=e&&"op"in e&&e.op==="always",u=()=>{var p;const h=e&&e.op!=="always"?e:{op:"eq",field:String(((p=t[0])==null?void 0:p.value)||""),value:""};n({op:"and",rules:[h]})},f=h=>{n(h?{op:"always",value:!0}:void 0)};return d?l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"flex items-center gap-4 bg-[var(--color-ds-background-neutral)]/30 p-3 rounded-lg border border-[var(--color-ds-border-default-50)]",children:[l.jsx("span",{className:"text-sm font-medium text-[var(--color-ds-text-primary)]",children:"Modo:"}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>f(!1),disabled:i,className:"px-3 py-1.5 rounded text-xs font-medium bg-[var(--color-ds-background-page)] border border-[var(--color-ds-border-default-50)] text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)] transition-colors",children:"Condicional"}),l.jsx("button",{disabled:!0,className:"px-3 py-1.5 rounded text-xs font-medium bg-amber-100 text-amber-800 border border-amber-200",children:"Siempre Activo"})]})]}),l.jsxs("div",{className:"flex items-center gap-3 p-4 bg-amber-50 border border-amber-100 rounded-lg text-amber-800 text-sm",children:[l.jsx(fn,{className:"w-5 h-5 flex-shrink-0"}),l.jsxs("span",{children:["Esta regla se aplicará ",l.jsx("strong",{children:"SIEMPRE"}),", incondicionalmente."]})]})]}):c?l.jsx("div",{className:"space-y-2",children:l.jsx(_h,{rule:e,onChange:n,fieldOptions:t,fieldTypes:r,depth:0,disabled:i})}):l.jsxs("div",{className:"space-y-3",children:[l.jsx("div",{className:"flex justify-end mb-2",children:l.jsx("button",{onClick:()=>f(!0),className:"text-xs text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-primary-700)] underline decoration-dotted underline-offset-2 transition-colors",disabled:i,children:'Cambiar a "Siempre activo"'})}),l.jsxs("div",{className:"bg-[var(--color-ds-background-neutral)]/20 p-3 rounded-xl border border-[var(--color-ds-border-default-50)] shadow-sm space-y-3 relative group",children:[l.jsx(fV,{value:e,fieldOptions:t,fieldTypes:r,onChange:n,fieldPickerSuffix:a,showHelp:o,disabled:i}),l.jsx("div",{className:"flex justify-end border-t border-[var(--color-ds-border-default-50)]/50 pt-2 mt-2",children:l.jsxs("button",{onClick:u,disabled:i,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium text-[var(--color-ds-primary-700)] hover:bg-[var(--color-ds-primary-50)] transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Permite añadir múltiples condiciones (AND/OR)",children:[l.jsx(Hs,{className:"w-4 h-4"}),"Convertir a Grupo Avanzado"]})})]})]})}function fV({value:e,fieldOptions:t,fieldTypes:r,onChange:n,fieldPickerSuffix:a,showHelp:o=!0,disabled:i=!1}){const[c,d]=C.useState(()=>e&&"field"in e?e.field:""),[u,f]=C.useState(()=>Ui(e)),[h,p]=C.useState(()=>e?"value"in e?Ar(e.value):"values"in e?e.values.map(Ar).join(", "):"":""),m=C.useRef(null),v=C.useRef(!0);C.useEffect(()=>{if(!v.current||(v.current=!1,!e))return;"field"in e&&d(e.field);const B=Ui(e);f(B),"value"in e?p(Ar(e.value)):"values"in e&&p(e.values.map(Ar).join(", "))},[]),C.useEffect(()=>{if(!e||"op"in e&&(e.op==="and"||e.op==="or"))return;"field"in e&&d(e.field);const B=Ui(e);f(B),"value"in e?p(Ar(e.value)):"values"in e&&p(e.values.map(Ar).join(", "))},[e]);const g=C.useMemo(()=>c&&r[c]||"text",[c,r]),b=C.useMemo(()=>Va(g),[g]),w=C.useMemo(()=>b.operators.map(B=>({value:B.op,label:B.label})),[b.operators]),x=C.useMemo(()=>{if(!c)return{valid:!1,message:"Selecciona"};const B=En(g,u);return(B==null?void 0:B.inputType)==="none"?{valid:!0}:cV(g,u,h)},[c,g,u,h]),y=B=>{if(d(B),B){const R=r[B]||"text",I=Va(R);f(I.defaultOperator),p("");try{const F=Za(I.defaultOperator,B,"",R);n(F)}catch(F){console.error("Error:",F)}}else n(void 0)},E=B=>{f(B);const R=En(g,B);(R==null?void 0:R.inputType)==="none"&&p("");try{const I=Za(B,c,h,g);n(I)}catch(I){console.error("Error:",I)}},k=B=>{p(B),m.current&&clearTimeout(m.current),m.current=window.setTimeout(()=>{if(c)try{const R=Za(u,c,B,g);n(R)}catch(R){console.error("Error:",R)}},300)};C.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]);const j=()=>{const B=En(g,u),R=["isEmpty","isNotEmpty","isTrue","isFalse","hasAnyValue","hasNoValue","today","inPast","inFuture"];if((B==null?void 0:B.inputType)==="none"||R.includes(u))return l.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md bg-[var(--color-ds-background-page)] border border-[var(--color-ds-border-default-50)] text-[var(--color-ds-text-secondary)] text-sm",children:[l.jsx(pa,{className:"w-4 h-4"}),l.jsx("span",{className:"text-xs",children:(B==null?void 0:B.description)||"No requiere valor"})]});if((B==null?void 0:B.inputType)==="range"||u==="inRange")return l.jsx(je,{size:"sm",label:"Rango",placeholder:(B==null?void 0:B.placeholder)||"min,max",value:h,onChange:F=>k(F.target.value),reserveErrorSpace:!1,hasError:!x.valid,errorMessage:x.message,disabled:i});if((B==null?void 0:B.inputType)==="multi"||u==="in"||u==="notIn")return l.jsx(je,{size:"sm",label:"Valores",placeholder:(B==null?void 0:B.placeholder)||"valor1, valor2, valor3",value:h,onChange:F=>k(F.target.value),reserveErrorSpace:!1,hasError:!x.valid,errorMessage:x.message,disabled:i});if((B==null?void 0:B.inputType)==="pattern"||u==="matches")return l.jsx(je,{size:"sm",label:"Patrón",placeholder:(B==null?void 0:B.placeholder)||"^patrón$",value:h,onChange:F=>k(F.target.value),reserveErrorSpace:!1,hasError:!x.valid,errorMessage:x.message});let I="text";return g==="number"&&(I="number"),g==="date"&&(I="date"),g==="email"&&(I="email"),g==="url"&&(I="url"),g==="tel"&&(I="tel"),l.jsx(je,{size:"sm",type:I,label:"Valor",placeholder:(B==null?void 0:B.placeholder)||b.defaultPlaceholder||"valor",value:h,onChange:F=>k(F.target.value),reserveErrorSpace:!1,hasError:!x.valid,errorMessage:x.message,disabled:i})},A=()=>c?l.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-mono bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-secondary)] border border-[var(--color-ds-border-default-50)]",children:g}):null,S=()=>{if(!o||!c)return null;const B=En(g,u),R=(B==null?void 0:B.description)||b.helpText;return R?l.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md bg-[color-mix(in_srgb,var(--color-ds-background-accent)_10%,transparent)] border border-[var(--color-ds-border-default-50)]",children:[l.jsx(F1,{className:"w-4 h-4 text-[var(--color-ds-text-secondary)] flex-shrink-0 mt-0.5"}),l.jsx("span",{className:"text-xs text-[var(--color-ds-text-secondary)] leading-relaxed",children:R})]}):null},_=()=>{if(!c)return null;const B=En(g,u),R=["isEmpty","isNotEmpty","isTrue","isFalse","hasAnyValue","hasNoValue","today","inPast","inFuture"];return(B==null?void 0:B.inputType)==="none"||R.includes(u)?null:l.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:x.valid?l.jsxs(l.Fragment,{children:[l.jsx(fn,{className:"w-4 h-4 text-[var(--color-ds-text-primary)]"}),l.jsx("span",{className:"text-[var(--color-ds-text-primary)]",children:"Válido"})]}):l.jsxs(l.Fragment,{children:[l.jsx(Ql,{className:"w-4 h-4 text-[var(--color-ds-text-primary)]"}),l.jsx("span",{className:"text-[var(--color-ds-text-primary)]",children:x.message||"Inválido"})]})})},M=C.useMemo(()=>[{label:"— Campo —",value:""},...t],[t]);return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"grid grid-cols-2 gap-3 items-start",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("span",{className:"text-[10px] uppercase font-bold text-[var(--color-ds-text-secondary)] tracking-wider",children:"Campo"}),A()]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx(Xe,{value:c,onChange:B=>y(B),options:M,size:"sm",coerceFirstValid:!1,reserveErrorSpace:!1,className:"flex-1 w-full",labelHidden:!0,disabled:i}),a&&l.jsx("div",{className:"flex-shrink-0",children:a})]})]}),l.jsxs("div",{className:"space-y-1",children:[l.jsx("span",{className:"text-[10px] uppercase font-bold text-[var(--color-ds-text-secondary)] tracking-wider",children:"Operador"}),c&&w.length>0?l.jsx(Xe,{value:u,onChange:B=>E(B),options:w,size:"sm",coerceFirstValid:!1,reserveErrorSpace:!1,labelHidden:!0,disabled:i}):l.jsx("div",{className:"h-8 w-full bg-[var(--color-ds-background-disabled)] rounded border border-[var(--color-ds-border-muted)] opacity-50"})]})]}),c&&l.jsxs("div",{className:"space-y-2 pt-1 border-t border-[var(--color-ds-border-default-50)]/50",children:[l.jsx("div",{className:"pt-2",children:j()}),S(),l.jsx("div",{className:"flex justify-end",children:_()})]})]})}let Yo={};function Qd(e){Yo={...Yo,...e}}function Cn(e){return Yo[e]}function hV(){const e={};for(const t of Object.values(Yo))e[t.controller]||(e[t.controller]=[]),e[t.controller].push(t);return e}function pV(e){return Object.values(Yo).filter(t=>t.type===e)}const eu=({filterType:e,selectedKey:t,onSelect:r})=>{const[n,a]=C.useState(""),o=C.useMemo(()=>{const u=hV();if(e){const f={};for(const[h,p]of Object.entries(u)){const m=p.filter(v=>v.type===e);m.length>0&&(f[h]=m)}return f}return u},[e]),i=C.useMemo(()=>{if(!n.trim())return o;const u=n.toLowerCase(),f={};for(const[h,p]of Object.entries(o)){const m=p.filter(v=>{var g;return v.name.toLowerCase().includes(u)||v.key.toLowerCase().includes(u)||((g=v.description)==null?void 0:g.toLowerCase().includes(u))||h.toLowerCase().includes(u)});m.length>0&&(f[h]=m)}return f},[o,n]),c=u=>u==="validation"?ic:u==="options"?k1:bo,d=u=>u==="validation"?"var(--color-ds-text-error)":u==="options"?"var(--color-ds-text-info)":"var(--color-ds-text-success)";return l.jsxs("div",{className:"h-full flex flex-col",children:[l.jsx("div",{className:"p-3 border-b border-[var(--color-ds-border-default-50)]",children:l.jsx(je,{size:"sm",placeholder:"Buscar endpoints...",value:n,onChange:u=>a(u.target.value),prefixIcon:bo})}),l.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:Object.keys(i).length===0?l.jsx("div",{className:"text-center py-8 text-[var(--color-ds-text-secondary)] text-sm",children:n.trim()?"No se encontraron endpoints":"No hay endpoints disponibles"}):Object.entries(i).map(([u,f])=>l.jsx(lt,{title:`${u} (${f.length})`,type:"plain",defaultOpen:Object.keys(i).length<=3||n.trim().length>0,children:l.jsx("div",{className:"space-y-1 pt-1",children:f.map(h=>{const p=h.key===t,m=c(h.type);d(h.type);const v=g=>{let b="--comp-text";switch(g==null?void 0:g.toUpperCase()){case"GET":b="--comp-email";break;case"POST":b="--comp-text";break;case"PUT":b="--comp-checkbox";break;case"DELETE":b="--comp-number";break;default:b="--color-ds-text-secondary";break}return{color:`var(${b})`,backgroundColor:`color-mix(in srgb, var(${b}) 10%, transparent)`,borderColor:`color-mix(in srgb, var(${b}) 20%, transparent)`}};return l.jsx("button",{onClick:()=>r(h),className:`
119
119
  w-full text-left px-3 py-2 rounded border
120
120
  transition-all
121
121
  ${p?"bg-[color-mix(in_srgb,var(--color-ds-primary-500)_10%,transparent)] border-[var(--color-ds-border-default)] shadow-sm":"bg-transparent border-transparent hover:bg-[color-mix(in_srgb,var(--color-ds-text-primary)_5%,transparent)] text-[var(--color-ds-text-primary)]"}
@@ -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=ZH();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:dc},{id:"system",label:"Sistema",icon:Jl},{id:"dark",label:"Oscuro",icon:ac}]})]})]})}),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 ku(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 Eu=e=>e.toLowerCase().endsWith(".json")?e:`${e}.json`,Mp=(e,t)=>`${e.replace(/\/+$/,"")}/${t.replace(/^\/+/,"")}`,Rp=()=>l.jsx("div",{className:"w-px h-6 bg-[var(--color-ds-border-default-50)] mx-2"});function qH(){var X;const{t:e,i18n:t}=At(),r=se(O=>O.schema),n=se(O=>O.undo),a=se(O=>O.redo),o=se(O=>O.setSchema),i=se(O=>O.resetHistory),c=se(O=>O.past.length),d=se(O=>O.future.length),u=se(O=>O.selection),f=se(O=>O.removeField),h=se(O=>O.duplicateField),p=se(O=>O.editorSettings),m=se(O=>O.showRelations??!1),v=se(O=>O.toggleRelations),g=se(O=>O.setShowRelations),b=se(O=>O.mode),w=se(O=>O.setMode),[x,y]=C.useState(!1),[E,k]=C.useState(!1),[j,A]=C.useState(!1),[S,_]=C.useState(!1),[M,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=()=>{ku(`${ne}.json`,JSON.stringify(r,null,2)),Y("Esquema exportado como JSON.","success")},Q=()=>{try{const O=vu(r,"validationSchema");ku(`${ne}.validation.ts`,O),Y("Yup exportado como TypeScript.","success")}catch(O){console.error(O),Y("No se pudo generar el Yup.","error")}},he=()=>{try{const O=bu(r,q,t),V=`${ne}.translations.json`;ku(V,JSON.stringify(O,null,2)),Y("Traducciones exportadas como JSON.","success")}catch(O){console.error(O),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 O;return(O=Z.current)==null?void 0:O.click()},ce=()=>{var O;return(O=ee.current)==null?void 0:O.click()},le=O=>{var P;const V=(P=O.target.files)==null?void 0:P[0];if(!V)return;if(!window.confirm("Vas a reemplazar el esquema actual. ¿Continuar?")){O.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),O.currentTarget.value=""},be=async O=>{var P;const V=O.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 MH({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 O=Mp(ae,Eu(`${ne}.json`));await te.write(O,JSON.stringify(r,null,2)),Y(`Guardado rápido en ${O}`,"success")}catch(O){console.error(O),Y("Guardado rápido fallido.","error")}},D=async()=>{try{const O=Eu(`${ne}.json`),V=window.prompt("Guardar como (archivo en baseDir):",O);if(!V)return;const T=Mp(ae,Eu(V));await te.write(T,JSON.stringify(r,null,2)),Y(`Guardado en ${T}`,"success")}catch(O){console.error(O),Y("No se pudo guardar el archivo.","error")}},{config:G,updateConfig:re}=WH({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:D1,onSelect:fe},{label:"Importar JSON...",icon:A1,onSelect:me},{label:"Importar Proyecto (ZIP)...",icon:a1,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 O=(N==null?void 0:N.registry)||{};console.log("Services Registry for Export:",O),PH({schema:r,translationsAdapter:q,i18n:t,servicesRegistry:O,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:f1,size:"sm",onClick:n,disabled:c===0,ariaLabel:`Deshacer (${os(G.undo)})`,title:`Deshacer (${os(G.undo)})`}),l.jsx(Jt,{icon:h1,size:"sm",onClick:a,disabled:d===0,ariaLabel:`Rehacer (${os(G.redo)})`,title:`Rehacer (${os(G.redo)})`}),l.jsx(Rp,{}),l.jsx(EH,{}),l.jsx(Rp,{}),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:O=>w(O),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(UH,{isOpen:x,onClose:()=>y(!1),config:G,onSaveShortcuts:re}),l.jsx(Yz,{open:E,onClose:()=>k(!1)}),l.jsx(rH,{open:j,onClose:()=>A(!1)}),l.jsx(gH,{isOpen:S,onClose:()=>_(!1)}),M&&l.jsx(vH,{isOpen:!0,onClose:()=>B(!1)}),l.jsx(kH,{isOpen:R,onClose:()=>I(!1)})]})}const il="application/x-ds-field-template",Op="application/x-ds-layout-kind";function Cu(e){return e.layout.find(t=>(t==null?void 0:t.type)==="rows")}function GH({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=Cu(r);if(!y)return[];const E=[];return(k=y.sections)==null||k.forEach((j,A)=>{var S;(S=j.rows)==null||S.forEach((_,M)=>{(_.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:M,colIdx:R,insertIdx:ee,key:`s${A}-r${M}-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(Op))&&(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(Op);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,M=(((B=Cu(A).sections[y.sectionIdx].rows[y.rowIdx].columns[y.colIdx].fields)==null?void 0:B.length)??1)-1;y.insertIdx>=0&&y.insertIdx<M&&d({s:y.sectionIdx,r:y.rowIdx,c:y.colIdx,idx:M},{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=Cu(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((_,M)=>{const B=[];(_.columns??[]).forEach((R,I)=>{const F=h.filter(Z=>Z.sectionIdx===A&&Z.rowIdx===M&&Z.colIdx===I);B.push(F)}),E.push({key:`s${A}-r${M}`,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(M=>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(M,B),f(!1)},title:`Insertar en Col ${M.colIdx+1}, posición ${M.insertIdx+1}`,children:_?"Soltar aquí":M.insertIdx===A.length-1?"Añadir al final":"Insertar aquí"},M.key))})})},`${j.key}-c${S}`)})},j.key))})()})]})]})}function KH({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 JH({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 Lp(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 YH(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 XH(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 QH(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=QH(e,XH(d)),h=!!e.suppressAll||f;if(C.useEffect(()=>{if(!a||h)return;const g=YH(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 Tp(e){return se(C.useCallback(t=>{if(e)return t.schema.fields.find(r=>r.name===e)},[e]))}const eW=C.memo(({fieldOrName:e,groupName:t,index:r,onRemove:n,setSelection:a,confirmDelete:o})=>{const i=typeof e=="string"?e:e.name,d=Tp(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]})}),tW=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=Tp(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]),M=C.useMemo(()=>{var Z;return(Z=_==null?void 0:_.overrides)==null?void 0:Z[w]},[_,w]),B=M==null?void 0:M.hidden,R=M==null?void 0:M.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(eW,{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)]})}),rW=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(tW,{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(Lp,{scope:"rows-column",rowsNodeIdx:n,s:a,r:o,c:i,children:E()}):l.jsx(Lp,{scope:"tabs-column",tabKey:d,s:a,r:o,c:i,children:E()})}),ju=({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"})]})})]})},nW=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"),aW=[1,2,3,4],oW=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=nW(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(ju,{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:aW.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((_,M)=>l.jsx(rW,{col:_,widthClass:E[M],nodeIdx:r,sIdx:n,rIdx:a,cIdx:M,parentType:o,tabKey:i,confirmDelete:c},`${o==="rows"?"col":"tcol"}-${r}-${n}-${a}-${M}`))}),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 sW({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 iW({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 $p({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 lW({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 Ip=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($p,{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(lW,{section:t,onChange:g,formId:f,parentType:a,sectionIndex:n,tabKey:o})}),a==="rows"?l.jsx(JH,{nodeIdx:r,sIdx:n}):l.jsx(iW,{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(oW,{row:w,nodeIdx:r,sIdx:n,rIdx:x,parentType:a,tabKey:o,confirmDelete:i},`${a==="rows"?"row":"trow"}-${a==="tabs"?o:r}-${x}`))})]})});function Bp({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 cW({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 dW({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(cW,{className:"text-[var(--color-ds-text-primary)]"}),a?l.jsx(ju,{value:n,onChange:a,className:"max-w-[10rem]",inputClassName:"w-20 text-[11px]"}):l.jsx("span",{className:"truncate max-w-[10rem]",children:n})]})}function uW({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 fW=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($p,{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(Bp,{nodeIdx:r,insertAt:0}),t.tabs.map((y,E)=>l.jsxs(C.Fragment,{children:[l.jsx(dW,{nodeIdx:r,index:E,tabKey:y.key,label:y.label,onRename:k=>h==null?void 0:h(y.key,k)}),l.jsx(Bp,{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(uW,{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(S1,{className:"w-5 h-5"})}),items:[{label:"Añadir Pestaña",icon:lc,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(sW,{nodeIdx:r,tabKey:E.key,insertAt:j})}),A<E.sections.length&&l.jsx(Ip,{section:S,nodeIdx:r,sIdx:A,parentType:"tabs",tabKey:E.key,confirmDelete:a})]},`tsec-${E.key}-${j}`)})]}),y),{})})})]})]})})});function hW(){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(KH,{nodeIdx:p,insertAt:g}),b<m.length&&l.jsx(Ip,{section:w,nodeIdx:p,sIdx:b,parentType:"rows",confirmDelete:d})]},`rows-slot-sec-${p}-${g}`)})},`rows-${p}`)}return h.type==="tabs"?l.jsx(fW,{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 Pp=(e,t,r)=>Math.max(t,Math.min(r,e));function Vp(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 Zp(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 pW(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=Zp(n,{li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx}),o=Zp(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=Pp(r.fieldIdx??d.length,0,d.length);return d.splice(u,0,c),o.fields=d,{...e,layout:n}}function mW(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 gW(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 vW(e,t,r){const n=gW(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=Pp(r.fieldIdx??d.fields.length,0,d.fields.length);return d.fields.splice(u,0,n),{...e,fields:o,layout:i}}const zp=C.createContext(null),Hp=()=>{const e=C.useContext(zp);if(!e)throw new Error("useRelations must be used inside <RelationsProvider>");return e},bW=e=>{const{registerFieldEl:t}=Hp();return C.useCallback(r=>{e&&t(e,r)},[e,t])},wW=({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(()=>lB),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 M=_.getBoundingClientRect();E[S]={x:Math.round(M.left-y.left+M.width/2),y:Math.round(M.top-y.top+M.height/2),w:Math.round(M.width),h:Math.round(M.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],M=k[S];if(!_||!M||_.x!==M.x||_.y!==M.y||_.w!==M.w||_.h!==M.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(zp.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 Du(e){return e!=null&&e.parameters?Object.values(e.parameters).filter(t=>t.type==="field"&&t.fieldRef).map(t=>t.fieldRef):[]}function xW(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 Du(g))t.push({from:x,to:h,kind:"visibleWhen"});for(const x of Du(b))t.push({from:x,to:h,kind:"disabledWhen"});for(const x of Du(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 Su={visibleWhen:"var(--color-success-500, #22c55e)",disabledWhen:"var(--color-warning-500, #f59e0b)",clearWhen:"var(--color-info-500, #0ea5e9)"};function Wp(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 Up(e,t,r=20,n=0){const a=Wp(e),o=Wp(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 yW=({enabled:e=!0,anchors:t,schema:r})=>{const n=C.useMemo(()=>r?xW(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=Su[x];let E=1;b?E=1:a?E=w?.4:.15:d&&(E=w?1:.2);const k=Up(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})},M=h.length,B=3,R=h.map((I,F)=>(F-(M-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=Su[I.kind],{d:ee}=Up(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=Su[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 qp(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(qp(e.name,e.style)),qp(e.name,e.style)}function kW(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,M=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:M,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 M=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(ud,{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,M)}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(cd,{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,M)}const B=j.suffixButton,R=typeof B=="string"?E(B):B,I=m(j.label),F=g&&v&&j.name?l.jsx(ju,{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,M)}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),M)}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(hd,{...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),M)}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,M)}case"file":{const N=l.jsx(Jc,{...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,M)}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,M)}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,M)}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,M)}case"toggle":{const N=l.jsx(gd,{...Z,checked:j.defaultValue??!1,errorMessage:m((ae=a[j.name])==null?void 0:ae.message),name:j.name},j.name);return y(N,M)}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(af,{columns:N,loadData:ne,idAccessor:j.idAccessor||"id",className:j.className},j.name);return y(K,M)}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,M)}}}}function EW(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 CW(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 jW({id:e,children:t,onDelete:r,fieldName:n,chromeDisabled:a=!1}){const{attributes:o,listeners:i,setNodeRef:c,transform:d,transition:u,isDragging:f}=Xh({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;EW(w)||CW(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 DW(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)}),DW(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 Gp(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 SW(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 AW(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 AW(n)?n:null}function Au(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:Au(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 NW({name:e,children:t}){const r=bW(e);return l.jsx("div",{ref:r,"data-field":e,style:{position:"relative"},children:t})}function Kp(e){return e.startsWith("row|")?Object.fromEntries(e.slice(4).split(";").map(r=>r.split(":"))):{}}function FW(e,t){const r=Kp(e),n=Kp(t);return r.ctx===n.ctx&&r.li===n.li&&r.s===n.s&&(r.t??"")===(n.t??"")}function Jp(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 _W(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 MW(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 RW(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 OW({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 LW(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 Yp({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 TW({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?ld(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?ld(oe,d):""},[a,d]),h=C.useMemo(()=>kW(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}=Hp();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),M=C.useRef(null),B=C.useRef(null),R=U=>{M.current==null&&(M.current=requestAnimationFrame(()=>{M.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)=>Vp({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)=>Vp({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=Id(Ba(Uo,{activationConstraint:{distance:6}}),Ba(Wo,{coordinateGetter:Qh})),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=SB(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&&Au(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(FW(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}=_W(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,M.current&&(cancelAnimationFrame(M.current),M.current=null),B.current=null},onDragEnd:()=>{he(!1),me(null),le(null),fe(40),D(null),j(null),_.current=null,M.current&&(cancelAnimationFrame(M.current),M.current=null),B.current=null}}),MW(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=SW(ft),Fe=vW(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=Jp(Re,N)}else Ie=Jp(Ce,N);const Le=pW(e,ke,Ie);re(null),j(null),t(Le)},[e,t,N,G]);function O(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=RW(U),we=O(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(OW,{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(Jh,{items:we,strategy:qh,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=LW(e,Me);if(!_e)return l.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0},`${U}-miss-${Fe}`);const Te=Au(_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(jW,{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=mW(e,ht);t($r)})},chromeDisabled:g,children:l.jsx(NW,{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(Yp,{ctx:{kind:"rows",li:J,sectionIdx:de,rowIdx:we},visible:!!ke&&!g}),l.jsx(Gp,{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(Yp,{ctx:{kind:"tabs",li:J,tabKey:ge.key,tabIdx:we,sectionIdx:ke,rowIdx:Le},visible:!!Re&&!g}),l.jsx(Gp,{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(wc,{...r.methods,children:[l.jsxs(Xd,{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(yW,{schema:e,anchors:w,enabled:b})]}),l.jsx(oh,{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 $W(e,t,r,n){var k;const{fields:a=[],layout:o,validationSchema:i}=e,c=IW(),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??id(e);return Yc(j)}catch{return}},[t,e,i]),h=$c({resolver:f,mode:"onBlur",reValidateMode:"onChange",defaultValues:e.defaultValues??{}}),p=C.useMemo(()=>(a??[]).filter(j=>j.type!=="inputGroup"&&j.type!=="button"),[a]),{optionsMap:m}=W2(p),v=Z2(a),g=U2(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(M=>M.type==="select"&&(M.optionSource||M.endpointConfig)).map(async M=>{const B=M.name,R=li(M.optionSource,M.endpointConfig);if(!R)return[B,[]];const I=M.endpointConfig?bn(M.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[M,B]of S)_[M]=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 IW(){try{return Zt()??void 0}catch{return}}function BW(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 PW=e=>{let{transform:t,draggingNodeRect:r,windowRect:n}=e;return!r||!n?t:BW(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 VW(e){if(!e)return null;const t=e.data;if(t.kind==="palette-field"){const r=t.factoryKind,n=tV[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(S1,{className:"w-5 h-5"})}),items:[{label:"Añadir Pestaña",icon:lc,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(sW,{nodeIdx:r,tabKey:E.key,insertAt:j})}),A<E.sections.length&&l.jsx(Ip,{section:S,nodeIdx:r,sIdx:A,parentType:"tabs",tabKey:E.key,confirmDelete:a})]},`tsec-${E.key}-${j}`)})]}),y),{})})})]})]})})});function hW(){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(KH,{nodeIdx:p,insertAt:g}),b<m.length&&l.jsx(Ip,{section:w,nodeIdx:p,sIdx:b,parentType:"rows",confirmDelete:d})]},`rows-slot-sec-${p}-${g}`)})},`rows-${p}`)}return h.type==="tabs"?l.jsx(fW,{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 Pp=(e,t,r)=>Math.max(t,Math.min(r,e));function Vp(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 Zp(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 pW(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=Zp(n,{li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx}),o=Zp(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=Pp(r.fieldIdx??d.length,0,d.length);return d.splice(u,0,c),o.fields=d,{...e,layout:n}}function mW(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 gW(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 vW(e,t,r){const n=gW(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=Pp(r.fieldIdx??d.fields.length,0,d.fields.length);return d.fields.splice(u,0,n),{...e,fields:o,layout:i}}const zp=C.createContext(null),Hp=()=>{const e=C.useContext(zp);if(!e)throw new Error("useRelations must be used inside <RelationsProvider>");return e},bW=e=>{const{registerFieldEl:t}=Hp();return C.useCallback(r=>{e&&t(e,r)},[e,t])},wW=({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(()=>lB),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 M=_.getBoundingClientRect();E[S]={x:Math.round(M.left-y.left+M.width/2),y:Math.round(M.top-y.top+M.height/2),w:Math.round(M.width),h:Math.round(M.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],M=k[S];if(!_||!M||_.x!==M.x||_.y!==M.y||_.w!==M.w||_.h!==M.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(zp.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 Du(e){return e!=null&&e.parameters?Object.values(e.parameters).filter(t=>t.type==="field"&&t.fieldRef).map(t=>t.fieldRef):[]}function xW(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 Du(g))t.push({from:x,to:h,kind:"visibleWhen"});for(const x of Du(b))t.push({from:x,to:h,kind:"disabledWhen"});for(const x of Du(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 Su={visibleWhen:"var(--color-success-500, #22c55e)",disabledWhen:"var(--color-warning-500, #f59e0b)",clearWhen:"var(--color-info-500, #0ea5e9)"};function Wp(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 Up(e,t,r=20,n=0){const a=Wp(e),o=Wp(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 yW=({enabled:e=!0,anchors:t,schema:r})=>{const n=C.useMemo(()=>r?xW(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=Su[x];let E=1;b?E=1:a?E=w?.4:.15:d&&(E=w?1:.2);const k=Up(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})},M=h.length,B=3,R=h.map((I,F)=>(F-(M-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=Su[I.kind],{d:ee}=Up(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=Su[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 qp(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(qp(e.name,e.style)),qp(e.name,e.style)}function kW(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,M=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:M,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 M=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(ud,{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,M)}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(cd,{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,M)}const B=j.suffixButton,R=typeof B=="string"?E(B):B,I=m(j.label),F=g&&v&&j.name?l.jsx(ju,{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,M)}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),M)}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(hd,{...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),M)}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,M)}case"file":{const N=l.jsx(Jc,{...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,M)}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,M)}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,M)}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,M)}case"toggle":{const N=l.jsx(gd,{...Z,checked:j.defaultValue??!1,errorMessage:m((ae=a[j.name])==null?void 0:ae.message),name:j.name},j.name);return y(N,M)}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(af,{columns:N,loadData:ne,idAccessor:j.idAccessor||"id",className:j.className},j.name);return y(K,M)}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,M)}}}}function EW(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 CW(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 jW({id:e,children:t,onDelete:r,fieldName:n,chromeDisabled:a=!1}){const{attributes:o,listeners:i,setNodeRef:c,transform:d,transition:u,isDragging:f}=Xh({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;EW(w)||CW(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 DW(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)}),DW(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 Gp(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 SW(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 AW(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 AW(n)?n:null}function Au(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:Au(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 NW({name:e,children:t}){const r=bW(e);return l.jsx("div",{ref:r,"data-field":e,style:{position:"relative"},children:t})}function Kp(e){return e.startsWith("row|")?Object.fromEntries(e.slice(4).split(";").map(r=>r.split(":"))):{}}function FW(e,t){const r=Kp(e),n=Kp(t);return r.ctx===n.ctx&&r.li===n.li&&r.s===n.s&&(r.t??"")===(n.t??"")}function Jp(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 _W(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 MW(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 RW(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 OW({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 LW(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 Yp({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 TW({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?ld(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?ld(oe,d):""},[a,d]),h=C.useMemo(()=>kW(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}=Hp();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),M=C.useRef(null),B=C.useRef(null),R=U=>{M.current==null&&(M.current=requestAnimationFrame(()=>{M.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)=>Vp({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)=>Vp({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=Id(Ba(Uo,{activationConstraint:{distance:6}}),Ba(Wo,{coordinateGetter:Qh})),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=SB(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&&Au(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(FW(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}=_W(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,M.current&&(cancelAnimationFrame(M.current),M.current=null),B.current=null},onDragEnd:()=>{he(!1),me(null),le(null),fe(40),D(null),j(null),_.current=null,M.current&&(cancelAnimationFrame(M.current),M.current=null),B.current=null}}),MW(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=SW(ft),Fe=vW(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=Jp(Re,N)}else Ie=Jp(Ce,N);const Le=pW(e,ke,Ie);re(null),j(null),t(Le)},[e,t,N,G]);function O(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=RW(U),we=O(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(OW,{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(Jh,{items:we,strategy:qh,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=LW(e,Me);if(!_e)return l.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0},`${U}-miss-${Fe}`);const Te=Au(_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(jW,{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=mW(e,ht);t($r)})},chromeDisabled:g,children:l.jsx(NW,{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(Yp,{ctx:{kind:"rows",li:J,sectionIdx:de,rowIdx:we},visible:!!ke&&!g}),l.jsx(Gp,{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(Yp,{ctx:{kind:"tabs",li:J,tabKey:ge.key,tabIdx:we,sectionIdx:ke,rowIdx:Le},visible:!!Re&&!g}),l.jsx(Gp,{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(wc,{...r.methods,children:[l.jsxs(Xd,{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(yW,{schema:e,anchors:w,enabled:b})]}),l.jsx(oh,{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 $W(e,t,r,n){var k;const{fields:a=[],layout:o,validationSchema:i}=e,c=IW(),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??id(e);return Yc(j)}catch{return}},[t,e,i]),h=$c({resolver:f,mode:"onBlur",reValidateMode:"onChange",defaultValues:e.defaultValues??{}}),p=C.useMemo(()=>(a??[]).filter(j=>j.type!=="inputGroup"&&j.type!=="button"),[a]),{optionsMap:m}=W2(p),v=Z2(a),g=U2(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(M=>M.type==="select"&&(M.optionSource||M.endpointConfig)).map(async M=>{const B=M.name,R=li(M.optionSource,M.endpointConfig);if(!R)return[B,[]];const I=M.endpointConfig?bn(M.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[M,B]of S)_[M]=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 IW(){try{return Zt()??void 0}catch{return}}function BW(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 PW=e=>{let{transform:t,draggingNodeRect:r,windowRect:n}=e;return!r||!n?t:BW(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 VW(e){if(!e)return null;const t=e.data;if(t.kind==="palette-field"){const r=t.factoryKind,n=tV[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