@fayz-ai/plugin-conversations 0.26.0 → 0.27.1

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.
Files changed (47) hide show
  1. package/dist/CampaignsSurface-75POQIRI.js +860 -0
  2. package/dist/CampaignsSurface-75POQIRI.js.map +1 -0
  3. package/dist/{ConversationsPage-7W7LDH2H.js → ConversationsPage-RYEND3MG.js} +345 -170
  4. package/dist/ConversationsPage-RYEND3MG.js.map +1 -0
  5. package/dist/TemplatesSurface-QNTRYYTX.js +281 -0
  6. package/dist/TemplatesSurface-QNTRYYTX.js.map +1 -0
  7. package/dist/chunk-4OWC3V53.js +323 -0
  8. package/dist/chunk-4OWC3V53.js.map +1 -0
  9. package/dist/chunk-HMWUU5O7.js +75 -0
  10. package/dist/chunk-HMWUU5O7.js.map +1 -0
  11. package/dist/{chunk-6EZLUC62.js → chunk-VZLFELO6.js} +4 -74
  12. package/dist/chunk-VZLFELO6.js.map +1 -0
  13. package/dist/data/journeys.d.ts +198 -0
  14. package/dist/data/journeys.d.ts.map +1 -0
  15. package/dist/index.d.ts +6 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +106 -10
  18. package/dist/index.js.map +1 -1
  19. package/dist/locales/en.d.ts.map +1 -1
  20. package/dist/locales/pt-BR.d.ts.map +1 -1
  21. package/dist/migrations/index.d.ts +2 -0
  22. package/dist/migrations/index.d.ts.map +1 -1
  23. package/dist/migrations/main.browser.js +3 -1
  24. package/dist/migrations/main.browser.js.map +1 -1
  25. package/dist/migrations/main.js +260 -2
  26. package/dist/migrations/main.js.map +1 -1
  27. package/dist/store.d.ts.map +1 -1
  28. package/dist/views/ContactPanel.d.ts.map +1 -1
  29. package/dist/views/ConversationList.d.ts.map +1 -1
  30. package/dist/views/ConversationsPage.d.ts +2 -0
  31. package/dist/views/ConversationsPage.d.ts.map +1 -1
  32. package/dist/views/MessageThread.d.ts.map +1 -1
  33. package/dist/views/campaigns/CampaignWizard.d.ts +8 -0
  34. package/dist/views/campaigns/CampaignWizard.d.ts.map +1 -0
  35. package/dist/views/campaigns/CampaignsSurface.d.ts +4 -0
  36. package/dist/views/campaigns/CampaignsSurface.d.ts.map +1 -0
  37. package/dist/views/campaigns/NumberProtection.d.ts +5 -0
  38. package/dist/views/campaigns/NumberProtection.d.ts.map +1 -0
  39. package/dist/views/campaigns/TemplatesSurface.d.ts +3 -0
  40. package/dist/views/campaigns/TemplatesSurface.d.ts.map +1 -0
  41. package/dist/views/contact-profile.d.ts +58 -0
  42. package/dist/views/contact-profile.d.ts.map +1 -0
  43. package/package.json +3 -3
  44. package/dist/ConversationsPage-7W7LDH2H.js.map +0 -1
  45. package/dist/chunk-6EZLUC62.js.map +0 -1
  46. package/dist/views/LeadCard.d.ts +0 -6
  47. package/dist/views/LeadCard.d.ts.map +0 -1
@@ -1,10 +1,11 @@
1
- import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, MessagePreview, providersApi, mediaPreviewKind } from './chunk-6EZLUC62.js';
1
+ import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, MessagePreview, mediaPreviewKind } from './chunk-VZLFELO6.js';
2
+ import { providersApi } from './chunk-HMWUU5O7.js';
2
3
  import * as React9 from 'react';
3
4
  import React9__default from 'react';
4
- import { SquarePen, MessageSquare, Globe, Mail, Instagram, Phone, Search, User, Inbox, CheckCheck, ChevronLeft, Archive, PanelRight, Send, X, MapPin, Tag, StickyNote, Link2, CheckCircle2, MoreVertical, Loader2, Forward, AlertTriangle, Check, Clock, ExternalLink, Reply, Snowflake, Sun, Flame, Building2, Ban, BarChart3, UserRound, Copy, FileText, Download } from 'lucide-react';
5
- import { PageHeaderActions, cn, Button, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Textarea, ModalFooter, Input, FilterChip, Skeleton, toast } from '@fayz-ai/ui';
5
+ import { SquarePen, MessageSquare, Globe, Mail, Instagram, Phone, Search, User, Archive, Inbox, CheckCheck, ChevronLeft, MoreHorizontal, ArchiveRestore, Send, X, Building2, CheckCircle2, MoreVertical, Loader2, Forward, AlertTriangle, Check, Clock, ExternalLink, Reply, Snowflake, Sun, Flame, Ban, BarChart3, MapPin, UserRound, Copy, FileText, Download } from 'lucide-react';
6
+ import { PageHeaderActions, cn, Button, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Textarea, ModalFooter, Input, FilterChip, Skeleton, Dropdown, DropdownTrigger, DropdownContent, DropdownItem, toast } from '@fayz-ai/ui';
6
7
  import { useRightRailStore, PageActions, useLimitGuard, ContactPicker, invalidateLimit, useConnectors, adminNavigateTo } from '@fayz-ai/admin';
