1import{c as S,I as k,J as C,a as $,r,s as L,j as e}from"./main-DF0DO6_-.js";import{u as P}from"./useServerFn-Cp7Hhp09.js";import{L as V}from"./loader-circle-g4oV6JCL.js";import{C as D}from"./chevron-down-rTAEz7ZP.js";import{C as E}from"./chevron-right-DOsBaZgG.js";import{B as A}from"./building-2-DI3cLhBk.js";const z=[["path",{d:"M21.54 15H17a2 2 0 0 0-2 2v4.54",key:"1djwo0"}],["path",{d:"M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",key:"1tzkfa"}],["path",{d:"M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05",key:"14pb5j"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],I=S("earth",z),M=k({method:"POST"}).handler(C("5c8234a0ea7fc41e82c90cba6a84044710c64cb65e888c59b6aa4eee14c877d3"));function h(a){if(a<60)return`${a}s`;const x=Math.floor(a/60),n=a%60;return`${x}m${n?` ${n}s`:""}`}function y(a){return new Date(a).toLocaleString("fr-FR",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}function R(a){return a>=60?"bg-green-100 text-green-800":a>=30?"bg-amber-100 text-amber-800":"bg-gray-100 text-gray-600"}function J(){const{user:a}=$(),x=P(M),[n,j]=r.useState(null),[i,u]=r.useState(null),[f,g]=r.useState(!0),[o,b]=r.useState(30),[c,N]=r.useState(!0),[m,v]=r.useState(""),[w,_]=r.useState(null);r.useEffect(()=>{a&&L.from("user_roles").select("role").eq("user_id",a.id).eq("role","admin").maybeSingle().then(({data:s})=>j(!!s))},[a]),r.useEffect(()=>{n&&(g(!0),x({data:{days:o,onlyIdentified:c}}).then(s=>u(s)).catch(()=>u(null)).finally(()=>g(!1)))},[n,o,c]);const p=r.useMemo(()=>{const s=i?.leads??[],l=m.trim().toLowerCase();return l?s.filter(t=>[t.company_name,t.isp,t.domain,t.city,t.country,t.first_landing,t.utm_campaign].filter(Boolean).some(d=>String(d).toLowerCase().includes(l))):s},[i,m]);return n===null?e.jsx("div",{className:"p-12 text-[14px] text-[#9a9a9a]",children:"Chargementâ¦"}):n?e.jsxs("div",{className:"mx-auto max-w-[1400px] p-8",children:[e.jsx("h1",{className:"mb-1 text-2xl font-semibold",children:"Visiteurs du site"}),e.jsx("p",{className:"mb-6 max-w-3xl text-sm text-gray-500",children:"Entreprises identifiées à partir de l'adresse réseau de leurs visites sur le site public : pages vues, ordre de visite, temps passé et provenance. Les particuliers et les connexions anonymes (VPN, hébergeurs) ne sont pas identifiables â ils apparaissent seulement dans le total « non identifiés »."}),e.jsxs("div",{className:"mb-5 flex flex-wrap items-center gap-2",children:[[7,30,90].map(s=>e.jsxs("button",{type:"button",onClick:()=>b(s),className:`rounded px-3 py-1.5 text-sm ${o===s?"bg-black text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:[s," jours"]},s)),e.jsx("button",{type:"button",onClick:()=>N(s=>!s),className:`rounded px-3 py-1.5 text-sm ${c?"bg-black text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:c?"Entreprises identifiées":"Toutes les visites"}),e.jsx("input",{value:m,onChange:s=>v(s.target.value),placeholder:"Rechercher une société, une ville, une pageâ¦",className:"ml-auto w-full max-w-xs rounded border border-gray-300 px-3 py-1.5 text-sm"})]}),i?e.jsx("div",{className:"mb-6 grid gap-3 sm:grid-cols-4",children:[{label:"Entreprises identifiées",value:i.totals.identified},{label:"Visiteurs non identifiés",value:i.totals.anonymous},{label:"Pages vues (sélection)",value:i.totals.pageViews},{label:"Sociétés affichées",value:p.length}].map(s=>e.jsxs("div",{className:"rounded-lg border bg-white p-4",children:[e.jsx("div",{className:"text-2xl font-semibold",children:s.value}),e.jsx("div",{className:"text-xs text-gray-500",children:s.label})]},s.label))}):null,f?e.jsxs("div",{className:"flex items-center gap-2 py-8 text-sm text-gray-500",children:[e.jsx(V,{className:"size-4 animate-spin"})," Chargementâ¦"]}):p.length===0?e.jsx("div",{className:"rounded-lg border bg-white py-8 text-center text-sm text-gray-500",children:"Aucune visite identifiée sur cette période."}):e.jsx("div",{className:"overflow-hidden rounded-lg border bg-white",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 text-left text-xs uppercase text-gray-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"Société"}),e.jsx("th",{className:"px-3 py-2",children:"Localisation"}),e.jsx("th",{className:"px-3 py-2",children:"Pages"}),e.jsx("th",{className:"px-3 py-2",children:"Temps"}),e.jsx("th",{className:"px-3 py-2",children:"Arrivée / provenance"}),e.jsx("th",{className:"px-3 py-2",children:"Dernière visite"}),e.jsx("th",{className:"px-3 py-2",children:"Intérêt"})]})}),e.jsx("tbody",{children:p.map(s=>{const l=w===s.id;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"cursor-pointer border-t align-top hover:bg-gray-50",onClick:()=>_(l?null:s.id),children:[e.jsxs("td",{className:"px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 font-semibold text-black",children:[l?e.jsx(D,{className:"size-4 shrink-0 text-gray-400"}):e.jsx(E,{className:"size-4 shrink-0 text-gray-400"}),s.company_name?e.jsx(A,{className:"size-4 text-gray-400"}):e.jsx(I,{className:"size-4 text-gray-400"}),s.company_name??"Visiteur non identifié"]}),s.domain?e.jsx("a",{href:`https://${s.domain}`,target:"_blank",rel:"noreferrer",onClick:t=>t.stopPropagation(),className:"ml-10 text-xs text-blue-600 hover:underline",children:s.domain}):s.isp?e.jsx("div",{className:"ml-10 text-xs text-gray-400",children:s.isp}):null]}),e.jsxs("td",{className:"px-3 py-2 text-xs text-gray-600",children:[[s.city,s.region].filter(
1Boolean).join(", ")||"â",e.jsx("div",{className:"text-gray-400",children:s.country??""})]}),e.jsx("td",{className:"px-3 py-2 font-medium",children:s.page_view_count}),e.jsx("td",{className:"px-3 py-2 text-xs text-gray-700",children:h(s.total_duration_seconds)}),e.jsxs("td",{className:"max-w-[260px] px-3 py-2 text-xs text-gray-600",children:[e.jsx("div",{className:"truncate",children:s.first_landing??"â"}),e.jsx("div",{className:"truncate text-gray-400",children:s.utm_campaign?`campagne : ${s.utm_campaign}`:s.first_referrer?s.first_referrer.replace(/^https?:\/\//,"").slice(0,60):"accès direct"})]}),e.jsx("td",{className:"px-3 py-2 text-xs text-gray-500",children:y(s.last_seen)}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:`rounded px-2 py-0.5 text-xs font-semibold ${R(s.score)}`,children:s.score})})]},s.id),l?e.jsx("tr",{className:"border-t bg-gray-50/60",children:e.jsxs("td",{colSpan:7,className:"px-6 py-4",children:[e.jsxs("div",{className:"mb-2 text-xs font-semibold uppercase text-gray-500",children:["Parcours (",s.views.length," page",s.views.length>1?"s":"",")"]}),s.views.length===0?e.jsx("div",{className:"text-xs text-gray-500",children:"Aucun détail de page enregistré."}):e.jsx("ol",{className:"space-y-1",children:s.views.map((t,d)=>e.jsxs("li",{className:"flex flex-wrap items-baseline gap-2 text-xs",children:[e.jsxs("span",{className:"w-5 shrink-0 text-gray-400",children:[d+1,"."]}),e.jsx("span",{className:"font-medium text-black",children:t.path}),t.title?e.jsxs("span",{className:"text-gray-500",children:["â ",t.title]}):null,e.jsxs("span",{className:"text-gray-400",children:[y(t.entered_at)," · ",h(t.duration_seconds)]})]},`${t.path}-${t.entered_at}-${d}`))})]})},`${s.id}-detail`):null]})})})]})}),i&&i.totals.topPages.length?e.jsxs("div",{className:"mt-8",children:[e.jsx("h2",{className:"mb-3 text-lg font-semibold",children:"Pages les plus vues"}),e.jsx("div",{className:"overflow-hidden rounded-lg border bg-white",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 text-left text-xs uppercase text-gray-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"Page"}),e.jsx("th",{className:"px-3 py-2",children:"Vues"}),e.jsx("th",{className:"px-3 py-2",children:"Temps moyen"})]})}),e.jsx("tbody",{children:i.totals.topPages.map(s=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"px-3 py-2",children:s.path}),e.jsx("td",{className:"px-3 py-2",children:s.views}),e.jsx("td",{className:"px-3 py-2 text-gray-600",children:h(s.avgDuration)})]},s.path))})]})})]}):null]}):e.jsx("div",{className:"p-12 text-[14px] text-[#9a9a9a]",children:"Accès réservé aux administrateurs."})}export{J as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.