@hanzo/ui 8.0.13 → 8.0.14

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.
@@ -0,0 +1,1229 @@
1
+ 'use client';
2
+ import { createContext, useContext, useSyncExternalStore, useRef, useEffect, useMemo, useState, useCallback } from 'react';
3
+ import { Card, XStack, Text, Button, YStack, Label, Input, TextArea, Switch, Slider, ScrollView } from '@hanzo/gui';
4
+ import { TriangleAlert, CreditCard, ChevronsUpDown, ChevronUp, ChevronDown, Check, ExternalLink, ArrowRight, X, Calendar, AlertTriangle, CheckCircle2, List, Plus, Link2, RefreshCw, Share2, Send, Pencil, Trash2 } from '@hanzogui/lucide-icons-2';
5
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
+
7
+ // src/product/social/api.ts
8
+ var enc = encodeURIComponent;
9
+ var str = (v) => typeof v === "string" ? v : v == null ? "" : String(v);
10
+ var num = (v) => {
11
+ if (typeof v === "number" && Number.isFinite(v)) return v;
12
+ if (typeof v === "string" && v.trim() !== "" && Number.isFinite(Number(v))) return Number(v);
13
+ return 0;
14
+ };
15
+ var strs = (v) => Array.isArray(v) ? v.filter((x) => typeof x === "string") : [];
16
+ var asRecord = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
17
+ var rows = (payload) => {
18
+ if (Array.isArray(payload)) return payload.filter((x) => x && typeof x === "object");
19
+ if (payload && typeof payload === "object") {
20
+ for (const k of ["data", "items", "rows"]) {
21
+ const v = payload[k];
22
+ if (Array.isArray(v)) return v.filter((x) => x && typeof x === "object");
23
+ }
24
+ }
25
+ return [];
26
+ };
27
+ var PROVIDERS = ["x", "facebook", "instagram", "linkedin", "tiktok", "youtube", "threads"];
28
+ var ACCOUNT_STATUSES = ["connected", "disconnected", "error"];
29
+ var POST_STATUSES = ["draft", "scheduled", "published", "failed"];
30
+ function normalizeAccount(raw) {
31
+ const r = asRecord(raw);
32
+ return {
33
+ id: str(r.id),
34
+ provider: str(r.provider) || "x",
35
+ handle: str(r.handle),
36
+ status: str(r.status) || "connected",
37
+ createdAt: num(r.createdAt),
38
+ updatedAt: num(r.updatedAt)
39
+ };
40
+ }
41
+ function normalizePost(raw) {
42
+ const r = asRecord(raw);
43
+ return {
44
+ id: str(r.id),
45
+ content: str(r.content),
46
+ channel: str(r.channel) || "x",
47
+ status: str(r.status) || "draft",
48
+ scheduleAt: num(r.scheduleAt),
49
+ media: strs(r.media),
50
+ accountId: str(r.accountId) || void 0,
51
+ externalId: str(r.externalId) || void 0,
52
+ error: str(r.error) || void 0,
53
+ createdAt: num(r.createdAt),
54
+ updatedAt: num(r.updatedAt)
55
+ };
56
+ }
57
+ function normalizeSummary(raw) {
58
+ const r = asRecord(raw);
59
+ return { posts: num(r.posts), scheduled: num(r.scheduled), published: num(r.published), accounts: num(r.accounts) };
60
+ }
61
+ function normalizeProviderCapability(raw) {
62
+ const r = asRecord(raw);
63
+ return {
64
+ provider: str(r.provider),
65
+ credentialsConfigured: Boolean(r.credentialsConfigured),
66
+ missingCredentials: strs(r.missingCredentials)
67
+ };
68
+ }
69
+ var normalizeAccounts = (p) => rows(p).map(normalizeAccount).filter((a) => a.id);
70
+ var normalizePosts = (p) => rows(p).map(normalizePost).filter((x) => x.id);
71
+ var normalizeProviders = (p) => rows(p).map(normalizeProviderCapability).filter((c) => c.provider);
72
+ function createSocialApi(rest) {
73
+ return {
74
+ summary: () => rest.get("summary").then(normalizeSummary),
75
+ /** Publish-readiness per network (+ the exact missing OAuth-app credentials). */
76
+ providers: () => rest.get("providers").then(normalizeProviders),
77
+ accounts: {
78
+ list: (provider) => rest.get(`accounts${provider ? `?provider=${enc(provider)}` : ""}`).then(normalizeAccounts),
79
+ get: (id) => rest.get(`accounts/${enc(id)}`).then(normalizeAccount),
80
+ create: (body) => rest.post("accounts", body).then(normalizeAccount),
81
+ update: (id, body) => rest.put(`accounts/${enc(id)}`, body).then(normalizeAccount),
82
+ remove: (id) => rest.del(`accounts/${enc(id)}`)
83
+ },
84
+ posts: {
85
+ list: (status) => rest.get(`posts${status ? `?status=${enc(status)}` : ""}`).then(normalizePosts),
86
+ get: (id) => rest.get(`posts/${enc(id)}`).then(normalizePost),
87
+ create: (body) => rest.post("posts", body).then(normalizePost),
88
+ update: (id, body) => rest.put(`posts/${enc(id)}`, body).then(normalizePost),
89
+ remove: (id) => rest.del(`posts/${enc(id)}`),
90
+ /** Publish a post NOW to its channel's connected accounts. */
91
+ publish: (id) => rest.post(`posts/${enc(id)}/publish`).then(normalizePost)
92
+ }
93
+ };
94
+ }
95
+ var HostCtx = createContext({});
96
+ var HostProvider = ({ actions, children }) => /* @__PURE__ */ jsx(HostCtx.Provider, { value: actions, children });
97
+ var useHost = () => useContext(HostCtx);
98
+ function classifyBackend(e) {
99
+ const status = typeof e?.status === "number" ? e.status : 0;
100
+ const message = e instanceof Error ? e.message : String(e);
101
+ if (status === 503) return { kind: "not-initialized", message };
102
+ if (status === 404 || status === 405) return { kind: "unavailable", message };
103
+ if (status === 501) return { kind: "not-implemented", message };
104
+ if (status === 402) return { kind: "billing", message };
105
+ if (status === 401) return { kind: "signin", message };
106
+ if (status === 403) return { kind: "access", message };
107
+ return { kind: "error", message };
108
+ }
109
+ function classifyRead(e) {
110
+ const s = classifyBackend(e);
111
+ return s.kind === "billing" ? null : s;
112
+ }
113
+ var TITLES = {
114
+ "not-initialized": "Backend not initialized",
115
+ unavailable: "Not available on this deployment yet",
116
+ "not-implemented": "Not yet available",
117
+ access: "Not enabled for your account",
118
+ signin: "Your session expired",
119
+ billing: "Add credits to continue",
120
+ error: "Could not reach the backend"
121
+ };
122
+ var BODIES = {
123
+ "not-initialized": "The /v1 route is mounted but its runtime (or the console API key it proxies to) is not configured on this deployment yet. Real data appears here once it is \u2014 no placeholder data is shown.",
124
+ unavailable: "This endpoint is not mounted at the gateway on this host yet. The view lights up automatically once the route is live.",
125
+ // 501 — a real, planned capability whose body ships in a later phase.
126
+ "not-implemented": "This capability is planned but not wired yet. The backend answers honestly rather than pretending it worked \u2014 nothing here is fabricated, and the view lights up automatically once it ships.",
127
+ // 403 for a SIGNED-IN user — never "sign in".
128
+ access: "You're signed in, but this isn't enabled for your organization on this deployment, or it's an admin-only surface. It appears here automatically once your account has access \u2014 nothing is fabricated.",
129
+ // 401 — the session itself lapsed; re-auth returns to this exact page.
130
+ signin: "Your session has expired or isn\u2019t recognized here. Sign in again to continue where you left off.",
131
+ // Empty → the card shows the backend's own message (the honest "Insufficient
132
+ // balance. Please add credits…" from the gateway billing gate).
133
+ billing: "",
134
+ error: ""
135
+ };
136
+ function BackendStateCard({
137
+ state,
138
+ onRetry,
139
+ hint
140
+ }) {
141
+ const { signIn, addCredits } = useHost();
142
+ return /* @__PURE__ */ jsxs(Card, { borderWidth: 1, borderColor: "$borderColor", p: "$4", gap: "$2", maxWidth: 640, children: [
143
+ /* @__PURE__ */ jsxs(XStack, { gap: "$2", items: "center", children: [
144
+ /* @__PURE__ */ jsx(TriangleAlert, { size: 16 }),
145
+ /* @__PURE__ */ jsx(Text, { fontSize: "$4", fontWeight: "700", children: TITLES[state.kind] })
146
+ ] }),
147
+ /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color11", children: BODIES[state.kind] || state.message }),
148
+ hint ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color10", children: hint }) : null,
149
+ state.kind === "signin" && signIn ? /* @__PURE__ */ jsx(Button, { size: "$2", theme: "light", self: "flex-start", onPress: signIn, children: "Sign in again" }) : state.kind === "billing" && addCredits ? (
150
+ // 402 — the org has no funded balance. Offer a top-up CTA (and keep Retry so
151
+ // a returning, funded caller can reload in place).
152
+ /* @__PURE__ */ jsxs(XStack, { gap: "$2", items: "center", flexWrap: "wrap", children: [
153
+ /* @__PURE__ */ jsx(Button, { size: "$2", theme: "light", self: "flex-start", icon: /* @__PURE__ */ jsx(CreditCard, { size: 14 }), onPress: addCredits, children: "Add credits" }),
154
+ onRetry ? /* @__PURE__ */ jsx(Button, { size: "$2", self: "flex-start", onPress: onRetry, children: "Retry" }) : null
155
+ ] })
156
+ ) : onRetry ? /* @__PURE__ */ jsx(Button, { size: "$2", self: "flex-start", onPress: onRetry, children: "Retry" }) : null
157
+ ] });
158
+ }
159
+ function SkeletonRows({ columns, count = 6 }) {
160
+ return /* @__PURE__ */ jsx(YStack, { children: Array.from({ length: count }).map((_, r) => /* @__PURE__ */ jsx(XStack, { py: "$2.5", px: "$3", gap: "$3", borderTopWidth: 1, borderColor: "$borderColor", items: "center", children: columns.map((c, i) => /* @__PURE__ */ jsx(YStack, { width: c.width, flex: c.width ? void 0 : 1, minW: c.width ? void 0 : FLEX_MIN_COL_W, items: c.align === "right" ? "flex-end" : "flex-start", children: /* @__PURE__ */ jsx(
161
+ "div",
162
+ {
163
+ className: "hz-skeleton",
164
+ style: { height: 12, borderRadius: 6, width: `${[62, 40, 54, 34, 48][(i + r) % 5]}%` },
165
+ "aria-hidden": true
166
+ }
167
+ ) }, c.key)) }, r)) });
168
+ }
169
+ function DataTable({
170
+ columns,
171
+ rows: rows2,
172
+ loading,
173
+ empty = "Nothing here yet.",
174
+ rowKey,
175
+ onRowPress,
176
+ isRowExpanded,
177
+ renderExpanded,
178
+ sort,
179
+ onSortChange
180
+ }) {
181
+ const minTableW = columns.reduce((sum, c) => sum + (c.width ?? FLEX_MIN_COL_W), 0) + (columns.length + 1) * 12;
182
+ return /* @__PURE__ */ jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", overflow: "hidden", children: [
183
+ /* @__PURE__ */ jsx(YStack, { style: { overflowX: "auto", overflowY: "visible" }, children: /* @__PURE__ */ jsxs(YStack, { minW: minTableW, children: [
184
+ /* @__PURE__ */ jsx(XStack, { bg: "$color1", py: "$2.5", px: "$3", gap: "$3", borderBottomWidth: 1, borderColor: "$borderColor", role: "row", children: columns.map((c) => {
185
+ const sortable = c.sortable === true && !!onSortChange;
186
+ const active = sortable && sort?.key === c.key;
187
+ const Caret = !sortable ? null : !active ? ChevronsUpDown : sort?.dir === "asc" ? ChevronUp : ChevronDown;
188
+ return /* @__PURE__ */ jsxs(
189
+ XStack,
190
+ {
191
+ width: c.width,
192
+ flex: c.width ? void 0 : 1,
193
+ minW: c.width ? void 0 : FLEX_MIN_COL_W,
194
+ items: "center",
195
+ gap: "$1",
196
+ justify: c.align === "right" ? "flex-end" : "flex-start",
197
+ role: "columnheader",
198
+ "aria-sort": sortable ? active ? sort?.dir === "asc" ? "ascending" : "descending" : "none" : void 0,
199
+ "aria-label": sortable ? `Sort by ${c.header}` : void 0,
200
+ cursor: sortable ? "pointer" : void 0,
201
+ hoverStyle: sortable ? { opacity: 0.75 } : void 0,
202
+ onPress: sortable ? () => onSortChange?.(c.key) : void 0,
203
+ children: [
204
+ /* @__PURE__ */ jsx(
205
+ Text,
206
+ {
207
+ fontSize: "$1",
208
+ fontWeight: "500",
209
+ color: active ? "$color12" : "$color10",
210
+ text: c.align === "right" ? "right" : "left",
211
+ className: c.mono ? "hz-tnum" : void 0,
212
+ children: c.header
213
+ }
214
+ ),
215
+ Caret ? /* @__PURE__ */ jsx(Caret, { size: 12, color: active ? "$color12" : "$color9" }) : null
216
+ ]
217
+ },
218
+ c.key
219
+ );
220
+ }) }),
221
+ loading ? /* @__PURE__ */ jsx(SkeletonRows, { columns }) : rows2.length > 0 ? /* @__PURE__ */ jsx(YStack, { children: rows2.map((row) => {
222
+ const expanded = (isRowExpanded?.(row) ?? false) && !!renderExpanded;
223
+ return /* @__PURE__ */ jsxs(YStack, { children: [
224
+ /* @__PURE__ */ jsx(
225
+ XStack,
226
+ {
227
+ className: "hz-row",
228
+ py: "$2.5",
229
+ px: "$3",
230
+ gap: "$3",
231
+ borderTopWidth: 1,
232
+ borderColor: "$borderColor",
233
+ items: "center",
234
+ bg: expanded ? "$color2" : void 0,
235
+ hoverStyle: onRowPress ? { bg: "$color2" } : void 0,
236
+ cursor: onRowPress ? "pointer" : void 0,
237
+ onPress: onRowPress ? () => onRowPress(row) : void 0,
238
+ children: columns.map((c) => {
239
+ const cell = c.render ? c.render(row) : String(row[c.key] ?? "");
240
+ return /* @__PURE__ */ jsx(
241
+ YStack,
242
+ {
243
+ width: c.width,
244
+ flex: c.width ? void 0 : 1,
245
+ minW: c.width ? void 0 : FLEX_MIN_COL_W,
246
+ justify: "center",
247
+ items: c.align === "right" ? "flex-end" : "flex-start",
248
+ children: typeof cell === "string" || typeof cell === "number" ? /* @__PURE__ */ jsx(
249
+ Text,
250
+ {
251
+ fontSize: "$3",
252
+ numberOfLines: 1,
253
+ color: "$color12",
254
+ text: c.align === "right" ? "right" : "left",
255
+ className: c.mono ? "hz-mono" : void 0,
256
+ children: cell
257
+ }
258
+ ) : cell
259
+ },
260
+ c.key
261
+ );
262
+ })
263
+ }
264
+ ),
265
+ expanded && renderExpanded ? /* @__PURE__ */ jsx(YStack, { borderTopWidth: 1, borderColor: "$borderColor", bg: "$color1", children: renderExpanded(row) }) : null
266
+ ] }, rowKey(row));
267
+ }) }) : null
268
+ ] }) }),
269
+ !loading && rows2.length === 0 ? /* @__PURE__ */ jsx(YStack, { py: "$8", px: "$4", items: "center", gap: "$1", borderTopWidth: 1, borderColor: "$borderColor", children: /* @__PURE__ */ jsx(Text, { color: "$color10", fontSize: "$3", text: "center", children: empty }) }) : null
270
+ ] });
271
+ }
272
+ var FLEX_MIN_COL_W = 120;
273
+ function isHexColor(v) {
274
+ return typeof v === "string" && /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(v.trim());
275
+ }
276
+ function resolveAccent(theme) {
277
+ if (!theme || !theme.isEnabled) return null;
278
+ const hex = (theme.colorPrimary ?? "").trim();
279
+ return isHexColor(hex) ? hex : null;
280
+ }
281
+ function expandHex(hex) {
282
+ const h = hex.trim().toLowerCase();
283
+ if (h.length === 4) return `#${h[1]}${h[1]}${h[2]}${h[2]}${h[3]}${h[3]}`;
284
+ return h;
285
+ }
286
+ function contrastText(hex) {
287
+ if (!isHexColor(hex)) return "#ffffff";
288
+ const h = expandHex(hex);
289
+ const r = parseInt(h.slice(1, 3), 16) / 255;
290
+ const g = parseInt(h.slice(3, 5), 16) / 255;
291
+ const b = parseInt(h.slice(5, 7), 16) / 255;
292
+ const lin = (c) => c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
293
+ const luminance = 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
294
+ return luminance > 0.5 ? "#000000" : "#ffffff";
295
+ }
296
+ function accentFor(theme) {
297
+ const hex = resolveAccent(theme);
298
+ return { accent: hex, contrast: hex ? contrastText(hex) : "#ffffff" };
299
+ }
300
+ var DEFAULT = { accent: null, contrast: "#ffffff" };
301
+ var current = DEFAULT;
302
+ var listeners = /* @__PURE__ */ new Set();
303
+ function setOrgAccent(theme) {
304
+ const next = accentFor(theme);
305
+ if (next.accent === current.accent) return;
306
+ current = next.accent ? next : DEFAULT;
307
+ for (const l of listeners) l();
308
+ }
309
+ function subscribe(cb) {
310
+ listeners.add(cb);
311
+ return () => {
312
+ listeners.delete(cb);
313
+ };
314
+ }
315
+ function useAccent() {
316
+ return useSyncExternalStore(
317
+ subscribe,
318
+ () => current,
319
+ () => DEFAULT
320
+ );
321
+ }
322
+ function PrimaryButton(props) {
323
+ const { accent, contrast } = useAccent();
324
+ if (accent) {
325
+ return /* @__PURE__ */ jsx(Button, { style: { backgroundColor: accent, color: contrast, borderColor: accent }, ...props });
326
+ }
327
+ return /* @__PURE__ */ jsx(Button, { theme: "light", ...props });
328
+ }
329
+ function openHref(href) {
330
+ if (typeof window !== "undefined") window.open(href, "_blank", "noopener");
331
+ }
332
+ function EmptyState({
333
+ icon: Icon,
334
+ title,
335
+ description,
336
+ bullets,
337
+ primary,
338
+ secondary
339
+ }) {
340
+ return /* @__PURE__ */ jsxs(
341
+ Card,
342
+ {
343
+ borderWidth: 1,
344
+ borderColor: "$borderColor",
345
+ borderStyle: "dashed",
346
+ p: "$6",
347
+ gap: "$4",
348
+ items: "center",
349
+ maxWidth: 640,
350
+ self: "center",
351
+ width: "100%",
352
+ children: [
353
+ /* @__PURE__ */ jsx(
354
+ YStack,
355
+ {
356
+ width: 48,
357
+ height: 48,
358
+ items: "center",
359
+ justify: "center",
360
+ rounded: "$4",
361
+ bg: "$color3",
362
+ children: /* @__PURE__ */ jsx(Icon, { size: 24 })
363
+ }
364
+ ),
365
+ /* @__PURE__ */ jsxs(YStack, { gap: "$2", items: "center", maxW: 480, children: [
366
+ /* @__PURE__ */ jsx(Text, { fontSize: "$6", fontWeight: "500", text: "center", letterSpacing: -0.3, children: title }),
367
+ /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color11", text: "center", children: description })
368
+ ] }),
369
+ bullets && bullets.length ? /* @__PURE__ */ jsx(YStack, { gap: "$2", self: "stretch", maxW: 420, mx: "auto", children: bullets.map((b) => /* @__PURE__ */ jsxs(XStack, { gap: "$2", items: "flex-start", children: [
370
+ /* @__PURE__ */ jsx(YStack, { pt: "$1", children: /* @__PURE__ */ jsx(Check, { size: 14, color: "$color10" }) }),
371
+ /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color11", flex: 1, children: b })
372
+ ] }, b)) }) : null,
373
+ primary || secondary ? /* @__PURE__ */ jsxs(XStack, { gap: "$2", items: "center", flexWrap: "wrap", justify: "center", children: [
374
+ primary ? /* @__PURE__ */ jsx(
375
+ PrimaryButton,
376
+ {
377
+ icon: primary.icon,
378
+ iconAfter: primary.href ? /* @__PURE__ */ jsx(ExternalLink, { size: 15 }) : /* @__PURE__ */ jsx(ArrowRight, { size: 15 }),
379
+ onPress: () => primary.href ? openHref(primary.href) : primary.onPress?.(),
380
+ children: primary.label
381
+ }
382
+ ) : null,
383
+ secondary ? /* @__PURE__ */ jsx(
384
+ Button,
385
+ {
386
+ chromeless: true,
387
+ icon: secondary.icon,
388
+ iconAfter: secondary.href ? /* @__PURE__ */ jsx(ExternalLink, { size: 14 }) : void 0,
389
+ onPress: () => secondary.href ? openHref(secondary.href) : secondary.onPress?.(),
390
+ children: secondary.label
391
+ }
392
+ ) : null
393
+ ] }) : null
394
+ ]
395
+ }
396
+ );
397
+ }
398
+ function FieldRow({ label, children }) {
399
+ return /* @__PURE__ */ jsxs(XStack, { gap: "$3", items: "flex-start", flexWrap: "wrap", children: [
400
+ /* @__PURE__ */ jsx(Label, { width: "100%", pt: "$2", color: "$color11", fontSize: "$3", $md: { width: 180 }, children: label }),
401
+ /* @__PURE__ */ jsx(YStack, { flex: 1, minW: 0, $md: { minW: 240 }, children })
402
+ ] });
403
+ }
404
+ function FieldText({
405
+ value,
406
+ onChange,
407
+ disabled,
408
+ secure,
409
+ placeholder
410
+ }) {
411
+ return /* @__PURE__ */ jsx(
412
+ Input,
413
+ {
414
+ value,
415
+ onChangeText: onChange,
416
+ disabled,
417
+ secureTextEntry: secure,
418
+ placeholder,
419
+ autoCapitalize: "none"
420
+ }
421
+ );
422
+ }
423
+ function FieldTextArea({
424
+ value,
425
+ onChange,
426
+ disabled,
427
+ rows: rows2 = 6
428
+ }) {
429
+ return /* @__PURE__ */ jsx(TextArea, { value, onChangeText: onChange, disabled, numberOfLines: rows2 });
430
+ }
431
+ function FieldSwitch({
432
+ checked,
433
+ onChange,
434
+ disabled
435
+ }) {
436
+ return /* @__PURE__ */ jsx(Switch, { checked, onCheckedChange: onChange, disabled, size: "$3", children: /* @__PURE__ */ jsx(Switch.Thumb, {}) });
437
+ }
438
+ var CHEVRON = `data:image/svg+xml,${encodeURIComponent(
439
+ '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#9a9a9a" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>'
440
+ )}`;
441
+ function selectStyle(disabled) {
442
+ return {
443
+ width: "100%",
444
+ boxSizing: "border-box",
445
+ appearance: "none",
446
+ WebkitAppearance: "none",
447
+ MozAppearance: "none",
448
+ background: `var(--background) url("${CHEVRON}") no-repeat right 10px center`,
449
+ color: "var(--color12)",
450
+ border: "1px solid var(--borderColor)",
451
+ borderRadius: 9,
452
+ padding: "9px 34px 9px 12px",
453
+ fontSize: 14,
454
+ lineHeight: "20px",
455
+ fontFamily: "inherit",
456
+ height: 40,
457
+ outline: "none",
458
+ cursor: disabled ? "not-allowed" : "pointer",
459
+ opacity: disabled ? 0.5 : 1
460
+ };
461
+ }
462
+ var OPTION_STYLE = { background: "var(--color2)", color: "var(--color12)" };
463
+ function FieldSelect({
464
+ value,
465
+ options,
466
+ onChange,
467
+ disabled,
468
+ placeholder = "Select\u2026"
469
+ }) {
470
+ const showPlaceholder = value === "" || !options.includes(value);
471
+ return /* @__PURE__ */ jsxs(
472
+ "select",
473
+ {
474
+ value: showPlaceholder ? "" : value,
475
+ onChange: (e) => onChange(e.currentTarget.value),
476
+ disabled,
477
+ "aria-label": placeholder,
478
+ style: selectStyle(disabled),
479
+ children: [
480
+ showPlaceholder ? /* @__PURE__ */ jsx("option", { value: "", disabled: true, style: OPTION_STYLE, children: placeholder }) : null,
481
+ options.map((opt) => /* @__PURE__ */ jsx("option", { value: opt, style: OPTION_STYLE, children: opt }, opt))
482
+ ]
483
+ }
484
+ );
485
+ }
486
+ function FieldSlider({
487
+ value,
488
+ min,
489
+ max,
490
+ step,
491
+ onChange,
492
+ disabled
493
+ }) {
494
+ return /* @__PURE__ */ jsxs(XStack, { gap: "$3", items: "center", children: [
495
+ /* @__PURE__ */ jsx(Text, { width: 56, fontSize: "$3", color: "$color11", children: value }),
496
+ /* @__PURE__ */ jsxs(
497
+ Slider,
498
+ {
499
+ flex: 1,
500
+ min,
501
+ max,
502
+ step,
503
+ value: [value],
504
+ onValueChange: (v) => onChange(v[0] ?? min),
505
+ disabled,
506
+ children: [
507
+ /* @__PURE__ */ jsx(Slider.Track, { children: /* @__PURE__ */ jsx(Slider.TrackActive, {}) }),
508
+ /* @__PURE__ */ jsx(Slider.Thumb, { index: 0, circular: true })
509
+ ]
510
+ }
511
+ )
512
+ ] });
513
+ }
514
+ function PageHeader({
515
+ title,
516
+ subtitle,
517
+ actions
518
+ }) {
519
+ return (
520
+ // flexWrap lets the actions drop below the title on narrow screens; flex={1}
521
+ // minW={0} lets the title column shrink so a long subtitle WRAPS instead of
522
+ // running off the viewport (a flex child defaults to min-width:auto = content
523
+ // width, which would overflow on mobile).
524
+ /* @__PURE__ */ jsxs(XStack, { justify: "space-between", items: "flex-start", gap: "$3", flexWrap: "wrap", children: [
525
+ /* @__PURE__ */ jsxs(YStack, { gap: "$1", flex: 1, minW: 200, children: [
526
+ /* @__PURE__ */ jsx(Text, { fontSize: "$7", fontWeight: "500", letterSpacing: -0.4, children: title }),
527
+ subtitle ? /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color11", children: subtitle }) : null
528
+ ] }),
529
+ actions ? /* @__PURE__ */ jsx(XStack, { gap: "$2", items: "center", flexWrap: "wrap", width: "100%", $md: { width: "auto", justify: "flex-end" }, children: actions }) : null
530
+ ] })
531
+ );
532
+ }
533
+ var toneOf = (status) => {
534
+ const s = status.toLowerCase();
535
+ if (s === "green") return "green";
536
+ if (s === "yellow") return "yellow";
537
+ if (s === "red") return "red";
538
+ if (["ready", "active", "running", "available", "ok", "live", "succeeded", "connected", "synced", "imported"].includes(s)) return "green";
539
+ if (["creating", "provisioning", "pending", "updating", "attaching", "building", "deploying", "queued", "importing"].includes(s))
540
+ return "yellow";
541
+ if (["error", "failed", "degraded", "down", "canceled", "conflict"].includes(s)) return "red";
542
+ return "neutral";
543
+ };
544
+ var TONE_BG = {
545
+ green: "$color5",
546
+ yellow: "$color4",
547
+ red: "$color4",
548
+ neutral: "$color3"
549
+ };
550
+ var TONE_FG = {
551
+ green: "$color12",
552
+ yellow: "$color12",
553
+ red: "$color12",
554
+ neutral: "$color11"
555
+ };
556
+ function StatusTag({ status }) {
557
+ const tone = toneOf(status ?? "");
558
+ return /* @__PURE__ */ jsx(Text, { fontSize: "$1", px: "$2", py: "$1", rounded: "$2", bg: TONE_BG[tone], color: TONE_FG[tone], children: status || "unknown" });
559
+ }
560
+
561
+ // src/product/color.ts
562
+ var asColor = (hex) => hex;
563
+ var LG = 1024;
564
+ var lockCount = 0;
565
+ var savedOverflow = "";
566
+ function lockScroll() {
567
+ if (typeof document === "undefined") return;
568
+ if (lockCount === 0) {
569
+ savedOverflow = document.body.style.overflow;
570
+ document.body.style.overflow = "hidden";
571
+ }
572
+ lockCount++;
573
+ }
574
+ function unlockScroll() {
575
+ if (typeof document === "undefined") return;
576
+ lockCount = Math.max(0, lockCount - 1);
577
+ if (lockCount === 0) document.body.style.overflow = savedOverflow;
578
+ }
579
+ function SlideOver({
580
+ open,
581
+ onClose,
582
+ side = "right",
583
+ size = 420,
584
+ title,
585
+ icon: Icon,
586
+ iconColor,
587
+ headerRight,
588
+ ariaLabel,
589
+ zIndex = 1e3,
590
+ children
591
+ }) {
592
+ const panelRef = useRef(null);
593
+ const openerRef = useRef(null);
594
+ useEffect(() => {
595
+ if (!open) return;
596
+ openerRef.current = typeof document !== "undefined" ? document.activeElement : null;
597
+ lockScroll();
598
+ const t = window.setTimeout(() => {
599
+ const el = panelRef.current;
600
+ if (el && typeof el.focus === "function") el.focus();
601
+ }, 0);
602
+ return () => {
603
+ window.clearTimeout(t);
604
+ unlockScroll();
605
+ const opener = openerRef.current;
606
+ if (opener && opener instanceof HTMLElement && typeof opener.focus === "function") opener.focus();
607
+ };
608
+ }, [open]);
609
+ useEffect(() => {
610
+ if (!open) return;
611
+ const onKey = (e) => {
612
+ if (e.key === "Escape") {
613
+ e.stopPropagation();
614
+ onClose();
615
+ }
616
+ };
617
+ window.addEventListener("keydown", onKey);
618
+ return () => window.removeEventListener("keydown", onKey);
619
+ }, [open, onClose]);
620
+ const offscreen = side === "right" ? "translateX(100%)" : "translateX(-100%)";
621
+ const edge = side === "right" ? { r: 0 } : { l: 0 };
622
+ return /* @__PURE__ */ jsxs(
623
+ YStack,
624
+ {
625
+ overflow: "hidden",
626
+ pointerEvents: open ? "auto" : "none",
627
+ "aria-hidden": !open,
628
+ style: { position: "fixed", inset: 0, zIndex },
629
+ children: [
630
+ /* @__PURE__ */ jsx(
631
+ YStack,
632
+ {
633
+ position: "absolute",
634
+ t: 0,
635
+ l: 0,
636
+ r: 0,
637
+ b: 0,
638
+ bg: "rgba(0,0,0,0.55)",
639
+ className: "hz-fade",
640
+ style: { opacity: open ? 1 : 0 },
641
+ onPress: onClose
642
+ }
643
+ ),
644
+ /* @__PURE__ */ jsx(
645
+ YStack,
646
+ {
647
+ ref: panelRef,
648
+ tabIndex: -1,
649
+ role: "dialog",
650
+ "aria-modal": open ? true : void 0,
651
+ "aria-label": typeof title === "string" ? title : ariaLabel,
652
+ position: "absolute",
653
+ t: 0,
654
+ b: 0,
655
+ ...edge,
656
+ width: "100%",
657
+ $lg: { width: size, maxW: "100vw" },
658
+ bg: "$color1",
659
+ borderLeftWidth: side === "right" ? 1 : 0,
660
+ borderRightWidth: side === "left" ? 1 : 0,
661
+ borderColor: "$borderColor",
662
+ className: "hz-slide hz-elevation-4",
663
+ style: {
664
+ transform: open ? "translateX(0)" : offscreen,
665
+ height: "100dvh",
666
+ paddingTop: "env(safe-area-inset-top)",
667
+ paddingBottom: "env(safe-area-inset-bottom)"
668
+ },
669
+ children: title !== void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
670
+ /* @__PURE__ */ jsxs(
671
+ XStack,
672
+ {
673
+ items: "center",
674
+ gap: "$2.5",
675
+ px: "$4",
676
+ height: 56,
677
+ borderBottomWidth: 1,
678
+ borderColor: "$borderColor",
679
+ children: [
680
+ Icon ? /* @__PURE__ */ jsx(Icon, { size: 18, color: iconColor ? asColor(iconColor) : void 0 }) : null,
681
+ /* @__PURE__ */ jsx(Text, { flex: 1, fontSize: "$5", fontWeight: "700", color: "$color12", numberOfLines: 1, children: title }),
682
+ headerRight,
683
+ /* @__PURE__ */ jsx(Button, { chromeless: true, width: 44, height: 44, icon: /* @__PURE__ */ jsx(X, { size: 18 }), onPress: onClose, "aria-label": "Close" })
684
+ ]
685
+ }
686
+ ),
687
+ /* @__PURE__ */ jsx(ScrollView, { flex: 1, children: /* @__PURE__ */ jsx(YStack, { flex: 1, p: "$4", gap: "$3", children }) })
688
+ ] }) : (
689
+ // Bare mode — the caller owns the full panel layout (e.g. the nav drawer
690
+ // renders its own header + scroll + footer).
691
+ children
692
+ )
693
+ }
694
+ )
695
+ ]
696
+ }
697
+ );
698
+ }
699
+
700
+ // src/product/social/format.ts
701
+ function formatPostTime(unix) {
702
+ if (!unix) return "\u2014";
703
+ return new Date(unix * 1e3).toLocaleString(void 0, {
704
+ month: "short",
705
+ day: "numeric",
706
+ hour: "2-digit",
707
+ minute: "2-digit"
708
+ });
709
+ }
710
+ function postDayBucket(unix) {
711
+ const d = new Date(unix * 1e3);
712
+ const key = `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
713
+ const label = d.toLocaleDateString(void 0, { weekday: "short", month: "short", day: "numeric" });
714
+ return { key, label };
715
+ }
716
+ function postPreview(s) {
717
+ const t = s.trim();
718
+ return t.length > 72 ? `${t.slice(0, 72)}\u2026` : t || "\u2014";
719
+ }
720
+ function parsePostTime(dt) {
721
+ const ms = Date.parse(dt.trim());
722
+ return Number.isFinite(ms) && ms > 0 ? Math.floor(ms / 1e3) : 0;
723
+ }
724
+ function PostAgenda({ posts, onOpen }) {
725
+ const days = useMemo(() => {
726
+ const timed = posts.filter((p) => (p.scheduleAt ?? 0) > 0).sort((a, b) => (a.scheduleAt ?? 0) - (b.scheduleAt ?? 0));
727
+ const groups = [];
728
+ const index = /* @__PURE__ */ new Map();
729
+ for (const p of timed) {
730
+ const { key, label } = postDayBucket(p.scheduleAt ?? 0);
731
+ let i = index.get(key);
732
+ if (i === void 0) {
733
+ i = groups.length;
734
+ index.set(key, i);
735
+ groups.push({ label, items: [] });
736
+ }
737
+ groups[i].items.push(p);
738
+ }
739
+ return groups;
740
+ }, [posts]);
741
+ if (days.length === 0) {
742
+ return /* @__PURE__ */ jsx(
743
+ EmptyState,
744
+ {
745
+ icon: Calendar,
746
+ title: "Nothing on the calendar",
747
+ description: "Scheduled and timed posts appear here, grouped by day. Compose a post and pick Schedule to plan ahead."
748
+ }
749
+ );
750
+ }
751
+ return /* @__PURE__ */ jsx(YStack, { gap: "$4", children: days.map((d) => /* @__PURE__ */ jsxs(YStack, { gap: "$2", children: [
752
+ /* @__PURE__ */ jsx(Text, { fontSize: "$3", fontWeight: "500", color: "$color11", children: d.label }),
753
+ d.items.map((p) => /* @__PURE__ */ jsxs(
754
+ XStack,
755
+ {
756
+ items: "center",
757
+ justify: "space-between",
758
+ gap: "$3",
759
+ borderWidth: 1,
760
+ borderColor: "$borderColor",
761
+ rounded: "$4",
762
+ px: "$4",
763
+ py: "$3",
764
+ cursor: "pointer",
765
+ hoverStyle: { bg: "$color2" },
766
+ onPress: () => onOpen(p),
767
+ children: [
768
+ /* @__PURE__ */ jsxs(YStack, { gap: "$1", flex: 1, children: [
769
+ /* @__PURE__ */ jsx(Text, { fontSize: "$3", children: postPreview(p.content) }),
770
+ /* @__PURE__ */ jsxs(XStack, { gap: "$2", items: "center", children: [
771
+ /* @__PURE__ */ jsx(Text, { fontSize: "$1", color: "$color10", children: p.channel }),
772
+ /* @__PURE__ */ jsxs(Text, { fontSize: "$1", color: "$color10", children: [
773
+ "\xB7 ",
774
+ formatPostTime(p.scheduleAt ?? 0)
775
+ ] })
776
+ ] })
777
+ ] }),
778
+ /* @__PURE__ */ jsx(StatusTag, { status: p.status })
779
+ ]
780
+ },
781
+ p.id
782
+ ))
783
+ ] }, d.label)) });
784
+ }
785
+ var COMPOSE_MODES = ["draft", "schedule", "now"];
786
+ var COMPOSE_LABEL = {
787
+ draft: "Save draft",
788
+ schedule: "Schedule",
789
+ now: "Publish now"
790
+ };
791
+ function PostComposer({
792
+ channels,
793
+ providers,
794
+ onSubmit
795
+ }) {
796
+ const [content, setContent] = useState("");
797
+ const [channel, setChannel] = useState(channels[0] ?? "x");
798
+ const [mode, setMode] = useState("draft");
799
+ const [scheduleAt, setScheduleAt] = useState("");
800
+ const [saving, setSaving] = useState(false);
801
+ const [error, setError] = useState(null);
802
+ const cap = providers.find((p) => p.provider === channel);
803
+ const unconfigured = (mode === "now" || mode === "schedule") && !!cap && !cap.credentialsConfigured;
804
+ const submit = async () => {
805
+ if (!content.trim()) {
806
+ setError("Content is required.");
807
+ return;
808
+ }
809
+ let status = "draft";
810
+ let at = 0;
811
+ if (mode === "schedule") {
812
+ at = parsePostTime(scheduleAt);
813
+ if (at <= Math.floor(Date.now() / 1e3)) {
814
+ setError("Pick a future date and time to schedule.");
815
+ return;
816
+ }
817
+ status = "scheduled";
818
+ } else if (mode === "now") {
819
+ status = "scheduled";
820
+ }
821
+ setSaving(true);
822
+ setError(null);
823
+ const message = await onSubmit({ content: content.trim(), channel, status, scheduleAt: at }, mode);
824
+ if (message) {
825
+ setError(message);
826
+ setSaving(false);
827
+ }
828
+ };
829
+ return /* @__PURE__ */ jsxs(YStack, { gap: "$3", p: "$4", children: [
830
+ /* @__PURE__ */ jsx(FieldRow, { label: "Content", children: /* @__PURE__ */ jsx(FieldTextArea, { value: content, onChange: setContent, disabled: saving }) }),
831
+ /* @__PURE__ */ jsx(FieldRow, { label: "Channel", children: /* @__PURE__ */ jsx(FieldSelect, { value: channel, options: channels, onChange: setChannel, disabled: saving }) }),
832
+ /* @__PURE__ */ jsx(FieldRow, { label: "When", children: /* @__PURE__ */ jsx(
833
+ FieldSelect,
834
+ {
835
+ value: mode,
836
+ options: [...COMPOSE_MODES],
837
+ onChange: (v) => setMode(v),
838
+ disabled: saving
839
+ }
840
+ ) }),
841
+ mode === "schedule" ? /* @__PURE__ */ jsx(FieldRow, { label: "Schedule at", children: /* @__PURE__ */ jsx(
842
+ FieldText,
843
+ {
844
+ value: scheduleAt,
845
+ onChange: setScheduleAt,
846
+ placeholder: "2026-07-15 09:00",
847
+ disabled: saving
848
+ }
849
+ ) }) : null,
850
+ unconfigured ? /* @__PURE__ */ jsxs(XStack, { items: "flex-start", gap: "$2", children: [
851
+ /* @__PURE__ */ jsx(AlertTriangle, { size: 14, color: "var(--yellow10)" }),
852
+ /* @__PURE__ */ jsxs(Text, { fontSize: "$1", color: "$color10", children: [
853
+ channel,
854
+ " isn\u2019t configured to publish yet \u2014 needs ",
855
+ cap?.missingCredentials.join(", "),
856
+ ". The post is saved and marked failed on publish until credentials are supplied."
857
+ ] })
858
+ ] }) : null,
859
+ error ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$red10", children: error }) : null,
860
+ /* @__PURE__ */ jsx(PrimaryButton, { onPress: submit, disabled: saving, children: saving ? "Working\u2026" : COMPOSE_LABEL[mode] })
861
+ ] });
862
+ }
863
+ function ProviderReadinessList({ providers }) {
864
+ return /* @__PURE__ */ jsxs(YStack, { gap: "$2", children: [
865
+ /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color10", children: "Network publish-readiness" }),
866
+ providers.map((p) => /* @__PURE__ */ jsxs(XStack, { items: "center", justify: "space-between", gap: "$3", py: "$1", children: [
867
+ /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", children: [
868
+ p.credentialsConfigured ? /* @__PURE__ */ jsx(CheckCircle2, { size: 14, color: "var(--green10)" }) : /* @__PURE__ */ jsx(AlertTriangle, { size: 14, color: "var(--yellow10)" }),
869
+ /* @__PURE__ */ jsx(Text, { fontSize: "$2", children: p.provider })
870
+ ] }),
871
+ /* @__PURE__ */ jsx(Text, { fontSize: "$1", color: "$color10", children: p.credentialsConfigured ? "Ready" : `needs ${p.missingCredentials.join(", ")}` })
872
+ ] }, p.provider))
873
+ ] });
874
+ }
875
+ function SocialSummaryBar({ summary }) {
876
+ const cells = [
877
+ { label: "Posts", value: summary.posts },
878
+ { label: "Scheduled", value: summary.scheduled },
879
+ { label: "Published", value: summary.published },
880
+ { label: "Accounts", value: summary.accounts }
881
+ ];
882
+ return /* @__PURE__ */ jsx(XStack, { gap: "$3", flexWrap: "wrap", children: cells.map((c) => /* @__PURE__ */ jsxs(
883
+ YStack,
884
+ {
885
+ gap: "$1",
886
+ borderWidth: 1,
887
+ borderColor: "$borderColor",
888
+ rounded: "$4",
889
+ px: "$4",
890
+ py: "$3",
891
+ minW: 140,
892
+ children: [
893
+ /* @__PURE__ */ jsx(Text, { fontSize: "$1", color: "$color10", children: c.label }),
894
+ /* @__PURE__ */ jsx(Text, { fontSize: "$6", fontWeight: "500", className: "hz-tnum", children: c.value })
895
+ ]
896
+ },
897
+ c.label
898
+ )) });
899
+ }
900
+ var OPTIONS = [
901
+ { id: "list", label: "List", icon: List },
902
+ { id: "calendar", label: "Calendar", icon: Calendar }
903
+ ];
904
+ function ViewToggle({
905
+ view,
906
+ onChange
907
+ }) {
908
+ return /* @__PURE__ */ jsx(XStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", overflow: "hidden", children: OPTIONS.map((o) => {
909
+ const Icon = o.icon;
910
+ const active = view === o.id;
911
+ return /* @__PURE__ */ jsxs(
912
+ XStack,
913
+ {
914
+ items: "center",
915
+ gap: "$2",
916
+ px: "$3",
917
+ py: "$2",
918
+ cursor: "pointer",
919
+ bg: active ? "$color4" : "transparent",
920
+ hoverStyle: { bg: active ? "$color4" : "$color2" },
921
+ onPress: () => onChange(o.id),
922
+ children: [
923
+ /* @__PURE__ */ jsx(Icon, { size: 14 }),
924
+ /* @__PURE__ */ jsx(Text, { fontSize: "$2", fontWeight: active ? "500" : "400", children: o.label })
925
+ ]
926
+ },
927
+ o.id
928
+ );
929
+ }) });
930
+ }
931
+ var POST_COLUMNS = [
932
+ { key: "content", header: "Post", render: (p) => postPreview(p.content) },
933
+ { key: "channel", header: "Channel", render: (p) => p.channel || "\u2014" },
934
+ { key: "status", header: "Status", render: (p) => /* @__PURE__ */ jsx(StatusTag, { status: p.status }) },
935
+ { key: "scheduleAt", header: "Scheduled", render: (p) => formatPostTime(p.scheduleAt) }
936
+ ];
937
+ var ACCOUNT_COLUMNS = [
938
+ { key: "handle", header: "Account", render: (a) => a.handle || "\u2014" },
939
+ { key: "provider", header: "Network", render: (a) => a.provider || "\u2014" },
940
+ { key: "status", header: "Status", render: (a) => /* @__PURE__ */ jsx(StatusTag, { status: a.status }) }
941
+ ];
942
+ function PostDetail({ api, post, onChanged }) {
943
+ const [publishing, setPublishing] = useState(false);
944
+ const [error, setError] = useState(null);
945
+ const canPublish = post.status === "draft" || post.status === "scheduled" || post.status === "failed";
946
+ const publish = async () => {
947
+ setPublishing(true);
948
+ setError(null);
949
+ try {
950
+ await api.posts.publish(post.id);
951
+ onChanged();
952
+ } catch (e) {
953
+ setError(classifyBackend(e).message || "Publish failed.");
954
+ } finally {
955
+ setPublishing(false);
956
+ }
957
+ };
958
+ return /* @__PURE__ */ jsxs(YStack, { gap: "$3", p: "$4", children: [
959
+ /* @__PURE__ */ jsx(FieldRow, { label: "Content", children: /* @__PURE__ */ jsx(Text, { fontSize: "$3", children: post.content || "\u2014" }) }),
960
+ /* @__PURE__ */ jsx(FieldRow, { label: "Channel", children: /* @__PURE__ */ jsx(Text, { fontSize: "$3", children: post.channel }) }),
961
+ /* @__PURE__ */ jsx(FieldRow, { label: "Status", children: /* @__PURE__ */ jsx(StatusTag, { status: post.status }) }),
962
+ post.scheduleAt > 0 ? /* @__PURE__ */ jsx(FieldRow, { label: "Scheduled", children: /* @__PURE__ */ jsx(Text, { fontSize: "$3", children: formatPostTime(post.scheduleAt) }) }) : null,
963
+ post.media.length > 0 ? /* @__PURE__ */ jsx(FieldRow, { label: "Media", children: /* @__PURE__ */ jsx(YStack, { gap: "$1", children: post.media.map((m) => /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", children: m }, m)) }) }) : null,
964
+ post.externalId ? /* @__PURE__ */ jsx(FieldRow, { label: "External id", children: /* @__PURE__ */ jsx(Text, { fontSize: "$3", className: "hz-tnum", children: post.externalId }) }) : null,
965
+ post.error ? /* @__PURE__ */ jsx(FieldRow, { label: "Last error", children: /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$red10", children: post.error }) }) : null,
966
+ error ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$red10", children: error }) : null,
967
+ canPublish ? /* @__PURE__ */ jsx(PrimaryButton, { onPress: publish, disabled: publishing, icon: /* @__PURE__ */ jsx(Send, { size: 16 }), children: publishing ? "Publishing\u2026" : "Publish now" }) : null
968
+ ] });
969
+ }
970
+ function ConnectAccount({
971
+ api,
972
+ providers,
973
+ onCreated
974
+ }) {
975
+ const [provider, setProvider] = useState("x");
976
+ const [handle, setHandle] = useState("");
977
+ const [saving, setSaving] = useState(false);
978
+ const [error, setError] = useState(null);
979
+ const submit = async () => {
980
+ setSaving(true);
981
+ setError(null);
982
+ try {
983
+ await api.accounts.create({ provider, handle: handle.trim(), status: "connected" });
984
+ onCreated();
985
+ } catch (e) {
986
+ setError(classifyBackend(e).message || "Failed to connect account.");
987
+ } finally {
988
+ setSaving(false);
989
+ }
990
+ };
991
+ return /* @__PURE__ */ jsxs(YStack, { gap: "$4", p: "$4", children: [
992
+ /* @__PURE__ */ jsx(ProviderReadinessList, { providers }),
993
+ /* @__PURE__ */ jsxs(YStack, { gap: "$3", children: [
994
+ /* @__PURE__ */ jsx(FieldRow, { label: "Network", children: /* @__PURE__ */ jsx(FieldSelect, { value: provider, options: [...PROVIDERS], onChange: setProvider, disabled: saving }) }),
995
+ /* @__PURE__ */ jsx(FieldRow, { label: "Handle", children: /* @__PURE__ */ jsx(FieldText, { value: handle, onChange: setHandle, placeholder: "@hanzo", disabled: saving }) }),
996
+ error ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$red10", children: error }) : null,
997
+ /* @__PURE__ */ jsx(PrimaryButton, { onPress: submit, disabled: saving, children: saving ? "Connecting\u2026" : "Connect account" })
998
+ ] })
999
+ ] });
1000
+ }
1001
+ function SocialResource({
1002
+ api,
1003
+ title = "Publish",
1004
+ subtitle = "Compose, schedule and publish your content across networks \u2014 per org, over the native /v1/social engine."
1005
+ }) {
1006
+ const [state, setState] = useState({ phase: "loading" });
1007
+ const [view, setView] = useState("list");
1008
+ const [composing, setComposing] = useState(false);
1009
+ const [connecting, setConnecting] = useState(false);
1010
+ const [openPost, setOpenPost] = useState(null);
1011
+ const load = useCallback(async () => {
1012
+ setState({ phase: "loading" });
1013
+ try {
1014
+ const [summary, posts2, accounts2, providers2] = await Promise.all([
1015
+ api.summary(),
1016
+ api.posts.list(),
1017
+ api.accounts.list(),
1018
+ api.providers()
1019
+ ]);
1020
+ setState({ phase: "ready", data: { summary, posts: posts2, accounts: accounts2, providers: providers2 } });
1021
+ } catch (e) {
1022
+ setState({ phase: "error", error: classifyBackend(e) });
1023
+ }
1024
+ }, [api]);
1025
+ useEffect(() => {
1026
+ void load();
1027
+ }, [load]);
1028
+ const providers = state.phase === "ready" ? state.data.providers : [];
1029
+ const posts = state.phase === "ready" ? state.data.posts : [];
1030
+ const accounts = state.phase === "ready" ? state.data.accounts : [];
1031
+ const empty = state.phase === "ready" && posts.length === 0 && accounts.length === 0;
1032
+ const submitDraft = async (draft, mode) => {
1033
+ try {
1034
+ const created = await api.posts.create(draft);
1035
+ if (mode === "now" && created.status === "failed") return created.error || "Publish failed.";
1036
+ } catch (e) {
1037
+ return classifyBackend(e).message || "Failed to create post.";
1038
+ }
1039
+ setComposing(false);
1040
+ void load();
1041
+ return null;
1042
+ };
1043
+ return /* @__PURE__ */ jsxs(YStack, { gap: "$4", p: "$4", children: [
1044
+ /* @__PURE__ */ jsx(
1045
+ PageHeader,
1046
+ {
1047
+ title,
1048
+ subtitle,
1049
+ actions: /* @__PURE__ */ jsxs(Fragment, { children: [
1050
+ /* @__PURE__ */ jsx(PrimaryButton, { onPress: () => setComposing(true), icon: /* @__PURE__ */ jsx(Plus, { size: 16 }), children: "New post" }),
1051
+ /* @__PURE__ */ jsx(PrimaryButton, { onPress: () => setConnecting(true), icon: /* @__PURE__ */ jsx(Link2, { size: 16 }), children: "Connect account" }),
1052
+ /* @__PURE__ */ jsx(PrimaryButton, { onPress: () => void load(), icon: /* @__PURE__ */ jsx(RefreshCw, { size: 16 }), children: "Refresh" })
1053
+ ] })
1054
+ }
1055
+ ),
1056
+ state.phase === "error" ? /* @__PURE__ */ jsx(BackendStateCard, { state: state.error, onRetry: () => void load() }) : empty ? /* @__PURE__ */ jsxs(YStack, { gap: "$4", children: [
1057
+ state.phase === "ready" ? /* @__PURE__ */ jsx(SocialSummaryBar, { summary: state.data.summary }) : null,
1058
+ /* @__PURE__ */ jsx(
1059
+ EmptyState,
1060
+ {
1061
+ icon: Share2,
1062
+ title: "No posts or accounts yet",
1063
+ description: "Connect a social account, then compose, schedule and publish across X, Instagram, LinkedIn, TikTok and more.",
1064
+ primary: { label: "New post", onPress: () => setComposing(true) }
1065
+ }
1066
+ )
1067
+ ] }) : /* @__PURE__ */ jsxs(YStack, { gap: "$5", children: [
1068
+ state.phase === "ready" ? /* @__PURE__ */ jsx(SocialSummaryBar, { summary: state.data.summary }) : null,
1069
+ /* @__PURE__ */ jsxs(YStack, { gap: "$3", children: [
1070
+ /* @__PURE__ */ jsxs(XStack, { items: "center", justify: "space-between", gap: "$2", flexWrap: "wrap", children: [
1071
+ /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", children: [
1072
+ /* @__PURE__ */ jsx(Send, { size: 16 }),
1073
+ /* @__PURE__ */ jsx(Text, { fontSize: "$5", fontWeight: "500", children: "Posts" })
1074
+ ] }),
1075
+ /* @__PURE__ */ jsx(ViewToggle, { view, onChange: setView })
1076
+ ] }),
1077
+ view === "list" ? /* @__PURE__ */ jsx(
1078
+ DataTable,
1079
+ {
1080
+ columns: POST_COLUMNS,
1081
+ rows: posts,
1082
+ loading: state.phase === "loading",
1083
+ empty: "No posts yet.",
1084
+ rowKey: (p) => p.id,
1085
+ onRowPress: (p) => setOpenPost(p)
1086
+ }
1087
+ ) : /* @__PURE__ */ jsx(PostAgenda, { posts, onOpen: (p) => setOpenPost(p) })
1088
+ ] }),
1089
+ /* @__PURE__ */ jsxs(YStack, { gap: "$2", children: [
1090
+ /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", children: [
1091
+ /* @__PURE__ */ jsx(Link2, { size: 16 }),
1092
+ /* @__PURE__ */ jsx(Text, { fontSize: "$5", fontWeight: "500", children: "Accounts" })
1093
+ ] }),
1094
+ /* @__PURE__ */ jsx(
1095
+ DataTable,
1096
+ {
1097
+ columns: ACCOUNT_COLUMNS,
1098
+ rows: accounts,
1099
+ loading: state.phase === "loading",
1100
+ empty: "No accounts connected yet.",
1101
+ rowKey: (a) => a.id
1102
+ }
1103
+ )
1104
+ ] })
1105
+ ] }),
1106
+ /* @__PURE__ */ jsx(SlideOver, { open: composing, onClose: () => setComposing(false), title: "New post", icon: Send, ariaLabel: "New post", children: /* @__PURE__ */ jsx(PostComposer, { channels: [...PROVIDERS], providers, onSubmit: submitDraft }) }),
1107
+ /* @__PURE__ */ jsx(
1108
+ SlideOver,
1109
+ {
1110
+ open: connecting,
1111
+ onClose: () => setConnecting(false),
1112
+ title: "Connect account",
1113
+ icon: Link2,
1114
+ ariaLabel: "Connect account",
1115
+ children: /* @__PURE__ */ jsx(
1116
+ ConnectAccount,
1117
+ {
1118
+ api,
1119
+ providers,
1120
+ onCreated: () => {
1121
+ setConnecting(false);
1122
+ void load();
1123
+ }
1124
+ }
1125
+ )
1126
+ }
1127
+ ),
1128
+ /* @__PURE__ */ jsx(SlideOver, { open: openPost !== null, onClose: () => setOpenPost(null), title: "Post", icon: Send, ariaLabel: "Post detail", children: openPost ? /* @__PURE__ */ jsx(
1129
+ PostDetail,
1130
+ {
1131
+ api,
1132
+ post: openPost,
1133
+ onChanged: () => {
1134
+ setOpenPost(null);
1135
+ void load();
1136
+ }
1137
+ }
1138
+ ) : null })
1139
+ ] });
1140
+ }
1141
+ var META = {
1142
+ x: { label: "X", bg: "#0f0f12", fg: "#e6e6ea", mark: "\u{1D54F}" },
1143
+ facebook: { label: "Facebook", bg: "#1877f2", fg: "#ffffff", mark: "f" },
1144
+ instagram: { label: "Instagram", bg: "#e1306c", fg: "#ffffff", mark: "IG" },
1145
+ linkedin: { label: "LinkedIn", bg: "#0a66c2", fg: "#ffffff", mark: "in" },
1146
+ tiktok: { label: "TikTok", bg: "#111114", fg: "#25f4ee", mark: "TT" },
1147
+ youtube: { label: "YouTube", bg: "#ff0000", fg: "#ffffff", mark: "\u25B6" },
1148
+ threads: { label: "Threads", bg: "#111114", fg: "#e6e6ea", mark: "@" }
1149
+ };
1150
+ function ChannelBadge({
1151
+ channel,
1152
+ showLabel = false,
1153
+ size = 22
1154
+ }) {
1155
+ const m = META[channel] ?? META.x;
1156
+ return /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", children: [
1157
+ /* @__PURE__ */ jsx(
1158
+ YStack,
1159
+ {
1160
+ width: size,
1161
+ height: size,
1162
+ items: "center",
1163
+ justify: "center",
1164
+ rounded: "$2",
1165
+ bg: m.bg,
1166
+ children: /* @__PURE__ */ jsx(Text, { fontSize: "$1", fontWeight: "800", color: m.fg, children: m.mark })
1167
+ }
1168
+ ),
1169
+ showLabel ? /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color12", children: m.label }) : null
1170
+ ] });
1171
+ }
1172
+ var money = (cents) => `$${Math.round((cents || 0) / 100).toLocaleString()}`;
1173
+ function CampaignCard({ campaign }) {
1174
+ const pct = campaign.budget > 0 ? Math.min(100, campaign.spend / campaign.budget * 100) : 0;
1175
+ return /* @__PURE__ */ jsxs(Card, { p: "$4", gap: "$3", borderWidth: 1, borderColor: "$borderColor", width: "100%", children: [
1176
+ /* @__PURE__ */ jsxs(XStack, { items: "flex-start", justify: "space-between", gap: "$2", children: [
1177
+ /* @__PURE__ */ jsxs(YStack, { gap: "$1", children: [
1178
+ /* @__PURE__ */ jsx(Text, { fontSize: "$4", fontWeight: "700", children: campaign.name }),
1179
+ /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", children: campaign.channel })
1180
+ ] }),
1181
+ /* @__PURE__ */ jsx(StatusTag, { status: campaign.status })
1182
+ ] }),
1183
+ campaign.objective ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", children: campaign.objective }) : null,
1184
+ /* @__PURE__ */ jsxs(YStack, { gap: "$1.5", children: [
1185
+ /* @__PURE__ */ jsxs(XStack, { justify: "space-between", children: [
1186
+ /* @__PURE__ */ jsxs(Text, { fontSize: "$1", color: "$color11", children: [
1187
+ money(campaign.spend),
1188
+ " spent"
1189
+ ] }),
1190
+ /* @__PURE__ */ jsxs(Text, { fontSize: "$1", color: "$color11", children: [
1191
+ money(campaign.budget),
1192
+ " budget"
1193
+ ] })
1194
+ ] }),
1195
+ /* @__PURE__ */ jsx(YStack, { height: 6, rounded: "$2", bg: "$color3", overflow: "hidden", children: /* @__PURE__ */ jsx(YStack, { height: 6, rounded: "$2", bg: "$color9", width: `${pct}%` }) })
1196
+ ] })
1197
+ ] });
1198
+ }
1199
+ function PostCard({
1200
+ post,
1201
+ onEdit,
1202
+ onDelete
1203
+ }) {
1204
+ const mediaCount = post.media?.length ?? 0;
1205
+ return /* @__PURE__ */ jsxs(Card, { p: "$3", gap: "$2.5", borderWidth: 1, borderColor: "$borderColor", width: "100%", children: [
1206
+ /* @__PURE__ */ jsxs(XStack, { items: "center", justify: "space-between", gap: "$2", children: [
1207
+ /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", children: [
1208
+ /* @__PURE__ */ jsx(ChannelBadge, { channel: post.channel }),
1209
+ /* @__PURE__ */ jsx(StatusTag, { status: post.status })
1210
+ ] }),
1211
+ /* @__PURE__ */ jsxs(XStack, { gap: "$1", children: [
1212
+ onEdit ? /* @__PURE__ */ jsx(Button, { size: "$2", chromeless: true, icon: /* @__PURE__ */ jsx(Pencil, { size: 15 }), onPress: () => onEdit(post) }) : null,
1213
+ onDelete ? /* @__PURE__ */ jsx(Button, { size: "$2", chromeless: true, icon: /* @__PURE__ */ jsx(Trash2, { size: 15 }), onPress: () => onDelete(post) }) : null
1214
+ ] })
1215
+ ] }),
1216
+ /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color12", children: post.content }),
1217
+ /* @__PURE__ */ jsxs(XStack, { items: "center", justify: "space-between", gap: "$2", children: [
1218
+ post.scheduleAt ? /* @__PURE__ */ jsx(Text, { fontSize: "$1", color: "$color11", children: formatPostTime(post.scheduleAt) }) : /* @__PURE__ */ jsx(YStack, {}),
1219
+ mediaCount ? /* @__PURE__ */ jsxs(Text, { fontSize: "$1", color: "$color10", children: [
1220
+ mediaCount,
1221
+ " media"
1222
+ ] }) : null
1223
+ ] })
1224
+ ] });
1225
+ }
1226
+
1227
+ export { ACCOUNT_STATUSES, BackendStateCard, COMPOSE_MODES, CampaignCard, ChannelBadge, DataTable, EmptyState, FieldRow, FieldSelect, FieldSlider, FieldSwitch, FieldText, FieldTextArea, HostProvider, LG, POST_STATUSES, PROVIDERS, PageHeader, PostAgenda, PostCard, PostComposer, PrimaryButton, ProviderReadinessList, SlideOver, SocialResource, SocialSummaryBar, StatusTag, ViewToggle, accentFor, asColor, classifyBackend, classifyRead, contrastText, createSocialApi, formatPostTime, isHexColor, normalizeAccount, normalizeAccounts, normalizePost, normalizePosts, normalizeProviderCapability, normalizeProviders, normalizeSummary, parsePostTime, postDayBucket, postPreview, resolveAccent, setOrgAccent, useAccent, useHost };
1228
+ //# sourceMappingURL=chunk-YAYUPOE3.js.map
1229
+ //# sourceMappingURL=chunk-YAYUPOE3.js.map