@ainelo/form-engine 1.0.3

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.js ADDED
@@ -0,0 +1,42 @@
1
+ 'use strict';var Me=require('react'),jsxRuntime=require('react/jsx-runtime'),zustand=require('zustand'),middleware=require('zustand/middleware'),zod$1=require('zod'),zod=require('@hookform/resolvers/zod'),reactHookForm=require('react-hook-form'),ze=require('react-hot-toast'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),lt=require('@radix-ui/react-switch'),Wt=require('@radix-ui/react-label'),dt=require('@radix-ui/react-checkbox'),xe=require('@radix-ui/react-popover'),reactDom=require('react-dom'),j=require('@radix-ui/react-select'),Ae=require('@radix-ui/react-radio-group'),react=require('@tiptap/react'),Wa=require('@tiptap/starter-kit'),qa=require('@tiptap/extension-image'),ja=require('@tiptap/extension-link'),Ka=require('@tiptap/extension-placeholder');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var Me__namespace=/*#__PURE__*/_interopNamespace(Me);var ze__default=/*#__PURE__*/_interopDefault(ze);var lt__namespace=/*#__PURE__*/_interopNamespace(lt);var Wt__namespace=/*#__PURE__*/_interopNamespace(Wt);var dt__namespace=/*#__PURE__*/_interopNamespace(dt);var xe__namespace=/*#__PURE__*/_interopNamespace(xe);var j__namespace=/*#__PURE__*/_interopNamespace(j);var Ae__namespace=/*#__PURE__*/_interopNamespace(Ae);var Wa__default=/*#__PURE__*/_interopDefault(Wa);var qa__default=/*#__PURE__*/_interopDefault(qa);var ja__default=/*#__PURE__*/_interopDefault(ja);var Ka__default=/*#__PURE__*/_interopDefault(Ka);function yt(e){return e===void 0?[]:Array.isArray(e)?e:[e]}function Se(e,t){return wr(t,e.conditionalDisplay)}function Ge(e,t){return wr(t,e.conditionalDisplay)}function wr(e,t){return t?Zn(t,e):true}function Zn(e,t){let r=yt(e.rules).map(i=>{let{fieldName:a,formFieldId:l,value:s,operator:d,numeric_compare_to:p,typeComputation:c}=i,u=yt(a).length>0?yt(a):yt(l);if(u.length===0)return false;let m=u.map(F=>t[F]?.responseValue).filter(F=>F!==void 0);if(m.length===0)return false;let x=m[0]||null;return m.length>1&&c&&(c==="SOMME"?x=m.map(T=>He(T)).reduce((T,y)=>T+y,0):c==="MULTIPLICATION"&&(x=m.map(T=>He(T)).reduce((T,y)=>T*y,1))),Qn(x,d,s,p)});return e.logic==="AND"?r.every(Boolean):r.some(Boolean)}function He(e){if(typeof e=="number")return e;if(typeof e=="string"){let t=parseFloat(e);return isNaN(t)?0:t}return typeof e=="boolean"?e?1:0:Array.isArray(e)?e.length:0}function Qn(e,t,o,r){if(!t)return true;switch(t){case "==":{let n=String(e),i=String(o);return n===i}case "!=":{let n=String(e),i=String(o);return n!==i}case ">":{let n=He(e),i=r??He(o);return n>i}case "<":{let n=He(e),i=r??He(o);return n<i}case "IN":return Array.isArray(o)?o.some(i=>String(i)===String(e)):false;case "NOT IN":return Array.isArray(o)?!o.some(i=>String(i)===String(e)):false;case "CONTAINS":return Array.isArray(e)?e.some(i=>String(i)===String(o)):false;case "NOT CONTAINS":return Array.isArray(e)?!e.some(i=>String(i)===String(o)):false;default:return false}}function Rr(e){return e.sections.flatMap(t=>t.formFields??[])}function es(e){switch(e.fieldType){case "text":case "textarea":case "radio":case "dropdown":case "number":return "";case "checkbox":return [];case "date":return null;default:return ""}}function Pr(e,t){let o={...e},r={};Object.entries(e).forEach(([n,i])=>{r[n]={responseValue:i};});for(let n of t)for(let i of n.formFields)!Se(i,r)&&o[i.fieldName]===void 0&&(o[i.fieldName]=es(i));return o}function ge(e){return e.formFields?.some(t=>t.fieldType==="OTP")??false}function $e(e){return e.formFields?.find(t=>t.fieldType==="OTP")}function Sr(e,t){let o={...e};for(let r of t)for(let n of r.formFields||[])if(n.fieldType==="OTP"){let i=n.fieldName,a=o[i];if(n.flattenOnSubmit===false)continue;a!=null&&typeof a=="object"&&!Array.isArray(a)&&(Object.entries(a).forEach(([l,s])=>{o[l]=s;}),delete o[i]);}return o}function vt(e,t){for(let o=0;o<t.length;o++)if(t[o].formFields?.find(i=>i.fieldName===e))return o;return -1}function Ft(e,t,o){if(!e.otpFormFieldExecOptions?.linkedEmailFieldName)return;let r=e.otpFormFieldExecOptions.linkedEmailFieldName;for(let n=0;n<o;n++){let a=t[n].formFields?.find(l=>l.fieldName===r);if(a&&a.validations?.some(s=>s.validationType==="email"))return a}}function Cr(e,t,o){if(!e.emailFormFieldExecOptions?.linkedOTPFieldName)return;let r=e.emailFormFieldExecOptions.linkedOTPFieldName;for(let n=o+1;n<t.length;n++){let a=t[n].formFields?.find(l=>l.fieldName===r&&l.fieldType==="OTP");if(a)return a}}var Er=({form:e,fieldsPerPage:t=4,paginationMode:o="byFields",sectionVisibility:r,pageVisibility:n})=>{let[i,a]=Me.useState(0),[l,s]=Me.useState(0),d=Me.useRef(0),p=o,c=e.sections[i],u=c?.formFields||[],m=Me.useMemo(()=>c?ge(c):false,[c]),x=Me.useMemo(()=>r&&r.length>0?r.filter(b=>b).length||1:e.sections.length,[r,e.sections.length]),g=Me.useMemo(()=>{if(r&&r.length>0){let b=0;for(let N=0;N<=i&&N<r.length;N++)r[N]&&(b+=1);return Math.max(1,b)}return i+1},[r,i]),F=m?1:Math.ceil(u.length/t),T=m?u:u.slice(l*t,(l+1)*t),y=m?0:l,v=Me.useMemo(()=>n&&n.length>0?n.reduce((b,N)=>b+N.filter(f=>f>0).length,0)||1:e.sections.reduce((b,N)=>b+Math.ceil((N.formFields?.length||0)/t),0),[n,e.sections,t]),k=Me.useMemo(()=>{if(n&&n.length>0){let N=0;for(let f=0;f<n.length;f++){let h=n[f]||[],C=h.filter(M=>M>0);if(f<i)N+=C.length;else if(f===i){for(let M=0;M<=y&&M<h.length;M++)h[M]>0&&(N+=1);return Math.max(1,N)}}return 1}let b=0;for(let N=0;N<i;N++){let f=e.sections[N];(f?ge(f):false)?b+=1:b+=Math.ceil((f?.formFields?.length||0)/t);}return b+=y+1,b},[n,i,y,e.sections,t]),P=Me.useMemo(()=>{let b=i===0&&y===0,N=i===e.sections.length-1&&y===F-1;return {isFirstSection:b,isLastSection:N,totalSteps:v,currentStep:k,fadeKey:i*1e4+d.current*1e3+y,isOTPSection:m}},[i,y,e.sections,F,t,m,v,k]);if(p==="bySection"){let b=u,N=x,f=g,h=i===0,C=i===e.sections.length-1,M=()=>{i>0&&(d.current+=1,a(i-1));},S=()=>{i<e.sections.length-1&&(d.current+=1,a(i+1));},w=()=>{d.current+=1,a(0);},D=()=>{d.current+=1;let z=e.sections.length-1;a(z);},$=(z,ne=0)=>{z>=0&&z<e.sections.length&&(z!==i&&(d.current+=1),a(z));},G=()=>{if(r&&r.length>0){for(let z=i-1;z>=0;z--)if(r[z]){$(z,0);return}}else M();},_=()=>{if(r&&r.length>0){for(let z=i+1;z<r.length;z++)if(r[z]){$(z,0);return}}else S();};return {sectionIndex:i,fieldPage:0,currentSection:c,pagedFields:b,isFirstSection:h,isLastSection:C,totalSteps:N,currentStep:f,totalVisibleSteps:x,currentVisibleStep:g,fadeKey:i*1e4+d.current*1e3,goToPrevious:M,goToNext:S,goToPreviousVisible:G,goToNextVisible:_,goToFirst:w,goToLast:D,goToStep:$,sectionVisibility:r,pageVisibility:n,debugInfo:{sectionCount:e.sections.length,totalFieldPages:1,fieldsOnCurrentPage:b.length}}}let R=()=>{if(m){if(i>0){d.current+=1,a(i-1);let b=e.sections[i-1];if(b){let N=ge(b);s(N?0:Math.ceil((b.formFields?.length||0)/t)-1);}}}else if(l>0)s(l-1);else if(i>0){let b=e.sections[i-1];if(b){a(i-1);let N=b.formFields||[],f=ge(b);s(f?0:Math.ceil(N.length/t)-1);}}},I=()=>{m?i<e.sections.length-1&&(d.current+=1,a(i+1),s(0)):l<F-1?s(l+1):i<e.sections.length-1&&(d.current+=1,a(i+1),s(0));},O=()=>{d.current+=1,a(0),s(0);},V=()=>{d.current+=1;let b=e.sections.length-1;a(b);let N=e.sections[b];if(N){let f=N.formFields||[],h=Math.ceil(f.length/t)-1;s(Math.max(0,h));}},E=(b,N=0)=>{if(b>=0&&b<e.sections.length){b!==i&&(d.current+=1),a(b);let f=e.sections[b];if(f)if(ge(f))s(0);else {let C=f.formFields||[],M=Math.ceil(C.length/t)-1;s(Math.max(0,Math.min(N,M)));}}};return {sectionIndex:i,fieldPage:y,currentSection:c,pagedFields:T,...P,totalVisibleSteps:v,currentVisibleStep:k,goToPrevious:R,goToNext:I,goToPreviousVisible:()=>{if(o==="bySection")if(r&&r.length>0){for(let N=i-1;N>=0;N--)if(r[N]){E(N,0);return}}else R();else if(n&&n.length>0){let N=n[i]||[];for(let f=y-1;f>=0;f--)if(N[f]>0){E(i,f);return}for(let f=i-1;f>=0;f--){let h=n[f]||[];for(let C=h.length-1;C>=0;C--)if(h[C]>0){E(f,C);return}}}else R();},goToNextVisible:()=>{if(o==="bySection")if(r&&r.length>0){for(let N=i+1;N<r.length;N++)if(r[N]){E(N,0);return}}else I();else if(n&&n.length>0){let N=n[i]||[];for(let f=y+1;f<N.length;f++)if(N[f]>0){E(i,f);return}for(let f=i+1;f<n.length;f++){let h=n[f]||[];for(let C=0;C<h.length;C++)if(h[C]>0){E(f,C);return}}}else I();},goToFirst:O,goToLast:V,goToStep:E,sectionVisibility:r,pageVisibility:n,debugInfo:{sectionCount:e.sections.length,totalFieldPages:F,fieldsOnCurrentPage:T.length}}};var it="#008080";function os(e){let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:null}function Or(e){let t=os(e);if(!t)return {"--fe-primary":it,"--fe-primary-light":"#e6f7f7","--fe-primary-dark":"#006666"};let[o,r,n]=t,i=`rgb(${Math.round(o+(255-o)*.9)},${Math.round(r+(255-r)*.9)},${Math.round(n+(255-n)*.9)})`,a=`rgb(${Math.round(o*.75)},${Math.round(r*.75)},${Math.round(n*.75)})`;return {"--fe-primary":e,"--fe-primary-light":i,"--fe-primary-dark":a}}var ns=Me__namespace.default.createContext({primaryColor:it});var Dr=({primaryColor:e=it,children:t})=>jsxRuntime.jsx(ns.Provider,{value:{primaryColor:e},children:t});function qe(e,t){let o={},r=new Set,n=i=>{r.add(i);for(let a of Object.keys(e))(a===i||a.startsWith(`${i}_`))&&r.add(a);};for(let i of t)for(let a of i.formFields){let l=a.repeatGroup;if(l){let s=e[l.fieldName];Array.isArray(s)?o[l.fieldName]=s.map(d=>{if(!d||typeof d!="object")return d;let p={};for(let c of l.formFields){let u=d[c.fieldName];if(c.repeatGroup){let m=c.repeatGroup.fieldName,x=d[m];Array.isArray(x)&&(p[m]=x.map(g=>{if(!g||typeof g!="object")return g;let F={};return c.repeatGroup.formFields.forEach(T=>{g[T.fieldName]!==void 0&&(F[T.fieldName]=g[T.fieldName]);}),F}),n(m)),u!==void 0&&(p[c.fieldName]=u);}else u!==void 0&&(p[c.fieldName]=u);}return p}):o[l.fieldName]=[],n(l.fieldName);continue}!r.has(a.fieldName)&&e[a.fieldName]!==void 0&&(o[a.fieldName]=e[a.fieldName],r.add(a.fieldName));}for(let[i,a]of Object.entries(e))r.has(i)||(o[i]=a);return o}var pe=zustand.create()(middleware.persist((e,t)=>({forms:{},setFormValue:(o,r,n)=>e(i=>({forms:{...i.forms,[o]:{...i.forms[o],[r]:n}}})),setAllFormValues:(o,r)=>e(n=>({forms:{...n.forms,[o]:r}})),getFormValues:o=>t().forms[o]||{},clearForm:o=>e(r=>{let n={...r.forms};return delete n[o],{forms:n}}),clearAll:()=>e({forms:{}})}),{name:"multi-form-drafts"})),Ir=(e,t)=>{let o=pe(),r=o.getFormValues(e),n=Me.useCallback(i=>{let a=qe(i,t);o.setAllFormValues(e,a);},[e,t]);return {savedValues:r,syncFormData:n}};var Vr=e=>{let t={};return e.forEach(o=>{let r;switch(o.fieldType){case "text":case "dropdown":case "radio":r=zod$1.z.string();break;case "textarea":r=zod$1.z.string();break;case "date":r=zod$1.z.string().refine(i=>!isNaN(Date.parse(i)),{message:"Date invalide"});break;case "number":r=zod$1.z.coerce.number();break;case "bool":r=zod$1.z.boolean();break;case "checkbox":r=zod$1.z.array(zod$1.z.string()).optional();break;case "file":r=zod$1.z.union([zod$1.z.instanceof(File),zod$1.z.array(zod$1.z.instanceof(File)),zod$1.z.null(),zod$1.z.undefined()]);break;default:r=zod$1.z.string();}o.validations?.forEach(i=>{let a;switch(i.errMsg?a=i.errMsg:i.validationType?a=ds(i.validationType,i.value):a="Unknown validation error",i.validationType){case "required":o.fieldType==="text"||o.fieldType==="textarea"||o.fieldType==="dropdown"||o.fieldType==="radio"?r=r.min(1,a):o.fieldType==="checkbox"?r=zod$1.z.array(zod$1.z.string()).min(1,a):o.fieldType==="bool"?r=r.refine(l=>l===true,{message:a}):o.fieldType==="number"?r=r.refine(l=>l!=null,{message:a}):o.fieldType==="file"&&(r=r.refine(l=>l instanceof File?true:Array.isArray(l)?l.length>0&&l.every(s=>s instanceof File):l&&typeof l.length=="number"?l.length>0:false,{message:a}));break;case "minLength":r instanceof zod$1.z.ZodString&&(r=r.min(i.value,a));break;case "maxLength":r instanceof zod$1.z.ZodString&&(r=r.max(i.value,a));break;case "regex":r instanceof zod$1.z.ZodString&&(r=r.regex(new RegExp(i.value),a));break;case "email":r instanceof zod$1.z.ZodString&&(r=r.email(a));break;case "number":r=zod$1.z.coerce.number().refine(l=>!isNaN(l),{message:a});break;case "phone_number":r instanceof zod$1.z.ZodString&&(r=r.regex(/^\+?[1-9]\d{1,14}$/,a));break;case "fileSize":case "fileType":if(r instanceof zod$1.z.ZodType)if(i.validationType==="fileSize"){let l=Number(i.value),s=d=>d==null||d===""?true:Array.isArray(d)?d.every(p=>s(p)):d instanceof File?d.size<=l:true;r=r.refine(s,a);}else {let l=Array.isArray(i.value)?i.value:[],s=l.map(u=>{if(!u)return null;let m=u.toLowerCase();return m.includes("/")?m.split("/").pop()??null:m.startsWith(".")?m.slice(1):m}).filter(u=>!!u),d=u=>l.length===0?true:u?l.includes(u):false,p=u=>{if(l.length===0)return true;if(!u)return false;let m=u.toLowerCase(),x=m,g=null;try{let T=new URL(m);x=T.pathname.toLowerCase(),g=T.searchParams.get("filename")??T.searchParams.get("file")??T.searchParams.get("file_name")??null;}catch{x=m;}let F=g?g.toLowerCase():null;return s.some(T=>!!(x.endsWith(`.${T}`)||F&&F.endsWith(`.${T}`)))},c=u=>u==null||u===""?true:Array.isArray(u)?u.every(m=>c(m)):u instanceof File?d(u.type):typeof u=="string"?p(u)||l.length===0:true;r=r.refine(c,a);}break}}),o.validations?.some(i=>i.validationType==="required")||(r=r.optional()),t[o.fieldName]=r;}),zod$1.z.object(t)};function ds(e,t){switch(e){case "required":return "Ce champ est obligatoire";case "minLength":return `Minimum ${t} caract\xE8res`;case "maxLength":return `Maximum ${t} caract\xE8res`;case "regex":return "Format invalide";case "email":return "Email invalide";case "number":return "Nombre invalide";case "fileSize":return "Fichier trop volumineux";case "fileType":return "Type de fichier non autoris\xE9";case "phone_number":return "Num\xE9ro de t\xE9l\xE9phone invalide";default:return "Valeur invalide"}}var je=zustand.create()(middleware.persist((e,t)=>({tokens:{},setOTPToken:(o,r,n)=>e(i=>({tokens:{...i.tokens,[o]:{...i.tokens[o],[r]:n}}})),getOTPToken:(o,r)=>t().tokens[o]?.[r],clearOTPToken:(o,r)=>e(n=>{let i=n.tokens[o];if(!i)return n;let{[r]:a,...l}=i;return {tokens:{...n.tokens,[o]:l}}}),clearAllOTPTokens:o=>e(r=>{if(o){let{[o]:n,...i}=r.tokens;return {tokens:i}}return {tokens:{}}})}),{name:"otp-auth-tokens"}));var ps=(e,t,o,r)=>({handleClearAll:Me.useCallback(()=>{try{let i=Object.fromEntries(t.map(a=>[a.fieldName,""]));e.reset(i),localStorage.removeItem(`form_${o}`),pe.getState().clearForm(o),je.getState().clearAllOTPTokens(o),setTimeout(()=>{r.goToFirst();},0),ze__default.default.success("Toutes les donn\xE9es ont \xE9t\xE9 supprim\xE9es ! \u{1F5D1}\uFE0F",{duration:3e3,position:"top-center",style:{background:"#10b981",color:"white",fontWeight:"bold"},icon:"\u2705"}),console.log("\u2705 Form cleared successfully:",o);}catch(i){console.error("\u274C Error clearing form:",i),ze__default.default.error("Erreur lors de la suppression des donn\xE9es",{duration:3e3,position:"top-center",style:{background:"#ef4444",color:"white",fontWeight:"bold"},icon:"\u274C"});}},[e,t,o,r])}),Ar=ps;var fs=(e,t)=>{let o=e.replace(/\/+$/,"");if(/^https?:\/\//i.test(t))return t;let r=t.replace(/^\/+/,"");return `${o}/${r}`},gs=(e,t,o,r,n=4)=>{if(r==="bySection")return e<o.sections.length-1?e+1:-1;let a=o.sections[e].formFields?.length||0,l=Math.ceil(a/n);return t<l-1?e:e<o.sections.length-1?e+1:-1},hs=async(e,t,o)=>{let r=e.otpFormFieldExecOptions;if(!r)throw new Error("OTP options are not configured for this field");let n=r.sendOTPApiConfig??{serverDns:r.serverDns,postApiEndPoint:r.postApiEndPoint,payload:r.payload,extraHeaders:r.extraHeaders,bearer:r.bearer},i=vt(e.fieldName,o),a=Ft(e,o,i);if(!a)throw new Error(`Linked field not found for OTP field: ${e.fieldName}`);if(!t[a.fieldName])throw new Error(`Le champ li\xE9 "${a.fieldName}" est vide`);let s=fs(n.serverDns,n.postApiEndPoint),p={...n.payload??{},...t},c={"Content-Type":"application/json",...n.extraHeaders??{}};n.bearer&&(c.Authorization=`Bearer ${n.bearer}`);let u=new AbortController,m=r.timeoutMs||15e3,x=fetch(s,{method:"POST",headers:c,body:JSON.stringify(p),signal:u.signal}),g=setTimeout(()=>u.abort(),m);try{let F=await x;clearTimeout(g);let T=null;try{T=await F.json();}catch{let v=await F.text();throw new Error(`R\xE9ponse OTP invalide: ${v}`)}if(!F.ok){let v=T?.message||`OTP request failed with status ${F.status} ${F.statusText}`;throw new Error(v)}if(T?.success===!1&&F.status!==200)throw new Error(T?.message||"\xC9chec de l'envoi du code OTP")}catch(F){throw clearTimeout(g),F.name==="AbortError"?new Error("D\xE9lai d'attente d\xE9pass\xE9 pour la requ\xEAte OTP"):F}},bs=(e,t,o,r,n,i,a,l=4)=>({handleNext:async()=>{r(true);try{let d=await t();if(d.invalidFields&&d.invalidFields.length>0){d.invalidFields.forEach(u=>{u.errors.forEach(m=>{ze__default.default.error(`${u.fieldLabel} : ${m}`);});});return}if(d.emptyRequiredFields&&d.emptyRequiredFields.length>0){d.emptyRequiredFields.forEach(u=>{ze__default.default.error(`${u.fieldLabel} : ${u.errors[0]}`);});return}if(d.untouchedRequiredFields&&d.untouchedRequiredFields.length>0){d.untouchedRequiredFields.forEach(u=>{ze__default.default.error(`${u.fieldLabel} : ${u.errors[0]}`);});return}let p=n.sections[e.sectionIndex];if(p&&ge(p)){let u=$e(p);if(u){let m=i[u.fieldName],x=u.otpFormFieldExecOptions?.otpLength??6;if(u.validations?.some(F=>F.validationType==="required")&&(!m||typeof m!="string"||m.length!==x)){ze__default.default.error(`\u26A0\uFE0F Veuillez remplir et valider le code OTP avant de continuer. Le code doit contenir ${x} chiffres.`);return}}}let c=gs(e.sectionIndex,e.fieldPage,n,a,l);if(c!==-1){let u=n.sections[c];if(ge(u)){let m=$e(u);if(m)try{await hs(m,i,n.sections),ze__default.default.success("Code de v\xE9rification envoy\xE9 !");}catch(x){let g=x instanceof Error?x.message:"Erreur lors de l'envoi du code OTP";ze__default.default.error(g);return}}}e.goToNextVisible?e.goToNextVisible():e.goToNext(),ze__default.default.success(`Super section suivante ! \u{1F389} (${d.requiredFieldsCount}/${d.visibleFieldsCount} champs requis)`);}finally{r(false);}}}),Lr=bs;var $r=()=>{let{trigger:e,formState:t}=reactHookForm.useFormContext();return {validateFields:async r=>{let n=r.map(i=>i.fieldName);if(n.length===0)return true;try{let i=await e(n);return i||console.log("Validation \xE9chou\xE9e, erreurs:",t.errors),i}catch(i){return console.error("Erreur lors de la validation:",i),false}},formState:t}};var vs=({tooltipContent:e="",helpTextContent:t="",children:o,position:r="top",className:n=""})=>{let[i,a]=Me.useState(false),[l]=Me.useState(()=>`tooltip-${Math.random().toString(36).substr(2,9)}`);if(!(e.trim()||t.trim()))return jsxRuntime.jsx(jsxRuntime.Fragment,{children:o});let d={top:"bottom-full left-1/2 transform -translate-x-1/2 mb-3",bottom:"top-full left-1/2 transform -translate-x-1/2 mt-3",left:"right-full top-1/2 transform -translate-y-1/2 mr-3",right:"left-full top-1/2 transform -translate-y-1/2 ml-3"},p={top:"top-full left-1/2 transform -translate-x-1/2 border-t-slate-800 border-t-[8px] border-l-transparent border-r-transparent border-l-[8px] border-r-[8px]",bottom:"bottom-full left-1/2 transform -translate-x-1/2 border-b-slate-800 border-b-[8px] border-l-transparent border-r-transparent border-l-[8px] border-r-[8px]",left:"left-full top-1/2 transform -translate-y-1/2 border-l-slate-800 border-l-[8px] border-t-transparent border-b-transparent border-t-[8px] border-b-[8px]",right:"right-full top-1/2 transform -translate-y-1/2 border-r-slate-800 border-r-[8px] border-t-transparent border-b-transparent border-t-[8px] border-b-[8px]"};return jsxRuntime.jsxs("div",{className:`relative inline-block ${n}`,onMouseEnter:()=>a(true),onMouseLeave:()=>a(false),onFocus:()=>a(true),onBlur:()=>a(false),children:[o,i&&jsxRuntime.jsxs("div",{id:l,role:"tooltip",className:`absolute z-50 px-4 py-3 text-sm font-medium text-white bg-slate-500 rounded-xl shadow-2xl max-w-2xl min-w-80 backdrop-blur-sm border border-slate-700 ${d[r]}`,style:{animation:"tooltipFadeIn 0.25s cubic-bezier(0.4, 0, 0.2, 1)",lineHeight:"1.5",wordWrap:"break-word",hyphens:"auto"},children:[jsxRuntime.jsx("div",{className:"relative space-y-2",children:jsxRuntime.jsxs("ul",{className:"list-disc list-inside space-y-1",children:[e&&jsxRuntime.jsx("li",{children:e}),t&&jsxRuntime.jsx("li",{children:t})]})}),jsxRuntime.jsx("div",{className:`absolute w-0 h-0 ${p[r]}`})]}),jsxRuntime.jsx("style",{children:`
2
+ @keyframes tooltipFadeIn {
3
+ from {
4
+ opacity: 0;
5
+ transform: translateY(8px) scale(0.95);
6
+ }
7
+ to {
8
+ opacity: 1;
9
+ transform: translateY(0) scale(1);
10
+ }
11
+ }
12
+ `})]})},Br=vs;var U=(e,t="fr")=>e?typeof e=="string"?e:e[t]||e.fr||e.en||Object.values(e)[0]||"":"";var Tt=e=>{if(!e)return [];if(Array.isArray(e))return e.flatMap(t=>Tt(t)).filter(Boolean);if(typeof e=="object"&&e!==null){if(typeof e.message=="string"&&e.message.trim())return [e.message];if(e.type&&typeof e.type=="string")return [e.type]}return typeof e=="string"&&e.trim()?[e]:[]},W=({field:e,currentLang:t="fr",showLabel:o=true,children:r,tooltipPosition:n="right"})=>{let i=e.validations?.some(g=>g.validationType==="required"),{formState:a,getFieldState:l}=reactHookForm.useFormContext();function s(g,F){if(!(!g||!F))return F.split(".").reduce((T,y)=>{if(T)return Array.isArray(T)?T[Number(y)]:T[y]},g)}let d=e.fieldName?.toString()??"",p=s(a.errors,d),c=l(d,a),u=Tt(p),m=u.length>0&&(c.isTouched&&c.invalid||a.isSubmitted||a.submitCount>0),x=U(e.tooltip,t);return jsxRuntime.jsxs("div",{className:"mb-4",children:[o&&jsxRuntime.jsxs("div",{className:"flex items-center mb-2",children:[(x||e.helpText)&&jsxRuntime.jsx(Br,{tooltipContent:x,helpTextContent:e.helpText?U(e.helpText,t):"",position:n,className:"ml-2",children:jsxRuntime.jsx(lucideReact.MessageCircle,{size:16,className:"text-gray-400 hover:text-gray-600 cursor-help transition-colors duration-200",tabIndex:0,"aria-label":"Information suppl\xE9mentaire"})}),jsxRuntime.jsxs("label",{className:"block text-sm font-medium text-gray-700",children:[U(e.label,t),i&&jsxRuntime.jsx(lucideReact.AlertCircle,{size:12,className:"inline text-red-500 ml-1"})]})]}),r,m&&u.map((g,F)=>jsxRuntime.jsx("p",{className:"text-sm text-red-500 mt-1",children:typeof g=="string"&&g.trim()?g:"Champ invalide"},F)),e.example&&jsxRuntime.jsxs("p",{className:"text-sm text-gray-300 mt-1 font-light italic",children:["Exemple: ",U(e.example,t)]})]})};var Rs=(e,t,o="fr",r="byFields")=>{let[n,i]=Me.useState(false),{validateFields:a}=$r();return {validatePage:async()=>{i(true);try{let d=t.getValues(),p={};Object.entries(d).forEach(([b,N])=>{p[b]={responseValue:N};});let c=e.pagedFields||[],u=e.currentSection,m=r==="bySection"?`Section ${e.sectionIndex+1}`:`Section ${e.sectionIndex+1}, Page ${e.fieldPage+1}`,x=u?ge(u):!1,g=x&&u?$e(u):void 0;if(x&&g){let b=d[g.fieldName],N=g.otpFormFieldExecOptions?.otpLength??6;if(!b||typeof b!="string"||b.length!==N){let f=U(g.label,o);return {isValid:!1,touched:!0,allRequiredFieldsFilled:!1,visibleFieldsCount:1,emptyRequiredFields:[{fieldName:g.fieldName,fieldLabel:f,errors:[`Le code OTP doit contenir ${N} chiffres`]}],invalidFields:[],untouchedRequiredFields:[],requiredFieldsCount:1}}return {isValid:!0,touched:!0,allRequiredFieldsFilled:!0,visibleFieldsCount:1,emptyRequiredFields:[],invalidFields:[],untouchedRequiredFields:[],requiredFieldsCount:1}}let F=c.filter(b=>{let N=Ge(u,p),f=Se(b,p),h=N&&f;return h}),T=F.filter(b=>b.repeatGroup).flatMap(b=>{let N=b.repeatGroup,f=d[N.fieldName]?.length??0,h=[];for(let C=0;C<f;C++)for(let M of N.formFields){let S={...M,fieldName:`${N.fieldName}_${M.fieldName}_${C}`};Se(S,p)&&h.push(S);}return h}),y=[...F,...T],v=await a(y),k=new Map(y.map(b=>[b.fieldName,b])),P=y.filter(b=>{let N=b.validations?.some(f=>f.validationType==="required");return N}),R=P.every(b=>{let N=!!t.formState.touchedFields?.[b.fieldName];return N||console.warn(`[Non touch\xE9] Champ requis non touch\xE9: ${b.fieldName}`),N}),I=P.every(b=>{let N=d[b.fieldName],f=Array.isArray(N)?N.length>0:N!=null&&N!=="";return f||console.warn(`[Non rempli] Champ requis vide: ${b.fieldName} \u2192`,N),f}),O=y.every(b=>!!t.formState.touchedFields?.[b.fieldName]),V=[];t.formState.errors&&Object.entries(t.formState.errors).forEach(([b,N])=>{let f=k.get(b);if(f&&N){let h=Tt(N);h.length>0&&V.push({fieldName:b,fieldLabel:U(f.label,o),errors:h});}});let E=[];P.forEach(b=>{t.formState.touchedFields?.[b.fieldName]||E.push({fieldName:b.fieldName,fieldLabel:U(b.label,o),errors:["Champ requis non rempli"]});});let A=[];return P.forEach(b=>{let N=d[b.fieldName];(Array.isArray(N)?N.length>0:N!=null&&N!=="")||A.push({fieldName:b.fieldName,fieldLabel:U(b.label,o),errors:["Champ requis"]});}),{isValid:v&&I,touched:R,allRequiredFieldsFilled:I,visibleFieldsCount:y.length,requiredFieldsCount:P.length,currentStep:m,sectionIndex:e.sectionIndex,fieldPage:e.fieldPage,allFieldsTouched:O,fieldNames:y.map(b=>b.fieldName),invalidFields:V,untouchedRequiredFields:E,emptyRequiredFields:A}}catch(d){return console.error("Erreur lors de la validation de la page:",d),{isValid:false,touched:false,allRequiredFieldsFilled:false,visibleFieldsCount:0,requiredFieldsCount:0,invalidFields:[],untouchedRequiredFields:[],emptyRequiredFields:[]}}finally{i(false);}},isValidating:n,setIsValidating:i}},_r=Rs;var Ps=(e,t,o,r,n)=>({handleSubmitWithValidation:async()=>{n(true);try{let a=await o();if(a.invalidFields&&a.invalidFields.length>0){a.invalidFields.forEach(c=>{c.errors.forEach(u=>{ze__default.default.error(`${c.fieldLabel} : ${u}`);});});return}if(a.emptyRequiredFields&&a.emptyRequiredFields.length>0){a.emptyRequiredFields.forEach(c=>{ze__default.default.error(`${c.fieldLabel} : ${c.errors[0]}`);});return}if(a.untouchedRequiredFields&&a.untouchedRequiredFields.length>0){a.untouchedRequiredFields.forEach(c=>{ze__default.default.error(`${c.fieldLabel} : ${c.errors[0]}`);});return}let l=e.getValues(),s=Pr(l,t.sections),d=Sr(s,t.sections),p=qe(d,t.sections);r(p),ze__default.default.success(`Formulaire soumis avec succ\xE8s ! \u{1F389} (${a.requiredFieldsCount} champs requis trait\xE9s)`);}finally{n(false);}}}),Ur=Ps;var jr=e=>{let{watch:t,setValue:o,getValues:r}=reactHookForm.useFormContext(),[n,i]=Me.useState(e),a=Me.useRef({}),l=Me.useCallback(c=>e.filter(u=>u.dynamicFilterRule?.dependentFieldName===c),[e]),s=Me.useCallback((c,u)=>{l(c).forEach(x=>{u[x.fieldName]&&o(x.fieldName,"",{shouldValidate:false}),s(x.fieldName,u);});},[l,o]),d=Me.useCallback((c,u)=>{if(!c.dynamicFilterRule||c.fieldType!=="dropdown")return c;let{dependentFieldName:m,dataSource:x}=c.dynamicFilterRule,g=u[m];if(!g||!x.data[g])return {...c,selectOptions:[]};let F=x.data[g];return {...c,selectOptions:F}},[]),p=Me.useCallback((c,u)=>c.map(m=>d(m,u)),[d]);return Me.useEffect(()=>{let c=t();a.current={...c};let u=t((m,{name:x})=>{requestAnimationFrame(()=>{setTimeout(()=>{let g=r(),F=p(e,g);if(i(F),x){let T=e.find(k=>k.fieldName===x),y=a.current[x],v=g[x];T&&!T.dynamicFilterRule&&y!==v&&(!v||y!=null&&y!=="")&&setTimeout(()=>{s(x,g);},0),a.current={...g};}},10);});});return ()=>u.unsubscribe()},[t,r,e,p,s]),n},Kr=(e,t,o=0)=>{let{watch:r,setValue:n,getValues:i}=reactHookForm.useFormContext(),[a,l]=Me.useState(e),s=Me.useRef({}),d=Me.useCallback((g,F,T,y)=>{let v=`${t}_${F}_${T}`,k=y?y():null;return k?k[v]:r(v)},[t,r]),p=Me.useCallback((g,F)=>`${t}_${g}_${F}`,[t]),c=Me.useCallback(g=>e.filter(F=>F.dynamicFilterRule?.dependentFieldName===g),[e]),u=Me.useCallback((g,F)=>{c(g).forEach(y=>{let v=p(y.fieldName,o);F[v]&&n(v,"",{shouldValidate:false}),u(y.fieldName,F);});},[c,n,p,o]),m=Me.useCallback((g,F,T,y)=>{if(!g.dynamicFilterRule||g.fieldType!=="dropdown")return g;let{dependentFieldName:v,dataSource:k}=g.dynamicFilterRule,P=d(F,v,T,y),R=P?String(P).trim().toLowerCase():"",I=P&&k.data[P],O=P;if(!I&&R&&(O=Object.keys(k.data||{}).find(A=>A.toLowerCase()===R)||P),!P||P===""||!k.data[O])return {...g,selectOptions:[]};let V=O,E=k.data[V];return Array.isArray(E)?{...g,selectOptions:E}:(console.error("\u274C [RepeatGroupDynamicFiltering] Les options filtr\xE9es ne sont pas un tableau:",{fieldName:g.fieldName,dependentValue:P,finalKey:V,filteredOptions:E,type:typeof E}),{...g,selectOptions:[]})},[d,t]),x=Me.useCallback((g,F,T,y)=>g.map(v=>m(v,F,T,y)),[m]);return Me.useEffect(()=>{let g=r();s.current={...g};let F=r((T,{name:y})=>{Object.keys(T).filter(P=>P.startsWith(`${t}_`)&&P.endsWith(`_${o}`)).reduce((P,R)=>(P[R]=T[R],P),{});if(requestAnimationFrame(()=>{setTimeout(()=>{let P=i(),R=x(e,T,o,()=>P);l(R);},10);}),y&&y.startsWith(`${t}_`)&&y.endsWith(`_${o}`)){let R=y.replace(`${t}_`,"").replace(`_${o}`,""),I=e.find(E=>E.fieldName===R),O=s.current[y],V=T[y];I&&!I.dynamicFilterRule&&O!==V&&(!V||O!=null&&O!=="")&&setTimeout(()=>{u(R,T);},0),s.current={...s.current,[y]:V};}});return ()=>F.unsubscribe()},[r,i,e,t,o,x,u,d,p]),a};var Es=({formId:e,sections:t})=>{let{watch:o}=reactHookForm.useFormContext(),r=pe(i=>i.setAllFormValues),n=Me.useCallback(i=>{let a=qe(i,t);r(e,a);},[e,t,r]);return Me.useEffect(()=>{let i=o(n);return ()=>i.unsubscribe()},[o,n]),null},Jr=Es;var Xr=Me.forwardRef(({children:e,className:t,...o},r)=>jsxRuntime.jsx("p",{ref:r,className:t,...o,children:e}));Xr.displayName="PContent";var Ce=Xr;var Yr=({currentStep:e,totalSteps:t})=>{let o=e/t*100;return jsxRuntime.jsxs("div",{className:"mt-4 w-full max-w-4xl mb-4",children:[jsxRuntime.jsx("div",{className:"h-2 bg-gray-200 rounded-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"h-full bg-secondary transition-all duration-500",style:{width:`${o}%`}})}),jsxRuntime.jsxs(Ce,{className:"text-right font-semibold text-xs text-gray-500 mt-1",children:["\xC9tape ",e," / ",t]})]})},Is=({currentStep:e,totalSteps:t})=>{let o=e/t*100;return jsxRuntime.jsx("div",{className:"mt-4 w-full max-w-4xl mb-4",children:jsxRuntime.jsx("div",{className:"h-2 bg-gray-200 rounded-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"h-full bg-secondary transition-all duration-500",style:{width:`${o}%`}})})})},Vs=({currentStep:e,totalSteps:t})=>jsxRuntime.jsxs("div",{className:"mt-4 w-full max-w-4xl mb-4",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-1.5",children:Array.from({length:t},(o,r)=>{let n=r+1,i=n<e,a=n===e;return jsxRuntime.jsx("div",{className:`
13
+ flex-1 h-3 rounded-full transition-all duration-500
14
+ ${i?"bg-pink-300":a?"bg-pink-400 ring-2 ring-pink-200 ring-offset-1":"bg-pink-100"}
15
+ `,style:{minWidth:"20px"}},n)})}),jsxRuntime.jsxs(Ce,{className:"text-right font-semibold text-xs text-pink-600 mt-1",children:["\xC9tape ",e," / ",t]})]}),Ms=({currentStep:e,totalSteps:t,colors:o})=>{let r=e/t*100,n=o?.background||"#e5e7eb",i=o?.foreground||"#008080";return jsxRuntime.jsxs("div",{className:"mt-4 w-full max-w-4xl mb-4",children:[jsxRuntime.jsx("div",{className:"h-2 rounded-full overflow-hidden",style:{backgroundColor:n},children:jsxRuntime.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${r}%`,backgroundColor:i}})}),jsxRuntime.jsxs(Ce,{className:"text-right font-semibold text-xs text-gray-500 mt-1",children:["\xC9tape ",e," / ",t]})]})},As=({sections:e,sectionVisibility:t,currentSectionIndex:o})=>{let r=e.map((l,s)=>({section:l,originalIndex:s})).filter(({originalIndex:l})=>!t||t[l]),n=r.map(l=>l.section),i=r.findIndex(({originalIndex:l})=>l===o),a=i>=0?i:0;return jsxRuntime.jsxs("div",{className:"mt-4 w-full max-w-4xl mb-4",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-center",children:n.map((l,s)=>{let d=s<a,p=s===a;return jsxRuntime.jsx(Me__namespace.default.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx("div",{className:`
16
+ w-10 h-10 rounded-full flex items-center justify-center font-semibold text-sm
17
+ transition-all duration-300 z-10 relative
18
+ ${d?"bg-secondary text-white":p?"border-4 border-secondary bg-white text-secondary":"border-2 border-gray-300 bg-white text-gray-400"}
19
+ `,children:s+1}),s<n.length-1&&jsxRuntime.jsx("div",{className:`
20
+ h-1 w-16 transition-all duration-500 -mx-1
21
+ ${s<a?"bg-secondary":"bg-gray-200"}
22
+ `})]})},l.sectionId||s)})}),jsxRuntime.jsxs(Ce,{className:"text-center font-semibold text-xs text-gray-500 mt-2",children:["Section ",a+1," / ",n.length]})]})},Ls=({sections:e,sectionVisibility:t,currentSectionIndex:o})=>{let r=e.map((l,s)=>({section:l,originalIndex:s})).filter(({originalIndex:l})=>!t||t[l]),n=r.map(l=>l.section),i=r.findIndex(({originalIndex:l})=>l===o),a=i>=0?i:0;return jsxRuntime.jsxs("div",{className:"mt-4 w-full max-w-4xl mb-4",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-center",children:n.map((l,s)=>{let d=s<a,p=s===a;return jsxRuntime.jsx(Me__namespace.default.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx("div",{className:`
23
+ w-10 h-10 rounded-full flex items-center justify-center font-semibold text-sm
24
+ transition-all duration-300 z-10 relative
25
+ ${d?"bg-pink-300 text-white":p?"border-4 border-pink-400 bg-white text-pink-400":"border-2 border-pink-200 bg-white text-pink-300"}
26
+ `,children:s+1}),s<n.length-1&&jsxRuntime.jsx("div",{className:`
27
+ h-1 w-16 transition-all duration-500 -mx-1
28
+ ${s<a?"bg-pink-300":"bg-pink-100"}
29
+ `})]})},l.sectionId||s)})}),jsxRuntime.jsxs(Ce,{className:"text-center font-semibold text-xs text-pink-600 mt-2",children:["Section ",a+1," / ",n.length]})]})},$s=({currentStep:e,totalSteps:t,progressBarType:o,sections:r,sectionVisibility:n,currentSectionIndex:i})=>{let a=o?.visible!==false,l=o?.type||"default_step",s=(l==="section_bubble"||l==="section_bubble_pastel")&&(!r||r.length===0||i===void 0)?"default_step":l;if(!a)return jsxRuntime.jsx("div",{style:{display:"none"}});switch(s){case "default_step":return jsxRuntime.jsx(Yr,{currentStep:e,totalSteps:t});case "linear":return jsxRuntime.jsx(Is,{currentStep:e,totalSteps:t});case "pastel":return jsxRuntime.jsx(Vs,{currentStep:e,totalSteps:t});case "custom":return jsxRuntime.jsx(Ms,{currentStep:e,totalSteps:t,colors:o?.colors});case "section_bubble":return jsxRuntime.jsx(As,{sections:r,sectionVisibility:n,currentSectionIndex:i});case "section_bubble_pastel":return jsxRuntime.jsx(Ls,{sections:r,sectionVisibility:n,currentSectionIndex:i});default:return jsxRuntime.jsx(Yr,{currentStep:e,totalSteps:t})}},Qr=$s;var zs=({form:e,currentLang:t,headerOptions:o})=>o?.visible===false?null:o?.type==="custom"&&o?.customHeader?jsxRuntime.jsx(jsxRuntime.Fragment,{children:o.customHeader}):jsxRuntime.jsxs("div",{className:"mb-8 p-6 text-white rounded-lg shadow-lg w-full max-w-4xl",style:{backgroundColor:"var(--fe-primary)"},children:[jsxRuntime.jsx("h1",{className:"text-3xl font-bold mb-2",children:U(e.name,t)}),jsxRuntime.jsx("p",{className:"text-white/80 mb-2",children:U(e.description,t)}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-4 text-sm",children:[jsxRuntime.jsxs("span",{className:"bg-white bg-opacity-20 px-2 py-1 rounded",children:["Fournisseur: ",e.provider]}),jsxRuntime.jsxs("span",{className:"bg-white bg-opacity-20 px-2 py-1 rounded",children:["Statut: ",e.status]}),e.version&&jsxRuntime.jsxs("span",{className:"bg-white bg-opacity-20 px-2 py-1 rounded",children:["Version: ",e.version]})]})]}),eo=zs;function B(...e){return tailwindMerge.twMerge(clsx.clsx(e))}var to=120,ro=320,Gs=233,Ws=2560;function Xe(){let[e,t]=Me.useState(120),[o,r]=Me.useState(36),[n,i]=Me.useState(16),[a,l]=Me.useState(false),[s,d]=Me.useState(false),[p,c]=Me.useState(false);return Me.useEffect(()=>{let x=()=>{let g=window.innerWidth,F=(Gs-to)/(Ws-ro),T=to-F*ro,y=F*g+T,v=y*.3;t(y),r(v),i(v*.45454545454545453),c(g<1024);};return x(),window.addEventListener("resize",x),()=>window.removeEventListener("resize",x)},[]),{width:e,height:o,borderRadius:n,pressed:a,isHovered:s,isMobile:p,transform:a?"scale(0.95)":s&&!p?"scale(1.02)":"scale(1)",handlers:{onMouseDown:()=>l(true),onMouseUp:()=>l(false),onMouseEnter:()=>d(true),onMouseLeave:()=>{l(false),d(false);},onTouchStart:()=>p&&l(true),onTouchEnd:()=>p&&l(false)}}}var qs=({children:e,className:t,onClick:o,...r})=>{let{width:n,height:i,borderRadius:a,pressed:l,isMobile:s,transform:d,handlers:p}=Xe(),c=jsxRuntime.jsx("span",{className:"inline-flex items-center justify-center gap-2 text-white font-medium text-sm",children:e});return jsxRuntime.jsx("button",{style:{width:`${n}px`,height:`${i}px`,borderRadius:`${a}px`,backgroundColor:"var(--fe-primary)",transform:d,transition:"transform 0.2s ease, opacity 0.15s ease",userSelect:"none",WebkitTapHighlightColor:"transparent"},className:B("inline-flex items-center justify-center px-6","text-sm font-medium whitespace-nowrap","shadow-sm","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--fe-primary)] focus-visible:ring-offset-2","disabled:pointer-events-none disabled:opacity-50","cursor-pointer overflow-hidden relative group","hover:opacity-90",t),...p,onClick:o,...r,children:jsxRuntime.jsxs("span",{className:"relative overflow-hidden w-full h-full flex items-center justify-center",children:[jsxRuntime.jsx("span",{className:B("flex items-center justify-center transition-transform duration-300 w-full h-full",!s&&"group-hover:translate-x-full"),style:s?{transform:l?"translateX(100%)":"translateX(0)"}:{},children:c}),jsxRuntime.jsx("span",{className:B("flex items-center justify-center absolute top-0 w-full h-full transition-transform duration-300",!s&&"group-hover:translate-x-[100%]"),style:{left:"-100%",...s?{transform:l?"translateX(100%)":"translateX(0)"}:{}},children:c})]})})},le=qs;var Js=({content:e,children:t})=>{let[o,r]=Me.useState(false);return e.trim()?jsxRuntime.jsxs("div",{className:"relative inline-block",onMouseEnter:()=>r(true),onMouseLeave:()=>r(false),onFocus:()=>r(true),onBlur:()=>r(false),children:[t,o&&jsxRuntime.jsxs("div",{role:"tooltip",className:"absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-3 py-1.5 text-xs font-medium text-white bg-gray-900 rounded-md shadow-lg whitespace-nowrap",style:{animation:"fadeIn 0.15s ease-out"},children:[e,jsxRuntime.jsx("div",{className:"absolute top-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-t-4 border-t-gray-900 border-l-4 border-l-transparent border-r-4 border-r-transparent"})]}),jsxRuntime.jsx("style",{children:`
30
+ @keyframes fadeIn {
31
+ from {
32
+ opacity: 0;
33
+ transform: translate(-50%, 4px) scale(0.96);
34
+ }
35
+ to {
36
+ opacity: 1;
37
+ transform: translate(-50%, 0) scale(1);
38
+ }
39
+ }
40
+ `})]}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:t})},Pt=Js;var Gt=Me__namespace.forwardRef(({className:e,...t},o)=>jsxRuntime.jsx(lt__namespace.Root,{className:B("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--fe-primary)] focus-visible:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50","data-[state=unchecked]:bg-slate-200 data-[state=checked]:bg-[var(--fe-primary)]",e),...t,ref:o,children:jsxRuntime.jsx(lt__namespace.Thumb,{className:B("pointer-events-none block h-5 w-5 rounded-full bg-white shadow-md ring-0 transition-transform","data-[state=unchecked]:translate-x-0 data-[state=checked]:translate-x-5")})}));Gt.displayName=lt__namespace.Root.displayName;var Be=Me__namespace.forwardRef(({className:e,...t},o)=>jsxRuntime.jsx(Wt__namespace.Root,{ref:o,className:B("text-sm font-medium leading-none text-slate-700","peer-disabled:cursor-not-allowed peer-disabled:opacity-70",e),...t}));Be.displayName=Wt__namespace.Root.displayName;var Qs=({field:e,name:t,currentLang:o="fr",className:r=""})=>{let{setValue:n,watch:i}=reactHookForm.useFormContext(),a=t??e.fieldName.toString(),l=U(e.label,o),s=e.validations?.some(c=>c.validationType==="required"),d=!!i(a),p=`switch-${a}`;return jsxRuntime.jsx(W,{field:e,currentLang:o,showLabel:false,children:jsxRuntime.jsxs("div",{className:`flex items-center justify-between rounded-lg border border-slate-200 bg-white px-4 py-3 transition-colors ${d?"border-teal-200 bg-teal-50/30":""} ${r}`,children:[jsxRuntime.jsxs(Be,{htmlFor:p,className:"cursor-pointer font-medium text-slate-700 flex-1 pr-4",children:[l,s&&jsxRuntime.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),jsxRuntime.jsx(Gt,{id:p,checked:d,onCheckedChange:c=>n(a,c,{shouldValidate:true,shouldTouch:true})})]})})},lo=Qs;var Kt=Me__namespace.forwardRef(({className:e,...t},o)=>jsxRuntime.jsx(dt__namespace.Root,{ref:o,className:B("peer h-4 w-4 shrink-0 rounded-sm border border-slate-300 bg-white","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--fe-primary)] focus-visible:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50","data-[state=checked]:bg-[var(--fe-primary)] data-[state=checked]:border-[var(--fe-primary)] data-[state=checked]:text-white",e),...t,children:jsxRuntime.jsx(dt__namespace.Indicator,{className:"flex items-center justify-center text-current",children:jsxRuntime.jsx(lucideReact.Check,{className:"h-3 w-3 stroke-[3]"})})}));Kt.displayName=dt__namespace.Root.displayName;var ri=({field:e,name:t,currentLang:o="fr",className:r})=>{let{watch:n,setValue:i}=reactHookForm.useFormContext(),a=t??e.fieldName.toString(),l=n(a)||[],s=(d,p)=>{let c=p?[...l,d]:l.filter(u=>u!==d);i(a,c,{shouldValidate:true,shouldTouch:true});};return jsxRuntime.jsx(W,{field:e,currentLang:o,children:jsxRuntime.jsx("div",{className:`flex flex-col gap-2 ${r||""}`,children:e.selectOptions?.map((d,p)=>{let c=`${a}-${d.value}-${p}`,u=l.includes(d.value);return jsxRuntime.jsxs("div",{className:"flex items-center gap-2 rounded px-2 py-1 hover:bg-teal-50 transition-colors",children:[jsxRuntime.jsx(Kt,{id:c,checked:u,onCheckedChange:m=>s(d.value,!!m)}),jsxRuntime.jsx(Be,{htmlFor:c,className:"cursor-pointer font-medium text-slate-700",children:U(d.label,o)})]},d.value)})})})},uo=ri;var fo=xe__namespace.Root,go=xe__namespace.Trigger;var Jt=Me__namespace.forwardRef(({className:e,align:t="start",sideOffset:o=4,...r},n)=>jsxRuntime.jsx(xe__namespace.Portal,{children:jsxRuntime.jsx(xe__namespace.Content,{ref:n,align:t,sideOffset:o,className:B("z-50 w-auto rounded-md border border-slate-200 bg-white p-0 shadow-md outline-none","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2",e),...r})}));Jt.displayName=xe__namespace.Content.displayName;var ii=["Janvier","F\xE9vrier","Mars","Avril","Mai","Juin","Juillet","Ao\xFBt","Septembre","Octobre","Novembre","D\xE9cembre"],ai=["January","February","March","April","May","June","July","August","September","October","November","December"],li=["Dim","Lun","Mar","Mer","Jeu","Ven","Sam"],di=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function ci(e){let t=e.getFullYear(),o=e.getMonth(),r=new Date(t,o,1),n=new Date(r);n.setDate(n.getDate()-r.getDay());let i=[];for(let a=0;a<42;a++){let l=new Date(n);l.setDate(n.getDate()+a),i.push(l);}return i}var bo=({value:e,onChange:t,currentLang:o="fr",className:r})=>{let[n,i]=Me__namespace.useState(e??new Date),a=o==="fr"?ii:ai,l=o==="fr"?li:di,s=o==="fr"?"Aujourd'hui":"Today",d=m=>{i(x=>{let g=new Date(x);return g.setMonth(x.getMonth()+(m==="next"?1:-1)),g});},c=new Date().toDateString(),u=e?.toDateString();return jsxRuntime.jsxs("div",{className:B("w-72 select-none",r),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-[var(--fe-primary-light)] border-b border-slate-100",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>d("prev"),className:"p-1.5 rounded-md hover:bg-white/70 transition-colors text-[var(--fe-primary-dark)]",children:jsxRuntime.jsx(lucideReact.ChevronLeft,{className:"h-4 w-4"})}),jsxRuntime.jsxs("span",{className:"text-sm font-semibold text-[var(--fe-primary-dark)]",children:[a[n.getMonth()]," ",n.getFullYear()]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>d("next"),className:"p-1.5 rounded-md hover:bg-white/70 transition-colors text-[var(--fe-primary-dark)]",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4"})})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-7 bg-slate-50 border-b border-slate-100",children:l.map(m=>jsxRuntime.jsx("div",{className:"py-2 text-center text-xs font-medium text-slate-500",children:m},m))}),jsxRuntime.jsx("div",{className:"grid grid-cols-7 p-2 gap-0.5",children:ci(n).map((m,x)=>{let g=m.getMonth()===n.getMonth(),F=m.toDateString()===c,T=u&&m.toDateString()===u;return jsxRuntime.jsx("button",{type:"button",onClick:()=>t(m),className:B("h-8 w-8 mx-auto flex items-center justify-center text-sm rounded-md transition-all",!g&&"text-slate-300",g&&!T&&!F&&"text-slate-700 hover:bg-slate-100",F&&!T&&"bg-blue-500 text-white font-semibold",T&&"bg-[var(--fe-primary)] text-white font-semibold shadow-sm"),children:m.getDate()},x)})}),jsxRuntime.jsx("div",{className:"border-t border-slate-100 p-2",children:jsxRuntime.jsx("button",{type:"button",onClick:()=>{let m=new Date;i(m),t(m);},className:"w-full text-sm font-medium py-1.5 px-3 rounded-md transition-colors text-[var(--fe-primary)] hover:bg-[var(--fe-primary-light)]",children:s})})]})};var fi=(e,t)=>e.toLocaleDateString(t==="fr"?"fr-FR":"en-US",{day:"numeric",month:"long",year:"numeric"}),gi=({field:e,name:t,defaultValue:o,currentLang:r="fr",className:n})=>{let{register:i,setValue:a}=reactHookForm.useFormContext(),l=t??e.fieldName.toString(),[s,d]=Me.useState(false),[p,c]=Me.useState(o?new Date(o):null),u=x=>{c(x),a(l,x.toISOString().split("T")[0],{shouldValidate:true,shouldTouch:true}),d(false);},m=r==="fr"?"S\xE9lectionner une date":"Select a date";return jsxRuntime.jsxs(W,{field:e,currentLang:r,children:[jsxRuntime.jsx("input",{type:"hidden",...i(l)}),jsxRuntime.jsxs(fo,{open:s,onOpenChange:d,children:[jsxRuntime.jsx(go,{asChild:true,children:jsxRuntime.jsxs("button",{type:"button",className:B("flex h-10 w-full items-center justify-between rounded-md border border-slate-200 bg-white px-3 py-2","text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-[var(--fe-primary)] focus:ring-offset-1 focus:border-[var(--fe-primary)]","disabled:cursor-not-allowed disabled:opacity-50",s&&"border-[var(--fe-primary)] ring-2 ring-[var(--fe-primary)] ring-offset-1",p?"text-slate-900":"text-slate-400",n),children:[jsxRuntime.jsxs("span",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.CalendarIcon,{className:"h-4 w-4 text-slate-400 shrink-0"}),p?fi(p,r):m]}),jsxRuntime.jsx(lucideReact.ChevronDown,{className:B("h-4 w-4 text-slate-400 shrink-0 transition-transform",s&&"rotate-180")})]})}),jsxRuntime.jsx(Jt,{className:"p-0 overflow-hidden",children:jsxRuntime.jsx(bo,{value:p,onChange:u,currentLang:r})})]})]})},vo=gi;var Fo=j__namespace.Root;var xo=j__namespace.Value,Yt=Me__namespace.forwardRef(({className:e,children:t,...o},r)=>jsxRuntime.jsxs(j__namespace.Trigger,{ref:r,className:B("flex h-10 w-full items-center justify-between rounded-md border border-slate-200 bg-white px-3 py-2","text-sm text-slate-900 placeholder:text-slate-400","focus:outline-none focus:ring-2 focus:ring-[var(--fe-primary)] focus:ring-offset-1 focus:border-[var(--fe-primary)]","disabled:cursor-not-allowed disabled:opacity-50","transition-colors [&>span]:line-clamp-1",e),...o,children:[t,jsxRuntime.jsx(j__namespace.Icon,{asChild:true,children:jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4 text-slate-400 shrink-0 ml-2"})})]}));Yt.displayName=j__namespace.Trigger.displayName;var Zt=Me__namespace.forwardRef(({className:e,children:t,position:o="popper",...r},n)=>jsxRuntime.jsx(j__namespace.Portal,{children:jsxRuntime.jsx(j__namespace.Content,{ref:n,className:B("relative z-50 min-w-[8rem] overflow-hidden rounded-md border border-slate-200 bg-white text-slate-900 shadow-lg",o==="popper"&&"w-[var(--radix-select-trigger-width)] max-h-64",e),position:o,...r,children:jsxRuntime.jsx(j__namespace.Viewport,{className:"p-1",children:t})})}));Zt.displayName=j__namespace.Content.displayName;var yi=Me__namespace.forwardRef(({className:e,...t},o)=>jsxRuntime.jsx(j__namespace.Label,{ref:o,className:B("py-1.5 pl-8 pr-2 text-xs font-semibold text-slate-500",e),...t}));yi.displayName=j__namespace.Label.displayName;var Qt=Me__namespace.forwardRef(({className:e,children:t,...o},r)=>jsxRuntime.jsxs(j__namespace.Item,{ref:r,className:B("relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm text-slate-700","outline-none focus:bg-[var(--fe-primary-light)] focus:text-[var(--fe-primary-dark)]","data-[disabled]:pointer-events-none data-[disabled]:opacity-50","data-[state=checked]:text-[var(--fe-primary)] data-[state=checked]:font-medium",e),...o,children:[jsxRuntime.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:jsxRuntime.jsx(j__namespace.ItemIndicator,{children:jsxRuntime.jsx(lucideReact.Check,{className:"h-4 w-4 text-[var(--fe-primary)]"})})}),jsxRuntime.jsx(j__namespace.ItemText,{children:t})]}));Qt.displayName=j__namespace.Item.displayName;var vi=Me__namespace.forwardRef(({className:e,...t},o)=>jsxRuntime.jsx(j__namespace.Separator,{ref:o,className:B("-mx-1 my-1 h-px bg-slate-100",e),...t}));vi.displayName=j__namespace.Separator.displayName;var ke=Me__namespace.forwardRef(({className:e,type:t,...o},r)=>jsxRuntime.jsx("input",{type:t,className:B("flex h-10 w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm text-slate-900","placeholder:text-slate-400","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--fe-primary)] focus-visible:ring-offset-1 focus-visible:border-[var(--fe-primary)]","disabled:cursor-not-allowed disabled:opacity-50","transition-colors",e),ref:r,...o}));ke.displayName="Input";var Ro=e=>e.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim().replace(/^-+|-+$/g,""),wi=({field:e,name:t,defaultValue:o,currentLang:r="fr",className:n,dependentFieldNameTransformed:i})=>{let{setValue:a,watch:l,getValues:s}=reactHookForm.useFormContext(),d=t??e.fieldName.toString(),p=l(d),c=e.dynamicFilterRule?i||e.dynamicFilterRule.dependentFieldName:null,u=c?l(c):null,m=c?s(c):null,x=u!=null&&u!==""?u:m!=null&&m!==""?m:null,g=e.dynamicFilterRule&&(!x||!e.selectOptions?.length),F=U(e.placeholder,r),T=U(e.label,r),y=g&&e.dynamicFilterRule?"S\xE9lectionnez d'abord le champ pr\xE9c\xE9dent":F||`S\xE9lectionner ${T}`,[v,k]=Me.useState(false),[P,R]=Me.useState(""),[I,O]=Me.useState(e.selectOptions||[]),[V,E]=Me.useState(null),[A,L]=Me.useState(null),[b,N]=Me.useState(null),f=Me.useRef(null),h=Me.useRef(null);Me.useEffect(()=>{if(o){let w=e.selectOptions?.find(D=>D.value===o);w&&(E(w),R(U(w.label,r)));}},[o,e.selectOptions,r]),Me.useEffect(()=>{if(p&&p!==V?.value){let w=e.selectOptions?.find(D=>D.value===p);w&&(E(w),R(U(w.label,r)));}else !p&&V&&(E(null),R(""));},[p,e.selectOptions,r,V]);let C=()=>{if(!h.current)return;let w=h.current.getBoundingClientRect(),D=window.pageYOffset||document.documentElement.scrollTop,$=window.pageXOffset||document.documentElement.scrollLeft;N({top:w.bottom+D,left:w.left+$,width:w.width});};Me.useEffect(()=>{if(v&&e.enableSearch)return C(),window.addEventListener("scroll",C,true),window.addEventListener("resize",C),()=>{window.removeEventListener("scroll",C,true),window.removeEventListener("resize",C);}},[v,e.enableSearch]),Me.useEffect(()=>{if(!e.enableSearch){O(e.selectOptions||[]);return}if(!P.trim()){O(e.selectOptions||[]);return}let w=Ro(P);O(e.selectOptions?.filter(D=>Ro(U(D.label,r)).includes(w))||[]);},[P,e.selectOptions,e.enableSearch,r]),Me.useEffect(()=>{let w=D=>{let $=D.target;f.current?.contains($)||e.enableSearch&&v&&document.querySelector('[data-dropdown-portal="true"]')?.contains($)||(k(false),L(null),V&&e.enableSearch&&R(U(V.label,r)));};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[V,r,e.enableSearch,v]);let M=w=>{E(w),R(U(w.label,r)),a(d,w.value,{shouldValidate:true,shouldTouch:true}),k(false),L(null);},S=w=>{let D=w.target.value;R(D),e.enableSearch&&(k(true),L(null),!D.trim()&&V&&(E(null),a(d,"",{shouldValidate:true,shouldTouch:true})));};return e.enableSearch?jsxRuntime.jsx(W,{field:e,currentLang:r,children:jsxRuntime.jsxs("div",{ref:f,className:"relative",children:[jsxRuntime.jsx(ke,{ref:h,type:"text",value:P,onChange:S,onClick:()=>{g||(k(w=>!w),V&&!v&&R(""));},onKeyDown:w=>{g||(w.key==="Escape"?(k(false),V&&R(U(V.label,r))):w.key==="Enter"?(w.preventDefault(),I.length===1&&I[0]&&M(I[0])):w.key==="ArrowDown"&&(w.preventDefault(),k(true)));},placeholder:y,autoComplete:"off",disabled:!!g,className:B("pr-10",n)}),jsxRuntime.jsx(lucideReact.ChevronDown,{className:B("absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none transition-transform",v&&"rotate-180")}),v&&b&&reactDom.createPortal(jsxRuntime.jsx("div",{"data-dropdown-portal":"true",style:{position:"absolute",top:b.top,left:b.left,width:b.width,zIndex:999999},className:"rounded-md border border-slate-200 bg-white shadow-lg max-h-52 overflow-y-auto",onMouseDown:w=>w.stopPropagation(),children:I.length===0?jsxRuntime.jsx("div",{className:"px-3 py-2 text-sm text-slate-400 italic",children:"Aucun r\xE9sultat trouv\xE9"}):I.map((w,D)=>jsxRuntime.jsx("div",{className:B("px-3 py-2 text-sm cursor-pointer border-b border-slate-100 last:border-0 transition-colors",A===D?"bg-teal-50 text-teal-800":"text-slate-700",V?.value===w.value&&"font-medium text-teal-700"),onMouseDown:$=>{g||($.preventDefault(),$.stopPropagation(),M(w));},onMouseEnter:()=>L(D),onMouseLeave:()=>L(null),children:U(w.label,r)},`${w.value}-${D}`))}),document.body)]})}):jsxRuntime.jsx(W,{field:e,currentLang:r,children:jsxRuntime.jsxs(Fo,{value:p||"",onValueChange:w=>a(d,w,{shouldValidate:true,shouldTouch:true}),disabled:!!g,children:[jsxRuntime.jsx(Yt,{className:B("w-full",n),children:jsxRuntime.jsx(xo,{placeholder:y})}),jsxRuntime.jsx(Zt,{children:e.selectOptions?.map((w,D)=>jsxRuntime.jsx(Qt,{value:w.value,children:U(w.label,r)},`${w.value}-${D}`))})]})})},So=wi;var H=e=>{if(!e)return;let t=r=>{try{return decodeURIComponent(r)}catch{return r}},o=r=>{let n=r.split("?")[0],i=n.split(/[\\/]/).filter(Boolean);return i.length===0?n?t(n):void 0:t(i[i.length-1])};try{let r=new URL(e),n=["filename","file","file_name","name"];for(let a of n){let l=r.searchParams.get(a);if(l){let s=l.split("/").filter(Boolean).pop()??l;return t(s)}}let i=r.pathname.split("/").filter(Boolean);if(i.length>0)return t(i[i.length-1])}catch{}return o(e)};var Pi=e=>e instanceof Map,rr=e=>e?Pi(e)?Object.fromEntries(e.entries()):{...e}:{},Co=(e,t)=>{let o=e.replace(/\/+$/,"");if(/^https?:\/\//i.test(t))return t;let r=t.replace(/^\/+/,"");return `${o}/${r}`},ko=(e,t,o)=>{if(o!=null){if(o instanceof File||o instanceof Blob){e.append(t,o);return}if(Array.isArray(o)){o.forEach(r=>ko(e,t,r));return}if(typeof o=="object"){e.append(t,JSON.stringify(o));return}e.append(t,String(o));}},Si=(e,t,o)=>{let r=[e?.filename,e?.fileName,e?.generatedFilename,e?.generatedFileName,e?.generated_filename,e?.storedFilename,e?.storedFileName,e?.name].filter(i=>typeof i=="string"&&i.trim().length>0);if(r.length>0)return r[0];let n=H(t);return n||o?.name},Ci=(e,t)=>{if(e instanceof File)return e;let o=t??`upload-${Date.now()}.${(e.type||"bin").split("/").pop()??"bin"}`;return new File([e],o,{type:e.type||"application/octet-stream"})},Eo=(e,t,o)=>{if(!t||t<=0||!o)return e;let r=setTimeout(()=>o.abort(),t);return e.finally(()=>{clearTimeout(r);})},ki=async(e,t)=>{let o=new AbortController,r=Co(e.serverDns,e.postApiEndPoint),i={...rr(e.payload),...t.payloadOverrides??{}},a=Ci(t.file,t.fallbackFilename),l=new FormData;Object.entries(i).forEach(([x,g])=>{x!=="file"&&ko(l,x,g);}),l.append("file",a);let s={...e.extraHeaders??{}};e.bearer&&(s.Authorization=`Bearer ${e.bearer}`);let d=fetch(r,{method:"POST",headers:s,body:l,signal:o.signal}),p=await Eo(d,e.timeoutMs,o);if(e.onResponse)try{await e.onResponse(p.clone());}catch(x){console.warn("[FileBucketUpload] onResponse hook error:",x);}let c=null;try{c=await p.clone().json();}catch{}if(!p.ok){let x=c?.message??`Upload failed with status ${p.status} ${p.statusText}`;throw new Error(x)}if(c?.success===false)throw new Error(c?.message??"Upload failed");let u=c?.data??{},m=u.url??u.file_url??u.downloadUrl??u.path??null;if(!m)throw new Error("Upload succeeded but no URL was returned by the API response.");return {url:m,filename:Si(u,m,a),originalName:u.originalname??u.originalName??void 0,folder:u.folder??u.folder_name??void 0,raw:c}},Ei=async(e,t)=>{let o=new AbortController,r=Co(e.serverDns,e.deleteApiEndPoint),n=rr(e.payload),i=rr(t?.payloadOverrides);t?.filename&&(i.filename=t.filename),t?.fileUrl&&(i.file_url=t.fileUrl);let a={...n,...i},l=e.deleteApiEndPoint.includes("delete-file-by-url");if(e.deleteApiEndPoint.includes("delete-file")&&!l&&!a.filename&&typeof a.file_url=="string"){let m=H(a.file_url);m&&(a.filename=m);}let d={"Content-Type":"application/json",...e.extraHeaders??{}};e.bearer&&(d.Authorization=`Bearer ${e.bearer}`);let p=fetch(r,{method:"DELETE",headers:d,body:JSON.stringify(a),signal:o.signal}),c=await Eo(p,e.timeoutMs,o);if(e.onResponse)try{await e.onResponse(c.clone());}catch(m){console.warn("[FileBucketDelete] onResponse hook error:",m);}let u=null;try{u=await c.clone().json();}catch{}if(!c.ok){let m=u?.message??`Delete failed with status ${c.status} ${c.statusText}`;throw new Error(m)}if(u?.success===false)throw new Error(u?.message??"Delete failed");return {success:true,raw:u}},ce=e=>{let[t,o]=Me.useState(false),[r,n]=Me.useState(false),[i,a]=Me.useState(null),l=e?.uploadOption,s=e?.deleteOption,d=Me.useCallback(async u=>{if(!l)throw new Error("Upload option is not configured for this field (fileToBucketManage.uploadOption missing).");o(true),a(null);try{return await ki(l,u)}catch(m){let x=m instanceof Error?m.message:"Unexpected upload error";throw a(x),m}finally{o(false);}},[l]),p=Me.useCallback(async u=>{if(!s)throw new Error("Delete option is not configured for this field (fileToBucketManage.deleteOption missing).");n(true),a(null);try{return await Ei(s,u)}catch(m){let x=m instanceof Error?m.message:"Unexpected delete error";throw a(x),m}finally{n(false);}},[s]),c=Me.useCallback(()=>a(null),[]);return Me.useMemo(()=>({uploadFile:d,deleteFile:p,isUploading:t,isDeleting:r,error:i,resetError:c,hasUploadSupport:!!l,hasDeleteSupport:!!s}),[d,p,t,r,i,c,l,s])};var nr=()=>crypto.randomUUID?.()??Math.random().toString(36).slice(2),Li=e=>{if(!e)return "0 Bytes";let t=1024,o=["Bytes","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(t));return `${parseFloat((e/Math.pow(t,r)).toFixed(2))} ${o[r]}`},$i=e=>e.startsWith("image/")?"\u{1F5BC}\uFE0F":e.startsWith("video/")?"\u{1F3AC}":e.startsWith("audio/")?"\u{1F3B5}":e.includes("pdf")?"\u{1F4C4}":e.includes("word")?"\u{1F4DD}":e.includes("excel")||e.includes("sheet")?"\u{1F4CA}":"\u{1F4CE}",zi=({field:e,name:t,currentLang:o="fr",className:r,defaultValue:n})=>{let{setValue:i}=reactHookForm.useFormContext(),[a,l]=Me.useState(false),[s,d]=Me.useState(()=>typeof n=="string"&&n.trim().length>0?[{id:nr(),name:H(n)??n,size:0,type:"",url:n,filename:H(n)??void 0,uploading:false,error:null}]:Array.isArray(n)?n.filter(f=>typeof f=="string"&&f.trim().length>0).map(f=>({id:nr(),name:H(f)??f,size:0,type:"",url:f,filename:H(f)??void 0,uploading:false,error:null})):[]),[p,c]=Me.useState(null),u=Me.useRef(null),m=t??e.fieldName.toString(),x=Me.useMemo(()=>Array.isArray(e.response?.responseValue)||Array.isArray(n),[e.response?.responseValue,n]),{uploadFile:g,deleteFile:F,isUploading:T,isDeleting:y,error:v,resetError:k,hasUploadSupport:P,hasDeleteSupport:R}=ce(e.fileToBucketManage),I=p??v??null,O=Me.useRef(false);Me.useEffect(()=>{if(!O.current&&(O.current=true,s.length>0)){let f=s.filter(h=>h.url&&!h.error).map(h=>h.url)??[];i(m,x?f:f[0]??null,{shouldValidate:false,shouldTouch:false});}},[s,m,x,i]);let V=f=>{d(h=>{let C=f(h),M=C.filter(S=>S.url&&!S.error).map(S=>S.url)??[];return i(m,x?M:M[0]??null,{shouldValidate:true,shouldTouch:true}),C});},E=f=>{f.preventDefault(),f.stopPropagation(),l(f.type==="dragenter"||f.type==="dragover");},A=f=>{f.preventDefault(),f.stopPropagation(),l(false),f.dataTransfer.files&&f.dataTransfer.files.length>0&&L(f.dataTransfer.files);},L=async f=>{if(!P){c("Configuration d'upload manquante pour ce champ (fileToBucketManage).");return}k(),c(null);let h=Array.from(f);x||V(()=>[]),await Promise.all(h.map(async C=>{let M=nr();V(S=>{let w={id:M,name:C.name,size:C.size,type:C.type,uploading:true,url:void 0,filename:void 0,error:null};return x?[...S,w]:[w]});try{let S=await g({file:C});V(w=>w.map(D=>D.id===M?{...D,uploading:!1,url:S.url,name:S.originalName??S.filename??H(S.url)??D.name,filename:S.filename??H(S.url),error:null}:D));}catch(S){let w=S instanceof Error?S.message:"\xC9chec du t\xE9l\xE9versement du fichier.";V(D=>D.map($=>$.id===M?{...$,uploading:false,error:w}:$));}})),u.current&&(u.current.value="");},b=f=>{f.target.files&&f.target.files.length>0&&L(f.target.files);},N=async f=>{k(),c(null);let h=s.find(C=>C.id===f);if(h){if(h.url&&R)try{await F({filename:h.filename??H(h.url??""),fileUrl:h.url});}catch(C){let M=C instanceof Error?C.message:"\xC9chec de la suppression du fichier distant.";V(S=>S.map(w=>w.id===f?{...w,error:M}:w));return}V(C=>C.filter(M=>M.id!==f));}};return jsxRuntime.jsxs(W,{field:e,currentLang:o,children:[jsxRuntime.jsxs("div",{className:B("relative border-2 border-dashed rounded-lg cursor-pointer transition-all duration-300 ease-in-out",a?"border-teal-500 bg-teal-50 scale-[1.02]":"border-gray-300 hover:border-teal-400 hover:bg-gray-50",r,T&&"pointer-events-none opacity-60"),onDragEnter:E,onDragLeave:E,onDragOver:E,onDrop:A,onClick:()=>u.current?.click(),children:[jsxRuntime.jsx("input",{type:"file",multiple:x,ref:u,onChange:b,className:"hidden"}),jsxRuntime.jsx("div",{className:"p-8 text-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[jsxRuntime.jsx("div",{className:B("p-3 rounded-full transition",a?"bg-teal-600 text-white":"bg-gray-100 text-teal-600 hover:bg-teal-100"),children:jsxRuntime.jsx(lucideReact.UploadCloud,{size:24})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-base font-medium text-gray-700 mb-1",children:a?"D\xE9posez vos fichiers ici":"Glissez-d\xE9posez vos fichiers"}),jsxRuntime.jsxs("p",{className:"text-sm text-gray-500",children:["ou"," ",jsxRuntime.jsx("span",{className:"text-teal-600 font-medium hover:underline",children:"cliquez pour parcourir"})]}),jsxRuntime.jsx("p",{className:"text-xs text-gray-400 mt-2",children:"Formats vari\xE9s support\xE9s. Chaque fichier est envoy\xE9 d\xE8s sa s\xE9lection."})]})]})})]}),s.length>0&&jsxRuntime.jsxs("div",{className:"mt-4 space-y-2",children:[jsxRuntime.jsxs("div",{className:"text-sm font-medium text-gray-700 mb-3",children:["Fichier(s) (",s.length,") :"]}),s.map(f=>jsxRuntime.jsxs("div",{className:B("flex items-center justify-between p-3 bg-white border border-gray-200 rounded-lg hover:shadow-sm transition-shadow",f.error&&"border-red-300"),children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-3",children:[jsxRuntime.jsx("div",{className:"text-lg",children:$i(f.type)}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-gray-800 truncate",children:f.name}),jsxRuntime.jsx("p",{className:"text-sm text-gray-500",children:f.size?Li(f.size):"En ligne"}),f.error&&jsxRuntime.jsx("p",{className:"text-xs text-red-500 mt-1",children:f.error})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[f.url&&!f.uploading&&jsxRuntime.jsx("button",{type:"button",onClick:()=>window.open(f.url,"_blank"),className:"p-2 hover:bg-teal-50 rounded-full transition-colors",children:jsxRuntime.jsx(lucideReact.ExternalLink,{size:18,className:"text-teal-600"})}),f.uploading&&jsxRuntime.jsx(lucideReact.Loader2,{size:18,className:"animate-spin text-teal-600"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{N(f.id);},className:"p-2 hover:bg-red-100 rounded-full disabled:opacity-60",disabled:f.uploading||y,children:y?jsxRuntime.jsx(lucideReact.Loader2,{size:18,className:"animate-spin text-red-500"}):jsxRuntime.jsx(lucideReact.Trash2,{size:18,className:"text-red-500"})})]})]},f.id))]}),I&&jsxRuntime.jsx("div",{className:"mt-3 rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-600",children:I})]})},Io=zi;var Ui=({field:e,name:t,defaultValue:o,currentLang:r="fr",className:n})=>{let{setValue:i,watch:a}=reactHookForm.useFormContext(),l=U(e.placeholder,r),s=t??e.fieldName.toString(),[d,p]=Me.useState(""),c=F=>{if(F==null||F==="")return "";let T=typeof F=="string"?parseFloat(F):F;return isNaN(T)?"":T.toLocaleString("fr-FR",{minimumFractionDigits:0,maximumFractionDigits:0})},u=F=>F&&parseFloat(F.replace(/\s/g,""))||0;Me.useEffect(()=>{o!=null&&!isNaN(Number(o))&&p(c(Number(o)));},[o]);let m=a(s);return Me.useEffect(()=>{if(m!=null&&!isNaN(Number(m))){let F=c(Number(m));F!==d&&p(F);}},[m]),jsxRuntime.jsx(W,{field:e,currentLang:r,children:jsxRuntime.jsx(ke,{type:"text",name:s,placeholder:l,value:d,onChange:F=>{let T=F.target.value;/^[\d\s,]*$/.test(T)&&(p(T),i(s,u(T),{shouldValidate:true,shouldTouch:true}));},onBlur:()=>{let F=u(d);isNaN(F)||p(c(F));},className:n})})},Ao=Ui;var ji=({field:e,name:t,defaultValue:o,currentLang:r="fr",className:n})=>{let{setValue:i,watch:a}=reactHookForm.useFormContext(),[l,s]=Me.useState(false),d=U(e.placeholder,r),p=t??e.fieldName.toString(),c=a(p)??o??"";return jsxRuntime.jsx(W,{field:e,currentLang:r,children:jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(ke,{type:l?"text":"password",name:p,value:c,placeholder:d,onChange:m=>{i(p,m.target.value,{shouldValidate:true,shouldTouch:true});},className:n}),jsxRuntime.jsx("button",{type:"button",onClick:()=>s(m=>!m),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 focus:outline-none",tabIndex:-1,children:l?jsxRuntime.jsx(lucideReact.EyeOff,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.Eye,{className:"h-4 w-4"})})]})})},Lo=ji;var ir=Me__namespace.forwardRef(({className:e,...t},o)=>jsxRuntime.jsx(Ae__namespace.Root,{className:B("grid gap-2",e),...t,ref:o}));ir.displayName=Ae__namespace.Root.displayName;var ar=Me__namespace.forwardRef(({className:e,...t},o)=>jsxRuntime.jsx(Ae__namespace.Item,{ref:o,className:B("aspect-square h-4 w-4 rounded-full border border-slate-300 bg-white","focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--fe-primary)] focus-visible:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50","data-[state=checked]:border-[var(--fe-primary)]",e),...t,children:jsxRuntime.jsx(Ae__namespace.Indicator,{className:"flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"h-2.5 w-2.5 rounded-full bg-[var(--fe-primary)]"})})}));ar.displayName=Ae__namespace.Item.displayName;var Xi=({field:e,name:t,defaultValue:o,currentLang:r="fr",className:n})=>{let{setValue:i,trigger:a,watch:l}=reactHookForm.useFormContext(),s=t??e.fieldName.toString(),d=l(s)??o??"";return jsxRuntime.jsx(W,{field:e,currentLang:r,children:jsxRuntime.jsx(ir,{value:d,onValueChange:async c=>{i(s,c,{shouldValidate:true,shouldTouch:true,shouldDirty:true}),await a(s),setTimeout(()=>a(),0);},className:`flex flex-col gap-2 ${n||""}`,children:e.selectOptions?.map((c,u)=>{let m=`${e.formFieldId}-${c.value}-${u}`;return jsxRuntime.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1 hover:bg-teal-50 transition-all",children:[jsxRuntime.jsx(ar,{value:c.value,id:m}),jsxRuntime.jsxs(Be,{htmlFor:m,className:"cursor-pointer text-slate-700 flex items-center gap-1",children:[c.icon&&jsxRuntime.jsx("span",{children:c.icon}),U(c.label,r)]})]},c.value)})})})},zo=Xi;var lr=Me__namespace.forwardRef(({className:e,...t},o)=>jsxRuntime.jsx("textarea",{className:B("flex min-h-[100px] w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm text-slate-900","placeholder:text-slate-400","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--fe-primary)] focus-visible:ring-offset-1 focus-visible:border-[var(--fe-primary)]","disabled:cursor-not-allowed disabled:opacity-50","transition-colors resize-y",e),ref:o,...t}));lr.displayName="Textarea";var ea=({field:e,name:t,defaultValue:o,currentLang:r="fr",className:n})=>{let{setValue:i,watch:a}=reactHookForm.useFormContext(),l=U(e.placeholder,r),s=t??e.fieldName.toString(),[d,p]=Me.useState(o||"");Me.useEffect(()=>{o!==void 0&&p(o);},[o]);let c=a(s);return Me.useEffect(()=>{c!==void 0&&c!==d&&p(c);},[c,d]),jsxRuntime.jsx(W,{field:e,currentLang:r,children:jsxRuntime.jsx(lr,{name:s,value:d,placeholder:l,onChange:m=>{let x=m.target.value;p(x),i(s,x,{shouldValidate:true,shouldTouch:true});},className:n})})},Ho=ea;var oa=e=>e instanceof Map,na=e=>e?oa(e)?Object.fromEntries(e.entries()):{...e}:{},jo=({emailField:e,allSections:t,currentSectionIndex:o,onOTPSent:r})=>{let{watch:n,trigger:i,formState:a}=reactHookForm.useFormContext(),[l,s]=Me.useState(false),[d,p]=Me.useState(false),[c,u]=Me.useState(null),[m,x]=Me.useState(null),g=Me.useRef(null),F=Me.useRef(false),T=n(e.fieldName),y=Cr(e,t,o),v=Me.useCallback(async k=>{if(!e.emailFormFieldExecOptions?.otpSendApiConfig){console.warn("Email field does not have OTP send API configuration");return}if(F.current)return;let P=e.emailFormFieldExecOptions.otpSendApiConfig;s(true),u(null),F.current=true;try{let R=`${P.serverDns}${P.postApiEndPoint}`,O={...na(P.payload),email:k},V={"Content-Type":"application/json",...P.extraHeaders||{}};P.bearer&&(V.Authorization=`Bearer ${P.bearer}`);let E=await fetch(R,{method:"POST",headers:V,body:JSON.stringify(O)});if(!E.ok){let L=await E.text().catch(()=>E.statusText);throw new Error(`OTP send failed: ${E.status} ${L}`)}let A=await E.json();return p(!0),x(k),r?.(k),ze__default.default.success(`Code OTP envoy\xE9 \xE0 ${k}`,{duration:3e3,position:"top-center"}),console.log(`\u2705 OTP envoy\xE9 \xE0 ${k}`,A),A}catch(R){let I=R instanceof Error?R.message:"Failed to send OTP";throw u(I),ze__default.default.error(`Erreur lors de l'envoi de l'OTP: ${I}`,{duration:4e3,position:"top-center"}),R}finally{s(false),F.current=false;}},[e,r]);return Me.useEffect(()=>{g.current&&clearTimeout(g.current);let k=T;if(!(!k||typeof k!="string"||k.trim()==="")&&e.emailFormFieldExecOptions?.triggerOTPSend&&y&&!(k===m&&d))return g.current=setTimeout(async()=>{try{if(!await i(e.fieldName)){console.log("Email validation failed, not sending OTP");return}k!==m&&(p(!1),u(null)),await v(k);}catch(P){console.error("Erreur lors de l'envoi automatique de l'OTP:",P);}},500),()=>{g.current&&clearTimeout(g.current);}},[T,e,i,d,v,y,m]),Me.useEffect(()=>{T!==m&&m!==null&&(p(false),u(null));},[T,m]),{isSendingOTP:l,otpSent:d,error:c,sendOTP:v,linkedOTPField:y,lastSentEmail:m}};var aa=({field:e,name:t,defaultValue:o,currentLang:r="fr",className:n,allSections:i=[],currentSectionIndex:a=0})=>{let{setValue:l,watch:s}=reactHookForm.useFormContext(),d=U(e.placeholder,r),p=t??e.fieldName.toString(),c=e.validations?.some(y=>y.validationType==="email"),u=e.emailFormFieldExecOptions?.triggerOTPSend===true,m=jo({emailField:e,allSections:i,currentSectionIndex:a,onOTPSent:y=>{console.log(`\u2705 OTP envoy\xE9 automatiquement \xE0 ${y}`);}}),[x,g]=Me.useState(o||"");Me.useEffect(()=>{o!==void 0&&g(o);},[o]);let F=s(p);Me.useEffect(()=>{F!==void 0&&F!==x&&g(F);},[F,x]);let T=y=>{let v=y.target.value;g(v),l(p,v,{shouldValidate:true,shouldTouch:true});};return jsxRuntime.jsxs(W,{field:e,currentLang:r,children:[c&&u&&m.isSendingOTP&&jsxRuntime.jsxs("div",{className:"mb-2 text-sm text-blue-600 flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-blue-600"}),jsxRuntime.jsx("span",{children:"Envoi du code OTP en cours..."})]}),c&&u&&m.otpSent&&!m.isSendingOTP&&jsxRuntime.jsx("div",{className:"mb-2 text-sm text-green-600",children:"\u2713 Code OTP envoy\xE9 avec succ\xE8s"}),c&&u&&m.error&&jsxRuntime.jsxs("div",{className:"mb-2 text-sm text-red-600",children:["\u26A0 Erreur: ",m.error]}),jsxRuntime.jsx(ke,{type:"text",name:p,value:x,placeholder:d,onChange:T,className:n})]})},Jo=aa;var pa=({field:e,name:t,currentLang:o="fr",className:r,defaultValue:n})=>{let{setValue:i}=reactHookForm.useFormContext(),[a,l]=Me.useState(false),[s,d]=Me.useState(null),[p,c]=Me.useState(null),[u,m]=Me.useState(null),x=Me.useRef(null),g=t??e.fieldName.toString(),F=Me.useRef(false),{uploadFile:T,deleteFile:y,isUploading:v,isDeleting:k,error:P,resetError:R,hasUploadSupport:I,hasDeleteSupport:O}=ce(e.fileToBucketManage),V=u??P??null;Me.useEffect(()=>{typeof n=="string"&&n.trim().length>0&&(d({url:n,name:H(n)??n,bucketFilename:H(n)??void 0}),F.current||(i(g,n,{shouldValidate:false,shouldTouch:false}),F.current=true));},[n,g,i]);let E=h=>{if(h===0)return "0 Bytes";let C=1024,M=["Bytes","KB","MB","GB"],S=Math.floor(Math.log(h)/Math.log(C));return parseFloat((h/Math.pow(C,S)).toFixed(2))+" "+M[S]},A=h=>{h.preventDefault(),h.stopPropagation(),l(h.type==="dragenter"||h.type==="dragover");},L=h=>{h.preventDefault(),h.stopPropagation(),l(false),h.dataTransfer.files&&h.dataTransfer.files.length>0&&b(h.dataTransfer.files[0]);},b=async h=>{if(!h.type.startsWith("image/")){alert("Veuillez s\xE9lectionner un fichier image valide");return}if(!I){m("Configuration d'upload manquante pour ce champ (fileToBucketManage).");return}R(),m(null);let C=URL.createObjectURL(h);c(C);try{let M=await T({file:h});d({url:M.url,name:M.originalName??M.filename??H(M.url)??h.name,size:h.size,type:h.type,bucketFilename:M.filename??H(M.url)}),i(g,M.url,{shouldValidate:!0,shouldTouch:!0});}catch(M){let S=M instanceof Error?M.message:"\xC9chec de l'upload de l'image.";m(S);}finally{URL.revokeObjectURL(C),c(null);}},N=h=>{h.target.files&&h.target.files.length>0&&b(h.target.files[0]);},f=async()=>{if(R(),m(null),s&&O)try{await y({filename:s.bucketFilename??H(s.url??"")??void 0,fileUrl:s.url});}catch(h){let C=h instanceof Error?h.message:"\xC9chec de la suppression du fichier distant.";m(C);return}d(null),i(g,null,{shouldValidate:true,shouldTouch:true}),x.current&&(x.current.value="");};return jsxRuntime.jsx(W,{field:e,currentLang:o,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[!s&&!p&&jsxRuntime.jsxs("div",{className:B("relative border-2 border-dashed rounded-lg cursor-pointer transition-all duration-300 ease-in-out",a?"border-teal-500 bg-teal-50 scale-[1.02]":"border-gray-300 hover:border-teal-400 hover:bg-gray-50",r,v&&"pointer-events-none opacity-60"),onDragEnter:A,onDragLeave:A,onDragOver:A,onDrop:L,onClick:()=>x.current?.click(),children:[jsxRuntime.jsx("input",{type:"file",accept:"image/*",ref:x,onChange:N,className:"hidden"}),jsxRuntime.jsx("div",{className:"p-8 text-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[jsxRuntime.jsx("div",{className:B("p-3 rounded-full transition",a?"bg-teal-600 text-white":"bg-gray-100 text-teal-600 hover:bg-teal-100"),children:jsxRuntime.jsx(lucideReact.UploadCloud,{size:24})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-base font-medium text-gray-700 mb-1",children:a?"D\xE9posez votre image ici":"Glissez-d\xE9posez votre image"}),jsxRuntime.jsxs("p",{className:"text-sm text-gray-500",children:["ou"," ",jsxRuntime.jsx("span",{className:"text-teal-600 font-medium hover:underline",children:"cliquez pour parcourir"})]}),jsxRuntime.jsx("p",{className:"text-xs text-gray-400 mt-2",children:"Formats accept\xE9s : JPG, PNG, GIF, WEBP"})]})]})})]}),(s||p)&&jsxRuntime.jsxs("div",{className:"relative border border-gray-200 rounded-lg overflow-hidden bg-gray-50",children:[jsxRuntime.jsxs("div",{className:"relative group",children:[jsxRuntime.jsx("img",{src:p??s?.url??"",alt:"Aper\xE7u",className:"w-full h-auto max-h-96 object-contain"}),jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-300 flex items-center justify-center opacity-0 group-hover:opacity-100",children:jsxRuntime.jsxs("div",{className:"flex space-x-2",children:[s&&jsxRuntime.jsx("button",{type:"button",onClick:()=>window.open(s.url,"_blank"),className:"p-2 bg-white rounded-full hover:bg-gray-100 transition-colors",children:jsxRuntime.jsx(lucideReact.Eye,{size:20,className:"text-teal-600"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{f();},className:"p-2 bg-white rounded-full hover:bg-red-100 transition-colors disabled:opacity-60",disabled:k,children:k?jsxRuntime.jsx(lucideReact.Loader2,{size:20,className:"animate-spin text-red-600"}):jsxRuntime.jsx(lucideReact.Trash2,{size:20,className:"text-red-600"})})]})})]}),jsxRuntime.jsx("div",{className:"p-4 bg-white border-t border-gray-200",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-gray-800 truncate",children:s?.name}),(s?.size??p)&&jsxRuntime.jsx("p",{className:"text-sm text-gray-500",children:s?.size?E(s.size):""})]}),v&&jsxRuntime.jsx(lucideReact.Loader2,{size:20,className:"animate-spin text-teal-600"})]})})]}),V&&jsxRuntime.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-600",children:V})]})})},Zo=pa;var ya=({field:e,name:t,currentLang:o="fr",className:r,defaultValue:n})=>{let{setValue:i}=reactHookForm.useFormContext(),[a,l]=Me.useState(false),[s,d]=Me.useState(null),[p,c]=Me.useState(null),[u,m]=Me.useState(null),x=Me.useRef(null),g=t??e.fieldName.toString(),F=Me.useRef(false),{uploadFile:T,deleteFile:y,isUploading:v,isDeleting:k,error:P,resetError:R,hasUploadSupport:I,hasDeleteSupport:O}=ce(e.fileToBucketManage),V=u??P??null;Me.useEffect(()=>{typeof n=="string"&&n.trim().length>0&&(d({url:n,name:H(n)??n,bucketFilename:H(n)??void 0}),F.current||(i(g,n,{shouldValidate:false,shouldTouch:false}),F.current=true));},[n,g,i]);let E=h=>{if(h===0)return "0 Bytes";let C=1024,M=["Bytes","KB","MB","GB"],S=Math.floor(Math.log(h)/Math.log(C));return parseFloat((h/Math.pow(C,S)).toFixed(2))+" "+M[S]},A=h=>{h.preventDefault(),h.stopPropagation(),l(h.type==="dragenter"||h.type==="dragover");},L=h=>{h.preventDefault(),h.stopPropagation(),l(false),h.dataTransfer.files&&h.dataTransfer.files.length>0&&b(h.dataTransfer.files[0]);},b=async h=>{if(!h.type.startsWith("video/")){alert("Veuillez s\xE9lectionner un fichier vid\xE9o valide");return}if(!I){m("Configuration d'upload manquante pour ce champ (fileToBucketManage).");return}R(),m(null);let C=URL.createObjectURL(h);c(C);try{let M=await T({file:h});d({url:M.url,name:M.originalName??M.filename??H(M.url)??h.name,size:h.size,type:h.type,bucketFilename:M.filename??H(M.url)}),i(g,M.url,{shouldValidate:!0,shouldTouch:!0});}catch(M){let S=M instanceof Error?M.message:"\xC9chec de l'upload de la vid\xE9o.";m(S);}finally{URL.revokeObjectURL(C),c(null);}},N=h=>{h.target.files&&h.target.files.length>0&&b(h.target.files[0]);},f=async()=>{if(R(),m(null),s&&O)try{await y({filename:s.bucketFilename??H(s.url??"")??void 0,fileUrl:s.url});}catch(h){let C=h instanceof Error?h.message:"\xC9chec de la suppression du fichier distant.";m(C);return}d(null),c(null),i(g,null,{shouldValidate:true,shouldTouch:true}),x.current&&(x.current.value="");};return jsxRuntime.jsx(W,{field:e,currentLang:o,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:B("relative border-2 border-dashed rounded-lg cursor-pointer transition-all duration-300 ease-in-out",a?"border-teal-500 bg-teal-50 scale-[1.02]":"border-gray-300 hover:border-teal-400 hover:bg-gray-50",(s||p)&&"hidden",r,v&&"pointer-events-none opacity-60"),onDragEnter:A,onDragLeave:A,onDragOver:A,onDrop:L,onClick:()=>x.current?.click(),children:[jsxRuntime.jsx("input",{type:"file",accept:"video/*",ref:x,onChange:N,className:"hidden"}),jsxRuntime.jsx("div",{className:"p-8 text-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[jsxRuntime.jsx("div",{className:B("p-3 rounded-full transition",a?"bg-teal-600 text-white":"bg-gray-100 text-teal-600 hover:bg-teal-100"),children:jsxRuntime.jsx(lucideReact.Video,{size:24})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-base font-medium text-gray-700 mb-1",children:a?"D\xE9posez votre vid\xE9o ici":"Glissez-d\xE9posez votre vid\xE9o"}),jsxRuntime.jsxs("p",{className:"text-sm text-gray-500",children:["ou"," ",jsxRuntime.jsx("span",{className:"text-teal-600 font-medium hover:underline",children:"cliquez pour parcourir"})]}),jsxRuntime.jsx("p",{className:"text-xs text-gray-400 mt-2",children:"Formats accept\xE9s : MP4, WEBM, AVI, etc."})]})]})})]}),(s||p)&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-3 bg-white border border-gray-200 rounded-lg",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-3",children:[jsxRuntime.jsx("div",{className:"p-2 bg-purple-50 rounded-lg",children:jsxRuntime.jsx(lucideReact.Video,{size:20,className:"text-purple-600"})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-gray-800 truncate",children:s?.name}),s?.size&&jsxRuntime.jsx("p",{className:"text-sm text-gray-500",children:E(s.size)})]})]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{f();},className:"p-2 hover:bg-red-50 rounded-lg transition-colors disabled:opacity-60",disabled:k,children:k?jsxRuntime.jsx(lucideReact.Loader2,{size:20,className:"animate-spin text-red-500"}):jsxRuntime.jsx(lucideReact.Trash2,{size:20,className:"text-red-500"})})]}),jsxRuntime.jsx("div",{className:"border border-gray-200 rounded-lg overflow-hidden bg-gray-50",children:jsxRuntime.jsx("video",{src:p??s?.url??void 0,controls:true,className:"w-full h-auto",style:{maxHeight:"400px"}})})]}),V&&jsxRuntime.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-600",children:V})]})})},tn=ya;var Ra=({field:e,name:t,currentLang:o="fr",className:r,defaultValue:n})=>{let{setValue:i}=reactHookForm.useFormContext(),[a,l]=Me.useState(false),[s,d]=Me.useState(null),[p,c]=Me.useState(null),[u,m]=Me.useState(null),[x,g]=Me.useState(false),F=Me.useRef(null),T=Me.useRef(null),y=t??e.fieldName.toString(),v=Me.useRef(false),{uploadFile:k,deleteFile:P,isUploading:R,isDeleting:I,error:O,resetError:V,hasUploadSupport:E,hasDeleteSupport:A}=ce(e.fileToBucketManage),L=u??O??null;Me.useEffect(()=>{typeof n=="string"&&n.trim().length>0&&(d({url:n,name:H(n)??n,bucketFilename:H(n)??void 0}),v.current||(i(y,n,{shouldValidate:false,shouldTouch:false}),v.current=true));},[n,y,i]);let b=w=>{if(w===0)return "0 Bytes";let D=1024,$=["Bytes","KB","MB","GB"],G=Math.floor(Math.log(w)/Math.log(D));return parseFloat((w/Math.pow(D,G)).toFixed(2))+" "+$[G]},N=w=>{w.preventDefault(),w.stopPropagation(),l(w.type==="dragenter"||w.type==="dragover");},f=w=>{w.preventDefault(),w.stopPropagation(),l(false),w.dataTransfer.files&&w.dataTransfer.files.length>0&&h(w.dataTransfer.files[0]);},h=async w=>{if(!w.type.startsWith("audio/")){alert("Veuillez s\xE9lectionner un fichier audio valide");return}if(!E){m("Configuration d'upload manquante pour ce champ (fileToBucketManage).");return}V(),m(null);let D=URL.createObjectURL(w);c(D);try{let $=await k({file:w});d({url:$.url,name:$.originalName??$.filename??H($.url)??w.name,size:w.size,type:w.type,bucketFilename:$.filename??H($.url)}),i(y,$.url,{shouldValidate:!0,shouldTouch:!0});}catch($){let G=$ instanceof Error?$.message:"\xC9chec de l'upload du fichier audio.";m(G);}finally{URL.revokeObjectURL(D),c(null);}},C=w=>{w.target.files&&w.target.files.length>0&&h(w.target.files[0]);},M=async()=>{if(V(),m(null),s&&A)try{await P({filename:s.bucketFilename??H(s.url??"")??void 0,fileUrl:s.url});}catch(w){let D=w instanceof Error?w.message:"\xC9chec de la suppression du fichier distant.";m(D);return}d(null),c(null),g(false),i(y,null,{shouldValidate:true,shouldTouch:true}),F.current&&(F.current.value="");},S=()=>{T.current&&(x?T.current.pause():T.current.play(),g(!x));};return jsxRuntime.jsx(W,{field:e,currentLang:o,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:B("relative border-2 border-dashed rounded-lg cursor-pointer transition-all duration-300 ease-in-out",a?"border-teal-500 bg-teal-50 scale-[1.02]":"border-gray-300 hover:border-teal-400 hover:bg-gray-50",(s||p)&&"hidden",r,R&&"pointer-events-none opacity-60"),onDragEnter:N,onDragLeave:N,onDragOver:N,onDrop:f,onClick:()=>F.current?.click(),children:[jsxRuntime.jsx("input",{type:"file",accept:"audio/*",ref:F,onChange:C,className:"hidden"}),jsxRuntime.jsx("div",{className:"p-8 text-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[jsxRuntime.jsx("div",{className:B("p-3 rounded-full transition",a?"bg-teal-600 text-white":"bg-gray-100 text-teal-600 hover:bg-teal-100"),children:jsxRuntime.jsx(lucideReact.Music,{size:24})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-base font-medium text-gray-700 mb-1",children:a?"D\xE9posez votre audio ici":"Glissez-d\xE9posez votre audio"}),jsxRuntime.jsxs("p",{className:"text-sm text-gray-500",children:["ou"," ",jsxRuntime.jsx("span",{className:"text-teal-600 font-medium hover:underline",children:"cliquez pour parcourir"})]}),jsxRuntime.jsx("p",{className:"text-xs text-gray-400 mt-2",children:"Formats accept\xE9s : MP3, WAV, OGG, etc."})]})]})})]}),(s||p)&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-4 bg-white border border-gray-200 rounded-lg",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-3",children:[jsxRuntime.jsx("div",{className:"p-2 bg-green-50 rounded-lg",children:jsxRuntime.jsx(lucideReact.Music,{size:20,className:"text-green-600"})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-gray-800 truncate",children:s?.name}),s?.size&&jsxRuntime.jsx("p",{className:"text-sm text-gray-500",children:b(s.size)})]})]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{M();},className:"p-2 hover:bg-red-50 rounded-lg transition-colors disabled:opacity-60",disabled:I,children:I?jsxRuntime.jsx(lucideReact.Loader2,{size:20,className:"animate-spin text-red-500"}):jsxRuntime.jsx(lucideReact.Trash2,{size:20,className:"text-red-500"})})]}),jsxRuntime.jsx("div",{className:"border border-gray-200 rounded-lg overflow-hidden bg-gray-50",children:jsxRuntime.jsxs("div",{className:"flex items-center space-x-3 p-4 bg-white",children:[jsxRuntime.jsx("button",{type:"button",onClick:S,className:"p-3 bg-teal-600 text-white rounded-full hover:bg-teal-700 transition-colors disabled:opacity-60",disabled:!(s||p),children:x?jsxRuntime.jsx(lucideReact.Pause,{size:20}):jsxRuntime.jsx(lucideReact.Play,{size:20})}),jsxRuntime.jsx("div",{className:"flex-1",children:jsxRuntime.jsx("audio",{ref:T,src:p??s?.url??void 0,onEnded:()=>g(false)})})]})})]}),L&&jsxRuntime.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-600",children:L})]})})},on=Ra;var ka=({field:e,name:t,currentLang:o="fr",className:r,defaultValue:n})=>{let{setValue:i}=reactHookForm.useFormContext(),[a,l]=Me.useState(false),[s,d]=Me.useState(null),[p,c]=Me.useState(null),[u,m]=Me.useState("idle"),[x,g]=Me.useState(null),[F,T]=Me.useState(null),y=Me.useRef(null),v=t??e.fieldName.toString(),k=Me.useRef(false),P=Me.useRef(null),{uploadFile:R,deleteFile:I,isUploading:O,isDeleting:V,error:E,resetError:A,hasUploadSupport:L,hasDeleteSupport:b}=ce(e.fileToBucketManage),N=F??E??null,f=Me.useCallback(()=>{P.current&&P.current.startsWith("blob:")&&URL.revokeObjectURL(P.current),P.current=null,c(null),m("idle"),g(null);},[]),h=Me.useCallback(_=>{f();let z=URL.createObjectURL(_);P.current=z,c(z),m("ready"),g(null);},[f]),C=Me.useCallback(async _=>{if(!_){f();return}m("loading"),g(null);try{let z=await fetch(_,{mode:"cors"});if(!z.ok)throw new Error(z.statusText);let ne=await z.blob(),bt=z.headers.get("Content-Type")?.toLowerCase()??"",Tr=ne.type?.toLowerCase()??"",Xn=H(_)?.toLowerCase()??_.split("?")[0].toLowerCase();if(!(bt.includes("pdf")||Tr.includes("pdf")||Xn.endsWith(".pdf")))throw new Error("Le fichier distant n'est pas un PDF.");let Yn=Tr.includes("pdf")?ne:new Blob([ne],{type:"application/pdf"});h(Yn);}catch(z){f(),m("error"),g("Pr\xE9visualisation impossible. Utilisez le bouton \xAB Ouvrir \xBB pour consulter le PDF."),console.warn("[PDFFormField] Preview fetch failed:",z);}},[f,h]);Me.useEffect(()=>{typeof n=="string"&&n.trim().length>0?(d({url:n,name:H(n)??n,bucketFilename:H(n)??void 0}),m("loading"),g(null),C(n),k.current||(i(v,n,{shouldValidate:false,shouldTouch:false}),k.current=true)):(f(),d(null));},[n,v,C,i,f]),Me.useEffect(()=>()=>{P.current&&P.current.startsWith("blob:")&&URL.revokeObjectURL(P.current);},[]);let M=_=>{if(_===0)return "0 Bytes";let z=1024,ne=["Bytes","KB","MB","GB"],bt=Math.floor(Math.log(_)/Math.log(z));return parseFloat((_/Math.pow(z,bt)).toFixed(2))+" "+ne[bt]},S=_=>{_.preventDefault(),_.stopPropagation(),l(_.type==="dragenter"||_.type==="dragover");},w=_=>{_.preventDefault(),_.stopPropagation(),l(false),_.dataTransfer.files&&_.dataTransfer.files.length>0&&D(_.dataTransfer.files[0]);},D=async _=>{if(_.type!=="application/pdf"){alert("Veuillez s\xE9lectionner un fichier PDF valide");return}if(!L){T("Configuration d'upload manquante pour ce champ (fileToBucketManage).");return}A(),T(null),h(_),m("ready"),g(null);try{let z=await R({file:_});d({url:z.url,name:z.originalName??z.filename??H(z.url)??_.name,size:_.size,bucketFilename:z.filename??H(z.url)}),i(v,z.url,{shouldValidate:!0,shouldTouch:!0});}catch(z){let ne=z instanceof Error?z.message:"\xC9chec de l'upload du PDF.";T(ne),f();}},$=_=>{_.target.files&&_.target.files.length>0&&D(_.target.files[0]);},G=async()=>{if(A(),T(null),s&&b)try{await I({filename:s.bucketFilename??H(s.url??"")??void 0,fileUrl:s.url});}catch(_){let z=_ instanceof Error?_.message:"\xC9chec de la suppression du fichier distant.";T(z);return}d(null),p&&p.startsWith("blob:")&&URL.revokeObjectURL(p),c(null),P.current=null,i(v,null,{shouldValidate:true,shouldTouch:true}),y.current&&(y.current.value="");};return jsxRuntime.jsx(W,{field:e,currentLang:o,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[!s&&!p&&jsxRuntime.jsxs("div",{className:B("relative border-2 border-dashed rounded-lg cursor-pointer transition-all duration-300 ease-in-out",a?"border-teal-500 bg-teal-50 scale-[1.02]":"border-gray-300 hover:border-teal-400 hover:bg-gray-50",r,O&&"pointer-events-none opacity-60"),onDragEnter:S,onDragLeave:S,onDragOver:S,onDrop:w,onClick:()=>y.current?.click(),children:[jsxRuntime.jsx("input",{type:"file",accept:"application/pdf",ref:y,onChange:$,className:"hidden"}),jsxRuntime.jsx("div",{className:"p-8 text-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[jsxRuntime.jsx("div",{className:B("p-3 rounded-full transition",a?"bg-teal-600 text-white":"bg-gray-100 text-teal-600 hover:bg-teal-100"),children:jsxRuntime.jsx(lucideReact.FileText,{size:24})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-base font-medium text-gray-700 mb-1",children:a?"D\xE9posez votre PDF ici":"Glissez-d\xE9posez votre PDF"}),jsxRuntime.jsxs("p",{className:"text-sm text-gray-500",children:["ou"," ",jsxRuntime.jsx("span",{className:"text-teal-600 font-medium hover:underline",children:"cliquez pour parcourir"})]}),jsxRuntime.jsx("p",{className:"text-xs text-gray-400 mt-2",children:"Format accept\xE9 : PDF uniquement"})]})]})})]}),(s||p||u==="loading"||u==="error")&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-3 bg-white border border-gray-200 rounded-lg",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-3",children:[jsxRuntime.jsx("div",{className:"p-2 bg-red-50 rounded-lg",children:jsxRuntime.jsx(lucideReact.FileText,{size:20,className:"text-red-600"})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-gray-800 truncate",children:s?.name}),(s?.size??p)&&jsxRuntime.jsx("p",{className:"text-sm text-gray-500",children:s?.size?M(s.size):""})]})]}),jsxRuntime.jsxs("div",{className:"flex space-x-2",children:[s&&jsxRuntime.jsx("button",{type:"button",onClick:()=>window.open(s.url,"_blank"),className:"p-2 hover:bg-teal-50 rounded-lg transition-colors",title:"Ouvrir dans un nouvel onglet",children:jsxRuntime.jsx(lucideReact.Eye,{size:20,className:"text-teal-600"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{G();},className:"p-2 hover:bg-red-50 rounded-lg transition-colors disabled:opacity-60",title:"Supprimer",disabled:V,children:V?jsxRuntime.jsx(lucideReact.Loader2,{size:20,className:"animate-spin text-red-500"}):jsxRuntime.jsx(lucideReact.Trash2,{size:20,className:"text-red-500"})})]})]}),u==="loading"?jsxRuntime.jsxs("div",{className:"border border-dashed border-gray-200 rounded-lg bg-white p-6 text-center text-sm text-gray-500 flex flex-col items-center gap-3",children:[jsxRuntime.jsx(lucideReact.Loader2,{size:24,className:"animate-spin text-teal-600"}),jsxRuntime.jsx("span",{children:"G\xE9n\xE9ration de l'aper\xE7u en cours\u2026"})]}):p?jsxRuntime.jsx("div",{className:"border border-gray-200 rounded-lg overflow-hidden bg-gray-50",children:jsxRuntime.jsx("iframe",{src:p,className:"w-full h-96",title:"Aper\xE7u PDF"})}):jsxRuntime.jsx("div",{className:"border border-dashed border-gray-200 rounded-lg bg-white p-6 text-center text-sm text-gray-500",children:x??"Aper\xE7u indisponible. Utilisez le bouton \xAB Ouvrir \xBB pour consulter le PDF."})]}),N&&jsxRuntime.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-600",children:N})]})})},ln=ka;var Ma=({field:e,name:t,currentLang:o="fr",className:r,defaultValue:n})=>{let{setValue:i}=reactHookForm.useFormContext(),[a,l]=Me.useState(false),[s,d]=Me.useState(null),[p,c]=Me.useState(null),[u,m]=Me.useState(0),[x,g]=Me.useState(null),F=Me.useRef(null),T=Me.useRef(null),y=Me.useRef([]),v=Me.useRef(null),k=t??e.fieldName.toString(),P=Me.useRef(false),{uploadFile:R,deleteFile:I,isUploading:O,isDeleting:V,error:E,resetError:A,hasUploadSupport:L,hasDeleteSupport:b}=ce(e.fileToBucketManage),N=x??E??null;Me.useEffect(()=>{typeof n=="string"&&n.trim().length>0&&(d(n),c({url:n,filename:H(n)}),P.current||(i(k,n,{shouldValidate:false,shouldTouch:false}),P.current=true));},[n,k,i]),Me.useEffect(()=>()=>{f(),F.current&&F.current.state!=="inactive"&&F.current.stop(),T.current&&T.current.pause();},[]);let f=()=>{v.current&&(clearInterval(v.current),v.current=null);},h=D=>{let $=Math.floor(D/60),G=Math.floor(D%60);return `${$}:${G.toString().padStart(2,"0")}`},C=async()=>{if(typeof navigator>"u"||!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia){console.error("L'API mediaDevices.getUserMedia n'est pas disponible dans ce contexte."),alert("L'enregistrement audio n'est pas pris en charge par votre navigateur ou ce contexte (HTTPS requis).");return}A(),g(null);try{let D=await navigator.mediaDevices.getUserMedia({audio:!0}),$=new MediaRecorder(D);F.current=$,y.current=[],$.ondataavailable=G=>{G.data.size>0&&y.current.push(G.data);},$.onstop=async()=>{let G=new Blob(y.current,{type:"audio/webm"});if(!L){g("Configuration d'upload manquante pour ce champ (fileToBucketManage)."),D.getTracks().forEach(z=>z.stop()),f();return}let _=URL.createObjectURL(G);d(_),c(null);try{let z=await R({file:G,fallbackFilename:`voice-${Date.now()}.webm`});d(z.url),c({url:z.url,filename:z.filename??H(z.url)}),i(k,z.url,{shouldValidate:!0,shouldTouch:!0}),URL.revokeObjectURL(_);}catch(z){let ne=z instanceof Error?z.message:"\xC9chec du t\xE9l\xE9versement de l'enregistrement.";g(ne);}D.getTracks().forEach(z=>z.stop()),f();},$.start(),l(!0),m(0),v.current=setInterval(()=>{m(G=>G+1);},1e3);}catch(D){console.error("Erreur d'acc\xE8s au microphone:",D),alert("Impossible d'acc\xE9der au microphone. V\xE9rifiez les permissions.");}},M=()=>{F.current&&a&&(F.current.stop(),l(false),f());},S=async()=>{if(A(),g(null),p&&b)try{await I({filename:p.filename??H(p.url??""),fileUrl:p.url});}catch(D){let $=D instanceof Error?D.message:"\xC9chec de la suppression de l'enregistrement distant.";g($);return}s&&s.startsWith("blob:")&&URL.revokeObjectURL(s),d(null),c(null),m(0),i(k,null,{shouldValidate:true,shouldTouch:true});},w=()=>{T.current&&(T.current.paused?T.current.play():T.current.pause());};return jsxRuntime.jsx(W,{field:e,currentLang:o,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[!s&&jsxRuntime.jsx("div",{className:B("relative border-2 border-dashed rounded-lg cursor-pointer transition-all duration-300 ease-in-out",a?"border-red-500 bg-red-50":"border-gray-300 hover:border-teal-400 hover:bg-gray-50",r),children:jsxRuntime.jsx("div",{className:"p-8 text-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[jsxRuntime.jsx("button",{type:"button",onClick:a?M:C,className:B("p-4 rounded-full transition-all duration-300",a?"bg-red-600 text-white animate-pulse":"bg-teal-600 text-white hover:bg-teal-700"),disabled:O,children:a?jsxRuntime.jsx(lucideReact.Mic,{size:32}):jsxRuntime.jsx(lucideReact.MicOff,{size:32})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-base font-medium text-gray-700 mb-1",children:a?"Enregistrement en cours...":"Enregistrer un message vocal"}),a&&jsxRuntime.jsx("p",{className:"text-lg font-bold text-red-600",children:h(u)}),!a&&jsxRuntime.jsx("p",{className:"text-sm text-gray-500",children:"Cliquez sur le bouton pour commencer"})]})]})})}),s&&jsxRuntime.jsx("div",{className:"space-y-3",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-4 bg-white border border-gray-200 rounded-lg",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-3",children:[jsxRuntime.jsx("button",{type:"button",onClick:w,className:"p-2 bg-teal-600 text-white rounded-full hover:bg-teal-700 transition-colors disabled:opacity-60",disabled:!s,children:jsxRuntime.jsx(lucideReact.Play,{size:20})}),jsxRuntime.jsx("audio",{ref:T,src:s??void 0,onTimeUpdate:D=>{let $=D.currentTarget;$.duration&&m($.currentTime);}}),jsxRuntime.jsx("span",{className:"text-sm text-gray-700 font-medium",children:h(u)})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[O&&jsxRuntime.jsx(lucideReact.Loader2,{size:18,className:"animate-spin text-teal-600"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{S();},className:"p-2 hover:bg-red-50 rounded-lg transition-colors disabled:opacity-60",disabled:V,children:V?jsxRuntime.jsx(lucideReact.Loader2,{size:18,className:"animate-spin text-red-500"}):jsxRuntime.jsx(lucideReact.Trash2,{size:18,className:"text-red-500"})})]})]})}),N&&jsxRuntime.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-600",children:N})]})})},un=Ma;var Ua=({field:e,name:t,currentLang:o="fr",className:r,defaultValue:n})=>{let{setValue:i}=reactHookForm.useFormContext(),[a,l]=Me.useState(false),[s,d]=Me.useState(null),[p,c]=Me.useState(null),u=Me.useRef(null),m=t??e.fieldName.toString(),x=Me.useRef(false),{uploadFile:g,deleteFile:F,isUploading:T,isDeleting:y,error:v,resetError:k,hasUploadSupport:P,hasDeleteSupport:R}=ce(e.fileToBucketManage),I=p??v??null;Me.useEffect(()=>{typeof n=="string"&&n.trim().length>0&&(d({url:n,name:H(n)??n,bucketFilename:H(n)??void 0}),x.current||(i(m,n,{shouldValidate:false,shouldTouch:false}),x.current=true));},[n,m,i]);let O=f=>{if(f===0)return "0 Bytes";let h=1024,C=["Bytes","KB","MB","GB"],M=Math.floor(Math.log(f)/Math.log(h));return parseFloat((f/Math.pow(h,M)).toFixed(2))+" "+C[M]},V=f=>{switch(f.split(".").pop()?.toLowerCase()){case "doc":case "docx":return "\u{1F4DD}";case "xls":case "xlsx":return "\u{1F4CA}";case "ppt":case "pptx":return "\u{1F4CA}";default:return "\u{1F4C4}"}},E=f=>{f.preventDefault(),f.stopPropagation(),l(f.type==="dragenter"||f.type==="dragover");},A=f=>{f.preventDefault(),f.stopPropagation(),l(false),f.dataTransfer.files&&f.dataTransfer.files.length>0&&L(f.dataTransfer.files[0]);},L=async f=>{if(!P){c("Configuration d'upload manquante pour ce champ (fileToBucketManage).");return}k(),c(null);try{let h=await g({file:f});d({url:h.url,name:h.originalName??h.filename??H(h.url)??f.name,size:f.size,type:f.type,bucketFilename:h.filename??H(h.url)}),i(m,h.url,{shouldValidate:!0,shouldTouch:!0});}catch(h){let C=h instanceof Error?h.message:"\xC9chec de l'upload du document.";c(C);}},b=f=>{f.target.files&&f.target.files.length>0&&L(f.target.files[0]);},N=async()=>{if(k(),c(null),s&&R)try{await F({filename:s.bucketFilename??H(s.url??"")??void 0,fileUrl:s.url});}catch(f){let h=f instanceof Error?f.message:"\xC9chec de la suppression du fichier distant.";c(h);return}d(null),i(m,null,{shouldValidate:true,shouldTouch:true}),u.current&&(u.current.value="");};return jsxRuntime.jsx(W,{field:e,currentLang:o,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[!s&&jsxRuntime.jsxs("div",{className:B("relative border-2 border-dashed rounded-lg cursor-pointer transition-all duration-300 ease-in-out",a?"border-teal-500 bg-teal-50 scale-[1.02]":"border-gray-300 hover:border-teal-400 hover:bg-gray-50",r,T&&"pointer-events-none opacity-60"),onDragEnter:E,onDragLeave:E,onDragOver:E,onDrop:A,onClick:()=>u.current?.click(),children:[jsxRuntime.jsx("input",{type:"file",accept:".doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.pdf",ref:u,onChange:b,className:"hidden"}),jsxRuntime.jsx("div",{className:"p-8 text-center",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[jsxRuntime.jsx("div",{className:B("p-3 rounded-full transition",a?"bg-teal-600 text-white":"bg-gray-100 text-teal-600 hover:bg-teal-100"),children:jsxRuntime.jsx(lucideReact.UploadCloud,{size:24})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-base font-medium text-gray-700 mb-1",children:a?"D\xE9posez votre document ici":"Glissez-d\xE9posez votre document"}),jsxRuntime.jsxs("p",{className:"text-sm text-gray-500",children:["ou"," ",jsxRuntime.jsx("span",{className:"text-teal-600 font-medium hover:underline",children:"cliquez pour parcourir"})]}),jsxRuntime.jsx("p",{className:"text-xs text-gray-400 mt-2",children:"Formats accept\xE9s : Word, Excel, PowerPoint, TXT, PDF"})]})]})})]}),s&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-4 bg-white border border-gray-200 rounded-lg hover:shadow-sm transition-shadow",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-3",children:[jsxRuntime.jsx("div",{className:"text-2xl",children:V(s.name)}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("p",{className:"font-medium text-gray-800 truncate",children:s.name}),s.size&&jsxRuntime.jsx("p",{className:"text-sm text-gray-500",children:O(s.size)})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>window.open(s.url,"_blank"),className:"p-2 hover:bg-teal-50 rounded-full transition-colors",children:jsxRuntime.jsx(lucideReact.ExternalLink,{size:18,className:"text-teal-600"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{N();},className:"p-2 hover:bg-red-100 rounded-full transition-colors disabled:opacity-60",disabled:y,children:y?jsxRuntime.jsx(lucideReact.Loader2,{size:18,className:"animate-spin text-red-500"}):jsxRuntime.jsx(lucideReact.Trash2,{size:18,className:"text-red-500"})})]})]}),I&&jsxRuntime.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 px-3 py-2 text-sm text-red-600",children:I})]})})},pn=Ua;var sl=({field:e,name:t,currentLang:o="fr",className:r,defaultValue:n})=>{let{setValue:i}=reactHookForm.useFormContext(),a=t??e.fieldName.toString(),l=react.useEditor({extensions:[Wa__default.default.configure({heading:{levels:[1,2,3]}}),qa__default.default.configure({inline:true,allowBase64:true}),ja__default.default.configure({openOnClick:false,HTMLAttributes:{target:"_blank",rel:"noopener noreferrer"}}),Ka__default.default.configure({placeholder:"\xC9crivez votre texte ici... (Utilisez le menu pour formater)"})],content:n||"",onUpdate:({editor:p})=>{let c=p.getHTML();i(a,c,{shouldValidate:true,shouldTouch:true});}}),s=Me.useCallback(()=>{let p=window.prompt("Entrez l'URL de l'image:");p&&l&&l.chain().focus().setImage({src:p}).run();},[l]),d=Me.useCallback(()=>{if(!l)return;let p=l.getAttributes("link").href,c=window.prompt("URL du lien:",p);if(c!==null){if(c===""){l.chain().focus().extendMarkRange("link").unsetLink().run();return}l.chain().focus().extendMarkRange("link").setLink({href:c}).run();}},[l]);return l?jsxRuntime.jsx(W,{field:e,currentLang:o,children:jsxRuntime.jsxs("div",{className:`border border-slate-200 rounded-lg overflow-hidden shadow-sm ${r||""}`,children:[jsxRuntime.jsxs("div",{className:"border-b border-slate-100 bg-slate-50 p-2 flex flex-wrap items-center gap-0.5",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>l.chain().focus().toggleBold().run(),className:`p-2 rounded hover:bg-gray-200 transition-colors ${l.isActive("bold")?"bg-teal-100 text-teal-600":"text-gray-700"}`,children:jsxRuntime.jsx(lucideReact.Bold,{size:18})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>l.chain().focus().toggleItalic().run(),className:`p-2 rounded hover:bg-gray-200 transition-colors ${l.isActive("italic")?"bg-teal-100 text-teal-600":"text-gray-700"}`,children:jsxRuntime.jsx(lucideReact.Italic,{size:18})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>l.chain().focus().toggleStrike().run(),className:`p-2 rounded hover:bg-gray-200 transition-colors ${l.isActive("strike")?"bg-teal-100 text-teal-600":"text-gray-700"}`,children:jsxRuntime.jsx(lucideReact.Underline,{size:18})}),jsxRuntime.jsx("div",{className:"w-px h-6 bg-gray-300 mx-1"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>l.chain().focus().toggleHeading({level:1}).run(),className:`p-2 rounded hover:bg-gray-200 transition-colors ${l.isActive("heading",{level:1})?"bg-teal-100 text-teal-600":"text-gray-700"}`,children:jsxRuntime.jsx(lucideReact.Heading1,{size:18})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>l.chain().focus().toggleHeading({level:2}).run(),className:`p-2 rounded hover:bg-gray-200 transition-colors ${l.isActive("heading",{level:2})?"bg-teal-100 text-teal-600":"text-gray-700"}`,children:jsxRuntime.jsx(lucideReact.Heading2,{size:18})}),jsxRuntime.jsx("div",{className:"w-px h-6 bg-gray-300 mx-1"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>l.chain().focus().toggleBulletList().run(),className:`p-2 rounded hover:bg-gray-200 transition-colors ${l.isActive("bulletList")?"bg-teal-100 text-teal-600":"text-gray-700"}`,children:jsxRuntime.jsx(lucideReact.List,{size:18})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>l.chain().focus().toggleOrderedList().run(),className:`p-2 rounded hover:bg-gray-200 transition-colors ${l.isActive("orderedList")?"bg-teal-100 text-teal-600":"text-gray-700"}`,children:jsxRuntime.jsx(lucideReact.ListOrdered,{size:18})}),jsxRuntime.jsx("div",{className:"w-px h-6 bg-gray-300 mx-1"}),jsxRuntime.jsx("button",{type:"button",onClick:d,className:`p-2 rounded hover:bg-gray-200 transition-colors ${l.isActive("link")?"bg-teal-100 text-teal-600":"text-gray-700"}`,children:jsxRuntime.jsx(lucideReact.Link,{size:18})}),jsxRuntime.jsx("button",{type:"button",onClick:s,className:"p-2 rounded hover:bg-gray-200 transition-colors text-gray-700",children:jsxRuntime.jsx(lucideReact.Image,{size:18})})]}),jsxRuntime.jsx("div",{className:"prose prose-sm max-w-none",children:jsxRuntime.jsx(react.EditorContent,{editor:l,className:"p-4 min-h-48 focus-within:outline-none prose-headings:text-teal-700 prose-strong:text-teal-600"})})]})}):null},hn=sl;var dl=({field:e,currentLang:t="fr",className:o="",name:r,formValues:n,allSections:i=[],currentSectionIndex:a=0,showControlButtons:l=false,hasFilledData:s=false,basedOnValue:d=0,onOpenModal:p,onOpenEdit:c,onOpenView:u,dependentFieldNameTransformed:m})=>{let x=r??e.fieldName,g=n?.[x],F=()=>l?jsxRuntime.jsx("div",{className:"flex justify-end mb-4 space-x-2",children:!s&&d>0?jsxRuntime.jsx(Pt,{content:"Remplir les champs du groupe r\xE9p\xE9table",children:jsxRuntime.jsxs(le,{type:"button",numerator:15,onClick:y=>{y.preventDefault(),y.stopPropagation(),p?.();},children:["Suivant",jsxRuntime.jsx(lucideReact.ArrowRight,{size:20})]})}):s?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Pt,{content:"Modifier les donn\xE9es du groupe",children:jsxRuntime.jsx(le,{type:"button",numerator:15,onClick:y=>{y.preventDefault(),y.stopPropagation(),c?.();},children:jsxRuntime.jsx(lucideReact.Edit,{size:20})})}),jsxRuntime.jsx(Pt,{content:"Voir les donn\xE9es en lecture seule",children:jsxRuntime.jsx(le,{type:"button",numerator:15,onClick:y=>{y.preventDefault(),y.stopPropagation(),u?.();},children:jsxRuntime.jsx(lucideReact.Eye,{size:20})})})]}):null}):null;return jsxRuntime.jsxs("div",{children:[(()=>{switch(e.fieldType){case "text":return jsxRuntime.jsx(Jo,{field:e,currentLang:t,className:o,name:r,defaultValue:g,allSections:i,currentSectionIndex:a});case "textarea":return jsxRuntime.jsx(Ho,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "password":return jsxRuntime.jsx(Lo,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "number":return jsxRuntime.jsx(Ao,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "radio":return jsxRuntime.jsx(zo,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "checkbox":return jsxRuntime.jsx(uo,{field:{...e,selectOptions:e.selectOptions??[]},currentLang:t,className:o,name:r,defaultValue:g});case "bool":return jsxRuntime.jsx(lo,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "dropdown":return jsxRuntime.jsx(So,{field:{...e,selectOptions:e.selectOptions??[]},currentLang:t,className:o,name:r,defaultValue:g,dependentFieldNameTransformed:m});case "file":return jsxRuntime.jsx(Io,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "date":return jsxRuntime.jsx(vo,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "IMAGE":return jsxRuntime.jsx(Zo,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "VIDEO":return jsxRuntime.jsx(tn,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "AUDIO":return jsxRuntime.jsx(on,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "PDF":return jsxRuntime.jsx(ln,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "VOICE":return jsxRuntime.jsx(un,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "DOCUMENT":return jsxRuntime.jsx(pn,{field:e,currentLang:t,className:o,name:r,defaultValue:g});case "TIP_TAP_DOC_TEXT":return jsxRuntime.jsx(hn,{field:e,currentLang:t,className:o,name:r,defaultValue:g});default:return jsxRuntime.jsxs("div",{className:"text-red-500 font-semibold",children:["Champ non support\xE9 : ",jsxRuntime.jsx("code",{children:e.fieldType})]})}})(),F()]})},De=dl;var bl=({isViewMode:e,hasFilledData:t,fieldName:o,basedOnValue:r,onClose:n,onExpandAll:i,onCollapseAll:a})=>{let l=()=>e?jsxRuntime.jsx(lucideReact.Eye,{className:"h-4 w-4 sm:h-5 sm:w-5"}):t?jsxRuntime.jsx(lucideReact.Edit,{className:"h-4 w-4 sm:h-5 sm:w-5"}):jsxRuntime.jsx(lucideReact.Plus,{className:"h-4 w-4 sm:h-5 sm:w-5"}),s=()=>e?"Visualisation":t?"Modifier":"Remplir";return jsxRuntime.jsxs("div",{className:"bg-gradient-to-r from-[#008080] to-[#006666] p-4 sm:p-6 text-white",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 sm:space-x-3",children:[jsxRuntime.jsx("div",{className:"p-1.5 sm:p-2 bg-white/20 rounded-lg",children:l()}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("h3",{className:"text-lg sm:text-xl font-bold",children:[s()," ",o]}),jsxRuntime.jsxs("p",{className:"text-teal-100 text-xs sm:text-sm",children:[r," s\xE9rie",r>1?"s":""," \xE0 ",e?"visualiser":"compl\xE9ter"]})]})]}),jsxRuntime.jsx("button",{type:"button",onClick:n,className:"p-1.5 sm:p-2 hover:bg-white/20 rounded-lg transition-colors",children:jsxRuntime.jsx(lucideReact.X,{className:"h-4 w-4 sm:h-5 sm:w-5"})})]}),jsxRuntime.jsxs("div",{className:"mt-4 flex space-x-2",children:[jsxRuntime.jsxs("button",{type:"button",onClick:i,className:"px-3 py-1.5 bg-white/20 hover:bg-white/30 rounded-lg text-sm font-medium transition-colors flex items-center space-x-1",children:[jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-3 w-3"}),jsxRuntime.jsx("span",{children:"Tout ouvrir"})]}),jsxRuntime.jsxs("button",{type:"button",onClick:a,className:"px-3 py-1.5 bg-white/20 hover:bg-white/30 rounded-lg text-sm font-medium transition-colors flex items-center space-x-1",children:[jsxRuntime.jsx(lucideReact.ChevronUp,{className:"h-3 w-3"}),jsxRuntime.jsx("span",{children:"Tout fermer"})]})]})]})},bn=bl;var At=(e,t="fr")=>{let{watch:o,setValue:r}=reactHookForm.useFormContext(),n=o(),i=Me.useMemo(()=>e.filter(l=>(l.fieldType==="dropdown"||l.fieldType==="radio"||l.fieldType==="checkbox")&&l.selectOptions?.some(s=>{let d=typeof s.value=="string"?s.value:String(s.value);return d==="autre"||d==="autres"})),[e]),a=Me.useMemo(()=>{let l={};return i.forEach(s=>{let d=s.fieldName,p=n[d],c=`autre_${d}`,u=false;if(s.fieldType==="checkbox"?Array.isArray(p)&&(u=p.includes("autre")||p.includes("autres")):u=p==="autre"||p==="autres",u){let m=U(s.label,t),x=typeof s.label=="string"?`Autre ${m}`:Object.keys(s.label).reduce((y,v)=>(y[v]=`Autre ${U(s.label,v)}`,y),{}),g=[];s.validations?.some(y=>y.validationType==="required")&&g.push({validationType:"required",errMsg:"Veuillez pr\xE9ciser votre choix"});let T={formFieldId:`autre_${s.formFieldId}`,fieldName:c,fieldType:"text",label:x,response:{responseValue:n[c]||""},validations:g.length>0?g:void 0,placeholder:s.placeholder,width:s.width||"half"};l[d]=T;}}),l},[i,n,t]);return Me.useEffect(()=>{i.forEach(l=>{let s=l.fieldName,d=n[s],p=`autre_${s}`,c=false;l.fieldType==="checkbox"?Array.isArray(d)&&(c=d.includes("autre")||d.includes("autres")):c=d==="autre"||d==="autres",!c&&n[p]&&r(p,"",{shouldValidate:false,shouldTouch:false});});},[n,i,r]),a};var Lt=(e,t="fr")=>{let{watch:o,setValue:r}=reactHookForm.useFormContext(),n=o(),i=Me.useMemo(()=>e.filter(l=>(l.fieldType==="dropdown"||l.fieldType==="radio"||l.fieldType==="checkbox")&&l.detailInfos&&Object.keys(l.detailInfos).length>0),[e]),a=Me.useMemo(()=>{let l={};return i.forEach(s=>{let d=s.fieldName,p=n[d],c=[];if(s.detailInfos){if(s.fieldType==="checkbox")Array.isArray(p)&&p.forEach(u=>{let m=s.detailInfos[u];if(m){let x=m.label?U(m.label,t):void 0,g=m.formFields.map(F=>{let T=`${d}_${u}_${F.fieldName}`;return {...F,formFieldId:`${s.formFieldId}_${u}_${F.formFieldId}`,fieldName:T,response:{responseValue:n[T]||(F.response?.responseValue??"")},width:F.width||s.width||"half"}});c.push({groupLabel:x,fields:g,optionValue:u});}});else if(p&&typeof p=="string"){let u=s.detailInfos[p];if(u){let m=u.label?U(u.label,t):void 0,x=u.formFields.map(g=>{let F=`${d}_${p}_${g.fieldName}`;return {...g,formFieldId:`${s.formFieldId}_${p}_${g.formFieldId}`,fieldName:F,response:{responseValue:n[F]||(g.response?.responseValue??"")},width:g.width||s.width||"half"}});c.push({groupLabel:m,fields:x,optionValue:p});}}c.length>0&&(l[d]=c);}}),l},[i,n,t]);return Me.useEffect(()=>{i.forEach(l=>{let s=l.fieldName,d=n[s];if(l.detailInfos)if(l.fieldType==="checkbox")Array.isArray(d)?Object.keys(l.detailInfos).forEach(p=>{if(!d.includes(p)){let c=l.detailInfos[p];c&&c.formFields.forEach(u=>{let m=`${s}_${p}_${u.fieldName}`;n[m]&&r(m,"",{shouldValidate:false,shouldTouch:false});});}}):Object.keys(l.detailInfos).forEach(p=>{let c=l.detailInfos[p];c&&c.formFields.forEach(u=>{let m=`${s}_${p}_${u.fieldName}`;n[m]&&r(m,"",{shouldValidate:false,shouldTouch:false});});});else {let p=d&&typeof d=="string"?d:null;Object.keys(l.detailInfos).forEach(c=>{if(c!==p){let u=l.detailInfos[c];u&&u.formFields.forEach(m=>{let x=`${s}_${c}_${m.fieldName}`;n[x]&&r(x,"",{shouldValidate:false,shouldTouch:false});});}});}});},[n,i,r]),a};var Rl=({index:e,repeatGroup:t,existingGroupData:o,buildTempFieldName:r,buildNestedGroupFieldName:n,buildNestedChildFieldName:i,isExpanded:a,isViewMode:l,currentLang:s,formValues:d,onToggle:p,seriesRef:c})=>{let{getValues:u,watch:m}=reactHookForm.useFormContext(),x=Kr(t.formFields,t.fieldName,e),g=Me.useMemo(()=>x.map(v=>({...v,fieldName:r(v.fieldName,e),formFieldId:`${v.formFieldId}_${e}`})),[x,e,r]),F=At(g,s),T=Lt(g,s),y=Me.useMemo(()=>{let v=[];return x.forEach(k=>{let P=r(k.fieldName,e);v.push({field:k,isOtherField:false});let R=F[P];if(R){let O={...R,fieldName:`autre_${P}`};v.push({field:O,isOtherField:true,originalFieldName:k.fieldName});}let I=T[P];I&&I.length>0&&I.forEach(O=>{let V=O.fields.map(E=>({...E}));v.push({field:k,isOtherField:false,isDetailGroup:true,detailGroup:{...O,fields:V},originalFieldName:k.fieldName});});}),v},[x,F,T,e,r]);return jsxRuntime.jsxs("div",{className:"group relative bg-gradient-to-br from-gray-50 to-gray-100 rounded-lg sm:rounded-xl border border-gray-200 hover:border-[#008080] transition-all duration-300 overflow-hidden",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>p(e),className:"w-full p-4 sm:p-6 flex items-center justify-between bg-white/50 hover:bg-white/70 transition-colors border-b border-gray-200",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-3",children:[jsxRuntime.jsxs("div",{className:"bg-gradient-to-r from-[#008080] to-[#006666] text-white px-2 sm:px-3 py-1 rounded-full text-xs sm:text-sm font-semibold shadow-lg",children:["S\xE9rie ",e+1]}),jsxRuntime.jsx("span",{className:"text-sm text-gray-600 font-medium",children:a?"Cliquez pour fermer":"Cliquez pour ouvrir"})]}),jsxRuntime.jsx("div",{className:"flex items-center space-x-2 text-[#008080]",children:a?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"h-5 w-5"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-5 w-5"})})]}),jsxRuntime.jsx("div",{ref:c,className:`${a?"":"h-0 opacity-0"} overflow-hidden`,children:jsxRuntime.jsx("div",{className:"p-4 sm:p-6 grid gap-3 sm:gap-4 grid-cols-1 sm:grid-cols-2",children:y.map(({field:v,isOtherField:k,isDetailGroup:P,detailGroup:R,originalFieldName:I})=>{if(P&&R)return jsxRuntime.jsxs("div",{className:"col-span-1 sm:col-span-2 mt-4 p-4 bg-gray-50 rounded-lg border border-gray-200",children:[R.groupLabel&&jsxRuntime.jsx("h4",{className:"font-semibold text-gray-700 mb-3 text-sm",children:R.groupLabel}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:R.fields.map(b=>{let N=b.fieldName,f=b.fieldName.split("_").slice(-1)[0],h=I?`${I}_${R.optionValue}_${f}`:N,C=o[h]??"",M={...d,[N]:C};return jsxRuntime.jsx("div",{className:"space-y-2",children:l?jsxRuntime.jsxs("div",{className:"bg-white/80 p-3 sm:p-4 rounded-lg border border-gray-200 shadow-sm",children:[jsxRuntime.jsx("div",{className:"text-xs sm:text-sm font-medium text-gray-600 mb-1",children:b.fieldName}),jsxRuntime.jsx("div",{className:"text-gray-900 font-medium text-sm sm:text-base",children:u(N)||jsxRuntime.jsx("span",{className:"text-gray-400 italic",children:"Non renseign\xE9"})})]}):jsxRuntime.jsx("div",{className:"bg-white/80 rounded-lg p-1 border border-gray-200 shadow-sm hover:shadow-md transition-shadow",children:jsxRuntime.jsx(De,{field:b,name:N,currentLang:s,formValues:M,showControlButtons:false})})},N)})})]},`detail-group-${R.optionValue}-${e}`);let O=k?v.fieldName:r(v.fieldName,e),V=k&&I?`autre_${I}`:v.fieldName,E=k&&I?o[`autre_${I}`]??"":o[V]??"",A={...d,[O]:E},L=!k&&v.dynamicFilterRule?r(v.dynamicFilterRule.dependentFieldName,e):void 0;if(!k&&v.repeatGroup&&v.repeatRule){let b=Math.max(0,Number(m(O))||0),N=n(v.repeatGroup.fieldName,e),f=Array.isArray(o[v.repeatGroup.fieldName])?o[v.repeatGroup.fieldName]:[];return jsxRuntime.jsxs("div",{className:"space-y-4 sm:col-span-2",children:[jsxRuntime.jsx("div",{className:"bg-white/80 rounded-lg p-1 border border-gray-200 shadow-sm hover:shadow-md transition-shadow",children:jsxRuntime.jsx(De,{field:v,name:O,currentLang:s,formValues:A,showControlButtons:false,dependentFieldNameTransformed:L})}),b>0&&jsxRuntime.jsx("div",{className:"space-y-3",children:Array.from({length:b},(h,C)=>{let M=f[C]??{};return jsxRuntime.jsxs("div",{className:"border border-teal-200 rounded-lg bg-white/70 shadow-sm",children:[jsxRuntime.jsx("div",{className:"px-3 sm:px-4 py-2 bg-teal-50 border-b border-teal-100 text-sm sm:text-base font-semibold text-teal-700",children:s==="fr"?`D\xE9pendant ${C+1}`:`Dependant ${C+1}`}),jsxRuntime.jsx("div",{className:"p-3 sm:p-4 grid gap-3 sm:gap-4 grid-cols-1 sm:grid-cols-2",children:v.repeatGroup.formFields.map(S=>{let w=i(v.repeatGroup.fieldName,e,S.fieldName,C),D={...d,[w]:M?.[S.fieldName]??""},$=n(v.repeatGroup.fieldName,e),G=S.dynamicFilterRule?`${$}_${S.dynamicFilterRule.dependentFieldName}_${C}`:void 0;return jsxRuntime.jsx("div",{className:"space-y-2",children:l?jsxRuntime.jsxs("div",{className:"bg-white/80 p-3 sm:p-4 rounded-lg border border-gray-200 shadow-sm",children:[jsxRuntime.jsx("div",{className:"text-xs sm:text-sm font-medium text-gray-600 mb-1",children:S.fieldName}),jsxRuntime.jsx("div",{className:"text-gray-900 font-medium text-sm sm:text-base",children:u(w)||jsxRuntime.jsx("span",{className:"text-gray-400 italic",children:"Non renseign\xE9"})})]}):jsxRuntime.jsx("div",{className:"bg-white/80 rounded-lg p-1 border border-gray-200 shadow-sm hover:shadow-md transition-shadow",children:jsxRuntime.jsx(De,{field:S,name:w,currentLang:s,formValues:D,showControlButtons:false,dependentFieldNameTransformed:G})})},w)})})]},`${N}_row_${C}`)})})]},`${O}_nested`)}return jsxRuntime.jsx("div",{className:"space-y-2",children:l?jsxRuntime.jsxs("div",{className:"bg-white/80 p-3 sm:p-4 rounded-lg border border-gray-200 shadow-sm",children:[jsxRuntime.jsx("div",{className:"text-xs sm:text-sm font-medium text-gray-600 mb-1",children:v.fieldName}),jsxRuntime.jsx("div",{className:"text-gray-900 font-medium text-sm sm:text-base",children:u(O)||jsxRuntime.jsx("span",{className:"text-gray-400 italic",children:"Non renseign\xE9"})})]}):jsxRuntime.jsx("div",{className:"bg-white/80 rounded-lg p-1 border border-gray-200 shadow-sm hover:shadow-md transition-shadow",children:jsxRuntime.jsx(De,{field:v,name:O,currentLang:s,formValues:A,showControlButtons:false,dependentFieldNameTransformed:L})})},O)})})})]})},xn=Rl;var Pl=({children:e,className:t,onClick:o,...r})=>{let{width:n,height:i,borderRadius:a,pressed:l,isMobile:s,transform:d,handlers:p}=Xe(),c=jsxRuntime.jsx("span",{className:"inline-flex items-center justify-center gap-2 font-medium text-sm",style:{color:"var(--fe-primary)"},children:e});return jsxRuntime.jsx("button",{style:{width:`${n}px`,height:`${i}px`,borderRadius:`${a}px`,borderColor:"var(--fe-primary)",transform:d,transition:"transform 0.2s ease, background-color 0.15s ease",userSelect:"none",WebkitTapHighlightColor:"transparent"},className:B("inline-flex items-center justify-center px-6","bg-white border text-sm font-medium whitespace-nowrap","shadow-sm","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--fe-primary)] focus-visible:ring-offset-2","disabled:pointer-events-none disabled:opacity-50","cursor-pointer overflow-hidden relative group","hover:bg-[var(--fe-primary-light)]",t),...p,onClick:o,...r,children:jsxRuntime.jsxs("span",{className:"relative overflow-hidden w-full h-full flex items-center justify-center",children:[jsxRuntime.jsx("span",{className:B("flex items-center justify-center transition-transform duration-300 w-full h-full",!s&&"group-hover:translate-x-full"),style:s?{transform:l?"translateX(100%)":"translateX(0)"}:{},children:c}),jsxRuntime.jsx("span",{className:B("flex items-center justify-center absolute top-0 w-full h-full transition-transform duration-300",!s&&"group-hover:translate-x-[100%]"),style:{left:"-100%",...s?{transform:l?"translateX(100%)":"translateX(0)"}:{}},children:c})]})})},_e=Pl;var Cl=({children:e,className:t,variant:o="validation",intent:r,onClick:n,...i})=>{let a=r==="cancel"?"cancel":r==="validation"?"validation":o,{height:l,borderRadius:s,transform:d,handlers:p}=Xe(),c=a==="cancel",u=a==="red-flag";return jsxRuntime.jsx("button",{style:{height:`${l}px`,borderRadius:`${s}px`,...c?{borderColor:"var(--fe-primary)"}:u?{}:{backgroundColor:"var(--fe-primary)"},transform:d,transition:"transform 0.2s ease, opacity 0.15s ease, background-color 0.15s ease",userSelect:"none",WebkitTapHighlightColor:"transparent"},className:B("inline-flex items-center justify-center px-5","text-sm font-medium whitespace-nowrap","shadow-sm","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2","disabled:pointer-events-none disabled:opacity-50","cursor-pointer relative overflow-hidden",c&&["bg-white border","focus-visible:ring-[var(--fe-primary)]","hover:bg-[var(--fe-primary-light)]"],!c&&!u&&["text-white","focus-visible:ring-[var(--fe-primary)]","hover:opacity-90"],u&&["bg-red-600 text-white","focus-visible:ring-red-600","hover:bg-red-700"],t),...p,onClick:n,...i,children:jsxRuntime.jsx("span",{style:c?{color:"var(--fe-primary)"}:void 0,className:"inline-flex items-center justify-center gap-2",children:e})})},Tn=Cl;var El=({isViewMode:e,onClose:t,onClear:o,onSave:r})=>jsxRuntime.jsx("div",{className:"bg-gray-50 border-t border-gray-200 p-3 sm:p-6",children:jsxRuntime.jsx("div",{className:"flex flex-col sm:flex-row justify-end space-y-2 sm:space-y-0 sm:space-x-3",children:e?jsxRuntime.jsx(_e,{type:"button",onClick:t,className:"w-full sm:w-auto px-4 sm:px-6 py-2.5 text-gray-600 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors font-medium text-sm sm:text-base",children:"Fermer"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[o&&jsxRuntime.jsx(Tn,{variant:"red-flag",type:"button",onClick:o,className:"w-full sm:w-auto px-4 sm:px-6 py-2.5",children:"Effacer tout"}),jsxRuntime.jsxs(le,{type:"button",onClick:r,className:"w-full sm:w-auto px-4 sm:px-6 py-2.5 bg-gradient-to-r from-[#008080] to-[#006666] text-white rounded-lg hover:from-[#007070] hover:to-[#005555] transition-all font-medium shadow-lg hover:shadow-xl flex items-center justify-center space-x-2 text-sm sm:text-base",children:[jsxRuntime.jsx(lucideReact.Save,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:"Sauvegarder"})]})]})})}),Rn=El;var Pn=(e,t)=>{let o=Me.useRef({}),r=Me.useCallback((a,l)=>{let s=o.current[a];if(!s)return;let d=window.innerWidth<768?200:300;if(l){let p=s.scrollHeight,c=s.animate([{height:"0px",opacity:"0"},{height:`${p}px`,opacity:"1"}],{duration:d,easing:"ease-out",fill:"forwards"});c.onfinish=()=>{s.style.height="auto";};}else {let p=s.scrollHeight;s.animate([{height:`${p}px`,opacity:"1"},{height:"0px",opacity:"0"}],{duration:d,easing:"ease-in-out",fill:"forwards"});}},[]),n=Me.useCallback(()=>{let a=window.innerWidth<768,l=a?150:300,s=a?50:100;Array.from({length:t},(d,p)=>p).forEach((d,p)=>{let c=o.current[d];if(c&&!e.has(d)){let u=c.scrollHeight,m=c.animate([{height:"0px",opacity:"0"},{height:`${u}px`,opacity:"1"}],{duration:l,delay:p*s,easing:"ease-out",fill:"forwards"});m.onfinish=()=>{c.style.height="auto";};}});},[t,e]),i=Me.useCallback(()=>{let a=window.innerWidth<768,l=a?150:300,s=a?50:100;e.forEach((d,p)=>{let c=o.current[d];if(c){let u=c.scrollHeight;c.animate([{height:`${u}px`,opacity:"1"},{height:"0px",opacity:"0"}],{duration:l,delay:p*s,easing:"ease-in-out",fill:"forwards"});}});},[e]);return {seriesRefs:o,animateSeriesToggle:r,animateExpandAll:n,animateCollapseAll:i}};var Ml=({isModalOpen:e,isViewMode:t,modalRef:o,overlayRef:r,contentRef:n,expandedSeries:i,basedOnValue:a,hasFilledData:l,repeatGroup:s,currentLang:d,formValues:p,filledSeries:c,buildTempFieldName:u,buildNestedGroupFieldName:m,buildNestedChildFieldName:x,onClose:g,onClear:F,onSave:T,onToggleSeries:y,setExpandedSeries:v})=>{let{seriesRefs:k,animateSeriesToggle:P,animateExpandAll:R,animateCollapseAll:I}=Pn(i,a),O=Me.useMemo(()=>{if(!e)return [];let L=new Set;for(let b=0;b<a;b++)L.add(b);return Array.from(L).sort((b,N)=>b-N)},[e,a]);Me.useEffect(()=>{e&&v(new Set([0]));},[e,v]);let V=L=>{!i.has(L)?(y(L),setTimeout(()=>{P(L,true);},50)):(P(L,false),setTimeout(()=>y(L),300));},E=()=>{let L=Array.from({length:a},(b,N)=>N);v(new Set(L)),setTimeout(()=>{R();},100);},A=()=>{I(),setTimeout(()=>{v(new Set);},300);};return e?jsxRuntime.jsxs("div",{ref:o,className:"fixed inset-0 z-[100] flex items-center justify-center p-2 sm:p-4",children:[jsxRuntime.jsx("div",{ref:r,className:"fixed inset-0 bg-black bg-opacity-60 backdrop-blur-sm transition-opacity",onClick:g}),jsxRuntime.jsxs("div",{ref:n,className:"relative z-10 bg-white w-[90%] sm:w-auto max-w-4xl max-h-[95vh] sm:max-h-[90vh] rounded-xl shadow-xl overflow-hidden flex flex-col",children:[jsxRuntime.jsx(bn,{isViewMode:t,hasFilledData:l,fieldName:s.fieldName,basedOnValue:a,onClose:g,onExpandAll:E,onCollapseAll:A}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 custom-scrollbar",children:jsxRuntime.jsx("div",{className:"space-y-4",children:O.map(L=>jsxRuntime.jsx(xn,{index:L,repeatGroup:s,existingGroupData:c[L]??{},buildTempFieldName:u,buildNestedGroupFieldName:m,buildNestedChildFieldName:x,isExpanded:i.has(L),isViewMode:t,currentLang:d,formValues:p,onToggle:V,seriesRef:b=>{k.current[L]=b;}},L))})}),jsxRuntime.jsx(Rn,{isViewMode:t,onClose:g,onClear:F,onSave:T})]})]}):null},Cn=Ml;var kn=(e,t)=>{let{getValues:o,setValue:r,watch:n}=reactHookForm.useFormContext(),[i,a]=Me.useState(new Set),l=e.repeatGroup,s=n(e.fieldName),d=Number(s)||0,p=t?.[l.fieldName]??[],c=(P,R)=>`${l.fieldName}_${P}_${R}`,u=(P,R)=>`${l.fieldName}_${P}_${R}`,m=(P,R,I,O)=>`${u(P,R)}_${I}_${O}`,x=p.some(P=>Object.values(P||{}).some(R=>R!==""&&R!==null&&R!==void 0));return {expandedSeries:i,setExpandedSeries:a,basedOnValue:d,filledSeries:p,watchedValue:s,hasFilledData:x,repeatGroup:l,toggleSeries:P=>{let R=new Set(i);R.has(P)?R.delete(P):R.add(P),a(R);},expandAll:()=>{let P=Array.from({length:d},(R,I)=>I);a(new Set(P));},collapseAll:()=>{a(new Set);},prefillTempFields:P=>{for(let R=0;R<d;R++){let I=P[R]??{};l.formFields.forEach(O=>{let V=c(O.fieldName,R),E=I[O.fieldName];r(V,E??"",{shouldValidate:true,shouldDirty:true});let A=`autre_${V}`,L=`autre_${O.fieldName}`;if(I[L]!==void 0&&r(A,I[L]??"",{shouldValidate:true,shouldDirty:true}),O.detailInfos){let b=I[O.fieldName];if(b)if(typeof b=="string"){let N=O.detailInfos[b];N&&N.formFields.forEach(f=>{let h=`${O.fieldName}_${b}_${f.fieldName}`,C=`${V}_${b}_${f.fieldName}`;I[h]!==void 0&&r(C,I[h]??"",{shouldValidate:true,shouldDirty:true});});}else Array.isArray(b)&&b.forEach(N=>{let f=O.detailInfos[N];f&&f.formFields.forEach(h=>{let C=`${O.fieldName}_${N}_${h.fieldName}`,M=`${V}_${N}_${h.fieldName}`;I[C]!==void 0&&r(M,I[C]??"",{shouldValidate:true,shouldDirty:true});});});}if(O.repeatGroup){let b=Array.isArray(I[O.repeatGroup.fieldName])?I[O.repeatGroup.fieldName]:[];(E==null||E==="")&&b.length>0&&r(V,b.length,{shouldValidate:true,shouldDirty:true}),b.forEach((N={},f)=>{O.repeatGroup.formFields.forEach(h=>{let C=m(O.repeatGroup.fieldName,R,h.fieldName,f);r(C,N?.[h.fieldName]??"",{shouldValidate:true,shouldDirty:true});});});}});}},saveGroups:()=>{let P=[];for(let R=0;R<d;R++){let I={};l.formFields.forEach(O=>{let V=c(O.fieldName,R),E=o(V);I[O.fieldName]=E;let A=`autre_${V}`,L=o(A);if(L!=null&&L!==""&&(I[`autre_${O.fieldName}`]=L),O.detailInfos){if(O.fieldType==="checkbox"&&Array.isArray(E))E.forEach(b=>{let N=O.detailInfos[b];N&&N.formFields.forEach(f=>{let h=`${V}_${b}_${f.fieldName}`,C=o(h);C!=null&&C!==""&&(I[`${O.fieldName}_${b}_${f.fieldName}`]=C);});});else if(typeof E=="string"&&E){let b=O.detailInfos[E];b&&b.formFields.forEach(N=>{let f=`${V}_${E}_${N.fieldName}`,h=o(f);h!=null&&h!==""&&(I[`${O.fieldName}_${E}_${N.fieldName}`]=h);});}}if(O.repeatGroup){let b=Math.max(0,Number(E)||0),N=[];for(let f=0;f<b;f++){let h={};O.repeatGroup.formFields.forEach(C=>{let M=m(O.repeatGroup.fieldName,R,C.fieldName,f);h[C.fieldName]=o(M);}),N.push(h);}I[O.repeatGroup.fieldName]=N;}}),P.push(I);}r(l.fieldName,P,{shouldValidate:true,shouldDirty:true});},clearGroups:()=>{for(let P=0;P<d;P++)l.formFields.forEach(R=>{let I=c(R.fieldName,P),O=o(I),V=`autre_${I}`;if(r(V,"",{shouldValidate:true,shouldDirty:true}),R.detailInfos&&Object.keys(R.detailInfos).forEach(E=>{let A=R.detailInfos[E];A&&A.formFields.forEach(L=>{let b=`${I}_${E}_${L.fieldName}`;r(b,"",{shouldValidate:true,shouldDirty:true});});}),R.repeatGroup){let E=Math.max(0,Number(O)||0);for(let A=0;A<E;A++)R.repeatGroup.formFields.forEach(L=>{let b=m(R.repeatGroup.fieldName,P,L.fieldName,A);r(b,"",{shouldValidate:true,shouldDirty:true});});r(u(R.repeatGroup.fieldName,P),[],{shouldValidate:true,shouldDirty:true});}r(I,"",{shouldValidate:true,shouldDirty:true});});r(l.fieldName,[],{shouldValidate:true,shouldDirty:true}),r(e.fieldName,0,{shouldValidate:true,shouldDirty:true});},buildTempFieldName:c,buildNestedGroupFieldName:u,buildNestedChildFieldName:m}};var On=()=>{let[e,t]=Me.useState(false),[o,r]=Me.useState(false),[n,i]=Me.useState(false),a=Me.useRef(null),l=Me.useRef(null),s=Me.useRef(null),d=(c=false,u=true)=>{!u&&n||(r(c),t(true),u&&i(false));},p=(c=false)=>{if(!s.current||!l.current)return;c&&i(true);let u=s.current.animate([{opacity:"1",transform:"scale(1) translateY(0px)"},{opacity:"0",transform:"scale(0.9) translateY(20px)"}],{duration:150,easing:"ease-in",fill:"forwards"});l.current.animate([{opacity:"1"},{opacity:"0"}],{duration:100,delay:50,easing:"ease-in",fill:"forwards"}),u.onfinish=()=>{t(false),r(false);};};return Me.useEffect(()=>{e&&l.current&&s.current&&(l.current.animate([{opacity:"0"},{opacity:"1"}],{duration:150,easing:"ease-out",fill:"forwards"}),s.current.animate([{opacity:"0",transform:"scale(0.9) translateY(20px)"},{opacity:"1",transform:"scale(1) translateY(0px)"}],{duration:200,delay:50,easing:"ease-out",fill:"forwards"}));},[e]),Me.useEffect(()=>(document.body.style.overflow=e?"hidden":"",()=>{document.body.style.overflow="";}),[e]),{isModalOpen:e,isViewMode:o,modalRef:a,overlayRef:l,contentRef:s,openModal:d,closeModal:p,manuallyClosed:n}};var zl=({field:e,formValues:t,currentLang:o="fr"})=>{let{expandedSeries:r,setExpandedSeries:n,basedOnValue:i,filledSeries:a,watchedValue:l,hasFilledData:s,repeatGroup:d,toggleSeries:p,prefillTempFields:c,saveGroups:u,clearGroups:m,buildTempFieldName:x,buildNestedGroupFieldName:g,buildNestedChildFieldName:F}=kn(e,t),{isModalOpen:T,isViewMode:y,modalRef:v,overlayRef:k,contentRef:P,openModal:R,closeModal:I}=On();return Me.useEffect(()=>{let N=Number(l)||0;N>0&&!s&&!T?setTimeout(()=>{R(false,false);},300):N===0&&I(false);},[l,s,T,R,I]),jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx(De,{field:e,currentLang:o,formValues:t,showControlButtons:true,hasFilledData:s,basedOnValue:i,onOpenModal:()=>R(false,true),onOpenEdit:()=>{c(a),R(false,true);},onOpenView:()=>{c(a),R(true,true);}}),jsxRuntime.jsx(Cn,{isModalOpen:T,isViewMode:y,modalRef:v,overlayRef:k,contentRef:P,expandedSeries:r,basedOnValue:i,hasFilledData:s,repeatGroup:d,currentLang:o,formValues:t,filledSeries:a,buildTempFieldName:x,buildNestedGroupFieldName:g,buildNestedChildFieldName:F,onClose:()=>{I(true);},onClear:()=>{m(),I(false);},onSave:()=>{u(),I(true);},onToggleSeries:p,setExpandedSeries:n})]})},In=zl;var Gl=({field:e,name:t,currentLang:o="fr",className:r,defaultValue:n="",onOTPComplete:i})=>{let{setValue:a,watch:l}=reactHookForm.useFormContext(),s=t??e.fieldName.toString(),d=e.otpFormFieldExecOptions?.otpLength??6,[p,c]=Me.useState(Array(d).fill("")),u=Me.useRef([]),m=l(s);Me.useEffect(()=>{if(m&&typeof m=="string"&&m.length===d){let y=m.split("").slice(0,d);c(y);}else if(n&&n.length===d){let y=n.split("").slice(0,d);c(y);}},[m,n,d]),Me.useEffect(()=>{let y=p.join("");y.length===d?a(s,y,{shouldValidate:true,shouldTouch:true}):a(s,y,{shouldValidate:false,shouldTouch:true});},[p,s,a,d]),Me.useEffect(()=>{let y=p.join("");if(y.length===d&&i){let v=setTimeout(()=>{i(y);},100);return ()=>clearTimeout(v)}},[p,d,i]);let x=(y,v)=>{let k=v.replace(/\D/g,"");if(k.length>1){let P=k.slice(-1);g(y,P);}else k.length===1?g(y,k):g(y,"");},g=(y,v)=>{let k=[...p];k[y]=v,c(k),v&&y<d-1&&setTimeout(()=>{u.current[y+1]?.focus();},10);},F=(y,v)=>{v.key==="ArrowLeft"&&y>0?(v.preventDefault(),u.current[y-1]?.focus()):v.key==="ArrowRight"&&y<d-1&&(v.preventDefault(),u.current[y+1]?.focus()),v.key==="Backspace"&&!p[y]&&y>0&&(v.preventDefault(),u.current[y-1]?.focus()),v.key==="Delete"&&g(y,"");},T=y=>{y.preventDefault();let k=y.clipboardData.getData("text").replace(/\D/g,"").slice(0,d).split(""),P=[...p];k.forEach((I,O)=>{O<d&&(P[O]=I);}),c(P);let R=Math.min(k.length-1,d-1);setTimeout(()=>{u.current[R]?.focus();},10);};return jsxRuntime.jsx(W,{field:e,currentLang:o,children:jsxRuntime.jsx("div",{className:`flex gap-2 justify-center ${r||""}`,children:p.map((y,v)=>jsxRuntime.jsx("input",{ref:k=>{u.current[v]=k;},type:"text",inputMode:"numeric",maxLength:1,value:y,onChange:k=>x(v,k.target.value),onKeyDown:k=>F(v,k),onPaste:T,className:"w-12 h-12 text-center text-2xl font-bold border-2 border-teal-500 rounded-lg text-teal-700 focus:border-teal-600 focus:ring-2 focus:ring-teal-200 outline-none transition-all bg-white",autoFocus:v===0&&!p.some(k=>k)},v))})})},Vn=Gl;var jl=({isOpen:e,field:t,currentLang:o,formValues:r,serverResponse:n,isSending:i,isResending:a=false,resendCooldown:l=0,otpValidated:s=false,onClose:d,onSendOTP:p,onValidateOTP:c,onResendOTP:u,onCallbackRedirect:m,onSubmit:x,onNext:g,isLastSection:F=false,linkedEmail:T,onOTPComplete:y})=>{let v=Me__namespace.default.useRef(null),k=Me__namespace.default.useRef(null),P=Me__namespace.default.useRef(null);if(Me__namespace.default.useEffect(()=>{e&&k.current&&P.current&&(k.current.animate([{opacity:"0"},{opacity:"1"}],{duration:150,easing:"ease-out",fill:"forwards"}),P.current.animate([{opacity:"0",transform:"scale(0.9) translateY(20px)"},{opacity:"1",transform:"scale(1) translateY(0px)"}],{duration:200,delay:50,easing:"ease-out",fill:"forwards"}));},[e]),Me__namespace.default.useEffect(()=>(e?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow="";}),[e]),!e)return null;let R=n?.call_back_url&&n?.call_back_url.trim()!=="";return jsxRuntime.jsxs("div",{ref:v,className:"fixed inset-0 z-[100] flex items-center justify-center p-2 sm:p-4",style:{display:e?"flex":"none"},children:[jsxRuntime.jsx("div",{ref:k,className:"fixed inset-0 bg-black bg-opacity-60 backdrop-blur-sm transition-opacity",onClick:d}),jsxRuntime.jsxs("div",{ref:P,className:"relative z-10 bg-white w-[90%] sm:w-auto max-w-md max-h-[95vh] sm:max-h-[90vh] rounded-xl shadow-xl overflow-hidden flex flex-col",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200",children:[jsxRuntime.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:typeof t.label=="string"?t.label:t.label[o]||t.label.fr||"V\xE9rification OTP"}),jsxRuntime.jsx("button",{type:"button",onClick:d,className:"text-gray-400 hover:text-gray-600 transition-colors",children:jsxRuntime.jsx(lucideReact.X,{size:24})})]}),jsxRuntime.jsxs("div",{className:"flex-1 overflow-y-auto p-6 custom-scrollbar",children:[t.helpText&&jsxRuntime.jsx("p",{className:"text-sm text-gray-600 mb-4",children:typeof t.helpText=="string"?t.helpText:t.helpText[o]||t.helpText.fr||""}),T&&jsxRuntime.jsx("div",{className:"mb-4 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:jsxRuntime.jsxs("p",{className:"text-sm text-blue-800",children:["Code envoy\xE9 \xE0 : ",jsxRuntime.jsx("span",{className:"font-semibold",children:T})]})}),jsxRuntime.jsx(Vn,{field:t,currentLang:o,onOTPComplete:y}),t.otpFormFieldExecOptions?.enableResend!==false&&!s&&T&&u&&jsxRuntime.jsxs("div",{className:"mt-4 flex items-center justify-center gap-2",children:[jsxRuntime.jsx("p",{className:"text-sm text-gray-600",children:"Vous n'avez pas re\xE7u le code ?"}),jsxRuntime.jsx("button",{type:"button",onClick:u,disabled:a||l>0,className:"text-sm text-teal-600 hover:text-teal-800 font-medium disabled:text-gray-400 disabled:cursor-not-allowed transition-colors underline",children:a?"Envoi en cours...":l>0?`Renvoyer (${l}s)`:"Renvoyer le code"})]}),n?.message&&jsxRuntime.jsx("div",{className:`mt-4 p-3 rounded-lg ${n.success?"bg-green-50 text-green-800 border border-green-200":"bg-red-50 text-red-800 border border-red-200"}`,children:jsxRuntime.jsx("p",{className:"text-sm",children:n.message})}),R&&jsxRuntime.jsxs("div",{className:"mt-6 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:[jsxRuntime.jsx("p",{className:"text-sm text-blue-800 mb-3",children:"Continuer sur :"}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>m(n.call_back_url),className:"flex items-center gap-2 text-blue-600 hover:text-blue-800 font-medium transition-colors",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{size:16}),jsxRuntime.jsx("span",{className:"underline break-all",children:n.call_back_url})]})]})]}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-3 p-6 border-t border-gray-200 bg-gray-50",children:[!s&&jsxRuntime.jsx(_e,{type:"button",onClick:d,children:"Annuler"}),R&&jsxRuntime.jsx(le,{type:"button",onClick:()=>m(n.call_back_url),children:"Continuer sur"}),!R&&!s&&jsxRuntime.jsx(le,{type:"button",onClick:c,disabled:i,children:i?"Validation en cours...":"Valider OTP"}),!R&&s&&jsxRuntime.jsx(le,{type:"button",onClick:F&&x?x:g,children:F?"Soumettre le formulaire":"Continuer"})]})]})]})},Mn=jl;var Kl=e=>e instanceof Map,vr=e=>e?Kl(e)?Object.fromEntries(e.entries()):{...e}:{},Fr=(e,t)=>{let o=e.replace(/\/+$/,"");if(/^https?:\/\//i.test(t))return t;let r=t.replace(/^\/+/,"");return `${o}/${r}`},xr=(e,t,o)=>{if(!t||t<=0||!o)return e;let r=setTimeout(()=>o.abort(),t);return e.finally(()=>{clearTimeout(r);})},An=e=>{let t=Object.keys(e).find(n=>n.toLowerCase().includes("token")&&typeof e[n]=="string");if(!t)return null;let o=e[t];if(!o||typeof o!="string")return null;let r={access_token:o,token_type:e.token_type||e.tokenType||"bearer",expires_in:e.expires_in||e.expiresIn};return r.expires_in&&(r.expires_at=Math.floor(Date.now()/1e3)+r.expires_in),r},Ln=(e,t,o)=>{let[r,n]=Me.useState(false),[i,a]=Me.useState(false),[l,s]=Me.useState(false),[d,p]=Me.useState(null),[c,u]=Me.useState(null),[m,x]=Me.useState(0),[g,F]=Me.useState(false),T=je(O=>O.setOTPToken),y=Me.useCallback(async O=>{if(!e)throw new Error("OTP options are not configured for this field");n(true),u(null);try{let V=new AbortController,E=Fr(e.serverDns,e.postApiEndPoint),L={...vr(e.payload),...O},b={"Content-Type":"application/json",...e.extraHeaders??{}};e.bearer&&(b.Authorization=`Bearer ${e.bearer}`);let N=fetch(E,{method:"POST",headers:b,body:JSON.stringify(L),signal:V.signal}),f=await xr(N,e.timeoutMs,V),h=null;try{h=await f.json();}catch{let w=await f.text();throw new Error(`Invalid JSON response: ${w}`)}if(!f.ok){let w=h?.message??`OTP request failed with status ${f.status} ${f.statusText}`;throw new Error(w)}let C=h;if(h?.json&&(C=h.json),E.includes("httpbin.org")){let w={success:!0,message:"OTP v\xE9rifi\xE9 avec succ\xE8s (simulation httpbin)"};return a(!0),p(w),w}let S={success:C?.success??!0,call_back_url:C?.call_back_url??C?.callback_url??C?.callBackUrl,message:C?.message};return a(!0),p(S),S}catch(V){let E=V instanceof Error?V.message:"Unexpected OTP error";throw u(E),V}finally{n(false);}},[e]),v=Me.useCallback((O,V)=>{V(),window.location.href=O;},[]),k=Me.useCallback(async(O,V)=>{if(!e)throw new Error("OTP options are not configured for this field");n(true),u(null);try{let E="123456";if(await new Promise(_=>setTimeout(_,800)),O!==E){let _="Code OTP invalide. Veuillez r\xE9essayer.";throw u(_),new Error(_)}let A=new AbortController,L=Fr(e.serverDns,e.postApiEndPoint),N={...vr(e.payload),...V,otpCode:O},f={"Content-Type":"application/json",...e.extraHeaders??{}};e.bearer&&(f.Authorization=`Bearer ${e.bearer}`);let h=fetch(L,{method:"POST",headers:f,body:JSON.stringify(N),signal:A.signal}),C=await xr(h,e.timeoutMs,A),M=null;try{M=await C.json();}catch{let _=await C.text();throw new Error(`Invalid JSON response: ${_}`)}if(!C.ok){let _=M?.message??`OTP validation failed with status ${C.status} ${C.statusText}`;throw new Error(_)}let S=M;if(M?.json&&(S=M.json),L.includes("httpbin.org")){let _=An(S),z={success:!0,message:"Code OTP valid\xE9 avec succ\xE8s",authToken:_||void 0,access_token:S?.access_token||S?.accessToken,token_type:S?.token_type||S?.tokenType,expires_in:S?.expires_in||S?.expiresIn};return _&&t&&o&&(T(t,o,_),console.log("\u2705 [OTP] Token d'authentification stock\xE9 (httpbin):",{formId:t,fieldName:o})),s(!0),a(!0),p(z),z}let D=S?.success??!0,$=An(S),G={success:D,call_back_url:S?.call_back_url??S?.callback_url??S?.callBackUrl,message:S?.message??"Code OTP valid\xE9 avec succ\xE8s",authToken:$||void 0,access_token:S?.access_token||S?.accessToken,token_type:S?.token_type||S?.tokenType,expires_in:S?.expires_in||S?.expiresIn};if(D===!1){let _=S?.message||"Code OTP invalide. Veuillez r\xE9essayer.";throw u(_),new Error(_)}return $&&t&&o&&(T(t,o,$),console.log("\u2705 [OTP] Token d'authentification stock\xE9:",{formId:t,fieldName:o})),s(!0),a(!0),p(G),G}catch(E){let A=E instanceof Error?E.message:"Erreur lors de la validation de l'OTP";throw u(A),E}finally{n(false);}},[e,t,o,T]),P=Me.useCallback(()=>{a(false),p(null),u(null),s(false);},[]),R=Me.useCallback(async O=>{if(!e)throw new Error("OTP options are not configured for this field");let V=e.resendCooldownSeconds??60;if(m>0)throw new Error(`Veuillez attendre ${m} secondes avant de renvoyer le code`);F(true),u(null);try{let E=e.sendOTPApiConfig||{serverDns:e.serverDns,postApiEndPoint:e.postApiEndPoint,payload:e.payload,extraHeaders:e.extraHeaders,bearer:e.bearer},A=new AbortController,L=Fr(E.serverDns,E.postApiEndPoint),N={...vr(E.payload),...O},f={"Content-Type":"application/json",...E.extraHeaders??{}};E.bearer&&(f.Authorization=`Bearer ${E.bearer}`);let h=fetch(L,{method:"POST",headers:f,body:JSON.stringify(N),signal:A.signal}),C=await xr(h,e.timeoutMs,A);if(!C.ok){let w=await C.json().catch(()=>({message:C.statusText}));throw new Error(w.message||`OTP resend failed with status ${C.status}`)}let M=await C.json();x(V);let S=setInterval(()=>{x(w=>w<=1?(clearInterval(S),0):w-1);},1e3);return a(!0),{success:!0,message:"Code OTP renvoy\xE9 avec succ\xE8s"}}catch(E){let A=E instanceof Error?E.message:"Erreur lors du renvoi du code";throw u(A),E}finally{F(false);}},[e,m]),I=Me.useCallback(()=>{n(false),a(false),s(false),p(null),u(null),x(0),F(false);},[]);return {sendOTP:y,validateOTP:k,resendOTP:R,resetOTPSentState:P,handleCallbackRedirect:v,isSending:r,isResending:g,resendCooldown:m,otpSent:i,otpValidated:l,serverResponse:d,error:c,reset:I}};var Yl=({field:e,formValues:t,formId:o,currentLang:r="fr",onClearForm:n,allSections:i=[],onSubmit:a,onNext:l,isLastSection:s=false})=>{let{getValues:d,watch:p}=reactHookForm.useFormContext(),[c,u]=Me__namespace.default.useState(false),m=p(e.fieldName),x=Me.useMemo(()=>vt(e.fieldName,i),[e.fieldName,i]),g=Me.useMemo(()=>{if(x!==-1)return Ft(e,i,x)},[e,i,x]),F=g?t[g.fieldName]:null,{sendOTP:T,validateOTP:y,resendOTP:v,resetOTPSentState:k,handleCallbackRedirect:P,isSending:R,isResending:I,resendCooldown:O,otpValidated:E,serverResponse:A}=Ln(e.otpFormFieldExecOptions,o,e.fieldName);Me.useEffect(()=>{c||setTimeout(()=>{u(true);},300);},[c]);let b=()=>{u(false);},N=async()=>{try{let D=d();await T(D);}catch(D){console.error("Erreur lors de l'envoi de l'OTP:",D);}},f=async()=>{try{let D=d(),$="";typeof m=="string"?$=m:m&&typeof m=="object"&&m.otp?$=m.otp:($=t[e.fieldName]||"",typeof $!="string"&&($=""));let G=e.otpFormFieldExecOptions?.otpLength??6;if(!$||$.length!==G){ze__default.default.error(`Code OTP incomplet. Le code doit contenir ${G} chiffres.`);return}await y($,D);}catch(D){let $=D instanceof Error?D.message:"Erreur lors de la validation de l'OTP";ze__default.default.error(`\u274C ${$}`),console.error("Erreur lors de la validation de l'OTP:",D);}},h=je(D=>D.clearAllOTPTokens),C=D=>{o&&h(o),P(D,n);},M=e.otpFormFieldExecOptions?.autoValidate??false,S=Me__namespace.default.useCallback(async D=>{if(M&&!E&&!R)try{let $=d();await y(D,$);}catch($){let G=$ instanceof Error?$.message:"Code OTP invalide";ze__default.default.error(`\u274C ${G}`),console.error("Erreur lors de l'auto-validation de l'OTP:",$);}},[M,E,R,y,d]);return jsxRuntime.jsx(Mn,{isOpen:c,field:e,currentLang:r,formValues:t,serverResponse:A,isSending:R,isResending:I,resendCooldown:O,otpValidated:E,onClose:b,onSendOTP:N,onValidateOTP:f,onResendOTP:async()=>{try{let D=d();k(),await v(D),ze__default.default.success("Code OTP renvoy\xE9 avec succ\xE8s !");}catch(D){console.error("Erreur lors du renvoi de l'OTP:",D),ze__default.default.error(D instanceof Error?D.message:"Erreur lors du renvoi du code");}},onCallbackRedirect:C,onSubmit:a,onNext:l,isLastSection:s,linkedEmail:F,onOTPComplete:M?S:void 0})},Bn=Yl;var _n=Me.forwardRef(({children:e,className:t,...o},r)=>jsxRuntime.jsx("h4",{ref:r,className:t,...o,children:e}));_n.displayName="H4Title";var Nr=_n;var td=({section:e,fields:t,currentLang:o,fadeKey:r,formValues:n,formId:i,paginationMode:a,allSections:l=[],currentSectionIndex:s=0,debugInfo:d,onConditionalChange:p,onConditionalError:c,onClearForm:u,onSubmit:m,onNext:x,isLastSection:g=false,sectionContainerStyles:F})=>{let T=Me__namespace.default.useMemo(()=>{let S={};return Object.entries(n).forEach(([w,D])=>{S[w]={responseValue:D};}),S},[n]);Me__namespace.default.useEffect(()=>{let S=t.map($=>$.fieldName),w=pe.getState(),D=Object.keys(w.forms)[0];if(D){let $=w.forms[D]||{},G={};Object.entries($).forEach(([z,ne])=>{S.includes(z)&&(G[z]=ne);}),Object.keys($).some(z=>!S.includes(z))&&w.setAllFormValues(D,G);}},[r,e.sectionId,t]);let y=Me__namespace.default.useMemo(()=>`section_${r}_${e.sectionId}`,[r,e.sectionId]),v=Me__namespace.default.useMemo(()=>{try{return Ge(e,T)}catch(S){return console.error("5-\u274C FormSection - Erreur \xE9valuation section",{sectionTitle:e.title?U(e.title,o):"Sans titre",error:S,section:e,allResponseInForms:T}),c?.(S,{section:e}),true}},[e,T,c,o]),{visibleFields:k,evaluationErrors:P}=Me__namespace.default.useMemo(()=>{let S=[],w=[];return t.forEach(D=>{try{Se(D,T)&&w.push(D);}catch($){console.error(`9-\u274C FormSection - Erreur \xE9valuation champ "${D.fieldName}"`,{fieldName:D.fieldName,error:$,field:D,allResponseInForms:T}),S.push(`Field ${D.fieldName}: ${$.message}`),c?.($,{section:e,field:D}),w.push(D);}}),{visibleFields:w,evaluationErrors:S}},[t,T,e,c,o]),R=At(k,o),I=Lt(k,o),O=Me__namespace.default.useMemo(()=>{let S=[];return k.forEach(w=>{S.push(w);let D=R[w.fieldName];D&&S.push(D);let $=I[w.fieldName];$&&$.length>0&&$.forEach(G=>{S.push({type:"detail-group",group:G});});}),S},[k,R,I]),V=Me__namespace.default.useMemo(()=>{let S=t.length,w=k.length,D=t.filter(z=>!k.some(ne=>ne.fieldName===z.fieldName)),$=k.filter(z=>z.validations?.some(ne=>ne.validationType==="required")),G=D.filter(z=>z.validations?.some(ne=>ne.validationType==="required"));return {sectionVisible:v,totalFields:S,visibleFields:w,hiddenFields:D.length,requiredVisible:$.length,requiredHidden:G.length,hiddenFieldNames:D.map(z=>z.fieldName),conditionalFields:t.filter(z=>z.conditionalDisplay).length,errors:P.length>0?P:void 0}},[t,k,v,P,e.title,o]);Me__namespace.default.useEffect(()=>{p?.(V);},[V,p,e.title,o]);let E=S=>(S.width||"half")==="full"?"col-span-1 tablet:col-span-2 w-full":"col-span-1 w-full",A=S=>{let w=`${r}_${S.fieldName}`;return S.repeatGroup&&S.repeatRule?jsxRuntime.jsx(In,{field:S,formValues:n,currentLang:o},w):jsxRuntime.jsx(De,{field:S,currentLang:o,formValues:n},w)};if(!v)return d?jsxRuntime.jsxs("div",{className:"border-2 border-red-200 w-full max-w-4xl bg-red-50 rounded-lg p-4 opacity-50",children:[jsxRuntime.jsx("div",{className:"text-red-600 text-sm",children:"\u26A0\uFE0F Section cach\xE9e par les conditions d'affichage"}),e?.title&&jsxRuntime.jsxs("div",{className:"text-xs text-red-500 mt-2",children:["Section: ",e.title?U(e.title,o):"Sans titre"]}),P.length>0&&jsxRuntime.jsxs("div",{className:"text-xs text-red-600 mt-2 bg-red-100 p-2 rounded",children:[jsxRuntime.jsx("div",{className:"font-medium",children:"Erreurs d'\xE9valuation:"}),P.map((S,w)=>jsxRuntime.jsxs("div",{className:"ml-2",children:["\u2022 ",S]},w))]})]}):null;let L=Me__namespace.default.useMemo(()=>{let S=$e(e);return S},[e]),b="#e2e8f0",N="2px",f="#F6F6F6",h=F?.borderColor||b,C=F?.borderWidth?typeof F.borderWidth=="number"?`${F.borderWidth}px`:F.borderWidth:N,M=F?.backgroundColor||f;return L?jsxRuntime.jsxs("div",{className:"w-full max-w-4xl rounded-lg p-2 tablet:p-8 flex flex-col items-center",style:{borderColor:h,borderWidth:C,borderStyle:"solid",backgroundColor:M},children:[e.title&&jsxRuntime.jsxs("div",{className:"w-full mb-6",children:[jsxRuntime.jsx(Nr,{className:"text-center mb-2",children:U(e.title,o)}),e.subTitle&&jsxRuntime.jsx(Ce,{className:"text-center text-gray-600",children:U(e.subTitle,o)})]}),jsxRuntime.jsx(Bn,{field:L,formValues:n,formId:i,currentLang:o,onClearForm:u||(()=>{console.warn("onClearForm not provided, using fallback");let S=pe.getState(),w=Object.keys(S.forms)[0];w&&S.clearForm(w);}),allSections:l,onSubmit:m,onNext:x,isLastSection:g})]},y):k.length===0?d?jsxRuntime.jsxs("div",{className:"border-2 border-orange-200 w-full max-w-4xl bg-orange-50 rounded-lg p-4 opacity-50",children:[jsxRuntime.jsxs("div",{className:"text-orange-600 text-sm",children:["\u26A0\uFE0F Section visible mais tous les champs sont cach\xE9s (",V.totalFields," champs)"]}),jsxRuntime.jsxs("div",{className:"text-xs text-orange-500 mt-2",children:["Champs cach\xE9s: ",V.hiddenFieldNames.join(", ")]}),P.length>0&&jsxRuntime.jsxs("div",{className:"text-xs text-orange-600 mt-2 bg-orange-100 p-2 rounded",children:[jsxRuntime.jsx("div",{className:"font-medium",children:"Erreurs d'\xE9valuation:"}),P.map((S,w)=>jsxRuntime.jsxs("div",{className:"ml-2",children:["\u2022 ",S]},w))]})]}):null:jsxRuntime.jsxs("div",{className:"w-full max-w-4xl rounded-lg p-2 tablet:p-8 flex flex-col items-center",style:{borderColor:h,borderWidth:C,borderStyle:"solid",backgroundColor:M},children:[e.title&&jsxRuntime.jsx(Nr,{className:"text-lg font-medium text-gray-700 mb-4 pb-2 border-b border-gray-200 w-full",children:U(e.title,o)}),e.subTitle&&jsxRuntime.jsx(Ce,{className:"text-gray-600 mb-4 w-full",children:U(e.subTitle,o)}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 tablet:grid-cols-2 gap-6 w-full [&_input:not([type='radio']):not([type='checkbox'])]:!w-full [&_textarea]:!w-full [&_select]:!w-full [&_*]:!max-w-full",children:O.map((S,w)=>{if("type"in S&&S.type==="detail-group"){let{group:$}=S;return jsxRuntime.jsxs("div",{className:"col-span-1 tablet:col-span-2 mt-4 p-4 bg-gray-50 rounded-lg border border-gray-200",children:[$.groupLabel&&jsxRuntime.jsx("h4",{className:"font-semibold text-gray-700 mb-3 text-sm",children:$.groupLabel}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 tablet:grid-cols-2 gap-4",children:$.fields.map(G=>jsxRuntime.jsx("div",{className:E(G),children:A(G)},`${r}_${G.fieldName}_wrapper`))})]},`${r}_detail-group_${$.optionValue}_${w}`)}let D=S;return jsxRuntime.jsx("div",{className:E(D),children:A(D)},`${r}_${D.fieldName}_wrapper`)})})]},y)},Un=td;var nd=({onPrevious:e,onNext:t,onPreviousVisible:o,onNextVisible:r,onSubmit:n,onClearAll:i,isFirstSection:a,isLastSection:l,isValidating:s=false,onSubmitButtonText:d,showStepNavigation:p=true,displayDeleteButton:c=true})=>{let u=o||e,m=t,[x,g]=Me.useState(false),F=d??"Soumettre",T=()=>{i(),g(false);},y=()=>x?jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:jsxRuntime.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full mx-4 transform transition-all",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200",children:[jsxRuntime.jsxs("div",{className:"flex items-center space-x-3",children:[jsxRuntime.jsx("div",{className:"flex-shrink-0",children:jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"h-6 w-6 text-red-600"})}),jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Supprimer toutes les donn\xE9es"})]}),jsxRuntime.jsx("button",{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),g(false);},className:"text-gray-400 hover:text-gray-600 transition-colors",children:jsxRuntime.jsx(lucideReact.X,{size:24})})]}),jsxRuntime.jsxs("div",{className:"p-6",children:[jsxRuntime.jsx("p",{className:"text-gray-600 mb-4",children:"\xCAtes-vous s\xFBr de vouloir supprimer toutes les donn\xE9es du formulaire ? Cette action est irr\xE9versible et effacera \xE9galement les donn\xE9es sauvegard\xE9es."}),jsxRuntime.jsx("div",{className:"bg-red-50 border border-red-200 rounded-md p-3",children:jsxRuntime.jsxs("div",{className:"flex",children:[jsxRuntime.jsx(lucideReact.AlertTriangle,{className:"h-5 w-5 text-red-400 mr-2 flex-shrink-0 mt-0.5"}),jsxRuntime.jsxs("div",{className:"text-sm text-red-800",children:[jsxRuntime.jsx("strong",{children:"Attention :"})," Toutes vos donn\xE9es seront d\xE9finitivement perdues."]})]})})]}),jsxRuntime.jsxs("div",{className:"flex justify-end space-x-3 p-6 border-t border-gray-200 bg-gray-50",children:[jsxRuntime.jsx("button",{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),g(false);},className:"px-4 py-2 text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 transition-colors font-medium",children:"Annuler"}),jsxRuntime.jsxs("button",{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),T?.();},className:"px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700 transition-colors font-medium flex items-center space-x-2",children:[jsxRuntime.jsx(lucideReact.Trash2,{size:16}),jsxRuntime.jsx("span",{children:"Supprimer"})]})]})]})}):null;return p?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"hidden md:flex justify-between items-center gap-2 mt-8 w-full max-w-2xl",children:[jsxRuntime.jsx(_e,{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),u?.();},disabled:a,children:"Pr\xE9c\xE9dent"}),c&&jsxRuntime.jsx("div",{className:"flex-1 flex justify-center",children:jsxRuntime.jsx("button",{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),g(true);},className:"group relative p-3 bg-red-600 text-white rounded-full hover:bg-red-700 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105",title:"Supprimer toutes les donn\xE9es",children:jsxRuntime.jsx(lucideReact.Trash2,{size:20,className:"transition-transform group-hover:scale-110"})})}),l?jsxRuntime.jsx(le,{type:"submit",onClick:n,children:F}):jsxRuntime.jsx(le,{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),m?.();},disabled:s,children:s?"Validation...":"Suivant"})]}),jsxRuntime.jsxs("div",{className:"md:hidden fixed bottom-0 left-0 right-0 bg-white/95 backdrop-blur-md border-t border-gray-200 px-4 py-3 shadow-lg z-50 mobile-nav-slide-up",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center gap-3 max-w-md mx-auto",children:[jsxRuntime.jsx(_e,{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),u?.();},disabled:a,className:"flex-1 min-h-[44px]",children:"Pr\xE9c\xE9dent"}),c&&jsxRuntime.jsx("button",{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),g(true);},className:"group relative p-3 bg-red-600 text-white rounded-full hover:bg-red-700 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105 min-h-[44px] min-w-[44px] flex items-center justify-center",title:"Supprimer toutes les donn\xE9es",children:jsxRuntime.jsx(lucideReact.Trash2,{size:20,className:"transition-transform group-hover:scale-110"})}),l?jsxRuntime.jsx(le,{type:"button",onClick:n,className:"flex-1 min-h-[44px]",children:F}):jsxRuntime.jsx(le,{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),m?.();},disabled:s,className:"flex-1 min-h-[44px]",children:s?"Validation...":"Suivant"})]}),jsxRuntime.jsx("div",{className:"h-safe-area-inset-bottom"})]}),jsxRuntime.jsx(y,{})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"mt-8 w-full max-w-2xl flex flex-col items-center gap-4",children:[jsxRuntime.jsx(le,{type:"submit",onClick:n,disabled:s,className:"min-w-[200px]",children:s?"Validation...":F}),c&&jsxRuntime.jsx("button",{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),g(true);},className:"group relative p-3 bg-red-600 text-white rounded-full hover:bg-red-700 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105",title:"Supprimer toutes les donn\xE9es",children:jsxRuntime.jsx(lucideReact.Trash2,{size:20,className:"transition-transform group-hover:scale-110"})})]}),jsxRuntime.jsx(y,{})]})},Wn=nd;var id=({form:e,formId:t,onSubmit:o,currentLang:r,navigation:n,handleFieldChange:i,onClearAll:a,methods:l,submitButtonText:s,paginationMode:d,progressBarType:p,sections:c,headerOptions:u,displayDeleteButton:m=true,containerStyles:x})=>{let g=pe(V=>V.forms[t]),F=Me.useMemo(()=>g??{},[g]),{validatePage:T,isValidating:y,setIsValidating:v}=_r(n,l,r,d),{handleNext:k}=Lr(n,T,y,v,e,F,d||"byFields"),{handleSubmitWithValidation:P}=Ur(l,e,T,o,v),R=n.sectionVisibility,I=n.pageVisibility,O=jr(n.pagedFields);return Me.useEffect(()=>{if(R&&R.length>0&&!R[n.sectionIndex]){let V=R.findIndex((A,L)=>A&&L>n.sectionIndex);if(V!==-1){n.goToStep(V,0);return}let E=R.lastIndexOf(true,n.sectionIndex-1);E!==-1&&n.goToStep(E,0);}},[R,n.sectionIndex,n.goToStep]),Me.useEffect(()=>{if(I&&I.length>0){let V=I[n.sectionIndex];if(!V||V.length===0||(V[n.fieldPage]||0)>0)return;let A=V.findIndex((b,N)=>b>0&&N>n.fieldPage);if(A!==-1){n.goToStep(n.sectionIndex,A);return}for(let b=n.fieldPage-1;b>=0;b--)if(V[b]>0){n.goToStep(n.sectionIndex,b);return}let L=I.findIndex((b,N)=>b.filter(h=>h>0).length>0&&N>n.sectionIndex);if(L!==-1){let b=I[L].findIndex(N=>N>0);n.goToStep(L,Math.max(0,b));return}for(let b=n.sectionIndex-1;b>=0;b--){let N=I[b];if(N.filter(h=>h>0).length>0){let h=(()=>{for(let C=N.length-1;C>=0;C--)if(N[C]>0)return C;return 0})();n.goToStep(b,h);return}}}},[I,n.sectionIndex,n.fieldPage,n.goToStep]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Jr,{formId:t,sections:e.sections}),jsxRuntime.jsxs("div",{className:"h-full w-[100%] laptop:w-[90%] flex flex-col items-center justify-center pb-20 md:pb-0",style:{backgroundColor:x?.mainContainer?.backgroundColor||"#ffffff",borderColor:x?.mainContainer?.borderColor,borderWidth:x?.mainContainer?.borderWidth?typeof x.mainContainer.borderWidth=="number"?`${x.mainContainer.borderWidth}px`:x.mainContainer.borderWidth:void 0,borderStyle:x?.mainContainer?.borderWidth?"solid":void 0},children:[jsxRuntime.jsx(Qr,{currentStep:n.currentVisibleStep??n.currentStep,totalSteps:n.totalVisibleSteps??n.totalSteps,progressBarType:p,sections:c,sectionVisibility:n.sectionVisibility,currentSectionIndex:n.sectionIndex}),jsxRuntime.jsx(eo,{form:e,currentLang:r,headerOptions:u}),jsxRuntime.jsx("div",{className:"flex-1 w-full flex flex-col items-center justify-center",children:jsxRuntime.jsx(Un,{section:n.currentSection,fields:O,currentLang:r,fadeKey:n.fadeKey,onFieldChange:i,formValues:F,formId:t,paginationMode:d,onClearForm:a,allSections:e.sections,currentSectionIndex:n.sectionIndex,onSubmit:P,onNext:k,isLastSection:n.isLastSection,sectionContainerStyles:x?.sectionContainer,debugInfo:{sectionIndex:n.sectionIndex,fieldPage:n.fieldPage,...n.debugInfo}})}),jsxRuntime.jsx(Wn,{onPrevious:n.goToPrevious,onNext:k,onPreviousVisible:n.goToPreviousVisible,onNextVisible:n.goToNextVisible,onClearAll:a,onSubmit:P,isFirstSection:n.isFirstSection,isLastSection:n.isLastSection,isValidating:y,onSubmitButtonText:s,showStepNavigation:n.totalSteps>1,displayDeleteButton:m})]})]})},Kn=id;var pd=({form:e,formId:t,onSubmit:o,currentLang:r="fr",submitButtonText:n,paginationMode:i})=>{let a=i??e.layoutOptions?.paginationMode??"byFields",l=e.layoutOptions?.progressBarType,s=e.layoutOptions?.headerOptions,d=e.layoutOptions?.displayDeleteButton??true,p=e.layoutOptions?.containerStyles,c=pe(A=>A.forms[t]),u=Me.useMemo(()=>c??{},[c]),m=Me.useMemo(()=>{let A={};return Object.entries(u).forEach(([L,b])=>{A[L]={responseValue:b};}),A},[u]),x=Me.useMemo(()=>e.sections.map(A=>{try{return Ge(A,m)}catch(L){return console.error("[FormEngine] Erreur \xE9valuation section",{sectionId:A.sectionId,error:L}),true}}),[e.sections,m]),g=4,F=Me.useMemo(()=>e.sections.map((A,L)=>{if(!x[L])return [];let b=A.formFields||[],N=Math.ceil(b.length/g),f=new Array(N).fill(0);return b.forEach((h,C)=>{let M=Math.floor(C/g);try{Se(h,m)&&(f[M]=(f[M]||0)+1);}catch(S){console.error("[FormEngine] Erreur \xE9valuation champ",{sectionId:A.sectionId,fieldName:h.fieldName,error:S}),f[M]=(f[M]||0)+1;}}),f}),[e.sections,x,m,g]),T=Er({form:e,paginationMode:a,sectionVisibility:x,pageVisibility:F}),y=Me.useMemo(()=>Rr(e),[e]),{savedValues:v}=Ir(t,e.sections),k=Me.useMemo(()=>Vr(y),[y]),P=Me.useMemo(()=>`${t}_${T.fadeKey}_${e.sections.length}`,[t,T.fadeKey,e.sections.length]),R=reactHookForm.useForm({resolver:zod.zodResolver(k),mode:"onTouched",defaultValues:Me.useMemo(()=>Object.fromEntries(y.map(A=>[A.fieldName,v[A.fieldName]??A.response?.responseValue??""])),[y,v])});Me.useEffect(()=>{let A=R.getValues();for(let L in A){let b=A[L];b!==void 0&&b!==""&&R.setValue(L,b,{shouldTouch:true});}},[R]);let I=Me.useCallback((A,L)=>{R.setValue(A,L,{shouldValidate:true});},[R]),{handleClearAll:O}=Ar(R,y,t,T),V=e.theme?.primaryColor??it,E=Or(V);return jsxRuntime.jsx(Dr,{primaryColor:V,children:jsxRuntime.jsx(reactHookForm.FormProvider,{...R,children:jsxRuntime.jsx("form",{onSubmit:A=>A.preventDefault(),className:"h-full w-full laptop:w-[90%] flex flex-col items-center justify-center bg-white",style:E,children:jsxRuntime.jsx(Kn,{form:e,formId:t,onSubmit:o,currentLang:r,navigation:T,allFields:y,handleFieldChange:I,onClearAll:O,methods:R,submitButtonText:n??"Continer",paginationMode:a,progressBarType:l,sections:e.sections,headerOptions:s,displayDeleteButton:d,containerStyles:p})},P)})})},fd=pd;var Jn=(s=>(s.IMAGE="IMAGE",s.VIDEO="VIDEO",s.AUDIO="AUDIO",s.DOCUMENT="DOCUMENT",s.PDF="PDF",s.VOICE="VOICE",s.TIP_TAP_DOC_TEXT="TIP_TAP_DOC_TEXT",s.OTP="OTP",s))(Jn||{});
41
+ exports.FormEngine=fd;exports.SpecialField=Jn;//# sourceMappingURL=index.js.map
42
+ //# sourceMappingURL=index.js.map