7
- import { currentAppPath, appHref, useTranslation, useActiveTenantId, errorMessage, tl, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
8
+ import { currentAppPath, appHref, onAppPathChange, replaceApp, useTranslation, useActiveTenantId, errorMessage, tl, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
8
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
9
10
 
10
11
  var CHANNEL_ICON = {
@@ -177,6 +178,11 @@ function ConversationList({ className }) {
177
178
  setLeadOwnerFilter,
178
179
  setSearch
179
180
  } = useConversationsStore((s) => s);
181
+ const [archived, setArchived] = React9__default.useState(false);
182
+ const shown = React9__default.useMemo(
183
+ () => conversations.filter((c) => archived ? c.status === "closed" : c.status !== "closed"),
184
+ [conversations, archived]
185
+ );
180
186
  const donos = React9__default.useMemo(() => {
181
187
  const vistos = /* @__PURE__ */ new Map();
182
188
  for (const c of conversations) {
@@ -216,19 +222,40 @@ function ConversationList({ className }) {
216
222
  id
217
223
  );
218
224
  }) }),
219
- donos.length > 0 && /* @__PURE__ */ jsx("div", { className: "mt-2", children: /* @__PURE__ */ jsx(
220
- FilterChip,
221
- {
222
- label: t("conversations.contact.leadOwner"),
223
- icon: User,
224
- allLabel: t("conversations.filter.anyOwner"),
225
- options: [{ value: "none", label: t("conversations.filter.noOwner") }, ...donos],
226
- value: leadOwnerFilter,
227
- onChange: (v) => {
228
- void setLeadOwnerFilter(v);
225
+ /* @__PURE__ */ jsxs("div", { className: "mt-2 flex flex-wrap items-center gap-1", children: [
226
+ donos.length > 0 && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
227
+ FilterChip,
228
+ {
229
+ label: t("conversations.contact.leadOwner"),
230
+ icon: User,
231
+ allLabel: t("conversations.filter.anyOwner"),
232
+ options: [{ value: "none", label: t("conversations.filter.noOwner") }, ...donos],
233
+ value: leadOwnerFilter,
234
+ onChange: (v) => {
235
+ void setLeadOwnerFilter(v);
236
+ }
229
237
  }
230
- }
231
- ) })
238
+ ) }),
239
+ /* @__PURE__ */ jsxs(
240
+ Button,
241
+ {
242
+ variant: "bare",
243
+ size: "bare",
244
+ type: "button",
245
+ "aria-pressed": archived,
246
+ onClick: () => setArchived((v) => !v),
247
+ className: cn(
248
+ "inline-flex items-center gap-1 rounded-full border px-2.5 py-1 text-xs font-medium transition-colors",
249
+ archived ? "border-transparent bg-primary text-primary-foreground" : "border-transparent bg-muted text-muted-foreground hover:bg-muted/70"
250
+ ),
251
+ children: [
252
+ /* @__PURE__ */ jsx(Archive, { className: "h-3 w-3" }),
253
+ " ",
254
+ t("conversations.filter.archived")
255
+ ]
256
+ }
257
+ )
258
+ ] })
232
259
  ] }),
233
260
  /* @__PURE__ */ jsxs("div", { className: "min-h-0 flex-1 overflow-y-auto", children: [
234
261
  loading && conversations.length === 0 && Array.from({ length: 6 }, (_, i) => /* @__PURE__ */ jsxs("div", { className: "flex w-full items-start gap-3 border-b border-border/50 px-3 py-3", children: [
@@ -242,11 +269,11 @@ function ConversationList({ className }) {
242
269
  /* @__PURE__ */ jsx(Skeleton, { className: "mt-1.5 h-3 w-3/4" })
243
270
  ] })
244
271
  ] }, i)),
245
- !loading && conversations.length === 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 p-8 text-center text-muted-foreground", children: [
272
+ !loading && shown.length === 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 p-8 text-center text-muted-foreground", children: [
246
273
  /* @__PURE__ */ jsx(Inbox, { className: "h-6 w-6" }),
247
- /* @__PURE__ */ jsx("p", { className: "text-sm", children: t("conversations.list.empty") })
274
+ /* @__PURE__ */ jsx("p", { className: "text-sm", children: archived ? t("conversations.list.emptyArchived") : t("conversations.list.empty") })
248
275
  ] }),
249
- conversations.map((c) => {
276
+ shown.map((c) => {
250
277
  const active = c.id === selectedId;
251
278
  const unread = isWaitingOnUs(c);
252
279
  return (
@@ -293,7 +320,7 @@ function ConversationList({ className }) {
293
320
  ] }),
294
321
  /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center justify-between gap-2", children: [
295
322
  /* @__PURE__ */ jsx("span", { className: cn("truncate text-xs", unread ? "text-foreground" : "text-muted-foreground"), children: /* @__PURE__ */ jsx(MessagePreview, { text: c.lastMessagePreview }) }),
296
- unread && /* @__PURE__ */ jsx("span", { className: "flex h-[18px] min-w-[18px] shrink-0 items-center justify-center rounded-full bg-destructive px-1.5 text-[10px] font-semibold text-destructive-foreground", children: c.unreadCount > 0 ? c.unreadCount : "\xB7" })
323
+ unread && /* @__PURE__ */ jsx("span", { className: "flex h-[18px] min-w-[18px] shrink-0 items-center justify-center rounded-full bg-destructive px-1.5 text-[10px] font-semibold text-destructive-foreground group-hover:invisible", children: c.unreadCount > 0 ? c.unreadCount : "\xB7" })
297
324
  ] })
298
325
  ] })
299
326
  ]
@@ -311,7 +338,7 @@ function ConversationList({ className }) {
311
338
  e.stopPropagation();
312
339
  void markRead(c.id);
313
340
  },
314
- className: "absolute right-2 top-2 hidden rounded-full p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground group-hover:block",
341
+ className: "absolute bottom-2.5 right-2.5 hidden rounded-full p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground group-hover:block",
315
342
  children: /* @__PURE__ */ jsx(CheckCheck, { className: "h-3.5 w-3.5" })
316
343
  }
317
344
  )
