@_solaris/messenger-widget 0.3.8 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,24 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),Fe=["connected","message","message_stream","conversation_updated","config_updated","action_status"],te="/client",ze=5*60*1e3,Pe=10*60*1e3,je=5*60*1e3;function ie(n){const t={baseUrl:Ue(n.baseUrl||""),widgetId:n.widgetId||"",userId:n.userId||"",userHash:n.userHash||"",listeners:new Map,eventSource:null,connection:"idle",visibilityHandler:null,started:!1,panelOpen:!1,pollTimer:null,burstTimer:null,hiddenGraceTimer:null,lastActivityAt:null};if(!t.baseUrl||!t.widgetId||!t.userId||!t.userHash)throw new Error("[transport] baseUrl, widgetId, userId, userHash are all required");function r(d,m){return t.listeners.has(d)||t.listeners.set(d,new Set),t.listeners.get(d).add(m),()=>t.listeners.get(d).delete(m)}function a(d,m){const p=t.listeners.get(d);p&&p.forEach(_=>{try{_(m)}catch(E){console.error("[transport] listener",d,E)}})}function s(d){t.connection!==d&&(t.connection=d,a("connection",d))}function o(){return{"X-User-Id":t.userId,"X-User-Hash":t.userHash,"X-Widget-Id":t.widgetId}}async function i(d,m,p){const _=await fetch(`${t.baseUrl}${te}${m}`,{method:d,headers:{"Content-Type":"application/json",...o()},body:p!==void 0?JSON.stringify(p):void 0});if(!_.ok){const E=await l(_),B=new Error(`HTTP ${_.status} ${d} ${m} :: ${(E==null?void 0:E.error)||_.statusText}`);throw B.status=_.status,B.body=E,B}return _.status===204?null:_.json()}async function l(d){try{return await d.json()}catch{return null}}async function f(){const[d,m]=await Promise.all([fetch(`${t.baseUrl}/widgets/${encodeURIComponent(t.widgetId)}/config`).then(async p=>{if(!p.ok){const _=await l(p);throw new Error(`HTTP ${p.status} GET /widgets/:id/config :: ${(_==null?void 0:_.error)||p.statusText}`)}return p.json()}),i("GET","/customers/me")]);return{config:d,customer:(m==null?void 0:m.customer)??null}}async function v(){const d=await i("GET","/customers/me");return(d==null?void 0:d.customer)??null}async function y(d){const m=await i("PATCH","/customers/me",d);return(m==null?void 0:m.customer)??null}async function b(){const d=await i("GET","/conversations");return(d==null?void 0:d.conversations)??[]}async function S(d={}){return(await i("POST","/conversations",d)).conversation}async function k(d){return(await i("GET",`/conversations/${encodeURIComponent(d)}`)).conversation}async function A(d,m){return(await i("PATCH",`/conversations/${encodeURIComponent(d)}`,m)).conversation}async function w(d,m={}){const p=new URLSearchParams;m.before&&p.set("before",m.before),m.since&&p.set("since",m.since),m.limit&&p.set("limit",String(m.limit));const _=p.toString()?`?${p.toString()}`:"";return i("GET",`/conversations/${encodeURIComponent(d)}/messages${_}`)}async function M(d,m){D();const p={client_msg_id:m.client_msg_id,type:"content",text_md:m.text_md,author:{id:t.userId,type:"user"},created_at:m.created_at||new Date().toISOString()};return Array.isArray(m.attachments)&&m.attachments.length&&(p.payload={type:"content",attachments:m.attachments}),m.metadata&&typeof m.metadata=="object"&&(p.metadata=m.metadata),i("POST",`/conversations/${encodeURIComponent(d)}/messages`,p)}async function x(d,m,p){return D(),i("POST",`/messages/${encodeURIComponent(d)}/callbacks/${encodeURIComponent(m)}`,p?{inputs:p}:{})}async function V(d){const m=d.name||"attachment",p=d.type||"application/octet-stream",_=d.size||0,E=await i("POST","/attachments",{mime_type:p,size_bytes:_,name:m}),B=await fetch(E.upload_url,{method:"PUT",headers:{"Content-Type":p},body:d});if(!B.ok)throw new Error(`HTTP ${B.status} PUT signed upload`);return{type:He(p),path:E.path,mime_type:p,size_bytes:_}}async function O(d){return i("GET",`/attachments/sign?path=${encodeURIComponent(d)}`)}function $(){const d=new URLSearchParams({userId:t.userId,userHash:t.userHash,widgetId:t.widgetId}).toString();return`${t.baseUrl}${te}/stream?${d}`}function I(){if(!t.eventSource&&!(typeof document<"u"&&document.hidden))try{const d=new EventSource($());for(const m of Fe)d.addEventListener(m,p=>F(m,p.data));d.addEventListener("error",()=>a("error",new Error("SSE error"))),t.eventSource=d,s("open")}catch(d){console.error("[transport] SSE open failed",d),a("error",d)}}function F(d,m){try{const p=JSON.parse(m),_=p&&typeof p=="object"&&"data"in p?p.data:p;a(d,_)}catch(p){console.error("[transport] bad SSE payload",d,p)}}function L(){t.eventSource&&(t.eventSource.close(),t.eventSource=null),t.connection!=="paused"&&s("idle")}function D(){clearTimeout(t.burstTimer),I(),t.panelOpen||(t.burstTimer=setTimeout(()=>{t.panelOpen||L()},Pe))}function R(d){t.panelOpen=!!d,t.panelOpen?(clearTimeout(t.burstTimer),I()):D()}async function J(){try{const d=await b(),m=d.reduce((_,E)=>{const B=E==null?void 0:E.last_message_at;return B&&(!_||B>_)?B:_},null);m&&(!t.lastActivityAt||m>t.lastActivityAt)&&(t.lastActivityAt=m,a("activity",{conversations:d,latestAt:m}),D())}catch(d){console.error("[transport] poll failed",d)}}function U(){c(),!(typeof document<"u"&&document.hidden)&&(t.pollTimer=setInterval(J,ze))}function c(){t.pollTimer&&(clearInterval(t.pollTimer),t.pollTimer=null)}function u(){if(document.hidden)clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=setTimeout(()=>{t.hiddenGraceTimer=null,document.hidden&&(c(),L(),s("paused"))},je);else{if(t.hiddenGraceTimer){clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=null;return}s("idle"),U(),t.panelOpen&&I()}}async function h(){if(t.started)return t.lastBootstrap;t.started=!0;const d=await f();t.lastBootstrap=d;try{const m=await b();t.lastActivityAt=m.reduce((p,_)=>{const E=_==null?void 0:_.last_message_at;return E&&(!p||E>p)?E:p},null)}catch(m){console.error("[transport] initial /conversations failed",m)}return typeof document<"u"&&(t.visibilityHandler=u,document.addEventListener("visibilitychange",t.visibilityHandler)),U(),d}function g(){c(),clearTimeout(t.burstTimer),clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=null,L(),t.visibilityHandler&&(document.removeEventListener("visibilitychange",t.visibilityHandler),t.visibilityHandler=null),t.started=!1}return{on:r,start:h,stop:g,setPanelOpen:R,bootstrap:f,getCustomer:v,patchCustomer:y,listConversations:b,createConversation:S,getConversation:k,patchConversation:A,listMessages:w,postMessage:M,postCallback:x,uploadAttachment:V,signAttachment:O,get connection(){return t.connection}}}function Ue(n){return n.endsWith("/")?n.slice(0,-1):n}function He(n){return n.startsWith("image/")?"image":n.startsWith("video/")?"video":n.startsWith("audio/")?"audio":"file"}function X(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const n=new Uint8Array(16);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(n);else for(let r=0;r<16;r++)n[r]=Math.floor(Math.random()*256);n[6]=n[6]&15|64,n[8]=n[8]&63|128;const t=[...n].map(r=>r.toString(16).padStart(2,"0"));return t.slice(0,4).join("")+"-"+t.slice(4,6).join("")+"-"+t.slice(6,8).join("")+"-"+t.slice(8,10).join("")+"-"+t.slice(10,16).join("")}function le(n){const t=e.reactive({ready:!1,error:null,config:null,customer:null,conversations:[],messagesByConv:{},paginationByConv:{},streamingByMsgId:{},awaitingCallback:{},runningActionsByConv:{},connection:"idle"}),r=[];r.push(n.on("connection",c=>{t.connection=c})),r.push(n.on("message",c=>{const u=c==null?void 0:c.conversation_id,h=c==null?void 0:c.message;!u||!(h!=null&&h.id)||(I(u,h),h.client_msg_id&&delete t.streamingByMsgId[h.client_msg_id],D(u,h.created_at))})),r.push(n.on("message_stream",c=>{const u=c==null?void 0:c.message_id,h=c==null?void 0:c.token;!u||typeof h!="string"||(t.streamingByMsgId[u]=(t.streamingByMsgId[u]||"")+h)})),r.push(n.on("conversation_updated",c=>{const u=c==null?void 0:c.conversation_id,h=c==null?void 0:c.changes;if(!u||!h)return;const g=t.conversations.findIndex(d=>d.id===u);g!==-1&&(t.conversations[g]={...t.conversations[g],...h})})),r.push(n.on("config_updated",c=>{c!=null&&c.config&&(t.config=c.config)})),r.push(n.on("action_status",c=>{const u=c==null?void 0:c.conversation_id,h=c==null?void 0:c.action_id,g=c==null?void 0:c.action_name;if(!u||!h)return;const d=t.runningActionsByConv[u]||{};c.state==="running"?(d[h]=g||h,t.runningActionsByConv[u]={...d}):c.state==="done"&&(delete d[h],t.runningActionsByConv[u]={...d})})),r.push(n.on("activity",c=>{Array.isArray(c==null?void 0:c.conversations)&&(t.conversations=c.conversations)}));async function a(){try{const c=new Promise((h,g)=>setTimeout(()=>g(new Error("bootstrap timeout (15s) — check baseUrl, CORS, and network")),15e3)),u=await Promise.race([n.start(),c]);t.config=u.config,t.customer=u.customer,t.conversations=await Promise.race([n.listConversations(),c]),t.ready=!0}catch(c){console.error("[store] start failed",c),t.error=(c==null?void 0:c.message)||String(c)}}function s(){for(const c of r)try{c()}catch{}n.stop()}async function o(c){const u=J(c);if(!u)return t.customer;try{const h=await n.patchCustomer(u);h&&(t.customer=h)}catch(h){console.error("[store] applyCustomer failed",h)}return t.customer}async function i(c={}){const u=await n.createConversation(c),h=t.conversations.findIndex(g=>g.id===u.id);return h===-1?t.conversations=[u,...t.conversations]:t.conversations[h]=u,u}const l=50;async function f(c){const u=t.paginationByConv[c];if(!(u!=null&&u.loaded||u!=null&&u.loading)){y(c,{nextCursor:null,loading:!0,loaded:!1});try{const h=await n.listMessages(c,{limit:l}),g=(h==null?void 0:h.messages)??[],d=t.messagesByConv[c]||[],m=new Set;for(const _ of g)(_==null?void 0:_.id)!=null&&m.add(`id:${String(_.id)}`),_!=null&&_.client_msg_id&&m.add(`c:${_.client_msg_id}`);const p=d.filter(_=>!((_==null?void 0:_.id)!=null&&m.has(`id:${String(_.id)}`)||_!=null&&_.client_msg_id&&m.has(`c:${_.client_msg_id}`)));t.messagesByConv[c]=[...g,...p].sort(R),y(c,{nextCursor:(h==null?void 0:h.next_cursor)??null,loading:!1,loaded:!0})}catch(h){console.error("[store] openConversation failed",h),y(c,{nextCursor:null,loading:!1,loaded:!1})}}}async function v(c){var d;const u=t.paginationByConv[c];if(!u||u.loading||!u.nextCursor)return;const g=(d=(t.messagesByConv[c]||[]).find(m=>m==null?void 0:m.created_at))==null?void 0:d.created_at;if(g){y(c,{...u,loading:!0});try{const m=await n.listMessages(c,{before:g,limit:l}),p=(m==null?void 0:m.messages)??[],_=t.messagesByConv[c]||[],E=new Set;for(const C of _)(C==null?void 0:C.id)!=null&&E.add(`id:${String(C.id)}`),C!=null&&C.client_msg_id&&E.add(`c:${C.client_msg_id}`);const B=p.filter(C=>!((C==null?void 0:C.id)!=null&&E.has(`id:${String(C.id)}`)||C!=null&&C.client_msg_id&&E.has(`c:${C.client_msg_id}`)));t.messagesByConv[c]=[...B,..._],y(c,{nextCursor:(m==null?void 0:m.next_cursor)??null,loading:!1,loaded:!0})}catch(m){console.error("[store] loadMore failed",m),y(c,{...u,loading:!1})}}}function y(c,u){t.paginationByConv={...t.paginationByConv,[c]:u}}async function b(c,u){const h=await n.patchConversation(c,u),g=t.conversations.findIndex(d=>d.id===c);g!==-1&&(t.conversations[g]=h)}async function S(c,u,{attachments:h,metadata:g}={}){var B;const d=(u||"").trim(),m=Array.isArray(h)&&h.length>0;if(!c||!d&&!m)return;const p=X(),_=U(c),E={id:p,client_msg_id:p,conversation_id:c,type:"content",text_md:d,author:{type:"user",id:((B=t.customer)==null?void 0:B.external_id)||null},created_at:_,_pending:!0,...m?{payload:{type:"content",attachments:h}}:{},...g&&typeof g=="object"?{metadata:g}:{}};I(c,E);try{await n.postMessage(c,{client_msg_id:p,text_md:d,created_at:_,...m?{attachments:h}:{},...g&&typeof g=="object"?{metadata:g}:{}})}catch(C){console.error("[store] send failed",C),L(c,p,{_failed:!0,_pending:!1})}}async function k(c,u,h){c!=null&&(t.awaitingCallback[c]=!0);try{await n.postCallback(c,u,h)}catch(g){console.error("[store] callback failed",g),c!=null&&delete t.awaitingCallback[c]}}const A=new Map;async function w(c){if(!c)return null;const u=A.get(c);if(u!=null&&u.url){const h=u.expires_at?Date.parse(u.expires_at):0;if(!h||h-Date.now()>6e4)return u.url}try{const h=await n.signAttachment(c);if(h!=null&&h.signed_url)return A.set(c,{url:h.signed_url,expires_at:h.expires_at}),h.signed_url}catch(h){console.error("[store] sign attachment failed",h)}return null}async function M(c,{rating:u,comment:h}={}){const g=t.conversations.find(p=>p.id===c),m={...(g==null?void 0:g.metadata)||{},feedback:{rating:u,comment:h||null,submitted_at:new Date().toISOString()}};await b(c,{metadata:m})}function x(c){var h,g;const u=t.messagesByConv[c]||[];for(let d=u.length-1;d>=0;d--){const m=u[d];if((m==null?void 0:m.type)==="action"&&((h=m==null?void 0:m.payload)==null?void 0:h.type)==="action"&&((g=m==null?void 0:m.payload)==null?void 0:g.state)==="pending"&&Array.isArray(m==null?void 0:m.callbacks)&&m.callbacks.length>0&&!t.awaitingCallback[m.id])return m}return null}function V(c){var h,g,d;const u=t.messagesByConv[c]||[];for(let m=u.length-1;m>=0;m--){const p=u[m];if(((h=p==null?void 0:p.author)==null?void 0:h.type)==="user"||(p==null?void 0:p.type)==="action"&&((g=p==null?void 0:p.payload)==null?void 0:g.state)==="pending")return null;const _=(d=p==null?void 0:p.metadata)==null?void 0:d.form;if(_&&Array.isArray(_.fields)&&_.fields.length>0)return{message:p,form:_}}return null}function O(c){const u=t.runningActionsByConv[c];if(!u)return null;const h=Object.keys(u);if(h.length===0)return null;const g=h[0];return{id:g,payload:{name:u[g]}}}function $(c){var h,g,d,m;const u=t.messagesByConv[c]||[];for(let p=u.length-1;p>=0;p--){const _=u[p];if(((h=_==null?void 0:_.author)==null?void 0:h.type)==="user")return[];if((_==null?void 0:_.type)==="action"&&((g=_==null?void 0:_.payload)==null?void 0:g.state)==="pending")return[];if(((d=_==null?void 0:_.author)==null?void 0:d.type)!=="agent_ia")continue;const E=(m=_==null?void 0:_.metadata)==null?void 0:m.suggested_replies;return Array.isArray(E)&&E.length?E.map(B=>{if(typeof B=="string"){const C=B.trim();return C?{label:C,kind:null}:null}if(B&&typeof B=="object"&&typeof B.label=="string"){const C=B.label.trim();if(!C)return null;const Re=B.kind==="cta"||B.kind==="choice"||B.kind==="followup"?B.kind:null;return{label:C,kind:Re}}return null}).filter(Boolean).slice(0,4):[]}return[]}function I(c,u){var m;const h=t.messagesByConv[c]||[];let g=-1;u!=null&&u.client_msg_id&&(g=h.findIndex(p=>(p==null?void 0:p.client_msg_id)&&p.client_msg_id===u.client_msg_id)),g===-1&&(u==null?void 0:u.id)!==void 0&&(u==null?void 0:u.id)!==null&&(g=h.findIndex(p=>F(p==null?void 0:p.id,u.id)));let d;g===-1?d=[...h,u].sort(R):(d=h.slice(),d[g]={...h[g],...u,_pending:!1,_failed:!1}),t.messagesByConv[c]=d,(u==null?void 0:u.type)==="action"&&((m=u==null?void 0:u.payload)!=null&&m.state)&&u.payload.state!=="pending"&&(u==null?void 0:u.id)!=null&&t.awaitingCallback[u.id]&&delete t.awaitingCallback[u.id]}function F(c,u){return c===u?!0:c==null||u==null?!1:String(c)===String(u)}function L(c,u,h){const g=t.messagesByConv[c];if(!g)return;const d=g.findIndex(p=>p.id===u);if(d===-1)return;const m=g.slice();m[d]={...g[d],...h},t.messagesByConv[c]=m}function D(c,u){const h=t.conversations.findIndex(d=>d.id===c);if(h===-1)return;const g=t.conversations[h];if(u&&(!g.last_message_at||u>g.last_message_at)){const d=t.conversations.slice();d[h]={...g,last_message_at:u},d.sort((m,p)=>(p.last_message_at||"").localeCompare(m.last_message_at||"")),t.conversations=d}}function R(c,u){return(c.created_at||"").localeCompare(u.created_at||"")}function J(c){if(!c||typeof c!="object")return null;const u={},h={};for(const[g,d]of Object.entries(c))d!==void 0&&(g==="name"||g==="email"?d!=null&&String(d).trim()!==""&&(u[g]=d):(g==="values"||g==="metadata")&&d&&typeof d=="object"?Object.assign(h,d):h[g]=d);return Object.keys(h).length&&(u.values=h),Object.keys(u).length?u:null}function U(c){const u=t.messagesByConv[c]||[];let h="";for(const m of u)m!=null&&m.created_at&&m.created_at>h&&(h=m.created_at);const g=new Date().toISOString();return!h||g>h?g:new Date(Date.parse(h)+1).toISOString()}return{state:t,start:a,destroy:s,applyCustomer:o,createConversation:i,openConversation:f,loadMore:v,patchConversation:b,send:S,clickCallback:k,signAttachment:w,submitFeedback:M,getPendingApproval:x,getActionInFlight:O,getLatestSuggestions:$,getLatestForm:V,setPanelOpen:n.setPanelOpen}}const T={w:"#ffffff",g50:"#F9F9F7",g100:"#F2F1EE",g150:"#E8E6E2",g200:"#D9D6CF",g300:"#B4B0A8",g400:"#888480",g500:"#5A5753",g700:"#2B2926",g900:"#17161A",accent:"#5B5FEF",accentLight:"#EEEFFE",green:"#22C55E",red:"#B91C1C",redBg:"#FDECEC"},q=["#5B5FEF","#7C3AED","#DB2777","#0891B2","#D97706","#059669"];function Q(n=""){return n?q[n.charCodeAt(0)%q.length]:q[0]}function Z(n=""){return n.split(" ").map(t=>t[0]||"").join("").toUpperCase().slice(0,2)}function ee(n=new Date){return n.toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit"})}const ce=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),Pe=["connected","message","message_stream","conversation_updated","config_updated","action_status"],ne="/client",Ue=5*60*1e3,je=10*60*1e3,ze=5*60*1e3;function ce(t){const n={baseUrl:He(t.baseUrl||""),widgetId:t.widgetId||"",userId:t.userId||"",userHash:t.userHash||"",listeners:new Map,eventSource:null,connection:"idle",visibilityHandler:null,started:!1,panelOpen:!1,pollTimer:null,burstTimer:null,hiddenGraceTimer:null,lastActivityAt:null};if(!n.baseUrl||!n.widgetId||!n.userId||!n.userHash)throw new Error("[transport] baseUrl, widgetId, userId, userHash are all required");function r(d,m){return n.listeners.has(d)||n.listeners.set(d,new Set),n.listeners.get(d).add(m),()=>n.listeners.get(d).delete(m)}function a(d,m){const f=n.listeners.get(d);f&&f.forEach(g=>{try{g(m)}catch(b){console.error("[transport] listener",d,b)}})}function s(d){n.connection!==d&&(n.connection=d,a("connection",d))}function o(){return{"X-User-Id":n.userId,"X-User-Hash":n.userHash,"X-Widget-Id":n.widgetId}}async function i(d,m,f){const g=await fetch(`${n.baseUrl}${ne}${m}`,{method:d,headers:{"Content-Type":"application/json",...o()},body:f!==void 0?JSON.stringify(f):void 0});if(!g.ok){const b=await l(g),C=new Error(`HTTP ${g.status} ${d} ${m} :: ${(b==null?void 0:b.error)||g.statusText}`);throw C.status=g.status,C.body=b,C}return g.status===204?null:g.json()}async function l(d){try{return await d.json()}catch{return null}}async function p(){const[d,m]=await Promise.all([fetch(`${n.baseUrl}/widgets/${encodeURIComponent(n.widgetId)}/config`).then(async f=>{if(!f.ok){const g=await l(f);throw new Error(`HTTP ${f.status} GET /widgets/:id/config :: ${(g==null?void 0:g.error)||f.statusText}`)}return f.json()}),i("GET","/customers/me")]);return{config:d,customer:(m==null?void 0:m.customer)??null}}async function v(){const d=await i("GET","/customers/me");return(d==null?void 0:d.customer)??null}async function y(d){const m=await i("PATCH","/customers/me",d);return(m==null?void 0:m.customer)??null}async function E(){const d=await i("GET","/conversations");return(d==null?void 0:d.conversations)??[]}async function S(d={}){return(await i("POST","/conversations",d)).conversation}async function k(d){return(await i("GET",`/conversations/${encodeURIComponent(d)}`)).conversation}async function x(d,m){return(await i("PATCH",`/conversations/${encodeURIComponent(d)}`,m)).conversation}async function w(d,m){return(await i("PATCH",`/conversations/${encodeURIComponent(d)}/read`,{message_id:m})).conversation}async function M(d,m={}){const f=new URLSearchParams;m.before&&f.set("before",m.before),m.since&&f.set("since",m.since),m.limit&&f.set("limit",String(m.limit));const g=f.toString()?`?${f.toString()}`:"";return i("GET",`/conversations/${encodeURIComponent(d)}/messages${g}`)}async function A(d,m){I();const f={client_msg_id:m.client_msg_id,type:"content",text_md:m.text_md,author:{id:n.userId,type:"user"},created_at:m.created_at||new Date().toISOString()};return Array.isArray(m.attachments)&&m.attachments.length&&(f.payload={type:"content",attachments:m.attachments}),m.metadata&&typeof m.metadata=="object"&&(f.metadata=m.metadata),i("POST",`/conversations/${encodeURIComponent(d)}/messages`,f)}async function T(d,m,f){return I(),i("POST",`/messages/${encodeURIComponent(d)}/callbacks/${encodeURIComponent(m)}`,f?{inputs:f}:{})}async function D(d){const m=d.name||"attachment",f=d.type||"application/octet-stream",g=d.size||0,b=await i("POST","/attachments",{mime_type:f,size_bytes:g,name:m}),C=await fetch(b.upload_url,{method:"PUT",headers:{"Content-Type":f},body:d});if(!C.ok)throw new Error(`HTTP ${C.status} PUT signed upload`);return{type:qe(f),path:b.path,mime_type:f,size_bytes:g}}async function F(d){return i("GET",`/attachments/sign?path=${encodeURIComponent(d)}`)}function $(){const d=new URLSearchParams({userId:n.userId,userHash:n.userHash,widgetId:n.widgetId}).toString();return`${n.baseUrl}${ne}/stream?${d}`}function O(){if(!n.eventSource&&!(typeof document<"u"&&document.hidden))try{const d=new EventSource($());for(const m of Pe)d.addEventListener(m,f=>P(m,f.data));d.addEventListener("error",()=>a("error",new Error("SSE error"))),n.eventSource=d,s("open")}catch(d){console.error("[transport] SSE open failed",d),a("error",d)}}function P(d,m){try{const f=JSON.parse(m),g=f&&typeof f=="object"&&"data"in f?f.data:f;a(d,g)}catch(f){console.error("[transport] bad SSE payload",d,f)}}function L(){n.eventSource&&(n.eventSource.close(),n.eventSource=null),n.connection!=="paused"&&s("idle")}function I(){clearTimeout(n.burstTimer),O(),n.panelOpen||(n.burstTimer=setTimeout(()=>{n.panelOpen||L()},je))}function H(d){n.panelOpen=!!d,n.panelOpen?(clearTimeout(n.burstTimer),O()):I()}async function J(){try{const d=await E(),m=d.reduce((g,b)=>{const C=b==null?void 0:b.last_message_at;return C&&(!g||C>g)?C:g},null);m&&(!n.lastActivityAt||m>n.lastActivityAt)&&(n.lastActivityAt=m,a("activity",{conversations:d,latestAt:m}),I())}catch(d){console.error("[transport] poll failed",d)}}function q(){c(),!(typeof document<"u"&&document.hidden)&&(n.pollTimer=setInterval(J,Ue))}function c(){n.pollTimer&&(clearInterval(n.pollTimer),n.pollTimer=null)}function u(){if(document.hidden)clearTimeout(n.hiddenGraceTimer),n.hiddenGraceTimer=setTimeout(()=>{n.hiddenGraceTimer=null,document.hidden&&(c(),L(),s("paused"))},ze);else{if(n.hiddenGraceTimer){clearTimeout(n.hiddenGraceTimer),n.hiddenGraceTimer=null;return}s("idle"),q(),n.panelOpen&&O()}}async function h(){if(n.started)return n.lastBootstrap;n.started=!0;const d=await p();n.lastBootstrap=d;try{const m=await E();n.lastActivityAt=m.reduce((f,g)=>{const b=g==null?void 0:g.last_message_at;return b&&(!f||b>f)?b:f},null)}catch(m){console.error("[transport] initial /conversations failed",m)}return typeof document<"u"&&(n.visibilityHandler=u,document.addEventListener("visibilitychange",n.visibilityHandler)),q(),d}function _(){c(),clearTimeout(n.burstTimer),clearTimeout(n.hiddenGraceTimer),n.hiddenGraceTimer=null,L(),n.visibilityHandler&&(document.removeEventListener("visibilitychange",n.visibilityHandler),n.visibilityHandler=null),n.started=!1}return{on:r,start:h,stop:_,setPanelOpen:H,bootstrap:p,getCustomer:v,patchCustomer:y,listConversations:E,createConversation:S,getConversation:k,patchConversation:x,markConversationRead:w,listMessages:M,postMessage:A,postCallback:T,uploadAttachment:D,signAttachment:F,get connection(){return n.connection}}}function He(t){return t.endsWith("/")?t.slice(0,-1):t}function qe(t){return t.startsWith("image/")?"image":t.startsWith("video/")?"video":t.startsWith("audio/")?"audio":"file"}function Q(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const t=new Uint8Array(16);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(t);else for(let r=0;r<16;r++)t[r]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const n=[...t].map(r=>r.toString(16).padStart(2,"0"));return n.slice(0,4).join("")+"-"+n.slice(4,6).join("")+"-"+n.slice(6,8).join("")+"-"+n.slice(8,10).join("")+"-"+n.slice(10,16).join("")}function de(t){const n=e.reactive({ready:!1,error:null,config:null,customer:null,conversations:[],messagesByConv:{},paginationByConv:{},streamingByMsgId:{},awaitingCallback:{},runningActionsByConv:{},connection:"idle"}),r=[];r.push(t.on("connection",c=>{n.connection=c})),r.push(t.on("message",c=>{const u=c==null?void 0:c.conversation_id,h=c==null?void 0:c.message;!u||!(h!=null&&h.id)||(O(u,h),h.client_msg_id&&delete n.streamingByMsgId[h.client_msg_id],I(u,h.created_at))})),r.push(t.on("message_stream",c=>{const u=c==null?void 0:c.message_id,h=c==null?void 0:c.token;!u||typeof h!="string"||(n.streamingByMsgId[u]=(n.streamingByMsgId[u]||"")+h)})),r.push(t.on("conversation_updated",c=>{const u=c==null?void 0:c.conversation_id,h=c==null?void 0:c.changes;if(!u||!h)return;const _=n.conversations.findIndex(d=>d.id===u);_!==-1&&(n.conversations[_]={...n.conversations[_],...h})})),r.push(t.on("config_updated",c=>{c!=null&&c.config&&(n.config=c.config)})),r.push(t.on("action_status",c=>{const u=c==null?void 0:c.conversation_id,h=c==null?void 0:c.action_id,_=c==null?void 0:c.action_name;if(!u||!h)return;const d=n.runningActionsByConv[u]||{};c.state==="running"?(d[h]=_||h,n.runningActionsByConv[u]={...d}):c.state==="done"&&(delete d[h],n.runningActionsByConv[u]={...d})})),r.push(t.on("activity",c=>{Array.isArray(c==null?void 0:c.conversations)&&(n.conversations=c.conversations)}));async function a(){try{const c=new Promise((h,_)=>setTimeout(()=>_(new Error("bootstrap timeout (15s) — check baseUrl, CORS, and network")),15e3)),u=await Promise.race([t.start(),c]);n.config=u.config,n.customer=u.customer,n.conversations=await Promise.race([t.listConversations(),c]),n.ready=!0}catch(c){console.error("[store] start failed",c),n.error=(c==null?void 0:c.message)||String(c)}}function s(){for(const c of r)try{c()}catch{}t.stop()}async function o(c){const u=J(c);if(!u)return n.customer;try{const h=await t.patchCustomer(u);h&&(n.customer=h)}catch(h){console.error("[store] applyCustomer failed",h)}return n.customer}async function i(c={}){const u=await t.createConversation(c),h=n.conversations.findIndex(_=>_.id===u.id);return h===-1?n.conversations=[u,...n.conversations]:n.conversations[h]=u,u}const l=50;async function p(c){const u=n.paginationByConv[c];if(!(u!=null&&u.loaded||u!=null&&u.loading)){y(c,{nextCursor:null,loading:!0,loaded:!1});try{const h=await t.listMessages(c,{limit:l}),_=(h==null?void 0:h.messages)??[],d=n.messagesByConv[c]||[],m=new Set;for(const g of _)(g==null?void 0:g.id)!=null&&m.add(`id:${String(g.id)}`),g!=null&&g.client_msg_id&&m.add(`c:${g.client_msg_id}`);const f=d.filter(g=>!((g==null?void 0:g.id)!=null&&m.has(`id:${String(g.id)}`)||g!=null&&g.client_msg_id&&m.has(`c:${g.client_msg_id}`)));n.messagesByConv[c]=[..._,...f].sort(H),y(c,{nextCursor:(h==null?void 0:h.next_cursor)??null,loading:!1,loaded:!0})}catch(h){console.error("[store] openConversation failed",h),y(c,{nextCursor:null,loading:!1,loaded:!1})}}}async function v(c){var d;const u=n.paginationByConv[c];if(!u||u.loading||!u.nextCursor)return;const _=(d=(n.messagesByConv[c]||[]).find(m=>m==null?void 0:m.created_at))==null?void 0:d.created_at;if(_){y(c,{...u,loading:!0});try{const m=await t.listMessages(c,{before:_,limit:l}),f=(m==null?void 0:m.messages)??[],g=n.messagesByConv[c]||[],b=new Set;for(const B of g)(B==null?void 0:B.id)!=null&&b.add(`id:${String(B.id)}`),B!=null&&B.client_msg_id&&b.add(`c:${B.client_msg_id}`);const C=f.filter(B=>!((B==null?void 0:B.id)!=null&&b.has(`id:${String(B.id)}`)||B!=null&&B.client_msg_id&&b.has(`c:${B.client_msg_id}`)));n.messagesByConv[c]=[...C,...g],y(c,{nextCursor:(m==null?void 0:m.next_cursor)??null,loading:!1,loaded:!0})}catch(m){console.error("[store] loadMore failed",m),y(c,{...u,loading:!1})}}}function y(c,u){n.paginationByConv={...n.paginationByConv,[c]:u}}async function E(c,u){const h=await t.patchConversation(c,u),_=n.conversations.findIndex(d=>d.id===c);_!==-1&&(n.conversations[_]=h)}async function S(c,u){if(!(!c||u==null))try{const h=await t.markConversationRead(c,u),_=n.conversations.findIndex(d=>d.id===c);_!==-1&&(n.conversations[_]=h)}catch(h){console.error("[store] markConversationRead failed",h)}}async function k(c,u,{attachments:h,metadata:_}={}){var C;const d=(u||"").trim(),m=Array.isArray(h)&&h.length>0;if(!c||!d&&!m)return;const f=Q(),g=q(c),b={id:f,client_msg_id:f,conversation_id:c,type:"content",text_md:d,author:{type:"user",id:((C=n.customer)==null?void 0:C.external_id)||null},created_at:g,_pending:!0,...m?{payload:{type:"content",attachments:h}}:{},..._&&typeof _=="object"?{metadata:_}:{}};O(c,b);try{await t.postMessage(c,{client_msg_id:f,text_md:d,created_at:g,...m?{attachments:h}:{},..._&&typeof _=="object"?{metadata:_}:{}})}catch(B){console.error("[store] send failed",B),L(c,f,{_failed:!0,_pending:!1})}}async function x(c,u,h){c!=null&&(n.awaitingCallback[c]=!0);try{await t.postCallback(c,u,h)}catch(_){console.error("[store] callback failed",_),c!=null&&delete n.awaitingCallback[c]}}const w=new Map;async function M(c){if(!c)return null;const u=w.get(c);if(u!=null&&u.url){const h=u.expires_at?Date.parse(u.expires_at):0;if(!h||h-Date.now()>6e4)return u.url}try{const h=await t.signAttachment(c);if(h!=null&&h.signed_url)return w.set(c,{url:h.signed_url,expires_at:h.expires_at}),h.signed_url}catch(h){console.error("[store] sign attachment failed",h)}return null}async function A(c,{rating:u,comment:h}={}){const _=n.conversations.find(f=>f.id===c),m={...(_==null?void 0:_.metadata)||{},feedback:{rating:u,comment:h||null,submitted_at:new Date().toISOString()}};await E(c,{metadata:m})}function T(c){var h,_;const u=n.messagesByConv[c]||[];for(let d=u.length-1;d>=0;d--){const m=u[d];if((m==null?void 0:m.type)==="action"&&((h=m==null?void 0:m.payload)==null?void 0:h.type)==="action"&&((_=m==null?void 0:m.payload)==null?void 0:_.state)==="pending"&&Array.isArray(m==null?void 0:m.callbacks)&&m.callbacks.length>0&&!n.awaitingCallback[m.id])return m}return null}function D(c){var h,_,d;const u=n.messagesByConv[c]||[];for(let m=u.length-1;m>=0;m--){const f=u[m];if(((h=f==null?void 0:f.author)==null?void 0:h.type)==="user"||(f==null?void 0:f.type)==="action"&&((_=f==null?void 0:f.payload)==null?void 0:_.state)==="pending")return null;const g=(d=f==null?void 0:f.metadata)==null?void 0:d.form;if(g&&Array.isArray(g.fields)&&g.fields.length>0)return{message:f,form:g}}return null}function F(c){const u=n.runningActionsByConv[c];if(!u)return null;const h=Object.keys(u);if(h.length===0)return null;const _=h[0];return{id:_,payload:{name:u[_]}}}function $(c){var h,_,d,m;const u=n.messagesByConv[c]||[];for(let f=u.length-1;f>=0;f--){const g=u[f];if(((h=g==null?void 0:g.author)==null?void 0:h.type)==="user")return[];if((g==null?void 0:g.type)==="action"&&((_=g==null?void 0:g.payload)==null?void 0:_.state)==="pending")return[];if(((d=g==null?void 0:g.author)==null?void 0:d.type)!=="agent_ia")continue;const b=(m=g==null?void 0:g.metadata)==null?void 0:m.suggested_replies;return Array.isArray(b)&&b.length?b.map(C=>{if(typeof C=="string"){const B=C.trim();return B?{label:B,kind:null}:null}if(C&&typeof C=="object"&&typeof C.label=="string"){const B=C.label.trim();if(!B)return null;const $e=C.kind==="cta"||C.kind==="choice"||C.kind==="followup"?C.kind:null;return{label:B,kind:$e}}return null}).filter(Boolean).slice(0,4):[]}return[]}function O(c,u){var m;const h=n.messagesByConv[c]||[];let _=-1;u!=null&&u.client_msg_id&&(_=h.findIndex(f=>(f==null?void 0:f.client_msg_id)&&f.client_msg_id===u.client_msg_id)),_===-1&&(u==null?void 0:u.id)!==void 0&&(u==null?void 0:u.id)!==null&&(_=h.findIndex(f=>P(f==null?void 0:f.id,u.id)));let d;_===-1?d=[...h,u].sort(H):(d=h.slice(),d[_]={...h[_],...u,_pending:!1,_failed:!1}),n.messagesByConv[c]=d,(u==null?void 0:u.type)==="action"&&((m=u==null?void 0:u.payload)!=null&&m.state)&&u.payload.state!=="pending"&&(u==null?void 0:u.id)!=null&&n.awaitingCallback[u.id]&&delete n.awaitingCallback[u.id]}function P(c,u){return c===u?!0:c==null||u==null?!1:String(c)===String(u)}function L(c,u,h){const _=n.messagesByConv[c];if(!_)return;const d=_.findIndex(f=>f.id===u);if(d===-1)return;const m=_.slice();m[d]={..._[d],...h},n.messagesByConv[c]=m}function I(c,u){const h=n.conversations.findIndex(d=>d.id===c);if(h===-1)return;const _=n.conversations[h];if(u&&(!_.last_message_at||u>_.last_message_at)){const d=n.conversations.slice();d[h]={..._,last_message_at:u},d.sort((m,f)=>(f.last_message_at||"").localeCompare(m.last_message_at||"")),n.conversations=d}}function H(c,u){return(c.created_at||"").localeCompare(u.created_at||"")}function J(c){if(!c||typeof c!="object")return null;const u={},h={};for(const[_,d]of Object.entries(c))d!==void 0&&(_==="name"||_==="email"?d!=null&&String(d).trim()!==""&&(u[_]=d):(_==="values"||_==="metadata")&&d&&typeof d=="object"?Object.assign(h,d):h[_]=d);return Object.keys(h).length&&(u.values=h),Object.keys(u).length?u:null}function q(c){const u=n.messagesByConv[c]||[];let h="";for(const m of u)m!=null&&m.created_at&&m.created_at>h&&(h=m.created_at);const _=new Date().toISOString();return!h||_>h?_:new Date(Date.parse(h)+1).toISOString()}return{state:n,start:a,destroy:s,applyCustomer:o,createConversation:i,openConversation:p,loadMore:v,patchConversation:E,markConversationRead:S,send:k,clickCallback:x,signAttachment:M,submitFeedback:A,getPendingApproval:T,getActionInFlight:F,getLatestSuggestions:$,getLatestForm:D,setPanelOpen:t.setPanelOpen}}const V={w:"#ffffff",g50:"#F9F9F7",g100:"#F2F1EE",g150:"#E8E6E2",g200:"#D9D6CF",g300:"#B4B0A8",g400:"#888480",g500:"#5A5753",g700:"#2B2926",g900:"#17161A",accent:"#5B5FEF",accentLight:"#EEEFFE",green:"#22C55E",red:"#B91C1C",redBg:"#FDECEC"},W=["#5B5FEF","#7C3AED","#DB2777","#0891B2","#D97706","#059669"];function Z(t=""){return t?W[t.charCodeAt(0)%W.length]:W[0]}function ee(t=""){return t.split(" ").map(n=>n[0]||"").join("").toUpperCase().slice(0,2)}function te(t=new Date){return t.toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit"})}const ue=`
2
2
  @import url('https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&family=Geist+Mono:wght@400;500&display=swap');
3
3
 
4
4
  .wm-root {
5
5
  --wm-f: 'Geist', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
6
6
  --wm-fm: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
7
- --wm-w: ${T.w};
8
- --wm-g50: ${T.g50};
9
- --wm-g100: ${T.g100};
10
- --wm-g150: ${T.g150};
11
- --wm-g200: ${T.g200};
12
- --wm-g300: ${T.g300};
13
- --wm-g400: ${T.g400};
14
- --wm-g500: ${T.g500};
15
- --wm-g700: ${T.g700};
16
- --wm-g900: ${T.g900};
17
- --wm-a: ${T.accent};
18
- --wm-al: ${T.accentLight};
19
- --wm-green: ${T.green};
20
- --wm-red: ${T.red};
21
- --wm-redBg: ${T.redBg};
7
+ --wm-w: ${V.w};
8
+ --wm-g50: ${V.g50};
9
+ --wm-g100: ${V.g100};
10
+ --wm-g150: ${V.g150};
11
+ --wm-g200: ${V.g200};
12
+ --wm-g300: ${V.g300};
13
+ --wm-g400: ${V.g400};
14
+ --wm-g500: ${V.g500};
15
+ --wm-g700: ${V.g700};
16
+ --wm-g900: ${V.g900};
17
+ --wm-a: ${V.accent};
18
+ --wm-al: ${V.accentLight};
19
+ --wm-green: ${V.green};
20
+ --wm-red: ${V.red};
21
+ --wm-redBg: ${V.redBg};
22
22
  --wm-sh1: 0 1px 3px rgba(0,0,0,.06);
23
23
  --wm-sh2: 0 4px 24px rgba(0,0,0,.09), 0 1px 4px rgba(0,0,0,.05);
24
24
  --wm-shPanel: 0 12px 40px rgba(0,0,0,.13), 0 2px 8px rgba(0,0,0,.06);
@@ -44,13 +44,13 @@
44
44
  0% { transform: translateX(110%); opacity: 0; }
45
45
  100% { transform: translateX(0); opacity: 1; }
46
46
  }
47
- `,de="https://api.messenger.victorc.fr";function ne(n,t){if(!Array.isArray(n==null?void 0:n.options))return t;const r=n.options.find(a=>(a==null?void 0:a.value)===t);return(r==null?void 0:r.label)||t}function ue(n,t){return Array.isArray(t)?t.map(r=>ne(n,String(r))).join(", "):typeof t=="boolean"?t?"Oui":"Non":ne(n,String(t))}function qe(n,t){if(!n||!t)return"";const r=Array.isArray(n.fields)?n.fields:[],a=[];for(const s of r){if(!(s!=null&&s.key)||!(s!=null&&s.label))continue;const o=t[s.key];if(o==null||o==="")continue;const i=ue(s,o);i&&a.push(`${s.label} :
47
+ `,me="https://api.messenger.victorc.fr";function re(t,n){if(!Array.isArray(t==null?void 0:t.options))return n;const r=t.options.find(a=>(a==null?void 0:a.value)===n);return(r==null?void 0:r.label)||n}function he(t,n){return Array.isArray(n)?n.map(r=>re(t,String(r))).join(", "):typeof n=="boolean"?n?"Oui":"Non":re(t,String(n))}function Ke(t,n){if(!t||!n)return"";const r=Array.isArray(t.fields)?t.fields:[],a=[];for(const s of r){if(!(s!=null&&s.key)||!(s!=null&&s.label))continue;const o=n[s.key];if(o==null||o==="")continue;const i=he(s,o);i&&a.push(`${s.label} :
48
48
  ${i}`)}return a.join(`
49
49
 
50
- `)}function Ke(n,t){const r=[],a=Array.isArray(n==null?void 0:n.fields)?n.fields:[];for(const s of a){if(!(s!=null&&s.key)||!(s!=null&&s.label))continue;const o=t==null?void 0:t[s.key];if(o==null||o==="")continue;const i=ue(s,o);if(!i)continue;const l=s.type==="textarea"||typeof i=="string"&&(i.length>60||i.includes(`
51
- `));r.push({label:s.label,value:i,multiline:l})}return{kind:"form_response",data:{title:(n==null?void 0:n.title)||"Formulaire",fields:r}}}function W(n){var r;const t=(r=n==null?void 0:n.author)==null?void 0:r.type;return t==="agent_ia"||t==="agent_human"}function K(n,t){let r=(n==null?void 0:n.last_message_at)||(n==null?void 0:n.updated_at)||(n==null?void 0:n.created_at)||"";for(const a of t)a!=null&&a.created_at&&a.created_at>r&&(r=a.created_at);return r}function We(n){var t,r;for(let a=n.length-1;a>=0;a--){const s=(r=(t=n[a])==null?void 0:t.author)==null?void 0:r.type;if(s)return s}return""}function Ge(n,t){var r,a,s;for(let o=t.length-1;o>=0;o--){const i=t[o];if(!i)continue;const l=typeof i.text_md=="string"?i.text_md.trim():"";if(l)return(((r=i.author)==null?void 0:r.type)==="user"?"Vous : ":"")+l.replace(/\s+/g," ");const f=(a=i.payload)==null?void 0:a.attachments;if(Array.isArray(f)&&f.length)return"📎 Pièce jointe"}return(n==null?void 0:n.last_message_preview)||(n==null?void 0:n.preview)||((s=n==null?void 0:n.metadata)==null?void 0:s.last_preview)||""}function Ye(n){return(n==null?void 0:n.name)||((n==null?void 0:n.type)==="user"?"Vous":(n==null?void 0:n.type)==="agent_human"?"Agent":(n==null?void 0:n.type)==="agent_ia"?"Assistant IA":"Système")}function Je(n,t){const r=[`# ${n.name||"Conversation"}`,n.created_at?`Créée le : ${n.created_at}`:"",""];for(const a of t){if(!a)continue;const s=(a.text_md||"").trim();if(!s)continue;const o=Ye(a.author),i=a.created_at?new Date(a.created_at).toLocaleString("fr-FR"):"";r.push(`[${i}] ${o} :`),r.push(s),r.push("")}return r.join(`
52
- `)}function Xe(n,t){if(!n)return;const r=Je(n,t||[]),a=new Blob([r],{type:"text/plain;charset=utf-8"});try{const s=URL.createObjectURL(a),o=document.createElement("a");o.href=s,o.download=`${(n.name||"conversation").replace(/[^a-z0-9-_]+/gi,"_")}.txt`,document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>URL.revokeObjectURL(s),1e3)}catch(s){console.error("[ww-messenger] export failed",s)}}const Qe={data(){const n=typeof Notification<"u";return{notifPermission:n?Notification.permission:"denied",soundEnabled:!0,browserNotifEnabled:n&&Notification.permission==="granted",_notifUnsub:null,_audioCtx:null}},methods:{setupNotifications(){this.transport&&(this.teardownNotifications(),this._notifUnsub=this.transport.on("message",this.onIncomingNotification))},teardownNotifications(){var n,t;if(this._notifUnsub){try{this._notifUnsub()}catch{}this._notifUnsub=null}if(this._audioCtx){try{(t=(n=this._audioCtx).close)==null||t.call(n)}catch{}this._audioCtx=null}},soundStorageKey(){return`wm:notif:sound:${this.widgetId||""}:${this.userId||""}`},browserNotifStorageKey(){return`wm:notif:browser:${this.widgetId||""}:${this.userId||""}`},hydrateNotifPref(){try{if(typeof localStorage>"u")return;const n=localStorage.getItem(this.soundStorageKey());n==="0"?this.soundEnabled=!1:n==="1"&&(this.soundEnabled=!0);const t=localStorage.getItem(this.browserNotifStorageKey());t==="0"?this.browserNotifEnabled=!1:t==="1"&&(this.browserNotifEnabled=typeof Notification<"u"&&Notification.permission==="granted")}catch{}},persistSoundPref(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.soundStorageKey(),this.soundEnabled?"1":"0")}catch{}},persistBrowserNotifPref(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.browserNotifStorageKey(),this.browserNotifEnabled?"1":"0")}catch{}},onSoundToggle(n){this.soundEnabled=!!n,this.persistSoundPref()},async onBrowserNotifToggle(n){if(typeof Notification>"u"){this.browserNotifEnabled=!1,this.persistBrowserNotifPref();return}if(!n){this.browserNotifEnabled=!1,this.persistBrowserNotifPref();return}let t=Notification.permission;if(t==="default"){try{t=await Notification.requestPermission()}catch(r){console.warn("[ww-messenger] notif permission request failed",r),t="denied"}this.notifPermission=t}this.browserNotifEnabled=t==="granted",this.persistBrowserNotifPref()},onIncomingNotification(n){var i;if(!this.soundEnabled&&!this.browserNotifEnabled)return;const t=n==null?void 0:n.conversation_id,r=n==null?void 0:n.message;if(!t||!r||!W(r))return;const a=r!=null&&r.created_at?Date.parse(r.created_at):NaN;if(Number.isFinite(a)&&a<this.convOpenedAt-1e3)return;const s=typeof document<"u"&&document.hidden;this.isOpen&&!s&&((i=this.currentConv)==null?void 0:i.id)===t||(this.soundEnabled&&this.playNotificationSound(),this.browserNotifEnabled&&this.showBrowserNotification(t,r))},playNotificationSound(){if(typeof window>"u")return;const n=window.AudioContext||window.webkitAudioContext;if(n)try{this._audioCtx||(this._audioCtx=new n);const t=this._audioCtx;if(t.state==="suspended")try{t.resume()}catch{}const r=t.currentTime,a=t.createOscillator(),s=t.createGain();a.connect(s),s.connect(t.destination),a.type="sine",a.frequency.setValueAtTime(880,r),a.frequency.exponentialRampToValueAtTime(1320,r+.08),s.gain.setValueAtTime(0,r),s.gain.linearRampToValueAtTime(.12,r+.02),s.gain.exponentialRampToValueAtTime(1e-4,r+.28),a.start(r),a.stop(r+.32)}catch{}},showBrowserNotification(n,t){var i;if(typeof Notification>"u"||Notification.permission!=="granted")return;const r=this.allConversations.find(l=>l.id===n),a=(r==null?void 0:r.name)||((i=this.widget)==null?void 0:i.name)||"Nouveau message",s=typeof(t==null?void 0:t.text_md)=="string"?t.text_md.trim():"",o=s?s.slice(0,140):"Vous avez un nouveau message";try{const l=new Notification(a,{body:o,tag:`wm-${n}`,renotify:!1,silent:!0});l.onclick=()=>{try{window.focus()}catch{}this.draftConv=null,this.showOnboarding=!1,this.activeConvId=n,this.isOpen=!0,this.store&&this.store.setPanelOpen(!0);try{l.close()}catch{}}}catch(l){console.warn("[ww-messenger] notification failed",l)}}}},Ze=450,et=50,tt=900,nt=12e3,rt=300,ot={data(){return{revealedAt:{},nextRevealAt:0,revealTimers:[]}},methods:{cancelReveals(){for(const n of this.revealTimers)clearTimeout(n);this.revealTimers=[]},resetRevealQueue(){this.cancelReveals(),this.revealedAt={},this.nextRevealAt=0},scheduleReveal(n){const t=Date.now(),r=((n==null?void 0:n.text_md)||"").length,a=Math.min(nt,Math.max(tt,r*et)),o=Math.max(t+Ze,this.nextRevealAt+rt)+a;this.nextRevealAt=o;const i=Math.max(0,o-t),l=n.id,f=setTimeout(()=>{this.revealedAt={...this.revealedAt,[l]:Date.now()},this.revealTimers=this.revealTimers.filter(v=>v!==f)},i);this.revealTimers.push(f)},paceMessages(n){var a;if(!Array.isArray(n)||!n.length)return;const t=Date.now(),r={...this.revealedAt};for(const s of n){if((s==null?void 0:s.id)==null||r[s.id]!==void 0)continue;if(!W(s)){r[s.id]=t;continue}const o=s!=null&&s.created_at?Date.parse(s.created_at):NaN;if(!Number.isFinite(o)||o<this.convOpenedAt){r[s.id]=t;continue}const i=typeof(s==null?void 0:s.text_md)=="string"&&s.text_md.trim().length>0,l=Array.isArray((a=s==null?void 0:s.payload)==null?void 0:a.attachments)&&s.payload.attachments.length>0;if(!i&&!l){r[s.id]=t;continue}r[s.id]=0,this.scheduleReveal(s)}this.revealedAt=r}}},st={data(){return{approvalSettled:!0,approvalSettleTimer:null,approvalLatchId:null}},methods:{resetApprovalPacing(){this.approvalSettleTimer&&(clearTimeout(this.approvalSettleTimer),this.approvalSettleTimer=null),this.approvalSettled=!0,this.approvalLatchId=null},bumpApprovalSettle(n=800){this.approvalSettled=!1,this.approvalSettleTimer&&clearTimeout(this.approvalSettleTimer),this.approvalSettleTimer=setTimeout(()=>{this.approvalSettled=!0,this.approvalSettleTimer=null},n)}}},at={data(){return{readState:{},readBootTs:"",unreadAnchorTs:"",unreadBoundaryTs:""}},methods:{readStorageKey(){return`wm:read:${this.widgetId||""}:${this.userId||""}`},readBootStorageKey(){return`wm:read-boot:${this.widgetId||""}:${this.userId||""}`},hydrateReadState(){try{if(typeof localStorage>"u")return;const n=localStorage.getItem(this.readStorageKey());if(n){const r=JSON.parse(n);r&&typeof r=="object"&&(this.readState=r)}let t=localStorage.getItem(this.readBootStorageKey())||"";t||(t=new Date().toISOString(),localStorage.setItem(this.readBootStorageKey(),t)),this.readBootTs=t}catch{}},persistReadState(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.readStorageKey(),JSON.stringify(this.readState))}catch{}},markConvRead(n){var a,s;if(!(n!=null&&n.id)||n._draft)return;const t=((s=(a=this.s)==null?void 0:a.messagesByConv)==null?void 0:s[n.id])||[],r=K(n,t);r&&this.readState[n.id]!==r&&(this.readState={...this.readState,[n.id]:r},this.persistReadState())}}},N=(n,t)=>{const r=n.__vccOpts||n;for(const[a,s]of t)r[a]=s;return r},it={name:"WmHumanAvatar",props:{name:{type:String,default:""},avatarUrl:{type:String,default:null},size:{type:Number,default:26},tail:{type:Boolean,default:!1}},computed:{bg(){return this.avatarUrl?"transparent":Q(this.name)},initials(){return Z(this.name)}}},lt=["src","alt"];function ct(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-huav",{"wm-huav--tail":r.tail}]),style:e.normalizeStyle({width:r.size+"px",height:r.size+"px","--wm-avr":Math.round(r.size*.32)+"px",background:o.bg})},[r.avatarUrl?(e.openBlock(),e.createElementBlock("img",{key:0,src:r.avatarUrl,alt:r.name||""},null,8,lt)):(e.openBlock(),e.createElementBlock("span",{key:1,style:e.normalizeStyle({fontSize:r.size*.36+"px"})},e.toDisplayString(o.initials),5))],6)}const G=N(it,[["render",ct],["__scopeId","data-v-07246775"]]),dt=3,ut={name:"WmLauncher",components:{HumanAvatar:G},props:{unreadCount:{type:Number,default:0},peeks:{type:Array,default:()=>[]}},emits:["open","dismiss"],computed:{visiblePeeks(){return this.peeks.slice(0,dt).reverse()}}},mt={class:"wm-launcherWrap"},ht=["aria-label","onClick","onKeydown"],pt=["onClick"],ft={class:"wm-peek__avatar"},_t=["aria-label"],gt={class:"wm-peek__body"},vt={class:"wm-peek__head"},yt={class:"wm-peek__name"},kt={class:"wm-peek__text"},wt=["onClick"],bt=["aria-label"];function Et(n,t,r,a,s,o){const i=e.resolveComponent("HumanAvatar");return e.openBlock(),e.createElementBlock("div",mt,[e.createVNode(e.Transition,{name:"wm-peek"},{default:e.withCtx(()=>[o.visiblePeeks.length?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["wm-peekStack",{"wm-peekStack--multi":o.visiblePeeks.length>1}])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.visiblePeeks,(l,f)=>(e.openBlock(),e.createElementBlock("div",{key:l.convId,class:"wm-peek",style:e.normalizeStyle({"--depth":o.visiblePeeks.length-1-f,zIndex:f+1}),role:"button",tabindex:"0","aria-label":`Ouvrir la conversation avec ${l.senderName||"l'agent"}`,onClick:v=>n.$emit("open",l.convId),onKeydown:[e.withKeys(e.withModifiers(v=>n.$emit("open",l.convId),["prevent"]),["enter"]),e.withKeys(e.withModifiers(v=>n.$emit("open",l.convId),["prevent"]),["space"])]},[e.createElementVNode("button",{type:"button",class:"wm-peek__close","aria-label":"Ignorer",onClick:e.withModifiers(v=>n.$emit("dismiss",l.convId),["stop"])},[...t[1]||(t[1]=[e.createElementVNode("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,pt),e.createElementVNode("div",ft,[e.createVNode(i,{name:l.senderName,"avatar-url":l.senderAvatarUrl,size:34},null,8,["name","avatar-url"]),l.count>1?(e.openBlock(),e.createElementBlock("span",{key:0,class:"wm-peek__avatarBadge","aria-label":`${l.count} messages non lus`},e.toDisplayString(l.count>9?"9+":l.count),9,_t)):e.createCommentVNode("",!0)]),e.createElementVNode("div",gt,[e.createElementVNode("div",vt,[e.createElementVNode("span",yt,e.toDisplayString(l.senderName||"Agent"),1),t[2]||(t[2]=e.createElementVNode("span",{class:"wm-peek__action"}," vous a répondu",-1))]),e.createElementVNode("p",kt,e.toDisplayString(l.preview),1)]),e.createElementVNode("button",{type:"button",class:"wm-peek__open",onClick:e.withModifiers(v=>n.$emit("open",l.convId),["stop"])},"Ouvrir",8,wt)],44,ht))),128))],2)):e.createCommentVNode("",!0)]),_:1}),e.createElementVNode("button",{type:"button",class:"wm-launcher","aria-label":"Ouvrir le messenger",onClick:t[0]||(t[0]=l=>n.$emit("open"))},[t[3]||(t[3]=e.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})],-1)),r.unreadCount>0?(e.openBlock(),e.createElementBlock("span",{key:0,class:"wm-launcher__badge","aria-label":`${r.unreadCount} conversation${r.unreadCount>1?"s":""} non lue${r.unreadCount>1?"s":""}`},e.toDisplayString(r.unreadCount>9?"9+":r.unreadCount),9,bt)):e.createCommentVNode("",!0)])])}const me=N(ut,[["render",Et],["__scopeId","data-v-7464ea26"]]),Bt={name:"WmAIAvatar",props:{size:{type:Number,default:26},pulse:{type:Boolean,default:!1},tail:{type:Boolean,default:!1}}},Ct={key:0,class:"wm-aiav__pulse"},Nt=["width","height"];function St(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-aiav",{"wm-aiav--tail":r.tail}]),style:e.normalizeStyle({width:r.size+"px",height:r.size+"px","--wm-avr":r.size*.32+"px"})},[r.pulse?(e.openBlock(),e.createElementBlock("div",Ct)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(["wm-aiav__inner",{"wm-aiav__inner--glow":r.pulse}])},[(e.openBlock(),e.createElementBlock("svg",{width:r.size*.5,height:r.size*.5,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true"},[...t[0]||(t[0]=[e.createElementVNode("path",{d:"M12 2 L13.5 9 L20 10.5 L13.5 12 L12 19 L10.5 12 L4 10.5 L10.5 9 Z",fill:"white",opacity:"0.92"},null,-1),e.createElementVNode("circle",{cx:"19",cy:"5",r:"1.5",fill:"white",opacity:"0.55"},null,-1),e.createElementVNode("circle",{cx:"5",cy:"18",r:"1",fill:"white",opacity:"0.38"},null,-1)])],8,Nt))],2)],6)}const z=N(Bt,[["render",St],["__scopeId","data-v-8c924688"]]),Vt={name:"WmTeamAvatars",props:{members:{type:Array,default:()=>[]},responseLabel:{type:String,default:""}},computed:{visible(){return Array.isArray(this.members)&&this.members.length>0},stackWidth(){return Math.min(this.members.length,3)===1?20:16+Math.min(this.members.length,3)*13}},methods:{colorFor(n){return n.avatar_url?"transparent":Q(n.name||"")},initialsFor(n){return Z(n.name||"")}}},At={key:0,class:"wm-team"},Tt=["src","alt"],Mt={key:1},xt={key:0,class:"wm-team__label"};function Ot(n,t,r,a,s,o){return o.visible?(e.openBlock(),e.createElementBlock("div",At,[e.createElementVNode("div",{class:"wm-team__stack",style:e.normalizeStyle({width:o.stackWidth+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.members.slice(0,3),(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-team__pill",style:e.normalizeStyle({left:l*13+"px",zIndex:3-l,background:o.colorFor(i)})},[i.avatar_url?(e.openBlock(),e.createElementBlock("img",{key:0,src:i.avatar_url,alt:i.name||""},null,8,Tt)):(e.openBlock(),e.createElementBlock("span",Mt,e.toDisplayString(o.initialsFor(i)),1))],4))),128))],4),r.responseLabel?(e.openBlock(),e.createElementBlock("span",xt,e.toDisplayString(r.responseLabel),1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)}const he=N(Vt,[["render",Ot],["__scopeId","data-v-3659b9c1"]]),It={name:"WmHeader",components:{AIAvatar:z,HumanAvatar:G,TeamAvatars:he},props:{title:{type:String,default:"Nouvelle conversation"},escalated:{type:Boolean,default:!1},agentName:{type:String,default:""},agentAvatarUrl:{type:String,default:null},showBack:{type:Boolean,default:!1},teamMembers:{type:Array,default:()=>[]},responseLabel:{type:String,default:""},showClose:{type:Boolean,default:!0},showMore:{type:Boolean,default:!0},moreActive:{type:Boolean,default:!1},showIdentity:{type:Boolean,default:!0}},emits:["back","close","more"],computed:{hasTeam(){return Array.isArray(this.teamMembers)&&this.teamMembers.length>0},displayedTeamMembers(){const n=Array.isArray(this.teamMembers)?this.teamMembers:[];if(n.length<=3)return n;const t=new Date().getHours()%n.length,r=[];for(let a=0;a<3;a++)r.push(n[(t+a)%n.length]);return r}}},Dt={class:"wm-header"},Lt={key:1,style:{width:"30px",height:"30px","flex-shrink":"0"}},$t={class:"wm-header__avatar"},Rt={class:"wm-header__main"},Ft={class:"wm-header__title"},zt={key:0,class:"wm-header__sub"},Pt={key:3,class:"wm-header__fill"},jt={class:"wm-header__actions"};function Ut(n,t,r,a,s,o){const i=e.resolveComponent("HumanAvatar"),l=e.resolveComponent("AIAvatar"),f=e.resolveComponent("TeamAvatars");return e.openBlock(),e.createElementBlock("div",Dt,[r.showBack?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-header__icon","aria-label":"Retour à l'accueil",onClick:t[0]||(t[0]=v=>n.$emit("back"))},[...t[3]||(t[3]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M19 12H5M12 5l-7 7 7 7"})],-1)])])):(e.openBlock(),e.createElementBlock("div",Lt)),r.showIdentity?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createElementVNode("div",$t,[r.escalated?(e.openBlock(),e.createBlock(i,{key:0,name:r.agentName,"avatar-url":r.agentAvatarUrl,size:34},null,8,["name","avatar-url"])):(e.openBlock(),e.createBlock(l,{key:1,size:34}))]),e.createElementVNode("div",Rt,[e.createElementVNode("div",Ft,e.toDisplayString(r.title),1),o.hasTeam?(e.openBlock(),e.createElementBlock("div",zt,[e.createVNode(f,{members:o.displayedTeamMembers,"response-label":r.responseLabel},null,8,["members","response-label"])])):e.createCommentVNode("",!0)])],64)):(e.openBlock(),e.createElementBlock("div",Pt)),e.createElementVNode("div",jt,[r.showMore?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:e.normalizeClass(["wm-header__icon",{"wm-header__icon--active":r.moreActive}]),"aria-label":"Plus d'options",title:"Plus d'options",onClick:t[1]||(t[1]=v=>n.$emit("more"))},[...t[4]||(t[4]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},[e.createElementVNode("circle",{cx:"12",cy:"5",r:"1.6"}),e.createElementVNode("circle",{cx:"12",cy:"12",r:"1.6"}),e.createElementVNode("circle",{cx:"12",cy:"19",r:"1.6"})],-1)])],2)):e.createCommentVNode("",!0),r.showClose?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-header__icon","aria-label":"Fermer le widget",title:"Fermer le widget",onClick:t[2]||(t[2]=v=>n.$emit("close"))},[...t[5]||(t[5]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])):e.createCommentVNode("",!0)])])}const pe=N(It,[["render",Ut],["__scopeId","data-v-a67a7ad8"]]),re={book:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253",changelog:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2",status:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z",chat:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z",link:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"},Ht={name:"WmOnboarding",components:{AIAvatar:z},props:{welcomeMessage:{type:String,default:""},agentName:{type:String,default:""},quickLinks:{type:Array,default:()=>[]},openThreads:{type:Array,default:()=>[]},busy:{type:Boolean,default:!1}},emits:["start","select","resume"],data(){return{query:""}},computed:{heroTitle(){return this.welcomeMessage?this.welcomeMessage:this.agentName?`Bonjour, je suis ${this.agentName}`:"Bonjour, je suis votre assistant"},heroSub(){return`Posez-moi n'importe quelle question.
53
- Je réponds en quelques secondes.`},isOddQuickLinks(){return this.quickLinks.length%2===1},quickLinksLayout(){return this.isOddQuickLinks?"wm-onb__qlist":"wm-onb__grid"},filteredThreads(){const n=this.query.trim().toLowerCase();return n?this.openThreads.filter(t=>(t.title||"").toLowerCase().includes(n)||(t.preview||"").toLowerCase().includes(n)):this.openThreads}},methods:{iconPath(n){return re[n]||re.link},formatTs(n){if(!n)return"";const t=new Date(n);if(Number.isNaN(t.getTime()))return"";const r=new Date;if(t.toDateString()===r.toDateString()){const o=String(t.getHours()).padStart(2,"0"),i=String(t.getMinutes()).padStart(2,"0");return`${o}h${i}`}if(r.getTime()-t.getTime()<7*864e5){const o=t.toLocaleDateString("fr-FR",{weekday:"short"});return o.charAt(0).toUpperCase()+o.slice(1)}return t.toLocaleDateString("fr-FR",{day:"2-digit",month:"2-digit"})}}},qt={class:"wm-onb"},Kt={class:"wm-onb__hero"},Wt={class:"wm-onb__title"},Gt={class:"wm-onb__sub"},Yt={class:"wm-onb__cta"},Jt=["disabled"],Xt={key:0,class:"wm-onb__section"},Qt=["onClick"],Zt={class:"wm-onb__card-icon"},en={width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},tn=["d"],nn={class:"wm-onb__card-body"},rn={class:"wm-onb__card-title"},on={key:0,class:"wm-onb__card-sub"},sn={key:1,class:"wm-onb__section"},an={class:"wm-onb__search"},ln={class:"wm-onb__list"},cn=["onClick"],dn={key:0,class:"wm-onb__thread-dot","aria-label":"Non lu"},un={class:"wm-onb__thread-body"},mn={class:"wm-onb__thread-title"},hn={class:"wm-onb__thread-preview"},pn={class:"wm-onb__thread-meta"},fn={key:0,class:"wm-onb__thread-time"},_n={key:0,class:"wm-onb__empty"};function gn(n,t,r,a,s,o){const i=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",qt,[e.createElementVNode("div",Kt,[e.createVNode(i,{size:56,pulse:!0}),e.createElementVNode("div",Wt,e.toDisplayString(o.heroTitle),1),e.createElementVNode("div",Gt,e.toDisplayString(o.heroSub),1)]),e.createElementVNode("div",Yt,[e.createElementVNode("button",{type:"button",class:"wm-onb__startBtn",disabled:r.busy,onClick:t[0]||(t[0]=l=>n.$emit("start"))},[t[2]||(t[2]=e.createElementVNode("span",{class:"wm-onb__startIcon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M12 5v14M5 12h14"})])],-1)),e.createElementVNode("span",null,e.toDisplayString(r.busy?"…":"Commencer une conversation"),1)],8,Jt)]),r.quickLinks.length?(e.openBlock(),e.createElementBlock("div",Xt,[t[3]||(t[3]=e.createElementVNode("div",{class:"wm-onb__section-title"},"Accès rapide",-1)),e.createElementVNode("div",{class:e.normalizeClass(o.quickLinksLayout)},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.quickLinks,(l,f)=>(e.openBlock(),e.createElementBlock("button",{key:f,type:"button",class:e.normalizeClass(["wm-onb__card",{"wm-onb__card--row":o.isOddQuickLinks}]),onClick:v=>n.$emit("select",l)},[e.createElementVNode("span",Zt,[(e.openBlock(),e.createElementBlock("svg",en,[e.createElementVNode("path",{d:o.iconPath(l.icon)},null,8,tn)]))]),e.createElementVNode("span",nn,[e.createElementVNode("span",rn,e.toDisplayString(l.label),1),l.description?(e.openBlock(),e.createElementBlock("span",on,e.toDisplayString(l.description),1)):e.createCommentVNode("",!0)])],10,Qt))),128))],2)])):e.createCommentVNode("",!0),r.openThreads.length?(e.openBlock(),e.createElementBlock("div",sn,[t[7]||(t[7]=e.createElementVNode("div",{class:"wm-onb__section-title"},"Conversations récentes",-1)),e.createElementVNode("div",an,[t[4]||(t[4]=e.createElementVNode("span",{class:"wm-onb__searchIcon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21 21l-4.35-4.35M11 17a6 6 0 100-12 6 6 0 000 12z"})])],-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[1]||(t[1]=l=>s.query=l),type:"text",placeholder:"Rechercher dans vos messages","aria-label":"Rechercher dans vos messages"},null,512),[[e.vModelText,s.query]])]),e.createElementVNode("div",ln,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.filteredThreads,l=>(e.openBlock(),e.createElementBlock("button",{key:l.id,type:"button",class:"wm-onb__thread",onClick:f=>n.$emit("resume",l)},[e.createElementVNode("span",{class:e.normalizeClass(["wm-onb__thread-icon",{"wm-onb__thread-icon--inverted":!l.unread}])},[t[5]||(t[5]=e.createElementVNode("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true"},[e.createElementVNode("path",{d:"M12 2 L13.5 9 L20 10.5 L13.5 12 L12 19 L10.5 12 L4 10.5 L10.5 9 Z",fill:"currentColor",opacity:"0.92"})],-1)),l.unread?(e.openBlock(),e.createElementBlock("span",dn)):e.createCommentVNode("",!0)],2),e.createElementVNode("span",un,[e.createElementVNode("span",mn,e.toDisplayString(l.title),1),e.createElementVNode("span",hn,e.toDisplayString(l.preview),1)]),e.createElementVNode("span",pn,[o.formatTs(l._ts)?(e.openBlock(),e.createElementBlock("span",fn,e.toDisplayString(o.formatTs(l._ts)),1)):e.createCommentVNode("",!0),t[6]||(t[6]=e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",class:"wm-onb__thread-chev","aria-hidden":"true"},[e.createElementVNode("path",{d:"M9 18l6-6-6-6"})],-1))])],8,cn))),128)),o.filteredThreads.length?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",_n," Aucun résultat pour « "+e.toDisplayString(s.query)+" ». ",1))])])):e.createCommentVNode("",!0)])}const fe=N(Ht,[["render",gn],["__scopeId","data-v-0fb4345b"]]);function vn(n){return typeof n!="string"?"":n.replace(/`([^`]+)`/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1").replace(new RegExp("(?<!\\*)\\*([^*]+)\\*(?!\\*)","g"),"$1").replace(/__([^_]+)__/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\s+/g," ").trim()}const yn={name:"WmActionResult",props:{state:{type:String,default:"success"},label:{type:String,required:!0},detail:{type:String,default:""}},computed:{detailText(){return vn(this.detail)}}},kn={class:"wm-result__icon","aria-hidden":"true"},wn={key:0,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.8","stroke-linecap":"round","stroke-linejoin":"round"},bn={key:1,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.6","stroke-linecap":"round","stroke-linejoin":"round"},En={key:2,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.4","stroke-linecap":"round","stroke-linejoin":"round"},Bn={key:3,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round"},Cn={class:"wm-result__body"},Nn={class:"wm-result__label"},Sn={class:"wm-result__detail"};function Vn(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-result",`wm-result--${r.state}`])},[e.createElementVNode("span",kn,[r.state==="success"?(e.openBlock(),e.createElementBlock("svg",wn,[...t[0]||(t[0]=[e.createElementVNode("path",{d:"M20 6L9 17l-5-5"},null,-1)])])):r.state==="rejected"?(e.openBlock(),e.createElementBlock("svg",bn,[...t[1]||(t[1]=[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"},null,-1)])])):r.state==="awaiting"?(e.openBlock(),e.createElementBlock("svg",En,[...t[2]||(t[2]=[e.createElementVNode("circle",{cx:"12",cy:"12",r:"10"},null,-1),e.createElementVNode("polyline",{points:"12 7 12 12 15 14"},null,-1)])])):(e.openBlock(),e.createElementBlock("svg",Bn,[...t[3]||(t[3]=[e.createElementVNode("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"},null,-1),e.createElementVNode("line",{x1:"12",y1:"9",x2:"12",y2:"13"},null,-1),e.createElementVNode("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"},null,-1)])]))]),e.createElementVNode("span",Cn,[e.createElementVNode("span",Nn,e.toDisplayString(r.label),1),o.detailText?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[t[4]||(t[4]=e.createElementVNode("span",{class:"wm-result__sep","aria-hidden":"true"}," · ",-1)),e.createElementVNode("span",Sn,e.toDisplayString(o.detailText),1)],64)):e.createCommentVNode("",!0)])],2)}const _e=N(yn,[["render",Vn],["__scopeId","data-v-64a83fb8"]]),An={name:"WmArtifactFormResponse",props:{data:{type:Object,required:!0}},computed:{fields(){var n;return Array.isArray((n=this.data)==null?void 0:n.fields)?this.data.fields:[]}}},Tn={class:"wm-art wm-art--formResponse"},Mn={class:"wm-art__head"},xn={class:"wm-art__title"},On={class:"wm-art__body"},In={class:"wm-art__fieldLabel"};function Dn(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Tn,[e.createElementVNode("div",Mn,[e.createElementVNode("div",xn,e.toDisplayString(r.data.title||"Formulaire"),1),t[0]||(t[0]=e.createElementVNode("span",{class:"wm-art__badge wm-art__badge--success"},[e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("polyline",{points:"20 6 9 17 4 12"})]),e.createTextVNode(" Envoyé ")],-1))]),e.createElementVNode("div",On,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.fields,(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",In,e.toDisplayString(i.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":i.multiline}])},e.toDisplayString(i.value),3)]))),128))])])}const ge=N(An,[["render",Dn],["__scopeId","data-v-ca24a9c9"]]),Ln={name:"WmArtifactInfoCard",props:{data:{type:Object,required:!0}},computed:{fields(){var n;return Array.isArray((n=this.data)==null?void 0:n.fields)?this.data.fields:[]},hasBody(){var n;return!!((n=this.data)!=null&&n.body)||this.fields.length>0}}},$n={class:"wm-art wm-art--infoCard"},Rn={key:0,class:"wm-art__image"},Fn=["src","alt"],zn={class:"wm-art__head"},Pn={class:"wm-art__headMain"},jn={class:"wm-art__title"},Un={key:0,class:"wm-art__subtitle"},Hn={key:1,class:"wm-art__body"},qn={key:0,class:"wm-art__text"},Kn={class:"wm-art__fieldLabel"};function Wn(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",$n,[r.data.image_url?(e.openBlock(),e.createElementBlock("figure",Rn,[e.createElementVNode("img",{src:r.data.image_url,alt:r.data.title||"",loading:"lazy"},null,8,Fn)])):e.createCommentVNode("",!0),e.createElementVNode("div",zn,[e.createElementVNode("div",Pn,[e.createElementVNode("div",jn,e.toDisplayString(r.data.title),1),r.data.subtitle?(e.openBlock(),e.createElementBlock("div",Un,e.toDisplayString(r.data.subtitle),1)):e.createCommentVNode("",!0)]),r.data.badge&&r.data.badge.label?(e.openBlock(),e.createElementBlock("span",{key:0,class:e.normalizeClass(["wm-art__badge",`wm-art__badge--${r.data.badge.tone||"neutral"}`])},e.toDisplayString(r.data.badge.label),3)):e.createCommentVNode("",!0)]),o.hasBody?(e.openBlock(),e.createElementBlock("div",Hn,[r.data.body?(e.openBlock(),e.createElementBlock("div",qn,e.toDisplayString(r.data.body),1)):e.createCommentVNode("",!0),o.fields.length?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(o.fields,(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",Kn,e.toDisplayString(i.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":i.multiline}])},e.toDisplayString(i.value),3)]))),128)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])}const ve=N(Ln,[["render",Wn],["__scopeId","data-v-d7369333"]]);function Gn(n){if(!n)return"";const t=new Date(n);if(Number.isNaN(t.getTime()))return n;const r=t.toLocaleDateString("fr-FR",{day:"numeric",month:"long",year:"numeric"}),a=t.toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit"});return`${r} à ${a}`}const Yn={name:"WmArtifactTicket",props:{data:{type:Object,required:!0}},computed:{fields(){var n;return Array.isArray((n=this.data)==null?void 0:n.fields)?this.data.fields:[]},formattedDate(){var n;return Gn((n=this.data)==null?void 0:n.created_at)}},methods:{isPriority(n){return/priorit|^prio$/i.test(String(n||"").trim())},isDate(n){return/date|échéanc|echeanc|deadline|due|créé|cree/i.test(String(n||"").trim())},priorityLevel(n){const t=String(n||"").toLowerCase();return/high|haute|élev|elev|critic|critiq|urgent/.test(t)?3:/low|basse|faible|minor/.test(t)?1:2}}},Jn={class:"wm-art wm-art--ticket"},Xn={class:"wm-art__head wm-tk__head"},Qn={class:"wm-art__title wm-tk__title"},Zn={class:"wm-tk__sub"},er={class:"wm-tk__ref"},tr={key:0,class:"wm-tk__text"},nr={key:0,class:"wm-art__body"},rr={class:"wm-art__fieldLabel"},or=["data-level"],sr={key:1,class:"wm-tk__date",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},ar={key:1,class:"wm-art__footer wm-tk__footer"};function ir(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Jn,[e.createElementVNode("div",Xn,[e.createElementVNode("div",Qn,e.toDisplayString(r.data.title),1),e.createElementVNode("div",Zn,[e.createElementVNode("div",er,[t[0]||(t[0]=e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M20 12a2 2 0 0 1 2-2V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v4a2 2 0 0 1 0 4v4a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-4a2 2 0 0 1-2-2z"}),e.createElementVNode("path",{d:"M13 5v2M13 17v2M13 11v2"})],-1)),e.createElementVNode("span",null,e.toDisplayString(r.data.reference),1)]),e.createElementVNode("span",{class:e.normalizeClass(["wm-art__badge","wm-tk__badge",`wm-art__badge--${r.data.status.tone||"neutral"}`])},[t[1]||(t[1]=e.createElementVNode("span",{class:"wm-tk__dot","aria-hidden":"true"},null,-1)),e.createTextVNode(" "+e.toDisplayString(r.data.status.label),1)],2)]),r.data.body?(e.openBlock(),e.createElementBlock("div",tr,e.toDisplayString(r.data.body),1)):e.createCommentVNode("",!0)]),o.fields.length?(e.openBlock(),e.createElementBlock("div",nr,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.fields,(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",rr,e.toDisplayString(i.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":i.multiline}])},[o.isPriority(i.label)?(e.openBlock(),e.createElementBlock("svg",{key:0,class:"wm-tk__prio","data-level":o.priorityLevel(i.value),width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true"},[...t[2]||(t[2]=[e.createElementVNode("rect",{x:"1",y:"8",width:"2",height:"3",rx:"0.5"},null,-1),e.createElementVNode("rect",{x:"5",y:"5",width:"2",height:"6",rx:"0.5"},null,-1),e.createElementVNode("rect",{x:"9",y:"2",width:"2",height:"9",rx:"0.5"},null,-1)])],8,or)):o.isDate(i.label)?(e.openBlock(),e.createElementBlock("svg",sr,[...t[3]||(t[3]=[e.createElementVNode("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"},null,-1),e.createElementVNode("path",{d:"M16 2v4M8 2v4M3 10h18"},null,-1)])])):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(i.value),1)],2)]))),128))])):e.createCommentVNode("",!0),r.data.created_at?(e.openBlock(),e.createElementBlock("div",ar,[t[4]||(t[4]=e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),e.createElementVNode("path",{d:"M16 2v4M8 2v4M3 10h18"})],-1)),e.createElementVNode("span",null,e.toDisplayString(o.formattedDate),1)])):e.createCommentVNode("",!0)])}const ye=N(Yn,[["render",ir],["__scopeId","data-v-8b274eb7"]]),lr={form_response:ge,info_card:ve,ticket:ye},cr={name:"WmArtifactRenderer",props:{artifact:{type:Object,required:!0}},computed:{component(){var t;const n=(t=this.artifact)==null?void 0:t.kind;return n&&lr[n]||null}}};function dr(n,t,r,a,s,o){return o.component?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.component),{key:0,data:r.artifact.data},null,8,["data"])):e.createCommentVNode("",!0)}const ke=N(cr,[["render",dr]]),ur={name:"WmAttachmentPreview",inject:{signAttachmentFn:{default:null}},props:{attachment:{type:Object,required:!0}},data(){return{url:null,loading:!1}},computed:{kind(){var r,a;const n=(r=this.attachment)==null?void 0:r.type;if(n)return n;const t=(((a=this.attachment)==null?void 0:a.mime_type)||"").toLowerCase();return t.startsWith("image/")?"image":t.startsWith("audio/")?"audio":t.startsWith("video/")?"video":"file"},displayName(){var n,t,r;return((t=(n=this.attachment)==null?void 0:n.metadata)==null?void 0:t.name)||((r=this.attachment)==null?void 0:r.name)||this.guessNameFromPath()||"Pièce jointe"},sizeLabel(){var t;const n=(t=this.attachment)==null?void 0:t.size_bytes;return n?n<1024?`${n} o`:n<1024*1024?`${(n/1024).toFixed(0)} ko`:`${(n/(1024*1024)).toFixed(1)} Mo`:""}},watch:{"attachment.path":{handler(){this.refresh()},immediate:!0}},methods:{guessNameFromPath(){var r;return((((r=this.attachment)==null?void 0:r.path)||"").split("/").pop()||"").replace(/^[0-9a-f-]{8,}-/,"")},async refresh(){var n;if(!(!((n=this.attachment)!=null&&n.path)||!this.signAttachmentFn)){this.loading=!0;try{this.url=await this.signAttachmentFn(this.attachment.path)}finally{this.loading=!1}}},onFileClick(n){this.url||n.preventDefault()}}},mr=["href"],hr=["src","alt"],pr=["src"],fr=["src"],_r=["href","download"],gr={class:"wm-att__main"},vr={class:"wm-att__name"},yr={key:0,class:"wm-att__meta"},kr={key:0,class:"wm-att__spin","aria-hidden":"true"};function wr(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-att",["wm-att--"+(o.kind||"file")]])},[o.kind==="image"&&s.url?(e.openBlock(),e.createElementBlock("a",{key:0,href:s.url,target:"_blank",rel:"noopener",class:"wm-att__imgWrap"},[e.createElementVNode("img",{src:s.url,alt:o.displayName,loading:"lazy"},null,8,hr)],8,mr)):o.kind==="audio"&&s.url?(e.openBlock(),e.createElementBlock("audio",{key:1,src:s.url,controls:"",preload:"metadata"},null,8,pr)):o.kind==="video"&&s.url?(e.openBlock(),e.createElementBlock("video",{key:2,src:s.url,controls:"",preload:"metadata"},null,8,fr)):(e.openBlock(),e.createElementBlock("a",{key:3,class:"wm-att__file",href:s.url||"#",download:o.displayName,target:"_blank",rel:"noopener",onClick:t[0]||(t[0]=(...i)=>o.onFileClick&&o.onFileClick(...i))},[t[1]||(t[1]=e.createElementVNode("span",{class:"wm-att__icon"},[e.createElementVNode("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.createElementVNode("path",{d:"M14 2v6h6"})])],-1)),e.createElementVNode("span",gr,[e.createElementVNode("span",vr,e.toDisplayString(o.displayName),1),o.sizeLabel?(e.openBlock(),e.createElementBlock("span",yr,e.toDisplayString(o.sizeLabel),1)):e.createCommentVNode("",!0)]),s.loading?(e.openBlock(),e.createElementBlock("span",kr)):e.createCommentVNode("",!0)],8,_r))],2)}const we=N(ur,[["render",wr],["__scopeId","data-v-1cd1267b"]]);function br(n){return String(n).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Er(n){return/^(https?:\/\/|mailto:|tel:)/i.test(String(n).trim())}const oe="";function H(n){let t=n;const r=[];return t=t.replace(/`([^`\n]+)`/g,(a,s)=>{const o=r.length;return r.push(s),`${oe}CODE${o}${oe}`}),t=t.replace(/\[([^\]\n]+)\]\(([^)\s]+)\)/g,(a,s,o)=>Er(o)?`<a href="${o}" target="_blank" rel="noopener noreferrer">${s}</a>`:s),t=t.replace(/\*\*([^\n*][^\n]*?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/__([^\n_][^\n]*?)__/g,"<u>$1</u>"),t=t.replace(/~~([^\n~][^\n]*?)~~/g,"<s>$1</s>"),t=t.replace(/(^|[^\w*])\*([^\n*]+?)\*(?!\w)/g,"$1<em>$2</em>"),t=t.replace(/(^|[^\w_])_([^\n_]+?)_(?!\w)/g,"$1<em>$2</em>"),t=t.replace(/CODE(\d+)/g,(a,s)=>`<code class="wm-md-code">${r[+s]}</code>`),t}function be(n){if(!n)return"";const t=br(n).split(`
54
- `),r=[];let a=0;for(;a<t.length;){const o=t[a];if(/^\s*```([\w-]*)\s*$/.exec(o)){a++;const v=[];for(;a<t.length&&!/^\s*```\s*$/.test(t[a]);)v.push(t[a]),a++;a<t.length&&a++,r.push({type:"block",html:`<pre class="wm-md-pre"><code>${v.join(`
55
- `)}</code></pre>`});continue}if(/^\s*[-*]\s+/.test(o)){const v=[];for(;a<t.length;){const b=/^\s*[-*]\s+(.*)$/.exec(t[a]);if(!b)break;v.push(b[1]),a++}const y=v.map(b=>`<li>${H(b)}</li>`).join("");r.push({type:"block",html:`<ul class="wm-md-ul">${y}</ul>`});continue}const l=/^\s*(\d+)\.\s+(.*)$/.exec(o);if(l){const v=parseInt(l[1],10),y=[l[2]];for(a++;a<t.length;){const k=/^\s*\d+\.\s+(.*)$/.exec(t[a]);if(!k)break;y.push(k[1]),a++}const b=y.map(k=>`<li>${H(k)}</li>`).join(""),S=v!==1?` start="${v}"`:"";r.push({type:"block",html:`<ol class="wm-md-ol"${S}>${b}</ol>`});continue}const f=/^(#{1,6})\s+(.*)$/.exec(o);if(f){const v=f[1].length;r.push({type:"block",html:`<h${v} class="wm-md-h wm-md-h${v}">${H(f[2])}</h${v}>`}),a++;continue}r.push({type:"text",html:H(o)}),a++}let s="";for(let o=0;o<r.length;o++){const i=r[o];s+=i.html;const l=r[o+1];l&&i.type!=="block"&&l.type!=="block"&&(s+=`
56
- `)}return s}const Br={name:"WmBubble",props:{role:{type:String,default:"ai"},text:{type:String,default:""}},computed:{rendered(){return be(this.text)}}},Cr=["innerHTML"];function Nr(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-bubble","wm-bubble--"+r.role])},[e.renderSlot(n.$slots,"default",{},()=>[e.createElementVNode("span",{innerHTML:o.rendered},null,8,Cr)],!0)],2)}const Ee=N(Br,[["render",Nr],["__scopeId","data-v-5c9e9f2b"]]),Sr={name:"WmTyping"},Vr={class:"wm-typing"};function Ar(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Vr,[...t[0]||(t[0]=[e.createElementVNode("span",{style:{"animation-delay":"0s"}},null,-1),e.createElementVNode("span",{style:{"animation-delay":"0.2s"}},null,-1),e.createElementVNode("span",{style:{"animation-delay":"0.4s"}},null,-1)])])}const Be=N(Sr,[["render",Ar],["__scopeId","data-v-df2447fd"]]);function P(n){return n?n.client_msg_id||n.id:""}const Tr={transferred_to_human:"Conversation transférée à un humain",assigned:"{name} a rejoint la conversation",unassigned:"L'agent a quitté la conversation",resolved:"Conversation résolue",reopened:"Conversation rouverte",idle:"Conversation en pause"},Mr=80,xr=200,Or={name:"WmMessageList",components:{AIAvatar:z,HumanAvatar:G,Bubble:Ee,Typing:Be,ActionResult:_e,AttachmentPreview:we,ArtifactRenderer:ke},props:{messages:{type:Array,default:()=>[]},streamingActive:{type:Boolean,default:!1},dateLabel:{type:String,default:""},conversationId:{type:[String,Number],default:null},loadingMore:{type:Boolean,default:!1},hasMore:{type:Boolean,default:!1},unreadAnchorTs:{type:String,default:""},unreadBoundaryTs:{type:String,default:""}},emits:["load-more"],data(){return{silentFades:!1,widthByKey:Object.freeze({})}},computed:{historyExhausted(){return!this.hasMore&&!this.loadingMore&&this.messages.length>=20},groups(){var r,a,s,o;const n=[];for(const i of this.messages){const l=this.roleOf(i);if(l==="system"){if(((r=i==null?void 0:i.payload)==null?void 0:r.event)==="action_admin_pending"){const y=n[n.length-1];y&&y.role==="ai"?y.messages.push(i):n.push({key:`g-${P(i)}`,role:"ai",agentName:"",agentAvatarUrl:null,messages:[i],items:[]});continue}n.push({key:`sys-${P(i)}`,role:l,messages:[i],items:[],systemLabel:this.systemLabel(i)});continue}const f=n[n.length-1];f&&f.role===l&&(l==="ai"||f.agentName===(((a=i==null?void 0:i.author)==null?void 0:a.name)||""))?f.messages.push(i):n.push({key:`g-${P(i)}`,role:l,agentName:((s=i==null?void 0:i.author)==null?void 0:s.name)||"",agentAvatarUrl:((o=i==null?void 0:i.author)==null?void 0:o.avatar_url)||null,messages:[i],items:[]})}for(const i of n){if(i.role==="system")continue;const l=[];for(const f of i.messages)for(const v of this.itemsOf(f))l.push(v);i.items=l}const t=[];for(const i of n){if(i.role!=="system"&&!i.items.length)continue;const l=t[t.length-1];if(l&&l.role!=="system"&&l.role===i.role&&(i.role==="ai"||l.agentName===i.agentName)){l.messages.push(...i.messages),l.items.push(...i.items);continue}t.push(i)}return t},unreadGroupKey(){if(!this.unreadAnchorTs)return null;for(const n of this.groups){if(n.role==="user"||n.role==="system"||!n.items.length)continue;const t=n.messages[0];if(t!=null&&t.created_at&&!(t.created_at<=this.unreadAnchorTs)&&!(this.unreadBoundaryTs&&t.created_at>this.unreadBoundaryTs))return n.key}return null}},watch:{messages:{handler:"snapshotAndRestore",deep:!0},loadingMore(n){n||(this._pendingLoadMore=!1),this.silentFades=!0,clearTimeout(this._silenceTimer),n||(this._silenceTimer=setTimeout(()=>{this.silentFades=!1},250)),this.snapshotAndRestore()},streamingActive:"snapshotAndRestore"},mounted(){this._lastSeenConvId=this.conversationId,this.scrollToBottom(),this._measureFrame=null,this._ro=new ResizeObserver(()=>this.scheduleMeasure()),this.$refs.scrollEl&&this._ro.observe(this.$refs.scrollEl),this.$nextTick(()=>this.measureRows())},beforeUnmount(){var n;(n=this._ro)==null||n.disconnect(),this._measureFrame&&cancelAnimationFrame(this._measureFrame),clearTimeout(this._silenceTimer)},updated(){this.scheduleMeasure()},methods:{messageKey:P,isAtBottom(n){return n.scrollHeight-n.scrollTop-n.clientHeight<=Mr},onScroll(){const n=this.$refs.scrollEl;n&&(this.loadingMore||!this.hasMore||this._pendingLoadMore||n.scrollTop<=xr&&(this._pendingLoadMore=!0,this.$emit("load-more")))},snapshotAndRestore(){const n=this.$refs.scrollEl;if(!n||this._scrollSnap)return;const t=this._lastSeenConvId!==this.conversationId;this._lastSeenConvId=this.conversationId;const r=this.isAtBottom(n);let a=null;if(!t&&!r){const o=this.pickAnchor(n);if(o!=null&&o.el){const i=n.getBoundingClientRect().top;a={el:o.el,relY:o.el.getBoundingClientRect().top-i}}}const s={forceBottom:t,wasPinned:r,anchor:a};this._scrollSnap=s,this.$nextTick(()=>{if(this._scrollSnap=null,s.forceBottom||s.wasPinned){n.scrollTop=n.scrollHeight;return}if(!s.anchor)return;const o=()=>{var v;const i=s.anchor;if(!((v=i.el)!=null&&v.isConnected))return;const f=i.el.getBoundingClientRect().top-n.getBoundingClientRect().top-i.relY;Math.abs(f)>.5&&(n.scrollTop+=f)};o(),requestAnimationFrame(()=>{o(),requestAnimationFrame(o)})})},pickAnchor(n){const t=n.scrollTop;let r=null;for(const a of n.children)if(a.classList.contains("wm-list__group")&&(r||(r=a),a.offsetTop+a.offsetHeight>=t))return{el:a,offsetTop:a.offsetTop};return r?{el:r,offsetTop:r.offsetTop}:null},roleOf(n){var r,a;if((n==null?void 0:n.type)==="system"||((r=n==null?void 0:n.payload)==null?void 0:r.type)==="system")return"system";const t=(a=n==null?void 0:n.author)==null?void 0:a.type;return t==="user"?"user":t==="agent_human"?"human":"ai"},roleLabel(n){return n.role==="human"?n.agentName||"Agent":"Assistant IA"},itemsOf(n){var t;if(!n)return[];if(n.type==="system"&&((t=n==null?void 0:n.payload)==null?void 0:t.event)==="action_admin_pending")return[{message:n,partKey:"main",renderAs:"admin-pending",kind:{top:"bubble",bottom:"bubble"}}];if(n.type==="action"&&n.payload&&n.payload.state!=="pending"){const r=[{message:n,partKey:"main",renderAs:"action",kind:{top:"bubble",bottom:"bubble"}}];return this.actionArtifact(n)&&r.push({message:n,partKey:"artifact",renderAs:"artifact-of-action",kind:{top:"card",bottom:"card"}}),r}return this.artifactOf(n)?[{message:n,partKey:"main",renderAs:"artifact",kind:{top:"card",bottom:"card"}}]:n.text_md||this.attachmentsOf(n).length?[{message:n,partKey:"main",renderAs:"bubble",kind:{top:"bubble",bottom:"bubble"}}]:[]},cornersFor(n,t){var $,I,F;const r=n.items,a=($=r[t])==null?void 0:$.kind,s=(I=r[t-1])==null?void 0:I.kind,o=(F=r[t+1])==null?void 0:F.kind,i=n.role==="user",l=14,f=4,v=s==null?void 0:s.bottom,y=o==null?void 0:o.top,b=this.widthByKey[this.rowKeyOf(n,t)],S=this.widthByKey[this.rowKeyOf(n,t-1)],k=this.widthByKey[this.rowKeyOf(n,t+1)],A=.5,w=(L,D,R)=>L!=null&&b!=null?L+A>=b:D===R||D==="card"&&R==="bubble";let M=l,x=l,V=l,O=l;return i?(v&&(x=f),(y||!o)&&(V=f),v&&w(S,v,a==null?void 0:a.top)&&(M=f),y&&w(k,y,a==null?void 0:a.bottom)&&(O=f)):(v&&(M=f),(y||!o)&&(O=f),v&&w(S,v,a==null?void 0:a.top)&&(x=f),y&&w(k,y,a==null?void 0:a.bottom)&&(V=f)),{tl:M,tr:x,br:V,bl:O}},cornersStyle(n,t){if(n.items.length<2)return null;const r=this.cornersFor(n,t);return{"--wm-r-tl":`${r.tl}px`,"--wm-r-tr":`${r.tr}px`,"--wm-r-br":`${r.br}px`,"--wm-r-bl":`${r.bl}px`}},rowKeyOf(n,t){var a;const r=(a=n==null?void 0:n.items)==null?void 0:a[t];return r?`${P(r.message)}-${r.partKey}`:""},scheduleMeasure(){this._measureFrame||(this._measureFrame=requestAnimationFrame(()=>{this._measureFrame=null,this.measureRows()}))},measureRows(){const n=this.$refs.scrollEl;if(!n)return;const t={};for(const o of n.querySelectorAll(".wm-list__row[data-row-key]")){const i=o.dataset.rowKey;if(!i)continue;const l=o.querySelector(".wm-bubble, .wm-result, .wm-art, .wm-list__body");if(!l)continue;const f=l.getBoundingClientRect().width;f>0&&(t[i]=f)}const r=this.widthByKey,a=Object.keys(r),s=Object.keys(t);if(a.length===s.length){let o=!0;for(const i of s)if(Math.abs((r[i]??0)-t[i])>.5){o=!1;break}if(o)return}this.widthByKey=Object.freeze(t)},lastTimeOf(n){const t=n.items[n.items.length-1],r=(t==null?void 0:t.message)||n.messages[n.messages.length-1];if(!(r!=null&&r.created_at))return"";try{return ee(new Date(r.created_at))}catch{return""}},hasTrailingOverlay(n){if(!n.messages.length)return!1;const t=n.messages[n.messages.length-1],r=n.items[n.items.length-1];return!!t&&(r==null?void 0:r.message)!==t},attachmentsOf(n){var r;const t=(r=n==null?void 0:n.payload)==null?void 0:r.attachments;return Array.isArray(t)?t:[]},artifactOf(n){var r;const t=(r=n==null?void 0:n.metadata)==null?void 0:r.artifact;return!t||typeof t!="object"||typeof t.kind!="string"?null:t},actionLabel(n){var t;return((t=n==null?void 0:n.payload)==null?void 0:t.name)||(n==null?void 0:n.text_md)||"Action"},actionDetail(n){var r,a,s,o,i,l;const t=n==null?void 0:n.payload;return t?t.state==="success"?((r=t.success)==null?void 0:r.summary)||((s=(a=t.success)==null?void 0:a.metadata)==null?void 0:s.description)||"":t.state==="rejected"?((o=t.rejected)==null?void 0:o.reason)||"Action annulée par l'utilisateur.":t.state==="failure"&&(((i=t.failure)==null?void 0:i.summary)||((l=t.failure)==null?void 0:l.error))||"":""},actionArtifact(n){var r,a;const t=(a=(r=n==null?void 0:n.payload)==null?void 0:r.success)==null?void 0:a.artifact;return!t||typeof t!="object"||typeof t.kind!="string"?null:t},systemLabel(n){var s,o,i;const t=(s=n==null?void 0:n.payload)==null?void 0:s.event,r=Tr[t]||(n==null?void 0:n.text_md)||"Mise à jour de la conversation",a=((o=n==null?void 0:n.metadata)==null?void 0:o.agent_name)||((i=n==null?void 0:n.author)==null?void 0:i.name)||"";return r.replace("{name}",a||"Un agent")},scrollToBottom(){const n=this.$refs.scrollEl;n&&(n.scrollTop=n.scrollHeight)}}},Ir={key:0,class:"wm-list__loadMore",role:"status","aria-live":"polite"},Dr={key:1,class:"wm-list__historyEnd"},Lr={key:2,class:"wm-list__sep"},$r={class:"wm-list__sep-label"},Rr={key:0,class:"wm-list__sep wm-list__sep--unread"},Fr={key:0,class:"wm-list__sysep"},zr={class:"wm-list__sysep-label"},Pr=["data-row-key"],jr={key:0,class:"wm-list__avatarSlot"},Ur={key:5,class:"wm-list__body"},Hr={key:0},qr={key:1,"aria-hidden":"true"},Kr={key:2},Wr={key:3,class:"wm-list__row wm-list__row--ai fade-up"},Gr={class:"wm-list__avatarSlot"};function Yr(n,t,r,a,s,o){const i=e.resolveComponent("AIAvatar"),l=e.resolveComponent("HumanAvatar"),f=e.resolveComponent("ActionResult"),v=e.resolveComponent("ArtifactRenderer"),y=e.resolveComponent("Bubble"),b=e.resolveComponent("AttachmentPreview"),S=e.resolveComponent("Typing");return e.openBlock(),e.createElementBlock("div",{ref:"scrollEl",class:e.normalizeClass(["wm-list",{"wm-list--silent":s.silentFades}]),onScrollPassive:t[0]||(t[0]=(...k)=>o.onScroll&&o.onScroll(...k))},[r.loadingMore?(e.openBlock(),e.createElementBlock("div",Ir,[...t[1]||(t[1]=[e.createElementVNode("span",{class:"wm-list__loadMore-spinner","aria-hidden":"true"},null,-1),e.createElementVNode("span",{class:"wm-list__loadMore-lbl"},"Chargement de l'historique…",-1)])])):o.historyExhausted?(e.openBlock(),e.createElementBlock("div",Dr,"Début de la conversation")):e.createCommentVNode("",!0),r.dateLabel?(e.openBlock(),e.createElementBlock("div",Lr,[t[2]||(t[2]=e.createElementVNode("div",{class:"wm-list__line"},null,-1)),e.createElementVNode("span",$r,e.toDisplayString(r.dateLabel),1),t[3]||(t[3]=e.createElementVNode("div",{class:"wm-list__line"},null,-1))])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.groups,(k,A)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:k.key},[k.key===o.unreadGroupKey?(e.openBlock(),e.createElementBlock("div",Rr,[...t[4]||(t[4]=[e.createElementVNode("div",{class:"wm-list__line wm-list__line--unread"},null,-1),e.createElementVNode("span",{class:"wm-list__sep-label wm-list__sep-label--unread"},"Non lus",-1),e.createElementVNode("div",{class:"wm-list__line wm-list__line--unread"},null,-1)])])):e.createCommentVNode("",!0),k.role==="system"||k.items.length?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["wm-list__group","wm-list__group--"+k.role])},[k.role==="system"?(e.openBlock(),e.createElementBlock("div",Fr,[t[5]||(t[5]=e.createElementVNode("div",{class:"wm-list__line wm-list__line--strong"},null,-1)),e.createElementVNode("span",zr,e.toDisplayString(k.systemLabel),1),t[6]||(t[6]=e.createElementVNode("div",{class:"wm-list__line wm-list__line--strong"},null,-1))])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(k.items,(w,M)=>(e.openBlock(),e.createElementBlock("div",{key:`${o.messageKey(w.message)}-${w.partKey}`,"data-row-key":`${o.messageKey(w.message)}-${w.partKey}`,class:e.normalizeClass(["wm-list__row fade-up",["wm-list__row--"+k.role,{"is-pending":w.message._pending,"is-failed":w.message._failed}]]),style:e.normalizeStyle(o.cornersStyle(k,M))},[k.role!=="user"?(e.openBlock(),e.createElementBlock("div",jr,[M===k.items.length-1?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[k.role==="ai"?(e.openBlock(),e.createBlock(i,{key:0,size:26,tail:!0})):(e.openBlock(),e.createBlock(l,{key:1,name:k.agentName,"avatar-url":k.agentAvatarUrl,size:26,tail:!0},null,8,["name","avatar-url"]))],64)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),w.renderAs==="action"?(e.openBlock(),e.createBlock(f,{key:1,state:w.message.payload.state,label:o.actionLabel(w.message),detail:o.actionDetail(w.message)},null,8,["state","label","detail"])):w.renderAs==="admin-pending"?(e.openBlock(),e.createBlock(f,{key:2,state:"awaiting",label:"Demande d'approbation envoyée",detail:w.message.text_md||""},null,8,["detail"])):w.renderAs==="artifact-of-action"?(e.openBlock(),e.createBlock(v,{key:3,artifact:o.actionArtifact(w.message)},null,8,["artifact"])):w.renderAs==="artifact"?(e.openBlock(),e.createBlock(v,{key:4,artifact:o.artifactOf(w.message)},null,8,["artifact"])):(e.openBlock(),e.createElementBlock("div",Ur,[w.message.text_md?(e.openBlock(),e.createBlock(y,{key:0,role:k.role,text:w.message.text_md},null,8,["role","text"])):e.createCommentVNode("",!0),o.attachmentsOf(w.message).length?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["wm-list__atts",{"wm-list__atts--align-end":k.role==="user"}])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.attachmentsOf(w.message),(x,V)=>(e.openBlock(),e.createBlock(b,{key:`${o.messageKey(w.message)}-att-${V}`,attachment:x},null,8,["attachment"]))),128))],2)):e.createCommentVNode("",!0)]))],14,Pr))),128)),(k.role!=="user"||o.lastTimeOf(k))&&!o.hasTrailingOverlay(k)?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["wm-list__meta",{"wm-list__meta--right":k.role==="user"}])},[k.role!=="user"?(e.openBlock(),e.createElementBlock("span",Hr,e.toDisplayString(o.roleLabel(k)),1)):e.createCommentVNode("",!0),k.role!=="user"&&o.lastTimeOf(k)?(e.openBlock(),e.createElementBlock("span",qr,"·")):e.createCommentVNode("",!0),o.lastTimeOf(k)?(e.openBlock(),e.createElementBlock("span",Kr,e.toDisplayString(o.lastTimeOf(k)),1)):e.createCommentVNode("",!0)],2)):e.createCommentVNode("",!0)],64))],2)):e.createCommentVNode("",!0)],64))),128)),r.streamingActive?(e.openBlock(),e.createElementBlock("div",Wr,[e.createElementVNode("div",Gr,[e.createVNode(i,{size:26,tail:!0})]),e.createVNode(S)])):e.createCommentVNode("",!0)],34)}const Ce=N(Or,[["render",Yr],["__scopeId","data-v-21381fcb"]]),j=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",Y=typeof window<"u"&&typeof window.MediaRecorder<"u";function Ne(){return Y&&["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(t=>{var r,a;return(a=(r=window.MediaRecorder).isTypeSupported)==null?void 0:a.call(r,t)})||""}function Se({audio:n}){return{video:!0,audio:!!n,selfBrowserSurface:"include",surfaceSwitching:"include",systemAudio:n?"include":"exclude"}}function Jr(n){return n?n.startsWith("image/")?"image":n.startsWith("video/")?"video":"file":"file"}async function Ve(){if(!j)return null;let n;try{n=await navigator.mediaDevices.getDisplayMedia(Se({audio:!1}))}catch(t){return(t==null?void 0:t.name)!=="NotAllowedError"&&console.error("[media] screenshot picker",t),null}try{return await Xr(n)}catch(t){return console.error("[media] screenshot capture",t),null}finally{n.getTracks().forEach(t=>{t.stop()})}}async function Xr(n){const t=document.createElement("video");t.muted=!0,t.playsInline=!0,t.srcObject=n,await t.play(),await new Promise(l=>requestAnimationFrame(l));const r=t.videoWidth||1280,a=t.videoHeight||720,s=document.createElement("canvas");s.width=r,s.height=a,s.getContext("2d").drawImage(t,0,0,r,a);const o=await new Promise((l,f)=>{s.toBlob(v=>v?l(v):f(new Error("toBlob failed")),"image/png")}),i=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);return new File([o],`capture-${i}.png`,{type:"image/png"})}async function Ae(n={}){var v;if(!j||!Y)return null;let t;try{t=await navigator.mediaDevices.getDisplayMedia(Se({audio:!0}))}catch(y){return(y==null?void 0:y.name)!=="NotAllowedError"&&console.error("[media] record picker",y),null}const r=Ne();let a;try{a=r?new window.MediaRecorder(t,{mimeType:r}):new window.MediaRecorder(t)}catch(y){return console.error("[media] recorder init",y),t.getTracks().forEach(b=>{b.stop()}),null}const s=[];let o=null,i=!1;a.addEventListener("dataavailable",y=>{y.data&&y.data.size>0&&s.push(y.data)}),a.addEventListener("stop",()=>{var y,b;if(o&&clearInterval(o),t.getTracks().forEach(S=>{S.stop()}),s.length){const S=a.mimeType||r||"video/webm",k=new Blob(s,{type:S}),A=/mp4/.test(S)?"mp4":"webm",w=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),M=new File([k],`ecran-${w}.${A}`,{type:S});(y=n.onfinalize)==null||y.call(n,M)}else(b=n.oncancel)==null||b.call(n)}),t.getVideoTracks().forEach(y=>{y.addEventListener("ended",()=>l(),{once:!0})});function l(){if(!i&&(i=!0,a.state!=="inactive"))try{a.stop()}catch(y){console.error("[media] recorder stop",y)}}try{a.start(1e3)}catch(y){return console.error("[media] recorder start",y),t.getTracks().forEach(b=>{b.stop()}),null}(v=n.onstart)==null||v.call(n);const f=Date.now();return o=setInterval(()=>{var y;(y=n.ontick)==null||y.call(n,Date.now()-f)},500),{stop:l,get state(){return a.state}}}const Qr=[{action:"file",label:"Joindre un fichier",path:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"},{action:"screenshot",label:"Capture d'écran",path:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z M12 17a4 4 0 100-8 4 4 0 000 8z"},{action:"record",label:"Enregistrer l'écran",path:"M23 7l-7 5 7 5V7z M1 5a2 2 0 012-2h12a2 2 0 012 2v14a2 2 0 01-2 2H3a2 2 0 01-2-2V5z"}],Zr={name:"WmComposer",props:{modelValue:{type:String,default:""},placeholder:{type:String,default:"Écrivez votre message…"},disabled:{type:Boolean,default:!1},attachLabel:{type:String,default:"Joindre"}},emits:["update:modelValue","send","attach"],data(){return{local:this.modelValue,attachOpen:!1,recording:!1,recordingElapsed:0,recorder:null}},computed:{canSend(){return!this.disabled&&!!this.local.trim()},attachItems(){return Qr.map(n=>({...n,disabled:n.action==="screenshot"&&!j||n.action==="record"&&(!j||!Y)}))},recordingElapsedLabel(){const n=Math.floor(this.recordingElapsed/1e3),t=Math.floor(n/60),r=n%60;return`${t}:${r.toString().padStart(2,"0")}`}},watch:{modelValue(n){n!==this.local&&(this.local=n,this.$nextTick(()=>this.autosize()))},local(n){this.$emit("update:modelValue",n)}},mounted(){this.autosize()},beforeUnmount(){if(this.recorder)try{this.recorder.stop()}catch{}},methods:{focus(){const n=this.$refs.inputEl;if(!(!n||this.disabled))try{n.focus({preventScroll:!0})}catch{n.focus()}},onSubmit(){if(!this.canSend)return;const n=this.local.trim();this.local="",this.$emit("send",n),this.$nextTick(()=>this.autosize())},onKeydown(n){n.key==="Enter"&&!n.shiftKey&&!n.ctrlKey&&!n.metaKey&&!n.isComposing&&(n.preventDefault(),this.onSubmit())},autosize(){const n=this.$refs.inputEl;n&&(n.style.height="auto",n.style.height=`${n.scrollHeight}px`)},onFile(n){const t=Array.from(n.target.files||[]);for(const r of t)this.$emit("attach",r);n.target.value=""},onAttachAction(n){this.attachOpen=!1,n==="file"?this.pickFile():n==="screenshot"?this.captureScreenshot():n==="record"&&this.startRecording()},pickFile(){var n;(n=this.$refs.fileEl)==null||n.click()},async captureScreenshot(){if(this.disabled)return;const n=await Ve();n&&this.$emit("attach",n)},async startRecording(){if(this.recording||this.disabled)return;this.recordingElapsed=0;const n=await Ae({onstart:()=>{this.recording=!0},ontick:t=>{this.recordingElapsed=t},onfinalize:t=>{this.$emit("attach",t),this.recording=!1,this.recordingElapsed=0,this.recorder=null},oncancel:()=>{this.recording=!1,this.recordingElapsed=0,this.recorder=null}});n&&(this.recorder=n)},stopRecording(){if(this.recorder)try{this.recorder.stop()}catch(n){console.error("[composer] stop recording",n)}}}},eo={class:"wm-compose-wrap"},to={key:0,class:"wm-rec"},no={class:"wm-rec__lbl"},ro={key:1,class:"wm-compose__menu",role:"menu"},oo=["disabled","onClick"],so={class:"wm-compose__menuIcon"},ao={viewBox:"0 0 24 24",width:"14",height:"14","aria-hidden":"true"},io=["d"],lo=["placeholder","disabled"],co={class:"wm-compose__actions"},uo=["title","aria-label","disabled"],mo=["disabled"];function ho(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",eo,[s.recording?(e.openBlock(),e.createElementBlock("div",to,[t[8]||(t[8]=e.createElementVNode("span",{class:"wm-rec__dot","aria-hidden":"true"},null,-1)),e.createElementVNode("span",no,"Enregistrement · "+e.toDisplayString(o.recordingElapsedLabel),1),e.createElementVNode("button",{type:"button",class:"wm-rec__stop",onClick:t[0]||(t[0]=(...i)=>o.stopRecording&&o.stopRecording(...i))},"Arrêter")])):e.createCommentVNode("",!0),e.createElementVNode("form",{class:e.normalizeClass(["wm-compose",{"has-attach":s.attachOpen}]),onSubmit:t[7]||(t[7]=e.withModifiers((...i)=>o.onSubmit&&o.onSubmit(...i),["prevent"]))},[e.createElementVNode("input",{ref:"fileEl",type:"file",hidden:"",multiple:"",onChange:t[1]||(t[1]=(...i)=>o.onFile&&o.onFile(...i))},null,544),s.attachOpen?(e.openBlock(),e.createElementBlock("div",{key:0,class:"wm-compose__overlay",onClick:t[2]||(t[2]=i=>s.attachOpen=!1)})):e.createCommentVNode("",!0),s.attachOpen?(e.openBlock(),e.createElementBlock("div",ro,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.attachItems,i=>(e.openBlock(),e.createElementBlock("button",{key:i.action,type:"button",class:"wm-compose__menuItem",disabled:i.disabled,onClick:l=>o.onAttachAction(i.action)},[e.createElementVNode("span",so,[(e.openBlock(),e.createElementBlock("svg",ao,[e.createElementVNode("path",{d:i.path,stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",fill:"none"},null,8,io)]))]),e.createElementVNode("span",null,e.toDisplayString(i.label),1)],8,oo))),128))])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("textarea",{ref:"inputEl","onUpdate:modelValue":t[3]||(t[3]=i=>s.local=i),class:"wm-compose__input",rows:"3",placeholder:r.placeholder,disabled:r.disabled,onKeydown:t[4]||(t[4]=(...i)=>o.onKeydown&&o.onKeydown(...i)),onInput:t[5]||(t[5]=(...i)=>o.autosize&&o.autosize(...i))},null,40,lo),[[e.vModelText,s.local]]),e.createElementVNode("div",co,[e.createElementVNode("button",{type:"button",class:e.normalizeClass(["wm-compose__icon",{"is-open":s.attachOpen}]),title:r.attachLabel,"aria-label":r.attachLabel,disabled:s.recording,onClick:t[6]||(t[6]=i=>s.attachOpen=!s.attachOpen)},[...t[9]||(t[9]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"})],-1)])],10,uo),e.createElementVNode("button",{type:"submit",class:e.normalizeClass(["wm-compose__send",{"is-empty":!o.canSend}]),disabled:!o.canSend,"aria-label":"Envoyer"},[...t[10]||(t[10]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})],-1)])],10,mo)])],34)])}const Te=N(Zr,[["render",ho],["__scopeId","data-v-14fa9ec0"]]),po={name:"WmSuggestionChips",props:{items:{type:Array,default:()=>[]},baseDelay:{type:Number,default:360},stepDelay:{type:Number,default:90}},emits:["select"],computed:{batchKey(){return this.items.map(n=>(n==null?void 0:n.label)||(n==null?void 0:n.text)||"").join("§")}}},fo=["onClick"];function _o(n,t,r,a,s,o){return r.items.length?(e.openBlock(),e.createElementBlock("div",{key:o.batchKey,class:"wm-chips"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.items,(i,l)=>(e.openBlock(),e.createElementBlock("button",{key:l,type:"button",class:"wm-chip",style:e.normalizeStyle({animationDelay:r.baseDelay+l*r.stepDelay+"ms"}),onClick:f=>n.$emit("select",i)},e.toDisplayString(i.label),13,fo))),128))])):e.createCommentVNode("",!0)}const Me=N(po,[["render",_o],["__scopeId","data-v-55aa529d"]]),go={name:"WmApprovalCard",components:{AIAvatar:z},props:{action:{type:String,required:!0},detail:{type:String,default:""},callbacks:{type:Array,default:()=>[]}},emits:["callback"],computed:{approveCallback(){return this.callbacks.find(n=>n.id==="approve"||n.style==="primary")||this.callbacks[0]},rejectCallback(){return this.callbacks.find(n=>n.id==="reject"||n.style==="danger"||n.style==="neutral")||(this.callbacks.length>1?this.callbacks[1]:null)},approveId(){var n;return(n=this.approveCallback)==null?void 0:n.id},rejectId(){var n;return(n=this.rejectCallback)==null?void 0:n.id},approveLabel(){var n;return((n=this.approveCallback)==null?void 0:n.label)||"Autoriser"},rejectLabel(){var n;return((n=this.rejectCallback)==null?void 0:n.label)||"Refuser"}}},vo={class:"wm-approval"},yo={class:"wm-approval__head"},ko={class:"wm-approval__icon"},wo={class:"wm-approval__main"},bo={class:"wm-approval__title"},Eo={key:0,class:"wm-approval__detail"},Bo={class:"wm-approval__actions"};function Co(n,t,r,a,s,o){const i=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",vo,[e.createElementVNode("div",yo,[e.createElementVNode("div",ko,[e.createVNode(i,{size:24})]),e.createElementVNode("div",wo,[e.createElementVNode("div",bo,e.toDisplayString(r.action),1),r.detail?(e.openBlock(),e.createElementBlock("div",Eo,e.toDisplayString(r.detail),1)):e.createCommentVNode("",!0)])]),e.createElementVNode("div",Bo,[o.rejectId?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-approval__btn wm-approval__btn--neutral",onClick:t[0]||(t[0]=l=>n.$emit("callback",o.rejectId))},e.toDisplayString(o.rejectLabel),1)):e.createCommentVNode("",!0),o.approveId?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-approval__btn wm-approval__btn--primary",onClick:t[1]||(t[1]=l=>n.$emit("callback",o.approveId))},e.toDisplayString(o.approveLabel),1)):e.createCommentVNode("",!0)])])}const xe=N(go,[["render",Co],["__scopeId","data-v-b1be139c"]]);let se=0;const No=new Set(["text","textarea","number","boolean","select","multiselect","date"]),So={name:"WmFormCard",components:{AIAvatar:z},props:{form:{type:Object,required:!0},readOnly:{type:Boolean,default:!1},initialValues:{type:Object,default:null}},emits:["submit"],data(){return se+=1,{_uid:se,values:{},busy:!1,error:""}},computed:{normalizedFields(){var t;return(Array.isArray((t=this.form)==null?void 0:t.fields)?this.form.fields:[]).filter(r=>!(!(r!=null&&r.key)||!(r!=null&&r.label)||!No.has(r==null?void 0:r.type)||(r.type==="select"||r.type==="multiselect")&&(!Array.isArray(r.options)||r.options.length===0)))}},created(){this.resetValues()},methods:{resetValues(){const n=this.initialValues&&typeof this.initialValues=="object"?this.initialValues:{},t={};for(const r of this.normalizedFields){if(n[r.key]!==void 0){t[r.key]=n[r.key];continue}r.type==="boolean"?t[r.key]=!1:r.type==="multiselect"?t[r.key]=[]:t[r.key]=""}this.values=t,this.error=""},toggleMulti(n,t,r){const a=Array.isArray(this.values[n])?this.values[n].slice():[],s=a.indexOf(t);r&&s===-1?a.push(t):!r&&s!==-1&&a.splice(s,1),this.values={...this.values,[n]:a}},validate(){for(const n of this.normalizedFields){if(!n.required)continue;const t=this.values[n.key];if(n.type!=="boolean"){if(n.type==="multiselect"){if(!Array.isArray(t)||t.length===0)return`« ${n.label} » est requis.`;continue}if(t==null||t==="")return`« ${n.label} » est requis.`}}return""},async onSubmit(){if(this.readOnly||this.busy)return;const n=this.validate();if(n){this.error=n;return}this.error="",this.busy=!0;try{await this.$emit("submit",{values:this.values})}finally{this.busy=!1}}}},Vo={class:"wm-form"},Ao={class:"wm-form__head"},To={class:"wm-form__icon"},Mo={class:"wm-form__main"},xo={class:"wm-form__title"},Oo={key:0,class:"wm-form__detail"},Io=["for"],Do={key:0,class:"wm-form__req","aria-hidden":"true"},Lo=["id","onUpdate:modelValue","placeholder","required","disabled"],$o=["id","onUpdate:modelValue","placeholder","required","disabled"],Ro=["id","onUpdate:modelValue","placeholder","required","disabled"],Fo=["id","onUpdate:modelValue","required","disabled"],zo={key:4,class:"wm-form__bool"},Po=["id","onUpdate:modelValue","disabled"],jo=["id","onUpdate:modelValue","required","disabled"],Uo={value:"",disabled:""},Ho=["value"],qo={key:6,class:"wm-form__multi"},Ko=["value","checked","disabled","onChange"],Wo={key:0,class:"wm-form__err"},Go=["disabled"],Yo={key:0,class:"wm-form__spinner","aria-hidden":"true"},Jo={key:2,class:"wm-form__doneLbl"};function Xo(n,t,r,a,s,o){const i=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",Vo,[e.createElementVNode("div",Ao,[e.createElementVNode("div",To,[e.createVNode(i,{size:24})]),e.createElementVNode("div",Mo,[e.createElementVNode("div",xo,e.toDisplayString(r.form.title||"Formulaire"),1),r.form.description?(e.openBlock(),e.createElementBlock("div",Oo,e.toDisplayString(r.form.description),1)):e.createCommentVNode("",!0)])]),e.createElementVNode("form",{class:"wm-form__body",onSubmit:t[0]||(t[0]=e.withModifiers((...l)=>o.onSubmit&&o.onSubmit(...l),["prevent"]))},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.normalizedFields,l=>(e.openBlock(),e.createElementBlock("div",{key:l.key,class:"wm-form__field"},[e.createElementVNode("label",{for:`wm-f-${s._uid}-${l.key}`,class:"wm-form__label"},[e.createTextVNode(e.toDisplayString(l.label),1),l.required?(e.openBlock(),e.createElementBlock("span",Do,"*")):e.createCommentVNode("",!0)],8,Io),l.type==="text"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:0,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":f=>s.values[l.key]=f,type:"text",class:"wm-form__input",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||s.busy},null,8,Lo)),[[e.vModelText,s.values[l.key]]]):l.type==="textarea"?e.withDirectives((e.openBlock(),e.createElementBlock("textarea",{key:1,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":f=>s.values[l.key]=f,class:"wm-form__textarea",rows:"3",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||s.busy},null,8,$o)),[[e.vModelText,s.values[l.key]]]):l.type==="number"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":f=>s.values[l.key]=f,type:"number",class:"wm-form__input",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||s.busy},null,8,Ro)),[[e.vModelText,s.values[l.key],void 0,{number:!0}]]):l.type==="date"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:3,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":f=>s.values[l.key]=f,type:"date",class:"wm-form__input",required:l.required,disabled:r.readOnly||s.busy},null,8,Fo)),[[e.vModelText,s.values[l.key]]]):l.type==="boolean"?(e.openBlock(),e.createElementBlock("label",zo,[e.withDirectives(e.createElementVNode("input",{id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":f=>s.values[l.key]=f,type:"checkbox",disabled:r.readOnly||s.busy},null,8,Po),[[e.vModelCheckbox,s.values[l.key]]]),e.createElementVNode("span",null,e.toDisplayString(l.placeholder||"Oui"),1)])):l.type==="select"?e.withDirectives((e.openBlock(),e.createElementBlock("select",{key:5,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":f=>s.values[l.key]=f,class:"wm-form__select",required:l.required,disabled:r.readOnly||s.busy},[e.createElementVNode("option",Uo,e.toDisplayString(l.placeholder||"Choisir…"),1),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.options,f=>(e.openBlock(),e.createElementBlock("option",{key:f.value,value:f.value},e.toDisplayString(f.label),9,Ho))),128))],8,jo)),[[e.vModelSelect,s.values[l.key]]]):l.type==="multiselect"?(e.openBlock(),e.createElementBlock("div",qo,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.options,f=>(e.openBlock(),e.createElementBlock("label",{key:f.value,class:"wm-form__multiItem"},[e.createElementVNode("input",{type:"checkbox",value:f.value,checked:Array.isArray(s.values[l.key])&&s.values[l.key].includes(f.value),disabled:r.readOnly||s.busy,onChange:v=>o.toggleMulti(l.key,f.value,v.target.checked)},null,40,Ko),e.createElementVNode("span",null,e.toDisplayString(f.label),1)]))),128))])):e.createCommentVNode("",!0)]))),128)),s.error?(e.openBlock(),e.createElementBlock("div",Wo,e.toDisplayString(s.error),1)):e.createCommentVNode("",!0),r.readOnly?(e.openBlock(),e.createElementBlock("div",Jo,"Réponse envoyée")):(e.openBlock(),e.createElementBlock("button",{key:1,type:"submit",class:"wm-form__submit",disabled:s.busy},[s.busy?(e.openBlock(),e.createElementBlock("span",Yo)):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(s.busy?"Envoi…":r.form.submit_label||"Envoyer"),1)],8,Go))],32)])}const Oe=N(So,[["render",Xo],["__scopeId","data-v-64b40f76"]]),Qo={name:"WmFeedback",props:{busy:{type:Boolean,default:!1},done:{type:Boolean,default:!1}},emits:["submit"],data(){return{sel:null,options:[{v:1,e:"😞",l:"Pas bien"},{v:2,e:"😐",l:"Moyen"},{v:3,e:"🙂",l:"Bien"},{v:4,e:"😄",l:"Super"},{v:5,e:"🤩",l:"Excellent"}]}},methods:{onSend(){!this.sel||this.busy||this.$emit("submit",{rating:this.sel})}}},Zo={class:"wm-fb"},es={class:"wm-fb__row"},ts=["onClick"],ns={class:"wm-fb__emoji"},rs={class:"wm-fb__label"},os=["disabled"],ss={key:1,class:"wm-fb__done"};function as(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Zo,[r.done?(e.openBlock(),e.createElementBlock("div",ss,[...t[3]||(t[3]=[e.createStaticVNode('<div class="wm-fb__check" data-v-6f45ff3b><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-6f45ff3b><path d="M20 6L9 17l-5-5" data-v-6f45ff3b></path></svg></div><div class="wm-fb__doneTitle" data-v-6f45ff3b>Merci pour votre retour !</div><div class="wm-fb__doneSub" data-v-6f45ff3b>Votre avis a bien été pris en compte.</div>',3)])])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[t[1]||(t[1]=e.createElementVNode("div",{class:"wm-fb__title"},"Comment s'est passée cette conversation ?",-1)),t[2]||(t[2]=e.createElementVNode("div",{class:"wm-fb__sub"},"Votre avis nous aide à améliorer l'assistant.",-1)),e.createElementVNode("div",es,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.options,i=>(e.openBlock(),e.createElementBlock("button",{key:i.v,type:"button",class:e.normalizeClass(["wm-fb__opt",{"is-selected":s.sel===i.v}]),onClick:l=>s.sel=i.v},[e.createElementVNode("span",ns,e.toDisplayString(i.e),1),e.createElementVNode("span",rs,e.toDisplayString(i.l),1)],10,ts))),128))]),e.createElementVNode("button",{type:"button",class:"wm-fb__send",disabled:!s.sel||r.busy,onClick:t[0]||(t[0]=(...i)=>o.onSend&&o.onSend(...i))},e.toDisplayString(r.busy?"Envoi…":"Envoyer mon avis"),9,os)],64))])}const Ie=N(Qo,[["render",as],["__scopeId","data-v-6f45ff3b"]]);function is(n){const t=new Date(n);return t.setHours(0,0,0,0),t}const ls={name:"WmHistoryDrawer",props:{conversations:{type:Array,default:()=>[]},activeId:{type:[String,Number],default:null}},emits:["close","new","pick"],data(){return{query:""}},computed:{normalized(){return(Array.isArray(this.conversations)?this.conversations.slice():[]).map(t=>{var s;const r=t.last_message_at||t.updated_at||t.created_at||null,a=r?Date.parse(r):0;return{id:t.id,raw:t,title:t.name||"Nouvelle conversation",preview:t._preview||t.last_message_preview||t.preview||((s=t.metadata)==null?void 0:s.last_preview)||"",unread:!!t._unread,stamp:a}}).sort((t,r)=>r.stamp-t.stamp)},filtered(){const n=this.query.trim().toLowerCase();return n?this.normalized.filter(t=>(t.title||"").toLowerCase().includes(n)||(t.preview||"").toLowerCase().includes(n)):this.normalized},groups(){const t=is(new Date).getTime(),r=t-6*864e5,a=[],s=[],o=[];for(const i of this.filtered){if(!i.stamp){o.push(i);continue}i.stamp>=t?a.push(i):i.stamp>=r?s.push(i):o.push(i)}return[{key:"today",label:"Aujourd'hui",items:a},{key:"week",label:"Cette semaine",items:s},{key:"older",label:"Plus ancien",items:o}]},hasAny(){return this.filtered.length>0}}},cs={class:"wm-hd"},ds={class:"wm-hd__panel",role:"dialog","aria-label":"Vos discussions"},us={class:"wm-hd__head"},ms={class:"wm-hd__top"},hs={class:"wm-hd__search"},ps={class:"wm-hd__list"},fs={key:0,class:"wm-hd__group"},_s={class:"wm-hd__groupLabel"},gs={class:"wm-hd__rows"},vs=["onClick"],ys={class:"wm-hd__rowIcon"},ks={key:0,class:"wm-hd__rowDot","aria-label":"Message non lu"},ws={class:"wm-hd__rowBody"},bs={class:"wm-hd__rowTop"},Es={class:"wm-hd__rowTitle"},Bs={class:"wm-hd__rowPreview"},Cs={key:0,class:"wm-hd__empty"};function Ns(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",cs,[e.createElementVNode("div",{class:"wm-hd__scrim",onClick:t[0]||(t[0]=i=>n.$emit("close"))}),e.createElementVNode("aside",ds,[e.createElementVNode("div",us,[t[5]||(t[5]=e.createElementVNode("div",{class:"wm-hd__heading"},[e.createElementVNode("div",{class:"wm-hd__title"},"Vos discussions"),e.createElementVNode("div",{class:"wm-hd__sub"},"Reprenez là où vous en étiez.")],-1)),e.createElementVNode("button",{type:"button",class:"wm-hd__close","aria-label":"Fermer",onClick:t[1]||(t[1]=i=>n.$emit("close"))},[...t[4]||(t[4]=[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])]),e.createElementVNode("div",ms,[e.createElementVNode("button",{type:"button",class:"wm-hd__new",onClick:t[2]||(t[2]=i=>n.$emit("new"))},[...t[6]||(t[6]=[e.createElementVNode("span",{class:"wm-hd__newIcon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M12 5v14M5 12h14"})])],-1),e.createElementVNode("span",null,"Démarrer un nouveau fil",-1)])]),e.createElementVNode("div",hs,[t[7]||(t[7]=e.createElementVNode("span",{class:"wm-hd__searchIcon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21 21l-4.35-4.35M11 17a6 6 0 100-12 6 6 0 000 12z"})])],-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[3]||(t[3]=i=>s.query=i),type:"text",placeholder:"Rechercher dans vos messages","aria-label":"Rechercher dans vos messages"},null,512),[[e.vModelText,s.query]])])]),e.createElementVNode("div",ps,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.groups,i=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:i.key},[i.items.length?(e.openBlock(),e.createElementBlock("div",fs,[e.createElementVNode("div",_s,e.toDisplayString(i.label),1),e.createElementVNode("div",gs,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.items,l=>(e.openBlock(),e.createElementBlock("button",{key:l.id,type:"button",class:e.normalizeClass(["wm-hd__row",{"wm-hd__row--active":l.id===r.activeId,"wm-hd__row--unread":l.unread}]),onClick:f=>n.$emit("pick",l)},[e.createElementVNode("div",ys,[t[8]||(t[8]=e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true"},[e.createElementVNode("path",{d:"M12 2 L13.5 9 L20 10.5 L13.5 12 L12 19 L10.5 12 L4 10.5 L10.5 9 Z",fill:"white",opacity:"0.92"})],-1)),l.unread?(e.openBlock(),e.createElementBlock("span",ks)):e.createCommentVNode("",!0)]),e.createElementVNode("div",ws,[e.createElementVNode("div",bs,[e.createElementVNode("span",Es,e.toDisplayString(l.title),1)]),e.createElementVNode("div",Bs,e.toDisplayString(l.preview||"Aucun message"),1)])],10,vs))),128))])])):e.createCommentVNode("",!0)],64))),128)),o.hasAny?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Cs," Aucun fil pour le moment. "))])])])}const De=N(ls,[["render",Ns],["__scopeId","data-v-1259e822"]]),Ss={name:"WmMoreMenu",props:{canRename:{type:Boolean,default:!0},canExport:{type:Boolean,default:!0},soundEnabled:{type:Boolean,default:!0},browserNotifEnabled:{type:Boolean,default:!1},statusUrl:{type:String,default:""},helpUrl:{type:String,default:""}},emits:["close","action","sound-toggle","browser-notif-toggle"],data(){return{soundOn:this.soundEnabled,browserNotifOn:this.browserNotifEnabled}},watch:{soundEnabled(n){this.soundOn=!!n},browserNotifEnabled(n){this.browserNotifOn=!!n}},methods:{emit(n){this.$emit("action",n)},toggleSound(){this.soundOn=!this.soundOn,this.$emit("sound-toggle",this.soundOn)},toggleBrowserNotif(){this.browserNotifOn=!this.browserNotifOn,this.$emit("browser-notif-toggle",this.browserNotifOn)}}},Vs={class:"wm-mm"},As={class:"wm-mm__pop",role:"menu"},Ts={class:"wm-mm__section"},Ms={class:"wm-mm__section"},xs={class:"wm-mm__section"};function Os(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Vs,[e.createElementVNode("div",{class:"wm-mm__scrim",onClick:t[0]||(t[0]=i=>n.$emit("close"))}),e.createElementVNode("div",As,[e.createElementVNode("div",Ts,[e.createElementVNode("button",{type:"button",class:"wm-mm__item",onClick:t[1]||(t[1]=i=>o.emit("history"))},[...t[8]||(t[8]=[e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M3 3v5h5M3.05 13A9 9 0 1 0 6 5.3L3 8M12 7v5l4 2"})])],-1),e.createElementVNode("span",{class:"wm-mm__label"},"Historique des discussions",-1)])]),r.canRename?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-mm__item",onClick:t[2]||(t[2]=i=>o.emit("rename"))},[...t[9]||(t[9]=[e.createStaticVNode('<span class="wm-mm__icon" data-v-e300b2de><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-e300b2de><path d="M12 20h9" data-v-e300b2de></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z" data-v-e300b2de></path></svg></span><span class="wm-mm__label" data-v-e300b2de>Modifier le titre</span>',2)])])):e.createCommentVNode("",!0),r.canExport?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-mm__item",onClick:t[3]||(t[3]=i=>o.emit("export"))},[...t[10]||(t[10]=[e.createStaticVNode('<span class="wm-mm__icon" data-v-e300b2de><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-e300b2de><path d="M4 12v8a2 2 0 002 2h12a2 2 0 002-2v-8M16 6l-4-4-4 4M12 2v13" data-v-e300b2de></path></svg></span><span class="wm-mm__label" data-v-e300b2de>Exporter la transcription</span><span class="wm-mm__hint" data-v-e300b2de>.txt</span>',3)])])):e.createCommentVNode("",!0)]),t[18]||(t[18]=e.createElementVNode("div",{class:"wm-mm__sep"},null,-1)),e.createElementVNode("div",Ms,[e.createElementVNode("button",{type:"button",class:"wm-mm__item",onClick:t[4]||(t[4]=(...i)=>o.toggleSound&&o.toggleSound(...i))},[t[12]||(t[12]=e.createStaticVNode('<span class="wm-mm__icon" data-v-e300b2de><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-e300b2de><path d="M11 5L6 9H2v6h4l5 4V5z" data-v-e300b2de></path><path d="M15.54 8.46a5 5 0 010 7.07M19.07 4.93a10 10 0 010 14.14" data-v-e300b2de></path></svg></span><span class="wm-mm__label" data-v-e300b2de>Son</span>',2)),e.createElementVNode("span",{class:e.normalizeClass(["wm-mm__toggle",{"wm-mm__toggle--on":s.soundOn}])},[...t[11]||(t[11]=[e.createElementVNode("span",{class:"wm-mm__knob"},null,-1)])],2)]),e.createElementVNode("button",{type:"button",class:"wm-mm__item",onClick:t[5]||(t[5]=(...i)=>o.toggleBrowserNotif&&o.toggleBrowserNotif(...i))},[t[14]||(t[14]=e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M15 17h5l-1.4-1.4A2 2 0 0118 14.2V11a6 6 0 10-12 0v3.2c0 .5-.2 1-.6 1.4L4 17h5m6 0a3 3 0 11-6 0"})])],-1)),t[15]||(t[15]=e.createElementVNode("span",{class:"wm-mm__label"},"Notifications navigateur",-1)),e.createElementVNode("span",{class:e.normalizeClass(["wm-mm__toggle",{"wm-mm__toggle--on":s.browserNotifOn}])},[...t[13]||(t[13]=[e.createElementVNode("span",{class:"wm-mm__knob"},null,-1)])],2)])]),t[19]||(t[19]=e.createElementVNode("div",{class:"wm-mm__sep"},null,-1)),e.createElementVNode("div",xs,[r.statusUrl?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-mm__item",onClick:t[6]||(t[6]=i=>o.emit("status"))},[...t[16]||(t[16]=[e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zM10 6v4l3 2"})])],-1),e.createElementVNode("span",{class:"wm-mm__label"},"Statut des services",-1)])])):e.createCommentVNode("",!0),r.helpUrl?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-mm__item",onClick:t[7]||(t[7]=i=>o.emit("help"))},[...t[17]||(t[17]=[e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M9 11a3 3 0 116 0c0 2-3 2-3 5M12 19h.01M12 22a10 10 0 110-20 10 10 0 010 20z"})])],-1),e.createElementVNode("span",{class:"wm-mm__label"},"Centre d'aide",-1)])])):e.createCommentVNode("",!0)])])])}const Le=N(Ss,[["render",Os],["__scopeId","data-v-e300b2de"]]),Is={name:"WmRenameDialog",props:{title:{type:String,default:"Modifier le titre"},initialValue:{type:String,default:""},placeholder:{type:String,default:"Titre de la conversation"}},emits:["close","submit"],data(){return{value:this.initialValue||""}},computed:{canSubmit(){const n=(this.value||"").trim();return!!n&&n!==(this.initialValue||"").trim()}},mounted(){this.$nextTick(()=>{const n=this.$refs.input;if(n){n.focus();try{n.select()}catch{}}})},methods:{onSubmit(){this.canSubmit&&this.$emit("submit",this.value.trim())}}},Ds={class:"wm-dialog"},Ls={class:"wm-dialog__card",role:"dialog","aria-modal":"true"},$s={class:"wm-dialog__head"},Rs={class:"wm-dialog__title"},Fs={class:"wm-dialog__body"},zs=["placeholder"],Ps={class:"wm-dialog__actions"},js=["disabled"];function Us(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Ds,[e.createElementVNode("div",{class:"wm-dialog__scrim",onClick:t[0]||(t[0]=i=>n.$emit("close"))}),e.createElementVNode("div",Ls,[e.createElementVNode("div",$s,[e.createElementVNode("div",Rs,e.toDisplayString(r.title),1),e.createElementVNode("button",{type:"button",class:"wm-dialog__close","aria-label":"Fermer",onClick:t[1]||(t[1]=i=>n.$emit("close"))},[...t[7]||(t[7]=[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])]),e.createElementVNode("div",Fs,[e.withDirectives(e.createElementVNode("input",{ref:"input","onUpdate:modelValue":t[2]||(t[2]=i=>s.value=i),type:"text",class:"wm-dialog__input",placeholder:r.placeholder,maxlength:120,onKeydown:[t[3]||(t[3]=e.withKeys(e.withModifiers((...i)=>o.onSubmit&&o.onSubmit(...i),["prevent"]),["enter"])),t[4]||(t[4]=e.withKeys(e.withModifiers(i=>n.$emit("close"),["prevent"]),["esc"]))]},null,40,zs),[[e.vModelText,s.value]])]),e.createElementVNode("div",Ps,[e.createElementVNode("button",{type:"button",class:"wm-dialog__btn",onClick:t[5]||(t[5]=i=>n.$emit("close"))},"Annuler"),e.createElementVNode("button",{type:"button",class:"wm-dialog__btn wm-dialog__btn--primary",disabled:!o.canSubmit,onClick:t[6]||(t[6]=(...i)=>o.onSubmit&&o.onSubmit(...i))},"Enregistrer",8,js)])])])}const Hs=N(Is,[["render",Us],["__scopeId","data-v-4f4b37c9"]]),ae="ww-messenger-tokens",qs={name:"Messenger",components:{Launcher:me,Header:pe,Onboarding:fe,MessageList:Ce,Composer:Te,SuggestionChips:Me,ApprovalCard:xe,FormCard:Oe,Feedback:Ie,HistoryDrawer:De,MoreMenu:Le,RenameDialog:Hs},mixins:[Qe,ot,st,at],provide(){return{signAttachmentFn:n=>{var t,r;return((r=(t=this.store)==null?void 0:t.signAttachment)==null?void 0:r.call(t,n))||null}}},props:{baseUrl:{type:String,default:de},widgetId:{type:String,default:""},userId:{type:String,default:""},userHash:{type:String,default:""},customer:{type:Object,default:null},displayMode:{type:String,default:"floating"},devtools:{type:Boolean,default:!1}},data(){return{transport:null,store:null,isOpen:!1,draft:"",busy:!1,bootError:null,pendingAttachments:[],feedbackBusy:!1,feedbackDone:!1,convOpenedAt:0,historyOpen:!1,moreOpen:!1,renameDialogOpen:!1,draftConv:null,activeConvId:null,showOnboarding:!1,dismissedPeeks:{},floatHeight:0,floatRO:null}},computed:{isEditor(){return!!this.devtools},isEmbedded(){return this.displayMode==="embedded"},error(){var n;return this.bootError||((n=this.s)==null?void 0:n.error)||null},canBoot(){return!!(this.baseUrl&&this.widgetId&&this.userId&&this.userHash)},s(){var n;return((n=this.store)==null?void 0:n.state)||null},ready(){var n;return!!((n=this.s)!=null&&n.ready)},allConversations(){var t;const n=(t=this.s)==null?void 0:t.conversations;return Array.isArray(n)?n:[]},drawerConversations(){var a;const n=this.readState,t=this.readBootTs,r=((a=this.s)==null?void 0:a.messagesByConv)||{};return this.allConversations.map(s=>{var S;const o=r[s.id]||[],i=K(s,o),l=n[s.id]||t||"",f=We(o),v=!!i&&f!=="user"&&(!l||i>l);let y=0,b=null;for(let k=o.length-1;k>=0;k--){const A=o[k];if(A){if(((S=A.author)==null?void 0:S.type)==="user"||l&&A.created_at&&A.created_at<=l)break;!b&&A.author&&(b=A.author),y++}}return v&&y===0&&(y=1),{...s,_preview:Ge(s,o),_unread:v,_unreadCount:y,_lastAuthor:b}})},unreadCount(){return this.drawerConversations.filter(n=>n._unread).length},openThreads(){var t;const n=((t=this.s)==null?void 0:t.messagesByConv)||{};return this.drawerConversations.filter(r=>r.status!=="resolved").map(r=>({id:r.id,title:r.name||"Nouvelle conversation",preview:r._preview||"Nouveau message",unread:!!r._unread,_ts:K(r,n[r.id]||[])})).sort((r,a)=>r._ts<a._ts?1:r._ts>a._ts?-1:0)},latestUnreads(){var r;const n=((r=this.s)==null?void 0:r.messagesByConv)||{},t=[];for(const a of this.drawerConversations){if(!a._unread)continue;const s=K(a,n[a.id]||[]),o=a._lastAuthor,i=!o||o.type==="agent_ia",l=(o==null?void 0:o.name)||(i?this.agentName:"")||"",f=(o==null?void 0:o.avatar_url)||(i?this.agentAvatarUrl:null);t.push({convId:a.id,preview:a._preview||"Vous avez un nouveau message",ts:s,count:a._unreadCount||1,senderName:l,senderAvatarUrl:f})}return t.sort((a,s)=>a.ts<s.ts?1:a.ts>s.ts?-1:0),t},launcherPeeks(){if(this.isOpen||this.isEmbedded)return[];const n=this.dismissedPeeks||{};return this.latestUnreads.filter(t=>n[t.convId]!==t.ts)},isViewingThread(){return(this.isOpen||this.isEmbedded)&&!this.historyOpen&&!!this.currentConv},currentConv(){if(this.draftConv)return this.draftConv;if(this.showOnboarding)return null;const n=this.allConversations;if(!n.length)return null;if(this.activeConvId!=null){const t=n.find(r=>r.id===this.activeConvId);if(t)return t}return n[0]||null},canBack(){return!!this.currentConv},statusUrl(){var r;const n=(r=this.widget)==null?void 0:r.quick_links;if(!Array.isArray(n))return"";const t=n.find(a=>a.icon==="status"&&a.url);return(t==null?void 0:t.url)||""},helpUrl(){var r;const n=(r=this.widget)==null?void 0:r.quick_links;if(!Array.isArray(n))return"";const t=n.find(a=>(a.icon==="chat"||a.icon==="help")&&a.url);return(t==null?void 0:t.url)||""},widget(){var n,t;return((t=(n=this.s)==null?void 0:n.config)==null?void 0:t.widget)||null},widgetWelcomeMessage(){var n;return((n=this.widget)==null?void 0:n.welcome_message)||""},agentName(){var n,t,r;return((r=(t=(n=this.s)==null?void 0:n.config)==null?void 0:t.agent)==null?void 0:r.name)||""},agentAvatarUrl(){var n,t,r;return((r=(t=(n=this.s)==null?void 0:n.config)==null?void 0:t.agent)==null?void 0:r.avatar_url)||null},quickLinks(){var t;const n=(t=this.widget)==null?void 0:t.quick_links;return Array.isArray(n)?n:[]},teamMembers(){var t;const n=(t=this.widget)==null?void 0:t.team_members;return Array.isArray(n)?n:[]},responseLabel(){var n;return((n=this.widget)==null?void 0:n.response_time_label)||""},humanMessageAuthor(){var t,r,a;if(!this.currentConv)return null;const n=((t=this.s.messagesByConv)==null?void 0:t[this.currentConv.id])||[];for(let s=n.length-1;s>=0;s--)if(((a=(r=n[s])==null?void 0:r.author)==null?void 0:a.type)==="agent_human")return n[s].author;return null},humanAgentName(){var n;return((n=this.humanMessageAuthor)==null?void 0:n.name)||""},humanAgentAvatarUrl(){var n;return((n=this.humanMessageAuthor)==null?void 0:n.avatar_url)||null},isEscalated(){return!!this.humanMessageAuthor},isWaitingHuman(){var t;const n=(t=this.currentConv)==null?void 0:t.status;return n==="waiting"||n==="handled"},headerTitle(){var n,t;return((n=this.currentConv)==null?void 0:n.name)||((t=this.widget)==null?void 0:t.name)||"Nouvelle conversation"},composerPlaceholder(){return this.isEscalated&&this.humanAgentName?`Répondre à ${this.humanAgentName.split(" ")[0]}…`:this.isWaitingHuman?"Un agent prend le relais…":"Écrivez votre message…"},displayedMessages(){const n=this.currentConv;if(!n)return[];const t=this.revealedAt;return(this.s.messagesByConv[n.id]||[]).filter(r=>{var a,s,o,i,l;return(r==null?void 0:r.type)==="action"&&((a=r==null?void 0:r.payload)==null?void 0:a.state)==="pending"||W(r)&&!(t[r.id]>0)?!1:(r==null?void 0:r.type)==="action"||(r==null?void 0:r.type)==="system"||((s=r==null?void 0:r.payload)==null?void 0:s.type)==="system"||Array.isArray((o=r==null?void 0:r.payload)==null?void 0:o.attachments)&&r.payload.attachments.length||(i=r==null?void 0:r.metadata)!=null&&i.artifact||(l=r==null?void 0:r.metadata)!=null&&l.form?!0:typeof(r==null?void 0:r.text_md)=="string"&&r.text_md.trim().length>0})},streamingActive(){var r,a,s;const n=this.currentConv;return n?Object.keys(((r=this.s)==null?void 0:r.streamingByMsgId)||{}).length>0?!0:this.actionInFlight?!1:(((s=(a=this.s)==null?void 0:a.messagesByConv)==null?void 0:s[n.id])||[]).some(o=>W(o)&&!(this.revealedAt[o.id]>0)):!1},currentConvMessages(){var t,r,a;const n=(t=this.currentConv)==null?void 0:t.id;return n?((a=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:a[n])||[]:[]},pendingApproval(){return!this.currentConv||!this.store||this.actionInFlight?null:this.store.getPendingApproval(this.currentConv.id)},approvalReady(){return this.pendingApproval?this.pendingApproval.id===this.approvalLatchId?!0:!(this.streamingActive||!this.approvalSettled):!1},approvalTitle(){var n,t,r;return((t=(n=this.pendingApproval)==null?void 0:n.payload)==null?void 0:t.name)||((r=this.pendingApproval)==null?void 0:r.text_md)||"Confirmer l'action"},approvalDetail(){var a,s,o,i,l,f;const n=(o=(s=(a=this.pendingApproval)==null?void 0:a.payload)==null?void 0:s.pending)==null?void 0:o.user_explanation;if(typeof n=="string"&&n.trim())return n.trim();const t=(f=(l=(i=this.pendingApproval)==null?void 0:i.payload)==null?void 0:l.pending)==null?void 0:f.prepared_params;if(!t||typeof t!="object")return"";const r=Object.entries(t);return r.length?r.slice(0,2).map(([v,y])=>`${v}: ${y}`).join(" · "):""},actionInFlight(){var n,t;return!this.currentConv||!this.store?null:((t=(n=this.store).getActionInFlight)==null?void 0:t.call(n,this.currentConv.id))||null},actionInFlightName(){var t;const n=this.actionInFlight;return n?((t=n.payload)==null?void 0:t.name)||n.text_md||"Action":""},suggestions(){return!this.currentConv||!this.store?[]:this.streamingActive?[]:this.pendingForm?[]:this.store.getLatestSuggestions(this.currentConv.id)},pendingForm(){var n,t;return!this.currentConv||!this.store||this.pendingApproval||this.actionInFlight||this.streamingActive||!this.approvalSettled?null:((t=(n=this.store).getLatestForm)==null?void 0:t.call(n,this.currentConv.id))||null},showFeedback(){var t;const n=this.currentConv;return n?this.feedbackDone?!0:n.status!=="resolved"?!1:!((t=n.metadata)!=null&&t.feedback):!1},floatVisible(){return this.approvalReady||!!this.pendingForm||this.showFeedback||this.suggestions.length>0},dateLabel(){var r,a,s;const n=this.currentConv;let t=new Date;if(n){const i=((s=(((a=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:a[n.id])||[]).find(l=>l==null?void 0:l.created_at))==null?void 0:s.created_at)||n.created_at;if(i){const l=new Date(i);Number.isNaN(l.getTime())||(t=l)}}return`Aujourd'hui · ${ee(t)}`},paginationState(){var r,a,s;const n=(r=this.currentConv)==null?void 0:r.id,t=n?(s=(a=this.s)==null?void 0:a.paginationByConv)==null?void 0:s[n]:null;return{loading:!!(t!=null&&t.loading),hasMore:!!(t!=null&&t.nextCursor)}}},watch:{latestUnreads:{handler(n){const t=new Set(n.map(i=>i.convId)),r=this.dismissedPeeks||{},a=Object.keys(r);if(!a.length)return;const s={};let o=!1;for(const i of a)t.has(i)?s[i]=r[i]:o=!0;o&&(this.dismissedPeeks=s)},deep:!0},"currentConv.id":{handler(n){this.resetRevealQueue(),this.convOpenedAt=Date.now(),this.moreOpen=!1,this.renameDialogOpen=!1,this.resetApprovalPacing(),this.isViewingThread&&(this.unreadAnchorTs=n&&this.readState[n]||"",this.unreadBoundaryTs=n?new Date().toISOString():"")},immediate:!0},isViewingThread(n,t){var r;if(n&&!t){const a=(r=this.currentConv)==null?void 0:r.id;this.unreadAnchorTs=a&&this.readState[a]||"",this.unreadBoundaryTs=a?new Date().toISOString():""}else n||(this.unreadAnchorTs="",this.unreadBoundaryTs="")},pendingApproval:{handler(n,t){if(n&&!t){const r=n!=null&&n.created_at?Date.parse(n.created_at):NaN;if(!(Number.isFinite(r)&&r>=this.convOpenedAt)){this.resetApprovalPacing();return}this.bumpApprovalSettle(2600)}else!n&&t&&this.resetApprovalPacing()},immediate:!1},streamingActive(n,t){n!==t&&this.pendingApproval&&this.pendingApproval.id!==this.approvalLatchId&&this.bumpApprovalSettle()},approvalReady(n){n&&this.pendingApproval&&(this.approvalLatchId=this.pendingApproval.id)},floatVisible:{handler(n){this.$nextTick(()=>this.syncFloatObserver(n))},immediate:!0},currentConvMessages(n){this.paceMessages(n),(this.isOpen||this.isEmbedded)&&!this.historyOpen&&this.currentConv&&this.markConvRead(this.currentConv)}},async mounted(){if(typeof document<"u"&&!document.getElementById(ae)){const n=document.createElement("style");n.id=ae,n.textContent=ce,document.head.appendChild(n)}this.hydrateReadState(),await this.boot(),this.isEmbedded&&this.store&&await this.open()},beforeUnmount(){this.cancelReveals(),this.disconnectFloatRO(),this.resetApprovalPacing(),this.teardownNotifications(),this.store&&this.store.destroy()},methods:{async boot(){if(!this.canBoot){console.warn("[messenger] boot skipped — missing creds");return}try{this.transport=e.markRaw(ie({baseUrl:this.baseUrl,widgetId:this.widgetId,userId:this.userId,userHash:this.userHash})),this.store=e.markRaw(le(this.transport)),this.hydrateNotifPref(),this.setupNotifications(),await this.store.start(),this.customer&&typeof this.customer=="object"&&await this.store.applyCustomer(this.customer)}catch(n){console.error("[ww-messenger] bootstrap failed",n),this.bootError=(n==null?void 0:n.message)||String(n)}},async refresh(){this.store&&this.store.destroy(),this.cancelReveals(),this.teardownNotifications(),this.convOpenedAt=0,this.transport=null,this.store=null,this.isOpen=!1,this.draft="",this.busy=!1,this.bootError=null,this.pendingAttachments=[],this.feedbackBusy=!1,this.feedbackDone=!1,this.historyOpen=!1,this.moreOpen=!1,this.renameDialogOpen=!1,this.draftConv=null,this.activeConvId=null,this.showOnboarding=!1,await this.boot(),this.isEmbedded&&this.store&&await this.open()},syncFloatObserver(n){if(this.disconnectFloatRO(),!n){this.floatHeight=0;return}const t=this.$refs.floatEl;if(t){if(typeof ResizeObserver>"u"){this.floatHeight=Math.ceil(t.getBoundingClientRect().height+8);return}this.floatRO=new ResizeObserver(r=>{const a=r[0];if(!a)return;const s=Math.ceil(a.contentRect.height+8);s!==this.floatHeight&&(this.floatHeight=s,this.$nextTick(()=>{var o,i;(i=(o=this.$refs.messageList)==null?void 0:o.scrollToBottom)==null||i.call(o)}))}),this.floatRO.observe(t)}},disconnectFloatRO(){if(this.floatRO){try{this.floatRO.disconnect()}catch{}this.floatRO=null}},async open(){this.isOpen=!0,this.store&&this.store.setPanelOpen(!0);const n=this.currentConv;if(n&&!n._draft){this.activeConvId==null&&(this.activeConvId=n.id);try{await this.store.openConversation(n.id)}catch(t){console.error("[ww-messenger] load messages failed",t)}this.markConvRead(n)}},close(){this.isOpen=!1,this.store&&this.store.setPanelOpen(!1)},async openFromPeek(n){var r,a;const t=n||((r=this.latestUnreads[0])==null?void 0:r.convId);t&&t!==((a=this.currentConv)==null?void 0:a.id)&&(this.draftConv=null,this.activeConvId=t,this.showOnboarding=!1),await this.open()},dismissPeek(n){const t=this.latestUnreads.find(r=>r.convId===n);t&&(this.dismissedPeeks={...this.dismissedPeeks,[n]:t.ts})},startConv(){this.draftConv={id:"__draft__",_draft:!0,name:"",created_at:new Date().toISOString()},this.activeConvId=null,this.showOnboarding=!1,this.focusComposer()},async ensureRealConv(){const n=this.currentConv;if(!n)return null;if(!n._draft)return n;if(this.busy)return null;this.busy=!0;try{const t=await this.store.createConversation({});return this.draftConv=null,this.activeConvId=t.id,await this.store.openConversation(t.id),this.markConvRead(t),t}catch(t){return console.error("[ww-messenger] create conv failed",t),this.bootError=(t==null?void 0:t.message)||String(t),null}finally{this.busy=!1}},focusComposer(){this.$nextTick(()=>{var n;return(n=this.$refs.composer)==null?void 0:n.focus()})},toggleMore(){this.historyOpen=!1,this.moreOpen=!this.moreOpen},goHome(){this.historyOpen=!1,this.moreOpen=!1,this.draftConv=null,this.activeConvId=null,this.showOnboarding=!0},async onDrawerPick(n){if(!(n!=null&&n.id)||!this.store)return;this.historyOpen=!1,this.draftConv=null,this.activeConvId=n.id,this.showOnboarding=!1;try{await this.store.openConversation(n.id)}catch(r){console.error("[ww-messenger] open conv failed",r)}const t=this.allConversations.find(r=>r.id===n.id);t&&this.markConvRead(t)},async onDrawerNew(){this.historyOpen=!1,await this.startConv()},async onMoreAction(n){var t,r;switch(this.moreOpen=!1,n){case"history":this.historyOpen=!0;break;case"rename":this.openRenameDialog();break;case"export":Xe(this.currentConv,this.currentConv?(r=(t=this.s)==null?void 0:t.messagesByConv)==null?void 0:r[this.currentConv.id]:[]);break;case"status":if(this.statusUrl)try{window.open(this.statusUrl,"_blank","noopener")}catch{}break;case"help":if(this.helpUrl)try{window.open(this.helpUrl,"_blank","noopener")}catch{}break}},openRenameDialog(){const n=this.currentConv;!n||n._draft||(this.renameDialogOpen=!0)},async onRenameSubmit(n){const t=this.currentConv;if(this.renameDialogOpen=!1,!t||t._draft||!this.store)return;const r=(n||"").trim();if(!(!r||r===t.name))try{await this.store.patchConversation(t.id,{name:r})}catch(a){console.error("[ww-messenger] rename failed",a)}},async onSend(n){let t=this.currentConv;if(!t&&(this.startConv(),t=this.currentConv,!t)||t._draft&&(t=await this.ensureRealConv(),!t))return;const r=t.id,a=this.pendingAttachments.slice();this.pendingAttachments=[],this.unreadAnchorTs="",this.unreadBoundaryTs="",await this.store.send(r,n,{attachments:a.length?a:void 0})},async onSuggestion(n){const t=n==null?void 0:n.label;t&&await this.onSend(t)},async onLoadMore(){var t;const n=(t=this.currentConv)==null?void 0:t.id;!n||!this.store||await this.store.loadMore(n)},async onApprovalCallback(n){const t=this.pendingApproval;t&&await this.store.clickCallback(t.id,n)},async onFormSubmit({values:n}){const t=this.pendingForm;if(!(t!=null&&t.form))return;const r=qe(t.form,n);if(!r)return;let a=this.currentConv;a&&(a._draft&&(a=await this.ensureRealConv(),!a)||await this.store.send(a.id,r,{metadata:{artifact:Ke(t.form,n)}}))},async onAttach(n){if(!(!n||!this.transport))try{const t=await this.transport.uploadAttachment(n);this.pendingAttachments.push({type:t.type||"file",path:t.path,name:n.name||"fichier",mime_type:n.type,size_bytes:n.size})}catch(t){console.error("[ww-messenger] attachment upload failed",t)}},async onQuickLink(n){if(n){if(n.url){try{window.open(n.url,"_blank","noopener")}catch{}return}this.currentConv||this.startConv(),await this.onSend(n.label)}},async onFeedback({rating:n,comment:t}){if(this.currentConv){this.feedbackBusy=!0;try{await this.store.submitFeedback(this.currentConv.id,{rating:n,comment:t}),this.feedbackDone=!0}catch(r){console.error("[ww-messenger] feedback failed",r)}finally{this.feedbackBusy=!1}}}}},Ks={key:0,class:"wm-loading","aria-busy":"true","aria-live":"polite"},Ws={key:0,class:"wm-state"},Gs={class:"wm-state__err"},Ys={class:"wm-state__errSub"},Js={class:"wm-bottom"},Xs={key:0,ref:"floatEl",class:"wm-float"},Qs={key:1,class:"wm-actionWait",role:"status","aria-live":"polite"},Zs={class:"wm-actionWait__lbl"},ea={key:2,class:"wm-attached"},ta=["onClick"];function na(n,t,r,a,s,o){const i=e.resolveComponent("Launcher"),l=e.resolveComponent("Header"),f=e.resolveComponent("Onboarding"),v=e.resolveComponent("MessageList"),y=e.resolveComponent("ApprovalCard"),b=e.resolveComponent("FormCard"),S=e.resolveComponent("Feedback"),k=e.resolveComponent("SuggestionChips"),A=e.resolveComponent("Composer"),w=e.resolveComponent("MoreMenu"),M=e.resolveComponent("RenameDialog"),x=e.resolveComponent("HistoryDrawer");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-root",`wm-root--${r.displayMode}`])},[!s.isOpen&&!o.isEmbedded?(e.openBlock(),e.createBlock(i,{key:0,"unread-count":o.unreadCount,peeks:o.launcherPeeks,onOpen:o.openFromPeek,onDismiss:o.dismissPeek},null,8,["unread-count","peeks","onOpen","onDismiss"])):e.createCommentVNode("",!0),s.isOpen||o.isEmbedded?(e.openBlock(),e.createElementBlock("section",{key:1,class:e.normalizeClass(["wm-panel",`wm-panel--${r.displayMode}`]),style:e.normalizeStyle(s.floatHeight?{"--wm-float-h":s.floatHeight+"px"}:null),role:"dialog","aria-label":"Messenger"},[!o.ready&&!o.error?(e.openBlock(),e.createElementBlock("div",Ks,[o.isEmbedded?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-loading__close","aria-label":"Réduire",onClick:t[0]||(t[0]=(...V)=>o.close&&o.close(...V))},[...t[6]||(t[6]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])),t[7]||(t[7]=e.createElementVNode("div",{class:"wm-loading__spinner","aria-hidden":"true"},null,-1))])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createVNode(l,{title:o.headerTitle,escalated:o.isEscalated,"agent-name":o.humanAgentName,"agent-avatar-url":o.humanAgentAvatarUrl,"team-members":o.teamMembers,"response-label":o.responseLabel,"show-identity":!!o.currentConv,"show-back":o.canBack,"show-close":!o.isEmbedded,"more-active":s.moreOpen,onBack:o.goHome,onMore:o.toggleMore,onClose:o.close},null,8,["title","escalated","agent-name","agent-avatar-url","team-members","response-label","show-identity","show-back","show-close","more-active","onBack","onMore","onClose"]),o.error?(e.openBlock(),e.createElementBlock("div",Ws,[e.createElementVNode("div",Gs,[t[9]||(t[9]=e.createElementVNode("div",{class:"wm-state__errIcon"},[e.createElementVNode("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})])],-1)),e.createElementVNode("div",null,[t[8]||(t[8]=e.createElementVNode("div",{class:"wm-state__errTitle"},"Connexion impossible",-1)),e.createElementVNode("div",Ys,e.toDisplayString(o.error),1)])])])):o.currentConv?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createVNode(v,{ref:"messageList",messages:o.displayedMessages,"streaming-active":o.streamingActive,"date-label":o.dateLabel,"conversation-id":o.currentConv?o.currentConv.id:null,"loading-more":o.paginationState.loading,"has-more":o.paginationState.hasMore,"unread-anchor-ts":n.unreadAnchorTs,"unread-boundary-ts":n.unreadBoundaryTs,onLoadMore:o.onLoadMore},null,8,["messages","streaming-active","date-label","conversation-id","loading-more","has-more","unread-anchor-ts","unread-boundary-ts","onLoadMore"]),e.createElementVNode("div",Js,[o.floatVisible?(e.openBlock(),e.createElementBlock("div",Xs,[o.approvalReady?(e.openBlock(),e.createBlock(y,{key:0,action:o.approvalTitle,detail:o.approvalDetail,callbacks:o.pendingApproval.callbacks,onCallback:o.onApprovalCallback},null,8,["action","detail","callbacks","onCallback"])):o.pendingForm?(e.openBlock(),e.createBlock(b,{key:o.pendingForm.message&&o.pendingForm.message.id,form:o.pendingForm.form,onSubmit:o.onFormSubmit},null,8,["form","onSubmit"])):o.showFeedback?(e.openBlock(),e.createBlock(S,{key:2,busy:s.feedbackBusy,done:s.feedbackDone,onSubmit:o.onFeedback},null,8,["busy","done","onSubmit"])):(e.openBlock(),e.createBlock(k,{key:3,items:o.suggestions,onSelect:o.onSuggestion},null,8,["items","onSelect"]))],512)):e.createCommentVNode("",!0),o.actionInFlight?(e.openBlock(),e.createElementBlock("div",Qs,[t[10]||(t[10]=e.createElementVNode("span",{class:"wm-actionWait__spinner","aria-hidden":"true"},null,-1)),e.createElementVNode("span",Zs,e.toDisplayString(o.actionInFlightName)+" en cours, veuillez patienter…",1)])):(e.openBlock(),e.createBlock(A,{key:2,ref:"composer",modelValue:s.draft,"onUpdate:modelValue":t[1]||(t[1]=V=>s.draft=V),placeholder:o.composerPlaceholder,disabled:!!o.pendingApproval,"attach-label":"Joindre un fichier",onSend:o.onSend,onAttach:o.onAttach},null,8,["modelValue","placeholder","disabled","onSend","onAttach"]))]),s.moreOpen?(e.openBlock(),e.createBlock(w,{key:0,"can-rename":!!o.currentConv&&!o.currentConv._draft,"can-export":!!o.currentConv&&!o.currentConv._draft,"sound-enabled":n.soundEnabled,"browser-notif-enabled":n.browserNotifEnabled,"status-url":o.statusUrl,"help-url":o.helpUrl,onClose:t[2]||(t[2]=V=>s.moreOpen=!1),onSoundToggle:n.onSoundToggle,onBrowserNotifToggle:n.onBrowserNotifToggle,onAction:o.onMoreAction},null,8,["can-rename","can-export","sound-enabled","browser-notif-enabled","status-url","help-url","onSoundToggle","onBrowserNotifToggle","onAction"])):e.createCommentVNode("",!0),s.renameDialogOpen&&o.currentConv&&!o.currentConv._draft?(e.openBlock(),e.createBlock(M,{key:1,"initial-value":o.currentConv.name||"",title:"Modifier le titre de la conversation",onClose:t[3]||(t[3]=V=>s.renameDialogOpen=!1),onSubmit:o.onRenameSubmit},null,8,["initial-value","onSubmit"])):e.createCommentVNode("",!0),s.pendingAttachments.length?(e.openBlock(),e.createElementBlock("div",ea,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.pendingAttachments,(V,O)=>(e.openBlock(),e.createElementBlock("div",{key:O,class:"wm-attached__chip"},[t[12]||(t[12]=e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"})],-1)),e.createElementVNode("span",null,e.toDisplayString(V.name),1),e.createElementVNode("button",{type:"button","aria-label":"Retirer",onClick:$=>s.pendingAttachments.splice(O,1)},[...t[11]||(t[11]=[e.createElementVNode("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,ta)]))),128))])):e.createCommentVNode("",!0)],64)):(e.openBlock(),e.createBlock(f,{key:1,"welcome-message":o.widgetWelcomeMessage,"agent-name":o.agentName,"quick-links":o.quickLinks,"open-threads":o.openThreads,busy:s.busy,onStart:o.startConv,onSelect:o.onQuickLink,onResume:o.onDrawerPick},null,8,["welcome-message","agent-name","quick-links","open-threads","busy","onStart","onSelect","onResume"])),s.historyOpen?(e.openBlock(),e.createBlock(x,{key:3,conversations:o.drawerConversations,"active-id":o.currentConv?o.currentConv.id:null,onClose:t[4]||(t[4]=V=>s.historyOpen=!1),onNew:o.onDrawerNew,onPick:o.onDrawerPick},null,8,["conversations","active-id","onNew","onPick"])):e.createCommentVNode("",!0),s.moreOpen&&!o.currentConv?(e.openBlock(),e.createBlock(w,{key:4,"can-rename":!1,"can-export":!1,"sound-enabled":n.soundEnabled,"browser-notif-enabled":n.browserNotifEnabled,"status-url":o.statusUrl,"help-url":o.helpUrl,onClose:t[5]||(t[5]=V=>s.moreOpen=!1),onSoundToggle:n.onSoundToggle,onBrowserNotifToggle:n.onBrowserNotifToggle,onAction:o.onMoreAction},null,8,["sound-enabled","browser-notif-enabled","status-url","help-url","onSoundToggle","onBrowserNotifToggle","onAction"])):e.createCommentVNode("",!0)],64))],6)):e.createCommentVNode("",!0)],2)}const $e=N(qs,[["render",na],["__scopeId","data-v-4567b974"]]),ra="0.3.8";exports.AIAvatar=z;exports.AVATAR_COLORS=q;exports.ActionResult=_e;exports.ApprovalCard=xe;exports.ArtifactFormResponse=ge;exports.ArtifactInfoCard=ve;exports.ArtifactRenderer=ke;exports.ArtifactTicket=ye;exports.AttachmentPreview=we;exports.Bubble=Ee;exports.Composer=Te;exports.DEFAULT_BASE_URL=de;exports.Feedback=Ie;exports.FormCard=Oe;exports.Header=pe;exports.HistoryDrawer=De;exports.HumanAvatar=G;exports.Launcher=me;exports.MEDIA_RECORDER_SUPPORTED=Y;exports.MessageList=Ce;exports.Messenger=$e;exports.MoreMenu=Le;exports.Onboarding=fe;exports.SCREEN_CAPTURE_SUPPORTED=j;exports.SuggestionChips=Me;exports.TeamAvatars=he;exports.Typing=Be;exports.VERSION=ra;exports.avatarColor=Q;exports.avatarInitials=Z;exports.captureScreenshotFile=Ve;exports.colors=T;exports.createStore=le;exports.createTransport=ie;exports.default=$e;exports.formatTime=ee;exports.guessAttachmentKind=Jr;exports.pickRecorderMime=Ne;exports.renderMarkdown=be;exports.startScreenRecording=Ae;exports.tokensCss=ce;exports.uuid=X;exports.v4=X;
50
+ `)}function We(t,n){const r=[],a=Array.isArray(t==null?void 0:t.fields)?t.fields:[];for(const s of a){if(!(s!=null&&s.key)||!(s!=null&&s.label))continue;const o=n==null?void 0:n[s.key];if(o==null||o==="")continue;const i=he(s,o);if(!i)continue;const l=s.type==="textarea"||typeof i=="string"&&(i.length>60||i.includes(`
51
+ `));r.push({label:s.label,value:i,multiline:l})}return{kind:"form_response",data:{title:(t==null?void 0:t.title)||"Formulaire",fields:r}}}function G(t){var r;const n=(r=t==null?void 0:t.author)==null?void 0:r.type;return n==="agent_ia"||n==="agent_human"}function R(t){if(t==null)return null;const n=typeof t=="number"?t:Number(t);return Number.isFinite(n)?n:null}function oe(t,n){let r=(t==null?void 0:t.last_message_at)||(t==null?void 0:t.updated_at)||(t==null?void 0:t.created_at)||"";for(const a of n)a!=null&&a.created_at&&a.created_at>r&&(r=a.created_at);return r}function Ge(t,n){var r,a,s;for(let o=n.length-1;o>=0;o--){const i=n[o];if(!i)continue;const l=typeof i.text_md=="string"?i.text_md.trim():"";if(l)return(((r=i.author)==null?void 0:r.type)==="user"?"Vous : ":"")+l.replace(/\s+/g," ");const p=(a=i.payload)==null?void 0:a.attachments;if(Array.isArray(p)&&p.length)return"📎 Pièce jointe"}return(t==null?void 0:t.last_message_preview)||(t==null?void 0:t.preview)||((s=t==null?void 0:t.metadata)==null?void 0:s.last_preview)||""}function Ye(t){return(t==null?void 0:t.name)||((t==null?void 0:t.type)==="user"?"Vous":(t==null?void 0:t.type)==="agent_human"?"Agent":(t==null?void 0:t.type)==="agent_ia"?"Assistant IA":"Système")}function Xe(t,n){const r=[`# ${t.name||"Conversation"}`,t.created_at?`Créée le : ${t.created_at}`:"",""];for(const a of n){if(!a)continue;const s=(a.text_md||"").trim();if(!s)continue;const o=Ye(a.author),i=a.created_at?new Date(a.created_at).toLocaleString("fr-FR"):"";r.push(`[${i}] ${o} :`),r.push(s),r.push("")}return r.join(`
52
+ `)}function Je(t,n){if(!t)return;const r=Xe(t,n||[]),a=new Blob([r],{type:"text/plain;charset=utf-8"});try{const s=URL.createObjectURL(a),o=document.createElement("a");o.href=s,o.download=`${(t.name||"conversation").replace(/[^a-z0-9-_]+/gi,"_")}.txt`,document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>URL.revokeObjectURL(s),1e3)}catch(s){console.error("[ww-messenger] export failed",s)}}const Qe={data(){const t=typeof Notification<"u";return{notifPermission:t?Notification.permission:"denied",soundEnabled:!0,browserNotifEnabled:t&&Notification.permission==="granted",_notifUnsub:null,_audioCtx:null}},methods:{setupNotifications(){this.transport&&(this.teardownNotifications(),this._notifUnsub=this.transport.on("message",this.onIncomingNotification))},teardownNotifications(){var t,n;if(this._notifUnsub){try{this._notifUnsub()}catch{}this._notifUnsub=null}if(this._audioCtx){try{(n=(t=this._audioCtx).close)==null||n.call(t)}catch{}this._audioCtx=null}},soundStorageKey(){return`wm:notif:sound:${this.widgetId||""}:${this.userId||""}`},browserNotifStorageKey(){return`wm:notif:browser:${this.widgetId||""}:${this.userId||""}`},hydrateNotifPref(){try{if(typeof localStorage>"u")return;const t=localStorage.getItem(this.soundStorageKey());t==="0"?this.soundEnabled=!1:t==="1"&&(this.soundEnabled=!0);const n=localStorage.getItem(this.browserNotifStorageKey());n==="0"?this.browserNotifEnabled=!1:n==="1"&&(this.browserNotifEnabled=typeof Notification<"u"&&Notification.permission==="granted")}catch{}},persistSoundPref(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.soundStorageKey(),this.soundEnabled?"1":"0")}catch{}},persistBrowserNotifPref(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.browserNotifStorageKey(),this.browserNotifEnabled?"1":"0")}catch{}},onSoundToggle(t){this.soundEnabled=!!t,this.persistSoundPref()},async onBrowserNotifToggle(t){if(typeof Notification>"u"){this.browserNotifEnabled=!1,this.persistBrowserNotifPref();return}if(!t){this.browserNotifEnabled=!1,this.persistBrowserNotifPref();return}let n=Notification.permission;if(n==="default"){try{n=await Notification.requestPermission()}catch(r){console.warn("[ww-messenger] notif permission request failed",r),n="denied"}this.notifPermission=n}this.browserNotifEnabled=n==="granted",this.persistBrowserNotifPref()},onIncomingNotification(t){var i;if(!this.soundEnabled&&!this.browserNotifEnabled)return;const n=t==null?void 0:t.conversation_id,r=t==null?void 0:t.message;if(!n||!r||!G(r))return;const a=r!=null&&r.created_at?Date.parse(r.created_at):NaN;if(Number.isFinite(a)&&a<this.convOpenedAt-1e3)return;const s=typeof document<"u"&&document.hidden;this.isOpen&&!s&&((i=this.currentConv)==null?void 0:i.id)===n||(this.soundEnabled&&this.playNotificationSound(),this.browserNotifEnabled&&this.showBrowserNotification(n,r))},playNotificationSound(){if(typeof window>"u")return;const t=window.AudioContext||window.webkitAudioContext;if(t)try{this._audioCtx||(this._audioCtx=new t);const n=this._audioCtx;if(n.state==="suspended")try{n.resume()}catch{}const r=n.currentTime,a=n.createOscillator(),s=n.createGain();a.connect(s),s.connect(n.destination),a.type="sine",a.frequency.setValueAtTime(880,r),a.frequency.exponentialRampToValueAtTime(1320,r+.08),s.gain.setValueAtTime(0,r),s.gain.linearRampToValueAtTime(.12,r+.02),s.gain.exponentialRampToValueAtTime(1e-4,r+.28),a.start(r),a.stop(r+.32)}catch{}},showBrowserNotification(t,n){var i;if(typeof Notification>"u"||Notification.permission!=="granted")return;const r=this.allConversations.find(l=>l.id===t),a=(r==null?void 0:r.name)||((i=this.widget)==null?void 0:i.name)||"Nouveau message",s=typeof(n==null?void 0:n.text_md)=="string"?n.text_md.trim():"",o=s?s.slice(0,140):"Vous avez un nouveau message";try{const l=new Notification(a,{body:o,tag:`wm-${t}`,renotify:!1,silent:!0});l.onclick=()=>{try{window.focus()}catch{}this.draftConv=null,this.showOnboarding=!1,this.activeConvId=t,this.isOpen=!0,this.store&&this.store.setPanelOpen(!0);try{l.close()}catch{}}}catch(l){console.warn("[ww-messenger] notification failed",l)}}}},Ze=450,et=50,tt=900,nt=12e3,rt=300,ot={data(){return{revealedAt:{},nextRevealAt:0,revealTimers:[]}},methods:{cancelReveals(){for(const t of this.revealTimers)clearTimeout(t);this.revealTimers=[]},resetRevealQueue(){this.cancelReveals(),this.revealedAt={},this.nextRevealAt=0},scheduleReveal(t){const n=Date.now(),r=((t==null?void 0:t.text_md)||"").length,a=Math.min(nt,Math.max(tt,r*et)),o=Math.max(n+Ze,this.nextRevealAt+rt)+a;this.nextRevealAt=o;const i=Math.max(0,o-n),l=t.id,p=setTimeout(()=>{this.revealedAt={...this.revealedAt,[l]:Date.now()},this.revealTimers=this.revealTimers.filter(v=>v!==p)},i);this.revealTimers.push(p)},paceMessages(t){var a;if(!Array.isArray(t)||!t.length)return;const n=Date.now(),r={...this.revealedAt};for(const s of t){if((s==null?void 0:s.id)==null||r[s.id]!==void 0)continue;if(!G(s)){r[s.id]=n;continue}const o=s!=null&&s.created_at?Date.parse(s.created_at):NaN;if(!Number.isFinite(o)||o<this.convOpenedAt){r[s.id]=n;continue}const i=typeof(s==null?void 0:s.text_md)=="string"&&s.text_md.trim().length>0,l=Array.isArray((a=s==null?void 0:s.payload)==null?void 0:a.attachments)&&s.payload.attachments.length>0;if(!i&&!l){r[s.id]=n;continue}r[s.id]=0,this.scheduleReveal(s)}this.revealedAt=r}}},st={data(){return{approvalSettled:!0,approvalSettleTimer:null,approvalLatchId:null}},methods:{resetApprovalPacing(){this.approvalSettleTimer&&(clearTimeout(this.approvalSettleTimer),this.approvalSettleTimer=null),this.approvalSettled=!0,this.approvalLatchId=null},bumpApprovalSettle(t=800){this.approvalSettled=!1,this.approvalSettleTimer&&clearTimeout(this.approvalSettleTimer),this.approvalSettleTimer=setTimeout(()=>{this.approvalSettled=!0,this.approvalSettleTimer=null},t)}}},at=300,it={data(){return{unreadAnchorId:null,unreadBoundaryTs:""}},created(){this._readMarkerTimer=null,this._readMarkerPending=null},beforeUnmount(){this._readMarkerTimer&&(clearTimeout(this._readMarkerTimer),this._readMarkerTimer=null),this._readMarkerPending=null},methods:{markConvRead(t){var o,i;if(!(t!=null&&t.id)||t._draft||!this.store)return;const n=((i=(o=this.s)==null?void 0:o.messagesByConv)==null?void 0:i[t.id])||[],r=lt(n);if(r==null)return;const a=R(t.last_read_message_id),s=R(r);s!=null&&(a!=null&&s<=a||(this._readMarkerPending={convId:t.id,messageId:r},!this._readMarkerTimer&&(this._readMarkerTimer=setTimeout(()=>{const l=this._readMarkerPending;this._readMarkerPending=null,this._readMarkerTimer=null,l&&this.store&&this.store.markConversationRead(l.convId,l.messageId)},at))))}}};function lt(t){for(let n=t.length-1;n>=0;n--){const r=t[n];if(!(!r||r._pending)&&R(r.id)!=null)return r.id}return null}const N=(t,n)=>{const r=t.__vccOpts||t;for(const[a,s]of n)r[a]=s;return r},ct={name:"WmHumanAvatar",props:{name:{type:String,default:""},avatarUrl:{type:String,default:null},size:{type:Number,default:26},tail:{type:Boolean,default:!1}},computed:{bg(){return this.avatarUrl?"transparent":Z(this.name)},initials(){return ee(this.name)}}},dt=["src","alt"];function ut(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-huav",{"wm-huav--tail":r.tail}]),style:e.normalizeStyle({width:r.size+"px",height:r.size+"px","--wm-avr":Math.round(r.size*.32)+"px",background:o.bg})},[r.avatarUrl?(e.openBlock(),e.createElementBlock("img",{key:0,src:r.avatarUrl,alt:r.name||""},null,8,dt)):(e.openBlock(),e.createElementBlock("span",{key:1,style:e.normalizeStyle({fontSize:r.size*.36+"px"})},e.toDisplayString(o.initials),5))],6)}const Y=N(ct,[["render",ut],["__scopeId","data-v-07246775"]]),mt=3,ht={name:"WmLauncher",components:{HumanAvatar:Y},props:{unreadCount:{type:Number,default:0},peeks:{type:Array,default:()=>[]}},emits:["open","dismiss"],computed:{visiblePeeks(){return this.peeks.slice(0,mt).reverse()}}},ft={class:"wm-launcherWrap"},pt=["aria-label","onClick","onKeydown"],_t=["onClick"],gt={class:"wm-peek__avatar"},vt=["aria-label"],yt={class:"wm-peek__body"},kt={class:"wm-peek__head"},wt={class:"wm-peek__name"},bt={class:"wm-peek__text"},Et=["onClick"],Ct=["aria-label"];function Bt(t,n,r,a,s,o){const i=e.resolveComponent("HumanAvatar");return e.openBlock(),e.createElementBlock("div",ft,[e.createVNode(e.Transition,{name:"wm-peek"},{default:e.withCtx(()=>[o.visiblePeeks.length?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["wm-peekStack",{"wm-peekStack--multi":o.visiblePeeks.length>1}])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.visiblePeeks,(l,p)=>(e.openBlock(),e.createElementBlock("div",{key:l.convId,class:"wm-peek",style:e.normalizeStyle({"--depth":o.visiblePeeks.length-1-p,zIndex:p+1}),role:"button",tabindex:"0","aria-label":`Ouvrir la conversation avec ${l.senderName||"l'agent"}`,onClick:v=>t.$emit("open",l.convId),onKeydown:[e.withKeys(e.withModifiers(v=>t.$emit("open",l.convId),["prevent"]),["enter"]),e.withKeys(e.withModifiers(v=>t.$emit("open",l.convId),["prevent"]),["space"])]},[e.createElementVNode("button",{type:"button",class:"wm-peek__close","aria-label":"Ignorer",onClick:e.withModifiers(v=>t.$emit("dismiss",l.convId),["stop"])},[...n[1]||(n[1]=[e.createElementVNode("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,_t),e.createElementVNode("div",gt,[e.createVNode(i,{name:l.senderName,"avatar-url":l.senderAvatarUrl,size:34},null,8,["name","avatar-url"]),l.count>1?(e.openBlock(),e.createElementBlock("span",{key:0,class:"wm-peek__avatarBadge","aria-label":`${l.count} messages non lus`},e.toDisplayString(l.count>9?"9+":l.count),9,vt)):e.createCommentVNode("",!0)]),e.createElementVNode("div",yt,[e.createElementVNode("div",kt,[e.createElementVNode("span",wt,e.toDisplayString(l.senderName||"Agent"),1),n[2]||(n[2]=e.createElementVNode("span",{class:"wm-peek__action"}," vous a répondu",-1))]),e.createElementVNode("p",bt,e.toDisplayString(l.preview),1)]),e.createElementVNode("button",{type:"button",class:"wm-peek__open",onClick:e.withModifiers(v=>t.$emit("open",l.convId),["stop"])},"Ouvrir",8,Et)],44,pt))),128))],2)):e.createCommentVNode("",!0)]),_:1}),e.createElementVNode("button",{type:"button",class:"wm-launcher","aria-label":"Ouvrir le messenger",onClick:n[0]||(n[0]=l=>t.$emit("open"))},[n[3]||(n[3]=e.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})],-1)),r.unreadCount>0?(e.openBlock(),e.createElementBlock("span",{key:0,class:"wm-launcher__badge","aria-label":`${r.unreadCount} conversation${r.unreadCount>1?"s":""} non lue${r.unreadCount>1?"s":""}`},e.toDisplayString(r.unreadCount>9?"9+":r.unreadCount),9,Ct)):e.createCommentVNode("",!0)])])}const fe=N(ht,[["render",Bt],["__scopeId","data-v-525fd423"]]),Nt={name:"WmAIAvatar",props:{size:{type:Number,default:26},pulse:{type:Boolean,default:!1},tail:{type:Boolean,default:!1}}},St={key:0,class:"wm-aiav__pulse"},At=["width","height"];function Vt(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-aiav",{"wm-aiav--tail":r.tail}]),style:e.normalizeStyle({width:r.size+"px",height:r.size+"px","--wm-avr":r.size*.32+"px"})},[r.pulse?(e.openBlock(),e.createElementBlock("div",St)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(["wm-aiav__inner",{"wm-aiav__inner--glow":r.pulse}])},[(e.openBlock(),e.createElementBlock("svg",{width:r.size*.5,height:r.size*.5,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true"},[...n[0]||(n[0]=[e.createElementVNode("path",{d:"M12 2 L13.5 9 L20 10.5 L13.5 12 L12 19 L10.5 12 L4 10.5 L10.5 9 Z",fill:"white",opacity:"0.92"},null,-1),e.createElementVNode("circle",{cx:"19",cy:"5",r:"1.5",fill:"white",opacity:"0.55"},null,-1),e.createElementVNode("circle",{cx:"5",cy:"18",r:"1",fill:"white",opacity:"0.38"},null,-1)])],8,At))],2)],6)}const U=N(Nt,[["render",Vt],["__scopeId","data-v-8c924688"]]),Mt={name:"WmTeamAvatars",props:{members:{type:Array,default:()=>[]},responseLabel:{type:String,default:""}},computed:{visible(){return Array.isArray(this.members)&&this.members.length>0},stackWidth(){return Math.min(this.members.length,3)===1?20:16+Math.min(this.members.length,3)*13}},methods:{colorFor(t){return t.avatar_url?"transparent":Z(t.name||"")},initialsFor(t){return ee(t.name||"")}}},Tt={key:0,class:"wm-team"},xt=["src","alt"],Ot={key:1},It={key:0,class:"wm-team__label"};function Dt(t,n,r,a,s,o){return o.visible?(e.openBlock(),e.createElementBlock("div",Tt,[e.createElementVNode("div",{class:"wm-team__stack",style:e.normalizeStyle({width:o.stackWidth+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.members.slice(0,3),(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-team__pill",style:e.normalizeStyle({left:l*13+"px",zIndex:3-l,background:o.colorFor(i)})},[i.avatar_url?(e.openBlock(),e.createElementBlock("img",{key:0,src:i.avatar_url,alt:i.name||""},null,8,xt)):(e.openBlock(),e.createElementBlock("span",Ot,e.toDisplayString(o.initialsFor(i)),1))],4))),128))],4),r.responseLabel?(e.openBlock(),e.createElementBlock("span",It,e.toDisplayString(r.responseLabel),1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)}const pe=N(Mt,[["render",Dt],["__scopeId","data-v-3659b9c1"]]),Lt={name:"WmHeader",components:{AIAvatar:U,HumanAvatar:Y,TeamAvatars:pe},props:{title:{type:String,default:"Nouvelle conversation"},escalated:{type:Boolean,default:!1},agentName:{type:String,default:""},agentAvatarUrl:{type:String,default:null},showBack:{type:Boolean,default:!1},teamMembers:{type:Array,default:()=>[]},responseLabel:{type:String,default:""},showClose:{type:Boolean,default:!0},showMore:{type:Boolean,default:!0},moreActive:{type:Boolean,default:!1},showIdentity:{type:Boolean,default:!0}},emits:["back","close","more"],computed:{hasTeam(){return Array.isArray(this.teamMembers)&&this.teamMembers.length>0},displayedTeamMembers(){const t=Array.isArray(this.teamMembers)?this.teamMembers:[];if(t.length<=3)return t;const n=new Date().getHours()%t.length,r=[];for(let a=0;a<3;a++)r.push(t[(n+a)%t.length]);return r}}},Rt={class:"wm-header"},Ft={key:1,style:{width:"30px",height:"30px","flex-shrink":"0"}},$t={class:"wm-header__avatar"},Pt={class:"wm-header__main"},Ut={class:"wm-header__title"},jt={key:3,class:"wm-header__fill"},zt={class:"wm-header__actions"};function Ht(t,n,r,a,s,o){const i=e.resolveComponent("HumanAvatar"),l=e.resolveComponent("AIAvatar"),p=e.resolveComponent("TeamAvatars");return e.openBlock(),e.createElementBlock("div",Rt,[r.showBack?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-header__icon","aria-label":"Retour à l'accueil",onClick:n[0]||(n[0]=v=>t.$emit("back"))},[...n[3]||(n[3]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M19 12H5M12 5l-7 7 7 7"})],-1)])])):(e.openBlock(),e.createElementBlock("div",Ft)),r.showIdentity?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createElementVNode("div",$t,[r.escalated?(e.openBlock(),e.createBlock(i,{key:0,name:r.agentName,"avatar-url":r.agentAvatarUrl,size:30},null,8,["name","avatar-url"])):(e.openBlock(),e.createBlock(l,{key:1,size:30}))]),e.createElementVNode("div",Pt,[e.createElementVNode("div",Ut,e.toDisplayString(r.title),1)]),o.hasTeam?(e.openBlock(),e.createBlock(p,{key:0,members:o.displayedTeamMembers,"response-label":""},null,8,["members"])):e.createCommentVNode("",!0)],64)):(e.openBlock(),e.createElementBlock("div",jt)),e.createElementVNode("div",zt,[r.showMore?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:e.normalizeClass(["wm-header__icon",{"wm-header__icon--active":r.moreActive}]),"aria-label":"Plus d'options",title:"Plus d'options",onClick:n[1]||(n[1]=v=>t.$emit("more"))},[...n[4]||(n[4]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},[e.createElementVNode("circle",{cx:"12",cy:"5",r:"1.6"}),e.createElementVNode("circle",{cx:"12",cy:"12",r:"1.6"}),e.createElementVNode("circle",{cx:"12",cy:"19",r:"1.6"})],-1)])],2)):e.createCommentVNode("",!0),r.showClose?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-header__icon","aria-label":"Fermer le widget",title:"Fermer le widget",onClick:n[2]||(n[2]=v=>t.$emit("close"))},[...n[5]||(n[5]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])):e.createCommentVNode("",!0)])])}const _e=N(Lt,[["render",Ht],["__scopeId","data-v-d6406b84"]]),se={book:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253",changelog:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2",status:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z",chat:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z",link:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"},qt={name:"WmOnboarding",components:{AIAvatar:U},props:{welcomeMessage:{type:String,default:""},agentName:{type:String,default:""},quickLinks:{type:Array,default:()=>[]},openThreads:{type:Array,default:()=>[]},busy:{type:Boolean,default:!1}},emits:["start","select","resume"],data(){return{query:""}},computed:{heroTitle(){return this.welcomeMessage?this.welcomeMessage:this.agentName?`Bonjour, je suis ${this.agentName}`:"Bonjour, je suis votre assistant"},heroSub(){return`Posez-moi n'importe quelle question.
53
+ Je réponds en quelques secondes.`},isOddQuickLinks(){return this.quickLinks.length%2===1},quickLinksLayout(){return this.isOddQuickLinks?"wm-onb__qlist":"wm-onb__grid"},filteredThreads(){const t=this.query.trim().toLowerCase();return t?this.openThreads.filter(n=>(n.title||"").toLowerCase().includes(t)||(n.preview||"").toLowerCase().includes(t)):this.openThreads}},methods:{iconPath(t){return se[t]||se.link},formatTs(t){if(!t)return"";const n=new Date(t);if(Number.isNaN(n.getTime()))return"";const r=new Date;if(n.toDateString()===r.toDateString()){const o=String(n.getHours()).padStart(2,"0"),i=String(n.getMinutes()).padStart(2,"0");return`${o}h${i}`}if(r.getTime()-n.getTime()<7*864e5){const o=n.toLocaleDateString("fr-FR",{weekday:"short"});return o.charAt(0).toUpperCase()+o.slice(1)}return n.toLocaleDateString("fr-FR",{day:"2-digit",month:"2-digit"})}}},Kt={class:"wm-onb"},Wt={class:"wm-onb__hero"},Gt={class:"wm-onb__title"},Yt={class:"wm-onb__sub"},Xt={class:"wm-onb__cta"},Jt=["disabled"],Qt={key:0,class:"wm-onb__section"},Zt=["onClick"],en={class:"wm-onb__card-icon"},tn={width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},nn=["d"],rn={class:"wm-onb__card-body"},on={class:"wm-onb__card-title"},sn={key:0,class:"wm-onb__card-sub"},an={key:1,class:"wm-onb__section"},ln={class:"wm-onb__search"},cn={class:"wm-onb__list"},dn=["onClick"],un={key:0,class:"wm-onb__thread-dot","aria-label":"Non lu"},mn={class:"wm-onb__thread-body"},hn={class:"wm-onb__thread-title"},fn={class:"wm-onb__thread-preview"},pn={class:"wm-onb__thread-meta"},_n={key:0,class:"wm-onb__thread-time"},gn={key:0,class:"wm-onb__empty"};function vn(t,n,r,a,s,o){const i=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",Kt,[e.createElementVNode("div",Wt,[e.createVNode(i,{size:56,pulse:!0}),e.createElementVNode("div",Gt,e.toDisplayString(o.heroTitle),1),e.createElementVNode("div",Yt,e.toDisplayString(o.heroSub),1)]),e.createElementVNode("div",Xt,[e.createElementVNode("button",{type:"button",class:"wm-onb__startBtn",disabled:r.busy,onClick:n[0]||(n[0]=l=>t.$emit("start"))},[n[2]||(n[2]=e.createElementVNode("span",{class:"wm-onb__startIcon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M12 5v14M5 12h14"})])],-1)),e.createElementVNode("span",null,e.toDisplayString(r.busy?"…":"Commencer une conversation"),1)],8,Jt)]),r.quickLinks.length?(e.openBlock(),e.createElementBlock("div",Qt,[n[3]||(n[3]=e.createElementVNode("div",{class:"wm-onb__section-title"},"Accès rapide",-1)),e.createElementVNode("div",{class:e.normalizeClass(o.quickLinksLayout)},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.quickLinks,(l,p)=>(e.openBlock(),e.createElementBlock("button",{key:p,type:"button",class:e.normalizeClass(["wm-onb__card",{"wm-onb__card--row":o.isOddQuickLinks}]),onClick:v=>t.$emit("select",l)},[e.createElementVNode("span",en,[(e.openBlock(),e.createElementBlock("svg",tn,[e.createElementVNode("path",{d:o.iconPath(l.icon)},null,8,nn)]))]),e.createElementVNode("span",rn,[e.createElementVNode("span",on,e.toDisplayString(l.label),1),l.description?(e.openBlock(),e.createElementBlock("span",sn,e.toDisplayString(l.description),1)):e.createCommentVNode("",!0)])],10,Zt))),128))],2)])):e.createCommentVNode("",!0),r.openThreads.length?(e.openBlock(),e.createElementBlock("div",an,[n[7]||(n[7]=e.createElementVNode("div",{class:"wm-onb__section-title"},"Conversations récentes",-1)),e.createElementVNode("div",ln,[n[4]||(n[4]=e.createElementVNode("span",{class:"wm-onb__searchIcon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21 21l-4.35-4.35M11 17a6 6 0 100-12 6 6 0 000 12z"})])],-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":n[1]||(n[1]=l=>s.query=l),type:"text",placeholder:"Rechercher dans vos messages","aria-label":"Rechercher dans vos messages"},null,512),[[e.vModelText,s.query]])]),e.createElementVNode("div",cn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.filteredThreads,l=>(e.openBlock(),e.createElementBlock("button",{key:l.id,type:"button",class:"wm-onb__thread",onClick:p=>t.$emit("resume",l)},[e.createElementVNode("span",{class:e.normalizeClass(["wm-onb__thread-icon",{"wm-onb__thread-icon--inverted":!l.unread}])},[n[5]||(n[5]=e.createElementVNode("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true"},[e.createElementVNode("path",{d:"M12 2 L13.5 9 L20 10.5 L13.5 12 L12 19 L10.5 12 L4 10.5 L10.5 9 Z",fill:"currentColor",opacity:"0.92"})],-1)),l.unread?(e.openBlock(),e.createElementBlock("span",un)):e.createCommentVNode("",!0)],2),e.createElementVNode("span",mn,[e.createElementVNode("span",hn,e.toDisplayString(l.title),1),e.createElementVNode("span",fn,e.toDisplayString(l.preview),1)]),e.createElementVNode("span",pn,[o.formatTs(l._ts)?(e.openBlock(),e.createElementBlock("span",_n,e.toDisplayString(o.formatTs(l._ts)),1)):e.createCommentVNode("",!0),n[6]||(n[6]=e.createElementVNode("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",class:"wm-onb__thread-chev","aria-hidden":"true"},[e.createElementVNode("path",{d:"M5 12h14M13 5l7 7-7 7"})],-1))])],8,dn))),128)),o.filteredThreads.length?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",gn," Aucun résultat pour « "+e.toDisplayString(s.query)+" ». ",1))])])):e.createCommentVNode("",!0)])}const ge=N(qt,[["render",vn],["__scopeId","data-v-c85f6958"]]);function yn(t){return typeof t!="string"?"":t.replace(/`([^`]+)`/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1").replace(new RegExp("(?<!\\*)\\*([^*]+)\\*(?!\\*)","g"),"$1").replace(/__([^_]+)__/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\s+/g," ").trim()}const kn={name:"WmActionResult",props:{state:{type:String,default:"success"},label:{type:String,required:!0},detail:{type:String,default:""}},computed:{detailText(){return yn(this.detail)}}},wn={class:"wm-result__icon","aria-hidden":"true"},bn={key:0,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.8","stroke-linecap":"round","stroke-linejoin":"round"},En={key:1,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.6","stroke-linecap":"round","stroke-linejoin":"round"},Cn={key:2,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.4","stroke-linecap":"round","stroke-linejoin":"round"},Bn={key:3,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round"},Nn={class:"wm-result__body"},Sn={class:"wm-result__label"},An={class:"wm-result__detail"};function Vn(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-result",`wm-result--${r.state}`])},[e.createElementVNode("span",wn,[r.state==="success"?(e.openBlock(),e.createElementBlock("svg",bn,[...n[0]||(n[0]=[e.createElementVNode("path",{d:"M20 6L9 17l-5-5"},null,-1)])])):r.state==="rejected"?(e.openBlock(),e.createElementBlock("svg",En,[...n[1]||(n[1]=[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"},null,-1)])])):r.state==="awaiting"?(e.openBlock(),e.createElementBlock("svg",Cn,[...n[2]||(n[2]=[e.createElementVNode("circle",{cx:"12",cy:"12",r:"10"},null,-1),e.createElementVNode("polyline",{points:"12 7 12 12 15 14"},null,-1)])])):(e.openBlock(),e.createElementBlock("svg",Bn,[...n[3]||(n[3]=[e.createElementVNode("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"},null,-1),e.createElementVNode("line",{x1:"12",y1:"9",x2:"12",y2:"13"},null,-1),e.createElementVNode("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"},null,-1)])]))]),e.createElementVNode("span",Nn,[e.createElementVNode("span",Sn,e.toDisplayString(r.label),1),o.detailText?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[n[4]||(n[4]=e.createElementVNode("span",{class:"wm-result__sep","aria-hidden":"true"}," · ",-1)),e.createElementVNode("span",An,e.toDisplayString(o.detailText),1)],64)):e.createCommentVNode("",!0)])],2)}const ve=N(kn,[["render",Vn],["__scopeId","data-v-64a83fb8"]]),Mn={name:"WmArtifactFormResponse",props:{data:{type:Object,required:!0}},computed:{fields(){var t;return Array.isArray((t=this.data)==null?void 0:t.fields)?this.data.fields:[]}}},Tn={class:"wm-art wm-art--formResponse"},xn={class:"wm-art__head"},On={class:"wm-art__title"},In={class:"wm-art__body"},Dn={class:"wm-art__fieldLabel"};function Ln(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Tn,[e.createElementVNode("div",xn,[e.createElementVNode("div",On,e.toDisplayString(r.data.title||"Formulaire"),1),n[0]||(n[0]=e.createElementVNode("span",{class:"wm-art__badge wm-art__badge--success"},[e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("polyline",{points:"20 6 9 17 4 12"})]),e.createTextVNode(" Envoyé ")],-1))]),e.createElementVNode("div",In,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.fields,(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",Dn,e.toDisplayString(i.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":i.multiline}])},e.toDisplayString(i.value),3)]))),128))])])}const ye=N(Mn,[["render",Ln],["__scopeId","data-v-ca24a9c9"]]),Rn={name:"WmArtifactInfoCard",props:{data:{type:Object,required:!0}},computed:{fields(){var t;return Array.isArray((t=this.data)==null?void 0:t.fields)?this.data.fields:[]},hasBody(){var t;return!!((t=this.data)!=null&&t.body)||this.fields.length>0}}},Fn={class:"wm-art wm-art--infoCard"},$n={key:0,class:"wm-art__image"},Pn=["src","alt"],Un={class:"wm-art__head"},jn={class:"wm-art__headMain"},zn={class:"wm-art__title"},Hn={key:0,class:"wm-art__subtitle"},qn={key:1,class:"wm-art__body"},Kn={key:0,class:"wm-art__text"},Wn={class:"wm-art__fieldLabel"};function Gn(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Fn,[r.data.image_url?(e.openBlock(),e.createElementBlock("figure",$n,[e.createElementVNode("img",{src:r.data.image_url,alt:r.data.title||"",loading:"lazy"},null,8,Pn)])):e.createCommentVNode("",!0),e.createElementVNode("div",Un,[e.createElementVNode("div",jn,[e.createElementVNode("div",zn,e.toDisplayString(r.data.title),1),r.data.subtitle?(e.openBlock(),e.createElementBlock("div",Hn,e.toDisplayString(r.data.subtitle),1)):e.createCommentVNode("",!0)]),r.data.badge&&r.data.badge.label?(e.openBlock(),e.createElementBlock("span",{key:0,class:e.normalizeClass(["wm-art__badge",`wm-art__badge--${r.data.badge.tone||"neutral"}`])},e.toDisplayString(r.data.badge.label),3)):e.createCommentVNode("",!0)]),o.hasBody?(e.openBlock(),e.createElementBlock("div",qn,[r.data.body?(e.openBlock(),e.createElementBlock("div",Kn,e.toDisplayString(r.data.body),1)):e.createCommentVNode("",!0),o.fields.length?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(o.fields,(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",Wn,e.toDisplayString(i.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":i.multiline}])},e.toDisplayString(i.value),3)]))),128)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])}const ke=N(Rn,[["render",Gn],["__scopeId","data-v-d7369333"]]);function Yn(t){if(!t)return"";const n=new Date(t);if(Number.isNaN(n.getTime()))return t;const r=n.toLocaleDateString("fr-FR",{day:"numeric",month:"long",year:"numeric"}),a=n.toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit"});return`${r} à ${a}`}const Xn={name:"WmArtifactTicket",props:{data:{type:Object,required:!0}},computed:{fields(){var t;return Array.isArray((t=this.data)==null?void 0:t.fields)?this.data.fields:[]},formattedDate(){var t;return Yn((t=this.data)==null?void 0:t.created_at)}},methods:{isPriority(t){return/priorit|^prio$/i.test(String(t||"").trim())},isDate(t){return/date|échéanc|echeanc|deadline|due|créé|cree/i.test(String(t||"").trim())},priorityLevel(t){const n=String(t||"").toLowerCase();return/high|haute|élev|elev|critic|critiq|urgent/.test(n)?3:/low|basse|faible|minor/.test(n)?1:2}}},Jn={class:"wm-art wm-art--ticket"},Qn={class:"wm-art__head wm-tk__head"},Zn={class:"wm-art__title wm-tk__title"},er={class:"wm-tk__sub"},tr={class:"wm-tk__ref"},nr={key:0,class:"wm-tk__text"},rr={key:0,class:"wm-art__body"},or={class:"wm-art__fieldLabel"},sr=["data-level"],ar={key:1,class:"wm-tk__date",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},ir={key:1,class:"wm-art__footer wm-tk__footer"};function lr(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Jn,[e.createElementVNode("div",Qn,[e.createElementVNode("div",Zn,e.toDisplayString(r.data.title),1),e.createElementVNode("div",er,[e.createElementVNode("div",tr,[n[0]||(n[0]=e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M20 12a2 2 0 0 1 2-2V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v4a2 2 0 0 1 0 4v4a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-4a2 2 0 0 1-2-2z"}),e.createElementVNode("path",{d:"M13 5v2M13 17v2M13 11v2"})],-1)),e.createElementVNode("span",null,e.toDisplayString(r.data.reference),1)]),e.createElementVNode("span",{class:e.normalizeClass(["wm-art__badge","wm-tk__badge",`wm-art__badge--${r.data.status.tone||"neutral"}`])},[n[1]||(n[1]=e.createElementVNode("span",{class:"wm-tk__dot","aria-hidden":"true"},null,-1)),e.createTextVNode(" "+e.toDisplayString(r.data.status.label),1)],2)]),r.data.body?(e.openBlock(),e.createElementBlock("div",nr,e.toDisplayString(r.data.body),1)):e.createCommentVNode("",!0)]),o.fields.length?(e.openBlock(),e.createElementBlock("div",rr,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.fields,(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",or,e.toDisplayString(i.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":i.multiline}])},[o.isPriority(i.label)?(e.openBlock(),e.createElementBlock("svg",{key:0,class:"wm-tk__prio","data-level":o.priorityLevel(i.value),width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true"},[...n[2]||(n[2]=[e.createElementVNode("rect",{x:"1",y:"8",width:"2",height:"3",rx:"0.5"},null,-1),e.createElementVNode("rect",{x:"5",y:"5",width:"2",height:"6",rx:"0.5"},null,-1),e.createElementVNode("rect",{x:"9",y:"2",width:"2",height:"9",rx:"0.5"},null,-1)])],8,sr)):o.isDate(i.label)?(e.openBlock(),e.createElementBlock("svg",ar,[...n[3]||(n[3]=[e.createElementVNode("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"},null,-1),e.createElementVNode("path",{d:"M16 2v4M8 2v4M3 10h18"},null,-1)])])):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(i.value),1)],2)]))),128))])):e.createCommentVNode("",!0),r.data.created_at?(e.openBlock(),e.createElementBlock("div",ir,[n[4]||(n[4]=e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),e.createElementVNode("path",{d:"M16 2v4M8 2v4M3 10h18"})],-1)),e.createElementVNode("span",null,e.toDisplayString(o.formattedDate),1)])):e.createCommentVNode("",!0)])}const we=N(Xn,[["render",lr],["__scopeId","data-v-8b274eb7"]]),cr={form_response:ye,info_card:ke,ticket:we},dr={name:"WmArtifactRenderer",props:{artifact:{type:Object,required:!0}},computed:{component(){var n;const t=(n=this.artifact)==null?void 0:n.kind;return t&&cr[t]||null}}};function ur(t,n,r,a,s,o){return o.component?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.component),{key:0,data:r.artifact.data},null,8,["data"])):e.createCommentVNode("",!0)}const be=N(dr,[["render",ur]]),mr={name:"WmAttachmentPreview",inject:{signAttachmentFn:{default:null}},props:{attachment:{type:Object,required:!0}},data(){return{url:null,loading:!1}},computed:{kind(){var r,a;const t=(r=this.attachment)==null?void 0:r.type;if(t)return t;const n=(((a=this.attachment)==null?void 0:a.mime_type)||"").toLowerCase();return n.startsWith("image/")?"image":n.startsWith("audio/")?"audio":n.startsWith("video/")?"video":"file"},displayName(){var t,n,r;return((n=(t=this.attachment)==null?void 0:t.metadata)==null?void 0:n.name)||((r=this.attachment)==null?void 0:r.name)||this.guessNameFromPath()||"Pièce jointe"},sizeLabel(){var n;const t=(n=this.attachment)==null?void 0:n.size_bytes;return t?t<1024?`${t} o`:t<1024*1024?`${(t/1024).toFixed(0)} ko`:`${(t/(1024*1024)).toFixed(1)} Mo`:""}},watch:{"attachment.path":{handler(){this.refresh()},immediate:!0}},methods:{guessNameFromPath(){var r;return((((r=this.attachment)==null?void 0:r.path)||"").split("/").pop()||"").replace(/^[0-9a-f-]{8,}-/,"")},async refresh(){var t;if(!(!((t=this.attachment)!=null&&t.path)||!this.signAttachmentFn)){this.loading=!0;try{this.url=await this.signAttachmentFn(this.attachment.path)}finally{this.loading=!1}}},onFileClick(t){this.url||t.preventDefault()}}},hr=["href"],fr=["src","alt"],pr=["src"],_r=["src"],gr=["href","download"],vr={class:"wm-att__main"},yr={class:"wm-att__name"},kr={key:0,class:"wm-att__meta"},wr={key:0,class:"wm-att__spin","aria-hidden":"true"};function br(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-att",["wm-att--"+(o.kind||"file")]])},[o.kind==="image"&&s.url?(e.openBlock(),e.createElementBlock("a",{key:0,href:s.url,target:"_blank",rel:"noopener",class:"wm-att__imgWrap"},[e.createElementVNode("img",{src:s.url,alt:o.displayName,loading:"lazy"},null,8,fr)],8,hr)):o.kind==="audio"&&s.url?(e.openBlock(),e.createElementBlock("audio",{key:1,src:s.url,controls:"",preload:"metadata"},null,8,pr)):o.kind==="video"&&s.url?(e.openBlock(),e.createElementBlock("video",{key:2,src:s.url,controls:"",preload:"metadata"},null,8,_r)):(e.openBlock(),e.createElementBlock("a",{key:3,class:"wm-att__file",href:s.url||"#",download:o.displayName,target:"_blank",rel:"noopener",onClick:n[0]||(n[0]=(...i)=>o.onFileClick&&o.onFileClick(...i))},[n[1]||(n[1]=e.createElementVNode("span",{class:"wm-att__icon"},[e.createElementVNode("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.createElementVNode("path",{d:"M14 2v6h6"})])],-1)),e.createElementVNode("span",vr,[e.createElementVNode("span",yr,e.toDisplayString(o.displayName),1),o.sizeLabel?(e.openBlock(),e.createElementBlock("span",kr,e.toDisplayString(o.sizeLabel),1)):e.createCommentVNode("",!0)]),s.loading?(e.openBlock(),e.createElementBlock("span",wr)):e.createCommentVNode("",!0)],8,gr))],2)}const Ee=N(mr,[["render",br],["__scopeId","data-v-1cd1267b"]]);function Er(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Cr(t){return/^(https?:\/\/|mailto:|tel:)/i.test(String(t).trim())}const ae="";function K(t){let n=t;const r=[];return n=n.replace(/`([^`\n]+)`/g,(a,s)=>{const o=r.length;return r.push(s),`${ae}CODE${o}${ae}`}),n=n.replace(/\[([^\]\n]+)\]\(([^)\s]+)\)/g,(a,s,o)=>Cr(o)?`<a href="${o}" target="_blank" rel="noopener noreferrer">${s}</a>`:s),n=n.replace(/\*\*([^\n*][^\n]*?)\*\*/g,"<strong>$1</strong>"),n=n.replace(/__([^\n_][^\n]*?)__/g,"<u>$1</u>"),n=n.replace(/~~([^\n~][^\n]*?)~~/g,"<s>$1</s>"),n=n.replace(/(^|[^\w*])\*([^\n*]+?)\*(?!\w)/g,"$1<em>$2</em>"),n=n.replace(/(^|[^\w_])_([^\n_]+?)_(?!\w)/g,"$1<em>$2</em>"),n=n.replace(/CODE(\d+)/g,(a,s)=>`<code class="wm-md-code">${r[+s]}</code>`),n}function Ce(t){if(!t)return"";const n=Er(t).split(`
54
+ `),r=[];let a=0;for(;a<n.length;){const o=n[a];if(/^\s*```([\w-]*)\s*$/.exec(o)){a++;const v=[];for(;a<n.length&&!/^\s*```\s*$/.test(n[a]);)v.push(n[a]),a++;a<n.length&&a++,r.push({type:"block",html:`<pre class="wm-md-pre"><code>${v.join(`
55
+ `)}</code></pre>`});continue}if(/^\s*[-*]\s+/.test(o)){const v=[];for(;a<n.length;){const E=/^\s*[-*]\s+(.*)$/.exec(n[a]);if(!E)break;v.push(E[1]),a++}const y=v.map(E=>`<li>${K(E)}</li>`).join("");r.push({type:"block",html:`<ul class="wm-md-ul">${y}</ul>`});continue}const l=/^\s*(\d+)\.\s+(.*)$/.exec(o);if(l){const v=parseInt(l[1],10),y=[l[2]];for(a++;a<n.length;){const k=/^\s*\d+\.\s+(.*)$/.exec(n[a]);if(!k)break;y.push(k[1]),a++}const E=y.map(k=>`<li>${K(k)}</li>`).join(""),S=v!==1?` start="${v}"`:"";r.push({type:"block",html:`<ol class="wm-md-ol"${S}>${E}</ol>`});continue}const p=/^(#{1,6})\s+(.*)$/.exec(o);if(p){const v=p[1].length;r.push({type:"block",html:`<h${v} class="wm-md-h wm-md-h${v}">${K(p[2])}</h${v}>`}),a++;continue}r.push({type:"text",html:K(o)}),a++}let s="";for(let o=0;o<r.length;o++){const i=r[o];s+=i.html;const l=r[o+1];l&&i.type!=="block"&&l.type!=="block"&&(s+=`
56
+ `)}return s}const Br={name:"WmBubble",props:{role:{type:String,default:"ai"},text:{type:String,default:""}},computed:{rendered(){return Ce(this.text)}}},Nr=["innerHTML"];function Sr(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-bubble","wm-bubble--"+r.role])},[e.renderSlot(t.$slots,"default",{},()=>[e.createElementVNode("span",{innerHTML:o.rendered},null,8,Nr)],!0)],2)}const Be=N(Br,[["render",Sr],["__scopeId","data-v-5c9e9f2b"]]),Ar={name:"WmTyping"},Vr={class:"wm-typing"};function Mr(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Vr,[...n[0]||(n[0]=[e.createElementVNode("span",{style:{"animation-delay":"0s"}},null,-1),e.createElementVNode("span",{style:{"animation-delay":"0.2s"}},null,-1),e.createElementVNode("span",{style:{"animation-delay":"0.4s"}},null,-1)])])}const Ne=N(Ar,[["render",Mr],["__scopeId","data-v-df2447fd"]]);function j(t){return t?t.client_msg_id||t.id:""}const Tr={transferred_to_human:"Conversation transférée à un humain",assigned:"{name} a rejoint la conversation",unassigned:"L'agent a quitté la conversation",resolved:"Conversation résolue",reopened:"Conversation rouverte",idle:"Conversation en pause"},xr=80,Or=200,Ir={name:"WmMessageList",components:{AIAvatar:U,HumanAvatar:Y,Bubble:Be,Typing:Ne,ActionResult:ve,AttachmentPreview:Ee,ArtifactRenderer:be},props:{messages:{type:Array,default:()=>[]},streamingActive:{type:Boolean,default:!1},dateLabel:{type:String,default:""},conversationId:{type:[String,Number],default:null},loadingMore:{type:Boolean,default:!1},hasMore:{type:Boolean,default:!1},unreadAnchorId:{type:Number,default:null},unreadBoundaryTs:{type:String,default:""}},emits:["load-more"],data(){return{silentFades:!1,widthByKey:Object.freeze({})}},computed:{historyExhausted(){return!this.hasMore&&!this.loadingMore&&this.messages.length>=20},groups(){var r,a,s,o;const t=[];for(const i of this.messages){const l=this.roleOf(i);if(l==="system"){if(((r=i==null?void 0:i.payload)==null?void 0:r.event)==="action_admin_pending"){const y=t[t.length-1];y&&y.role==="ai"?y.messages.push(i):t.push({key:`g-${j(i)}`,role:"ai",agentName:"",agentAvatarUrl:null,messages:[i],items:[]});continue}t.push({key:`sys-${j(i)}`,role:l,messages:[i],items:[],systemLabel:this.systemLabel(i)});continue}const p=t[t.length-1];p&&p.role===l&&(l==="ai"||p.agentName===(((a=i==null?void 0:i.author)==null?void 0:a.name)||""))?p.messages.push(i):t.push({key:`g-${j(i)}`,role:l,agentName:((s=i==null?void 0:i.author)==null?void 0:s.name)||"",agentAvatarUrl:((o=i==null?void 0:i.author)==null?void 0:o.avatar_url)||null,messages:[i],items:[]})}for(const i of t){if(i.role==="system")continue;const l=[];for(const p of i.messages)for(const v of this.itemsOf(p))l.push(v);i.items=l}const n=[];for(const i of t){if(i.role!=="system"&&!i.items.length)continue;const l=n[n.length-1];if(l&&l.role!=="system"&&l.role===i.role&&(i.role==="ai"||l.agentName===i.agentName)){l.messages.push(...i.messages),l.items.push(...i.items);continue}n.push(i)}return n},unreadGroupKey(){if(this.unreadAnchorId==null)return null;const t=this.unreadAnchorId,n=this.unreadBoundaryTs;for(const r of this.groups){if(r.role==="user"||r.role==="system"||!r.items.length)continue;const a=r.messages[0];if(!a)continue;const s=R(a.id);if(s!=null&&!(s<=t)&&!(n&&a.created_at&&a.created_at>n))return r.key}return null}},watch:{messages:{handler:"snapshotAndRestore",deep:!0},loadingMore(t){t||(this._pendingLoadMore=!1),this.silentFades=!0,clearTimeout(this._silenceTimer),t||(this._silenceTimer=setTimeout(()=>{this.silentFades=!1},250)),this.snapshotAndRestore()},streamingActive:"snapshotAndRestore"},mounted(){this._lastSeenConvId=this.conversationId,this.scrollToBottom(),this._measureFrame=null,this._ro=new ResizeObserver(()=>this.scheduleMeasure()),this.$refs.scrollEl&&this._ro.observe(this.$refs.scrollEl),this.$nextTick(()=>this.measureRows())},beforeUnmount(){var t;(t=this._ro)==null||t.disconnect(),this._measureFrame&&cancelAnimationFrame(this._measureFrame),clearTimeout(this._silenceTimer)},updated(){this.scheduleMeasure()},methods:{messageKey:j,isAtBottom(t){return t.scrollHeight-t.scrollTop-t.clientHeight<=xr},onScroll(){const t=this.$refs.scrollEl;t&&(this.loadingMore||!this.hasMore||this._pendingLoadMore||t.scrollTop<=Or&&(this._pendingLoadMore=!0,this.$emit("load-more")))},snapshotAndRestore(){const t=this.$refs.scrollEl;if(!t||this._scrollSnap)return;const n=this._lastSeenConvId!==this.conversationId;this._lastSeenConvId=this.conversationId;const r=this.isAtBottom(t);let a=null;if(!n&&!r){const o=this.pickAnchor(t);if(o!=null&&o.el){const i=t.getBoundingClientRect().top;a={el:o.el,relY:o.el.getBoundingClientRect().top-i}}}const s={forceBottom:n,wasPinned:r,anchor:a};this._scrollSnap=s,this.$nextTick(()=>{if(this._scrollSnap=null,s.forceBottom||s.wasPinned){t.scrollTop=t.scrollHeight;return}if(!s.anchor)return;const o=()=>{var v;const i=s.anchor;if(!((v=i.el)!=null&&v.isConnected))return;const p=i.el.getBoundingClientRect().top-t.getBoundingClientRect().top-i.relY;Math.abs(p)>.5&&(t.scrollTop+=p)};o(),requestAnimationFrame(()=>{o(),requestAnimationFrame(o)})})},pickAnchor(t){const n=t.scrollTop;let r=null;for(const a of t.children)if(a.classList.contains("wm-list__group")&&(r||(r=a),a.offsetTop+a.offsetHeight>=n))return{el:a,offsetTop:a.offsetTop};return r?{el:r,offsetTop:r.offsetTop}:null},roleOf(t){var r,a;if((t==null?void 0:t.type)==="system"||((r=t==null?void 0:t.payload)==null?void 0:r.type)==="system")return"system";const n=(a=t==null?void 0:t.author)==null?void 0:a.type;return n==="user"?"user":n==="agent_human"?"human":"ai"},roleLabel(t){return t.role==="human"?t.agentName||"Agent":"Assistant IA"},itemsOf(t){var n;if(!t)return[];if(t.type==="system"&&((n=t==null?void 0:t.payload)==null?void 0:n.event)==="action_admin_pending")return[{message:t,partKey:"main",renderAs:"admin-pending",kind:{top:"bubble",bottom:"bubble"}}];if(t.type==="action"&&t.payload&&t.payload.state!=="pending"){const r=[{message:t,partKey:"main",renderAs:"action",kind:{top:"bubble",bottom:"bubble"}}];return this.actionArtifact(t)&&r.push({message:t,partKey:"artifact",renderAs:"artifact-of-action",kind:{top:"card",bottom:"card"}}),r}return this.artifactOf(t)?[{message:t,partKey:"main",renderAs:"artifact",kind:{top:"card",bottom:"card"}}]:t.text_md||this.attachmentsOf(t).length?[{message:t,partKey:"main",renderAs:"bubble",kind:{top:"bubble",bottom:"bubble"}}]:[]},cornersFor(t,n){var F,$,O;const r=t.items,a=(F=r[n])==null?void 0:F.kind,s=($=r[n-1])==null?void 0:$.kind,o=(O=r[n+1])==null?void 0:O.kind,i=t.role==="user",l=14,p=4,v=s==null?void 0:s.bottom,y=o==null?void 0:o.top,E=this.widthByKey[this.rowKeyOf(t,n)],S=this.widthByKey[this.rowKeyOf(t,n-1)],k=this.widthByKey[this.rowKeyOf(t,n+1)],x=.5,w=(P,L,I)=>P!=null&&E!=null?P+x>=E:L===I||L==="card"&&I==="bubble";let M=l,A=l,T=l,D=l;return i?(v&&(A=p),(y||!o)&&(T=p),v&&w(S,v,a==null?void 0:a.top)&&(M=p),y&&w(k,y,a==null?void 0:a.bottom)&&(D=p)):(v&&(M=p),(y||!o)&&(D=p),v&&w(S,v,a==null?void 0:a.top)&&(A=p),y&&w(k,y,a==null?void 0:a.bottom)&&(T=p)),{tl:M,tr:A,br:T,bl:D}},cornersStyle(t,n){if(t.items.length<2)return null;const r=this.cornersFor(t,n);return{"--wm-r-tl":`${r.tl}px`,"--wm-r-tr":`${r.tr}px`,"--wm-r-br":`${r.br}px`,"--wm-r-bl":`${r.bl}px`}},rowKeyOf(t,n){var a;const r=(a=t==null?void 0:t.items)==null?void 0:a[n];return r?`${j(r.message)}-${r.partKey}`:""},scheduleMeasure(){this._measureFrame||(this._measureFrame=requestAnimationFrame(()=>{this._measureFrame=null,this.measureRows()}))},measureRows(){const t=this.$refs.scrollEl;if(!t)return;const n={};for(const o of t.querySelectorAll(".wm-list__row[data-row-key]")){const i=o.dataset.rowKey;if(!i)continue;const l=o.querySelector(".wm-bubble, .wm-result, .wm-art, .wm-list__body");if(!l)continue;const p=l.getBoundingClientRect().width;p>0&&(n[i]=p)}const r=this.widthByKey,a=Object.keys(r),s=Object.keys(n);if(a.length===s.length){let o=!0;for(const i of s)if(Math.abs((r[i]??0)-n[i])>.5){o=!1;break}if(o)return}this.widthByKey=Object.freeze(n)},lastTimeOf(t){const n=t.items[t.items.length-1],r=(n==null?void 0:n.message)||t.messages[t.messages.length-1];if(!(r!=null&&r.created_at))return"";try{return te(new Date(r.created_at))}catch{return""}},hasTrailingOverlay(t){if(!t.messages.length)return!1;const n=t.messages[t.messages.length-1],r=t.items[t.items.length-1];return!!n&&(r==null?void 0:r.message)!==n},attachmentsOf(t){var r;const n=(r=t==null?void 0:t.payload)==null?void 0:r.attachments;return Array.isArray(n)?n:[]},artifactOf(t){var r;const n=(r=t==null?void 0:t.metadata)==null?void 0:r.artifact;return!n||typeof n!="object"||typeof n.kind!="string"?null:n},actionLabel(t){var n;return((n=t==null?void 0:t.payload)==null?void 0:n.name)||(t==null?void 0:t.text_md)||"Action"},actionDetail(t){var r,a,s,o,i,l;const n=t==null?void 0:t.payload;return n?n.state==="success"?((r=n.success)==null?void 0:r.summary)||((s=(a=n.success)==null?void 0:a.metadata)==null?void 0:s.description)||"":n.state==="rejected"?((o=n.rejected)==null?void 0:o.reason)||"Action annulée par l'utilisateur.":n.state==="failure"&&(((i=n.failure)==null?void 0:i.summary)||((l=n.failure)==null?void 0:l.error))||"":""},actionArtifact(t){var r,a;const n=(a=(r=t==null?void 0:t.payload)==null?void 0:r.success)==null?void 0:a.artifact;return!n||typeof n!="object"||typeof n.kind!="string"?null:n},systemLabel(t){var s,o,i;const n=(s=t==null?void 0:t.payload)==null?void 0:s.event,r=Tr[n]||(t==null?void 0:t.text_md)||"Mise à jour de la conversation",a=((o=t==null?void 0:t.metadata)==null?void 0:o.agent_name)||((i=t==null?void 0:t.author)==null?void 0:i.name)||"";return r.replace("{name}",a||"Un agent")},scrollToBottom(){const t=this.$refs.scrollEl;t&&(t.scrollTop=t.scrollHeight)}}},Dr={key:0,class:"wm-list__loadMore",role:"status","aria-live":"polite"},Lr={key:1,class:"wm-list__historyEnd"},Rr={key:2,class:"wm-list__sep"},Fr={class:"wm-list__sep-label"},$r={key:0,class:"wm-list__sep wm-list__sep--unread"},Pr={key:0,class:"wm-list__sysep"},Ur={class:"wm-list__sysep-label"},jr=["data-row-key"],zr={key:0,class:"wm-list__avatarSlot"},Hr={key:5,class:"wm-list__body"},qr={key:0},Kr={key:1,"aria-hidden":"true"},Wr={key:2},Gr={key:3,class:"wm-list__row wm-list__row--ai fade-up"},Yr={class:"wm-list__avatarSlot"};function Xr(t,n,r,a,s,o){const i=e.resolveComponent("AIAvatar"),l=e.resolveComponent("HumanAvatar"),p=e.resolveComponent("ActionResult"),v=e.resolveComponent("ArtifactRenderer"),y=e.resolveComponent("Bubble"),E=e.resolveComponent("AttachmentPreview"),S=e.resolveComponent("Typing");return e.openBlock(),e.createElementBlock("div",{ref:"scrollEl",class:e.normalizeClass(["wm-list",{"wm-list--silent":s.silentFades}]),onScrollPassive:n[0]||(n[0]=(...k)=>o.onScroll&&o.onScroll(...k))},[r.loadingMore?(e.openBlock(),e.createElementBlock("div",Dr,[...n[1]||(n[1]=[e.createElementVNode("span",{class:"wm-list__loadMore-spinner","aria-hidden":"true"},null,-1),e.createElementVNode("span",{class:"wm-list__loadMore-lbl"},"Chargement de l'historique…",-1)])])):o.historyExhausted?(e.openBlock(),e.createElementBlock("div",Lr,"Début de la conversation")):e.createCommentVNode("",!0),r.dateLabel?(e.openBlock(),e.createElementBlock("div",Rr,[n[2]||(n[2]=e.createElementVNode("div",{class:"wm-list__line"},null,-1)),e.createElementVNode("span",Fr,e.toDisplayString(r.dateLabel),1),n[3]||(n[3]=e.createElementVNode("div",{class:"wm-list__line"},null,-1))])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.groups,(k,x)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:k.key},[k.key===o.unreadGroupKey?(e.openBlock(),e.createElementBlock("div",$r,[...n[4]||(n[4]=[e.createElementVNode("div",{class:"wm-list__line wm-list__line--unread"},null,-1),e.createElementVNode("span",{class:"wm-list__sep-label wm-list__sep-label--unread"},"Non lus",-1),e.createElementVNode("div",{class:"wm-list__line wm-list__line--unread"},null,-1)])])):e.createCommentVNode("",!0),k.role==="system"||k.items.length?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["wm-list__group","wm-list__group--"+k.role])},[k.role==="system"?(e.openBlock(),e.createElementBlock("div",Pr,[n[5]||(n[5]=e.createElementVNode("div",{class:"wm-list__line wm-list__line--strong"},null,-1)),e.createElementVNode("span",Ur,e.toDisplayString(k.systemLabel),1),n[6]||(n[6]=e.createElementVNode("div",{class:"wm-list__line wm-list__line--strong"},null,-1))])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(k.items,(w,M)=>(e.openBlock(),e.createElementBlock("div",{key:`${o.messageKey(w.message)}-${w.partKey}`,"data-row-key":`${o.messageKey(w.message)}-${w.partKey}`,class:e.normalizeClass(["wm-list__row fade-up",["wm-list__row--"+k.role,{"is-pending":w.message._pending,"is-failed":w.message._failed}]]),style:e.normalizeStyle(o.cornersStyle(k,M))},[k.role!=="user"?(e.openBlock(),e.createElementBlock("div",zr,[M===k.items.length-1?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[k.role==="ai"?(e.openBlock(),e.createBlock(i,{key:0,size:26,tail:!0})):(e.openBlock(),e.createBlock(l,{key:1,name:k.agentName,"avatar-url":k.agentAvatarUrl,size:26,tail:!0},null,8,["name","avatar-url"]))],64)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),w.renderAs==="action"?(e.openBlock(),e.createBlock(p,{key:1,state:w.message.payload.state,label:o.actionLabel(w.message),detail:o.actionDetail(w.message)},null,8,["state","label","detail"])):w.renderAs==="admin-pending"?(e.openBlock(),e.createBlock(p,{key:2,state:"awaiting",label:"Demande d'approbation envoyée",detail:w.message.text_md||""},null,8,["detail"])):w.renderAs==="artifact-of-action"?(e.openBlock(),e.createBlock(v,{key:3,artifact:o.actionArtifact(w.message)},null,8,["artifact"])):w.renderAs==="artifact"?(e.openBlock(),e.createBlock(v,{key:4,artifact:o.artifactOf(w.message)},null,8,["artifact"])):(e.openBlock(),e.createElementBlock("div",Hr,[w.message.text_md?(e.openBlock(),e.createBlock(y,{key:0,role:k.role,text:w.message.text_md},null,8,["role","text"])):e.createCommentVNode("",!0),o.attachmentsOf(w.message).length?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["wm-list__atts",{"wm-list__atts--align-end":k.role==="user"}])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.attachmentsOf(w.message),(A,T)=>(e.openBlock(),e.createBlock(E,{key:`${o.messageKey(w.message)}-att-${T}`,attachment:A},null,8,["attachment"]))),128))],2)):e.createCommentVNode("",!0)]))],14,jr))),128)),(k.role!=="user"||o.lastTimeOf(k))&&!o.hasTrailingOverlay(k)?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["wm-list__meta",{"wm-list__meta--right":k.role==="user"}])},[k.role!=="user"?(e.openBlock(),e.createElementBlock("span",qr,e.toDisplayString(o.roleLabel(k)),1)):e.createCommentVNode("",!0),k.role!=="user"&&o.lastTimeOf(k)?(e.openBlock(),e.createElementBlock("span",Kr,"·")):e.createCommentVNode("",!0),o.lastTimeOf(k)?(e.openBlock(),e.createElementBlock("span",Wr,e.toDisplayString(o.lastTimeOf(k)),1)):e.createCommentVNode("",!0)],2)):e.createCommentVNode("",!0)],64))],2)):e.createCommentVNode("",!0)],64))),128)),r.streamingActive?(e.openBlock(),e.createElementBlock("div",Gr,[e.createElementVNode("div",Yr,[e.createVNode(i,{size:26,tail:!0})]),e.createVNode(S)])):e.createCommentVNode("",!0)],34)}const Se=N(Ir,[["render",Xr],["__scopeId","data-v-946babe3"]]),z=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",X=typeof window<"u"&&typeof window.MediaRecorder<"u";function Ae(){return X&&["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(n=>{var r,a;return(a=(r=window.MediaRecorder).isTypeSupported)==null?void 0:a.call(r,n)})||""}function Ve({audio:t}){return{video:!0,audio:!!t,selfBrowserSurface:"include",surfaceSwitching:"include",systemAudio:t?"include":"exclude"}}function Jr(t){return t?t.startsWith("image/")?"image":t.startsWith("video/")?"video":"file":"file"}async function Me(){if(!z)return null;let t;try{t=await navigator.mediaDevices.getDisplayMedia(Ve({audio:!1}))}catch(n){return(n==null?void 0:n.name)!=="NotAllowedError"&&console.error("[media] screenshot picker",n),null}try{return await Qr(t)}catch(n){return console.error("[media] screenshot capture",n),null}finally{t.getTracks().forEach(n=>{n.stop()})}}async function Qr(t){const n=document.createElement("video");n.muted=!0,n.playsInline=!0,n.srcObject=t,await n.play(),await new Promise(l=>requestAnimationFrame(l));const r=n.videoWidth||1280,a=n.videoHeight||720,s=document.createElement("canvas");s.width=r,s.height=a,s.getContext("2d").drawImage(n,0,0,r,a);const o=await new Promise((l,p)=>{s.toBlob(v=>v?l(v):p(new Error("toBlob failed")),"image/png")}),i=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);return new File([o],`capture-${i}.png`,{type:"image/png"})}async function Te(t={}){var v;if(!z||!X)return null;let n;try{n=await navigator.mediaDevices.getDisplayMedia(Ve({audio:!0}))}catch(y){return(y==null?void 0:y.name)!=="NotAllowedError"&&console.error("[media] record picker",y),null}const r=Ae();let a;try{a=r?new window.MediaRecorder(n,{mimeType:r}):new window.MediaRecorder(n)}catch(y){return console.error("[media] recorder init",y),n.getTracks().forEach(E=>{E.stop()}),null}const s=[];let o=null,i=!1;a.addEventListener("dataavailable",y=>{y.data&&y.data.size>0&&s.push(y.data)}),a.addEventListener("stop",()=>{var y,E;if(o&&clearInterval(o),n.getTracks().forEach(S=>{S.stop()}),s.length){const S=a.mimeType||r||"video/webm",k=new Blob(s,{type:S}),x=/mp4/.test(S)?"mp4":"webm",w=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),M=new File([k],`ecran-${w}.${x}`,{type:S});(y=t.onfinalize)==null||y.call(t,M)}else(E=t.oncancel)==null||E.call(t)}),n.getVideoTracks().forEach(y=>{y.addEventListener("ended",()=>l(),{once:!0})});function l(){if(!i&&(i=!0,a.state!=="inactive"))try{a.stop()}catch(y){console.error("[media] recorder stop",y)}}try{a.start(1e3)}catch(y){return console.error("[media] recorder start",y),n.getTracks().forEach(E=>{E.stop()}),null}(v=t.onstart)==null||v.call(t);const p=Date.now();return o=setInterval(()=>{var y;(y=t.ontick)==null||y.call(t,Date.now()-p)},500),{stop:l,get state(){return a.state}}}const Zr=[{action:"file",label:"Joindre un fichier",path:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"},{action:"screenshot",label:"Capture d'écran",path:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z M12 17a4 4 0 100-8 4 4 0 000 8z"},{action:"record",label:"Enregistrer l'écran",path:"M23 7l-7 5 7 5V7z M1 5a2 2 0 012-2h12a2 2 0 012 2v14a2 2 0 01-2 2H3a2 2 0 01-2-2V5z"}],eo={name:"WmComposer",props:{modelValue:{type:String,default:""},placeholder:{type:String,default:"Écrivez votre message…"},disabled:{type:Boolean,default:!1},attachLabel:{type:String,default:"Joindre"}},emits:["update:modelValue","send","attach"],data(){return{local:this.modelValue,attachOpen:!1,recording:!1,recordingElapsed:0,recorder:null}},computed:{canSend(){return!this.disabled&&!!this.local.trim()},attachItems(){return Zr.map(t=>({...t,disabled:t.action==="screenshot"&&!z||t.action==="record"&&(!z||!X)}))},recordingElapsedLabel(){const t=Math.floor(this.recordingElapsed/1e3),n=Math.floor(t/60),r=t%60;return`${n}:${r.toString().padStart(2,"0")}`}},watch:{modelValue(t){t!==this.local&&(this.local=t,this.$nextTick(()=>this.autosize()))},local(t){this.$emit("update:modelValue",t)}},mounted(){this.autosize()},beforeUnmount(){if(this.recorder)try{this.recorder.stop()}catch{}},methods:{focus(){const t=this.$refs.inputEl;if(!(!t||this.disabled))try{t.focus({preventScroll:!0})}catch{t.focus()}},onSubmit(){if(!this.canSend)return;const t=this.local.trim();this.local="",this.$emit("send",t),this.$nextTick(()=>this.autosize())},onKeydown(t){t.key==="Enter"&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey&&!t.isComposing&&(t.preventDefault(),this.onSubmit())},autosize(){const t=this.$refs.inputEl;t&&(t.style.height="auto",t.style.height=`${t.scrollHeight}px`)},onFile(t){const n=Array.from(t.target.files||[]);for(const r of n)this.$emit("attach",r);t.target.value=""},onAttachAction(t){this.attachOpen=!1,t==="file"?this.pickFile():t==="screenshot"?this.captureScreenshot():t==="record"&&this.startRecording()},pickFile(){var t;(t=this.$refs.fileEl)==null||t.click()},async captureScreenshot(){if(this.disabled)return;const t=await Me();t&&this.$emit("attach",t)},async startRecording(){if(this.recording||this.disabled)return;this.recordingElapsed=0;const t=await Te({onstart:()=>{this.recording=!0},ontick:n=>{this.recordingElapsed=n},onfinalize:n=>{this.$emit("attach",n),this.recording=!1,this.recordingElapsed=0,this.recorder=null},oncancel:()=>{this.recording=!1,this.recordingElapsed=0,this.recorder=null}});t&&(this.recorder=t)},stopRecording(){if(this.recorder)try{this.recorder.stop()}catch(t){console.error("[composer] stop recording",t)}}}},to={class:"wm-compose-wrap"},no={key:0,class:"wm-rec"},ro={class:"wm-rec__lbl"},oo={key:1,class:"wm-compose__menu",role:"menu"},so=["disabled","onClick"],ao={class:"wm-compose__menuIcon"},io={viewBox:"0 0 24 24",width:"14",height:"14","aria-hidden":"true"},lo=["d"],co=["placeholder","disabled"],uo={class:"wm-compose__actions"},mo=["title","aria-label","disabled"],ho=["disabled"];function fo(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",to,[s.recording?(e.openBlock(),e.createElementBlock("div",no,[n[8]||(n[8]=e.createElementVNode("span",{class:"wm-rec__dot","aria-hidden":"true"},null,-1)),e.createElementVNode("span",ro,"Enregistrement · "+e.toDisplayString(o.recordingElapsedLabel),1),e.createElementVNode("button",{type:"button",class:"wm-rec__stop",onClick:n[0]||(n[0]=(...i)=>o.stopRecording&&o.stopRecording(...i))},"Arrêter")])):e.createCommentVNode("",!0),e.createElementVNode("form",{class:e.normalizeClass(["wm-compose",{"has-attach":s.attachOpen}]),onSubmit:n[7]||(n[7]=e.withModifiers((...i)=>o.onSubmit&&o.onSubmit(...i),["prevent"]))},[e.createElementVNode("input",{ref:"fileEl",type:"file",hidden:"",multiple:"",onChange:n[1]||(n[1]=(...i)=>o.onFile&&o.onFile(...i))},null,544),s.attachOpen?(e.openBlock(),e.createElementBlock("div",{key:0,class:"wm-compose__overlay",onClick:n[2]||(n[2]=i=>s.attachOpen=!1)})):e.createCommentVNode("",!0),s.attachOpen?(e.openBlock(),e.createElementBlock("div",oo,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.attachItems,i=>(e.openBlock(),e.createElementBlock("button",{key:i.action,type:"button",class:"wm-compose__menuItem",disabled:i.disabled,onClick:l=>o.onAttachAction(i.action)},[e.createElementVNode("span",ao,[(e.openBlock(),e.createElementBlock("svg",io,[e.createElementVNode("path",{d:i.path,stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",fill:"none"},null,8,lo)]))]),e.createElementVNode("span",null,e.toDisplayString(i.label),1)],8,so))),128))])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("textarea",{ref:"inputEl","onUpdate:modelValue":n[3]||(n[3]=i=>s.local=i),class:"wm-compose__input",rows:"3",placeholder:r.placeholder,disabled:r.disabled,onKeydown:n[4]||(n[4]=(...i)=>o.onKeydown&&o.onKeydown(...i)),onInput:n[5]||(n[5]=(...i)=>o.autosize&&o.autosize(...i))},null,40,co),[[e.vModelText,s.local]]),e.createElementVNode("div",uo,[e.createElementVNode("button",{type:"button",class:e.normalizeClass(["wm-compose__icon",{"is-open":s.attachOpen}]),title:r.attachLabel,"aria-label":r.attachLabel,disabled:s.recording,onClick:n[6]||(n[6]=i=>s.attachOpen=!s.attachOpen)},[...n[9]||(n[9]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"})],-1)])],10,mo),e.createElementVNode("button",{type:"submit",class:e.normalizeClass(["wm-compose__send",{"is-empty":!o.canSend}]),disabled:!o.canSend,"aria-label":"Envoyer"},[...n[10]||(n[10]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})],-1)])],10,ho)])],34)])}const xe=N(eo,[["render",fo],["__scopeId","data-v-14fa9ec0"]]),po={name:"WmSuggestionChips",props:{items:{type:Array,default:()=>[]},baseDelay:{type:Number,default:360},stepDelay:{type:Number,default:90}},emits:["select"],computed:{batchKey(){return this.items.map(t=>(t==null?void 0:t.label)||(t==null?void 0:t.text)||"").join("§")}}},_o=["onClick"];function go(t,n,r,a,s,o){return r.items.length?(e.openBlock(),e.createElementBlock("div",{key:o.batchKey,class:"wm-chips"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.items,(i,l)=>(e.openBlock(),e.createElementBlock("button",{key:l,type:"button",class:"wm-chip",style:e.normalizeStyle({animationDelay:r.baseDelay+l*r.stepDelay+"ms"}),onClick:p=>t.$emit("select",i)},e.toDisplayString(i.label),13,_o))),128))])):e.createCommentVNode("",!0)}const Oe=N(po,[["render",go],["__scopeId","data-v-55aa529d"]]),vo={name:"WmApprovalCard",components:{AIAvatar:U},props:{action:{type:String,required:!0},detail:{type:String,default:""},callbacks:{type:Array,default:()=>[]}},emits:["callback"],computed:{approveCallback(){return this.callbacks.find(t=>t.id==="approve"||t.style==="primary")||this.callbacks[0]},rejectCallback(){return this.callbacks.find(t=>t.id==="reject"||t.style==="danger"||t.style==="neutral")||(this.callbacks.length>1?this.callbacks[1]:null)},approveId(){var t;return(t=this.approveCallback)==null?void 0:t.id},rejectId(){var t;return(t=this.rejectCallback)==null?void 0:t.id},approveLabel(){var t;return((t=this.approveCallback)==null?void 0:t.label)||"Autoriser"},rejectLabel(){var t;return((t=this.rejectCallback)==null?void 0:t.label)||"Refuser"}}},yo={class:"wm-approval"},ko={class:"wm-approval__head"},wo={class:"wm-approval__icon"},bo={class:"wm-approval__main"},Eo={class:"wm-approval__title"},Co={key:0,class:"wm-approval__detail"},Bo={class:"wm-approval__actions"};function No(t,n,r,a,s,o){const i=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",yo,[e.createElementVNode("div",ko,[e.createElementVNode("div",wo,[e.createVNode(i,{size:24})]),e.createElementVNode("div",bo,[e.createElementVNode("div",Eo,e.toDisplayString(r.action),1),r.detail?(e.openBlock(),e.createElementBlock("div",Co,e.toDisplayString(r.detail),1)):e.createCommentVNode("",!0)])]),e.createElementVNode("div",Bo,[o.rejectId?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-approval__btn wm-approval__btn--neutral",onClick:n[0]||(n[0]=l=>t.$emit("callback",o.rejectId))},e.toDisplayString(o.rejectLabel),1)):e.createCommentVNode("",!0),o.approveId?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-approval__btn wm-approval__btn--primary",onClick:n[1]||(n[1]=l=>t.$emit("callback",o.approveId))},e.toDisplayString(o.approveLabel),1)):e.createCommentVNode("",!0)])])}const Ie=N(vo,[["render",No],["__scopeId","data-v-b1be139c"]]);let ie=0;const So=new Set(["text","textarea","number","boolean","select","multiselect","date"]),Ao={name:"WmFormCard",components:{AIAvatar:U},props:{form:{type:Object,required:!0},readOnly:{type:Boolean,default:!1},initialValues:{type:Object,default:null}},emits:["submit"],data(){return ie+=1,{_uid:ie,values:{},busy:!1,error:""}},computed:{normalizedFields(){var n;return(Array.isArray((n=this.form)==null?void 0:n.fields)?this.form.fields:[]).filter(r=>!(!(r!=null&&r.key)||!(r!=null&&r.label)||!So.has(r==null?void 0:r.type)||(r.type==="select"||r.type==="multiselect")&&(!Array.isArray(r.options)||r.options.length===0)))}},created(){this.resetValues()},methods:{resetValues(){const t=this.initialValues&&typeof this.initialValues=="object"?this.initialValues:{},n={};for(const r of this.normalizedFields){if(t[r.key]!==void 0){n[r.key]=t[r.key];continue}r.type==="boolean"?n[r.key]=!1:r.type==="multiselect"?n[r.key]=[]:n[r.key]=""}this.values=n,this.error=""},toggleMulti(t,n,r){const a=Array.isArray(this.values[t])?this.values[t].slice():[],s=a.indexOf(n);r&&s===-1?a.push(n):!r&&s!==-1&&a.splice(s,1),this.values={...this.values,[t]:a}},validate(){for(const t of this.normalizedFields){if(!t.required)continue;const n=this.values[t.key];if(t.type!=="boolean"){if(t.type==="multiselect"){if(!Array.isArray(n)||n.length===0)return`« ${t.label} » est requis.`;continue}if(n==null||n==="")return`« ${t.label} » est requis.`}}return""},async onSubmit(){if(this.readOnly||this.busy)return;const t=this.validate();if(t){this.error=t;return}this.error="",this.busy=!0;try{await this.$emit("submit",{values:this.values})}finally{this.busy=!1}}}},Vo={class:"wm-form"},Mo={class:"wm-form__head"},To={class:"wm-form__icon"},xo={class:"wm-form__main"},Oo={class:"wm-form__title"},Io={key:0,class:"wm-form__detail"},Do=["for"],Lo={key:0,class:"wm-form__req","aria-hidden":"true"},Ro=["id","onUpdate:modelValue","placeholder","required","disabled"],Fo=["id","onUpdate:modelValue","placeholder","required","disabled"],$o=["id","onUpdate:modelValue","placeholder","required","disabled"],Po=["id","onUpdate:modelValue","required","disabled"],Uo={key:4,class:"wm-form__bool"},jo=["id","onUpdate:modelValue","disabled"],zo=["id","onUpdate:modelValue","required","disabled"],Ho={value:"",disabled:""},qo=["value"],Ko={key:6,class:"wm-form__multi"},Wo=["value","checked","disabled","onChange"],Go={key:0,class:"wm-form__err"},Yo=["disabled"],Xo={key:0,class:"wm-form__spinner","aria-hidden":"true"},Jo={key:2,class:"wm-form__doneLbl"};function Qo(t,n,r,a,s,o){const i=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",Vo,[e.createElementVNode("div",Mo,[e.createElementVNode("div",To,[e.createVNode(i,{size:24})]),e.createElementVNode("div",xo,[e.createElementVNode("div",Oo,e.toDisplayString(r.form.title||"Formulaire"),1),r.form.description?(e.openBlock(),e.createElementBlock("div",Io,e.toDisplayString(r.form.description),1)):e.createCommentVNode("",!0)])]),e.createElementVNode("form",{class:"wm-form__body",onSubmit:n[0]||(n[0]=e.withModifiers((...l)=>o.onSubmit&&o.onSubmit(...l),["prevent"]))},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.normalizedFields,l=>(e.openBlock(),e.createElementBlock("div",{key:l.key,class:"wm-form__field"},[e.createElementVNode("label",{for:`wm-f-${s._uid}-${l.key}`,class:"wm-form__label"},[e.createTextVNode(e.toDisplayString(l.label),1),l.required?(e.openBlock(),e.createElementBlock("span",Lo,"*")):e.createCommentVNode("",!0)],8,Do),l.type==="text"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:0,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,type:"text",class:"wm-form__input",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||s.busy},null,8,Ro)),[[e.vModelText,s.values[l.key]]]):l.type==="textarea"?e.withDirectives((e.openBlock(),e.createElementBlock("textarea",{key:1,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,class:"wm-form__textarea",rows:"3",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||s.busy},null,8,Fo)),[[e.vModelText,s.values[l.key]]]):l.type==="number"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,type:"number",class:"wm-form__input",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||s.busy},null,8,$o)),[[e.vModelText,s.values[l.key],void 0,{number:!0}]]):l.type==="date"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:3,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,type:"date",class:"wm-form__input",required:l.required,disabled:r.readOnly||s.busy},null,8,Po)),[[e.vModelText,s.values[l.key]]]):l.type==="boolean"?(e.openBlock(),e.createElementBlock("label",Uo,[e.withDirectives(e.createElementVNode("input",{id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,type:"checkbox",disabled:r.readOnly||s.busy},null,8,jo),[[e.vModelCheckbox,s.values[l.key]]]),e.createElementVNode("span",null,e.toDisplayString(l.placeholder||"Oui"),1)])):l.type==="select"?e.withDirectives((e.openBlock(),e.createElementBlock("select",{key:5,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,class:"wm-form__select",required:l.required,disabled:r.readOnly||s.busy},[e.createElementVNode("option",Ho,e.toDisplayString(l.placeholder||"Choisir…"),1),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.options,p=>(e.openBlock(),e.createElementBlock("option",{key:p.value,value:p.value},e.toDisplayString(p.label),9,qo))),128))],8,zo)),[[e.vModelSelect,s.values[l.key]]]):l.type==="multiselect"?(e.openBlock(),e.createElementBlock("div",Ko,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.options,p=>(e.openBlock(),e.createElementBlock("label",{key:p.value,class:"wm-form__multiItem"},[e.createElementVNode("input",{type:"checkbox",value:p.value,checked:Array.isArray(s.values[l.key])&&s.values[l.key].includes(p.value),disabled:r.readOnly||s.busy,onChange:v=>o.toggleMulti(l.key,p.value,v.target.checked)},null,40,Wo),e.createElementVNode("span",null,e.toDisplayString(p.label),1)]))),128))])):e.createCommentVNode("",!0)]))),128)),s.error?(e.openBlock(),e.createElementBlock("div",Go,e.toDisplayString(s.error),1)):e.createCommentVNode("",!0),r.readOnly?(e.openBlock(),e.createElementBlock("div",Jo,"Réponse envoyée")):(e.openBlock(),e.createElementBlock("button",{key:1,type:"submit",class:"wm-form__submit",disabled:s.busy},[s.busy?(e.openBlock(),e.createElementBlock("span",Xo)):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(s.busy?"Envoi…":r.form.submit_label||"Envoyer"),1)],8,Yo))],32)])}const De=N(Ao,[["render",Qo],["__scopeId","data-v-64b40f76"]]),Zo={name:"WmFeedback",props:{busy:{type:Boolean,default:!1},done:{type:Boolean,default:!1}},emits:["submit"],data(){return{sel:null,options:[{v:1,e:"😞",l:"Pas bien"},{v:2,e:"😐",l:"Moyen"},{v:3,e:"🙂",l:"Bien"},{v:4,e:"😄",l:"Super"},{v:5,e:"🤩",l:"Excellent"}]}},methods:{onSend(){!this.sel||this.busy||this.$emit("submit",{rating:this.sel})}}},es={class:"wm-fb"},ts={class:"wm-fb__row"},ns=["onClick"],rs={class:"wm-fb__emoji"},os={class:"wm-fb__label"},ss=["disabled"],as={key:1,class:"wm-fb__done"};function is(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",es,[r.done?(e.openBlock(),e.createElementBlock("div",as,[...n[3]||(n[3]=[e.createStaticVNode('<div class="wm-fb__check" data-v-6f45ff3b><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-6f45ff3b><path d="M20 6L9 17l-5-5" data-v-6f45ff3b></path></svg></div><div class="wm-fb__doneTitle" data-v-6f45ff3b>Merci pour votre retour !</div><div class="wm-fb__doneSub" data-v-6f45ff3b>Votre avis a bien été pris en compte.</div>',3)])])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[n[1]||(n[1]=e.createElementVNode("div",{class:"wm-fb__title"},"Comment s'est passée cette conversation ?",-1)),n[2]||(n[2]=e.createElementVNode("div",{class:"wm-fb__sub"},"Votre avis nous aide à améliorer l'assistant.",-1)),e.createElementVNode("div",ts,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.options,i=>(e.openBlock(),e.createElementBlock("button",{key:i.v,type:"button",class:e.normalizeClass(["wm-fb__opt",{"is-selected":s.sel===i.v}]),onClick:l=>s.sel=i.v},[e.createElementVNode("span",rs,e.toDisplayString(i.e),1),e.createElementVNode("span",os,e.toDisplayString(i.l),1)],10,ns))),128))]),e.createElementVNode("button",{type:"button",class:"wm-fb__send",disabled:!s.sel||r.busy,onClick:n[0]||(n[0]=(...i)=>o.onSend&&o.onSend(...i))},e.toDisplayString(r.busy?"Envoi…":"Envoyer mon avis"),9,ss)],64))])}const Le=N(Zo,[["render",is],["__scopeId","data-v-6f45ff3b"]]),ls={name:"WmMoreMenu",props:{canRename:{type:Boolean,default:!0},canExport:{type:Boolean,default:!0},soundEnabled:{type:Boolean,default:!0},browserNotifEnabled:{type:Boolean,default:!1},statusUrl:{type:String,default:""},helpUrl:{type:String,default:""}},emits:["close","action","sound-toggle","browser-notif-toggle"],data(){return{soundOn:this.soundEnabled,browserNotifOn:this.browserNotifEnabled}},watch:{soundEnabled(t){this.soundOn=!!t},browserNotifEnabled(t){this.browserNotifOn=!!t}},methods:{emit(t){this.$emit("action",t)},toggleSound(){this.soundOn=!this.soundOn,this.$emit("sound-toggle",this.soundOn)},toggleBrowserNotif(){this.browserNotifOn=!this.browserNotifOn,this.$emit("browser-notif-toggle",this.browserNotifOn)}}},cs={class:"wm-mm"},ds={class:"wm-mm__pop",role:"menu"},us={key:0,class:"wm-mm__section"},ms={key:1,class:"wm-mm__sep"},hs={class:"wm-mm__section"},fs={class:"wm-mm__section"};function ps(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",cs,[e.createElementVNode("div",{class:"wm-mm__scrim",onClick:n[0]||(n[0]=i=>t.$emit("close"))}),e.createElementVNode("div",ds,[r.canRename||r.canExport?(e.openBlock(),e.createElementBlock("div",us,[r.canRename?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-mm__item",onClick:n[1]||(n[1]=i=>o.emit("rename"))},[...n[7]||(n[7]=[e.createStaticVNode('<span class="wm-mm__icon" data-v-3a73911b><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-3a73911b><path d="M12 20h9" data-v-3a73911b></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z" data-v-3a73911b></path></svg></span><span class="wm-mm__label" data-v-3a73911b>Modifier le titre</span>',2)])])):e.createCommentVNode("",!0),r.canExport?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-mm__item",onClick:n[2]||(n[2]=i=>o.emit("export"))},[...n[8]||(n[8]=[e.createStaticVNode('<span class="wm-mm__icon" data-v-3a73911b><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-3a73911b><path d="M4 12v8a2 2 0 002 2h12a2 2 0 002-2v-8M16 6l-4-4-4 4M12 2v13" data-v-3a73911b></path></svg></span><span class="wm-mm__label" data-v-3a73911b>Exporter la transcription</span><span class="wm-mm__hint" data-v-3a73911b>.txt</span>',3)])])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),r.canRename||r.canExport?(e.openBlock(),e.createElementBlock("div",ms)):e.createCommentVNode("",!0),e.createElementVNode("div",hs,[e.createElementVNode("button",{type:"button",class:"wm-mm__item",onClick:n[3]||(n[3]=(...i)=>o.toggleSound&&o.toggleSound(...i))},[n[10]||(n[10]=e.createStaticVNode('<span class="wm-mm__icon" data-v-3a73911b><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-3a73911b><path d="M11 5L6 9H2v6h4l5 4V5z" data-v-3a73911b></path><path d="M15.54 8.46a5 5 0 010 7.07M19.07 4.93a10 10 0 010 14.14" data-v-3a73911b></path></svg></span><span class="wm-mm__label" data-v-3a73911b>Son</span>',2)),e.createElementVNode("span",{class:e.normalizeClass(["wm-mm__toggle",{"wm-mm__toggle--on":s.soundOn}])},[...n[9]||(n[9]=[e.createElementVNode("span",{class:"wm-mm__knob"},null,-1)])],2)]),e.createElementVNode("button",{type:"button",class:"wm-mm__item",onClick:n[4]||(n[4]=(...i)=>o.toggleBrowserNotif&&o.toggleBrowserNotif(...i))},[n[12]||(n[12]=e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M15 17h5l-1.4-1.4A2 2 0 0118 14.2V11a6 6 0 10-12 0v3.2c0 .5-.2 1-.6 1.4L4 17h5m6 0a3 3 0 11-6 0"})])],-1)),n[13]||(n[13]=e.createElementVNode("span",{class:"wm-mm__label"},"Notifications navigateur",-1)),e.createElementVNode("span",{class:e.normalizeClass(["wm-mm__toggle",{"wm-mm__toggle--on":s.browserNotifOn}])},[...n[11]||(n[11]=[e.createElementVNode("span",{class:"wm-mm__knob"},null,-1)])],2)])]),n[16]||(n[16]=e.createElementVNode("div",{class:"wm-mm__sep"},null,-1)),e.createElementVNode("div",fs,[r.statusUrl?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-mm__item",onClick:n[5]||(n[5]=i=>o.emit("status"))},[...n[14]||(n[14]=[e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zM10 6v4l3 2"})])],-1),e.createElementVNode("span",{class:"wm-mm__label"},"Statut des services",-1)])])):e.createCommentVNode("",!0),r.helpUrl?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-mm__item",onClick:n[6]||(n[6]=i=>o.emit("help"))},[...n[15]||(n[15]=[e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M9 11a3 3 0 116 0c0 2-3 2-3 5M12 19h.01M12 22a10 10 0 110-20 10 10 0 010 20z"})])],-1),e.createElementVNode("span",{class:"wm-mm__label"},"Centre d'aide",-1)])])):e.createCommentVNode("",!0)])])])}const Re=N(ls,[["render",ps],["__scopeId","data-v-3a73911b"]]),_s={name:"WmRenameDialog",props:{title:{type:String,default:"Modifier le titre"},initialValue:{type:String,default:""},placeholder:{type:String,default:"Titre de la conversation"}},emits:["close","submit"],data(){return{value:this.initialValue||""}},computed:{canSubmit(){const t=(this.value||"").trim();return!!t&&t!==(this.initialValue||"").trim()}},mounted(){this.$nextTick(()=>{const t=this.$refs.input;if(t){t.focus();try{t.select()}catch{}}})},methods:{onSubmit(){this.canSubmit&&this.$emit("submit",this.value.trim())}}},gs={class:"wm-dialog"},vs={class:"wm-dialog__card",role:"dialog","aria-modal":"true"},ys={class:"wm-dialog__head"},ks={class:"wm-dialog__title"},ws={class:"wm-dialog__body"},bs=["placeholder"],Es={class:"wm-dialog__actions"},Cs=["disabled"];function Bs(t,n,r,a,s,o){return e.openBlock(),e.createElementBlock("div",gs,[e.createElementVNode("div",{class:"wm-dialog__scrim",onClick:n[0]||(n[0]=i=>t.$emit("close"))}),e.createElementVNode("div",vs,[e.createElementVNode("div",ys,[e.createElementVNode("div",ks,e.toDisplayString(r.title),1),e.createElementVNode("button",{type:"button",class:"wm-dialog__close","aria-label":"Fermer",onClick:n[1]||(n[1]=i=>t.$emit("close"))},[...n[7]||(n[7]=[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])]),e.createElementVNode("div",ws,[e.withDirectives(e.createElementVNode("input",{ref:"input","onUpdate:modelValue":n[2]||(n[2]=i=>s.value=i),type:"text",class:"wm-dialog__input",placeholder:r.placeholder,maxlength:120,onKeydown:[n[3]||(n[3]=e.withKeys(e.withModifiers((...i)=>o.onSubmit&&o.onSubmit(...i),["prevent"]),["enter"])),n[4]||(n[4]=e.withKeys(e.withModifiers(i=>t.$emit("close"),["prevent"]),["esc"]))]},null,40,bs),[[e.vModelText,s.value]])]),e.createElementVNode("div",Es,[e.createElementVNode("button",{type:"button",class:"wm-dialog__btn",onClick:n[5]||(n[5]=i=>t.$emit("close"))},"Annuler"),e.createElementVNode("button",{type:"button",class:"wm-dialog__btn wm-dialog__btn--primary",disabled:!o.canSubmit,onClick:n[6]||(n[6]=(...i)=>o.onSubmit&&o.onSubmit(...i))},"Enregistrer",8,Cs)])])])}const Ns=N(_s,[["render",Bs],["__scopeId","data-v-4f4b37c9"]]),le="ww-messenger-tokens",Ss={name:"Messenger",components:{Launcher:fe,Header:_e,Onboarding:ge,MessageList:Se,Composer:xe,SuggestionChips:Oe,ApprovalCard:Ie,FormCard:De,Feedback:Le,MoreMenu:Re,RenameDialog:Ns},mixins:[Qe,ot,st,it],provide(){return{signAttachmentFn:t=>{var n,r;return((r=(n=this.store)==null?void 0:n.signAttachment)==null?void 0:r.call(n,t))||null}}},props:{baseUrl:{type:String,default:me},widgetId:{type:String,default:""},userId:{type:String,default:""},userHash:{type:String,default:""},customer:{type:Object,default:null},displayMode:{type:String,default:"floating"},devtools:{type:Boolean,default:!1}},data(){return{transport:null,store:null,isOpen:!1,draft:"",busy:!1,bootError:null,pendingAttachments:[],feedbackBusy:!1,feedbackDone:!1,convOpenedAt:0,moreOpen:!1,renameDialogOpen:!1,draftConv:null,activeConvId:null,showOnboarding:!1,dismissedPeeks:{},floatHeight:0,floatRO:null}},computed:{isEditor(){return!!this.devtools},isEmbedded(){return this.displayMode==="embedded"},error(){var t;return this.bootError||((t=this.s)==null?void 0:t.error)||null},canBoot(){return!!(this.baseUrl&&this.widgetId&&this.userId&&this.userHash)},s(){var t;return((t=this.store)==null?void 0:t.state)||null},ready(){var t;return!!((t=this.s)!=null&&t.ready)},allConversations(){var n;const t=(n=this.s)==null?void 0:n.conversations;return Array.isArray(t)?t:[]},drawerConversations(){var n;const t=((n=this.s)==null?void 0:n.messagesByConv)||{};return this.allConversations.map(r=>{var l;const a=t[r.id]||[],s=R(r.last_read_message_id);let o=0,i=null;for(let p=a.length-1;p>=0;p--){const v=a[p];if(!v)continue;if(((l=v.author)==null?void 0:l.type)==="user")break;const y=R(v.id);if(y!=null){if(s!=null&&y<=s)break;!i&&v.author&&(i=v.author),o++}}return{...r,_preview:Ge(r,a),_unread:o>0,_unreadCount:o,_lastAuthor:i}})},unreadCount(){return this.drawerConversations.filter(t=>t._unread).length},openThreads(){var n;const t=((n=this.s)==null?void 0:n.messagesByConv)||{};return this.drawerConversations.filter(r=>r.status!=="resolved").map(r=>({id:r.id,title:r.name||"Nouvelle conversation",preview:r._preview||"Nouveau message",unread:!!r._unread,_ts:oe(r,t[r.id]||[])})).sort((r,a)=>r._ts<a._ts?1:r._ts>a._ts?-1:0)},latestUnreads(){var r;const t=((r=this.s)==null?void 0:r.messagesByConv)||{},n=[];for(const a of this.drawerConversations){if(!a._unread)continue;const s=oe(a,t[a.id]||[]),o=a._lastAuthor,i=!o||o.type==="agent_ia",l=(o==null?void 0:o.name)||(i?this.agentName:"")||"",p=(o==null?void 0:o.avatar_url)||(i?this.agentAvatarUrl:null);n.push({convId:a.id,preview:a._preview||"Vous avez un nouveau message",ts:s,count:a._unreadCount||1,senderName:l,senderAvatarUrl:p})}return n.sort((a,s)=>a.ts<s.ts?1:a.ts>s.ts?-1:0),n},launcherPeeks(){if(this.isOpen||this.isEmbedded)return[];const t=this.dismissedPeeks||{};return this.latestUnreads.filter(n=>t[n.convId]!==n.ts)},isViewingThread(){return(this.isOpen||this.isEmbedded)&&!!this.currentConv},currentConv(){if(this.draftConv)return this.draftConv;if(this.showOnboarding)return null;const t=this.allConversations;if(!t.length)return null;if(this.activeConvId!=null){const n=t.find(r=>r.id===this.activeConvId);if(n)return n}return t[0]||null},canBack(){return!!this.currentConv},statusUrl(){var r;const t=(r=this.widget)==null?void 0:r.quick_links;if(!Array.isArray(t))return"";const n=t.find(a=>a.icon==="status"&&a.url);return(n==null?void 0:n.url)||""},helpUrl(){var r;const t=(r=this.widget)==null?void 0:r.quick_links;if(!Array.isArray(t))return"";const n=t.find(a=>(a.icon==="chat"||a.icon==="help")&&a.url);return(n==null?void 0:n.url)||""},widget(){var t,n;return((n=(t=this.s)==null?void 0:t.config)==null?void 0:n.widget)||null},widgetWelcomeMessage(){var t;return((t=this.widget)==null?void 0:t.welcome_message)||""},agentName(){var t,n,r;return((r=(n=(t=this.s)==null?void 0:t.config)==null?void 0:n.agent)==null?void 0:r.name)||""},agentAvatarUrl(){var t,n,r;return((r=(n=(t=this.s)==null?void 0:t.config)==null?void 0:n.agent)==null?void 0:r.avatar_url)||null},quickLinks(){var n;const t=(n=this.widget)==null?void 0:n.quick_links;return Array.isArray(t)?t:[]},teamMembers(){var n;const t=(n=this.widget)==null?void 0:n.team_members;return Array.isArray(t)?t:[]},responseLabel(){var t;return((t=this.widget)==null?void 0:t.response_time_label)||""},humanMessageAuthor(){var n,r,a;if(!this.currentConv)return null;const t=((n=this.s.messagesByConv)==null?void 0:n[this.currentConv.id])||[];for(let s=t.length-1;s>=0;s--)if(((a=(r=t[s])==null?void 0:r.author)==null?void 0:a.type)==="agent_human")return t[s].author;return null},humanAgentName(){var t;return((t=this.humanMessageAuthor)==null?void 0:t.name)||""},humanAgentAvatarUrl(){var t;return((t=this.humanMessageAuthor)==null?void 0:t.avatar_url)||null},isEscalated(){return!!this.humanMessageAuthor},isWaitingHuman(){var n;const t=(n=this.currentConv)==null?void 0:n.status;return t==="waiting"||t==="handled"},headerTitle(){var t,n;return((t=this.currentConv)==null?void 0:t.name)||((n=this.widget)==null?void 0:n.name)||"Nouvelle conversation"},composerPlaceholder(){return this.isEscalated&&this.humanAgentName?`Répondre à ${this.humanAgentName.split(" ")[0]}…`:this.isWaitingHuman?"Un agent prend le relais…":"Écrivez votre message…"},displayedMessages(){const t=this.currentConv;if(!t)return[];const n=this.revealedAt;return(this.s.messagesByConv[t.id]||[]).filter(r=>{var a,s,o,i,l;return(r==null?void 0:r.type)==="action"&&((a=r==null?void 0:r.payload)==null?void 0:a.state)==="pending"||G(r)&&!(n[r.id]>0)?!1:(r==null?void 0:r.type)==="action"||(r==null?void 0:r.type)==="system"||((s=r==null?void 0:r.payload)==null?void 0:s.type)==="system"||Array.isArray((o=r==null?void 0:r.payload)==null?void 0:o.attachments)&&r.payload.attachments.length||(i=r==null?void 0:r.metadata)!=null&&i.artifact||(l=r==null?void 0:r.metadata)!=null&&l.form?!0:typeof(r==null?void 0:r.text_md)=="string"&&r.text_md.trim().length>0})},streamingActive(){var r,a,s;const t=this.currentConv;return t?Object.keys(((r=this.s)==null?void 0:r.streamingByMsgId)||{}).length>0?!0:this.actionInFlight?!1:(((s=(a=this.s)==null?void 0:a.messagesByConv)==null?void 0:s[t.id])||[]).some(o=>G(o)&&!(this.revealedAt[o.id]>0)):!1},currentConvMessages(){var n,r,a;const t=(n=this.currentConv)==null?void 0:n.id;return t?((a=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:a[t])||[]:[]},pendingApproval(){return!this.currentConv||!this.store||this.actionInFlight?null:this.store.getPendingApproval(this.currentConv.id)},approvalReady(){return this.pendingApproval?this.pendingApproval.id===this.approvalLatchId?!0:!(this.streamingActive||!this.approvalSettled):!1},approvalTitle(){var t,n,r;return((n=(t=this.pendingApproval)==null?void 0:t.payload)==null?void 0:n.name)||((r=this.pendingApproval)==null?void 0:r.text_md)||"Confirmer l'action"},approvalDetail(){var a,s,o,i,l,p;const t=(o=(s=(a=this.pendingApproval)==null?void 0:a.payload)==null?void 0:s.pending)==null?void 0:o.user_explanation;if(typeof t=="string"&&t.trim())return t.trim();const n=(p=(l=(i=this.pendingApproval)==null?void 0:i.payload)==null?void 0:l.pending)==null?void 0:p.prepared_params;if(!n||typeof n!="object")return"";const r=Object.entries(n);return r.length?r.slice(0,2).map(([v,y])=>`${v}: ${y}`).join(" · "):""},actionInFlight(){var t,n;return!this.currentConv||!this.store?null:((n=(t=this.store).getActionInFlight)==null?void 0:n.call(t,this.currentConv.id))||null},actionInFlightName(){var n;const t=this.actionInFlight;return t?((n=t.payload)==null?void 0:n.name)||t.text_md||"Action":""},suggestions(){return!this.currentConv||!this.store?[]:this.streamingActive?[]:this.pendingForm?[]:this.store.getLatestSuggestions(this.currentConv.id)},pendingForm(){var t,n;return!this.currentConv||!this.store||this.pendingApproval||this.actionInFlight||this.streamingActive||!this.approvalSettled?null:((n=(t=this.store).getLatestForm)==null?void 0:n.call(t,this.currentConv.id))||null},showFeedback(){var n;const t=this.currentConv;return t?this.feedbackDone?!0:t.status!=="resolved"?!1:!((n=t.metadata)!=null&&n.feedback):!1},floatVisible(){return this.approvalReady||!!this.pendingForm||this.showFeedback||this.suggestions.length>0},dateLabel(){var r,a,s;const t=this.currentConv;let n=new Date;if(t){const i=((s=(((a=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:a[t.id])||[]).find(l=>l==null?void 0:l.created_at))==null?void 0:s.created_at)||t.created_at;if(i){const l=new Date(i);Number.isNaN(l.getTime())||(n=l)}}return`Aujourd'hui · ${te(n)}`},paginationState(){var r,a,s;const t=(r=this.currentConv)==null?void 0:r.id,n=t?(s=(a=this.s)==null?void 0:a.paginationByConv)==null?void 0:s[t]:null;return{loading:!!(n!=null&&n.loading),hasMore:!!(n!=null&&n.nextCursor)}}},watch:{latestUnreads:{handler(t){const n=new Set(t.map(i=>i.convId)),r=this.dismissedPeeks||{},a=Object.keys(r);if(!a.length)return;const s={};let o=!1;for(const i of a)n.has(i)?s[i]=r[i]:o=!0;o&&(this.dismissedPeeks=s)},deep:!0},"currentConv.id":{handler(t){var n;this.resetRevealQueue(),this.convOpenedAt=Date.now(),this.moreOpen=!1,this.renameDialogOpen=!1,this.resetApprovalPacing(),this.isViewingThread&&(this.unreadAnchorId=R((n=this.currentConv)==null?void 0:n.last_read_message_id),this.unreadBoundaryTs=t?new Date().toISOString():"")},immediate:!0},isViewingThread(t,n){var r;t&&!n?(this.unreadAnchorId=R((r=this.currentConv)==null?void 0:r.last_read_message_id),this.unreadBoundaryTs=new Date().toISOString()):t||(this.unreadAnchorId=null,this.unreadBoundaryTs="")},pendingApproval:{handler(t,n){if(t&&!n){const r=t!=null&&t.created_at?Date.parse(t.created_at):NaN;if(!(Number.isFinite(r)&&r>=this.convOpenedAt)){this.resetApprovalPacing();return}this.bumpApprovalSettle(2600)}else!t&&n&&this.resetApprovalPacing()},immediate:!1},streamingActive(t,n){t!==n&&this.pendingApproval&&this.pendingApproval.id!==this.approvalLatchId&&this.bumpApprovalSettle()},approvalReady(t){t&&this.pendingApproval&&(this.approvalLatchId=this.pendingApproval.id)},floatVisible:{handler(t){this.$nextTick(()=>this.syncFloatObserver(t))},immediate:!0},currentConvMessages(t){this.paceMessages(t),(this.isOpen||this.isEmbedded)&&this.currentConv&&this.markConvRead(this.currentConv)}},async mounted(){if(typeof document<"u"&&!document.getElementById(le)){const t=document.createElement("style");t.id=le,t.textContent=ue,document.head.appendChild(t)}await this.boot(),this.isEmbedded&&this.store&&await this.open()},beforeUnmount(){this.cancelReveals(),this.disconnectFloatRO(),this.resetApprovalPacing(),this.teardownNotifications(),this.store&&this.store.destroy()},methods:{async boot(){if(!this.canBoot){console.warn("[messenger] boot skipped — missing creds");return}try{this.transport=e.markRaw(ce({baseUrl:this.baseUrl,widgetId:this.widgetId,userId:this.userId,userHash:this.userHash})),this.store=e.markRaw(de(this.transport)),this.hydrateNotifPref(),this.setupNotifications(),await this.store.start(),this.customer&&typeof this.customer=="object"&&await this.store.applyCustomer(this.customer)}catch(t){console.error("[ww-messenger] bootstrap failed",t),this.bootError=(t==null?void 0:t.message)||String(t)}},async refresh(){this.store&&this.store.destroy(),this.cancelReveals(),this.teardownNotifications(),this.convOpenedAt=0,this.transport=null,this.store=null,this.isOpen=!1,this.draft="",this.busy=!1,this.bootError=null,this.pendingAttachments=[],this.feedbackBusy=!1,this.feedbackDone=!1,this.moreOpen=!1,this.renameDialogOpen=!1,this.draftConv=null,this.activeConvId=null,this.showOnboarding=!1,await this.boot(),this.isEmbedded&&this.store&&await this.open()},syncFloatObserver(t){if(this.disconnectFloatRO(),!t){this.floatHeight=0;return}const n=this.$refs.floatEl;if(n){if(typeof ResizeObserver>"u"){this.floatHeight=Math.ceil(n.getBoundingClientRect().height+8);return}this.floatRO=new ResizeObserver(r=>{const a=r[0];if(!a)return;const s=Math.ceil(a.contentRect.height+8);s!==this.floatHeight&&(this.floatHeight=s,this.$nextTick(()=>{var o,i;(i=(o=this.$refs.messageList)==null?void 0:o.scrollToBottom)==null||i.call(o)}))}),this.floatRO.observe(n)}},disconnectFloatRO(){if(this.floatRO){try{this.floatRO.disconnect()}catch{}this.floatRO=null}},async open(){this.isOpen=!0,this.store&&this.store.setPanelOpen(!0);const t=this.currentConv;if(t&&!t._draft){this.activeConvId==null&&(this.activeConvId=t.id);try{await this.store.openConversation(t.id)}catch(n){console.error("[ww-messenger] load messages failed",n)}this.markConvRead(t)}},close(){this.isOpen=!1,this.store&&this.store.setPanelOpen(!1)},async openFromPeek(t){var r,a;const n=t||((r=this.latestUnreads[0])==null?void 0:r.convId);n&&n!==((a=this.currentConv)==null?void 0:a.id)&&(this.draftConv=null,this.activeConvId=n,this.showOnboarding=!1),await this.open()},dismissPeek(t){const n=this.latestUnreads.find(r=>r.convId===t);n&&(this.dismissedPeeks={...this.dismissedPeeks,[t]:n.ts})},startConv(){this.draftConv={id:"__draft__",_draft:!0,name:"",created_at:new Date().toISOString()},this.activeConvId=null,this.showOnboarding=!1,this.focusComposer()},async ensureRealConv(){const t=this.currentConv;if(!t)return null;if(!t._draft)return t;if(this.busy)return null;this.busy=!0;try{const n=await this.store.createConversation({});return this.draftConv=null,this.activeConvId=n.id,await this.store.openConversation(n.id),this.markConvRead(n),n}catch(n){return console.error("[ww-messenger] create conv failed",n),this.bootError=(n==null?void 0:n.message)||String(n),null}finally{this.busy=!1}},focusComposer(){this.$nextTick(()=>{var t;return(t=this.$refs.composer)==null?void 0:t.focus()})},toggleMore(){this.moreOpen=!this.moreOpen},goHome(){this.moreOpen=!1,this.draftConv=null,this.activeConvId=null,this.showOnboarding=!0},async onDrawerPick(t){if(!(t!=null&&t.id)||!this.store)return;this.draftConv=null,this.activeConvId=t.id,this.showOnboarding=!1;try{await this.store.openConversation(t.id)}catch(r){console.error("[ww-messenger] open conv failed",r)}const n=this.allConversations.find(r=>r.id===t.id);n&&this.markConvRead(n)},async onMoreAction(t){var n,r;switch(this.moreOpen=!1,t){case"rename":this.openRenameDialog();break;case"export":Je(this.currentConv,this.currentConv?(r=(n=this.s)==null?void 0:n.messagesByConv)==null?void 0:r[this.currentConv.id]:[]);break;case"status":if(this.statusUrl)try{window.open(this.statusUrl,"_blank","noopener")}catch{}break;case"help":if(this.helpUrl)try{window.open(this.helpUrl,"_blank","noopener")}catch{}break}},openRenameDialog(){const t=this.currentConv;!t||t._draft||(this.renameDialogOpen=!0)},async onRenameSubmit(t){const n=this.currentConv;if(this.renameDialogOpen=!1,!n||n._draft||!this.store)return;const r=(t||"").trim();if(!(!r||r===n.name))try{await this.store.patchConversation(n.id,{name:r})}catch(a){console.error("[ww-messenger] rename failed",a)}},async onSend(t){let n=this.currentConv;if(!n&&(this.startConv(),n=this.currentConv,!n)||n._draft&&(n=await this.ensureRealConv(),!n))return;const r=n.id,a=this.pendingAttachments.slice();this.pendingAttachments=[],this.unreadAnchorId=null,this.unreadBoundaryTs="",await this.store.send(r,t,{attachments:a.length?a:void 0})},async onSuggestion(t){const n=t==null?void 0:t.label;n&&await this.onSend(n)},async onLoadMore(){var n;const t=(n=this.currentConv)==null?void 0:n.id;!t||!this.store||await this.store.loadMore(t)},async onApprovalCallback(t){const n=this.pendingApproval;n&&await this.store.clickCallback(n.id,t)},async onFormSubmit({values:t}){const n=this.pendingForm;if(!(n!=null&&n.form))return;const r=Ke(n.form,t);if(!r)return;let a=this.currentConv;a&&(a._draft&&(a=await this.ensureRealConv(),!a)||await this.store.send(a.id,r,{metadata:{artifact:We(n.form,t)}}))},async onAttach(t){if(!(!t||!this.transport))try{const n=await this.transport.uploadAttachment(t);this.pendingAttachments.push({type:n.type||"file",path:n.path,name:t.name||"fichier",mime_type:t.type,size_bytes:t.size})}catch(n){console.error("[ww-messenger] attachment upload failed",n)}},async onQuickLink(t){if(t){if(t.url){try{window.open(t.url,"_blank","noopener")}catch{}return}this.currentConv||this.startConv(),await this.onSend(t.label)}},async onFeedback({rating:t,comment:n}){if(this.currentConv){this.feedbackBusy=!0;try{await this.store.submitFeedback(this.currentConv.id,{rating:t,comment:n}),this.feedbackDone=!0}catch(r){console.error("[ww-messenger] feedback failed",r)}finally{this.feedbackBusy=!1}}}}},As={key:0,class:"wm-loading","aria-busy":"true","aria-live":"polite"},Vs={key:0,class:"wm-state"},Ms={class:"wm-state__err"},Ts={class:"wm-state__errSub"},xs={class:"wm-bottom"},Os={key:0,ref:"floatEl",class:"wm-float"},Is={key:1,class:"wm-actionWait",role:"status","aria-live":"polite"},Ds={class:"wm-actionWait__lbl"},Ls={key:2,class:"wm-attached"},Rs=["onClick"];function Fs(t,n,r,a,s,o){const i=e.resolveComponent("Launcher"),l=e.resolveComponent("Header"),p=e.resolveComponent("Onboarding"),v=e.resolveComponent("MessageList"),y=e.resolveComponent("ApprovalCard"),E=e.resolveComponent("FormCard"),S=e.resolveComponent("Feedback"),k=e.resolveComponent("SuggestionChips"),x=e.resolveComponent("Composer"),w=e.resolveComponent("MoreMenu"),M=e.resolveComponent("RenameDialog");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-root",`wm-root--${r.displayMode}`])},[!s.isOpen&&!o.isEmbedded?(e.openBlock(),e.createBlock(i,{key:0,"unread-count":o.unreadCount,peeks:o.launcherPeeks,onOpen:o.openFromPeek,onDismiss:o.dismissPeek},null,8,["unread-count","peeks","onOpen","onDismiss"])):e.createCommentVNode("",!0),s.isOpen||o.isEmbedded?(e.openBlock(),e.createElementBlock("section",{key:1,class:e.normalizeClass(["wm-panel",`wm-panel--${r.displayMode}`]),style:e.normalizeStyle(s.floatHeight?{"--wm-float-h":s.floatHeight+"px"}:null),role:"dialog","aria-label":"Messenger"},[!o.ready&&!o.error?(e.openBlock(),e.createElementBlock("div",As,[o.isEmbedded?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-loading__close","aria-label":"Réduire",onClick:n[0]||(n[0]=(...A)=>o.close&&o.close(...A))},[...n[5]||(n[5]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])),n[6]||(n[6]=e.createElementVNode("div",{class:"wm-loading__spinner","aria-hidden":"true"},null,-1))])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createVNode(l,{title:o.headerTitle,escalated:o.isEscalated,"agent-name":o.humanAgentName,"agent-avatar-url":o.humanAgentAvatarUrl,"team-members":o.teamMembers,"response-label":o.responseLabel,"show-identity":!!o.currentConv,"show-back":o.canBack,"show-close":!o.isEmbedded,"more-active":s.moreOpen,onBack:o.goHome,onMore:o.toggleMore,onClose:o.close},null,8,["title","escalated","agent-name","agent-avatar-url","team-members","response-label","show-identity","show-back","show-close","more-active","onBack","onMore","onClose"]),o.error?(e.openBlock(),e.createElementBlock("div",Vs,[e.createElementVNode("div",Ms,[n[8]||(n[8]=e.createElementVNode("div",{class:"wm-state__errIcon"},[e.createElementVNode("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})])],-1)),e.createElementVNode("div",null,[n[7]||(n[7]=e.createElementVNode("div",{class:"wm-state__errTitle"},"Connexion impossible",-1)),e.createElementVNode("div",Ts,e.toDisplayString(o.error),1)])])])):o.currentConv?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createVNode(v,{ref:"messageList",messages:o.displayedMessages,"streaming-active":o.streamingActive,"date-label":o.dateLabel,"conversation-id":o.currentConv?o.currentConv.id:null,"loading-more":o.paginationState.loading,"has-more":o.paginationState.hasMore,"unread-anchor-id":t.unreadAnchorId,"unread-boundary-ts":t.unreadBoundaryTs,onLoadMore:o.onLoadMore},null,8,["messages","streaming-active","date-label","conversation-id","loading-more","has-more","unread-anchor-id","unread-boundary-ts","onLoadMore"]),e.createElementVNode("div",xs,[o.floatVisible?(e.openBlock(),e.createElementBlock("div",Os,[o.approvalReady?(e.openBlock(),e.createBlock(y,{key:0,action:o.approvalTitle,detail:o.approvalDetail,callbacks:o.pendingApproval.callbacks,onCallback:o.onApprovalCallback},null,8,["action","detail","callbacks","onCallback"])):o.pendingForm?(e.openBlock(),e.createBlock(E,{key:o.pendingForm.message&&o.pendingForm.message.id,form:o.pendingForm.form,onSubmit:o.onFormSubmit},null,8,["form","onSubmit"])):o.showFeedback?(e.openBlock(),e.createBlock(S,{key:2,busy:s.feedbackBusy,done:s.feedbackDone,onSubmit:o.onFeedback},null,8,["busy","done","onSubmit"])):(e.openBlock(),e.createBlock(k,{key:3,items:o.suggestions,onSelect:o.onSuggestion},null,8,["items","onSelect"]))],512)):e.createCommentVNode("",!0),o.actionInFlight?(e.openBlock(),e.createElementBlock("div",Is,[n[9]||(n[9]=e.createElementVNode("span",{class:"wm-actionWait__spinner","aria-hidden":"true"},null,-1)),e.createElementVNode("span",Ds,e.toDisplayString(o.actionInFlightName)+" en cours, veuillez patienter…",1)])):(e.openBlock(),e.createBlock(x,{key:2,ref:"composer",modelValue:s.draft,"onUpdate:modelValue":n[1]||(n[1]=A=>s.draft=A),placeholder:o.composerPlaceholder,disabled:!!o.pendingApproval,"attach-label":"Joindre un fichier",onSend:o.onSend,onAttach:o.onAttach},null,8,["modelValue","placeholder","disabled","onSend","onAttach"]))]),s.moreOpen?(e.openBlock(),e.createBlock(w,{key:0,"can-rename":!!o.currentConv&&!o.currentConv._draft,"can-export":!!o.currentConv&&!o.currentConv._draft,"sound-enabled":t.soundEnabled,"browser-notif-enabled":t.browserNotifEnabled,"status-url":o.statusUrl,"help-url":o.helpUrl,onClose:n[2]||(n[2]=A=>s.moreOpen=!1),onSoundToggle:t.onSoundToggle,onBrowserNotifToggle:t.onBrowserNotifToggle,onAction:o.onMoreAction},null,8,["can-rename","can-export","sound-enabled","browser-notif-enabled","status-url","help-url","onSoundToggle","onBrowserNotifToggle","onAction"])):e.createCommentVNode("",!0),s.renameDialogOpen&&o.currentConv&&!o.currentConv._draft?(e.openBlock(),e.createBlock(M,{key:1,"initial-value":o.currentConv.name||"",title:"Modifier le titre de la conversation",onClose:n[3]||(n[3]=A=>s.renameDialogOpen=!1),onSubmit:o.onRenameSubmit},null,8,["initial-value","onSubmit"])):e.createCommentVNode("",!0),s.pendingAttachments.length?(e.openBlock(),e.createElementBlock("div",Ls,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.pendingAttachments,(A,T)=>(e.openBlock(),e.createElementBlock("div",{key:T,class:"wm-attached__chip"},[n[11]||(n[11]=e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"})],-1)),e.createElementVNode("span",null,e.toDisplayString(A.name),1),e.createElementVNode("button",{type:"button","aria-label":"Retirer",onClick:D=>s.pendingAttachments.splice(T,1)},[...n[10]||(n[10]=[e.createElementVNode("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,Rs)]))),128))])):e.createCommentVNode("",!0)],64)):(e.openBlock(),e.createBlock(p,{key:1,"welcome-message":o.widgetWelcomeMessage,"agent-name":o.agentName,"quick-links":o.quickLinks,"open-threads":o.openThreads,busy:s.busy,onStart:o.startConv,onSelect:o.onQuickLink,onResume:o.onDrawerPick},null,8,["welcome-message","agent-name","quick-links","open-threads","busy","onStart","onSelect","onResume"])),s.moreOpen&&!o.currentConv?(e.openBlock(),e.createBlock(w,{key:3,"can-rename":!1,"can-export":!1,"sound-enabled":t.soundEnabled,"browser-notif-enabled":t.browserNotifEnabled,"status-url":o.statusUrl,"help-url":o.helpUrl,onClose:n[4]||(n[4]=A=>s.moreOpen=!1),onSoundToggle:t.onSoundToggle,onBrowserNotifToggle:t.onBrowserNotifToggle,onAction:o.onMoreAction},null,8,["sound-enabled","browser-notif-enabled","status-url","help-url","onSoundToggle","onBrowserNotifToggle","onAction"])):e.createCommentVNode("",!0)],64))],6)):e.createCommentVNode("",!0)],2)}const Fe=N(Ss,[["render",Fs],["__scopeId","data-v-b5eb5af4"]]),$s="0.3.10";exports.AIAvatar=U;exports.AVATAR_COLORS=W;exports.ActionResult=ve;exports.ApprovalCard=Ie;exports.ArtifactFormResponse=ye;exports.ArtifactInfoCard=ke;exports.ArtifactRenderer=be;exports.ArtifactTicket=we;exports.AttachmentPreview=Ee;exports.Bubble=Be;exports.Composer=xe;exports.DEFAULT_BASE_URL=me;exports.Feedback=Le;exports.FormCard=De;exports.Header=_e;exports.HumanAvatar=Y;exports.Launcher=fe;exports.MEDIA_RECORDER_SUPPORTED=X;exports.MessageList=Se;exports.Messenger=Fe;exports.MoreMenu=Re;exports.Onboarding=ge;exports.SCREEN_CAPTURE_SUPPORTED=z;exports.SuggestionChips=Oe;exports.TeamAvatars=pe;exports.Typing=Ne;exports.VERSION=$s;exports.avatarColor=Z;exports.avatarInitials=ee;exports.captureScreenshotFile=Me;exports.colors=V;exports.createStore=de;exports.createTransport=ce;exports.default=Fe;exports.formatTime=te;exports.guessAttachmentKind=Jr;exports.pickRecorderMime=Ae;exports.renderMarkdown=Ce;exports.startScreenRecording=Te;exports.tokensCss=ue;exports.uuid=Q;exports.v4=Q;