{"version":3,"file":"RedirectionPI.ozTPjHFw.mjs","names":["useState","useRef","_Fragment"],"sources":["https:/framerusercontent.com/modules/DI8oHtVfDXRvMoBQqbab/8A0pMfZGYH3qj4ZSPqvZ/RedirectionPI.js"],"sourcesContent":["// RedirectionPI.tsx\n\"use client\";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{getBranding}from\"https://framerusercontent.com/modules/cHotz1gOytBWbN0alrj3/uxqoTqfc8mW5BAbLkSrl/branding.js\";export default function RedirectionPI(){const isLiveSite=typeof window!==\"undefined\"&&window.location.hostname.includes(\"majob.ca\");if(!isLiveSite){return /*#__PURE__*/_jsx(\"div\",{style:{textAlign:\"center\",padding:40},children:/*#__PURE__*/_jsx(\"div\",{style:{fontSize:18,color:\"#999\"},children:\"[Placeholder de redirection vers Predictive Index]\"})});}return /*#__PURE__*/_jsx(RedirectionPIReal,{});}function RedirectionPIReal(){// Branding\nconst{couleurPrincipale,couleurSecondaire,fontFamily,emailContact}=getBranding();const loaderCSS=`\n    .loader {\n      font-family: ${fontFamily};\n      border: 6px solid ${couleurSecondaire};\n      border-top: 6px solid ${couleurPrincipale};\n      border-radius: 50%;\n      width: 40px;\n      height: 40px;\n      animation: spin 1s linear infinite;\n      }\n    sup {\n        font-size: 0.7em;\n    }  \n    @keyframes spin {\n      0% { transform: rotate(0deg); }\n      100% { transform: rotate(360deg); }\n    }\n  `;// State\nconst[visibleCountdown,setVisibleCountdown]=useState(8)// décompte affiché 8s\n;const[piLink,setPiLink]=useState(\"\");const[showManualOption,setShowManualOption]=useState(false);const[showError,setShowError]=useState(false);// Refs\nconst redirectedRef=useRef(false);const hardStopRef=useRef(false)// devient true à 5s → plus de redirection possible\n;const mountedRef=useRef(true);// Déclenchement immédiat du webhook (GET) + arrêt dur à 5s\nuseEffect(()=>{mountedRef.current=true;const ac=new AbortController;const run=async()=>{const params=new URLSearchParams(window.location.search);const submissionId=params.get(\"submission_id\")||\"\";if(!submissionId){setShowError(true);return;}const url=new URL(\"https://n8n.toutsimple.ca/webhook/framer-proxy-pi-c72a34cf-18aa-44b9-b168-9512c833cbab\");// URLSearchParams encode déjà correctement\nurl.searchParams.set(\"submission_id\",submissionId);url.searchParams.set(\"t\",String(Date.now()))// anti-cache\n;try{const res=await fetch(url.toString(),{method:\"GET\",cache:\"no-store\",signal:ac.signal});// Si on a déjà “hard stop” (après 5s), on ignore la réponse\nif(hardStopRef.current)return;const data=await res.json().catch(()=>null);const link=typeof data?.pi_link===\"string\"?data.pi_link:\"\";if(link&&link.startsWith(\"http\")){setPiLink(link);redirectedRef.current=true;// Redirection immédiate\nlocation.replace(link);// Bouton manuel en secours si la redirection est bloquée\nsetTimeout(()=>{if(!mountedRef.current||hardStopRef.current)return;setShowManualOption(true);},2e3);}else{// pas de lien → on laisse le timer d'erreur gérer\n}}catch{// erreur réseau/abort → le timer d’erreur tranchera à 5s\n}};// Lance le webhook tout de suite\nrun();// À 5s : on arrête tout et on bascule en erreur définitive\nconst hardStopTimer=setTimeout(()=>{hardStopRef.current=true;try{ac.abort();}catch{}if(!redirectedRef.current)setShowError(true);},5700);return()=>{mountedRef.current=false;clearTimeout(hardStopTimer);try{ac.abort();}catch{}};},[]);// Décompte visuel (7s)\nuseEffect(()=>{if(visibleCountdown<=0)return;const id=setTimeout(()=>setVisibleCountdown(s=>s-1),1e3);return()=>clearTimeout(id);},[visibleCountdown]);return /*#__PURE__*/_jsxs(\"div\",{style:{textAlign:\"center\",padding:40},children:[/*#__PURE__*/_jsxs(\"div\",{style:{fontSize:20,marginBottom:20},children:[/*#__PURE__*/_jsxs(\"p\",{style:{marginBottom:15},children:[\"Tu seras redirig\\xe9(e) vers Predictive Index\",/*#__PURE__*/_jsx(\"sup\",{children:\"TM\"}),\" dans un instant\"]}),/*#__PURE__*/_jsx(\"p\",{children:/*#__PURE__*/_jsx(\"strong\",{children:\"Pr\\xe9paration du questionnaire...\"})})]}),!showError&&/*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(\"div\",{className:\"loader\",style:{margin:\"20px auto\"}}),/*#__PURE__*/_jsxs(\"div\",{style:{fontSize:16,marginBottom:20},children:[\"Redirection dans \",visibleCountdown,\" seconde\",visibleCountdown!==1?\"s\":\"\"]})]}),showManualOption&&piLink&&!showError&&/*#__PURE__*/_jsx(\"a\",{href:piLink,style:{padding:\"12px 20px\",fontSize:16,borderRadius:8,backgroundColor:\"#3330E3\",color:\"#fff\",textDecoration:\"none\",display:\"inline-block\"},children:\"Rediriger manuellement\"}),showError&&/*#__PURE__*/_jsxs(\"div\",{style:{marginTop:20,fontSize:16,color:\"#D8000C\"},children:[\"Nous avons eu un probl\\xe8me avec la redirection vers le questionnaire Predictive Index, veuillez contacter\",\" \",/*#__PURE__*/_jsx(\"a\",{href:`mailto:${emailContact}`,children:emailContact}),\" pour recevoir le lien. Nous sommes d\\xe9sol\\xe9s des d\\xe9sagr\\xe9ments.\"]}),/*#__PURE__*/_jsx(\"style\",{children:loaderCSS})]});}\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"RedirectionPI\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./RedirectionPI.map"],"mappings":"6MAC8P,SAAwB,GAAe,CAAyT,OAAhS,IAAS,QAAa,EAAO,SAAS,SAAS,SAAS,UAAU,EAAkP,EAAK,EAAkB,CAAC,CAAC,EAArO,EAAK,MAAM,CAAC,MAAM,CAAC,UAAU,SAAS,QAAQ,EAAE,EAAE,SAAsB,EAAK,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,MAAM,EAAE,SAAS,oDAAoD,CAAC,CAAC,CAAC,CAAkD,CAAC,SAAS,GAAmB,CAC1qB,GAAK,CAAC,oBAAkB,oBAAkB,aAAW,gBAAc,EAAY,EAAQ,EAAU;;qBAE5E,EAAW;0BACN,EAA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