@@ -854,15 +881,15 @@ function buildRows(messages) {
854
881
  const rows = [];
855
882
  let lastDay = "";
856
883
  messages.forEach((m, i) => {
857
- const day = new Date(m.at).toDateString();
858
- if (day !== lastDay) {
859
- rows.push({ kind: "day", id: `day-${day}`, label: dayLabel(m.at) });
860
- lastDay = day;
884
+ const day2 = new Date(m.at).toDateString();
885
+ if (day2 !== lastDay) {
886
+ rows.push({ kind: "day", id: `day-${day2}`, label: dayLabel(m.at) });
887
+ lastDay = day2;
861
888
  }
862
889
  const prev = messages[i - 1];
863
890
  const next = messages[i + 1];
864
- const samePrev = prev && prev.direction === m.direction && new Date(prev.at).toDateString() === day;
865
- const sameNext = next && next.direction === m.direction && new Date(next.at).toDateString() === day;
891
+ const samePrev = prev && prev.direction === m.direction && new Date(prev.at).toDateString() === day2;
892
+ const sameNext = next && next.direction === m.direction && new Date(next.at).toDateString() === day2;
866
893
  rows.push({ kind: "msg", id: m.id, message: m, startsRun: !samePrev, endsRun: !sameNext });
867
894
  });
868
895
  return rows;
@@ -915,36 +942,53 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
915
942
  window.setTimeout(() => el.classList.remove("ring-2", "ring-primary"), 1200);
916
943
  }, []);
917
944
  return /* @__PURE__ */ jsxs("section", { className: cn("flex min-w-0 flex-1 flex-col bg-muted/20", className), children: [
918
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 border-b border-border bg-card px-3 py-2.5 md:px-5", children: [
919
- /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2 md:gap-3", children: [
920
- onBack && /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: cn("-ml-1 shrink-0", !backAlways && "lg:hidden"), onClick: onBack, "aria-label": t("conversations.thread.back"), children: /* @__PURE__ */ jsx(ChevronLeft, { className: "h-5 w-5" }) }),
921
- /* @__PURE__ */ jsx(Avatar, { name: selected.contactName, accent: selected.accent, size: "sm", channel: selected.channel }),
922
- /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
923
- /* @__PURE__ */ jsx("p", { className: "truncate text-sm font-semibold text-foreground", children: selected.contactName }),
924
- !panelOpen && /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
925
- /* @__PURE__ */ jsx(ChannelBadge, { channel: selected.channel }),
926
- /* @__PURE__ */ jsx("span", { className: "truncate", children: selected.contactHandle })
927
- ] })
928
- ] })
929
- ] }),
930
- /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [
931
- /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", onClick: () => setStatus("closed"), "aria-label": "Arquivar", children: [
932
- /* @__PURE__ */ jsx(Archive, { className: "h-3.5 w-3.5 sm:mr-1" }),
933
- " ",
934
- /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: "Arquivar" })
935
- ] }),
936
- /* @__PURE__ */ jsx(
937
- Button,
938
- {
939
- variant: panelOpen ? "secondary" : "ghost",
940
- size: "icon",
941
- onClick: onTogglePanel,
942
- "aria-label": t("conversations.thread.details"),
943
- children: /* @__PURE__ */ jsx(PanelRight, { className: "h-4 w-4" })
945
+ /* @__PURE__ */ jsxs(
946
+ "div",
947
+ {
948
+ role: "button",
949
+ tabIndex: 0,
950
+ "aria-label": t("conversations.thread.details"),
951
+ "aria-expanded": panelOpen,
952
+ onClick: () => {
953
+ if (!panelOpen) onTogglePanel();
954
+ },
955
+ onKeyDown: (e) => {
956
+ if ((e.key === "Enter" || e.key === " ") && e.target === e.currentTarget && !panelOpen) {
957
+ e.preventDefault();
958
+ onTogglePanel();
944
959
  }
945
- )
946
- ] })
947
- ] }),
960
+ },
961
+ className: cn("flex items-center justify-between gap-2 border-b border-border bg-card px-3 py-2.5 md:px-5", !panelOpen && "cursor-pointer hover:bg-muted/40"),
962
+ children: [
963
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2 md:gap-3", children: [
964
+ onBack && /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: cn("-ml-1 shrink-0", !backAlways && "lg:hidden"), onClick: (e) => {
965
+ e.stopPropagation();
966
+ onBack?.();
967
+ }, "aria-label": t("conversations.thread.back"), children: /* @__PURE__ */ jsx(ChevronLeft, { className: "h-5 w-5" }) }),
968
+ /* @__PURE__ */ jsx(Avatar, { name: selected.contactName, accent: selected.accent, size: "sm", channel: selected.channel }),
969
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
970
+ /* @__PURE__ */ jsx("p", { className: "truncate text-sm font-semibold text-foreground", children: selected.contactName }),
971
+ !panelOpen && /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
972
+ /* @__PURE__ */ jsx(ChannelBadge, { channel: selected.channel }),
973
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: selected.contactHandle })
974
+ ] })
975
+ ] })
976
+ ] }),
977
+ /* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-center gap-1.5", onClick: (e) => e.stopPropagation(), onKeyDown: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxs(Dropdown, { children: [
978
+ /* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", "aria-label": t("conversations.thread.more"), children: /* @__PURE__ */ jsx(MoreHorizontal, { className: "h-4 w-4" }) }) }),
979
+ /* @__PURE__ */ jsx(DropdownContent, { align: "end", children: selected.status === "closed" ? /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => setStatus("open"), children: [
980
+ /* @__PURE__ */ jsx(ArchiveRestore, { className: "mr-2 h-3.5 w-3.5" }),
981
+ " ",
982
+ t("conversations.thread.unarchive")
983
+ ] }) : /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => setStatus("closed"), children: [
984
+ /* @__PURE__ */ jsx(Archive, { className: "mr-2 h-3.5 w-3.5" }),
985
+ " ",
986
+ t("conversations.thread.archive")
987
+ ] }) })
988
+ ] }) })
989
+ ]
990
+ }
991
+ ),
948
992
  /* @__PURE__ */ jsxs("div", { ref: threadRef, className: "min-h-0 flex-1 overflow-y-auto px-5 py-4", children: [
949
993
  rows.map((row) => {
950
994
  if (row.kind === "day") {
@@ -1027,156 +1071,260 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
1027
1071
  ] })
1028
1072
  ] });
