@_solaris/messenger-widget 0.3.6 → 0.3.7

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,4 +1,4 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),Re=["connected","message","message_stream","conversation_updated","config_updated","action_status"],te="/client",$e=5*60*1e3,Fe=10*60*1e3,Ue=5*60*1e3;function ae(n){const t={baseUrl:je(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 i(d,m){const p=t.listeners.get(d);p&&p.forEach(_=>{try{_(m)}catch(E){console.error("[transport] listener",d,E)}})}function o(d){t.connection!==d&&(t.connection=d,i("connection",d))}function s(){return{"X-User-Id":t.userId,"X-User-Hash":t.userHash,"X-Widget-Id":t.widgetId}}async function a(d,m,p){const _=await fetch(`${t.baseUrl}${te}${m}`,{method:d,headers:{"Content-Type":"application/json",...s()},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()}),a("GET","/customers/me")]);return{config:d,customer:(m==null?void 0:m.customer)??null}}async function y(){const d=await a("GET","/customers/me");return(d==null?void 0:d.customer)??null}async function g(d){const m=await a("PATCH","/customers/me",d);return(m==null?void 0:m.customer)??null}async function w(){const d=await a("GET","/conversations");return(d==null?void 0:d.conversations)??[]}async function S(d={}){return(await a("POST","/conversations",d)).conversation}async function k(d){return(await a("GET",`/conversations/${encodeURIComponent(d)}`)).conversation}async function A(d,m){return(await a("PATCH",`/conversations/${encodeURIComponent(d)}`,m)).conversation}async function b(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 a("GET",`/conversations/${encodeURIComponent(d)}/messages${_}`)}async function x(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),a("POST",`/conversations/${encodeURIComponent(d)}/messages`,p)}async function M(d,m,p){return D(),a("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 a("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:Pe(p),path:E.path,mime_type:p,size_bytes:_}}async function O(d){return a("GET",`/attachments/sign?path=${encodeURIComponent(d)}`)}function R(){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(R());for(const m of Re)d.addEventListener(m,p=>F(m,p.data));d.addEventListener("error",()=>i("error",new Error("SSE error"))),t.eventSource=d,o("open")}catch(d){console.error("[transport] SSE open failed",d),i("error",d)}}function F(d,m){try{const p=JSON.parse(m),_=p&&typeof p=="object"&&"data"in p?p.data:p;i(d,_)}catch(p){console.error("[transport] bad SSE payload",d,p)}}function L(){t.eventSource&&(t.eventSource.close(),t.eventSource=null),t.connection!=="paused"&&o("idle")}function D(){clearTimeout(t.burstTimer),I(),t.panelOpen||(t.burstTimer=setTimeout(()=>{t.panelOpen||L()},Fe))}function $(d){t.panelOpen=!!d,t.panelOpen?(clearTimeout(t.burstTimer),I()):D()}async function J(){try{const d=await w(),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,i("activity",{conversations:d,latestAt:m}),D())}catch(d){console.error("[transport] poll failed",d)}}function z(){c(),!(typeof document<"u"&&document.hidden)&&(t.pollTimer=setInterval(J,$e))}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(),o("paused"))},Ue);else{if(t.hiddenGraceTimer){clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=null;return}o("idle"),z(),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 w();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)),z(),d}function v(){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:v,setPanelOpen:$,bootstrap:f,getCustomer:y,patchCustomer:g,listConversations:w,createConversation:S,getConversation:k,patchConversation:A,listMessages:b,postMessage:x,postCallback:M,uploadAttachment:V,signAttachment:O,get connection(){return t.connection}}}function je(n){return n.endsWith("/")?n.slice(0,-1):n}function Pe(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 ie(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 v=t.conversations.findIndex(d=>d.id===u);v!==-1&&(t.conversations[v]={...t.conversations[v],...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,v=c==null?void 0:c.action_name;if(!u||!h)return;const d=t.runningActionsByConv[u]||{};c.state==="running"?(d[h]=v||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 i(){try{const c=new Promise((h,v)=>setTimeout(()=>v(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 o(){for(const c of r)try{c()}catch{}n.stop()}async function s(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 a(c={}){const u=await n.createConversation(c),h=t.conversations.findIndex(v=>v.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)){g(c,{nextCursor:null,loading:!0,loaded:!1});try{const h=await n.listMessages(c,{limit:l}),v=(h==null?void 0:h.messages)??[],d=t.messagesByConv[c]||[],m=new Set;for(const _ of v)(_==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]=[...v,...p].sort($),g(c,{nextCursor:(h==null?void 0:h.next_cursor)??null,loading:!1,loaded:!0})}catch(h){console.error("[store] openConversation failed",h),g(c,{nextCursor:null,loading:!1,loaded:!1})}}}async function y(c){var d;const u=t.paginationByConv[c];if(!u||u.loading||!u.nextCursor)return;const v=(d=(t.messagesByConv[c]||[]).find(m=>m==null?void 0:m.created_at))==null?void 0:d.created_at;if(v){g(c,{...u,loading:!0});try{const m=await n.listMessages(c,{before:v,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,..._],g(c,{nextCursor:(m==null?void 0:m.next_cursor)??null,loading:!1,loaded:!0})}catch(m){console.error("[store] loadMore failed",m),g(c,{...u,loading:!1})}}}function g(c,u){t.paginationByConv={...t.paginationByConv,[c]:u}}async function w(c,u){const h=await n.patchConversation(c,u),v=t.conversations.findIndex(d=>d.id===c);v!==-1&&(t.conversations[v]=h)}async function S(c,u,{attachments:h,metadata:v}={}){var B;const d=(u||"").trim(),m=Array.isArray(h)&&h.length>0;if(!c||!d&&!m)return;const p=X(),_=z(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}}:{},...v&&typeof v=="object"?{metadata:v}:{}};I(c,E);try{await n.postMessage(c,{client_msg_id:p,text_md:d,created_at:_,...m?{attachments:h}:{},...v&&typeof v=="object"?{metadata:v}:{}})}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(v){console.error("[store] callback failed",v),c!=null&&delete t.awaitingCallback[c]}}const A=new Map;async function b(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 x(c,{rating:u,comment:h}={}){const v=t.conversations.find(p=>p.id===c),m={...(v==null?void 0:v.metadata)||{},feedback:{rating:u,comment:h||null,submitted_at:new Date().toISOString()}};await w(c,{metadata:m})}function M(c){var h,v;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"&&((v=m==null?void 0:m.payload)==null?void 0:v.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,v,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"&&((v=p==null?void 0:p.payload)==null?void 0:v.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 v=h[0];return{id:v,payload:{name:u[v]}}}function R(c){var h,v,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"&&((v=_==null?void 0:_.payload)==null?void 0:v.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 Le=B.kind==="cta"||B.kind==="choice"||B.kind==="followup"?B.kind:null;return{label:C,kind:Le}}return null}).filter(Boolean).slice(0,4):[]}return[]}function I(c,u){var m;const h=t.messagesByConv[c]||[];let v=-1;u!=null&&u.client_msg_id&&(v=h.findIndex(p=>(p==null?void 0:p.client_msg_id)&&p.client_msg_id===u.client_msg_id)),v===-1&&(u==null?void 0:u.id)!==void 0&&(u==null?void 0:u.id)!==null&&(v=h.findIndex(p=>F(p==null?void 0:p.id,u.id)));let d;v===-1?d=[...h,u].sort($):(d=h.slice(),d[v]={...h[v],...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 v=t.messagesByConv[c];if(!v)return;const d=v.findIndex(p=>p.id===u);if(d===-1)return;const m=v.slice();m[d]={...v[d],...h},t.messagesByConv[c]=m}function D(c,u){const h=t.conversations.findIndex(d=>d.id===c);if(h===-1)return;const v=t.conversations[h];if(u&&(!v.last_message_at||u>v.last_message_at)){const d=t.conversations.slice();d[h]={...v,last_message_at:u},d.sort((m,p)=>(p.last_message_at||"").localeCompare(m.last_message_at||"")),t.conversations=d}}function $(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[v,d]of Object.entries(c))d!==void 0&&(v==="name"||v==="email"?d!=null&&String(d).trim()!==""&&(u[v]=d):(v==="values"||v==="metadata")&&d&&typeof d=="object"?Object.assign(h,d):h[v]=d);return Object.keys(h).length&&(u.values=h),Object.keys(u).length?u:null}function z(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 v=new Date().toISOString();return!h||v>h?v:new Date(Date.parse(h)+1).toISOString()}return{state:t,start:i,destroy:o,applyCustomer:s,createConversation:a,openConversation:f,loadMore:y,patchConversation:w,send:S,clickCallback:k,signAttachment:b,submitFeedback:x,getPendingApproval:M,getActionInFlight:O,getLatestSuggestions:R,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"},K=["#5B5FEF","#7C3AED","#DB2777","#0891B2","#D97706","#059669"];function Z(n=""){return n?K[n.charCodeAt(0)%K.length]:K[0]}function Q(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 le=`
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",Pe=5*60*1e3,je=10*60*1e3,ze=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 V(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 x(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 M(d,m,p){return D(),i("POST",`/messages/${encodeURIComponent(d)}/callbacks/${encodeURIComponent(m)}`,p?{inputs:p}:{})}async function S(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 L(){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(L());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 $(){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||$()},je))}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,Pe))}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(),$(),s("paused"))},ze);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,$(),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:V,getConversation:k,patchConversation:A,listMessages:w,postMessage:x,postCallback:M,uploadAttachment:S,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 V(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),$(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 x(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 M(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 S(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 L(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 $(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:V,clickCallback:k,signAttachment:w,submitFeedback:x,getPendingApproval:M,getActionInFlight:O,getLatestSuggestions:L,getLatestForm:S,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=`
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 {
@@ -44,13 +44,13 @@
44
44
  0% { transform: translateX(110%); opacity: 0; }
45
45
  100% { transform: translateX(0); opacity: 1; }
46
46
  }
47
- `,ce="https://api.messenger.victorc.fr",N=(n,t)=>{const r=n.__vccOpts||n;for(const[i,o]of t)r[i]=o;return r},ze={name:"WmHumanAvatar",props:{name:{type:String,default:""},avatarUrl:{type:String,default:null},size:{type:Number,default:26}},computed:{bg(){return this.avatarUrl?"transparent":Z(this.name)},initials(){return Q(this.name)}}},He=["src","alt"];function qe(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",{class:"wm-huav",style:e.normalizeStyle({width:r.size+"px",height:r.size+"px","--wm-avr":Math.round(r.size*.32)+"px",background:s.bg})},[r.avatarUrl?(e.openBlock(),e.createElementBlock("img",{key:0,src:r.avatarUrl,alt:r.name||""},null,8,He)):(e.openBlock(),e.createElementBlock("span",{key:1,style:e.normalizeStyle({fontSize:r.size*.36+"px"})},e.toDisplayString(s.initials),5))],4)}const G=N(ze,[["render",qe],["__scopeId","data-v-a772b179"]]),Ke=2,We=6,Ge={name:"WmLauncher",components:{HumanAvatar:G},props:{unreadCount:{type:Number,default:0},peeks:{type:Array,default:()=>[]}},emits:["open","dismiss"],computed:{behindCount(){return Math.min(Math.max(this.peeks.length-1,0),Ke)},stackExtra(){return this.behindCount*We}}},Ye={class:"wm-launcherWrap"},Je=["aria-label"],Xe={class:"wm-peek__avatar"},Ze=["aria-label"],Qe={class:"wm-peek__body"},et={class:"wm-peek__head"},tt={class:"wm-peek__name"},nt={class:"wm-peek__text"},rt=["aria-label"];function st(n,t,r,i,o,s){const a=e.resolveComponent("HumanAvatar");return e.openBlock(),e.createElementBlock("div",Ye,[e.createVNode(e.Transition,{name:"wm-peek"},{default:e.withCtx(()=>[r.peeks.length?(e.openBlock(),e.createElementBlock("div",{key:0,class:"wm-peekStack",style:e.normalizeStyle({"--wm-stack-extra":s.stackExtra+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.behindCount,l=>(e.openBlock(),e.createElementBlock("div",{key:`behind-${l}`,class:"wm-peek wm-peek--ghost",style:e.normalizeStyle({"--i":l}),"aria-hidden":"true"},null,4))),128)),e.createElementVNode("div",{class:"wm-peek wm-peek--top",role:"button",tabindex:"0","aria-label":`Ouvrir la conversation avec ${r.peeks[0].senderName||"l'agent"}`,onClick:t[2]||(t[2]=l=>n.$emit("open",r.peeks[0].convId)),onKeydown:[t[3]||(t[3]=e.withKeys(e.withModifiers(l=>n.$emit("open",r.peeks[0].convId),["prevent"]),["enter"])),t[4]||(t[4]=e.withKeys(e.withModifiers(l=>n.$emit("open",r.peeks[0].convId),["prevent"]),["space"]))]},[e.createElementVNode("button",{type:"button",class:"wm-peek__close","aria-label":"Ignorer",onClick:t[0]||(t[0]=e.withModifiers(l=>n.$emit("dismiss",r.peeks[0].convId),["stop"]))},[...t[6]||(t[6]=[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)])]),e.createElementVNode("div",Xe,[e.createVNode(a,{name:r.peeks[0].senderName,"avatar-url":r.peeks[0].senderAvatarUrl,size:34},null,8,["name","avatar-url"]),r.peeks[0].count>1?(e.openBlock(),e.createElementBlock("span",{key:0,class:"wm-peek__avatarBadge","aria-label":`${r.peeks[0].count} messages non lus`},e.toDisplayString(r.peeks[0].count>9?"9+":r.peeks[0].count),9,Ze)):e.createCommentVNode("",!0)]),e.createElementVNode("div",Qe,[e.createElementVNode("div",et,[e.createElementVNode("span",tt,e.toDisplayString(r.peeks[0].senderName||"Agent"),1),t[7]||(t[7]=e.createElementVNode("span",{class:"wm-peek__action"}," vous a répondu",-1))]),e.createElementVNode("p",nt,e.toDisplayString(r.peeks[0].preview),1)]),e.createElementVNode("button",{type:"button",class:"wm-peek__open",onClick:t[1]||(t[1]=e.withModifiers(l=>n.$emit("open",r.peeks[0].convId),["stop"]))},"Ouvrir")],40,Je)],4)):e.createCommentVNode("",!0)]),_:1}),e.createElementVNode("button",{type:"button",class:"wm-launcher","aria-label":"Ouvrir le messenger",onClick:t[5]||(t[5]=l=>n.$emit("open"))},[t[8]||(t[8]=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,rt)):e.createCommentVNode("",!0)])])}const de=N(Ge,[["render",st],["__scopeId","data-v-e7ea0209"]]),ot={name:"WmAIAvatar",props:{size:{type:Number,default:26},pulse:{type:Boolean,default:!1},tail:{type:Boolean,default:!1}}},at={key:0,class:"wm-aiav__pulse"},it=["width","height"];function lt(n,t,r,i,o,s){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",at)):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,it))],2)],6)}const U=N(ot,[["render",lt],["__scopeId","data-v-8c924688"]]),ct={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":Z(n.name||"")},initialsFor(n){return Q(n.name||"")}}},dt={key:0,class:"wm-team"},ut=["src","alt"],mt={key:1},ht={key:0,class:"wm-team__label"};function pt(n,t,r,i,o,s){return s.visible?(e.openBlock(),e.createElementBlock("div",dt,[e.createElementVNode("div",{class:"wm-team__stack",style:e.normalizeStyle({width:s.stackWidth+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.members.slice(0,3),(a,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-team__pill",style:e.normalizeStyle({left:l*13+"px",zIndex:3-l,background:s.colorFor(a)})},[a.avatar_url?(e.openBlock(),e.createElementBlock("img",{key:0,src:a.avatar_url,alt:a.name||""},null,8,ut)):(e.openBlock(),e.createElementBlock("span",mt,e.toDisplayString(s.initialsFor(a)),1))],4))),128))],4),r.responseLabel?(e.openBlock(),e.createElementBlock("span",ht,e.toDisplayString(r.responseLabel),1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)}const ue=N(ct,[["render",pt],["__scopeId","data-v-3659b9c1"]]),ft={name:"WmHeader",components:{AIAvatar:U,HumanAvatar:G,TeamAvatars:ue},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},showPresence(){return this.hasTeam||this.escalated&&!!this.agentName},statusText(){return this.escalated&&this.agentName?this.agentName:"En ligne"}}},_t={class:"wm-header"},gt={key:1,style:{width:"30px",height:"30px","flex-shrink":"0"}},vt={class:"wm-header__avatar"},yt={class:"wm-header__main"},kt={class:"wm-header__title"},wt={key:0,class:"wm-header__sub"},bt={class:"wm-header__status"},Et={key:3,class:"wm-header__fill"},Bt={class:"wm-header__actions"};function Ct(n,t,r,i,o,s){const a=e.resolveComponent("HumanAvatar"),l=e.resolveComponent("AIAvatar"),f=e.resolveComponent("TeamAvatars");return e.openBlock(),e.createElementBlock("div",_t,[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]=y=>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",gt)),r.showIdentity?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createElementVNode("div",vt,[r.escalated?(e.openBlock(),e.createBlock(a,{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",yt,[e.createElementVNode("div",kt,e.toDisplayString(r.title),1),s.showPresence?(e.openBlock(),e.createElementBlock("div",wt,[s.hasTeam?(e.openBlock(),e.createBlock(f,{key:0,members:r.teamMembers,"response-label":r.responseLabel},null,8,["members","response-label"])):e.createCommentVNode("",!0),e.createElementVNode("span",bt,[t[4]||(t[4]=e.createElementVNode("span",{class:"wm-header__dot"},null,-1)),e.createTextVNode(" "+e.toDisplayString(s.statusText),1)])])):e.createCommentVNode("",!0)])],64)):(e.openBlock(),e.createElementBlock("div",Et)),e.createElementVNode("div",Bt,[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]=y=>n.$emit("more"))},[...t[5]||(t[5]=[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]=y=>n.$emit("close"))},[...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)])])):e.createCommentVNode("",!0)])])}const me=N(ft,[["render",Ct],["__scopeId","data-v-b5f5f6a9"]]),ne={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"},Nt={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","view-all"],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.
48
- Je réponds en quelques secondes.`}},methods:{iconPath(n){return ne[n]||ne.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 s=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0");return`${s}h${a}`}if(r.getTime()-t.getTime()<7*864e5){const s=t.toLocaleDateString("fr-FR",{weekday:"short"});return s.charAt(0).toUpperCase()+s.slice(1)}return t.toLocaleDateString("fr-FR",{day:"2-digit",month:"2-digit"})}}},St={class:"wm-onb"},Vt={class:"wm-onb__hero"},At={class:"wm-onb__title"},Tt={class:"wm-onb__sub"},xt={key:0,class:"wm-onb__section"},Mt={class:"wm-onb__grid"},Ot=["onClick"],It={class:"wm-onb__card-icon"},Dt={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"},Lt=["d"],Rt={class:"wm-onb__card-title"},$t={key:0,class:"wm-onb__card-sub"},Ft={key:1,class:"wm-onb__section"},Ut={class:"wm-onb__list"},jt=["onClick"],Pt={class:"wm-onb__thread-icon"},zt={key:0,class:"wm-onb__thread-dot","aria-label":"Non lu"},Ht={class:"wm-onb__thread-body"},qt={class:"wm-onb__thread-title"},Kt={class:"wm-onb__thread-preview"},Wt={class:"wm-onb__thread-meta"},Gt={key:0,class:"wm-onb__thread-time"},Yt={class:"wm-onb__cta"},Jt=["disabled"];function Xt(n,t,r,i,o,s){const a=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",St,[e.createElementVNode("div",Vt,[e.createVNode(a,{size:56,pulse:!0}),e.createElementVNode("div",At,e.toDisplayString(s.heroTitle),1),e.createElementVNode("div",Tt,e.toDisplayString(s.heroSub),1)]),r.quickLinks.length?(e.openBlock(),e.createElementBlock("div",xt,[t[2]||(t[2]=e.createElementVNode("div",{class:"wm-onb__section-title"},"Accès rapide",-1)),e.createElementVNode("div",Mt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.quickLinks,(l,f)=>(e.openBlock(),e.createElementBlock("button",{key:f,type:"button",class:"wm-onb__card",onClick:y=>n.$emit("select",l)},[e.createElementVNode("span",It,[(e.openBlock(),e.createElementBlock("svg",Dt,[e.createElementVNode("path",{d:s.iconPath(l.icon)},null,8,Lt)]))]),e.createElementVNode("span",Rt,e.toDisplayString(l.label),1),l.description?(e.openBlock(),e.createElementBlock("span",$t,e.toDisplayString(l.description),1)):e.createCommentVNode("",!0)],8,Ot))),128))])])):e.createCommentVNode("",!0),r.openThreads.length?(e.openBlock(),e.createElementBlock("div",Ft,[t[6]||(t[6]=e.createElementVNode("div",{class:"wm-onb__section-title"},"Conversations récentes",-1)),e.createElementVNode("div",Ut,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.openThreads,l=>(e.openBlock(),e.createElementBlock("button",{key:l.id,type:"button",class:"wm-onb__thread",onClick:f=>n.$emit("resume",l)},[e.createElementVNode("span",Pt,[t[3]||(t[3]=e.createElementVNode("svg",{width:"18",height:"18",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:"M12 5v14M5 12h14"})],-1)),l.unread?(e.openBlock(),e.createElementBlock("span",zt)):e.createCommentVNode("",!0)]),e.createElementVNode("span",Ht,[e.createElementVNode("span",qt,e.toDisplayString(l.title),1),e.createElementVNode("span",Kt,e.toDisplayString(l.preview),1)]),e.createElementVNode("span",Wt,[s.formatTs(l._ts)?(e.openBlock(),e.createElementBlock("span",Gt,e.toDisplayString(s.formatTs(l._ts)),1)):e.createCommentVNode("",!0),t[4]||(t[4]=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,jt))),128)),e.createElementVNode("button",{type:"button",class:"wm-onb__viewAll",onClick:t[0]||(t[0]=l=>n.$emit("view-all"))},[...t[5]||(t[5]=[e.createTextVNode(" Voir toutes les conversations ",-1),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 18l6-6-6-6"})],-1)])])])])):e.createCommentVNode("",!0),e.createElementVNode("div",Yt,[e.createElementVNode("button",{type:"button",class:"wm-onb__startBtn",disabled:r.busy,onClick:t[1]||(t[1]=l=>n.$emit("start"))},e.toDisplayString(r.busy?"…":"Commencer une conversation"),9,Jt)])])}const he=N(Nt,[["render",Xt],["__scopeId","data-v-770bfafa"]]);function Zt(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 Qt={name:"WmActionResult",props:{state:{type:String,default:"success"},label:{type:String,required:!0},detail:{type:String,default:""}},computed:{detailText(){return Zt(this.detail)}}},en={class:"wm-result__icon","aria-hidden":"true"},tn={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"},nn={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"},rn={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"},sn={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"},on={class:"wm-result__body"},an={class:"wm-result__label"},ln={class:"wm-result__detail"};function cn(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-result",`wm-result--${r.state}`])},[e.createElementVNode("span",en,[r.state==="success"?(e.openBlock(),e.createElementBlock("svg",tn,[...t[0]||(t[0]=[e.createElementVNode("path",{d:"M20 6L9 17l-5-5"},null,-1)])])):r.state==="rejected"?(e.openBlock(),e.createElementBlock("svg",nn,[...t[1]||(t[1]=[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"},null,-1)])])):r.state==="awaiting"?(e.openBlock(),e.createElementBlock("svg",rn,[...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",sn,[...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",on,[e.createElementVNode("span",an,e.toDisplayString(r.label),1),s.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",ln,e.toDisplayString(s.detailText),1)],64)):e.createCommentVNode("",!0)])],2)}const pe=N(Qt,[["render",cn],["__scopeId","data-v-64a83fb8"]]),dn={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:[]}}},un={class:"wm-art wm-art--formResponse"},mn={class:"wm-art__head"},hn={class:"wm-art__title"},pn={class:"wm-art__body"},fn={class:"wm-art__fieldLabel"};function _n(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",un,[e.createElementVNode("div",mn,[e.createElementVNode("div",hn,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",pn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.fields,(a,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",fn,e.toDisplayString(a.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":a.multiline}])},e.toDisplayString(a.value),3)]))),128))])])}const fe=N(dn,[["render",_n],["__scopeId","data-v-ca24a9c9"]]),gn={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}}},vn={class:"wm-art wm-art--infoCard"},yn={key:0,class:"wm-art__image"},kn=["src","alt"],wn={class:"wm-art__head"},bn={class:"wm-art__headMain"},En={class:"wm-art__title"},Bn={key:0,class:"wm-art__subtitle"},Cn={key:1,class:"wm-art__body"},Nn={key:0,class:"wm-art__text"},Sn={class:"wm-art__fieldLabel"};function Vn(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",vn,[r.data.image_url?(e.openBlock(),e.createElementBlock("figure",yn,[e.createElementVNode("img",{src:r.data.image_url,alt:r.data.title||"",loading:"lazy"},null,8,kn)])):e.createCommentVNode("",!0),e.createElementVNode("div",wn,[e.createElementVNode("div",bn,[e.createElementVNode("div",En,e.toDisplayString(r.data.title),1),r.data.subtitle?(e.openBlock(),e.createElementBlock("div",Bn,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)]),s.hasBody?(e.openBlock(),e.createElementBlock("div",Cn,[r.data.body?(e.openBlock(),e.createElementBlock("div",Nn,e.toDisplayString(r.data.body),1)):e.createCommentVNode("",!0),s.fields.length?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(s.fields,(a,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",Sn,e.toDisplayString(a.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":a.multiline}])},e.toDisplayString(a.value),3)]))),128)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])}const _e=N(gn,[["render",Vn],["__scopeId","data-v-d7369333"]]);function An(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"}),i=t.toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit"});return`${r} à ${i}`}const Tn={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 An((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}}},xn={class:"wm-art wm-art--ticket"},Mn={class:"wm-art__head wm-tk__head"},On={class:"wm-art__title wm-tk__title"},In={class:"wm-tk__sub"},Dn={class:"wm-tk__ref"},Ln={key:0,class:"wm-tk__text"},Rn={key:0,class:"wm-art__body"},$n={class:"wm-art__fieldLabel"},Fn=["data-level"],Un={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"},jn={key:1,class:"wm-art__footer wm-tk__footer"};function Pn(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",xn,[e.createElementVNode("div",Mn,[e.createElementVNode("div",On,e.toDisplayString(r.data.title),1),e.createElementVNode("div",In,[e.createElementVNode("div",Dn,[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",Ln,e.toDisplayString(r.data.body),1)):e.createCommentVNode("",!0)]),s.fields.length?(e.openBlock(),e.createElementBlock("div",Rn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.fields,(a,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",$n,e.toDisplayString(a.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":a.multiline}])},[s.isPriority(a.label)?(e.openBlock(),e.createElementBlock("svg",{key:0,class:"wm-tk__prio","data-level":s.priorityLevel(a.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,Fn)):s.isDate(a.label)?(e.openBlock(),e.createElementBlock("svg",Un,[...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(a.value),1)],2)]))),128))])):e.createCommentVNode("",!0),r.data.created_at?(e.openBlock(),e.createElementBlock("div",jn,[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(s.formattedDate),1)])):e.createCommentVNode("",!0)])}const ge=N(Tn,[["render",Pn],["__scopeId","data-v-8b274eb7"]]),zn={form_response:fe,info_card:_e,ticket:ge},Hn={name:"WmArtifactRenderer",props:{artifact:{type:Object,required:!0}},computed:{component(){var t;const n=(t=this.artifact)==null?void 0:t.kind;return n&&zn[n]||null}}};function qn(n,t,r,i,o,s){return s.component?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(s.component),{key:0,data:r.artifact.data},null,8,["data"])):e.createCommentVNode("",!0)}const ve=N(Hn,[["render",qn]]),Kn={name:"WmAttachmentPreview",inject:{signAttachmentFn:{default:null}},props:{attachment:{type:Object,required:!0}},data(){return{url:null,loading:!1}},computed:{kind(){var r,i;const n=(r=this.attachment)==null?void 0:r.type;if(n)return n;const t=(((i=this.attachment)==null?void 0:i.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()}}},Wn=["href"],Gn=["src","alt"],Yn=["src"],Jn=["src"],Xn=["href","download"],Zn={class:"wm-att__main"},Qn={class:"wm-att__name"},er={key:0,class:"wm-att__meta"},tr={key:0,class:"wm-att__spin","aria-hidden":"true"};function nr(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-att",["wm-att--"+(s.kind||"file")]])},[s.kind==="image"&&o.url?(e.openBlock(),e.createElementBlock("a",{key:0,href:o.url,target:"_blank",rel:"noopener",class:"wm-att__imgWrap"},[e.createElementVNode("img",{src:o.url,alt:s.displayName,loading:"lazy"},null,8,Gn)],8,Wn)):s.kind==="audio"&&o.url?(e.openBlock(),e.createElementBlock("audio",{key:1,src:o.url,controls:"",preload:"metadata"},null,8,Yn)):s.kind==="video"&&o.url?(e.openBlock(),e.createElementBlock("video",{key:2,src:o.url,controls:"",preload:"metadata"},null,8,Jn)):(e.openBlock(),e.createElementBlock("a",{key:3,class:"wm-att__file",href:o.url||"#",download:s.displayName,target:"_blank",rel:"noopener",onClick:t[0]||(t[0]=(...a)=>s.onFileClick&&s.onFileClick(...a))},[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",Zn,[e.createElementVNode("span",Qn,e.toDisplayString(s.displayName),1),s.sizeLabel?(e.openBlock(),e.createElementBlock("span",er,e.toDisplayString(s.sizeLabel),1)):e.createCommentVNode("",!0)]),o.loading?(e.openBlock(),e.createElementBlock("span",tr)):e.createCommentVNode("",!0)],8,Xn))],2)}const ye=N(Kn,[["render",nr],["__scopeId","data-v-1cd1267b"]]);function rr(n){return String(n).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function sr(n){return/^(https?:\/\/|mailto:|tel:)/i.test(String(n).trim())}const re="";function H(n){let t=n;const r=[];return t=t.replace(/`([^`\n]+)`/g,(i,o)=>{const s=r.length;return r.push(o),`${re}CODE${s}${re}`}),t=t.replace(/\[([^\]\n]+)\]\(([^)\s]+)\)/g,(i,o,s)=>sr(s)?`<a href="${s}" target="_blank" rel="noopener noreferrer">${o}</a>`:o),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,(i,o)=>`<code class="wm-md-code">${r[+o]}</code>`),t}function ke(n){if(!n)return"";const t=rr(n).split(`
49
- `),r=[];let i=0;for(;i<t.length;){const s=t[i];if(/^\s*```([\w-]*)\s*$/.exec(s)){i++;const y=[];for(;i<t.length&&!/^\s*```\s*$/.test(t[i]);)y.push(t[i]),i++;i<t.length&&i++,r.push({type:"block",html:`<pre class="wm-md-pre"><code>${y.join(`
50
- `)}</code></pre>`});continue}if(/^\s*[-*]\s+/.test(s)){const y=[];for(;i<t.length;){const w=/^\s*[-*]\s+(.*)$/.exec(t[i]);if(!w)break;y.push(w[1]),i++}const g=y.map(w=>`<li>${H(w)}</li>`).join("");r.push({type:"block",html:`<ul class="wm-md-ul">${g}</ul>`});continue}const l=/^\s*(\d+)\.\s+(.*)$/.exec(s);if(l){const y=parseInt(l[1],10),g=[l[2]];for(i++;i<t.length;){const k=/^\s*\d+\.\s+(.*)$/.exec(t[i]);if(!k)break;g.push(k[1]),i++}const w=g.map(k=>`<li>${H(k)}</li>`).join(""),S=y!==1?` start="${y}"`:"";r.push({type:"block",html:`<ol class="wm-md-ol"${S}>${w}</ol>`});continue}const f=/^(#{1,6})\s+(.*)$/.exec(s);if(f){const y=f[1].length;r.push({type:"block",html:`<h${y} class="wm-md-h wm-md-h${y}">${H(f[2])}</h${y}>`}),i++;continue}r.push({type:"text",html:H(s)}),i++}let o="";for(let s=0;s<r.length;s++){const a=r[s];o+=a.html;const l=r[s+1];l&&a.type!=="block"&&l.type!=="block"&&(o+=`
51
- `)}return o}const or={name:"WmBubble",props:{role:{type:String,default:"ai"},text:{type:String,default:""}},computed:{rendered(){return ke(this.text)}}},ar=["innerHTML"];function ir(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-bubble","wm-bubble--"+r.role])},[e.renderSlot(n.$slots,"default",{},()=>[e.createElementVNode("span",{innerHTML:s.rendered},null,8,ar)],!0)],2)}const we=N(or,[["render",ir],["__scopeId","data-v-5c9e9f2b"]]),lr={name:"WmTyping"},cr={class:"wm-typing"};function dr(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",cr,[...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(lr,[["render",dr],["__scopeId","data-v-df2447fd"]]);function j(n){return n?n.client_msg_id||n.id:""}const ur={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,hr=200,pr={name:"WmMessageList",components:{AIAvatar:U,HumanAvatar:G,Bubble:we,Typing:be,ActionResult:pe,AttachmentPreview:ye,ArtifactRenderer:ve},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,i,o,s;const n=[];for(const a of this.messages){const l=this.roleOf(a);if(l==="system"){if(((r=a==null?void 0:a.payload)==null?void 0:r.event)==="action_admin_pending"){const g=n[n.length-1];g&&g.role==="ai"?g.messages.push(a):n.push({key:`g-${j(a)}`,role:"ai",agentName:"",agentAvatarUrl:null,messages:[a],items:[]});continue}n.push({key:`sys-${j(a)}`,role:l,messages:[a],items:[],systemLabel:this.systemLabel(a)});continue}const f=n[n.length-1];f&&f.role===l&&(l==="ai"||f.agentName===(((i=a==null?void 0:a.author)==null?void 0:i.name)||""))?f.messages.push(a):n.push({key:`g-${j(a)}`,role:l,agentName:((o=a==null?void 0:a.author)==null?void 0:o.name)||"",agentAvatarUrl:((s=a==null?void 0:a.author)==null?void 0:s.avatar_url)||null,messages:[a],items:[]})}for(const a of n){if(a.role==="system")continue;const l=[];for(const f of a.messages)for(const y of this.itemsOf(f))l.push(y);a.items=l}const t=[];for(const a of n){if(a.role!=="system"&&!a.items.length)continue;const l=t[t.length-1];if(l&&l.role!=="system"&&l.role===a.role&&(a.role==="ai"||l.agentName===a.agentName)){l.messages.push(...a.messages),l.items.push(...a.items);continue}t.push(a)}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:j,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<=hr&&(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 i=null;if(!t&&!r){const s=this.pickAnchor(n);if(s!=null&&s.el){const a=n.getBoundingClientRect().top;i={el:s.el,relY:s.el.getBoundingClientRect().top-a}}}const o={forceBottom:t,wasPinned:r,anchor:i};this._scrollSnap=o,this.$nextTick(()=>{if(this._scrollSnap=null,o.forceBottom||o.wasPinned){n.scrollTop=n.scrollHeight;return}if(!o.anchor)return;const s=()=>{var y;const a=o.anchor;if(!((y=a.el)!=null&&y.isConnected))return;const f=a.el.getBoundingClientRect().top-n.getBoundingClientRect().top-a.relY;Math.abs(f)>.5&&(n.scrollTop+=f)};s(),requestAnimationFrame(()=>{s(),requestAnimationFrame(s)})})},pickAnchor(n){const t=n.scrollTop;let r=null;for(const i of n.children)if(i.classList.contains("wm-list__group")&&(r||(r=i),i.offsetTop+i.offsetHeight>=t))return{el:i,offsetTop:i.offsetTop};return r?{el:r,offsetTop:r.offsetTop}:null},roleOf(n){var r,i;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=(i=n==null?void 0:n.author)==null?void 0:i.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 R,I,F;const r=n.items,i=(R=r[t])==null?void 0:R.kind,o=(I=r[t-1])==null?void 0:I.kind,s=(F=r[t+1])==null?void 0:F.kind,a=n.role==="user",l=14,f=4,y=o==null?void 0:o.bottom,g=s==null?void 0:s.top,w=this.widthByKey[this.rowKeyOf(n,t)],S=this.widthByKey[this.rowKeyOf(n,t-1)],k=this.widthByKey[this.rowKeyOf(n,t+1)],A=.5,b=(L,D,$)=>L!=null&&w!=null?L+A>=w:D===$||D==="card"&&$==="bubble";let x=l,M=l,V=l,O=l;return a?(y&&(M=f),(g||!s)&&(V=f),y&&b(S,y,i==null?void 0:i.top)&&(x=f),g&&b(k,g,i==null?void 0:i.bottom)&&(O=f)):(y&&(x=f),(g||!s)&&(O=f),y&&b(S,y,i==null?void 0:i.top)&&(M=f),g&&b(k,g,i==null?void 0:i.bottom)&&(V=f)),{tl:x,tr:M,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 i;const r=(i=n==null?void 0:n.items)==null?void 0:i[t];return r?`${j(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 s of n.querySelectorAll(".wm-list__row[data-row-key]")){const a=s.dataset.rowKey;if(!a)continue;const l=s.querySelector(".wm-bubble, .wm-result, .wm-art, .wm-list__body");if(!l)continue;const f=l.getBoundingClientRect().width;f>0&&(t[a]=f)}const r=this.widthByKey,i=Object.keys(r),o=Object.keys(t);if(i.length===o.length){let s=!0;for(const a of o)if(Math.abs((r[a]??0)-t[a])>.5){s=!1;break}if(s)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,i,o,s,a,l;const t=n==null?void 0:n.payload;return t?t.state==="success"?((r=t.success)==null?void 0:r.summary)||((o=(i=t.success)==null?void 0:i.metadata)==null?void 0:o.description)||"":t.state==="rejected"?((s=t.rejected)==null?void 0:s.reason)||"Action annulée par l'utilisateur.":t.state==="failure"&&(((a=t.failure)==null?void 0:a.summary)||((l=t.failure)==null?void 0:l.error))||"":""},actionArtifact(n){var r,i;const t=(i=(r=n==null?void 0:n.payload)==null?void 0:r.success)==null?void 0:i.artifact;return!t||typeof t!="object"||typeof t.kind!="string"?null:t},systemLabel(n){var o,s,a;const t=(o=n==null?void 0:n.payload)==null?void 0:o.event,r=ur[t]||(n==null?void 0:n.text_md)||"Mise à jour de la conversation",i=((s=n==null?void 0:n.metadata)==null?void 0:s.agent_name)||((a=n==null?void 0:n.author)==null?void 0:a.name)||"";return r.replace("{name}",i||"Un agent")},scrollToBottom(){const n=this.$refs.scrollEl;n&&(n.scrollTop=n.scrollHeight)}}},fr={key:0,class:"wm-list__loadMore",role:"status","aria-live":"polite"},_r={key:1,class:"wm-list__historyEnd"},gr={key:2,class:"wm-list__sep"},vr={class:"wm-list__sep-label"},yr={key:0,class:"wm-list__sep wm-list__sep--unread"},kr={key:0,class:"wm-list__sysep"},wr={class:"wm-list__sysep-label"},br=["data-row-key"],Er={key:0,class:"wm-list__avatarSlot"},Br={key:5,class:"wm-list__body"},Cr={key:0},Nr={key:1,"aria-hidden":"true"},Sr={key:2},Vr={key:3,class:"wm-list__row wm-list__row--ai fade-up"},Ar={class:"wm-list__avatarSlot"};function Tr(n,t,r,i,o,s){const a=e.resolveComponent("AIAvatar"),l=e.resolveComponent("HumanAvatar"),f=e.resolveComponent("ActionResult"),y=e.resolveComponent("ArtifactRenderer"),g=e.resolveComponent("Bubble"),w=e.resolveComponent("AttachmentPreview"),S=e.resolveComponent("Typing");return e.openBlock(),e.createElementBlock("div",{ref:"scrollEl",class:e.normalizeClass(["wm-list",{"wm-list--silent":o.silentFades}]),onScrollPassive:t[0]||(t[0]=(...k)=>s.onScroll&&s.onScroll(...k))},[r.loadingMore?(e.openBlock(),e.createElementBlock("div",fr,[...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)])])):s.historyExhausted?(e.openBlock(),e.createElementBlock("div",_r,"Début de la conversation")):e.createCommentVNode("",!0),r.dateLabel?(e.openBlock(),e.createElementBlock("div",gr,[t[2]||(t[2]=e.createElementVNode("div",{class:"wm-list__line"},null,-1)),e.createElementVNode("span",vr,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(s.groups,(k,A)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:k.key},[k.key===s.unreadGroupKey?(e.openBlock(),e.createElementBlock("div",yr,[...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",kr,[t[5]||(t[5]=e.createElementVNode("div",{class:"wm-list__line wm-list__line--strong"},null,-1)),e.createElementVNode("span",wr,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,(b,x)=>(e.openBlock(),e.createElementBlock("div",{key:`${s.messageKey(b.message)}-${b.partKey}`,"data-row-key":`${s.messageKey(b.message)}-${b.partKey}`,class:e.normalizeClass(["wm-list__row fade-up",["wm-list__row--"+k.role,{"is-pending":b.message._pending,"is-failed":b.message._failed}]]),style:e.normalizeStyle(s.cornersStyle(k,x))},[k.role!=="user"?(e.openBlock(),e.createElementBlock("div",Er,[x===k.items.length-1?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[k.role==="ai"?(e.openBlock(),e.createBlock(a,{key:0,size:26,tail:!0})):(e.openBlock(),e.createBlock(l,{key:1,name:k.agentName,"avatar-url":k.agentAvatarUrl,size:26},null,8,["name","avatar-url"]))],64)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),b.renderAs==="action"?(e.openBlock(),e.createBlock(f,{key:1,state:b.message.payload.state,label:s.actionLabel(b.message),detail:s.actionDetail(b.message)},null,8,["state","label","detail"])):b.renderAs==="admin-pending"?(e.openBlock(),e.createBlock(f,{key:2,state:"awaiting",label:"Demande d'approbation envoyée",detail:b.message.text_md||""},null,8,["detail"])):b.renderAs==="artifact-of-action"?(e.openBlock(),e.createBlock(y,{key:3,artifact:s.actionArtifact(b.message)},null,8,["artifact"])):b.renderAs==="artifact"?(e.openBlock(),e.createBlock(y,{key:4,artifact:s.artifactOf(b.message)},null,8,["artifact"])):(e.openBlock(),e.createElementBlock("div",Br,[b.message.text_md?(e.openBlock(),e.createBlock(g,{key:0,role:k.role,text:b.message.text_md},null,8,["role","text"])):e.createCommentVNode("",!0),s.attachmentsOf(b.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(s.attachmentsOf(b.message),(M,V)=>(e.openBlock(),e.createBlock(w,{key:`${s.messageKey(b.message)}-att-${V}`,attachment:M},null,8,["attachment"]))),128))],2)):e.createCommentVNode("",!0)]))],14,br))),128)),(k.role!=="user"||s.lastTimeOf(k))&&!s.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",Cr,e.toDisplayString(s.roleLabel(k)),1)):e.createCommentVNode("",!0),k.role!=="user"&&s.lastTimeOf(k)?(e.openBlock(),e.createElementBlock("span",Nr,"·")):e.createCommentVNode("",!0),s.lastTimeOf(k)?(e.openBlock(),e.createElementBlock("span",Sr,e.toDisplayString(s.lastTimeOf(k)),1)):e.createCommentVNode("",!0)],2)):e.createCommentVNode("",!0)],64))],2)):e.createCommentVNode("",!0)],64))),128)),r.streamingActive?(e.openBlock(),e.createElementBlock("div",Vr,[e.createElementVNode("div",Ar,[e.createVNode(a,{size:26,tail:!0})]),e.createVNode(S)])):e.createCommentVNode("",!0)],34)}const Ee=N(pr,[["render",Tr],["__scopeId","data-v-54959b73"]]),P=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",Y=typeof window<"u"&&typeof window.MediaRecorder<"u";function Be(){return Y&&["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(t=>{var r,i;return(i=(r=window.MediaRecorder).isTypeSupported)==null?void 0:i.call(r,t)})||""}function Ce({audio:n}){return{video:!0,audio:!!n,selfBrowserSurface:"include",surfaceSwitching:"include",systemAudio:n?"include":"exclude"}}function xr(n){return n?n.startsWith("image/")?"image":n.startsWith("video/")?"video":"file":"file"}async function Ne(){if(!P)return null;let n;try{n=await navigator.mediaDevices.getDisplayMedia(Ce({audio:!1}))}catch(t){return(t==null?void 0:t.name)!=="NotAllowedError"&&console.error("[media] screenshot picker",t),null}try{return await Mr(n)}catch(t){return console.error("[media] screenshot capture",t),null}finally{n.getTracks().forEach(t=>{t.stop()})}}async function Mr(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,i=t.videoHeight||720,o=document.createElement("canvas");o.width=r,o.height=i,o.getContext("2d").drawImage(t,0,0,r,i);const s=await new Promise((l,f)=>{o.toBlob(y=>y?l(y):f(new Error("toBlob failed")),"image/png")}),a=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);return new File([s],`capture-${a}.png`,{type:"image/png"})}async function Se(n={}){var y;if(!P||!Y)return null;let t;try{t=await navigator.mediaDevices.getDisplayMedia(Ce({audio:!0}))}catch(g){return(g==null?void 0:g.name)!=="NotAllowedError"&&console.error("[media] record picker",g),null}const r=Be();let i;try{i=r?new window.MediaRecorder(t,{mimeType:r}):new window.MediaRecorder(t)}catch(g){return console.error("[media] recorder init",g),t.getTracks().forEach(w=>{w.stop()}),null}const o=[];let s=null,a=!1;i.addEventListener("dataavailable",g=>{g.data&&g.data.size>0&&o.push(g.data)}),i.addEventListener("stop",()=>{var g,w;if(s&&clearInterval(s),t.getTracks().forEach(S=>{S.stop()}),o.length){const S=i.mimeType||r||"video/webm",k=new Blob(o,{type:S}),A=/mp4/.test(S)?"mp4":"webm",b=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),x=new File([k],`ecran-${b}.${A}`,{type:S});(g=n.onfinalize)==null||g.call(n,x)}else(w=n.oncancel)==null||w.call(n)}),t.getVideoTracks().forEach(g=>{g.addEventListener("ended",()=>l(),{once:!0})});function l(){if(!a&&(a=!0,i.state!=="inactive"))try{i.stop()}catch(g){console.error("[media] recorder stop",g)}}try{i.start(1e3)}catch(g){return console.error("[media] recorder start",g),t.getTracks().forEach(w=>{w.stop()}),null}(y=n.onstart)==null||y.call(n);const f=Date.now();return s=setInterval(()=>{var g;(g=n.ontick)==null||g.call(n,Date.now()-f)},500),{stop:l,get state(){return i.state}}}const Or=[{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"}],Ir={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 Or.map(n=>({...n,disabled:n.action==="screenshot"&&!P||n.action==="record"&&(!P||!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 Ne();n&&this.$emit("attach",n)},async startRecording(){if(this.recording||this.disabled)return;this.recordingElapsed=0;const n=await Se({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)}}}},Dr={class:"wm-compose-wrap"},Lr={key:0,class:"wm-rec"},Rr={class:"wm-rec__lbl"},$r={key:1,class:"wm-compose__menu",role:"menu"},Fr=["disabled","onClick"],Ur={class:"wm-compose__menuIcon"},jr={viewBox:"0 0 24 24",width:"14",height:"14","aria-hidden":"true"},Pr=["d"],zr=["placeholder","disabled"],Hr={class:"wm-compose__actions"},qr=["title","aria-label","disabled"],Kr=["disabled"];function Wr(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",Dr,[o.recording?(e.openBlock(),e.createElementBlock("div",Lr,[t[8]||(t[8]=e.createElementVNode("span",{class:"wm-rec__dot","aria-hidden":"true"},null,-1)),e.createElementVNode("span",Rr,"Enregistrement · "+e.toDisplayString(s.recordingElapsedLabel),1),e.createElementVNode("button",{type:"button",class:"wm-rec__stop",onClick:t[0]||(t[0]=(...a)=>s.stopRecording&&s.stopRecording(...a))},"Arrêter")])):e.createCommentVNode("",!0),e.createElementVNode("form",{class:e.normalizeClass(["wm-compose",{"has-attach":o.attachOpen}]),onSubmit:t[7]||(t[7]=e.withModifiers((...a)=>s.onSubmit&&s.onSubmit(...a),["prevent"]))},[e.createElementVNode("input",{ref:"fileEl",type:"file",hidden:"",multiple:"",onChange:t[1]||(t[1]=(...a)=>s.onFile&&s.onFile(...a))},null,544),o.attachOpen?(e.openBlock(),e.createElementBlock("div",{key:0,class:"wm-compose__overlay",onClick:t[2]||(t[2]=a=>o.attachOpen=!1)})):e.createCommentVNode("",!0),o.attachOpen?(e.openBlock(),e.createElementBlock("div",$r,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.attachItems,a=>(e.openBlock(),e.createElementBlock("button",{key:a.action,type:"button",class:"wm-compose__menuItem",disabled:a.disabled,onClick:l=>s.onAttachAction(a.action)},[e.createElementVNode("span",Ur,[(e.openBlock(),e.createElementBlock("svg",jr,[e.createElementVNode("path",{d:a.path,stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",fill:"none"},null,8,Pr)]))]),e.createElementVNode("span",null,e.toDisplayString(a.label),1)],8,Fr))),128))])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("textarea",{ref:"inputEl","onUpdate:modelValue":t[3]||(t[3]=a=>o.local=a),class:"wm-compose__input",rows:"3",placeholder:r.placeholder,disabled:r.disabled,onKeydown:t[4]||(t[4]=(...a)=>s.onKeydown&&s.onKeydown(...a)),onInput:t[5]||(t[5]=(...a)=>s.autosize&&s.autosize(...a))},null,40,zr),[[e.vModelText,o.local]]),e.createElementVNode("div",Hr,[e.createElementVNode("button",{type:"button",class:e.normalizeClass(["wm-compose__icon",{"is-open":o.attachOpen}]),title:r.attachLabel,"aria-label":r.attachLabel,disabled:o.recording,onClick:t[6]||(t[6]=a=>o.attachOpen=!o.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,qr),e.createElementVNode("button",{type:"submit",class:e.normalizeClass(["wm-compose__send",{"is-empty":!s.canSend}]),disabled:!s.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,Kr)])],34)])}const Ve=N(Ir,[["render",Wr],["__scopeId","data-v-14fa9ec0"]]),Gr={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("§")}}},Yr=["onClick"];function Jr(n,t,r,i,o,s){return r.items.length?(e.openBlock(),e.createElementBlock("div",{key:s.batchKey,class:"wm-chips"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.items,(a,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",a)},e.toDisplayString(a.label),13,Yr))),128))])):e.createCommentVNode("",!0)}const Ae=N(Gr,[["render",Jr],["__scopeId","data-v-55aa529d"]]),Xr={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(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"}}},Zr={class:"wm-approval"},Qr={class:"wm-approval__head"},es={class:"wm-approval__icon"},ts={class:"wm-approval__main"},ns={class:"wm-approval__title"},rs={key:0,class:"wm-approval__detail"},ss={class:"wm-approval__actions"};function os(n,t,r,i,o,s){const a=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",Zr,[e.createElementVNode("div",Qr,[e.createElementVNode("div",es,[e.createVNode(a,{size:24})]),e.createElementVNode("div",ts,[e.createElementVNode("div",ns,e.toDisplayString(r.action),1),r.detail?(e.openBlock(),e.createElementBlock("div",rs,e.toDisplayString(r.detail),1)):e.createCommentVNode("",!0)])]),e.createElementVNode("div",ss,[s.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",s.rejectId))},e.toDisplayString(s.rejectLabel),1)):e.createCommentVNode("",!0),s.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",s.approveId))},e.toDisplayString(s.approveLabel),1)):e.createCommentVNode("",!0)])])}const Te=N(Xr,[["render",os],["__scopeId","data-v-b1be139c"]]);let se=0;const as=new Set(["text","textarea","number","boolean","select","multiselect","date"]),is={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 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)||!as.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 i=Array.isArray(this.values[n])?this.values[n].slice():[],o=i.indexOf(t);r&&o===-1?i.push(t):!r&&o!==-1&&i.splice(o,1),this.values={...this.values,[n]:i}},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}}}},ls={class:"wm-form"},cs={class:"wm-form__head"},ds={class:"wm-form__icon"},us={class:"wm-form__main"},ms={class:"wm-form__title"},hs={key:0,class:"wm-form__detail"},ps=["for"],fs={key:0,class:"wm-form__req","aria-hidden":"true"},_s=["id","onUpdate:modelValue","placeholder","required","disabled"],gs=["id","onUpdate:modelValue","placeholder","required","disabled"],vs=["id","onUpdate:modelValue","placeholder","required","disabled"],ys=["id","onUpdate:modelValue","required","disabled"],ks={key:4,class:"wm-form__bool"},ws=["id","onUpdate:modelValue","disabled"],bs=["id","onUpdate:modelValue","required","disabled"],Es={value:"",disabled:""},Bs=["value"],Cs={key:6,class:"wm-form__multi"},Ns=["value","checked","disabled","onChange"],Ss={key:0,class:"wm-form__err"},Vs=["disabled"],As={key:0,class:"wm-form__spinner","aria-hidden":"true"},Ts={key:2,class:"wm-form__doneLbl"};function xs(n,t,r,i,o,s){const a=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",ls,[e.createElementVNode("div",cs,[e.createElementVNode("div",ds,[e.createVNode(a,{size:24})]),e.createElementVNode("div",us,[e.createElementVNode("div",ms,e.toDisplayString(r.form.title||"Formulaire"),1),r.form.description?(e.openBlock(),e.createElementBlock("div",hs,e.toDisplayString(r.form.description),1)):e.createCommentVNode("",!0)])]),e.createElementVNode("form",{class:"wm-form__body",onSubmit:t[0]||(t[0]=e.withModifiers((...l)=>s.onSubmit&&s.onSubmit(...l),["prevent"]))},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.normalizedFields,l=>(e.openBlock(),e.createElementBlock("div",{key:l.key,class:"wm-form__field"},[e.createElementVNode("label",{for:`wm-f-${o._uid}-${l.key}`,class:"wm-form__label"},[e.createTextVNode(e.toDisplayString(l.label),1),l.required?(e.openBlock(),e.createElementBlock("span",fs,"*")):e.createCommentVNode("",!0)],8,ps),l.type==="text"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:0,id:`wm-f-${o._uid}-${l.key}`,"onUpdate:modelValue":f=>o.values[l.key]=f,type:"text",class:"wm-form__input",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||o.busy},null,8,_s)),[[e.vModelText,o.values[l.key]]]):l.type==="textarea"?e.withDirectives((e.openBlock(),e.createElementBlock("textarea",{key:1,id:`wm-f-${o._uid}-${l.key}`,"onUpdate:modelValue":f=>o.values[l.key]=f,class:"wm-form__textarea",rows:"3",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||o.busy},null,8,gs)),[[e.vModelText,o.values[l.key]]]):l.type==="number"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,id:`wm-f-${o._uid}-${l.key}`,"onUpdate:modelValue":f=>o.values[l.key]=f,type:"number",class:"wm-form__input",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||o.busy},null,8,vs)),[[e.vModelText,o.values[l.key],void 0,{number:!0}]]):l.type==="date"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:3,id:`wm-f-${o._uid}-${l.key}`,"onUpdate:modelValue":f=>o.values[l.key]=f,type:"date",class:"wm-form__input",required:l.required,disabled:r.readOnly||o.busy},null,8,ys)),[[e.vModelText,o.values[l.key]]]):l.type==="boolean"?(e.openBlock(),e.createElementBlock("label",ks,[e.withDirectives(e.createElementVNode("input",{id:`wm-f-${o._uid}-${l.key}`,"onUpdate:modelValue":f=>o.values[l.key]=f,type:"checkbox",disabled:r.readOnly||o.busy},null,8,ws),[[e.vModelCheckbox,o.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-${o._uid}-${l.key}`,"onUpdate:modelValue":f=>o.values[l.key]=f,class:"wm-form__select",required:l.required,disabled:r.readOnly||o.busy},[e.createElementVNode("option",Es,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,Bs))),128))],8,bs)),[[e.vModelSelect,o.values[l.key]]]):l.type==="multiselect"?(e.openBlock(),e.createElementBlock("div",Cs,[(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(o.values[l.key])&&o.values[l.key].includes(f.value),disabled:r.readOnly||o.busy,onChange:y=>s.toggleMulti(l.key,f.value,y.target.checked)},null,40,Ns),e.createElementVNode("span",null,e.toDisplayString(f.label),1)]))),128))])):e.createCommentVNode("",!0)]))),128)),o.error?(e.openBlock(),e.createElementBlock("div",Ss,e.toDisplayString(o.error),1)):e.createCommentVNode("",!0),r.readOnly?(e.openBlock(),e.createElementBlock("div",Ts,"Réponse envoyée")):(e.openBlock(),e.createElementBlock("button",{key:1,type:"submit",class:"wm-form__submit",disabled:o.busy},[o.busy?(e.openBlock(),e.createElementBlock("span",As)):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(o.busy?"Envoi…":r.form.submit_label||"Envoyer"),1)],8,Vs))],32)])}const xe=N(is,[["render",xs],["__scopeId","data-v-64b40f76"]]),Ms={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})}}},Os={class:"wm-fb"},Is={class:"wm-fb__row"},Ds=["onClick"],Ls={class:"wm-fb__emoji"},Rs={class:"wm-fb__label"},$s=["disabled"],Fs={key:1,class:"wm-fb__done"};function Us(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",Os,[r.done?(e.openBlock(),e.createElementBlock("div",Fs,[...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",Is,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.options,a=>(e.openBlock(),e.createElementBlock("button",{key:a.v,type:"button",class:e.normalizeClass(["wm-fb__opt",{"is-selected":o.sel===a.v}]),onClick:l=>o.sel=a.v},[e.createElementVNode("span",Ls,e.toDisplayString(a.e),1),e.createElementVNode("span",Rs,e.toDisplayString(a.l),1)],10,Ds))),128))]),e.createElementVNode("button",{type:"button",class:"wm-fb__send",disabled:!o.sel||r.busy,onClick:t[0]||(t[0]=(...a)=>s.onSend&&s.onSend(...a))},e.toDisplayString(r.busy?"Envoi…":"Envoyer mon avis"),9,$s)],64))])}const Me=N(Ms,[["render",Us],["__scopeId","data-v-6f45ff3b"]]);function js(n){const t=new Date(n);return t.setHours(0,0,0,0),t}const Ps={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 o;const r=t.last_message_at||t.updated_at||t.created_at||null,i=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||((o=t.metadata)==null?void 0:o.last_preview)||"",unread:!!t._unread,stamp:i}}).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=js(new Date).getTime(),r=t-6*864e5,i=[],o=[],s=[];for(const a of this.filtered){if(!a.stamp){s.push(a);continue}a.stamp>=t?i.push(a):a.stamp>=r?o.push(a):s.push(a)}return[{key:"today",label:"Aujourd'hui",items:i},{key:"week",label:"Cette semaine",items:o},{key:"older",label:"Plus ancien",items:s}]},hasAny(){return this.filtered.length>0}}},zs={class:"wm-hd"},Hs={class:"wm-hd__panel",role:"dialog","aria-label":"Vos discussions"},qs={class:"wm-hd__head"},Ks={class:"wm-hd__top"},Ws={class:"wm-hd__search"},Gs={class:"wm-hd__list"},Ys={key:0,class:"wm-hd__group"},Js={class:"wm-hd__groupLabel"},Xs={class:"wm-hd__rows"},Zs=["onClick"],Qs={class:"wm-hd__rowIcon"},eo={key:0,class:"wm-hd__rowDot","aria-label":"Message non lu"},to={class:"wm-hd__rowBody"},no={class:"wm-hd__rowTop"},ro={class:"wm-hd__rowTitle"},so={class:"wm-hd__rowPreview"},oo={key:0,class:"wm-hd__empty"};function ao(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",zs,[e.createElementVNode("div",{class:"wm-hd__scrim",onClick:t[0]||(t[0]=a=>n.$emit("close"))}),e.createElementVNode("aside",Hs,[e.createElementVNode("div",qs,[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]=a=>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",Ks,[e.createElementVNode("button",{type:"button",class:"wm-hd__new",onClick:t[2]||(t[2]=a=>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",Ws,[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]=a=>o.query=a),type:"text",placeholder:"Rechercher dans vos messages","aria-label":"Rechercher dans vos messages"},null,512),[[e.vModelText,o.query]])])]),e.createElementVNode("div",Gs,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.groups,a=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:a.key},[a.items.length?(e.openBlock(),e.createElementBlock("div",Ys,[e.createElementVNode("div",Js,e.toDisplayString(a.label),1),e.createElementVNode("div",Xs,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.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",Qs,[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",eo)):e.createCommentVNode("",!0)]),e.createElementVNode("div",to,[e.createElementVNode("div",no,[e.createElementVNode("span",ro,e.toDisplayString(l.title),1)]),e.createElementVNode("div",so,e.toDisplayString(l.preview||"Aucun message"),1)])],10,Zs))),128))])])):e.createCommentVNode("",!0)],64))),128)),s.hasAny?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",oo," Aucun fil pour le moment. "))])])])}const Oe=N(Ps,[["render",ao],["__scopeId","data-v-1259e822"]]),io={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)}}},lo={class:"wm-mm"},co={class:"wm-mm__pop",role:"menu"},uo={class:"wm-mm__section"},mo={class:"wm-mm__section"},ho={class:"wm-mm__section"};function po(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",lo,[e.createElementVNode("div",{class:"wm-mm__scrim",onClick:t[0]||(t[0]=a=>n.$emit("close"))}),e.createElementVNode("div",co,[e.createElementVNode("div",uo,[e.createElementVNode("button",{type:"button",class:"wm-mm__item",onClick:t[1]||(t[1]=a=>s.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]=a=>s.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]=a=>s.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",mo,[e.createElementVNode("button",{type:"button",class:"wm-mm__item",onClick:t[4]||(t[4]=(...a)=>s.toggleSound&&s.toggleSound(...a))},[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":o.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]=(...a)=>s.toggleBrowserNotif&&s.toggleBrowserNotif(...a))},[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":o.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",ho,[r.statusUrl?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-mm__item",onClick:t[6]||(t[6]=a=>s.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]=a=>s.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 Ie=N(io,[["render",po],["__scopeId","data-v-e300b2de"]]),fo={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())}}},_o={class:"wm-dialog"},go={class:"wm-dialog__card",role:"dialog","aria-modal":"true"},vo={class:"wm-dialog__head"},yo={class:"wm-dialog__title"},ko={class:"wm-dialog__body"},wo=["placeholder"],bo={class:"wm-dialog__actions"},Eo=["disabled"];function Bo(n,t,r,i,o,s){return e.openBlock(),e.createElementBlock("div",_o,[e.createElementVNode("div",{class:"wm-dialog__scrim",onClick:t[0]||(t[0]=a=>n.$emit("close"))}),e.createElementVNode("div",go,[e.createElementVNode("div",vo,[e.createElementVNode("div",yo,e.toDisplayString(r.title),1),e.createElementVNode("button",{type:"button",class:"wm-dialog__close","aria-label":"Fermer",onClick:t[1]||(t[1]=a=>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",ko,[e.withDirectives(e.createElementVNode("input",{ref:"input","onUpdate:modelValue":t[2]||(t[2]=a=>o.value=a),type:"text",class:"wm-dialog__input",placeholder:r.placeholder,maxlength:120,onKeydown:[t[3]||(t[3]=e.withKeys(e.withModifiers((...a)=>s.onSubmit&&s.onSubmit(...a),["prevent"]),["enter"])),t[4]||(t[4]=e.withKeys(e.withModifiers(a=>n.$emit("close"),["prevent"]),["esc"]))]},null,40,wo),[[e.vModelText,o.value]])]),e.createElementVNode("div",bo,[e.createElementVNode("button",{type:"button",class:"wm-dialog__btn",onClick:t[5]||(t[5]=a=>n.$emit("close"))},"Annuler"),e.createElementVNode("button",{type:"button",class:"wm-dialog__btn wm-dialog__btn--primary",disabled:!s.canSubmit,onClick:t[6]||(t[6]=(...a)=>s.onSubmit&&s.onSubmit(...a))},"Enregistrer",8,Eo)])])])}const Co=N(fo,[["render",Bo],["__scopeId","data-v-4f4b37c9"]]),oe="ww-messenger-tokens";function q(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 No(n,t){if(!n||!t)return"";const r=Array.isArray(n.fields)?n.fields:[],i=[];for(const o of r){if(!(o!=null&&o.key)||!(o!=null&&o.label))continue;const s=t[o.key];if(s==null||s==="")continue;let a;if(Array.isArray(s)){if(a=s.map(l=>W(o,String(l))).join(", "),!a)continue}else typeof s=="boolean"?a=s?"Oui":"Non":a=W(o,String(s));i.push(`${o.label} :
52
- ${a}`)}return i.join(`
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} :
48
+ ${i}`)}return a.join(`
53
49
 
54
- `)}function W(n,t){if(!Array.isArray(n==null?void 0:n.options))return t;const r=n.options.find(i=>(i==null?void 0:i.value)===t);return(r==null?void 0:r.label)||t}function So(n,t){const r=[],i=Array.isArray(n==null?void 0:n.fields)?n.fields:[];for(const o of i){if(!(o!=null&&o.key)||!(o!=null&&o.label))continue;const s=t==null?void 0:t[o.key];if(s==null||s==="")continue;let a;if(Array.isArray(s)){if(a=s.map(f=>W(o,String(f))).join(", "),!a)continue}else typeof s=="boolean"?a=s?"Oui":"Non":a=W(o,String(s));const l=o.type==="textarea"||typeof a=="string"&&(a.length>60||a.includes(`
55
- `));r.push({label:o.label,value:a,multiline:l})}return{kind:"form_response",data:{title:(n==null?void 0:n.title)||"Formulaire",fields:r}}}const Vo=450,Ao=50,To=900,xo=12e3,Mo=300,Oo={name:"Messenger",components:{Launcher:de,Header:me,Onboarding:he,MessageList:Ee,Composer:Ve,SuggestionChips:Ae,ApprovalCard:Te,FormCard:xe,Feedback:Me,HistoryDrawer:Oe,MoreMenu:Ie,RenameDialog:Co},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:ce},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,revealedAt:{},nextRevealAt:0,revealTimers:[],convOpenedAt:0,historyOpen:!1,moreOpen:!1,renameDialogOpen:!1,draftConv:null,notifPermission:typeof Notification<"u"?Notification.permission:"denied",_notifUnsub:null,_audioCtx:null,activeConvId:null,showOnboarding:!1,soundEnabled:!0,browserNotifEnabled:typeof Notification<"u"&&Notification.permission==="granted",dismissedPeeks:{},readState:{},readBootTs:"",unreadAnchorTs:"",unreadBoundaryTs:"",floatHeight:0,floatRO:null,approvalSettled:!0,approvalSettleTimer:null,approvalLatchId: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 i;const n=this.readState,t=this.readBootTs,r=((i=this.s)==null?void 0:i.messagesByConv)||{};return this.allConversations.map(o=>{var S;const s=r[o.id]||[],a=this.convLastActivity(o,s),l=n[o.id]||t||"",f=this.lastMessageAuthorType(s),y=!!a&&f!=="user"&&(!l||a>l);let g=0,w=null;for(let k=s.length-1;k>=0;k--){const A=s[k];if(A){if(((S=A.author)==null?void 0:S.type)==="user"||l&&A.created_at&&A.created_at<=l)break;!w&&A.author&&(w=A.author),g++}}return y&&g===0&&(g=1),{...o,_preview:this.convPreview(o,s),_unread:y,_unreadCount:g,_lastAuthor:w}})},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:this.convLastActivity(r,n[r.id]||[])})).sort((r,i)=>r._ts<i._ts?1:r._ts>i._ts?-1:0).slice(0,5)},latestUnreads(){var r;const n=((r=this.s)==null?void 0:r.messagesByConv)||{},t=[];for(const i of this.drawerConversations){if(!i._unread)continue;const o=this.convLastActivity(i,n[i.id]||[]),s=i._lastAuthor,a=!s||s.type==="agent_ai",l=(s==null?void 0:s.name)||(a?this.agentName:"")||"",f=(s==null?void 0:s.avatar_url)||(a?this.agentAvatarUrl:null);t.push({convId:i.id,preview:i._preview||"Vous avez un nouveau message",ts:o,count:i._unreadCount||1,senderName:l,senderAvatarUrl:f})}return t.sort((i,o)=>i.ts<o.ts?1:i.ts>o.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(i=>i.icon==="status"&&i.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(i=>(i.icon==="chat"||i.icon==="help")&&i.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,i;if(!this.currentConv)return null;const n=((t=this.s.messagesByConv)==null?void 0:t[this.currentConv.id])||[];for(let o=n.length-1;o>=0;o--)if(((i=(r=n[o])==null?void 0:r.author)==null?void 0:i.type)==="agent_human")return n[o].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 i,o,s,a,l;return(r==null?void 0:r.type)==="action"&&((i=r==null?void 0:r.payload)==null?void 0:i.state)==="pending"||q(r)&&!(t[r.id]>0)?!1:(r==null?void 0:r.type)==="action"||(r==null?void 0:r.type)==="system"||((o=r==null?void 0:r.payload)==null?void 0:o.type)==="system"||Array.isArray((s=r==null?void 0:r.payload)==null?void 0:s.attachments)&&r.payload.attachments.length||(a=r==null?void 0:r.metadata)!=null&&a.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,i,o;const n=this.currentConv;return n?Object.keys(((r=this.s)==null?void 0:r.streamingByMsgId)||{}).length>0?!0:this.actionInFlight?!1:(((o=(i=this.s)==null?void 0:i.messagesByConv)==null?void 0:o[n.id])||[]).some(s=>q(s)&&!(this.revealedAt[s.id]>0)):!1},currentConvMessages(){var t,r,i;const n=(t=this.currentConv)==null?void 0:t.id;return n?((i=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:i[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 i,o,s,a,l,f;const n=(s=(o=(i=this.pendingApproval)==null?void 0:i.payload)==null?void 0:o.pending)==null?void 0:s.user_explanation;if(typeof n=="string"&&n.trim())return n.trim();const t=(f=(l=(a=this.pendingApproval)==null?void 0:a.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(([y,g])=>`${y}: ${g}`).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,i,o;const n=this.currentConv;let t=new Date;if(n){const a=((o=(((i=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:i[n.id])||[]).find(l=>l==null?void 0:l.created_at))==null?void 0:o.created_at)||n.created_at;if(a){const l=new Date(a);Number.isNaN(l.getTime())||(t=l)}}return`Aujourd'hui · ${ee(t)}`},paginationState(){var r,i,o;const n=(r=this.currentConv)==null?void 0:r.id,t=n?(o=(i=this.s)==null?void 0:i.paginationByConv)==null?void 0:o[n]:null;return{loading:!!(t!=null&&t.loading),hasMore:!!(t!=null&&t.nextCursor)}}},watch:{latestUnreads:{handler(n){const t=new Set(n.map(a=>a.convId)),r=this.dismissedPeeks||{},i=Object.keys(r);if(!i.length)return;const o={};let s=!1;for(const a of i)t.has(a)?o[a]=r[a]:s=!0;s&&(this.dismissedPeeks=o)},deep:!0},"currentConv.id":{handler(n){this.cancelReveals(),this.revealedAt={},this.nextRevealAt=0,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 i=(r=this.currentConv)==null?void 0:r.id;this.unreadAnchorTs=i&&this.readState[i]||"",this.unreadBoundaryTs=i?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){var i;if(!Array.isArray(n)||!n.length)return;const t=Date.now(),r={...this.revealedAt};for(const o of n){if((o==null?void 0:o.id)==null||r[o.id]!==void 0)continue;if(!q(o)){r[o.id]=t;continue}const s=o!=null&&o.created_at?Date.parse(o.created_at):NaN;if(!Number.isFinite(s)||s<this.convOpenedAt){r[o.id]=t;continue}const a=typeof(o==null?void 0:o.text_md)=="string"&&o.text_md.trim().length>0,l=Array.isArray((i=o==null?void 0:o.payload)==null?void 0:i.attachments)&&o.payload.attachments.length>0;if(!a&&!l){r[o.id]=t;continue}r[o.id]=0,this.scheduleReveal(o)}this.revealedAt=r,(this.isOpen||this.isEmbedded)&&!this.historyOpen&&this.currentConv&&this.markConvRead(this.currentConv)}},async mounted(){if(console.log("[messenger] mounted",{isEditor:this.isEditor,canBoot:this.canBoot,hasBaseUrl:!!this.baseUrl,hasWidgetId:!!this.widgetId,hasUserId:!!this.userId,hasUserHash:!!this.userHash}),typeof document<"u"&&!document.getElementById(oe)){const n=document.createElement("style");n.id=oe,n.textContent=le,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:{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 i=r[0];if(!i)return;const o=Math.ceil(i.contentRect.height+8);o!==this.floatHeight&&(this.floatHeight=o,this.$nextTick(()=>{var s,a;(a=(s=this.$refs.messageList)==null?void 0:s.scrollToBottom)==null||a.call(s)}))}),this.floatRO.observe(t)}},disconnectFloatRO(){if(this.floatRO){try{this.floatRO.disconnect()}catch{}this.floatRO=null}},convLastActivity(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 i of t)i!=null&&i.created_at&&i.created_at>r&&(r=i.created_at);return r},lastMessageAuthorType(n){var t,r;for(let i=n.length-1;i>=0;i--){const o=(r=(t=n[i])==null?void 0:t.author)==null?void 0:r.type;if(o)return o}return""},convPreview(n,t){var r,i,o;for(let s=t.length-1;s>=0;s--){const a=t[s];if(!a)continue;const l=typeof a.text_md=="string"?a.text_md.trim():"";if(l)return(((r=a.author)==null?void 0:r.type)==="user"?"Vous : ":"")+l.replace(/\s+/g," ");const f=(i=a.payload)==null?void 0:i.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)||((o=n==null?void 0:n.metadata)==null?void 0:o.last_preview)||""},readStorageKey(){const n=this.widgetId||"",t=this.userId||"";return`wm:read:${n}:${t}`},readBootStorageKey(){const n=this.widgetId||"",t=this.userId||"";return`wm:read-boot:${n}:${t}`},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 i,o;if(!(n!=null&&n.id)||n._draft)return;const t=((o=(i=this.s)==null?void 0:i.messagesByConv)==null?void 0:o[n.id])||[],r=this.convLastActivity(n,t);r&&this.readState[n.id]!==r&&(this.readState={...this.readState,[n.id]:r},this.persistReadState())},cancelReveals(){for(const n of this.revealTimers)clearTimeout(n);this.revealTimers=[]},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)},scheduleReveal(n){const t=Date.now(),r=((n==null?void 0:n.text_md)||"").length,i=Math.min(xo,Math.max(To,r*Ao)),s=Math.max(t+Vo,this.nextRevealAt+Mo)+i;this.nextRevealAt=s;const a=Math.max(0,s-t),l=n.id,f=setTimeout(()=>{this.revealedAt={...this.revealedAt,[l]:Date.now()},this.revealTimers=this.revealTimers.filter(y=>y!==f)},a);this.revealTimers.push(f)},async boot(){if(!this.canBoot){console.warn("[messenger] boot skipped — missing creds",{baseUrl:this.baseUrl,widgetId:this.widgetId,userId:this.userId,hasUserHash:!!this.userHash});return}try{console.log("[messenger] boot start",{baseUrl:this.baseUrl,widgetId:this.widgetId,userId:this.userId}),this.transport=e.markRaw(ae({baseUrl:this.baseUrl,widgetId:this.widgetId,userId:this.userId,userHash:this.userHash})),this.store=e.markRaw(ie(this.transport)),this.hydrateNotifPref(),this.setupNotifications(),await this.store.start(),this.customer&&typeof this.customer=="object"&&await this.store.applyCustomer(this.customer),console.log("[ww-messenger] boot done",{ready:this.store.state.ready,error:this.store.state.error})}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.revealedAt={},this.nextRevealAt=0,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()},async openFromPeek(n){var r,i;const t=n||((r=this.latestUnreads[0])==null?void 0:r.convId);t&&t!==((i=this.currentConv)==null?void 0:i.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})},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)},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()},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()},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{}},onIncomingNotification(n){var a;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||!q(r))return;const i=r!=null&&r.created_at?Date.parse(r.created_at):NaN;if(Number.isFinite(i)&&i<this.convOpenedAt-1e3)return;const o=typeof document<"u"&&document.hidden;this.isOpen&&!o&&((a=this.currentConv)==null?void 0:a.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,i=t.createOscillator(),o=t.createGain();i.connect(o),o.connect(t.destination),i.type="sine",i.frequency.setValueAtTime(880,r),i.frequency.exponentialRampToValueAtTime(1320,r+.08),o.gain.setValueAtTime(0,r),o.gain.linearRampToValueAtTime(.12,r+.02),o.gain.exponentialRampToValueAtTime(1e-4,r+.28),i.start(r),i.stop(r+.32)}catch{}},showBrowserNotification(n,t){var a;if(typeof Notification>"u"||Notification.permission!=="granted")return;const r=this.allConversations.find(l=>l.id===n),i=(r==null?void 0:r.name)||((a=this.widget)==null?void 0:a.name)||"Nouveau message",o=typeof(t==null?void 0:t.text_md)=="string"?t.text_md.trim():"",s=o?o.slice(0,140):"Vous avez un nouveau message";try{const l=new Notification(i,{body:s,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)}},async onMoreAction(n){switch(this.moreOpen=!1,n){case"history":this.historyOpen=!0;break;case"rename":this.openRenameDialog();break;case"export":this.exportCurrentConv();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(i){console.error("[ww-messenger] rename failed",i)}},exportCurrentConv(){var o,s,a,l,f,y;const n=this.currentConv;if(!n)return;const t=(((s=(o=this.s)==null?void 0:o.messagesByConv)==null?void 0:s[n.id])||[]).slice(),r=[`# ${n.name||"Conversation"}`,n.created_at?`Créée le : ${n.created_at}`:"",""];for(const g of t){if(!g)continue;const w=((a=g.author)==null?void 0:a.name)||(((l=g.author)==null?void 0:l.type)==="user"?"Vous":((f=g.author)==null?void 0:f.type)==="agent_human"?"Agent":((y=g.author)==null?void 0:y.type)==="agent_ia"?"Assistant IA":"Système"),S=g.created_at?new Date(g.created_at).toLocaleString("fr-FR"):"",k=(g.text_md||"").trim();k&&(r.push(`[${S}] ${w} :`),r.push(k),r.push(""))}const i=new Blob([r.join(`
56
- `)],{type:"text/plain;charset=utf-8"});try{const g=URL.createObjectURL(i),w=document.createElement("a");w.href=g,w.download=`${(n.name||"conversation").replace(/[^a-z0-9-_]+/gi,"_")}.txt`,document.body.appendChild(w),w.click(),document.body.removeChild(w),setTimeout(()=>URL.revokeObjectURL(g),1e3)}catch(g){console.error("[ww-messenger] export failed",g)}},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,i=this.pendingAttachments.slice();this.pendingAttachments=[],this.unreadAnchorTs="",this.unreadBoundaryTs="",await this.store.send(r,n,{attachments:i.length?i: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=No(t.form,n);if(!r)return;let i=this.currentConv;i&&(i._draft&&(i=await this.ensureRealConv(),!i)||await this.store.send(i.id,r,{metadata:{artifact:So(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}}}}},Io={key:0,class:"wm-loading","aria-busy":"true","aria-live":"polite"},Do={key:0,class:"wm-state"},Lo={class:"wm-state__err"},Ro={class:"wm-state__errSub"},$o={class:"wm-bottom"},Fo={key:0,ref:"floatEl",class:"wm-float"},Uo={key:1,class:"wm-actionWait",role:"status","aria-live":"polite"},jo={class:"wm-actionWait__lbl"},Po={key:2,class:"wm-attached"},zo=["onClick"];function Ho(n,t,r,i,o,s){const a=e.resolveComponent("Launcher"),l=e.resolveComponent("Header"),f=e.resolveComponent("Onboarding"),y=e.resolveComponent("MessageList"),g=e.resolveComponent("ApprovalCard"),w=e.resolveComponent("FormCard"),S=e.resolveComponent("Feedback"),k=e.resolveComponent("SuggestionChips"),A=e.resolveComponent("Composer"),b=e.resolveComponent("MoreMenu"),x=e.resolveComponent("RenameDialog"),M=e.resolveComponent("HistoryDrawer");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-root",`wm-root--${r.displayMode}`])},[!o.isOpen&&!s.isEmbedded?(e.openBlock(),e.createBlock(a,{key:0,"unread-count":s.unreadCount,peeks:s.launcherPeeks,onOpen:s.openFromPeek,onDismiss:s.dismissPeek},null,8,["unread-count","peeks","onOpen","onDismiss"])):e.createCommentVNode("",!0),o.isOpen||s.isEmbedded?(e.openBlock(),e.createElementBlock("section",{key:1,class:e.normalizeClass(["wm-panel",`wm-panel--${r.displayMode}`]),style:e.normalizeStyle(o.floatHeight?{"--wm-float-h":o.floatHeight+"px"}:null),role:"dialog","aria-label":"Messenger"},[!s.ready&&!s.error?(e.openBlock(),e.createElementBlock("div",Io,[s.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)=>s.close&&s.close(...V))},[...t[7]||(t[7]=[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[8]||(t[8]=e.createElementVNode("div",{class:"wm-loading__spinner","aria-hidden":"true"},null,-1))])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createVNode(l,{title:s.headerTitle,escalated:s.isEscalated,"agent-name":s.humanAgentName,"agent-avatar-url":s.humanAgentAvatarUrl,"team-members":s.teamMembers,"response-label":s.responseLabel,"show-identity":!!s.currentConv,"show-back":s.canBack,"show-close":!s.isEmbedded,"more-active":o.moreOpen,onBack:s.goHome,onMore:s.toggleMore,onClose:s.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"]),s.error?(e.openBlock(),e.createElementBlock("div",Do,[e.createElementVNode("div",Lo,[t[10]||(t[10]=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[9]||(t[9]=e.createElementVNode("div",{class:"wm-state__errTitle"},"Connexion impossible",-1)),e.createElementVNode("div",Ro,e.toDisplayString(s.error),1)])])])):s.currentConv?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createVNode(y,{ref:"messageList",messages:s.displayedMessages,"streaming-active":s.streamingActive,"date-label":s.dateLabel,"conversation-id":s.currentConv?s.currentConv.id:null,"loading-more":s.paginationState.loading,"has-more":s.paginationState.hasMore,"unread-anchor-ts":o.unreadAnchorTs,"unread-boundary-ts":o.unreadBoundaryTs,onLoadMore:s.onLoadMore},null,8,["messages","streaming-active","date-label","conversation-id","loading-more","has-more","unread-anchor-ts","unread-boundary-ts","onLoadMore"]),e.createElementVNode("div",$o,[s.floatVisible?(e.openBlock(),e.createElementBlock("div",Fo,[s.approvalReady?(e.openBlock(),e.createBlock(g,{key:0,action:s.approvalTitle,detail:s.approvalDetail,callbacks:s.pendingApproval.callbacks,onCallback:s.onApprovalCallback},null,8,["action","detail","callbacks","onCallback"])):s.pendingForm?(e.openBlock(),e.createBlock(w,{key:s.pendingForm.message&&s.pendingForm.message.id,form:s.pendingForm.form,onSubmit:s.onFormSubmit},null,8,["form","onSubmit"])):s.showFeedback?(e.openBlock(),e.createBlock(S,{key:2,busy:o.feedbackBusy,done:o.feedbackDone,onSubmit:s.onFeedback},null,8,["busy","done","onSubmit"])):(e.openBlock(),e.createBlock(k,{key:3,items:s.suggestions,onSelect:s.onSuggestion},null,8,["items","onSelect"]))],512)):e.createCommentVNode("",!0),s.actionInFlight?(e.openBlock(),e.createElementBlock("div",Uo,[t[11]||(t[11]=e.createElementVNode("span",{class:"wm-actionWait__spinner","aria-hidden":"true"},null,-1)),e.createElementVNode("span",jo,e.toDisplayString(s.actionInFlightName)+" en cours, veuillez patienter…",1)])):(e.openBlock(),e.createBlock(A,{key:2,ref:"composer",modelValue:o.draft,"onUpdate:modelValue":t[2]||(t[2]=V=>o.draft=V),placeholder:s.composerPlaceholder,disabled:!!s.pendingApproval,"attach-label":"Joindre un fichier",onSend:s.onSend,onAttach:s.onAttach},null,8,["modelValue","placeholder","disabled","onSend","onAttach"]))]),o.moreOpen?(e.openBlock(),e.createBlock(b,{key:0,"can-rename":!!s.currentConv&&!s.currentConv._draft,"can-export":!!s.currentConv&&!s.currentConv._draft,"sound-enabled":o.soundEnabled,"browser-notif-enabled":o.browserNotifEnabled,"status-url":s.statusUrl,"help-url":s.helpUrl,onClose:t[3]||(t[3]=V=>o.moreOpen=!1),onSoundToggle:s.onSoundToggle,onBrowserNotifToggle:s.onBrowserNotifToggle,onAction:s.onMoreAction},null,8,["can-rename","can-export","sound-enabled","browser-notif-enabled","status-url","help-url","onSoundToggle","onBrowserNotifToggle","onAction"])):e.createCommentVNode("",!0),o.renameDialogOpen&&s.currentConv&&!s.currentConv._draft?(e.openBlock(),e.createBlock(x,{key:1,"initial-value":s.currentConv.name||"",title:"Modifier le titre de la conversation",onClose:t[4]||(t[4]=V=>o.renameDialogOpen=!1),onSubmit:s.onRenameSubmit},null,8,["initial-value","onSubmit"])):e.createCommentVNode("",!0),o.pendingAttachments.length?(e.openBlock(),e.createElementBlock("div",Po,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.pendingAttachments,(V,O)=>(e.openBlock(),e.createElementBlock("div",{key:O,class:"wm-attached__chip"},[t[13]||(t[13]=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:R=>o.pendingAttachments.splice(O,1)},[...t[12]||(t[12]=[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,zo)]))),128))])):e.createCommentVNode("",!0)],64)):(e.openBlock(),e.createBlock(f,{key:1,"welcome-message":s.widgetWelcomeMessage,"agent-name":s.agentName,"quick-links":s.quickLinks,"open-threads":s.openThreads,busy:o.busy,onStart:s.startConv,onSelect:s.onQuickLink,onResume:s.onDrawerPick,onViewAll:t[1]||(t[1]=V=>o.historyOpen=!0)},null,8,["welcome-message","agent-name","quick-links","open-threads","busy","onStart","onSelect","onResume"])),o.historyOpen?(e.openBlock(),e.createBlock(M,{key:3,conversations:s.drawerConversations,"active-id":s.currentConv?s.currentConv.id:null,onClose:t[5]||(t[5]=V=>o.historyOpen=!1),onNew:s.onDrawerNew,onPick:s.onDrawerPick},null,8,["conversations","active-id","onNew","onPick"])):e.createCommentVNode("",!0),o.moreOpen&&!s.currentConv?(e.openBlock(),e.createBlock(b,{key:4,"can-rename":!1,"can-export":!1,"sound-enabled":o.soundEnabled,"browser-notif-enabled":o.browserNotifEnabled,"status-url":s.statusUrl,"help-url":s.helpUrl,onClose:t[6]||(t[6]=V=>o.moreOpen=!1),onSoundToggle:s.onSoundToggle,onBrowserNotifToggle:s.onBrowserNotifToggle,onAction:s.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 De=N(Oo,[["render",Ho],["__scopeId","data-v-a000a0f5"]]),qo="0.3.6";exports.AIAvatar=U;exports.AVATAR_COLORS=K;exports.ActionResult=pe;exports.ApprovalCard=Te;exports.ArtifactFormResponse=fe;exports.ArtifactInfoCard=_e;exports.ArtifactRenderer=ve;exports.ArtifactTicket=ge;exports.AttachmentPreview=ye;exports.Bubble=we;exports.Composer=Ve;exports.DEFAULT_BASE_URL=ce;exports.Feedback=Me;exports.FormCard=xe;exports.Header=me;exports.HistoryDrawer=Oe;exports.HumanAvatar=G;exports.Launcher=de;exports.MEDIA_RECORDER_SUPPORTED=Y;exports.MessageList=Ee;exports.Messenger=De;exports.MoreMenu=Ie;exports.Onboarding=he;exports.SCREEN_CAPTURE_SUPPORTED=P;exports.SuggestionChips=Ae;exports.TeamAvatars=ue;exports.Typing=be;exports.VERSION=qo;exports.avatarColor=Z;exports.avatarInitials=Q;exports.captureScreenshotFile=Ne;exports.colors=T;exports.createStore=ie;exports.createTransport=ae;exports.default=De;exports.formatTime=ee;exports.guessAttachmentKind=xr;exports.pickRecorderMime=Be;exports.renderMarkdown=ke;exports.startScreenRecording=Se;exports.tokensCss=le;exports.uuid=X;exports.v4=X;
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 Vt(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 P=N(Bt,[["render",Vt],["__scopeId","data-v-8c924688"]]),St={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"],xt={key:1},Mt={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",xt,e.toDisplayString(o.initialsFor(i)),1))],4))),128))],4),r.responseLabel?(e.openBlock(),e.createElementBlock("span",Mt,e.toDisplayString(r.responseLabel),1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)}const he=N(St,[["render",Ot],["__scopeId","data-v-3659b9c1"]]),It={name:"WmHeader",components:{AIAvatar:P,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},showPresence(){return this.hasTeam||this.escalated&&!!this.agentName},statusText(){return this.escalated&&this.agentName?this.agentName:"En ligne"}}},Dt={class:"wm-header"},$t={key:1,style:{width:"30px",height:"30px","flex-shrink":"0"}},Lt={class:"wm-header__avatar"},Rt={class:"wm-header__main"},Ft={class:"wm-header__title"},Pt={key:0,class:"wm-header__sub"},jt={class:"wm-header__status"},zt={key:3,class:"wm-header__fill"},Ut={class:"wm-header__actions"};function Ht(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",$t)),r.showIdentity?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createElementVNode("div",Lt,[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.showPresence?(e.openBlock(),e.createElementBlock("div",Pt,[o.hasTeam?(e.openBlock(),e.createBlock(f,{key:0,members:r.teamMembers,"response-label":r.responseLabel},null,8,["members","response-label"])):e.createCommentVNode("",!0),e.createElementVNode("span",jt,[t[4]||(t[4]=e.createElementVNode("span",{class:"wm-header__dot"},null,-1)),e.createTextVNode(" "+e.toDisplayString(o.statusText),1)])])):e.createCommentVNode("",!0)])],64)):(e.openBlock(),e.createElementBlock("div",zt)),e.createElementVNode("div",Ut,[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[5]||(t[5]=[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[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)])])):e.createCommentVNode("",!0)])])}const pe=N(It,[["render",Ht],["__scopeId","data-v-b5f5f6a9"]]),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"},qt={name:"WmOnboarding",components:{AIAvatar:P},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","view-all"],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"}},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"})}}},Kt={class:"wm-onb"},Wt={class:"wm-onb__hero"},Gt={class:"wm-onb__title"},Yt={class:"wm-onb__sub"},Jt={class:"wm-onb__cta"},Xt=["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__list"},cn=["onClick"],dn={class:"wm-onb__thread-icon"},un={key:0,class:"wm-onb__thread-dot","aria-label":"Non lu"},mn={class:"wm-onb__thread-body"},hn={class:"wm-onb__thread-title"},pn={class:"wm-onb__thread-preview"},fn={class:"wm-onb__thread-meta"},_n={key:0,class:"wm-onb__thread-time"};function gn(n,t,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",Jt,[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,Xt)]),r.quickLinks.length?(e.openBlock(),e.createElementBlock("div",Qt,[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",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,[t[7]||(t[7]=e.createElementVNode("div",{class:"wm-onb__section-title"},"Conversations récentes",-1)),e.createElementVNode("div",ln,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.openThreads,l=>(e.openBlock(),e.createElementBlock("button",{key:l.id,type:"button",class:"wm-onb__thread",onClick:f=>n.$emit("resume",l)},[e.createElementVNode("span",dn,[t[4]||(t[4]=e.createElementVNode("svg",{width:"18",height:"18",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:"M12 5v14M5 12h14"})],-1)),l.unread?(e.openBlock(),e.createElementBlock("span",un)):e.createCommentVNode("",!0)]),e.createElementVNode("span",mn,[e.createElementVNode("span",hn,e.toDisplayString(l.title),1),e.createElementVNode("span",pn,e.toDisplayString(l.preview),1)]),e.createElementVNode("span",fn,[o.formatTs(l._ts)?(e.openBlock(),e.createElementBlock("span",_n,e.toDisplayString(o.formatTs(l._ts)),1)):e.createCommentVNode("",!0),t[5]||(t[5]=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)),e.createElementVNode("button",{type:"button",class:"wm-onb__viewAll",onClick:t[1]||(t[1]=l=>n.$emit("view-all"))},[...t[6]||(t[6]=[e.createTextVNode(" Voir toutes les conversations ",-1),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 18l6-6-6-6"})],-1)])])])])):e.createCommentVNode("",!0)])}const fe=N(qt,[["render",gn],["__scopeId","data-v-3de759ce"]]);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"},Vn={class:"wm-result__detail"};function Sn(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",Vn,e.toDisplayString(o.detailText),1)],64)):e.createCommentVNode("",!0)])],2)}const _e=N(yn,[["render",Sn],["__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"},xn={class:"wm-art__head"},Mn={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",xn,[e.createElementVNode("div",Mn,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"]]),$n={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}}},Ln={class:"wm-art wm-art--infoCard"},Rn={key:0,class:"wm-art__image"},Fn=["src","alt"],Pn={class:"wm-art__head"},jn={class:"wm-art__headMain"},zn={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",Ln,[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",Pn,[e.createElementVNode("div",jn,[e.createElementVNode("div",zn,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($n,[["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(""),V=v!==1?` start="${v}"`:"";r.push({type:"block",html:`<ol class="wm-md-ol"${V}>${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"]]),Vr={name:"WmTyping"},Sr={class:"wm-typing"};function Ar(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Sr,[...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(Vr,[["render",Ar],["__scopeId","data-v-df2447fd"]]);function j(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"},xr=80,Mr=200,Or={name:"WmMessageList",components:{AIAvatar:P,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-${j(i)}`,role:"ai",agentName:"",agentAvatarUrl:null,messages:[i],items:[]});continue}n.push({key:`sys-${j(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-${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 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:j,isAtBottom(n){return n.scrollHeight-n.scrollTop-n.clientHeight<=xr},onScroll(){const n=this.$refs.scrollEl;n&&(this.loadingMore||!this.hasMore||this._pendingLoadMore||n.scrollTop<=Mr&&(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 L,I,F;const r=n.items,a=(L=r[t])==null?void 0:L.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)],V=this.widthByKey[this.rowKeyOf(n,t-1)],k=this.widthByKey[this.rowKeyOf(n,t+1)],A=.5,w=($,D,R)=>$!=null&&b!=null?$+A>=b:D===R||D==="card"&&R==="bubble";let x=l,M=l,S=l,O=l;return i?(v&&(M=f),(y||!o)&&(S=f),v&&w(V,v,a==null?void 0:a.top)&&(x=f),y&&w(k,y,a==null?void 0:a.bottom)&&(O=f)):(v&&(x=f),(y||!o)&&(O=f),v&&w(V,v,a==null?void 0:a.top)&&(M=f),y&&w(k,y,a==null?void 0:a.bottom)&&(S=f)),{tl:x,tr:M,br:S,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?`${j(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"},$r={key:2,class:"wm-list__sep"},Lr={class:"wm-list__sep-label"},Rr={key:0,class:"wm-list__sep wm-list__sep--unread"},Fr={key:0,class:"wm-list__sysep"},Pr={class:"wm-list__sysep-label"},jr=["data-row-key"],zr={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"),V=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",$r,[t[2]||(t[2]=e.createElementVNode("div",{class:"wm-list__line"},null,-1)),e.createElementVNode("span",Lr,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",Pr,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,x)=>(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,x))},[k.role!=="user"?(e.openBlock(),e.createElementBlock("div",zr,[x===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),(M,S)=>(e.openBlock(),e.createBlock(b,{key:`${o.messageKey(w.message)}-att-${S}`,attachment:M},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",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(V)])):e.createCommentVNode("",!0)],34)}const Ce=N(Or,[["render",Yr],["__scopeId","data-v-21381fcb"]]),z=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 Ve({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 Se(){if(!z)return null;let n;try{n=await navigator.mediaDevices.getDisplayMedia(Ve({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(!z||!Y)return null;let t;try{t=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=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(V=>{V.stop()}),s.length){const V=a.mimeType||r||"video/webm",k=new Blob(s,{type:V}),A=/mp4/.test(V)?"mp4":"webm",w=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),x=new File([k],`ecran-${w}.${A}`,{type:V});(y=n.onfinalize)==null||y.call(n,x)}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"&&!z||n.action==="record"&&(!z||!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 Se();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 xe=N(po,[["render",_o],["__scopeId","data-v-55aa529d"]]),go={name:"WmApprovalCard",components:{AIAvatar:P},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 Me=N(go,[["render",Co],["__scopeId","data-v-b1be139c"]]);let se=0;const No=new Set(["text","textarea","number","boolean","select","multiselect","date"]),Vo={name:"WmFormCard",components:{AIAvatar:P},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}}}},So={class:"wm-form"},Ao={class:"wm-form__head"},To={class:"wm-form__icon"},xo={class:"wm-form__main"},Mo={class:"wm-form__title"},Oo={key:0,class:"wm-form__detail"},Io=["for"],Do={key:0,class:"wm-form__req","aria-hidden":"true"},$o=["id","onUpdate:modelValue","placeholder","required","disabled"],Lo=["id","onUpdate:modelValue","placeholder","required","disabled"],Ro=["id","onUpdate:modelValue","placeholder","required","disabled"],Fo=["id","onUpdate:modelValue","required","disabled"],Po={key:4,class:"wm-form__bool"},jo=["id","onUpdate:modelValue","disabled"],zo=["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",So,[e.createElementVNode("div",Ao,[e.createElementVNode("div",To,[e.createVNode(i,{size:24})]),e.createElementVNode("div",xo,[e.createElementVNode("div",Mo,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,$o)),[[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,Lo)),[[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",Po,[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,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":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,zo)),[[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(Vo,[["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"]]),Vs={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)}}},Ss={class:"wm-mm"},As={class:"wm-mm__pop",role:"menu"},Ts={class:"wm-mm__section"},xs={class:"wm-mm__section"},Ms={class:"wm-mm__section"};function Os(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Ss,[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",xs,[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",Ms,[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 $e=N(Vs,[["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"},$s={class:"wm-dialog__card",role:"dialog","aria-modal":"true"},Ls={class:"wm-dialog__head"},Rs={class:"wm-dialog__title"},Fs={class:"wm-dialog__body"},Ps=["placeholder"],js={class:"wm-dialog__actions"},zs=["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",$s,[e.createElementVNode("div",Ls,[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,Ps),[[e.vModelText,s.value]])]),e.createElementVNode("div",js,[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,zs)])])])}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:xe,ApprovalCard:Me,FormCard:Oe,Feedback:Ie,HistoryDrawer:De,MoreMenu:$e,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 V;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(((V=A.author)==null?void 0:V.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).slice(0,5)},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"),V=e.resolveComponent("Feedback"),k=e.resolveComponent("SuggestionChips"),A=e.resolveComponent("Composer"),w=e.resolveComponent("MoreMenu"),x=e.resolveComponent("RenameDialog"),M=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]=(...S)=>o.close&&o.close(...S))},[...t[7]||(t[7]=[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[8]||(t[8]=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[10]||(t[10]=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[9]||(t[9]=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(V,{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[11]||(t[11]=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[2]||(t[2]=S=>s.draft=S),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[3]||(t[3]=S=>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(x,{key:1,"initial-value":o.currentConv.name||"",title:"Modifier le titre de la conversation",onClose:t[4]||(t[4]=S=>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,(S,O)=>(e.openBlock(),e.createElementBlock("div",{key:O,class:"wm-attached__chip"},[t[13]||(t[13]=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(S.name),1),e.createElementVNode("button",{type:"button","aria-label":"Retirer",onClick:L=>s.pendingAttachments.splice(O,1)},[...t[12]||(t[12]=[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,onViewAll:t[1]||(t[1]=S=>s.historyOpen=!0)},null,8,["welcome-message","agent-name","quick-links","open-threads","busy","onStart","onSelect","onResume"])),s.historyOpen?(e.openBlock(),e.createBlock(M,{key:3,conversations:o.drawerConversations,"active-id":o.currentConv?o.currentConv.id:null,onClose:t[5]||(t[5]=S=>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[6]||(t[6]=S=>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 Le=N(qs,[["render",na],["__scopeId","data-v-29cf778d"]]),ra="0.3.7";exports.AIAvatar=P;exports.AVATAR_COLORS=q;exports.ActionResult=_e;exports.ApprovalCard=Me;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=Le;exports.MoreMenu=$e;exports.Onboarding=fe;exports.SCREEN_CAPTURE_SUPPORTED=z;exports.SuggestionChips=xe;exports.TeamAvatars=he;exports.Typing=Be;exports.VERSION=ra;exports.avatarColor=Q;exports.avatarInitials=Z;exports.captureScreenshotFile=Se;exports.colors=T;exports.createStore=le;exports.createTransport=ie;exports.default=Le;exports.formatTime=ee;exports.guessAttachmentKind=Jr;exports.pickRecorderMime=Ne;exports.renderMarkdown=be;exports.startScreenRecording=Ae;exports.tokensCss=ce;exports.uuid=X;exports.v4=X;