app.js 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  1. /* Audit Express Self - Livinweb */
  2. const appEl = document.getElementById('app');
  3. const API_BASE = appEl?.dataset?.apiBase || '/api';
  4. const BOOKING_URL = appEl?.dataset?.bookingUrl || '';
  5. const DEVIS_URL = appEl?.dataset?.devisUrl || '';
  6. /* ── Catalogue packs ── */
  7. const PACK_CATALOGUE = [
  8. {
  9. id: 'onboarding-v1',
  10. title: 'Onboarding collaborateur',
  11. desc: "Clarté du flux, traçabilité, continuité — auditez votre process d'intégration.",
  12. tag: 'Pré-configuré',
  13. tagStyle: 'tag--pre',
  14. },
  15. {
  16. id: 'validation-facture',
  17. title: 'Validation de facture',
  18. desc: 'Contrôles, séparation des tâches, preuve — évaluez votre circuit factures.',
  19. tag: 'Pré-configuré',
  20. tagStyle: 'tag--pre',
  21. },
  22. {
  23. id: 'process-generique',
  24. title: 'Process générique',
  25. desc: 'Applicable à tout process opérationnel : achat, production, relation client, support, projet…',
  26. tag: 'Universel',
  27. tagStyle: 'tag--new',
  28. },
  29. {
  30. id: 'process-generique-v2',
  31. title: 'Diagnostic d\'opportunité',
  32. desc: 'Évaluez sur 8 axes si ce process est prioritaire à automatiser : friction, volume, risque, données, outils, variabilité, collaboration, déploiement.',
  33. tag: 'Diagnostic d\'opportunité',
  34. tagStyle: 'tag--v2',
  35. },
  36. {
  37. id: 'transformation-excel',
  38. title: 'Transformation fichier Excel',
  39. desc: 'Votre fichier Excel vous coûte-t-il du temps, des erreurs ou de la maîtrise ? 14 questions pour savoir s\'il faut le garder, l\'optimiser ou le transformer en application web.',
  40. tag: 'Transformation Excel',
  41. tagStyle: 'tag--excel',
  42. },
  43. {
  44. id: 'intervention-sav-maintenance-terrain-v2-compact',
  45. title: 'Intervention SAV / Maintenance terrain',
  46. desc: '16 questions pour auditer votre process d\'interventions terrain : canal d\'entrée, affectation, traçabilité, KPI, résilience et coût caché.',
  47. tag: 'Pré-configuré',
  48. tagStyle: 'tag--pre',
  49. },
  50. {
  51. id: 'internal-requests-validations-v2',
  52. title: 'Demandes internes & validations',
  53. desc: '16 questions pour auditer votre process de demandes internes (achats, RH, IT, juridique, marketing…) : point d\'entrée, catégorisation, règles de validation, traçabilité, résilience et coût.',
  54. tag: 'Pré-configuré',
  55. tagStyle: 'tag--pre',
  56. },
  57. {
  58. id: 'collecte-terrain-qualite-conformite-v2',
  59. title: 'Collecte terrain / qualité / conformité',
  60. desc: '16 questions pour auditer checklists, contrôles, non-conformités et traçabilité audit : clarté, fiabilité, preuve, résilience et coût.',
  61. tag: 'Pré-configuré',
  62. tagStyle: 'tag--pre',
  63. },
  64. ];
  65. /* ── Outils à venir ── */
  66. const COMING_SOON_TOOLS = [
  67. {
  68. id: 'process-mapper',
  69. title: 'Process Mapper',
  70. desc: 'Cartographiez visuellement votre process étape par étape, identifiez les goulots d\'étranglement et générez une documentation structurée prête à partager.',
  71. },
  72. ];
  73. const state = {
  74. view: 'landing',
  75. packId: null,
  76. pack: null,
  77. idx: 0,
  78. answers: {},
  79. optional: {},
  80. result: null,
  81. emailUnlocked: false,
  82. unlockExiting: false,
  83. captureEmail: '',
  84. notifyTool: '',
  85. roiInputs: { volume: '', tempsActuel: '', tempsCible: '', salaireNet: '', tauxErreurs: '', tempsErreur: '', delaiActuel: '', delaiCible: '' },
  86. roiResult: null,
  87. qwfSignals: {},
  88. qwfResult: null,
  89. excelSignals: {},
  90. excelResult: null,
  91. excelQual: { outil: null, personnes: null, consequence: [] },
  92. excelStep: 1,
  93. };
  94. let autoAdvanceTimer = null;
  95. /* ── DOM helpers ── */
  96. function h(tag, attrs = {}, children = []) {
  97. const el = document.createElement(tag);
  98. for (const [k, v] of Object.entries(attrs || {})) {
  99. if (k === 'class') el.className = v;
  100. else if (k.startsWith('on') && typeof v === 'function') el.addEventListener(k.slice(2).toLowerCase(), v);
  101. else if (v !== undefined && v !== null && v !== false) el.setAttribute(k, String(v));
  102. }
  103. for (const child of (Array.isArray(children) ? children : [children])) {
  104. if (child == null) continue;
  105. el.appendChild(typeof child === 'string' ? document.createTextNode(child) : child);
  106. }
  107. return el;
  108. }
  109. function storageKey(packId) { return `aes_${packId}_v1`; }
  110. function saveProgress() {
  111. if (!state.packId) return;
  112. localStorage.setItem(storageKey(state.packId), JSON.stringify({ answers: state.answers, optional: state.optional }));
  113. }
  114. function loadProgress(packId) {
  115. try {
  116. const obj = JSON.parse(localStorage.getItem(storageKey(packId)) || '{}');
  117. return {
  118. answers: typeof obj?.answers === 'object' ? obj.answers : {},
  119. optional: typeof obj?.optional === 'object' ? obj.optional : {},
  120. };
  121. } catch { return { answers: {}, optional: {} }; }
  122. }
  123. async function apiJson(path, { method = 'GET', body } = {}) {
  124. const headers = {};
  125. if (body) {
  126. headers['Content-Type'] = 'application/json';
  127. const csrf = appEl?.dataset?.csrfToken;
  128. if (csrf) headers['X-CSRF-Token'] = csrf;
  129. }
  130. const res = await fetch(`${API_BASE}${path}`, {
  131. method,
  132. headers: Object.keys(headers).length ? headers : undefined,
  133. body: body ? JSON.stringify(body) : undefined,
  134. credentials: 'same-origin',
  135. });
  136. const data = await res.json().catch(() => ({}));
  137. if (!res.ok) throw new Error(data?.error || 'Erreur API');
  138. return data;
  139. }
  140. function setView(v) { state.view = v; render(); }
  141. /* ── Navigation globale (exposée pour la navbar) ── */
  142. const VIEW_TO_NAV = {
  143. select: 'nav-diag',
  144. intro: 'nav-diag',
  145. quiz: 'nav-diag',
  146. computing: 'nav-diag',
  147. optional: 'nav-diag',
  148. results: 'nav-diag',
  149. roi: 'nav-roi',
  150. 'roi-results': 'nav-roi',
  151. qwf: 'nav-qwf',
  152. 'qwf-results': 'nav-qwf',
  153. excel: 'nav-excel',
  154. 'excel-results': 'nav-excel',
  155. };
  156. const VIEW_LABELS = {
  157. select: 'Diagnostic process',
  158. intro: null,
  159. quiz: null,
  160. computing: null,
  161. optional: null,
  162. results: null,
  163. roi: 'ROI Calculator',
  164. 'roi-results': 'ROI Calculator',
  165. qwf: 'Quick Wins Finder',
  166. 'qwf-results': 'Quick Wins Finder',
  167. excel: 'Excel → Application',
  168. 'excel-results': 'Excel → Application',
  169. };
  170. function getNavLabel() {
  171. if (['intro', 'quiz', 'computing', 'optional', 'results'].includes(state.view)) {
  172. return state.pack?.pack_title || 'Diagnostic process';
  173. }
  174. return VIEW_LABELS[state.view] || null;
  175. }
  176. function updateNavbar() {
  177. const crumb = document.getElementById('navBreadcrumb');
  178. if (crumb) crumb.textContent = getNavLabel() || '';
  179. document.querySelectorAll('.navbar__dropdown-item').forEach(el => el.classList.remove('active'));
  180. if (state.view !== 'landing') {
  181. let navId = VIEW_TO_NAV[state.view];
  182. if (!navId && state.packId === 'process-generique-v2') navId = 'nav-v2';
  183. if (navId) document.getElementById(navId)?.classList.add('active');
  184. }
  185. }
  186. window._ae = {
  187. goStart,
  188. goDiag: () => setView('select'),
  189. goV2: () => selectPack('process-generique-v2'),
  190. goRoi: () => setView('roi'),
  191. goQwf: () => setView('qwf'),
  192. goExcel: () => { state.excelStep = 1; setView('excel'); },
  193. };
  194. function hasOptionalQuestions() {
  195. const opt = state.pack?.optional_questions || {};
  196. return Object.keys(opt).length > 0;
  197. }
  198. function goStart() {
  199. Object.assign(state, { packId: null, pack: null, idx: 0, answers: {}, optional: {}, result: null, emailUnlocked: false, unlockExiting: false, captureEmail: '' });
  200. setView('landing');
  201. }
  202. async function selectPack(packId) {
  203. state.packId = packId;
  204. const saved = loadProgress(packId);
  205. state.answers = saved.answers;
  206. state.optional = saved.optional;
  207. try {
  208. const data = await apiJson(`/pack.php?pack=${encodeURIComponent(packId)}`);
  209. state.pack = data.pack;
  210. state.idx = 0;
  211. setView('intro');
  212. } catch (e) {
  213. alert('Impossible de charger le pack : ' + (e.message || ''));
  214. }
  215. }
  216. function levelColor(level) {
  217. return { A: '#1e8a5e', B: '#1e8a5e', C: '#c07c10', D: '#b83040' }[level] || '#2F506D';
  218. }
  219. /* ── COMING-SOON card helper ── */
  220. function makeComingSoonCard(tool) {
  221. return h('div', {
  222. class: 'pack-card pack-card--soon',
  223. onClick: () => {
  224. state.notifyTool = tool.id;
  225. document.getElementById('notifyDialog')?.showModal();
  226. },
  227. }, [
  228. h('span', { class: 'tag tag--soon' }, ['Bientôt disponible']),
  229. h('div', { class: 'title', style: 'margin-top:8px' }, [tool.title]),
  230. h('div', { class: 'desc' }, [tool.desc]),
  231. h('div', { class: 'soon-overlay' }, [
  232. h('div', { class: 'soon-overlay__label' }, ['Bientôt disponible']),
  233. h('div', { class: 'soon-overlay__text' }, ['Me notifier du lancement →']),
  234. ]),
  235. ]);
  236. }
  237. /* ── NOTIFY DIALOG (Coming soon) ── */
  238. function renderNotifyDialog() {
  239. const toolMeta = COMING_SOON_TOOLS.find(t => t.id === state.notifyTool);
  240. const toolName = toolMeta?.title || 'cet outil';
  241. const onSubmit = async (e) => {
  242. e.preventDefault();
  243. const email = e.target.querySelector('input[type="email"]').value.trim();
  244. if (!email) return;
  245. const btn = e.target.querySelector('button[type="submit"]');
  246. btn.disabled = true;
  247. btn.textContent = 'Envoi…';
  248. try {
  249. await apiJson('/notify.php', { method: 'POST', body: { email, tool: state.notifyTool } });
  250. const body = document.querySelector('#notifyDialog .dialog__body');
  251. if (body) {
  252. body.innerHTML = '';
  253. body.appendChild(h('div', { style: 'text-align:center;padding:20px 0' }, [
  254. h('div', { class: 'h2', style: 'color:var(--good);margin-bottom:8px' }, ['C\'est noté !']),
  255. h('p', { class: 'lead' }, [`Vous serez parmi les premiers informés du lancement de ${toolName}.`]),
  256. h('button', {
  257. class: 'btn btn--primary', style: 'margin-top:16px',
  258. onClick: () => document.getElementById('notifyDialog')?.close(),
  259. }, ['Fermer']),
  260. ]));
  261. }
  262. } catch (err) {
  263. btn.disabled = false;
  264. btn.textContent = 'Me prévenir au lancement →';
  265. alert('Erreur : ' + (err.message || 'Réessayez.'));
  266. }
  267. };
  268. return h('dialog', { id: 'notifyDialog', class: 'dialog' }, [
  269. h('div', { class: 'dialog__inner' }, [
  270. h('div', { class: 'dialog__head' }, [
  271. h('strong', {}, [`Soyez informé : ${toolName}`]),
  272. h('button', {
  273. class: 'btn btn--outline', style: 'padding:6px 12px;font-size:13px', type: 'button',
  274. onClick: () => document.getElementById('notifyDialog')?.close(),
  275. }, ['Fermer']),
  276. ]),
  277. h('div', { class: 'dialog__body' }, [
  278. h('p', { class: 'lead', style: 'margin-bottom:16px' }, [
  279. `${toolName} est en cours de développement. Laissez votre email et on vous prévient en priorité au lancement.`,
  280. ]),
  281. h('form', { onSubmit }, [
  282. h('div', { class: 'field' }, [
  283. h('label', { for: 'notifyEmail' }, ['Email professionnel']),
  284. h('input', {
  285. id: 'notifyEmail', type: 'email', required: 'required',
  286. placeholder: 'vous@entreprise.com', autocomplete: 'email',
  287. }),
  288. ]),
  289. h('div', { class: 'btnrow', style: 'margin-top:14px' }, [
  290. h('button', { class: 'btn btn--primary', type: 'submit' }, ['Me prévenir au lancement →']),
  291. ]),
  292. h('p', { class: 'hint' }, ['Aucun spam. Désabonnement en 1 clic.']),
  293. ]),
  294. ]),
  295. ]),
  296. ]);
  297. }
  298. /* ── LANDING (page d'accueil) ── */
  299. function renderLanding() {
  300. const diagnosticV2 = PACK_CATALOGUE.find(p => p.id === 'process-generique-v2');
  301. const makeCard = (attrs, children) => h('div', attrs, children);
  302. /* Audits & Diagnostics */
  303. const auditCards = [
  304. makeCard({ class: 'pack-card', onClick: () => setView('select') }, [
  305. h('span', { class: 'tag tag--pre' }, ['Diagnostic']),
  306. h('div', { class: 'title' }, ['Diagnostic process', h('span', { class: 'arrow' }, [' →'])]),
  307. h('div', { class: 'desc' }, ['Évaluez votre process sur 5 piliers en 20 questions. Packs pré-configurés (onboarding, facture) ou questionnaire universel.']),
  308. ]),
  309. diagnosticV2 ? makeCard({ class: 'pack-card', onClick: () => selectPack(diagnosticV2.id) }, [
  310. h('span', { class: `tag ${diagnosticV2.tagStyle}` }, [diagnosticV2.tag]),
  311. h('div', { class: 'title' }, [diagnosticV2.title, h('span', { class: 'arrow' }, [' →'])]),
  312. h('div', { class: 'desc' }, [diagnosticV2.desc]),
  313. ]) : null,
  314. makeCard({ class: 'pack-card', onClick: () => { state.excelStep = 1; setView('excel'); } }, [
  315. h('span', { class: 'tag tag--excel' }, ['Excel → Application']),
  316. h('div', { class: 'title' }, ['Dois-je transformer mon Excel ?', h('span', { class: 'arrow' }, [' →'])]),
  317. h('div', { class: 'desc' }, ['15 signaux pour savoir si votre fichier Excel a atteint ses limites et si une application web est justifiée.']),
  318. ]),
  319. ].filter(Boolean);
  320. /* Calculateurs rapides */
  321. const calcCards = [
  322. makeCard({ class: 'pack-card', onClick: () => setView('roi') }, [
  323. h('span', { class: 'tag tag--roi' }, ['ROI Calculator']),
  324. h('div', { class: 'title' }, ['ROI Calculator', h('span', { class: 'arrow' }, [' →'])]),
  325. h('div', { class: 'desc' }, ['Chiffrez le gain mensuel et le ROI annuel. Identifiez les 2 leviers qui pèsent le plus sur votre process.']),
  326. ]),
  327. makeCard({ class: 'pack-card', onClick: () => setView('qwf') }, [
  328. h('span', { class: 'tag tag--qwf' }, ['Quick Wins Finder']),
  329. h('div', { class: 'title' }, ['Quick Wins Finder', h('span', { class: 'arrow' }, [' →'])]),
  330. h('div', { class: 'desc' }, ['7 signaux → 3 actions concrètes et priorisées avec résultat attendu, effort et délai typique.']),
  331. ]),
  332. ];
  333. return h('div', { class: 'grid' }, [
  334. h('div', { class: 'card' }, [
  335. h('h1', { class: 'h1' }, ['Choisissez un outil']),
  336. h('p', { class: 'lead' }, ['Diagnostiquez et optimisez vos process opérationnels.']),
  337. /* Section 1 : Audits & Diagnostics */
  338. h('div', { class: 'landing-section' }, [
  339. h('div', { class: 'section-label section-label--audit' }, ['Audits & Diagnostics']),
  340. h('div', { class: 'grid grid--2' }, auditCards),
  341. ]),
  342. /* Section 2 : Calculateurs rapides */
  343. h('div', { class: 'landing-section' }, [
  344. h('div', { class: 'section-label section-label--calc' }, ['Calculateurs rapides']),
  345. h('div', { class: 'grid grid--2' }, calcCards),
  346. ]),
  347. /* Section 3 : Conseil (booking) */
  348. BOOKING_URL ? h('div', { class: 'landing-section' }, [
  349. h('div', { class: 'section-label section-label--conseil' }, ['Conseil & accompagnement']),
  350. h('div', { class: 'grid grid--2' }, [
  351. h('a', {
  352. class: 'pack-card pack-card--link',
  353. href: BOOKING_URL,
  354. target: '_blank',
  355. rel: 'noreferrer',
  356. }, [
  357. h('span', { class: 'tag tag--booking' }, ['Prise de décision']),
  358. h('div', { class: 'title' }, ['Faisabilité d\'automatisation d\'un process', h('span', { class: 'arrow' }, [' →'])]),
  359. h('div', { class: 'desc' }, ['Moins d\'une heure. Prenez rendez-vous pour évaluer ensemble si votre process est prioritaire à automatiser.']),
  360. ]),
  361. ]),
  362. ]) : null,
  363. /* Section 4 : Bientôt disponible */
  364. h('div', { class: 'landing-section' }, [
  365. h('div', { class: 'section-label' }, ['Bientôt disponible']),
  366. h('div', { class: 'grid grid--2' }, COMING_SOON_TOOLS.map(makeComingSoonCard)),
  367. ]),
  368. ]),
  369. renderNotifyDialog(),
  370. ]);
  371. }
  372. /* ── SELECT (page Diagnostic process) ── */
  373. function renderSelect() {
  374. const makeCard = (p, featured = false) =>
  375. h('div', { class: `pack-card${featured ? ' pack-card--featured' : ''}`, onClick: () => selectPack(p.id) }, [
  376. h('span', { class: `tag ${p.tagStyle}` }, [p.tag]),
  377. h('div', { class: 'title' }, [p.title, h('span', { class: 'arrow' }, [' →'])]),
  378. h('div', { class: 'desc' }, [p.desc]),
  379. ]);
  380. const preConfigured = PACK_CATALOGUE.filter(p => p.tag === 'Pré-configuré');
  381. const generic = PACK_CATALOGUE.find(p => p.id === 'process-generique');
  382. return h('div', { class: 'grid' }, [
  383. h('div', { class: 'card' }, [
  384. h('h1', { class: 'h1' }, ['Choisissez le process à diagnostiquer']),
  385. h('p', { class: 'lead' }, ['Utilisez le questionnaire universel ou un pack pré-configuré.']),
  386. h('div', { class: 'section-label section-label--featured', style: 'margin-top:18px' }, ['Process universel']),
  387. h('div', { class: 'grid grid--2' }, generic ? [makeCard(generic, true)] : []),
  388. h('div', { class: 'section-label', style: 'margin-top:24px' }, ['Packs pré-configurés']),
  389. h('div', { class: 'grid grid--2' }, preConfigured.map(makeCard)),
  390. h('div', { class: 'btnrow', style: 'margin-top:18px' }, [
  391. h('button', { class: 'btn btn--outline', onClick: () => setView('landing') }, ['← Retour']),
  392. ]),
  393. ]),
  394. ]);
  395. }
  396. /* ── INTRO ── */
  397. function renderIntro() {
  398. const meta = PACK_CATALOGUE.find(p => p.id === state.packId);
  399. const answeredCount = Object.keys(state.answers).length;
  400. const total = state.pack?.questions?.length || 20;
  401. const hasSaved = answeredCount > 0;
  402. const startFresh = () => {
  403. state.answers = {};
  404. state.optional = {};
  405. state.idx = 0;
  406. state.emailUnlocked = false;
  407. state.unlockExiting = false;
  408. state.captureEmail = '';
  409. saveProgress();
  410. setView('quiz');
  411. };
  412. const resume = () => {
  413. const qs = state.pack?.questions || [];
  414. let resumeIdx = 0;
  415. for (let i = 0; i < qs.length; i++) {
  416. if (state.answers[qs[i].id]) resumeIdx = i;
  417. }
  418. state.idx = Math.min(resumeIdx + 1, qs.length - 1);
  419. setView('quiz');
  420. };
  421. return h('div', { class: 'grid' }, [
  422. h('div', { class: 'card' }, [
  423. h('span', { class: `tag ${meta?.tagStyle || ''}`, style: 'margin-bottom:12px;display:inline-block' }, [
  424. state.pack?.pack_title || '',
  425. ]),
  426. h('h1', { class: 'h1' }, ['Avant de commencer']),
  427. h('p', { class: 'lead' }, [
  428. 'Répondez franchement. Le score sert à prioriser, pas à juger. ',
  429. `Temps estimé : ${total <= 15 ? 5 : 7} minutes. Questions : ${total}.`,
  430. ]),
  431. state.pack?.pack_description
  432. ? h('p', { style: 'color:var(--muted);font-size:14px;margin-top:0' }, [state.pack.pack_description])
  433. : null,
  434. hasSaved
  435. ? h('div', { class: 'resume-notice' }, [
  436. h('span', {}, [`Progression sauvegardée : ${answeredCount} / ${total} questions`]),
  437. ])
  438. : null,
  439. h('div', { class: 'btnrow' }, [
  440. h('button', { class: 'btn btn--outline', onClick: () => setView('landing') }, ['← Choisir un autre outil']),
  441. hasSaved
  442. ? h('button', { class: 'btn btn--outline', onClick: startFresh }, ['Recommencer à zéro'])
  443. : null,
  444. h('button', { class: 'btn btn--primary', onClick: hasSaved ? resume : startFresh }, [
  445. hasSaved ? `Reprendre (Q${Math.min(Object.keys(state.answers).length + 1, total)}) →` : 'Commencer →',
  446. ]),
  447. ]),
  448. ]),
  449. ]);
  450. }
  451. /* ── QUIZ ── */
  452. function renderQuiz() {
  453. const q = state.pack?.questions?.[state.idx];
  454. if (!q) return h('div', { class: 'card' }, ['Chargement…']);
  455. const total = state.pack.questions.length;
  456. const pos = state.idx + 1;
  457. const pct = Math.round(((pos - 1) / total) * 100);
  458. const selected = state.answers[q.id] || '';
  459. const opts = (q.options || []).map(opt => {
  460. const id = `opt_${q.id}_${opt.id}`;
  461. const isSelected = selected === opt.id;
  462. const isNa = opt.id === 'NA' || opt.id === 'DK' || opt.id.toLowerCase().endsWith('_na') || opt.id.toLowerCase().endsWith('_dk');
  463. return h('label', { class: `opt${isSelected ? ' opt--selected' : ''}${isNa ? ' opt--na' : ''}`, for: id }, [
  464. h('input', {
  465. id, type: 'radio', name: q.id, value: opt.id,
  466. checked: isSelected ? 'checked' : null,
  467. onChange: (e) => {
  468. state.answers[q.id] = e.target.value;
  469. saveProgress();
  470. render();
  471. if (autoAdvanceTimer) clearTimeout(autoAdvanceTimer);
  472. autoAdvanceTimer = setTimeout(() => {
  473. autoAdvanceTimer = null;
  474. const t = state.pack?.questions?.length || 0;
  475. if (state.idx < t - 1) { state.idx++; saveProgress(); render(); }
  476. else setView(hasOptionalQuestions() ? 'optional' : 'computing');
  477. }, 380);
  478. },
  479. }),
  480. h('div', {}, [h('strong', {}, [opt.label])]),
  481. ]);
  482. });
  483. const canPrev = state.idx > 0;
  484. const canNext = !!selected;
  485. const isLast = state.idx === total - 1;
  486. const next = async () => {
  487. if (!canNext) return;
  488. if (!isLast) { state.idx++; saveProgress(); render(); return; }
  489. setView(hasOptionalQuestions() ? 'optional' : 'computing');
  490. };
  491. return h('div', { class: 'grid' }, [
  492. h('div', { class: 'card' }, [
  493. h('div', { class: 'quizHead' }, [
  494. h('span', { class: 'tag', style: 'font-size:11px' }, [state.pack.pack_title]),
  495. h('div', { class: 'quizStep' }, [
  496. h('strong', {}, [`${pos}`]),
  497. h('span', {}, [` / ${total}`]),
  498. ]),
  499. ]),
  500. h('div', { class: 'progressWrap' }, [
  501. h('div', { class: 'progress' }, [h('div', { style: `width:${pct}%` })]),
  502. h('div', { class: 'progressMeta' }, [
  503. h('span', { class: 'progressPct' }, [`${pct}\u00a0%`]),
  504. h('span', { class: 'progressRemain' }, [
  505. isLast ? 'Dernière question' : `encore ${total - pos} question${total - pos > 1 ? 's' : ''}`,
  506. ]),
  507. ]),
  508. ]),
  509. h('div', { class: 'qTitle' }, [q.label]),
  510. q.help ? h('p', { class: 'qHelp' }, [q.help]) : null,
  511. h('div', { class: 'options' }, opts),
  512. h('div', { class: 'btnrow', style: 'margin-top:18px' }, [
  513. h('button', { class: 'btn btn--outline', disabled: canPrev ? null : 'disabled', onClick: () => { state.idx--; saveProgress(); render(); } }, ['← Précédent']),
  514. h('button', { class: `btn ${canNext ? 'btn--primary' : 'btn--outline'}`, disabled: canNext ? null : 'disabled', onClick: next }, [
  515. isLast ? 'Voir mon résultat →' : 'Suivant →',
  516. ]),
  517. ]),
  518. h('p', { class: 'hint', style: 'margin-top:10px' }, ['Vous pouvez modifier vos réponses avant la fin.']),
  519. ]),
  520. ]);
  521. }
  522. /* ── COMPUTING (skip optional, submit directly) ── */
  523. function renderComputing() {
  524. (async () => {
  525. try {
  526. const data = await apiJson('/score.php', {
  527. method: 'POST',
  528. body: { pack_id: state.packId, answers: state.answers, optional: state.optional },
  529. });
  530. state.result = data.result;
  531. saveProgress();
  532. setView('results');
  533. } catch (e) { alert(e.message || 'Erreur'); }
  534. })();
  535. return h('div', { class: 'grid' }, [
  536. h('div', { class: 'card', style: 'text-align:center;padding:40px 20px' }, [
  537. h('div', { class: 'h2' }, ['Calcul en cours…']),
  538. h('p', { class: 'lead' }, ['Analyse de vos réponses et génération du diagnostic.']),
  539. ]),
  540. ]);
  541. }
  542. /* ── OPTIONAL ── */
  543. function renderOptional() {
  544. const opt = state.pack?.optional_questions || {};
  545. const volumeKey = Object.keys(opt).find(k => opt[k]?.required_for_cost);
  546. const volumeQ = volumeKey ? opt[volumeKey] : null;
  547. const makeRadioGroup = (q, stateKey, storeAsNumber = true) => {
  548. const cur = state.optional[stateKey];
  549. return h('div', { class: 'field' }, [
  550. h('label', {}, [q.label]),
  551. h('div', { class: 'options', style: 'margin-top:6px' }, q.options.map(o => {
  552. const id = `opt_${stateKey}_${o.id}`;
  553. const val = String(o.value ?? o.id);
  554. const onCh = (e) => {
  555. const v = e.target.value;
  556. state.optional[stateKey] = storeAsNumber && /^-?\d+(\.\d+)?$/.test(v) ? Number(v) : v;
  557. saveProgress();
  558. };
  559. return h('label', { class: 'opt', for: id }, [
  560. h('input', {
  561. id, type: 'radio', name: stateKey, value: val,
  562. checked: String(cur) === val ? 'checked' : null,
  563. onChange: onCh,
  564. }),
  565. h('div', {}, [h('strong', {}, [o.label])]),
  566. ]);
  567. })),
  568. ]);
  569. };
  570. const netSalaryInput = h('div', { class: 'field' }, [
  571. h('label', { for: 'opt_net_salary' }, ['Salaire net mensuel estimé des personnes impliquées']),
  572. h('input', {
  573. id: 'opt_net_salary', type: 'number', min: '0', step: '100',
  574. placeholder: '3500',
  575. value: state.optional.net_salary !== undefined ? String(state.optional.net_salary) : '',
  576. onInput: (e) => { state.optional.net_salary = e.target.value ? Number(e.target.value) : undefined; saveProgress(); },
  577. }),
  578. h('div', { class: 'field-hint' }, [
  579. 'Coût chargé France = salaire net × 1,82 / 152 h/mois (charges salariales + patronales).',
  580. state.optional.net_salary
  581. ? ` → ${Math.round(state.optional.net_salary * COEFF_CHARGE_FR / HEURES_MOIS)} €/h estimé.`
  582. : ' Par défaut : 3 500 €/mois → ~42 €/h.',
  583. ]),
  584. ]);
  585. const compute = async () => {
  586. try {
  587. const optWithCost = { ...state.optional };
  588. const sn = state.optional.net_salary;
  589. if (sn) {
  590. optWithCost.hourly_cost = Math.round(sn * COEFF_CHARGE_FR / HEURES_MOIS);
  591. }
  592. const data = await apiJson('/score.php', {
  593. method: 'POST',
  594. body: { pack_id: state.packId, answers: state.answers, optional: optWithCost },
  595. });
  596. state.result = data.result;
  597. saveProgress();
  598. setView('results');
  599. } catch (e) { alert(e.message || 'Erreur'); }
  600. };
  601. const qualKeys = Object.keys(opt).filter(k => k !== volumeKey && k !== 'net_salary' && opt[k]?.options);
  602. const hasCost = volumeQ || state.pack?.cost_hidden;
  603. const qualBlocks = qualKeys.map(k => makeRadioGroup(opt[k], k, false));
  604. return h('div', { class: 'grid' }, [
  605. h('div', { class: 'card' }, [
  606. h('span', { class: 'tag tag--new', style: 'margin-bottom:12px;display:inline-block' }, ['Optionnel']),
  607. h('h1', { class: 'h1' }, [hasCost ? 'Quelques infos pour le coût caché' : 'Quelques infos pour personnaliser vos résultats']),
  608. h('p', { class: 'lead' }, [hasCost ? 'Ces données servent uniquement à estimer le coût caché en heures/mois (indicatif). Vous pouvez passer.' : 'Ces données nous aident à mieux qualifier votre contexte. Vous pouvez passer.']),
  609. ...qualBlocks,
  610. volumeQ ? makeRadioGroup(volumeQ, volumeKey) : null,
  611. hasCost ? netSalaryInput : null,
  612. h('div', { class: 'btnrow', style: 'margin-top:20px' }, [
  613. h('button', { class: 'btn btn--outline', onClick: () => setView('quiz') }, ['← Retour']),
  614. h('button', { class: 'btn btn--primary', onClick: compute }, ['Voir mes résultats →']),
  615. ]),
  616. ]),
  617. ]);
  618. }
  619. /* ── RESULTS ── */
  620. function renderResults() {
  621. const r = state.result;
  622. if (!r) return h('div', { class: 'card' }, ['Calcul en cours…']);
  623. const dotColor = levelColor(r.level);
  624. const cost = r.cost_hidden;
  625. const unlocked = state.emailUnlocked;
  626. const pillarRows = (r.pillars || []).map(p => {
  627. const pct = p.max ? Math.round((p.score / p.max) * 100) : 0;
  628. return h('div', { class: 'pRow' }, [
  629. h('div', { class: 'name' }, [p.label]),
  630. h('div', { class: 'val' }, [`${p.score}/${p.max}`]),
  631. h('div', { class: 'bar' }, [h('div', { style: `width:${pct}%` })]),
  632. ]);
  633. });
  634. const riskItems = (r.risks_top3 || []).map(x =>
  635. h('li', {}, [
  636. h('strong', {}, [x.title]),
  637. h('div', { class: 'hint' }, [x.what_happens]),
  638. ])
  639. );
  640. const winItems = (r.quick_wins_preview || []).map(x =>
  641. h('li', {}, [
  642. h('strong', {}, [x.title]),
  643. h('div', { class: 'hint' }, [`${x.effect} ; Effort : ${x.effort}`]),
  644. ])
  645. );
  646. /* ── Excel Diagnostic ── */
  647. const xl = r.excel_diagnostic || null;
  648. const renderExcelDiagnostic = () => {
  649. if (!xl) return null;
  650. const doulColor = xl.douleur >= 65 ? '#b83040' : xl.douleur >= 35 ? '#c07c10' : '#1e8a5e';
  651. const cplxColor = xl.complexite >= 60 ? '#b83040' : xl.complexite >= 35 ? '#c07c10' : '#1e8a5e';
  652. const verdictColor = { transformer: '#b83040', intermediaire: '#c07c10', optimiser: '#1e8a5e' }[xl.verdict.code] || '#2F506D';
  653. const meter = (score, label, color) =>
  654. h('div', { class: 'v2-meter' }, [
  655. h('div', { class: 'v2-meter__num', style: `color:${color}` }, [String(score)]),
  656. h('div', { class: 'v2-meter__sub' }, ['/100']),
  657. h('div', { class: 'v2-meter__lbl' }, [label]),
  658. h('div', { class: 'v2-meter__track' }, [
  659. h('div', { class: 'v2-meter__fill', style: `width:${score}%;background:${color}` }),
  660. ]),
  661. ]);
  662. return h('div', { class: 'card v2-diagnostic' }, [
  663. h('div', { class: 'v2-meters' }, [
  664. meter(xl.douleur, 'Douleur actuelle (collaboration, friction, risque)', doulColor),
  665. meter(xl.complexite, 'Complexité du fichier (technique, gouvernance)', cplxColor),
  666. ]),
  667. h('div', { class: 'v2-badges' }, [
  668. h('span', { class: 'v2-verdict-badge', style: `border-color:${verdictColor};color:${verdictColor}` }, [
  669. `${xl.verdict.label} — ${xl.verdict.desc}`,
  670. ]),
  671. h('span', { class: `v2-tag-badge${xl.tag === 'optimiser' ? ' v2-tag-badge--qw' : xl.tag === 'intermediaire' ? ' v2-tag-badge--qw' : ' v2-tag-badge--proj'}` }, [
  672. xl.tag_label,
  673. ]),
  674. ]),
  675. ]);
  676. };
  677. const renderExcelMiniPlan = () => {
  678. if (!xl || !unlocked) return null;
  679. const actionList = (items, startNum) =>
  680. h('ol', { class: 'v2-plan-list', start: String(startNum) },
  681. (items || []).map(a => h('li', {}, [
  682. h('strong', {}, [a.title]),
  683. h('span', { class: 'hint' }, [` - ${a.effect} ; Effort : ${a.effort}`]),
  684. ]))
  685. );
  686. return h('div', { class: 'v2-mini-plan' }, [
  687. h('div', { class: 'v2-plan-cols' }, [
  688. h('div', { class: 'card v2-plan-section' }, [
  689. h('div', { class: 'v2-plan-title' }, ['3 actions immédiates']),
  690. actionList(xl.actions, 1),
  691. ]),
  692. h('div', { class: 'card v2-plan-section v2-plan-section--qw' }, [
  693. h('div', { class: 'v2-plan-title' }, ['2 quick wins possibles']),
  694. actionList(xl.quick_wins, 4),
  695. ]),
  696. ]),
  697. xl.risque_majeur ? h('div', { class: 'v2-plan-risk-block' }, [
  698. h('div', { class: 'v2-plan-title v2-plan-title--risk' }, ['1 risque majeur à adresser en parallèle']),
  699. h('div', { class: 'v2-plan-risk-card' }, [
  700. h('strong', {}, [xl.risque_majeur.title]),
  701. h('p', { class: 'hint', style: 'margin-top:4px' }, [xl.risque_majeur.what_happens]),
  702. ]),
  703. ]) : null,
  704. ]);
  705. };
  706. /* ── V2 Diagnostic ── */
  707. const v2 = r.v2_diagnostic || null;
  708. const renderV2Diagnostic = () => {
  709. if (!v2) return null;
  710. const potColor = v2.potentiel >= 70 ? '#1e8a5e' : v2.potentiel >= 40 ? '#c07c10' : '#b83040';
  711. const cplxColor = v2.complexite <= 35 ? '#1e8a5e' : v2.complexite <= 65 ? '#c07c10' : '#b83040';
  712. const verdictColor = { prioritaire: '#1e8a5e', candidat: '#c07c10', attente: '#5e789a' }[v2.verdict.code] || '#2F506D';
  713. const meter = (score, label, color) =>
  714. h('div', { class: 'v2-meter' }, [
  715. h('div', { class: 'v2-meter__num', style: `color:${color}` }, [String(score)]),
  716. h('div', { class: 'v2-meter__sub' }, ['/100']),
  717. h('div', { class: 'v2-meter__lbl' }, [label]),
  718. h('div', { class: 'v2-meter__track' }, [
  719. h('div', { class: 'v2-meter__fill', style: `width:${score}%;background:${color}` }),
  720. ]),
  721. ]);
  722. return h('div', { class: 'card v2-diagnostic' }, [
  723. h('div', { class: 'v2-meters' }, [
  724. meter(v2.potentiel, 'Potentiel d\'automatisation', potColor),
  725. meter(v2.complexite, 'Complexité de mise en œuvre', cplxColor),
  726. ]),
  727. h('div', { class: 'v2-badges' }, [
  728. h('span', { class: 'v2-verdict-badge', style: `border-color:${verdictColor};color:${verdictColor}` }, [
  729. `${v2.verdict.label} - ${v2.verdict.desc}`,
  730. ]),
  731. h('span', { class: `v2-tag-badge${v2.tag === 'quick_win' ? ' v2-tag-badge--qw' : ' v2-tag-badge--proj'}` }, [
  732. v2.tag_label,
  733. ]),
  734. ]),
  735. ]);
  736. };
  737. const renderMiniPlan = () => {
  738. if (!v2 || !unlocked) return null;
  739. const actionList = (items, startNum) =>
  740. h('ol', { class: 'v2-plan-list', start: String(startNum) },
  741. (items || []).map(a => h('li', {}, [
  742. h('strong', {}, [a.title]),
  743. h('span', { class: 'hint' }, [` - ${a.effect} ; Effort : ${a.effort}`]),
  744. ]))
  745. );
  746. return h('div', { class: 'v2-mini-plan' }, [
  747. h('div', { class: 'v2-plan-cols' }, [
  748. h('div', { class: 'card v2-plan-section' }, [
  749. h('div', { class: 'v2-plan-title' }, ['3 actions immédiates']),
  750. actionList(v2.actions, 1),
  751. ]),
  752. h('div', { class: 'card v2-plan-section v2-plan-section--qw' }, [
  753. h('div', { class: 'v2-plan-title' }, ['2 quick wins possibles']),
  754. actionList(v2.quick_wins, 4),
  755. ]),
  756. ]),
  757. v2.risque_majeur ? h('div', { class: 'v2-plan-risk-block' }, [
  758. h('div', { class: 'v2-plan-title v2-plan-title--risk' }, ['1 risque majeur à adresser en parallèle']),
  759. h('div', { class: 'v2-plan-risk-card' }, [
  760. h('strong', {}, [v2.risque_majeur.title]),
  761. h('p', { class: 'hint', style: 'margin-top:4px' }, [v2.risque_majeur.what_happens]),
  762. ]),
  763. ]) : null,
  764. ]);
  765. };
  766. /* ── Unlock gate ── */
  767. const renderUnlockGate = () => {
  768. const onUnlock = (e) => {
  769. e.preventDefault();
  770. const email = e.target.querySelector('input[type="email"]').value.trim();
  771. if (!email.includes('@') || email.length < 5) return;
  772. state.captureEmail = email;
  773. state.unlockExiting = true;
  774. render();
  775. setTimeout(() => {
  776. state.emailUnlocked = true;
  777. state.unlockExiting = false;
  778. saveProgress();
  779. render();
  780. setTimeout(() => document.getElementById('pdfDialog')?.showModal(), 50);
  781. }, 320);
  782. };
  783. const exiting = state.unlockExiting;
  784. return h('div', { class: 'unlock-gate' + (exiting ? ' unlock-gate--exiting' : '') }, [
  785. h('div', { class: 'unlock-gate__inner' }, [
  786. h('div', { class: 'unlock-gate__icon' }, ['↓']),
  787. h('div', { class: 'h2', style: 'margin-bottom:6px' }, ['Débloquez vos axes d\'amélioration']),
  788. h('p', { class: 'lead', style: 'margin-bottom:20px' }, [
  789. 'Entrez votre email professionnel pour accéder aux 5 actions prioritaires et télécharger votre PDF synthèse.',
  790. ]),
  791. h('form', { class: 'unlock-form', onSubmit: onUnlock }, [
  792. h('div', { class: 'unlock-row' }, [
  793. h('input', {
  794. type: 'email', required: 'required',
  795. placeholder: 'vous@entreprise.com',
  796. autocomplete: 'email',
  797. }),
  798. h('button', { class: 'btn btn--primary btn--unlock', type: 'submit' }, ['Débloquer →']),
  799. ]),
  800. h('p', { class: 'hint', style: 'margin-top:8px;text-align:center' }, [
  801. 'Aucun spam. Désinscription en 1 clic.',
  802. ]),
  803. ]),
  804. ]),
  805. ]);
  806. };
  807. /* ── CTAs débloqués ── */
  808. const renderUnlockedCtas = () =>
  809. h('div', { class: 'unlocked-ctas unlocked-ctas--entering' }, [
  810. h('div', { class: 'unlocked-ctas__inner' }, [
  811. /* En-tête */
  812. h('div', { class: 'h2', style: 'margin-bottom:6px' }, ['Et maintenant ?']),
  813. h('p', { class: 'lead', style: 'margin-bottom:24px' }, [
  814. 'Votre diagnostic révèle des opportunités concrètes. Réservez un entretien offert avec un consultant pour les prioriser et définir votre plan d\'action.',
  815. ]),
  816. /* CTAs commerciaux */
  817. h('div', { class: 'cta-block' }, [
  818. BOOKING_URL ? h('div', { style: 'display:flex;flex-direction:column;align-items:center;width:100%' }, [
  819. h('span', { class: 'cta-offert' }, ['30 min offert']),
  820. h('a', {
  821. class: 'btn btn--primary btn--cta-main',
  822. href: BOOKING_URL, target: '_blank', rel: 'noreferrer',
  823. }, ['Découvrir les opportunités suite à mon audit - Entretien de 30 min offert avec un consultant']),
  824. ]) : null,
  825. DEVIS_URL ? h('a', {
  826. class: 'btn btn--outline btn--cta-secondary',
  827. href: DEVIS_URL,
  828. }, ['Demander un devis']) : null,
  829. ]),
  830. h('p', { class: 'hint', style: 'text-align:center;margin-top:10px' }, [
  831. 'Pas d\'engagement. On analyse vos résultats ensemble et on vous propose une solution adaptée.',
  832. ]),
  833. /* Séparateur */
  834. h('hr', { style: 'border:none;border-top:1px solid var(--border,#e2e8f0);margin:24px 0' }),
  835. /* Actions secondaires */
  836. h('div', { class: 'btnrow', style: 'justify-content:center;gap:10px' }, [
  837. h('button', {
  838. class: 'btn btn--outline',
  839. onClick: () => document.getElementById('pdfDialog')?.showModal(),
  840. }, ['Télécharger mon PDF']),
  841. h('button', {
  842. class: 'btn btn--outline',
  843. style: 'font-size:13px',
  844. onClick: goStart,
  845. }, ['Diagnostiquer un autre process']),
  846. ]),
  847. ]),
  848. ]);
  849. return h('div', { class: 'grid' }, [
  850. /* Score header */
  851. h('div', { class: 'card' }, [
  852. h('div', { style: 'display:flex;align-items:center;gap:10px;margin-bottom:16px' }, [
  853. h('span', { class: 'tag' }, [state.pack?.pack_title || '']),
  854. ]),
  855. h('div', { class: 'scoreBox' }, [
  856. h('div', {}, [
  857. h('div', { class: 'scoreLabel' }, ['Score global']),
  858. h('div', { class: 'scoreBig' }, [`${r.score_total}/100`]),
  859. h('div', { class: 'level-badge', style: 'margin-top:10px' }, [
  860. h('span', { class: 'level-dot', style: `background:${dotColor}` }),
  861. h('span', {}, [`${r.level} - ${r.level_label}`]),
  862. ]),
  863. h('div', { class: 'confidence' }, [`Confiance du diagnostic : ${r.confidence?.label || ''}`]),
  864. ]),
  865. ]),
  866. h('div', { class: 'pillars' }, pillarRows),
  867. ]),
  868. /* V2 : carte diagnostic (toujours visible) */
  869. v2 ? renderV2Diagnostic() : null,
  870. /* Excel : carte diagnostic (toujours visible) */
  871. xl ? renderExcelDiagnostic() : null,
  872. /* Non-V2/Excel : risques (visibles uniquement après déblocage) */
  873. !v2 && !xl && unlocked && !state.unlockExiting ? h('div', { class: 'card' }, [
  874. h('div', { class: 'h2' }, ['3 risques probables']),
  875. riskItems.length
  876. ? h('ol', { class: 'list' }, riskItems)
  877. : h('p', { class: 'muted small' }, ['Aucun risque majeur détecté.']),
  878. ]) : null,
  879. /* Non-V2/Excel : coût caché (visible uniquement après déblocage) */
  880. !v2 && !xl && unlocked && !state.unlockExiting && cost ? h('div', { class: 'cost-block' }, [
  881. h('div', { class: 'h2' }, ['Coût caché estimé']),
  882. h('div', { class: 'cost-figures' }, [
  883. h('div', { class: 'cost-fig' }, [
  884. h('span', { class: 'val' }, [`${cost.hours_per_month} h`]),
  885. h('span', { class: 'lbl' }, ['par mois (estimé)']),
  886. ]),
  887. h('div', { class: 'cost-fig' }, [
  888. h('span', { class: 'val' }, [`~${cost.eur_per_month} €`]),
  889. h('span', { class: 'lbl' }, ['par mois (indicatif)']),
  890. ]),
  891. ]),
  892. h('p', { class: 'hint' }, ['Estimation indicative, à valider par mesure réelle.']),
  893. ]) : null,
  894. /* Gate (formulaire déblocage) ou contenu débloqué - gate visible pendant animation de sortie */
  895. !unlocked || state.unlockExiting ? renderUnlockGate() : null,
  896. /* V2 : mini plan (débloqué) */
  897. v2 ? renderMiniPlan() : null,
  898. /* Excel : mini plan (débloqué) */
  899. xl ? renderExcelMiniPlan() : null,
  900. /* Non-V2/Excel : quick wins (débloqués) */
  901. !v2 && !xl && unlocked && !state.unlockExiting ? h('div', { class: 'card' }, [
  902. h('div', { class: 'h2' }, ['5 quick wins prioritaires']),
  903. winItems.length
  904. ? h('ol', { class: 'list' }, winItems)
  905. : h('p', { class: 'muted small' }, ['-']),
  906. h('p', { class: 'hint', style: 'margin-top:8px' }, ['Le PDF contient les 5 actions avec détail effort/impact.']),
  907. ]) : null,
  908. /* CTA débloqué */
  909. unlocked && !state.unlockExiting ? renderUnlockedCtas() : null,
  910. renderPdfDialog(),
  911. ]);
  912. }
  913. /* ── PDF DIALOG ── */
  914. function renderPdfDialog() {
  915. const onSubmit = async (e) => {
  916. e.preventDefault();
  917. const email = e.target.email.value.trim();
  918. if (!email) return;
  919. try {
  920. const headers = { 'Content-Type': 'application/json' };
  921. const csrf = appEl?.dataset?.csrfToken;
  922. if (csrf) headers['X-CSRF-Token'] = csrf;
  923. const res = await fetch(`${API_BASE}/pdf.php`, {
  924. method: 'POST',
  925. headers,
  926. credentials: 'same-origin',
  927. body: JSON.stringify({
  928. pack_id: state.packId, answers: state.answers,
  929. optional: state.optional, booking_url: BOOKING_URL, email,
  930. }),
  931. });
  932. if (!res.ok) { const j = await res.json().catch(() => ({})); throw new Error(j?.error || 'Erreur PDF'); }
  933. const blob = await res.blob();
  934. const url = URL.createObjectURL(blob);
  935. const a = document.createElement('a');
  936. a.href = url; a.download = `controle-technique-${state.packId}.pdf`;
  937. document.body.appendChild(a); a.click(); a.remove(); URL.revokeObjectURL(url);
  938. document.getElementById('pdfDialog')?.close();
  939. } catch (err) { alert(err.message || 'Erreur'); }
  940. };
  941. return h('dialog', { id: 'pdfDialog', class: 'dialog' }, [
  942. h('form', { class: 'dialog__inner', onSubmit }, [
  943. h('div', { class: 'dialog__head' }, [
  944. h('strong', {}, ['Télécharger votre synthèse PDF']),
  945. h('button', { class: 'btn btn--outline', style: 'padding:6px 12px;font-size:13px', type: 'button',
  946. onClick: () => document.getElementById('pdfDialog')?.close() }, ['Fermer']),
  947. ]),
  948. h('div', { class: 'dialog__body' }, [
  949. h('div', { class: 'field' }, [
  950. h('label', { for: 'pdfEmail' }, ['Email professionnel']),
  951. h('input', {
  952. id: 'pdfEmail', name: 'email', type: 'email', required: 'required',
  953. placeholder: 'vous@entreprise.com',
  954. value: state.captureEmail || '',
  955. }),
  956. ]),
  957. h('label', { class: 'check' }, [
  958. h('input', { type: 'checkbox', required: 'required' }),
  959. h('span', {}, ['J\'accepte de recevoir mon PDF et un email de suivi éventuel.']),
  960. ]),
  961. h('div', { class: 'btnrow', style: 'margin-top:14px' }, [
  962. h('button', { class: 'btn btn--primary', type: 'submit' }, ['Télécharger mon PDF →']),
  963. ]),
  964. h('p', { class: 'hint' }, ['Désinscription en 1 clic. Suppression des données sur demande.']),
  965. ]),
  966. ]),
  967. ]);
  968. }
  969. /* ════════════════════════════════════════════════════
  970. ROI CALCULATOR - données & calcul
  971. ════════════════════════════════════════════════════ */
  972. // Coût chargé France : net → brut (÷0,78) → coût employeur (×1,42) ≈ net × 1,82
  973. // Base légale 35h : 35 × 52 / 12 ≈ 152 h/mois
  974. const COEFF_CHARGE_FR = 1.82;
  975. const HEURES_MOIS = 152;
  976. const ROI_DEFAULTS = { salaireNet: 3500, tauxErreurs: 10, tempsErreur: 15 };
  977. function computeRoi(inp) {
  978. const v = Math.max(0, parseFloat(inp.volume) || 0);
  979. const tA = Math.max(0, parseFloat(inp.tempsActuel) || 0);
  980. const tC = Math.max(0, parseFloat(inp.tempsCible) || 0);
  981. const sn = inp.salaireNet !== '' ? (parseFloat(inp.salaireNet) || 0) : ROI_DEFAULTS.salaireNet;
  982. const ch = Math.round((sn * COEFF_CHARGE_FR) / HEURES_MOIS * 100) / 100;
  983. const te = inp.tauxErreurs !== '' ? (parseFloat(inp.tauxErreurs) || 0) : ROI_DEFAULTS.tauxErreurs;
  984. const tpe = inp.tempsErreur !== '' ? (parseFloat(inp.tempsErreur) || 0) : ROI_DEFAULTS.tempsErreur;
  985. const usedDefaults = [inp.salaireNet, inp.tauxErreurs, inp.tempsErreur].filter(x => x === '').length;
  986. const confidence = usedDefaults === 0 ? 'Fort' : usedDefaults <= 1 ? 'Moyen' : 'Faible';
  987. const gainTempsMin = v * Math.max(0, tA - tC);
  988. const gainTempsH = gainTempsMin / 60;
  989. const gainTraitement = gainTempsH * ch;
  990. const nbErreurs = v * (te / 100);
  991. const gainErreursMin = nbErreurs * tpe;
  992. const gainErreursH = gainErreursMin / 60;
  993. const gainErreurs = gainErreursH * ch;
  994. const roiMensuel = gainTraitement + gainErreurs;
  995. const roiAnnuel = roiMensuel * 12;
  996. const levers = [
  997. { label: 'Gain de traitement', euros: gainTraitement, heures: gainTempsH, detail: `${v} cas × ${Math.max(0, tA - tC)} min gagnées` },
  998. { label: 'Réduction des erreurs', euros: gainErreurs, heures: gainErreursH, detail: `~${Math.round(nbErreurs * 10) / 10} erreurs évitées × ${tpe} min` },
  999. ].sort((a, b) => b.euros - a.euros);
  1000. const conclusion =
  1001. roiAnnuel >= 50000 ? 'À ce niveau, l\'investissement se rentabilise en quelques semaines - difficile de ne pas le faire.' :
  1002. roiAnnuel >= 20000 ? 'À ce niveau, ça se rentabilise en moins de 3 mois sur la plupart des projets.' :
  1003. roiAnnuel >= 5000 ? 'Des gains concrets et mesurables - suffisant pour déclencher une discussion interne.' :
  1004. 'Des gains modestes en valeur absolue, mais chaque heure récupérée libère du temps à forte valeur.';
  1005. return { gainTempsH, gainTraitement, gainErreursH, gainErreurs, roiMensuel, roiAnnuel, levers, conclusion, confidence, usedDefaults, coutHoraire: ch, salaireNet: sn };
  1006. }
  1007. function renderRoi() {
  1008. const inp = state.roiInputs;
  1009. const roiField = (key, label, unit, required, placeholder, defHint) =>
  1010. h('div', { class: 'roi-field' }, [
  1011. h('label', { for: `roi_${key}` }, [
  1012. label,
  1013. h('span', { class: 'roi-unit' }, [` (${unit})`]),
  1014. ]),
  1015. h('input', {
  1016. id: `roi_${key}`, type: 'number', min: '0', step: 'any',
  1017. required: required ? 'required' : null,
  1018. placeholder: placeholder != null ? String(placeholder) : undefined,
  1019. value: inp[key] !== undefined ? String(inp[key]) : '',
  1020. onInput: (e) => { state.roiInputs[key] = e.target.value; },
  1021. }),
  1022. defHint ? h('div', { class: 'field-hint' }, [defHint]) : null,
  1023. ]);
  1024. return h('div', { class: 'grid' }, [
  1025. h('form', { class: 'card', onSubmit: (e) => { e.preventDefault(); state.roiResult = computeRoi(state.roiInputs); setView('roi-results'); } }, [
  1026. h('div', { style: 'margin-bottom:14px' }, [h('span', { class: 'tag tag--roi' }, ['ROI Calculator'])]),
  1027. h('h1', { class: 'h1' }, ['Calculez le gain potentiel de votre optimisation']),
  1028. h('p', { class: 'lead' }, [
  1029. 'Renseignez vos données - les valeurs par défaut permettent d\'avancer sans avoir tous les chiffres.',
  1030. ]),
  1031. h('div', { class: 'section-label', style: 'margin-top:18px' }, ['Données de base']),
  1032. h('p', { class: 'hint', style: 'margin:0 0 10px' }, ['Ces 3 champs sont nécessaires au calcul.']),
  1033. h('div', { class: 'roi-grid' }, [
  1034. roiField('volume', 'Volume mensuel', 'cas/mois', true, 80),
  1035. roiField('tempsActuel', 'Temps actuel par cas', 'min', true, 45),
  1036. roiField('tempsCible', 'Temps cible après opt.', 'min', true, 20),
  1037. ]),
  1038. h('div', { class: 'section-label', style: 'margin-top:20px' }, ['Paramètres de coût']),
  1039. h('p', { class: 'hint', style: 'margin:0 0 10px' }, ['Pré-remplis avec des valeurs types - modifiez si vous les connaissez.']),
  1040. h('div', { class: 'roi-grid' }, [
  1041. roiField('salaireNet', 'Salaire net mensuel estimé', '€/mois', false, null, 'Par défaut : 3 500 €/mois → ~42 €/h chargé'),
  1042. roiField('tauxErreurs', 'Taux erreurs / retours', '%', false, null, 'Par défaut : 10 %'),
  1043. roiField('tempsErreur', 'Temps perdu par erreur', 'min', false, null, 'Par défaut : 15 min'),
  1044. ]),
  1045. h('p', { class: 'hint', style: 'margin:4px 0 0;font-style:italic' }, [
  1046. 'Coût chargé France = salaire net × 1,82 / 152 h/mois (charges salariales + patronales estimées).',
  1047. ]),
  1048. h('div', { class: 'btnrow', style: 'margin-top:24px' }, [
  1049. h('button', { class: 'btn btn--outline', type: 'button', onClick: () => setView('landing') }, ['← Retour']),
  1050. h('button', { class: 'btn btn--primary', type: 'submit' }, ['Calculer mon ROI →']),
  1051. ]),
  1052. ]),
  1053. ]);
  1054. }
  1055. function renderRoiResults() {
  1056. const r = state.roiResult;
  1057. if (!r) { setView('roi'); return h('div', {}); }
  1058. const fmt = (n) => Math.round(n).toLocaleString('fr-FR');
  1059. const fmtH = (n) => n < 1 ? `${Math.round(n * 60)} min` : `${(Math.round(n * 10) / 10).toLocaleString('fr-FR')} h`;
  1060. const confClass = { Fort: 'confidence-pill--fort', Moyen: 'confidence-pill--moyen', Faible: 'confidence-pill--faible' }[r.confidence] || '';
  1061. const confLabel = {
  1062. Fort: '● Confiance forte - vos propres chiffres',
  1063. Moyen: '◐ Confiance moyenne - mix données + défauts',
  1064. Faible: '○ Confiance faible - majorité de valeurs par défaut',
  1065. }[r.confidence] || '';
  1066. return h('div', { class: 'grid' }, [
  1067. h('div', { class: 'card' }, [
  1068. h('div', { style: 'display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:10px;margin-bottom:12px' }, [
  1069. h('span', { class: 'tag tag--roi' }, ['ROI Calculator - Résultats']),
  1070. h('span', { class: `confidence-pill ${confClass}` }, [confLabel]),
  1071. ]),
  1072. h('div', { class: 'roi-hero' }, [
  1073. h('div', { class: 'roi-hero__item' }, [
  1074. h('div', { class: 'roi-hero__val' }, [`${fmt(r.roiMensuel)} €`]),
  1075. h('div', { class: 'roi-hero__lbl' }, ['ROI mensuel estimé']),
  1076. h('div', { class: 'roi-hero__sub' }, [`≈ ${fmt(r.roiAnnuel)} €/an`]),
  1077. ]),
  1078. h('div', { class: 'roi-hero__sep' }),
  1079. h('div', { class: 'roi-hero__item' }, [
  1080. h('div', { class: 'roi-hero__val' }, [fmtH(r.gainTempsH + r.gainErreursH)]),
  1081. h('div', { class: 'roi-hero__lbl' }, ['Heures récupérées / mois']),
  1082. ]),
  1083. ]),
  1084. ]),
  1085. h('div', { class: 'card' }, [
  1086. h('div', { class: 'h2' }, ['Les 2 leviers qui pèsent le plus']),
  1087. h('div', { class: 'lever-cards' }, r.levers.map((l, i) =>
  1088. h('div', { class: `lever-card${i === 0 ? ' lever-card--top' : ''}` }, [
  1089. h('div', { class: 'lever-card__lbl' }, [i === 0 ? '🏆 Levier principal' : 'Levier secondaire']),
  1090. h('div', { style: 'font-weight:700;font-size:15px;color:var(--navy);margin:4px 0 2px' }, [l.label]),
  1091. h('div', { class: 'lever-card__amt' }, [`${fmt(l.euros)} €/mois`]),
  1092. h('div', { class: 'lever-card__det' }, [`${fmtH(l.heures)} récupérées ; ${l.detail}`]),
  1093. ])
  1094. )),
  1095. ]),
  1096. h('div', { class: 'conclusion-box' }, [
  1097. h('p', {}, [r.conclusion]),
  1098. h('p', { class: 'hint' }, [
  1099. `Hypothèse coût : ${Math.round(r.coutHoraire)} €/h chargé (base ${r.salaireNet.toLocaleString('fr-FR')} € net/mois × 1,82 / 152 h — France).`,
  1100. ]),
  1101. r.usedDefaults > 0
  1102. ? h('p', { class: 'hint' }, [
  1103. `${r.usedDefaults} valeur${r.usedDefaults > 1 ? 's' : ''} par défaut utilisée${r.usedDefaults > 1 ? 's' : ''} - affinez avec vos chiffres réels pour plus de précision.`,
  1104. ])
  1105. : null,
  1106. ]),
  1107. h('div', { class: 'card' }, [
  1108. h('div', { class: 'h2' }, ['Et maintenant ?']),
  1109. h('p', { class: 'lead', style: 'margin-bottom:16px' }, [
  1110. 'Utilisez ces chiffres pour déclencher une décision. La prochaine étape : identifier les 3 actions concrètes à mettre en œuvre.',
  1111. ]),
  1112. h('div', { class: 'btnrow' }, [
  1113. BOOKING_URL ? h('a', { class: 'btn btn--primary', href: BOOKING_URL, target: '_blank', rel: 'noreferrer' }, ['Entretien 30 min offert avec un consultant']) : null,
  1114. h('button', { class: BOOKING_URL ? 'btn btn--outline' : 'btn btn--primary', onClick: () => setView('qwf') }, ['Trouver mes 3 quick wins →']),
  1115. ]),
  1116. h('div', { class: 'btnrow', style: 'margin-top:6px' }, [
  1117. h('button', { class: 'btn btn--outline', style: 'font-size:13px', onClick: () => setView('roi') }, ['← Modifier mes données']),
  1118. h('button', { class: 'btn btn--outline', style: 'font-size:13px', onClick: () => setView('landing') }, ['Autres outils']),
  1119. ]),
  1120. ]),
  1121. ]);
  1122. }
  1123. /* ════════════════════════════════════════════════════
  1124. QUICK WINS FINDER - données & calcul
  1125. ════════════════════════════════════════════════════ */
  1126. const QW_LIBRARY = [
  1127. {
  1128. id: 'statuts-notifications',
  1129. title: 'Statuts uniques + notifications ciblées',
  1130. result: 'Fin des relances et visibilité instantanée sur l\'avancement',
  1131. setup: 'Statut central (ex : "à valider", "en cours IT", "bloqué", "terminé") + notifications automatiques aux bons rôles',
  1132. prereqs: 'Définir un owner, les statuts métier, accès boîtes mail ou Teams',
  1133. effort: 'S à M', delay: '2 à 4 semaines',
  1134. impact: ['Baisse du délai global', 'Moins d\'interruptions', 'Moins de relances'],
  1135. triggers: { relancesFrequentes: 3, validationsMultiples: 1 },
  1136. },
  1137. {
  1138. id: 'formulaire-intelligent',
  1139. title: 'Formulaire intelligent de collecte',
  1140. result: 'Moins de retours arrière, dossiers complets dès le départ',
  1141. setup: 'Champs conditionnels + contrôles à la saisie + pièces demandées au bon moment + validation de cohérence',
  1142. prereqs: 'Liste des champs obligatoires, règles simples, rôles définis',
  1143. effort: 'M', delay: '3 à 6 semaines',
  1144. impact: ['Baisse des erreurs', 'Baisse du temps de traitement', 'Moins de rejets'],
  1145. triggers: { erreursFréquentes: 3, validationsMultiples: 2 },
  1146. },
  1147. {
  1148. id: 'suppression-double-saisie',
  1149. title: 'Suppression de la double saisie entre outils',
  1150. result: 'Arrêt du copier-coller Excel/email vers outil final',
  1151. setup: 'Synchronisation des champs clés (push) ou import structuré automatique entre les outils',
  1152. prereqs: 'Accès API ou export/import structuré, mapping des champs clés',
  1153. effort: 'M', delay: '4 à 8 semaines',
  1154. impact: ['Gain de temps direct', 'Moins d\'erreurs de saisie', 'Données fiables partout'],
  1155. triggers: { doubleSaisie: 3, nbOutilsEleve: 2 },
  1156. },
  1157. {
  1158. id: 'dossier-unique',
  1159. title: 'Dossier unique par dossier',
  1160. result: 'Fin du chaos documentaire - tout au même endroit',
  1161. setup: 'Convention de nommage + dépôt structuré des pièces + lien unique accessible depuis le process',
  1162. prereqs: 'Choix d\'un espace de stockage partagé, définition des règles de nommage',
  1163. effort: 'S', delay: '1 à 3 semaines',
  1164. impact: ['Moins de temps perdu à chercher', 'Moins d\'erreurs', 'Meilleure traçabilité'],
  1165. triggers: { docsEparpilles: 3, erreursFréquentes: 1 },
  1166. },
  1167. {
  1168. id: 'workflow-validation',
  1169. title: 'Workflow de validation simplifié',
  1170. result: 'Validation en un clic, délais réduits, zéro perte en route',
  1171. setup: 'Règles de validation claires + SLA définis + tableau de bord de suivi des en-cours',
  1172. prereqs: 'Matrice de validation, SLA définis, accès configuré pour les validateurs',
  1173. effort: 'M', delay: '3 à 5 semaines',
  1174. impact: ['Baisse du délai global', 'Moins de blocages', 'Meilleure traçabilité'],
  1175. triggers: { validationsMultiples: 3, relancesFrequentes: 1 },
  1176. },
  1177. {
  1178. id: 'exports-automatiques',
  1179. title: 'Exports propres automatiques',
  1180. result: 'Fin du reporting manuel - données toujours à jour',
  1181. setup: 'Export planifié + format standard + envoi automatique aux destinataires',
  1182. prereqs: 'Accès aux sources de données, liste des destinataires, fréquence définie',
  1183. effort: 'S à M', delay: '2 à 5 semaines',
  1184. impact: ['Temps récupéré sur le reporting', 'Fiabilité des données', 'Partage facilité'],
  1185. triggers: { reportingManuel: 3, nbOutilsEleve: 1 },
  1186. },
  1187. ];
  1188. const QWF_QUESTIONS = [
  1189. { id: 'doubleSaisie', label: 'Des données sont saisies manuellement dans plusieurs outils différents (copier-coller, ressaisie…)' },
  1190. { id: 'validationsMultiples', label: 'Plusieurs personnes ou étapes distinctes doivent valider chaque dossier' },
  1191. { id: 'relancesFrequentes', label: 'Des relances sont nécessaires pour savoir où en est un dossier' },
  1192. { id: 'docsEparpilles', label: 'Les documents d\'un dossier sont éparpillés (email, drive, bureau local…)' },
  1193. { id: 'reportingManuel', label: 'Du reporting est préparé manuellement (copier-coller, recomposition de données)' },
  1194. { id: 'erreursFréquentes', label: 'Des dossiers reviennent en arrière à cause d\'informations manquantes ou incorrectes' },
  1195. { id: 'nbOutilsEleve', label: 'Ce process fait intervenir 3 outils ou plus (ERP, email, tableur, outil métier…)' },
  1196. ];
  1197. function computeQuickWins(signals) {
  1198. return QW_LIBRARY
  1199. .map(qw => {
  1200. let score = 0;
  1201. for (const [trigger, weight] of Object.entries(qw.triggers)) {
  1202. if (signals[trigger]) score += weight;
  1203. }
  1204. return { ...qw, score };
  1205. })
  1206. .sort((a, b) => b.score - a.score)
  1207. .slice(0, 3);
  1208. }
  1209. function renderQwf() {
  1210. const sig = state.qwfSignals;
  1211. const makeSignalRow = (q) => {
  1212. const isOui = sig[q.id] === true;
  1213. const isNon = sig[q.id] === false;
  1214. return h('div', { class: 'signal-row' }, [
  1215. h('span', { class: 'signal-row__lbl' }, [q.label]),
  1216. h('div', { class: 'signal-row__btns' }, [
  1217. h('button', {
  1218. type: 'button',
  1219. class: `signal-btn signal-btn--oui${isOui ? ' active' : ''}`,
  1220. onClick: () => { state.qwfSignals[q.id] = isOui ? undefined : true; render(); },
  1221. }, ['Oui']),
  1222. h('button', {
  1223. type: 'button',
  1224. class: `signal-btn signal-btn--non${isNon ? ' active' : ''}`,
  1225. onClick: () => { state.qwfSignals[q.id] = isNon ? undefined : false; render(); },
  1226. }, ['Non']),
  1227. ]),
  1228. ]);
  1229. };
  1230. const answeredCount = QWF_QUESTIONS.filter(q => sig[q.id] !== undefined).length;
  1231. const canSubmit = answeredCount >= 3;
  1232. return h('div', { class: 'grid' }, [
  1233. h('div', { class: 'card' }, [
  1234. h('div', { style: 'margin-bottom:14px' }, [h('span', { class: 'tag tag--qwf' }, ['Quick Wins Finder'])]),
  1235. h('h1', { class: 'h1' }, ['Identifiez vos 3 actions prioritaires']),
  1236. h('p', { class: 'lead' }, [
  1237. 'Répondez à ces 7 signaux pour recevoir 3 recommandations concrètes adaptées à votre process.',
  1238. ]),
  1239. h('div', { class: 'signal-list' }, QWF_QUESTIONS.map(makeSignalRow)),
  1240. h('div', { class: 'btnrow', style: 'margin-top:22px' }, [
  1241. h('button', { class: 'btn btn--outline', onClick: () => setView('landing') }, ['← Retour']),
  1242. h('button', {
  1243. class: 'btn btn--primary',
  1244. disabled: canSubmit ? null : 'disabled',
  1245. onClick: () => { if (canSubmit) { state.qwfResult = computeQuickWins(state.qwfSignals); setView('qwf-results'); } },
  1246. }, [canSubmit ? 'Voir mes 3 quick wins →' : `Répondre à encore ${3 - answeredCount} signal${3 - answeredCount > 1 ? 's' : ''}`]),
  1247. ]),
  1248. h('p', { class: 'hint', style: 'margin-top:8px' }, ['Répondez à au moins 3 signaux pour déverrouiller le résultat.']),
  1249. ]),
  1250. ]);
  1251. }
  1252. function renderQwfResults() {
  1253. const qws = state.qwfResult;
  1254. if (!qws || qws.length === 0) { setView('qwf'); return h('div', {}); }
  1255. const makeQwCard = (qw, idx) =>
  1256. h('div', { class: 'qw-card' }, [
  1257. h('div', { class: 'qw-card__head' }, [
  1258. h('div', { class: 'qw-card__num' }, [String(idx + 1)]),
  1259. h('div', { class: 'qw-card__head-title' }, [qw.title]),
  1260. ]),
  1261. h('div', { class: 'qw-card__body' }, [
  1262. h('div', { class: 'qw-card__result' }, [qw.result]),
  1263. h('div', { class: 'qw-section' }, [
  1264. h('div', { class: 'qw-section__lbl' }, ['Ce qu\'on met en place']),
  1265. h('div', { class: 'qw-section__val' }, [qw.setup]),
  1266. ]),
  1267. h('div', { class: 'qw-section' }, [
  1268. h('div', { class: 'qw-section__lbl' }, ['Pré-requis']),
  1269. h('div', { class: 'qw-section__val' }, [qw.prereqs]),
  1270. ]),
  1271. h('div', { class: 'qw-meta' }, [
  1272. h('span', { class: 'badge-effort' }, [`Effort : ${qw.effort}`]),
  1273. h('span', { class: 'badge-delay' }, [`Délai : ${qw.delay}`]),
  1274. ]),
  1275. h('div', { class: 'impact-chips' }, qw.impact.map(i =>
  1276. h('span', { class: 'impact-chip' }, [i])
  1277. )),
  1278. ]),
  1279. ]);
  1280. return h('div', { class: 'grid' }, [
  1281. h('div', { class: 'card' }, [
  1282. h('div', { style: 'margin-bottom:12px' }, [h('span', { class: 'tag tag--qwf' }, ['Quick Wins Finder - Résultats'])]),
  1283. h('h1', { class: 'h1' }, ['Vos 3 actions prioritaires']),
  1284. h('p', { class: 'lead' }, [
  1285. 'Commencez par la première - elle a le plus fort impact selon vos signaux. Chaque fiche contient tout ce qu\'il faut pour démarrer.',
  1286. ]),
  1287. ]),
  1288. h('div', { class: 'qw-cards' }, qws.map(makeQwCard)),
  1289. h('div', { class: 'card' }, [
  1290. h('div', { class: 'h2' }, ['Et maintenant ?']),
  1291. h('p', { class: 'lead', style: 'margin-bottom:16px' }, [
  1292. 'Ces 3 quick wins sont un point de départ solide. Un entretien offert avec un consultant permet de découvrir les opportunités et de cadrer le quick win n°1 en plan d\'action.',
  1293. ]),
  1294. h('div', { class: 'btnrow' }, [
  1295. BOOKING_URL ? h('a', {
  1296. class: 'btn btn--primary', href: BOOKING_URL, target: '_blank', rel: 'noreferrer',
  1297. }, ['Découvrir les opportunités - Entretien 30 min offert']) : null,
  1298. h('button', { class: 'btn btn--outline', onClick: () => setView('roi') }, ['Calculer le ROI →']),
  1299. ]),
  1300. h('div', { class: 'btnrow', style: 'margin-top:6px' }, [
  1301. h('button', { class: 'btn btn--outline', style: 'font-size:13px', onClick: () => setView('qwf') }, ['← Modifier mes signaux']),
  1302. h('button', { class: 'btn btn--outline', style: 'font-size:13px', onClick: () => setView('landing') }, ['Autres outils']),
  1303. ]),
  1304. ]),
  1305. ]);
  1306. }
  1307. /* ════════════════════════════════════════════════════
  1308. EXCEL → APPLICATION - données & calcul
  1309. ════════════════════════════════════════════════════ */
  1310. const EXCEL_QUESTIONS = [
  1311. { id: 'multiUsagers', label: 'Plus d\'une personne utilise ce fichier Excel' },
  1312. { id: 'simultaneite', label: 'Plusieurs personnes ont besoin de le modifier en même temps' },
  1313. { id: 'erreursSaisie', label: 'Des erreurs de saisie ont déjà causé des problèmes réels (mauvais montant, perte de données…)' },
  1314. { id: 'doubleSaisie', label: 'Des données sont copiées-collées depuis ou vers d\'autres outils (ERP, CRM, email…)' },
  1315. { id: 'partageExterne', label: 'Le fichier est partagé avec des clients, fournisseurs ou partenaires externes' },
  1316. { id: 'tracabilite', label: 'Vous avez besoin de savoir qui a modifié quoi et quand (historique, audit trail)' },
  1317. { id: 'automatisation', label: 'Vous avez besoin de notifications, rappels ou alertes automatiques' },
  1318. { id: 'complexite', label: 'Le fichier est devenu lent, fragile ou difficile à maintenir pour un non-expert' },
  1319. { id: 'processStatuts', label: 'Ce fichier sert à gérer un processus avec des étapes, statuts ou validations' },
  1320. { id: 'impactExternal', label: 'Une erreur ou un retard dans ce fichier peut impacter un client, un fournisseur ou la production' },
  1321. { id: 'tempsPerdu', label: 'Vous et votre équipe passez plus de 2 heures par semaine à saisir, vérifier, corriger ou relancer autour de ce fichier' },
  1322. { id: 'personnesCle', label: 'Une seule personne maîtrise vraiment le fonctionnement du fichier (formules, logique, macros)' },
  1323. { id: 'processStable', label: 'Le processus géré par ce fichier est stable (il ne change pas complètement tous les mois)' },
  1324. { id: 'vuesProfils', label: 'Vous avez besoin de vues différentes selon les profils (opérateur, manager, direction, client, RH…)' },
  1325. { id: 'scalabilite', label: 'Si le volume d\'activité double, ce fichier risque de ne plus tenir correctement' },
  1326. ];
  1327. const EXCEL_QUAL_OUTIL = [
  1328. { id: 'excel_local', label: 'Excel local / réseau' },
  1329. { id: 'excel_partage', label: 'Excel partagé (SharePoint / OneDrive)' },
  1330. { id: 'google_sheet', label: 'Google Sheet' },
  1331. { id: 'les_deux', label: 'Les deux' },
  1332. ];
  1333. const EXCEL_QUAL_PERSONNES = [
  1334. { id: '1', label: '1 seule' },
  1335. { id: '2_3', label: '2 à 3' },
  1336. { id: '4_10', label: '4 à 10' },
  1337. { id: 'plus10', label: 'Plus de 10' },
  1338. ];
  1339. const EXCEL_QUAL_CONSEQUENCE = [
  1340. { id: 'temps', label: 'Perte de temps' },
  1341. { id: 'erreurs', label: 'Risque d\'erreur' },
  1342. { id: 'visibilite', label: 'Manque de visibilité' },
  1343. { id: 'conformite', label: 'Conformité / audit' },
  1344. { id: 'client', label: 'Impact client / fournisseur' },
  1345. ];
  1346. function computeExcelVerdict(signals, qual = {}) {
  1347. const total = EXCEL_QUESTIONS.length;
  1348. const score = EXCEL_QUESTIONS.filter(q => signals[q.id] === true).length;
  1349. if (score <= 4) {
  1350. return {
  1351. score, total, level: 'ok', qual,
  1352. title: 'Excel reste adapté pour l\'instant',
  1353. color: '#1e8a5e',
  1354. icon: '✓',
  1355. summary: `Avec ${score} signaux sur ${total}, votre usage d'Excel est encore maîtrisable. Continuez à l'utiliser, mais documentez vos règles et anticipez l'évolution de vos besoins.`,
  1356. actions: [
  1357. 'Documentez vos formules et règles métier pour faciliter la maintenance et la transmission',
  1358. 'Mettez en place des sauvegardes automatiques et un versionnage du fichier',
  1359. 'Réévaluez dans 6 mois si le volume d\'utilisateurs ou de données augmente',
  1360. ],
  1361. };
  1362. } else if (score <= 8) {
  1363. return {
  1364. score, total, level: 'warn', qual,
  1365. title: 'Vous approchez des limites d\'Excel',
  1366. color: '#c07c10',
  1367. icon: '⚠',
  1368. summary: `Avec ${score} signaux sur ${total}, votre Excel fonctionne encore mais vous en perdez progressivement le contrôle. Une application dédiée deviendra nécessaire à court terme.`,
  1369. actions: [
  1370. 'Identifiez les 2 risques prioritaires (erreurs humaines, conflits de version, perte de données)',
  1371. 'Explorez des solutions no-code ou low-code (Airtable, AppSheet, Make) pour une transition progressive',
  1372. 'Planifiez la migration avant que la situation ne devienne critique ou coûteuse à réparer',
  1373. ],
  1374. };
  1375. } else {
  1376. return {
  1377. score, total, level: 'critical', qual,
  1378. title: 'Une application dédiée s\'impose',
  1379. color: '#b83040',
  1380. icon: '!',
  1381. summary: `Avec ${score} signaux sur ${total}, Excel ne répond plus à vos besoins. Chaque jour sans application dédiée génère des risques réels et du temps perdu.`,
  1382. actions: [
  1383. 'Priorisez ce projet : le coût de l\'inaction (erreurs, temps perdu, risques) dépasse le coût de la transformation',
  1384. 'Commencez par un MVP centré sur vos 2-3 pain points principaux — pas besoin de tout refaire d\'un coup',
  1385. 'Évaluez selon votre volume : no-code (Airtable, Notion) pour de petits volumes, développement sur mesure au-delà',
  1386. ],
  1387. };
  1388. }
  1389. }
  1390. function renderExcelTool() {
  1391. const sig = state.excelSignals;
  1392. const qual = state.excelQual;
  1393. const answeredCount = EXCEL_QUESTIONS.filter(q => sig[q.id] !== undefined).length;
  1394. const remaining = EXCEL_QUESTIONS.length - answeredCount;
  1395. const canSubmit = answeredCount >= EXCEL_QUESTIONS.length;
  1396. const makeSignalRow = (q) => {
  1397. const isOui = sig[q.id] === true;
  1398. const isNon = sig[q.id] === false;
  1399. return h('div', { class: 'signal-row' }, [
  1400. h('span', { class: 'signal-row__lbl' }, [q.label]),
  1401. h('div', { class: 'signal-row__btns' }, [
  1402. h('button', {
  1403. type: 'button',
  1404. class: `signal-btn signal-btn--oui${isOui ? ' active' : ''}`,
  1405. onClick: () => { state.excelSignals[q.id] = isOui ? undefined : true; render(); },
  1406. }, ['Oui']),
  1407. h('button', {
  1408. type: 'button',
  1409. class: `signal-btn signal-btn--non${isNon ? ' active' : ''}`,
  1410. onClick: () => { state.excelSignals[q.id] = isNon ? undefined : false; render(); },
  1411. }, ['Non']),
  1412. ]),
  1413. ]);
  1414. };
  1415. const makeQualChips = (options, field) =>
  1416. h('div', { class: 'qual-chips' }, options.map(opt =>
  1417. h('button', {
  1418. type: 'button',
  1419. class: `qual-chip${qual[field] === opt.id ? ' active' : ''}`,
  1420. onClick: () => { state.excelQual[field] = qual[field] === opt.id ? null : opt.id; render(); },
  1421. }, [opt.label])
  1422. ));
  1423. const makeQualChipsMulti = (options, field) =>
  1424. h('div', { class: 'qual-chips' }, options.map(opt => {
  1425. const arr = Array.isArray(qual[field]) ? qual[field] : [];
  1426. const isActive = arr.includes(opt.id);
  1427. return h('button', {
  1428. type: 'button',
  1429. class: `qual-chip${isActive ? ' active' : ''}`,
  1430. onClick: () => {
  1431. const next = isActive ? arr.filter(x => x !== opt.id) : [...arr, opt.id];
  1432. state.excelQual[field] = next;
  1433. render();
  1434. },
  1435. }, [opt.label]);
  1436. }));
  1437. const group1 = EXCEL_QUESTIONS.slice(0, 8);
  1438. const group2 = EXCEL_QUESTIONS.slice(8);
  1439. const step = state.excelStep || 1;
  1440. const group1Answered = group1.every(q => sig[q.id] !== undefined);
  1441. const group2Answered = group2.every(q => sig[q.id] !== undefined);
  1442. if (step === 1) {
  1443. return h('div', { class: 'grid' }, [
  1444. h('div', { class: 'card' }, [
  1445. h('div', { style: 'margin-bottom:14px' }, [h('span', { class: 'tag tag--excel' }, ['Excel → Application — Étape 1'])]),
  1446. h('h1', { class: 'h1' }, ['Dois-je transformer mon fichier Excel en application ?']),
  1447. h('p', { class: 'lead' }, ['Contexte et premiers signaux.']),
  1448. h('div', { class: 'section-label', style: 'margin-top:18px' }, ['Contexte de votre usage (optionnel)']),
  1449. h('div', { class: 'qual-row' }, [
  1450. h('div', { class: 'qual-row__lbl' }, ['Outil utilisé']),
  1451. makeQualChips(EXCEL_QUAL_OUTIL, 'outil'),
  1452. ]),
  1453. h('div', { class: 'qual-row' }, [
  1454. h('div', { class: 'qual-row__lbl' }, ['Nombre de personnes impliquées']),
  1455. makeQualChips(EXCEL_QUAL_PERSONNES, 'personnes'),
  1456. ]),
  1457. h('div', { class: 'qual-row' }, [
  1458. h('div', { class: 'qual-row__lbl' }, ['Conséquences principales ressenties (choix multiple)']),
  1459. makeQualChipsMulti(EXCEL_QUAL_CONSEQUENCE, 'consequence'),
  1460. ]),
  1461. h('div', { class: 'section-label', style: 'margin-top:20px' }, ['Signaux — Usage et organisation']),
  1462. h('div', { class: 'signal-list' }, group1.map(makeSignalRow)),
  1463. h('div', { class: 'btnrow', style: 'margin-top:22px' }, [
  1464. h('button', { class: 'btn btn--outline', onClick: () => setView('landing') }, ['← Retour']),
  1465. h('button', {
  1466. class: 'btn btn--primary',
  1467. disabled: group1Answered ? null : 'disabled',
  1468. onClick: () => { if (group1Answered) { state.excelStep = 2; render(); } },
  1469. }, [group1Answered ? 'Continuer — Étape 2 →' : `Répondre aux 8 signaux ci-dessus pour continuer`]),
  1470. ]),
  1471. h('p', { class: 'hint', style: 'margin-top:8px' }, ['Étape 1 sur 2.']),
  1472. ]),
  1473. ]);
  1474. }
  1475. return h('div', { class: 'grid' }, [
  1476. h('div', { class: 'card' }, [
  1477. h('div', { style: 'margin-bottom:14px' }, [h('span', { class: 'tag tag--excel' }, ['Excel → Application — Étape 2'])]),
  1478. h('h1', { class: 'h1' }, ['Signaux — Process et viabilité']),
  1479. h('p', { class: 'lead' }, ['Ces 7 derniers signaux permettent d\'affiner le verdict.']),
  1480. h('div', { class: 'signal-list', style: 'margin-top:18px' }, group2.map(makeSignalRow)),
  1481. h('div', { class: 'btnrow', style: 'margin-top:22px' }, [
  1482. h('button', { class: 'btn btn--outline', onClick: () => { state.excelStep = 1; render(); } }, ['← Étape précédente']),
  1483. h('button', {
  1484. class: 'btn btn--primary',
  1485. disabled: canSubmit ? null : 'disabled',
  1486. onClick: () => { if (canSubmit) { state.excelResult = computeExcelVerdict(state.excelSignals, state.excelQual); state.excelStep = 1; setView('excel-results'); } },
  1487. }, [canSubmit ? 'Voir mon verdict →' : `Répondre à encore ${remaining} signal${remaining > 1 ? 's' : ''}`]),
  1488. ]),
  1489. h('p', { class: 'hint', style: 'margin-top:8px' }, ['Étape 2 sur 2. Répondez aux 7 signaux pour déverrouiller le verdict.']),
  1490. ]),
  1491. ]);
  1492. }
  1493. function renderExcelResults() {
  1494. const r = state.excelResult;
  1495. if (!r) { setView('excel'); return h('div', {}); }
  1496. const qual = r.qual || {};
  1497. const outilLabels = { excel_local: 'Excel local / réseau', excel_partage: 'Excel partagé (SharePoint / OneDrive)', google_sheet: 'Google Sheet', les_deux: 'Excel et Google Sheet' };
  1498. const personnesLabels = { '1': '1 seule personne', '2_3': '2 à 3 personnes', '4_10': '4 à 10 personnes', 'plus10': 'Plus de 10 personnes' };
  1499. const consequenceLabels = { temps: 'Perte de temps', erreurs: 'Risque d\'erreur', visibilite: 'Manque de visibilité', conformite: 'Conformité / audit', client: 'Impact client / fournisseur' };
  1500. const consequenceArr = Array.isArray(qual.consequence) ? qual.consequence : (qual.consequence ? [qual.consequence] : []);
  1501. const consequenceText = consequenceArr.map(id => consequenceLabels[id] || id).join(', ');
  1502. const hasQual = qual.outil || qual.personnes || consequenceArr.length > 0;
  1503. const qualCard = hasQual ? h('div', { class: 'card' }, [
  1504. h('div', { class: 'h2' }, ['Contexte de votre usage']),
  1505. h('div', { class: 'qual-summary' }, [
  1506. qual.outil ? h('div', { class: 'qual-summary__row' }, [h('span', { class: 'qual-summary__lbl' }, ['Outil : ']), outilLabels[qual.outil] || qual.outil]) : null,
  1507. qual.personnes ? h('div', { class: 'qual-summary__row' }, [h('span', { class: 'qual-summary__lbl' }, ['Personnes impliquées : ']), personnesLabels[qual.personnes] || qual.personnes]) : null,
  1508. consequenceText ? h('div', { class: 'qual-summary__row' }, [h('span', { class: 'qual-summary__lbl' }, ['Conséquences principales : ']), consequenceText]) : null,
  1509. ].filter(Boolean)),
  1510. ]) : null;
  1511. return h('div', { class: 'grid' }, [
  1512. h('div', { class: 'card' }, [
  1513. h('div', { style: 'margin-bottom:14px' }, [h('span', { class: 'tag tag--excel' }, ['Excel → Application - Verdict'])]),
  1514. h('h1', { class: 'h1' }, ['Votre verdict']),
  1515. h('div', { class: 'excel-verdict', style: `border-color:${r.color}` }, [
  1516. h('div', { class: 'excel-verdict__icon', style: `background:${r.color}` }, [r.icon]),
  1517. h('div', { class: 'excel-verdict__body' }, [
  1518. h('div', { class: 'excel-verdict__score' }, [`${r.score} / ${r.total} signaux d'alerte`]),
  1519. h('div', { class: 'excel-verdict__title', style: `color:${r.color}` }, [r.title]),
  1520. h('div', { class: 'excel-verdict__summary' }, [r.summary]),
  1521. ]),
  1522. ]),
  1523. ]),
  1524. qualCard,
  1525. h('div', { class: 'card' }, [
  1526. h('div', { class: 'h2' }, ['Nos recommandations']),
  1527. h('div', { class: 'excel-actions' }, r.actions.map((action, i) =>
  1528. h('div', { class: 'excel-action' }, [
  1529. h('div', { class: 'excel-action__num' }, [String(i + 1)]),
  1530. h('div', { class: 'excel-action__text' }, [action]),
  1531. ])
  1532. )),
  1533. ]),
  1534. h('div', { class: 'card' }, [
  1535. h('div', { class: 'h2' }, ['Et maintenant ?']),
  1536. h('p', { class: 'lead', style: 'margin-bottom:16px' }, [
  1537. r.level === 'ok'
  1538. ? 'Votre Excel est encore sous contrôle. Si vos besoins évoluent, revenez faire ce diagnostic.'
  1539. : 'Un entretien de 30 minutes permet d\'évaluer ensemble la meilleure solution pour votre situation et de chiffrer l\'effort de transformation.',
  1540. ]),
  1541. h('div', { class: 'btnrow' }, [
  1542. BOOKING_URL ? h('a', {
  1543. class: 'btn btn--primary', href: BOOKING_URL, target: '_blank', rel: 'noreferrer',
  1544. }, ['Évaluer la solution - Entretien 30 min offert']) : null,
  1545. h('button', { class: 'btn btn--outline', onClick: () => setView('roi') }, ['Calculer le ROI →']),
  1546. ]),
  1547. h('div', { class: 'btnrow', style: 'margin-top:6px' }, [
  1548. h('button', { class: 'btn btn--outline', style: 'font-size:13px', onClick: () => { state.excelStep = 1; setView('excel'); } }, ['← Modifier mes réponses']),
  1549. h('button', { class: 'btn btn--outline', style: 'font-size:13px', onClick: () => setView('landing') }, ['Accueil']),
  1550. ]),
  1551. ]),
  1552. ].filter(Boolean));
  1553. }
  1554. /* ── RENDER ── */
  1555. function render() {
  1556. if (!appEl) return;
  1557. appEl.innerHTML = '';
  1558. const views = {
  1559. landing: renderLanding,
  1560. select: renderSelect,
  1561. intro: renderIntro,
  1562. quiz: renderQuiz,
  1563. computing: renderComputing,
  1564. optional: renderOptional,
  1565. results: renderResults,
  1566. 'roi': renderRoi,
  1567. 'roi-results': renderRoiResults,
  1568. 'qwf': renderQwf,
  1569. 'qwf-results': renderQwfResults,
  1570. 'excel': renderExcelTool,
  1571. 'excel-results': renderExcelResults,
  1572. };
  1573. appEl.appendChild((views[state.view] || renderLanding)());
  1574. updateNavbar();
  1575. }
  1576. /* ── HEADER update ── */
  1577. function initHeader() {
  1578. const header = document.querySelector('.header');
  1579. if (!header) return;
  1580. header.innerHTML = '';
  1581. const brand = document.createElement('div');
  1582. brand.innerHTML =
  1583. '<div class="brand__logo">Contrôle technique process</div>' +
  1584. '<div class="brand__sub">Diagnostic self-serve ; Livinweb</div>';
  1585. const badge = document.createElement('span');
  1586. badge.className = 'brand__badge';
  1587. badge.textContent = 'V1';
  1588. header.appendChild(brand);
  1589. header.appendChild(badge);
  1590. }
  1591. initHeader();
  1592. render();