1029
1073
  }
1030
- var TEMP = {
1031
- hot: { icon: Flame, cls: "bg-destructive-soft text-destructive-soft-foreground", label: "Quente" },
1032
- warm: { icon: Sun, cls: "bg-warning-soft text-warning-soft-foreground", label: "Morno" },
1033
- cold: { icon: Snowflake, cls: "bg-info-soft text-info-soft-foreground", label: "Frio" }
1034
- };
1035
- function LeadCard({ personId, handle }) {
1036
- const [lead, setLead] = React9__default.useState(void 0);
1074
+ var str = (v) => typeof v === "string" && v.trim() ? v.trim() : null;
1075
+ function declaredCompany(meta) {
1076
+ const f = meta.fields ?? {};
1077
+ const name = str(f.trade_name_declared) ?? str(meta.credential_company) ?? str(meta.company) ?? str(f.legal_name_declared);
1078
+ if (!name) return null;
1079
+ return {
1080
+ id: "",
1081
+ name,
1082
+ legalName: str(f.legal_name_declared),
1083
+ document: str(f.cnpj_declared)?.replace(/\D/g, "") ?? null,
1084
+ role: str(f.role),
1085
+ phone: null,
1086
+ email: null,
1087
+ website: null,
1088
+ address: null,
1089
+ city: null,
1090
+ state: null,
1091
+ size: null,
1092
+ openedAt: null,
1093
+ declaredOnly: true
1094
+ };
1095
+ }
1096
+ function useContactProfile(personId, handle) {
1097
+ const [profile, setProfile] = React9__default.useState(void 0);
1037
1098
  React9__default.useEffect(() => {
1038
1099
  let alive = true;
1100
+ setProfile(void 0);
1039
1101
  const sb = getSupabaseClientOptional();
1040
1102
  const tenantId = getActiveTenantId();
1041
1103
  if (!sb || !tenantId || !personId && !handle) {
1042
- setLead(null);
1104
+ setProfile(null);
1043
1105
  return;
1044
1106
  }
1045
1107
  (async () => {
1046
1108
  try {
1047
- let q = sb.from("people").select("id, name, metadata, phone").eq("tenant_id", tenantId).eq("kind", "lead").limit(1);
1109
+ let q = sb.from("people").select("id, kind, name, email, phone, document_number, city, state, tags, metadata").eq("tenant_id", tenantId).limit(1);
1048
1110
  q = personId ? q.eq("id", personId) : q.like("phone", `%${String(handle).replace(/\D/g, "").slice(-8)}`);
1049
- const { data } = await q.maybeSingle();
1111
+ const { data: p } = await q.maybeSingle();
1050
1112
  if (!alive) return;
1051
- if (!data) {
1052
- setLead(null);
1113
+ if (!p) {
1114
+ setProfile(null);
1053
1115
  return;
1054
1116
  }
1055
- const meta = data.metadata ?? {};
1056
- let score = null;
1057
- try {
1058
- const { data: s } = await sb.from("v_crm_lead_score").select("temperature, fit_score, interest_score, reasons").eq("lead_id", data.id).maybeSingle();
1059
- score = s;
1060
- } catch {
1061
- }
1062
- setLead({
1063
- id: data.id,
1064
- name: data.name,
1065
- company: meta.company ?? null,
1066
- status: meta.status ?? null,
1067
- sourceName: meta.sourceName ?? null,
1117
+ const meta = p.metadata ?? {};
1118
+ const [score, link] = await Promise.all([
1119
+ sb.from("v_crm_lead_score").select("temperature, interest_score, reasons").eq("lead_id", p.id).maybeSingle().then((r) => r.data).catch(() => null),
1120
+ sb.from("plg_crm_company_people").select("role, is_primary, company:plg_crm_companies(id, name, legal_name, document_number, phone, email, website, address, city, state, metadata)").eq("person_id", p.id).order("is_primary", { ascending: false }).limit(1).maybeSingle().then((r) => r.data).catch(() => null)
1121
+ ]);
1122
+ if (!alive) return;
1123
+ const c = link?.company;
1124
+ const receita = c?.metadata?.receita ?? {};
1125
+ const company = c ? {
1126
+ id: c.id,
1127
+ name: c.name,
1128
+ legalName: str(c.legal_name),
1129
+ document: str(c.document_number),
1130
+ role: str(link.role),
1131
+ phone: str(c.phone),
1132
+ email: str(c.email),
1133
+ website: str(c.website),
1134
+ address: str(c.address),
1135
+ city: str(c.city),
1136
+ state: str(c.state),
1137
+ size: str(receita.porte),
1138
+ openedAt: str(receita.abertura)
1139
+ } : declaredCompany(meta);
1140
+ setProfile({
1141
+ id: p.id,
1142
+ kind: p.kind,
1143
+ name: p.name,
1144
+ phone: str(p.phone),
1145
+ email: str(p.email),
1146
+ document: str(p.document_number),
1147
+ city: str(p.city),
1148
+ state: str(p.state),
1149
+ tags: Array.isArray(p.tags) ? p.tags : [],
1150
+ status: str(meta.status),
1151
+ sourceName: str(meta.sourceName),
1068
1152
  temperature: score?.temperature ?? null,
1069
- fitScore: score?.fit_score ?? null,
1070
1153
  interestScore: score?.interest_score ?? null,
1071
- reasons: Array.isArray(score?.reasons) ? score.reasons : []
1154
+ reasons: Array.isArray(score?.reasons) ? score.reasons : [],
1155
+ fields: meta.fields ?? {},
1156
+ touchpoints: Array.isArray(meta.touchpoints) ? meta.touchpoints.filter((x) => x && x.detail).map((x) => ({ at: String(x.at ?? ""), kind: String(x.kind ?? ""), detail: String(x.detail) })) : [],
1157
+ company
1072
1158
  });
1073
1159
  } catch {
1074
- if (alive) setLead(null);
1160
+ if (alive) setProfile(null);
1075
1161
  }
1076
1162
  })();
1077
1163
  return () => {
1078
1164
  alive = false;
1079
1165
  };
1080
1166
  }, [personId, handle]);
1081
- if (lead === void 0) return /* @__PURE__ */ jsx("div", { className: "px-4 py-3 text-xs text-muted-foreground", children: "carregando\u2026" });
1082
- if (!lead) {
1083
- return /* @__PURE__ */ jsx("div", { className: "border-t border-border px-4 py-3", children: /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Este contato ainda n\xE3o \xE9 um lead cadastrado." }) });
1084
- }
1085
- const t = lead.temperature ? TEMP[lead.temperature] : null;
1086
- const Icon = t?.icon;
1087
- return /* @__PURE__ */ jsxs("div", { className: "border-t border-border px-4 py-3", children: [
1088
- /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-2", children: [
1089
- /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
1090
- /* @__PURE__ */ jsx("p", { className: "truncate text-sm font-semibold", children: lead.name }),
1091
- lead.company && /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1 truncate text-xs text-muted-foreground", children: [
1092
- /* @__PURE__ */ jsx(Building2, { className: "h-3 w-3 shrink-0" }),
1093
- " ",
1094
- lead.company
1095
- ] })
1096
- ] }),
1097
- /* @__PURE__ */ jsxs(
1098
- "a",
1099
- {
1100
- href: appHref(`/sales/leads/${lead.id}`),
1101
- className: "inline-flex shrink-0 items-center gap-1 rounded-button border bg-card px-2 py-1 text-[11px] font-medium hover:bg-muted",
1102
- children: [
1103
- "Abrir lead ",
1104
- /* @__PURE__ */ jsx(ExternalLink, { className: "h-3 w-3" })
1105
- ]
1106
- }
1107
- )
1108
- ] }),
1109
- /* @__PURE__ */ jsxs("div", { className: "mt-2 flex flex-wrap items-center gap-1.5", children: [
1110
- t && Icon && /* @__PURE__ */ jsxs("span", { className: `inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${t.cls}`, children: [
1111
- /* @__PURE__ */ jsx(Icon, { className: "h-3 w-3" }),
1112
- " ",
1113
- t.label,
1114
- lead.interestScore != null && /* @__PURE__ */ jsx("span", { className: "tabular-nums opacity-70", children: lead.interestScore })
1115
- ] }),
1116
- lead.status && /* @__PURE__ */ jsx("span", { className: "rounded-full bg-muted px-2 py-0.5 text-[10px] capitalize text-muted-foreground", children: lead.status }),
1117
- lead.sourceName && /* @__PURE__ */ jsx("span", { className: "rounded-full bg-muted px-2 py-0.5 text-[10px] text-muted-foreground", children: lead.sourceName })
1167
+ return profile;
1168
+ }
1169
+ var PROFILE_FIELDS = [
1170
+ ["role", "conversations.profile.role"],
1171
+ ["buying_role", "conversations.profile.buyingRole"],
1172
+ ["venue_type", "conversations.profile.venueType"],
1173
+ ["revenue", "conversations.profile.revenue"],
1174
+ ["challenges", "conversations.profile.challenges"],
1175
+ ["goals", "conversations.profile.goals"]
1176
+ ];
1177
+ function fieldText(value) {
1178
+ if (value === null || value === void 0 || value === "") return null;
1179
+ if (Array.isArray(value)) return value.length ? value.join(", ") : null;
1180
+ if (typeof value === "boolean") return value ? "Sim" : "N\xE3o";
1181
+ if (typeof value === "object") return null;
1182
+ return String(value);
1183
+ }
1184
+ function formatDocument(doc) {
1185
+ const d = (doc ?? "").replace(/\D/g, "");
1186
+ if (d.length === 14) return `${d.slice(0, 2)}.${d.slice(2, 5)}.${d.slice(5, 8)}/${d.slice(8, 12)}-${d.slice(12)}`;
1187
+ if (d.length === 11) return `${d.slice(0, 3)}.${d.slice(3, 6)}.${d.slice(6, 9)}-${d.slice(9)}`;
1188
+ return doc;
1189
+ }
1190
+ var LEAD_STATUS = {
1191
+ new: { labelKey: "conversations.leadStatus.new", dot: "#3B82F6" },
1192
+ contacted: { labelKey: "conversations.leadStatus.contacted", dot: "#8B5CF6" },
1193
+ qualified: { labelKey: "conversations.leadStatus.qualified", dot: "#10B981" },
1194
+ unqualified: { labelKey: "conversations.leadStatus.unqualified", dot: "#94A3B8" },
1195
+ converted: { labelKey: "conversations.leadStatus.converted", dot: "#F59E0B" },
1196
+ lost: { labelKey: "conversations.leadStatus.lost", dot: "#EF4444" }
1197
+ };
1198
+ var TEMP = {
1199
+ hot: { icon: Flame, cls: "bg-destructive-soft text-destructive-soft-foreground", labelKey: "conversations.temperature.hot" },
1200
+ warm: { icon: Sun, cls: "bg-warning-soft text-warning-soft-foreground", labelKey: "conversations.temperature.warm" },
1201
+ cold: { icon: Snowflake, cls: "bg-info-soft text-info-soft-foreground", labelKey: "conversations.temperature.cold" }
1202
+ };
1203
+ function Section({ title, action, children }) {
1204
+ return /* @__PURE__ */ jsxs("section", { className: "px-4 pt-4", children: [
1205
+ /* @__PURE__ */ jsxs("div", { className: "mb-1 flex items-center justify-between gap-2", children: [
1206
+ /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground", children: title }),
1207
+ action
1118
1208
  ] }),
1119
- lead.reasons.length > 0 && /* @__PURE__ */ jsx("ul", { className: "mt-2 space-y-0.5", children: lead.reasons.slice(0, 4).map((r, i) => /* @__PURE__ */ jsxs("li", { className: "flex gap-1.5 text-[11px] text-muted-foreground", children: [
1120
- /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/40", children: "\u2022" }),
1121
- /* @__PURE__ */ jsx("span", { children: r })
1122
- ] }, i)) })
1209
+ /* @__PURE__ */ jsx("div", { className: "rounded-card border bg-card shadow-sm", children })
1123
1210
  ] });
1124
1211
  }
1125
- function Section({ icon: Icon, title, children }) {
1126
- return /* @__PURE__ */ jsxs("div", { className: "border-t border-border px-4 py-3", children: [
1127
- /* @__PURE__ */ jsxs("p", { className: "mb-1.5 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground", children: [
1128
- /* @__PURE__ */ jsx(Icon, { className: "h-3 w-3" }),
1129
- " ",
1130
- title
1131
- ] }),
1132
- children
1212
+ function Rows({ rows }) {
1213
+ const shown = rows.filter(([, v]) => v !== null && v !== void 0 && v !== "");
1214
+ if (!shown.length) return null;
1215
+ return /* @__PURE__ */ jsx("dl", { className: "divide-y", children: shown.map(([label, value]) => /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[6.5rem_minmax(0,1fr)] gap-x-3 px-3 py-2", children: [
1216
+ /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium text-muted-foreground", children: label }),
1217
+ /* @__PURE__ */ jsx("dd", { className: "min-w-0 break-words text-xs text-foreground", children: value })
1218
+ ] }, label)) });
1219
+ }
1220
+ function OpenLink({ href, label }) {
1221
+ return /* @__PURE__ */ jsxs("a", { href: appHref(href), className: "inline-flex items-center gap-1 text-xs font-medium text-primary hover:underline", children: [
1222
+ label,
1223
+ " ",
1224
+ /* @__PURE__ */ jsx(ExternalLink, { className: "h-3 w-3" })
1133
1225
  ] });
1134
1226
  }
1227
+ function place(city, state) {
1228
+ return [city, state].filter(Boolean).join(" / ") || null;
1229
+ }
1230
+ function day(iso) {
1231
+ const d = new Date(iso.length === 10 ? `${iso}T12:00:00` : iso);
1232
+ return Number.isNaN(d.getTime()) ? iso : d.toLocaleDateString("pt-BR");
1233
+ }
1135
1234
  function ContactPanel({ contact, onClose, className }) {
1136
1235
  const t = useTranslation();
1137
- return /* @__PURE__ */ jsxs("aside", { className: cn("flex shrink-0 flex-col overflow-y-auto border-l border-border bg-card", className), children: [
1138
- onClose && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b border-border px-3 py-2 xl:hidden", children: [
1236
+ const profile = useContactProfile(contact.contactPersonId, contact.contactHandle);
1237
+ return /* @__PURE__ */ jsxs("aside", { className: cn("flex shrink-0 flex-col overflow-y-auto border-l border-border bg-muted/20 pb-4", className), children: [
1238
+ /* @__PURE__ */ jsxs("div", { className: "sticky top-0 z-10 flex items-center justify-between border-b border-border bg-card px-3 py-2", children: [
1139
1239
  /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold text-foreground", children: t("conversations.contact.details") }),
1140
- /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", onClick: onClose, "aria-label": t("conversations.contact.closeDetails"), children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" }) })
1240
+ onClose && /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", onClick: onClose, "aria-label": t("conversations.contact.closeDetails"), children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" }) })
1141
1241
  ] }),
1142
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 px-4 py-5 text-center", children: [
1242
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 bg-card px-4 py-5 text-center", children: [
1143
1243
  /* @__PURE__ */ jsx(Avatar, { name: contact.contactName, accent: contact.accent, size: "lg", channel: contact.channel }),
1144
- /* @__PURE__ */ jsxs("div", { children: [
1145
- /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-foreground", children: contact.contactName }),
1244
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
1245
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-foreground", children: profile?.name ?? contact.contactName }),
1246
+ profile?.company && /* @__PURE__ */ jsxs("p", { className: "mt-0.5 flex items-center justify-center gap-1 text-xs text-muted-foreground", children: [
1247
+ /* @__PURE__ */ jsx(Building2, { className: "h-3 w-3 shrink-0" }),
1248
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: [profile.company.role, profile.company.name].filter(Boolean).join(" \xB7 ") })
1249
+ ] }),
1146
1250
  /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: contact.contactHandle })
1147
1251
  ] }),
