{"version":3,"file":"RedirectionPI.Chj7ipTP.mjs","names":["useState","useRef","_Fragment"],"sources":["https:/framerusercontent.com/modules/DI8oHtVfDXRvMoBQqbab/6raoZpRpc6AMVIzJia8x/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/vQOBzWseOfawwHQqCTZR/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://toutsimple.app.n8n.cloud/webhook/framer-proxy-pi\");// 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\"}}}"],"mappings":"6MAC8P,SAAwB,GAAe,CAAyT,OAAhS,IAAS,QAAa,EAAO,SAAS,SAAS,SAAS,WAAW,CAAiP,EAAK,EAAkB,EAAE,CAAC,CAAtO,EAAK,MAAM,CAAC,MAAM,CAAC,UAAU,SAAS,QAAQ,GAAG,CAAC,SAAsB,EAAK,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,OAAO,CAAC,SAAS,qDAAqD,CAAC,CAAC,CAAC,CAAkD,SAAS,GAAmB,CAC1qB,GAAK,CAAC,oBAAkB,oBAAkB,aAAW,gBAAc,GAAa,CAAO,EAAU;;qBAE5E,EAAW;0BACN,EAAkB;8BACd,EAAkB;;;;;;;;;;;;;IAc3C,CAAC,EAAiB,GAAqBA,EAAS,EA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