1148
1252
  /* @__PURE__ */ jsx(ChannelBadge, { channel: contact.channel })
1149
1253
  ] }),
1150
- /* @__PURE__ */ jsx(LeadCard, { personId: contact.contactPersonId, handle: contact.contactHandle }),
1151
- /* @__PURE__ */ jsx(Section, { icon: User, title: t("conversations.contact.details"), children: /* @__PURE__ */ jsxs("dl", { className: "space-y-1.5 text-sm", children: [
1152
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
1153
- /* @__PURE__ */ jsx("dt", { className: "text-muted-foreground", children: t("conversations.contact.channel") }),
1154
- /* @__PURE__ */ jsx("dd", { className: "text-foreground", children: CHANNEL_LABELS[contact.channel] })
1155
- ] }),
1156
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
1157
- /* @__PURE__ */ jsx("dt", { className: "text-muted-foreground", children: t("conversations.contact.status") }),
1158
- /* @__PURE__ */ jsx("dd", { className: "text-foreground", children: t(`conversations.status.${contact.status}`) })
1159
- ] }),
1160
- contact.assignedTo && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
1161
- /* @__PURE__ */ jsx("dt", { className: "text-muted-foreground", children: t("conversations.contact.assignedTo") }),
1162
- /* @__PURE__ */ jsx("dd", { className: "text-foreground", children: contact.assignedTo })
1163
- ] }),
1164
- contact.leadOwnerName && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
1165
- /* @__PURE__ */ jsx("dt", { className: "text-muted-foreground", children: t("conversations.contact.leadOwner") }),
1166
- /* @__PURE__ */ jsx("dd", { className: "font-medium text-foreground", children: contact.leadOwnerName })
1167
- ] }),
1168
- contact.location && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
1169
- /* @__PURE__ */ jsxs("dt", { className: "flex items-center gap-1 text-muted-foreground", children: [
1170
- /* @__PURE__ */ jsx(MapPin, { className: "h-3 w-3" }),
1254
+ profile === void 0 && /* @__PURE__ */ jsx("p", { className: "px-4 pt-4 text-xs text-muted-foreground", children: t("conversations.profile.loading") }),
1255
+ profile === null && /* @__PURE__ */ jsx("p", { className: "px-4 pt-4 text-xs text-muted-foreground", children: t("conversations.profile.notInCrm") }),
1256
+ profile && /* @__PURE__ */ jsx(ProfileSections, { profile }),
1257
+ /* @__PURE__ */ jsx(Section, { title: t("conversations.profile.conversation"), children: /* @__PURE__ */ jsx(Rows, { rows: [
1258
+ [t("conversations.contact.channel"), CHANNEL_LABELS[contact.channel]],
1259
+ [t("conversations.contact.status"), t(`conversations.status.${contact.status}`)],
1260
+ [t("conversations.contact.assignedTo"), contact.assignedTo],
1261
+ // Who answers this conversation may not be who follows the lead up:
1262
+ // side by side on purpose — when they differ, that is information.
1263
+ [t("conversations.contact.leadOwner"), contact.leadOwnerName],
1264
+ [t("conversations.contact.location"), contact.location],
1265
+ [t("conversations.contact.note"), contact.note]
1266
+ ] }) })
1267
+ ] });
1268
+ }
1269
+ function ProfileSections({ profile }) {
1270
+ const t = useTranslation();
1271
+ const status = profile.status ? LEAD_STATUS[profile.status] : null;
1272
+ const temp = profile.temperature ? TEMP[profile.temperature] : null;
1273
+ const TempIcon = temp?.icon;
1274
+ const c = profile.company;
1275
+ const isLead = profile.kind === "lead";
1276
+ const fields = PROFILE_FIELDS.map(([key, labelKey]) => [t(labelKey), fieldText(profile.fields[key])]);
1277
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1278
+ isLead && /* @__PURE__ */ jsxs(Section, { title: t("conversations.profile.lead"), action: /* @__PURE__ */ jsx(OpenLink, { href: `/sales/leads/${profile.id}`, label: t("conversations.profile.openLead") }), children: [
1279
+ /* @__PURE__ */ jsx(Rows, { rows: [
1280
+ [t("conversations.profile.status"), status ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5", children: [
1281
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full", style: { backgroundColor: status.dot } }),
1282
+ t(status.labelKey)
1283
+ ] }) : profile.status],
1284
+ [t("conversations.profile.temperature"), temp && TempIcon ? /* @__PURE__ */ jsxs("span", { className: cn("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-medium", temp.cls), children: [
1285
+ /* @__PURE__ */ jsx(TempIcon, { className: "h-3 w-3" }),
1171
1286
  " ",
1172
- t("conversations.contact.location")
1173
- ] }),
1174
- /* @__PURE__ */ jsx("dd", { className: "text-foreground", children: contact.location })
1175
- ] })
1287
+ t(temp.labelKey),
1288
+ profile.interestScore != null && /* @__PURE__ */ jsx("span", { className: "tabular-nums opacity-70", children: profile.interestScore })
1289
+ ] }) : null],
1290
+ [t("conversations.profile.source"), profile.sourceName]
1291
+ ] }),
1292
+ profile.reasons.length > 0 && /* @__PURE__ */ jsx("ul", { className: "space-y-0.5 border-t px-3 py-2", children: profile.reasons.slice(0, 5).map((r, i) => /* @__PURE__ */ jsxs("li", { className: "flex gap-1.5 text-[11px] text-muted-foreground", children: [
1293
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/40", children: "\u2022" }),
1294
+ /* @__PURE__ */ jsx("span", { children: r })
1295
+ ] }, i)) })
1296
+ ] }),
1297
+ c && /* @__PURE__ */ jsx(
1298
+ Section,
1299
+ {
1300
+ title: t("conversations.profile.company"),
1301
+ action: c.declaredOnly ? /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: t("conversations.profile.declared") }) : /* @__PURE__ */ jsx(OpenLink, { href: `/sales/companies/${c.id}`, label: t("conversations.profile.openCompany") }),
1302
+ children: /* @__PURE__ */ jsx(Rows, { rows: [
1303
+ [t("conversations.profile.tradeName"), c.name],
1304
+ [t("conversations.profile.legalName"), c.legalName !== c.name ? c.legalName : null],
1305
+ [t("conversations.profile.cnpj"), c.document ? /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: formatDocument(c.document) }) : null],
1306
+ [t("conversations.profile.role"), c.role],
1307
+ [t("conversations.profile.size"), c.size],
1308
+ [t("conversations.profile.since"), c.openedAt ? day(c.openedAt) : null],
1309
+ [t("conversations.profile.phone"), c.phone],
1310
+ [t("conversations.profile.email"), c.email],
1311
+ [t("conversations.profile.website"), c.website],
1312
+ [t("conversations.profile.address"), [c.address, place(c.city, c.state)].filter(Boolean).join(" \u2014 ") || null]
1313
+ ] })
1314
+ }
1315
+ ),
1316
+ /* @__PURE__ */ jsx(Section, { title: t("conversations.profile.person"), children: /* @__PURE__ */ jsx(Rows, { rows: [
1317
+ [t("conversations.profile.phone"), profile.phone],
1318
+ [t("conversations.profile.email"), profile.email],
1319
+ [t("conversations.profile.cpf"), profile.document ? /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: formatDocument(profile.document) }) : null],
1320
+ [t("conversations.profile.city"), place(profile.city, profile.state)],
1321
+ ...fields.filter(([label]) => label !== t("conversations.profile.role") || !c?.role)
1176
1322
  ] }) }),
1177
- contact.tags.length > 0 && /* @__PURE__ */ jsx(Section, { icon: Tag, title: t("conversations.contact.tags"), children: /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: contact.tags.map((tag) => /* @__PURE__ */ jsx("span", { className: "rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-foreground", children: tag }, tag)) }) }),
1178
- contact.note && /* @__PURE__ */ jsx(Section, { icon: StickyNote, title: t("conversations.contact.note"), children: /* @__PURE__ */ jsx("p", { className: "text-sm text-foreground", children: contact.note }) }),
1179
- /* @__PURE__ */ jsx(Section, { icon: Link2, title: t("conversations.contact.linkedRecords"), children: /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("conversations.contact.noLinkedRecords") }) })
1323
+ profile.tags.length > 0 && /* @__PURE__ */ jsx(Section, { title: t("conversations.contact.tags"), children: /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5 px-3 py-2", children: profile.tags.map((tag) => /* @__PURE__ */ jsx("span", { className: "rounded-full border border-border bg-card px-2 py-0.5 text-[11px] text-foreground/80", children: tag }, tag)) }) }),
1324
+ profile.touchpoints.length > 0 && /* @__PURE__ */ jsx(Section, { title: t("conversations.profile.history"), children: /* @__PURE__ */ jsx("ol", { className: "divide-y", children: profile.touchpoints.map((tp, i) => /* @__PURE__ */ jsxs("li", { className: "grid grid-cols-[6.5rem_minmax(0,1fr)] gap-x-3 px-3 py-2 text-xs", children: [
1325
+ /* @__PURE__ */ jsx("span", { className: "tabular-nums text-muted-foreground", children: tp.at ? day(tp.at) : "\u2014" }),
1326
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 break-words text-foreground", children: tp.detail })
1327
+ ] }, i)) }) })
1180
1328
  ] });
1181
1329
  }
1182
1330
  var CHANNELS = ["whatsapp", "sms", "instagram", "email", "webchat"];
@@ -1429,10 +1577,16 @@ function requestedContact() {
1429
1577
  return null;
1430
1578
  }
1431
1579
  }
1580
+ function conversationIdFromPath(path) {
1581
+ const m = /^\/conversations\/([^/?#]+)/.exec(path);
1582
+ return m ? decodeURIComponent(m[1]) : null;
1583
+ }
1432
1584
  function ConversationsPage({ store, config }) {
1433
1585
  React9__default.useEffect(() => {
1434
1586
  const wanted = requestedContact();
1435
1587
  if (!wanted) {
1588
+ const fromPath = conversationIdFromPath(currentAppPath());
1589
+ if (fromPath) store.setState({ selectedId: fromPath });
1436
1590
  void store.getState().load();
1437
1591
  return;
1438
1592
  }
@@ -1446,9 +1600,30 @@ function ConversationsPage({ store, config }) {
1446
1600
  } catch {
1447
1601
  }
1448
1602
  }, []);
1603
+ React9__default.useEffect(() => {
1604
+ const write = (id) => {
1605
+ const path = currentAppPath();
1606
+ if (!path.startsWith("/conversations")) return;
1607
+ if (path.includes("?")) return;
1608
+ if (conversationIdFromPath(path) === id) return;
1609
+ replaceApp(id ? `/conversations/${encodeURIComponent(id)}` : "/conversations");
1610
+ };
1611
+ write(store.getState().selectedId);
1612
+ const unsubscribe = store.subscribe((state, previous) => {
1613
+ if (state.selectedId !== previous.selectedId) write(state.selectedId);
1614
+ });
1615
+ const off = onAppPathChange((path) => {
1616
+ const id = conversationIdFromPath(path || "/");
1617
+ if (id && id !== store.getState().selectedId) void store.getState().select(id);
1618
+ });
1619
+ return () => {
1620
+ unsubscribe();
1621
+ off();
1622
+ };
1623
+ }, [store]);
1449
1624
  return /* @__PURE__ */ jsx(ConversationsContextProvider, { store, config, children: /* @__PURE__ */ jsx(InboxView, {}) });
1450
1625
  }
1451
1626
 
1452
- export { ConversationsPage };
1453
- //# sourceMappingURL=ConversationsPage-7W7LDH2H.js.map
1454
- //# sourceMappingURL=ConversationsPage-7W7LDH2H.js.map
1627
+ export { ConversationsPage, conversationIdFromPath };
1628
+ //# sourceMappingURL=ConversationsPage-RYEND3MG.js.map
1629
+ //# sourceMappingURL=ConversationsPage-RYEND3MG.js.map