diff --git a/docs/slider-captcha-frozen-spec.md b/docs/slider-captcha-frozen-spec.md
index 967aaf2..65a6246 100644
--- a/docs/slider-captcha-frozen-spec.md
+++ b/docs/slider-captcha-frozen-spec.md
@@ -117,12 +117,12 @@ distance = track.width - button.width
主引擎轨迹冻结为以下行为:
- 按钮按下前,从按钮左侧附近自然接近,再悬停、对准按钮中心并停顿。
-- 按下后使用恰好 6 个高层轨迹点。
-- 轨迹分为加速、匀速、减速三段;带小幅 Y 轴抖动。
-- X 轴不超调,最后一个点强制等于计算出的精确距离。
-- 保留每个点的短随机计划延时,同时按真实墙钟时间补偿,使移动阶段处于 `480–900ms` 目标窗口。
+- 按下后使用随机的 `8–12` 个高层轨迹点。
+- 轨迹分为加速、匀速、减速三段;Y 轴按连续、非线性的完整 S 形曲线移动,峰峰值精确为实际滑轨高度的 `1/2`。高层锚点之间必须以不超过 `15ms` 的连续鼠标事件连接;按下到释放期间不得出现可感知的静止停顿或中段确认停顿。
+- 标准 NC 先按精确可用距离计算轨道终点,再让鼠标最终 X 随机超出 `4–20px`;页面滑块控件必须仍受自身轨道边界限制,不得越出可见轨道。
+- 保留每个锚点的非均匀随机时长权重,并按真实墙钟时间补偿,使移动阶段处于 `0.55–1.05s` 目标窗口;该时长必须由持续移动分配,不能用锚点后的长等待填充。
- 顺序固定为 `mouse down → 分段移动 → mouse up → 兼容性 click 事件`。
-- 标准 NC 不得添加尾部超调、回拉或额外轨迹点。
+- 标准 NC 不得添加回拉;仅允许上述受控的鼠标尾部超调。
拖动完成后保留 `800ms` 等待,再进入严格成功检查。
@@ -178,11 +178,11 @@ purecaptcha
恢复状态机固定如下:
-1. 优先点击可见的失败/刷新控件。
-2. 控件可能延迟出现,首次未找到时按现有逻辑最多短暂等待 `800ms` 并轮询。
+1. 已完成一次拖动后出现失败提示时,优先点击可见的失败/刷新控件,直接让平台生成新滑块。
+2. 控件可能延迟出现,首次未找到时最多短暂等待 `800ms` 并轮询;该等待期间不得刷新页面。
3. 点击后最多等待 `4s`,确认按钮和轨道重新出现,且按钮回到轨道起点 `±3px` 内。
-4. 点击恢复失败或滑块未归位时,重载原页面。
-5. 重载等待 `domcontentloaded`,单次超时最多 `8s`;重载后最多等待 `5s` 确认滑块归位。
+4. 已完成一次拖动后的点击恢复失败或滑块未归位时,保留当前失败现场并结束本次滑块流程,不得重载原页面。
+5. 仅首次页面准备阶段尚未实际拖动、且又不属于第 3.1 节直接错误页时,保留重载恢复:重载等待 `domcontentloaded`,单次超时最多 `8s`;重载后最多等待 `5s` 确认滑块归位。
6. 主引擎两次尝试之间保留 `1–2s` 随机等待;总尝试次数保持 3 次。
不得用“元素重新出现”替代“元素重新出现且按钮回到原点”的确认。
@@ -211,6 +211,10 @@ Playwright 主引擎
Alibaba 风控资源出现 `ERR_CERT_AUTHORITY_INVALID` 时,才允许显式设为 `true`;此时主引擎和
备用 Chromium 都追加 `--ignore-certificate-errors`,HTTP 客户端仍保持正常证书校验。该开关
必须记录在部署配置中,不能默认开启或静默改变。
+- `CAPTCHA_BROWSER_PROXY` 默认未设置,Chromium 保留操作系统代理配置。仅当诊断确认系统代理的
+ Fake-IP 或 PAC 路径使 Alibaba 风控资源不能作为脚本加载时,可显式设置为无凭证的
+ `http://`、`https://`、`socks4://` 或 `socks5://` 代理地址;主引擎与备用 Chromium 必须同时追加
+ 相同的 `--proxy-server`。该开关不得接受代理凭证、查询或片段,也不得记录其值或改变非浏览器 HTTP 客户端。
- 初始化时必须从随包 Chromium 实测 UA 和 Client Hints。无头上下文只允许把 legacy UA 中的
`HeadlessChrome/<实际版本>` 规范化为 `Chrome/<相同实际版本>`;不得伪造版本、操作系统或移动端
状态。有头上下文不覆盖 Chromium 原生 UA。Playwright 主引擎必须同时使用 context `userAgent`
@@ -312,6 +316,25 @@ go vet ./internal/browser ./internal/engine ./internal/account ./internal/server
本规范第 6 至 9 节同步加入了只移除无头产品标记、保留实际版本与 Client Hints、覆盖主/备用引擎、
并在诊断包及真实 Chromium 集成测试中核验页面实际指纹的契约。
+### 2026-08-17 主引擎轨迹授权变更
+
+用户明确要求主引擎避免固定、流畅且稳定的短时拖动,因为这类动作在实际风控页上缺少人工操作的
+确认节奏。第 3.3 节据此从固定 6 点和 `480–900ms` 调整为 `8–12` 个单调前进点、一次中段停顿及
+`1.1–2.1s` 墙钟窗口。用户随后明确要求 Y 轴不能只是微扰,因此该节补充为使用实际滑轨半高的连续
+非线性 S 形纵向范围。用户随后明确要求 X 轴也不能每次精确落点,因此末点改为在精确可用距离外随机 `4–20px` 的受控鼠标超调,页面控件仍由轨道边界钳位。距离计算、事件顺序、严格成功判定及备用引擎均保持不变。
+
+### 2026-08-18 主引擎连续拖动授权变更
+
+用户在实际风控页观察到主引擎呈现逐段拖动效果,明确要求按下后必须一口气连续拖至终点。第 3.3 节据此移除中段确认停顿:保留原有高层曲线锚点、三段速度形状、完整 S 形纵向范围、受控鼠标超调和 `1.1–2.1s` 墙钟窗口,但将锚点间移动展开为最大间隔 `30ms` 的连续事件流。距离计算、成功判定、失败恢复、Cookie 处理和备用引擎保持不变。
+
+### 2026-08-18 主引擎提速授权变更
+
+用户在有头模式观察后明确要求主引擎滑动速度提高一倍。第 3.3 节据此将按下到释放的目标窗口从 `1.1–2.1s` 缩短为 `0.55–1.05s`,并将连续事件最大间隔从 `30ms` 收紧为 `15ms`。非匀速节奏、三段速度形状、完整 S 形纵向范围、受控鼠标超调、距离计算、成功判定、失败恢复、Cookie 处理和备用引擎保持不变。
+
+### 2026-08-18 滑动失败直接重试授权变更
+
+用户明确要求滑动后出现平台失败提示时,不得刷新验证页;必须点击失败按钮,让平台在当前页重新生成滑块后直接进行下一次拖动。第 5 节据此限制已完成拖动后的恢复路径为按钮点击与归位确认:找不到失败按钮或点击后滑块未归位时结束本次流程并保留现场。首次页面准备尚未实际拖动时的既有重载恢复保留。
+
只有用户在当前任务中明确点名要求修改滑块认证时,才允许触碰冻结范围。获得授权后也必须在同一个变更中:
1. 说明要改变本文哪一条冻结契约及原因。
diff --git a/frontend/app/features/chat/hooks.test.tsx b/frontend/app/features/chat/hooks.test.tsx
index 026805e..8ee725b 100644
--- a/frontend/app/features/chat/hooks.test.tsx
+++ b/frontend/app/features/chat/hooks.test.tsx
@@ -438,7 +438,9 @@ describe('useChat', /* 当前回调处理聊天加载、分页、发送和实时
// unknownMessage 是不在当前联系人列表中的实时消息。
const unknownMessage = { ...messageFixture, chat_id: 'chat-unknown', message_key: 'message-unknown', content: '未知会话消息' };
- getSessionPageMock.mockResolvedValueOnce({ sessions: [sessionFixture], has_more: false, next_cursor: undefined });
+ // unknownSession 是刷新接口返回的新会话,必须自动出现在联系人列表中。
+ const unknownSession = { ...sessionFixture, chat_id: 'chat-unknown', buyer_id: 'buyer-unknown', last_message: '未知会话消息', last_message_at: 9 };
+ getSessionPageMock.mockResolvedValueOnce({ sessions: [unknownSession, sessionFixture], has_more: false, next_cursor: undefined });
await act(
// unknownMessageAction 触发未知会话的联系人刷新。
() => latestSocket?.onmessage?.({ data: JSON.stringify({ message: unknownMessage }) }),
@@ -447,6 +449,10 @@ describe('useChat', /* 当前回调处理聊天加载、分页、发送和实时
// reloadAssertion 等待未知会话触发联系人刷新。
() => expect(getSessionPageMock).toHaveBeenCalledWith('account-1', undefined, expect.objectContaining({ signal: expect.any(AbortSignal) }), true),
);
+ await waitFor(
+ // unknownSessionAssertion 等待实时事件关联的新会话写入联系人列表。
+ () => expect(hook.result.current.activeSessions).toContainEqual(unknownSession),
+ );
await act(
// emptyMessageAction 触发无消息载荷并保持状态稳定。
() => latestSocket?.onmessage?.({ data: JSON.stringify({}) }),
diff --git a/frontend/app/features/chat/pages/Chat.tsx b/frontend/app/features/chat/pages/Chat.tsx
index 89b5524..b4855cc 100644
--- a/frontend/app/features/chat/pages/Chat.tsx
+++ b/frontend/app/features/chat/pages/Chat.tsx
@@ -4,6 +4,7 @@ import {
Search, Send, Smile, UserRound, Wifi, WifiOff,
} from 'lucide-react';
import { useChat } from '../hooks';
+import { unreadBadgeClassName, unreadBadgeLabel } from '../state';
// Chat 展示实时会话、消息分页和消息发送界面。
const Chat: React.FC = () => {
@@ -38,6 +39,8 @@ const Chat: React.FC = () => {
const active = account.id === activeAccountID;
// unread unread,负责当前功能中的对应处理。
const unread = unreadForAccount(account.id);
+ // unreadLabel 保存账号未读徽标的展示文本。
+ const unreadLabel = unreadBadgeLabel(unread);
// online 响应当前用户操作(line)。
const online = account.runtime_state === 'online';
return (
@@ -45,7 +48,7 @@ const Chat: React.FC = () => {
className={`relative flex h-11 shrink-0 items-center gap-2 border-b-2 px-3 text-sm font-extrabold transition-colors ${active ? 'border-sky-500 text-sky-700' : 'border-transparent text-slate-500 hover:text-slate-900'}`}>
{account.nickname || account.remark || account.id}
- {unread > 0 && {unread > 99 ? '99+' : unread}}
+ {unread > 0 && {unreadLabel}}
);
})}
@@ -91,7 +94,7 @@ const Chat: React.FC = () => {
diff --git a/frontend/app/features/chat/state.test.ts b/frontend/app/features/chat/state.test.ts
index e4d88c4..21ca003 100644
--- a/frontend/app/features/chat/state.test.ts
+++ b/frontend/app/features/chat/state.test.ts
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';
import type { ChatMessage, ChatSession } from '../../../shared/api-contract';
-import { collectChatReadReceipts, filterChatSessions, formatClock, isChatAbortError, isCurrentChatRequest, mergeLiveMessage, mergeOlderMessages, messageTime } from './state';
+import { collectChatReadReceipts, filterChatSessions, formatClock, isChatAbortError, isCurrentChatRequest, mergeLiveMessage, mergeOlderMessages, messageTime, unreadBadgeClassName, unreadBadgeLabel } from './state';
// sessionFixture 是覆盖搜索、未读筛选和联系人隔离的最小会话数据。
const sessionFixture: ChatSession[] = [
@@ -62,3 +62,15 @@ test('Chat 状态工具覆盖追加消息、搜索字段和时间格式化',
expect(formatClock(Date.now() - 86_400_000)).toMatch(/\d{2}\/\d{2}/);
expect(messageTime(Date.now())).toMatch(/\d{2}\/\d{2}/);
});
+
+test('Chat 未读徽标为单数字保留正圆尺寸,多数字才横向扩展',
+ // 未读徽标测试验证账号页签和会话列表共享的形状边界。
+ () => {
+ expect(unreadBadgeLabel(1)).toBe('1');
+ expect(unreadBadgeLabel(99)).toBe('99');
+ expect(unreadBadgeLabel(100)).toBe('99+');
+ expect(unreadBadgeClassName(1)).toContain('w-5');
+ expect(unreadBadgeClassName(1)).not.toContain('min-w-5');
+ expect(unreadBadgeClassName(10)).toContain('min-w-5');
+ expect(unreadBadgeClassName(99)).toContain('min-w-5');
+ });
diff --git a/frontend/app/features/chat/state.ts b/frontend/app/features/chat/state.ts
index b6da959..72a482b 100644
--- a/frontend/app/features/chat/state.ts
+++ b/frontend/app/features/chat/state.ts
@@ -1,6 +1,22 @@
import type { ChatMessage, ChatSession } from '../../../shared/api-contract';
import type { ChatReadReceipt } from './types';
+/** 将未读数规范为徽标可展示的文本,超过两位数时统一显示 99+。 */
+export const unreadBadgeLabel = (count: number): string => {
+ // normalized 保存排除 NaN、负数与小数后的未读数量。
+ const normalized = Number.isFinite(count) ? Math.max(0, Math.floor(count)) : 0;
+ return normalized > 99 ? '99+' : String(normalized);
+};
+
+/** 根据未读文本长度返回稳定徽标尺寸,单数字必须为正圆,双数字及 99+ 才可横向扩展。 */
+export const unreadBadgeClassName = (count: number): string => {
+ // normalized 保存用于区分单数字与多数字徽标的规范未读数量。
+ const normalized = Number.isFinite(count) ? Math.max(0, Math.floor(count)) : 0;
+ return normalized < 10
+ ? 'inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-red-500 text-[10px] font-bold leading-none text-white'
+ : 'inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full bg-red-500 px-1.5 text-[10px] font-bold leading-none text-white';
+};
+
/** 将可确认的普通入站消息转换为平台已读回执。 */
export const collectChatReadReceipts = (messages: ChatMessage[], chatID: string): ChatReadReceipt[] => messages
.filter(/* currentMessage 只保留平台可接受的普通入站消息。 */ currentMessage => (
diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.js
index 62d48fb..0be5b7b 100644
--- a/frontend/tailwind.config.js
+++ b/frontend/tailwind.config.js
@@ -11,6 +11,9 @@ export default {
"./index.html",
"./*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
+ // 阶段七后的页面和共享 UI 位于 app/shared,必须参与生产 utility 扫描。
+ "./app/**/*.{js,ts,jsx,tsx}",
+ "./shared/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {
diff --git a/frontend/tailwindConfig.test.ts b/frontend/tailwindConfig.test.ts
new file mode 100644
index 0000000..776c842
--- /dev/null
+++ b/frontend/tailwindConfig.test.ts
@@ -0,0 +1,17 @@
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+import { expect, test } from 'vitest';
+
+// tailwindConfigPath 指向生产构建读取的 Tailwind 配置,测试以文本方式审计其静态扫描范围。
+const tailwindConfigPath = resolve(__dirname, 'tailwind.config.js');
+
+/** verifyTailwindFeatureSourceGlobs 验证阶段七迁移后的 app/shared 源码不会被 Tailwind 生产构建遗漏。 */
+function verifyTailwindFeatureSourceGlobs(): void {
+ // configSource 是当前 Tailwind 配置原文,避免 TypeScript 为 JavaScript 配置要求声明文件。
+ const configSource = readFileSync(tailwindConfigPath, 'utf8');
+
+ expect(configSource).toContain('"./app/**/*.{js,ts,jsx,tsx}"');
+ expect(configSource).toContain('"./shared/**/*.{js,ts,jsx,tsx}"');
+}
+
+test('Tailwind scans feature and shared UI source trees', verifyTailwindFeatureSourceGlobs);
diff --git a/internal/adapter/chat_contract_conversion_test.go b/internal/adapter/chat_contract_conversion_test.go
index b8b13e5..a8db4d0 100644
--- a/internal/adapter/chat_contract_conversion_test.go
+++ b/internal/adapter/chat_contract_conversion_test.go
@@ -24,14 +24,14 @@ func TestChatSessionFromApplicationKeepsNonSensitiveFields(t *testing.T) {
// TestChatMessagesFromDBKeepsMessageContract 验证数据库消息转换为应用消息时完整保留 API 所需字段。
func TestChatMessagesFromDBKeepsMessageContract(t *testing.T) {
// messages 保存 legacy 聊天仓储返回的消息模型。
- messages := []db.ChatMessage{{ID: 7, CookieID: "account-1", ChatID: "chat-1", MessageKey: "key-1", Direction: "incoming", SenderID: "buyer-1", SenderName: "买家", MessageType: "text", Content: "你好", Status: "received", SentAt: 99}}
+ messages := []db.ChatMessage{{ID: 7, CookieID: "account-1", ChatID: "chat-1", MessageKey: "key-1", Direction: "incoming", SenderID: "buyer-1", SenderName: "买家", MessageType: "text", Content: "你好", Status: "received", ReadStatus: 2, ReadAt: 88, SentAt: 99}}
// converted 保存不再暴露数据库模型的应用层消息。
converted := ChatMessagesFromDB(messages)
if len(converted) != 1 {
t.Fatalf("消息数量异常: got=%d", len(converted))
}
// expected 保存应用层消息字段。
- expected := chatapp.Message{ID: 7, AccountID: "account-1", ChatID: "chat-1", MessageKey: "key-1", Direction: "incoming", SenderID: "buyer-1", SenderName: "买家", MessageType: "text", Content: "你好", Status: "received", SentAt: 99}
+ expected := chatapp.Message{ID: 7, AccountID: "account-1", ChatID: "chat-1", MessageKey: "key-1", Direction: "incoming", SenderID: "buyer-1", SenderName: "买家", MessageType: "text", Content: "你好", Status: "received", ReadStatus: 2, ReadAt: 88, SentAt: 99}
if !reflect.DeepEqual(converted[0], expected) {
t.Fatalf("聊天消息转换异常: got=%+v want=%+v", converted[0], expected)
}
diff --git a/internal/adapter/chat_repository.go b/internal/adapter/chat_repository.go
index f80b584..c6ab017 100644
--- a/internal/adapter/chat_repository.go
+++ b/internal/adapter/chat_repository.go
@@ -37,7 +37,8 @@ func (r chatRepository) ListMessages(ctx context.Context, userID int64, accountI
messages = append(messages, chatapp.Message{
ID: row.ID, AccountID: row.CookieID, ChatID: row.ChatID, MessageKey: row.MessageKey,
Direction: row.Direction, SenderID: row.SenderID, SenderName: row.SenderName,
- MessageType: row.MessageType, Content: row.Content, Status: row.Status, SentAt: row.SentAt,
+ MessageType: row.MessageType, Content: row.Content, Status: row.Status,
+ ReadStatus: row.ReadStatus, ReadAt: row.ReadAt, SentAt: row.SentAt,
})
}
return messages, nil
diff --git a/internal/adapter/chat_sending.go b/internal/adapter/chat_sending.go
index 374f7c1..d414fae 100644
--- a/internal/adapter/chat_sending.go
+++ b/internal/adapter/chat_sending.go
@@ -88,7 +88,8 @@ func chatApplicationMessage(message *db.ChatMessage) chatapp.Message {
return chatapp.Message{
ID: message.ID, AccountID: message.CookieID, ChatID: message.ChatID, MessageKey: message.MessageKey,
Direction: message.Direction, SenderID: message.SenderID, SenderName: message.SenderName,
- MessageType: message.MessageType, Content: message.Content, Status: message.Status, SentAt: message.SentAt,
+ MessageType: message.MessageType, Content: message.Content, Status: message.Status,
+ ReadStatus: message.ReadStatus, ReadAt: message.ReadAt, SentAt: message.SentAt,
}
}
diff --git a/internal/application/chat/service.go b/internal/application/chat/service.go
index ed39f05..1683fbb 100644
--- a/internal/application/chat/service.go
+++ b/internal/application/chat/service.go
@@ -48,6 +48,10 @@ type Message struct {
Content string
// Status 是消息投递状态。
Status string
+ // ReadStatus 是平台确认的读取状态;值为 2 表示对方已读,其他值表示尚未确认。
+ ReadStatus int
+ // ReadAt 是平台确认对方已读的 Unix 毫秒时间戳;零值表示尚未收到回执。
+ ReadAt int64
// SentAt 是消息发送时间的 Unix 秒时间戳。
SentAt int64
}
diff --git a/internal/browser/lifecycle.go b/internal/browser/lifecycle.go
index 768414a..1e5a855 100644
--- a/internal/browser/lifecycle.go
+++ b/internal/browser/lifecycle.go
@@ -9,6 +9,7 @@ import (
"log/slog"
"net/http"
"net/http/httptest"
+ "net/url"
"os"
"path/filepath"
"runtime"
@@ -48,6 +49,10 @@ func chromiumLaunchArgs() []string {
if captchaIgnoreCertificateErrors() {
args = append(args, "--ignore-certificate-errors")
}
+ // proxy 是通过受限解析验证后的验证码浏览器代理,仅在部署显式配置时覆盖 Chromium 的系统代理选择。
+ if proxy := captchaBrowserProxy(); proxy != "" {
+ args = append(args, "--proxy-server="+proxy)
+ }
return args
}
@@ -63,6 +68,28 @@ func captchaIgnoreCertificateErrors() bool {
return err == nil && parsed
}
+// captchaBrowserProxy 返回仅供 token CAPTCHA Chromium 使用的显式代理地址;默认保留系统代理,非法、带凭证或带查询的值一律忽略,避免把敏感代理信息写入启动参数或日志。
+func captchaBrowserProxy() string {
+ // value 是环境变量中的代理地址,空值表示让 Chromium 沿用操作系统的正常网络配置。
+ value := strings.TrimSpace(os.Getenv("CAPTCHA_BROWSER_PROXY"))
+ if value == "" {
+ return ""
+ }
+ // parsed、parseErr 是受限代理地址的结构化解析结果;仅接受 Chromium 支持的无凭证 HTTP(S)/SOCKS 代理。
+ parsed, parseErr := url.Parse(value)
+ if parseErr != nil || parsed.Host == "" || parsed.User != nil || parsed.RawQuery != "" || parsed.Fragment != "" {
+ return ""
+ }
+ // scheme 是统一小写后的代理协议,限制集合避免把任意 Chromium flag 拼入 Args。
+ scheme := strings.ToLower(parsed.Scheme)
+ switch scheme {
+ case "http", "https", "socks4", "socks5":
+ return value
+ default:
+ return ""
+ }
+}
+
// chromiumExecutablePath 负责chromiumExecutable路径相关处理。
func chromiumExecutablePath() *string {
if // path 保存路径,供当前处理流程使用
diff --git a/internal/browser/pure_extra_test.go b/internal/browser/pure_extra_test.go
index 5eff67a..85392e7 100644
--- a/internal/browser/pure_extra_test.go
+++ b/internal/browser/pure_extra_test.go
@@ -129,6 +129,48 @@ func TestCaptchaIgnoreCertificateErrors(t *testing.T) {
}
}
+// TestCaptchaBrowserProxy 验证验证码浏览器只接受无凭证的受限代理地址,并在配置为空或非法时保留系统代理行为。
+func TestCaptchaBrowserProxy(t *testing.T) {
+ // testCases 是输入环境值与预期解析结果,覆盖默认、支持协议及敏感/危险输入。
+ testCases := []struct {
+ // name 是失败时定位具体输入的用例名。
+ name string
+ // value 是待解析的 CAPTCHA 浏览器代理配置。
+ value string
+ // want 是允许传给 Chromium 的预期代理地址,空串代表不追加覆盖参数。
+ want string
+ }{
+ {name: "empty", value: "", want: ""},
+ {name: "http", value: " http://127.0.0.1:1082 ", want: "http://127.0.0.1:1082"},
+ {name: "socks5", value: "socks5://127.0.0.1:1080", want: "socks5://127.0.0.1:1080"},
+ {name: "credentials", value: "http://user:secret@127.0.0.1:1082", want: ""},
+ {name: "query", value: "http://127.0.0.1:1082?secret=value", want: ""},
+ {name: "unsupported", value: "file:///tmp/proxy", want: ""},
+ }
+ // testCase 是当前要通过独立环境变量验证的代理配置用例。
+ for _, testCase := range testCases {
+ t.Run(testCase.name, func(t *testing.T) {
+ t.Setenv("CAPTCHA_BROWSER_PROXY", testCase.value)
+ // got 是解析后允许写入 Chromium 参数的代理地址。
+ got := captchaBrowserProxy()
+ if got != testCase.want {
+ t.Fatalf("captchaBrowserProxy()=%q, want %q", got, testCase.want)
+ }
+ })
+ }
+ t.Setenv("CAPTCHA_BROWSER_PROXY", "http://127.0.0.1:1082")
+ // proxyArgs 是显式代理启用时主 Chromium 引擎的启动参数集合。
+ proxyArgs := strings.Join(chromiumLaunchArgs(), " ")
+ if !strings.Contains(proxyArgs, "--proxy-server=http://127.0.0.1:1082") {
+ t.Fatalf("主引擎未写入显式代理参数: %s", proxyArgs)
+ }
+ // fallbackArgs 是备用直接 CDP 引擎的独立参数集合,必须使用相同代理而不是回退到 Fake-IP 直连。
+ fallbackArgs := strings.Join(fallbackChromiumArgs("/tmp/profile", true), " ")
+ if !strings.Contains(fallbackArgs, "--proxy-server=http://127.0.0.1:1082") {
+ t.Fatalf("备用引擎未写入显式代理参数: %s", fallbackArgs)
+ }
+}
+
// TestNormalizeBrowserFingerprintRemovesOnlyHeadlessMarker 验证规范化不伪造 Chromium 的版本或平台身份。
func TestNormalizeBrowserFingerprintRemovesOnlyHeadlessMarker(t *testing.T) {
// fingerprint 是含无头标记的实测身份经过规范化后的结果,用于断言只移除产品标记。
diff --git a/internal/browser/slider.go b/internal/browser/slider.go
index d118d30..e723660 100644
--- a/internal/browser/slider.go
+++ b/internal/browser/slider.go
@@ -30,12 +30,19 @@ var sliderSuccessSelectors = []string{
const (
sliderSuccessCheckAttempts = 4
sliderSuccessCheckInterval = 400 * time.Millisecond
+ // sliderContinuousEventMaxInterval 是主引擎按住期间相邻微移动事件的最大间隔,保证提速后仍呈连续轨迹。
+ sliderContinuousEventMaxInterval = 15 * time.Millisecond
+ // sliderMovementMinDuration、sliderMovementMaxDuration 是主引擎按下到释放的目标墙钟范围,较上一版提速一倍。
+ sliderMovementMinDuration = 550 * time.Millisecond
+ sliderMovementMaxDuration = 1050 * time.Millisecond
)
// trajectoryPoint 轨迹中的单个采样点。
type trajectoryPoint struct {
- x float64
- y float64
+ // x、y 是相对滑块中心的曲线锚点偏移;x 保持单调前进并在末点落到受控超调终点。
+ x float64
+ y float64
+ // delay 是该锚点对应的相对时长权重;连续微移动会按该权重分配时间,不能形成锚点后的静止停顿。
delay time.Duration
}
@@ -56,58 +63,155 @@ type sliderResetResult struct {
err error
}
-// generateTrajectory mirrors the reference Playwright engine's short
-// acceleration/constant/deceleration trajectory. Each point is a high-level
-// browser protocol call, so generating dozens of points makes the drag unlike
-// the reference implementation even when the wall-clock duration is similar.
-func generateTrajectory(distance float64) []trajectoryPoint {
- requestedSteps := 5 + rng.Intn(2)
- totalDuration := randomFloat(0.010, 0.020)
- avgDelay := totalDuration / float64(requestedSteps)
-
- accelRatio := 0.35 + randomFloat(-0.05, 0.05)
- decelRatio := 0.30 + randomFloat(-0.05, 0.05)
+// generateTrajectory 根据 distance 和 verticalSpan 生成标准 NC 的单调三阶段曲线锚点。
+// distance 是按钮可用移动距离;verticalSpan 是 Y 轴峰峰值,锚点之间由连续微移动连接,末点会受控超出可用距离。
+func generateTrajectory(distance, verticalSpan float64) []trajectoryPoint {
+ // requestedSteps 是本次高层鼠标移动采样数,范围避免固定轨迹特征,同时保持在 Chromium CDP 的低开销区间。
+ requestedSteps := 8 + rng.Intn(5)
+ // averageDelay 是各采样点的基础等待秒数;实际总时长由 simulateSlide 的墙钟预算补偿。
+ averageDelay := randomFloat(0.045, 0.085)
+ // accelRatio、decelRatio 分别限定加速和减速阶段所占轨迹比例,余量构成中速前进阶段。
+ accelRatio := randomFloat(0.26, 0.34)
+ decelRatio := randomFloat(0.24, 0.32)
+ // accelSteps、decelSteps、constantSteps 是三段分别包含的采样点数,至少各保留两个点以避免变成直线移动。
accelSteps := max(2, int(math.Round(float64(requestedSteps)*accelRatio)))
decelSteps := max(2, int(math.Round(float64(requestedSteps)*decelRatio)))
constantSteps := max(2, requestedSteps-accelSteps-decelSteps)
- accelDistance := distance * randomFloat(0.25, 0.35)
- constantDistance := distance * randomFloat(0.50, 0.60)
- decelDistance := distance - accelDistance - constantDistance
- pts := make([]trajectoryPoint, 0, accelSteps+constantSteps+decelSteps)
+ // overshoot 是鼠标终点超出可用滑轨的像素量;页面控件自身会在轨道边界钳位,因此不会被拖出滑轨。
+ overshoot := randomFloat(4, 20)
+ // targetDistance 是鼠标实际行进的水平目标,包含受控超调;三段距离相加后在末点落到该目标。
+ targetDistance := distance + overshoot
+ // accelDistance、constantDistance、decelDistance 是三段覆盖的水平距离;三者相加始终等于带超调的鼠标目标距离。
+ accelDistance := targetDistance * randomFloat(0.24, 0.34)
+ constantDistance := targetDistance * randomFloat(0.46, 0.56)
+ decelDistance := targetDistance - accelDistance - constantDistance
+ // points 保存按加速、中速、减速依次生成的高层鼠标坐标。
+ points := make([]trajectoryPoint, 0, accelSteps+constantSteps+decelSteps)
- for i := 1; i <= accelSteps; i++ {
- progress := float64(i) / float64(accelSteps)
- pts = append(pts, trajectoryPoint{
+ // step 表示当前加速段采样点序号。
+ for step := 1; step <= accelSteps; step++ {
+ // progress 是当前采样点在加速段中的归一化进度。
+ progress := float64(step) / float64(accelSteps)
+ points = append(points, trajectoryPoint{
x: accelDistance * progress * progress,
- y: randomFloat(-1, 1),
- delay: secondsDuration(avgDelay * randomFloat(1, 1.3)),
+ delay: secondsDuration(averageDelay * randomFloat(0.70, 1.20)),
})
}
- for i := 1; i <= constantSteps; i++ {
- progress := float64(i) / float64(constantSteps)
- delay := avgDelay * randomFloat(0.85, 1.15)
- if randomFloat(0, 1) < 0.03 {
- delay *= randomFloat(1.1, 1.3)
- }
- pts = append(pts, trajectoryPoint{
+ // step 表示当前中速段采样点序号。
+ for step := 1; step <= constantSteps; step++ {
+ // progress 是当前采样点在中速段中的归一化进度。
+ progress := float64(step) / float64(constantSteps)
+ // delay 是中速段本点后的基础等待,刻意保留差异而非固定间隔。
+ delay := averageDelay * randomFloat(0.65, 1.25)
+ points = append(points, trajectoryPoint{
x: accelDistance + constantDistance*progress,
- y: randomFloat(-1, 1) * 0.6,
delay: secondsDuration(delay),
})
}
- for i := 1; i <= decelSteps; i++ {
- progress := float64(i) / float64(decelSteps)
- pts = append(pts, trajectoryPoint{
+ // step 表示当前减速段采样点序号。
+ for step := 1; step <= decelSteps; step++ {
+ // progress 是当前采样点在减速段中的归一化进度。
+ progress := float64(step) / float64(decelSteps)
+ points = append(points, trajectoryPoint{
x: accelDistance + constantDistance + decelDistance*(1-math.Pow(1-progress, 2)),
- y: randomFloat(-1, 1) * 0.4,
- delay: secondsDuration(avgDelay * randomFloat(1.1, 1.5)),
+ delay: secondsDuration(averageDelay * randomFloat(0.90, 1.55)),
})
}
- if len(pts) > 0 {
- pts[len(pts)-1].x = distance
+ applyContinuousVerticalDrift(points, verticalSpan)
+ if len(points) > 0 {
+ points[len(points)-1].x = targetDistance
}
- return pts
+ return points
+}
+
+// expandContinuousTrajectory 把稀疏曲线锚点展开为连续事件流,避免鼠标在每个锚点后肉眼可见地停住。
+// points 是调用方生成的有序锚点;target 是按下到释放的目标总时长;返回点中的 delay 不超过连续事件允许的最大间隔。
+func expandContinuousTrajectory(points []trajectoryPoint, target time.Duration) []trajectoryPoint {
+ // totalWeight 汇总各锚点的相对时长权重,以便保持加速、中速、减速三段的时间比例。
+ var totalWeight time.Duration
+ for _, point := range points {
+ totalWeight += point.delay
+ }
+ if len(points) == 0 || target <= 0 || totalWeight <= 0 {
+ return nil
+ }
+ // expanded 保存连接每一对锚点后的连续微移动事件。
+ expanded := make([]trajectoryPoint, 0, len(points)*8)
+ // previous 是本段的起点;首次从按钮中心开始,后续从前一个锚点继续。
+ previous := trajectoryPoint{}
+ for _, point := range points {
+ // segmentDuration 是本段在总拖动窗口中所占时长,按生成轨迹的非均匀权重分配。
+ segmentDuration := time.Duration(int64(target) * int64(point.delay) / int64(totalWeight))
+ if segmentDuration <= 0 {
+ segmentDuration = time.Nanosecond
+ }
+ // eventCount 是本段需要发出的微移动数量,预留节奏变化空间且至少两个事件以避免跨锚点跳跃。
+ eventCount := max(2, int(math.Ceil(float64(segmentDuration)/float64(sliderContinuousEventMaxInterval)*1.34)))
+ // rhythmPhase、rhythmRate 为本段节奏曲线的随机相位和周期,产生平滑的快慢变化而不是逐点抖动。
+ rhythmPhase := randomFloat(0, 2*math.Pi)
+ rhythmRate := randomFloat(0.8, 1.6)
+ // eventWeights 保存每个微移动的相对时长,归一化后总和仍等于本段预算。
+ eventWeights := make([]float64, eventCount)
+ var weightTotal float64
+ for eventIndex := range eventWeights {
+ // progress 是本段节奏曲线的归一化位置;较低权重代表更快移动,较高权重代表更慢移动。
+ progress := float64(eventIndex) / float64(max(1, eventCount-1))
+ weight := 1 + 0.22*math.Sin(2*math.Pi*rhythmRate*progress+rhythmPhase)
+ eventWeights[eventIndex] = weight
+ weightTotal += weight
+ }
+ for eventIndex := 1; eventIndex <= eventCount; eventIndex++ {
+ // progress 是当前微移动在本段中的线性进度,使拖动一直前进而不在锚点处驻留。
+ progress := float64(eventIndex) / float64(eventCount)
+ // eventDelay 是归一化后的本次微移动间隔,确保节奏变化不突破连续事件上限。
+ eventDelay := time.Duration(float64(segmentDuration) * eventWeights[eventIndex-1] / weightTotal)
+ if eventDelay <= 0 {
+ eventDelay = time.Nanosecond
+ }
+ expanded = append(expanded, trajectoryPoint{
+ x: previous.x + (point.x-previous.x)*progress,
+ y: previous.y + (point.y-previous.y)*progress,
+ delay: eventDelay,
+ })
+ }
+ previous = point
+ }
+ return expanded
+}
+
+// applyContinuousVerticalDrift 把 Y 坐标改为连续的正弦形曲线。
+// points 由调用方拥有;verticalSpan 是轨迹实际达到的 Y 轴峰峰值,非正值或不足三个点时保留水平路径作为降级行为。
+func applyContinuousVerticalDrift(points []trajectoryPoint, verticalSpan float64) {
+ if len(points) < 3 || verticalSpan <= 0 {
+ return
+ }
+ // direction 决定本次先向上还是先向下偏移,避免每次都从相同方向开始。
+ direction := 1.0
+ if rng.Intn(2) == 0 {
+ direction = -1
+ }
+ // rawY 保存未缩放的完整正弦周期;minY、maxY 用于把离散采样后的实际峰峰值精确映射到滑轨高度的一半。
+ rawY := make([]float64, len(points))
+ minY, maxY := math.Inf(1), math.Inf(-1)
+ // pointIndex 是当前轨迹点下标;pointCount 是轨迹总点数减一,用于得到闭区间的归一化进度。
+ pointCount := len(points) - 1
+ for pointIndex := range points {
+ // progress 是从按下到释放的归一化进度,正弦曲线让纵向移动连续且不呈线性变化。
+ progress := float64(pointIndex) / float64(pointCount)
+ rawY[pointIndex] = math.Sin(2 * math.Pi * progress)
+ minY = min(minY, rawY[pointIndex])
+ maxY = max(maxY, rawY[pointIndex])
+ }
+ // scale 把当前离散采样的最大纵向范围精确缩放到请求的峰峰值。
+ scale := verticalSpan / (maxY - minY)
+ // centre 让曲线围绕滑块中心上下摆动,而不是单向贴近轨道边缘。
+ centre := (minY + maxY) / 2
+ for pointIndex := range points {
+ points[pointIndex].y = direction * (rawY[pointIndex] - centre) * scale
+ }
+ points[0].y = 0
+ points[len(points)-1].y = 0
}
func randomFloat(minValue, maxValue float64) float64 {
@@ -171,7 +275,7 @@ func solveSliderStrict(page playwright.Page, scratch bool, logger sliderLogger,
}
logSliderAttemptStart(logger, page, frame, btn, track, attempt+1, dist)
- motion, err := simulateSlide(page, btn, dist)
+ motion, err := simulateSlide(page, btn, track, dist)
if err != nil {
logger.Warn("模拟滑动失败", "err", err)
if attempt < 2 {
@@ -214,7 +318,8 @@ func solveSliderStrict(page playwright.Page, scratch bool, logger sliderLogger,
}
logSliderFailureState(logger, page, attempt+1)
if attempt < 2 {
- reset := resetSliderForRetry(context.Background(), page, deadline)
+ // reset 是已完成拖动后点击页面失败按钮得到的恢复结果;该路径禁止 reload,避免丢失平台重新生成的滑块状态。
+ reset := retrySliderAfterFailedDrag(context.Background(), page, deadline)
logSliderReset(logger, attempt+1, reset)
if reset.err != nil {
return fmt.Errorf("滑块第 %d 次失败后无法恢复: %w", attempt+1, reset.err)
@@ -347,7 +452,8 @@ func calculateSlideDistance(btn, track playwright.ElementHandle, scratch bool) (
}
// simulateSlide 模拟人类滑动,并返回协议调用后的真实墙钟耗时。
-func simulateSlide(page playwright.Page, btn playwright.ElementHandle, distance float64) (slideMotionMetrics, error) {
+// btn 和 track 必须来自同一 frame;distance 是精确水平距离,纵向范围优先使用 track 的实际高度。
+func simulateSlide(page playwright.Page, btn, track playwright.ElementHandle, distance float64) (slideMotionMetrics, error) {
metrics := slideMotionMetrics{}
totalStarted := time.Now()
time.Sleep(secondsDuration(randomFloat(0.1, 0.3)))
@@ -357,6 +463,13 @@ func simulateSlide(page playwright.Page, btn playwright.ElementHandle, distance
}
startX := bb.X + bb.Width/2
startY := bb.Y + bb.Height/2
+ // verticalSpan 是拖动 Y 坐标的峰峰值,默认使用按钮高度的一半;track 可测量时改用实际滑轨高度的一半。
+ verticalSpan := bb.Height / 2
+ // trackBox、trackErr 保存同一滑轨的几何信息及其读取错误;读取失败时保持按钮高度的安全降级值。
+ trackBox, trackErr := track.BoundingBox()
+ if trackErr == nil && trackBox != nil && trackBox.Height > 0 {
+ verticalSpan = trackBox.Height / 2
+ }
mouse := page.Mouse()
// 第一阶段:从左侧附近自然接近滑块。
@@ -377,28 +490,36 @@ func simulateSlide(page playwright.Page, btn playwright.ElementHandle, distance
}
time.Sleep(secondsDuration(randomFloat(0.05, 0.15)))
- pts := generateTrajectory(distance)
+ pts := generateTrajectory(distance, verticalSpan)
metrics.points = len(pts)
- for _, pt := range pts {
- metrics.plannedDelay += pt.delay
+ // point 是当前曲线锚点;plannedDelay 汇总锚点相对时长权重,便于诊断曲线规划。
+ for _, point := range pts {
+ metrics.plannedDelay += point.delay
}
- // The reference implementation gets roughly 80-150ms of CDP round-trip
- // latency per high-level point. The Go driver is often much faster, so keep
- // the same six-point shape while compensating to the observed 480-900ms
- // movement window using wall-clock time.
- metrics.targetMovement = secondsDuration(randomFloat(0.48, 0.90))
+ // targetMovement 是拖动阶段的目标墙钟时长,保持连续且非匀速的前提下按用户要求提速一倍。
+ metrics.targetMovement = secondsDuration(randomFloat(
+ float64(sliderMovementMinDuration)/float64(time.Second),
+ float64(sliderMovementMaxDuration)/float64(time.Second),
+ ))
+ // continuousPoints 是在相邻曲线锚点间持续分发的微移动事件;按下后至释放前不允许插入独立的静止停顿。
+ continuousPoints := expandContinuousTrajectory(pts, metrics.targetMovement)
movementStarted := time.Now()
currentX, currentY := startX, startY
- for index, pt := range pts {
+ // scheduledElapsed 是当前微移动完成后的目标累计时间;浏览器调用本身消耗的时间会从后续等待中扣除。
+ var scheduledElapsed time.Duration
+ for _, pt := range continuousPoints {
currentX, currentY = startX+pt.x, startY+pt.y
- if err := mouse.Move(currentX, currentY, playwright.MouseMoveOptions{Steps: playwright.Int(1 + rng.Intn(3))}); err != nil {
+ if err := mouse.Move(currentX, currentY, playwright.MouseMoveOptions{Steps: playwright.Int(1)}); err != nil {
_ = mouse.Up()
return metrics, err
}
- planned := time.Duration(float64(pt.delay) * randomFloat(0.9, 1.1))
- remainingPoints := len(pts) - index
- delay := compensatedTrajectoryDelay(planned, metrics.targetMovement, time.Since(movementStarted), remainingPoints)
- time.Sleep(delay)
+ // scheduledElapsed 按平滑节奏曲线推进,保证整段的快慢变化不会被浏览器调用开销累积拉长。
+ scheduledElapsed += pt.delay
+ // delay 是到下一计划时间点的剩余等待;非正值表示浏览器调用已耗尽本次等待预算,应立即继续移动。
+ delay := scheduledElapsed - time.Since(movementStarted)
+ if delay > 0 {
+ time.Sleep(delay)
+ }
}
metrics.movementElapsed = time.Since(movementStarted)
if isScratchCaptchaFromPage(page) {
@@ -549,12 +670,21 @@ func sliderRetryText(text string) bool {
return false
}
-func resetSliderForRetry(ctx context.Context, page playwright.Page, deadline time.Time) sliderResetResult {
+// retrySliderAfterFailedDrag 在一次拖动已经完成且页面明确失败后,点击平台提供的失败按钮重新生成滑块。
+// ctx 控制等待;page 是当前验证页;deadline 是浏览器总期限;该函数绝不 reload 页面,调用方应保留本次失败现场。
+func retrySliderAfterFailedDrag(ctx context.Context, page playwright.Page, deadline time.Time) sliderResetResult {
+ return clickSliderRetry(ctx, page, deadline)
+}
+
+// clickSliderRetry 等待并点击可见的失败重试控件,然后确认新滑块已回到轨道起点。
+// ctx 控制轮询;page 是当前验证页;deadline 限制等待;返回结果只描述点击恢复,绝不包含页面刷新。
+func clickSliderRetry(ctx context.Context, page playwright.Page, deadline time.Time) sliderResetResult {
+ // result 保存重试按钮点击与新滑块归位的观察结果,供调用方决定是否允许后续刷新恢复。
result := sliderResetResult{}
+ // selector、clickErr 分别保存命中的失败按钮选择器和首次点击结果。
selector, clickErr := clickRetry(page)
if clickErr != nil {
- // AWSC can publish the failure control shortly after its verification
- // request completes. Give it a brief chance before reloading the page.
+ // waitDeadline 给平台渲染失败按钮一个短暂窗口;轮询期间不刷新当前验证页。
waitDeadline := boundedDeadline(deadline, 800*time.Millisecond)
for time.Now().Before(waitDeadline) {
if err := sleepUntil(ctx, waitDeadline, 100*time.Millisecond); err != nil {
@@ -566,34 +696,46 @@ func resetSliderForRetry(ctx context.Context, page playwright.Page, deadline tim
}
}
}
- if clickErr == nil {
- result.method = "click"
- result.selector = selector
- result.ready = waitForSliderReady(ctx, page, boundedDeadline(deadline, 4*time.Second))
- if result.ready {
- return result
- }
+ if clickErr != nil {
+ result.err = fmt.Errorf("未找到可点击的滑块失败重试控件: %w", clickErr)
+ return result
+ }
+ result.method = "click"
+ result.selector = selector
+ result.ready = waitForSliderReady(ctx, page, boundedDeadline(deadline, 4*time.Second))
+ if !result.ready {
+ result.err = fmt.Errorf("点击滑块失败重试控件后未重新归位")
+ }
+ return result
+}
+
+func resetSliderForRetry(ctx context.Context, page playwright.Page, deadline time.Time) sliderResetResult {
+ // result 保存先尝试点击恢复后的结果;只有非拖动失败的调用方才允许在其失败时回退到 reload。
+ result := clickSliderRetry(ctx, page, deadline)
+ if result.err == nil {
+ return result
}
- result.method = "reload"
+ // reloadResult 清除点击失败的细节,记录初始页面恢复场景允许使用的页面重载结果。
+ reloadResult := sliderResetResult{method: "reload"}
reloadTimeout := boundedDuration(deadline, 8*time.Second)
if reloadTimeout <= 0 {
- result.err = fmt.Errorf("滑块恢复前已超过总超时")
- return result
+ reloadResult.err = fmt.Errorf("滑块恢复前已超过总超时")
+ return reloadResult
}
_, reloadErr := page.Reload(playwright.PageReloadOptions{
WaitUntil: playwright.WaitUntilStateDomcontentloaded,
Timeout: playwright.Float(float64(reloadTimeout.Milliseconds())),
})
if reloadErr != nil {
- result.err = fmt.Errorf("重载滑块验证页: %w", reloadErr)
- return result
+ reloadResult.err = fmt.Errorf("重载滑块验证页: %w", reloadErr)
+ return reloadResult
}
- result.ready = waitForSliderReady(ctx, page, boundedDeadline(deadline, 5*time.Second))
- if !result.ready {
- result.err = fmt.Errorf("重载后滑块未重新出现")
+ reloadResult.ready = waitForSliderReady(ctx, page, boundedDeadline(deadline, 5*time.Second))
+ if !reloadResult.ready {
+ reloadResult.err = fmt.Errorf("重载后滑块未重新出现")
}
- return result
+ return reloadResult
}
func waitForSliderReady(ctx context.Context, page playwright.Page, deadline time.Time) bool {
diff --git a/internal/browser/slider_test.go b/internal/browser/slider_test.go
index 3c93878..43aaa26 100644
--- a/internal/browser/slider_test.go
+++ b/internal/browser/slider_test.go
@@ -6,41 +6,124 @@ import (
"time"
)
+// TestGenerateTrajectoryShape 验证标准 NC 轨迹保持单调前进,并在末端使用受控鼠标超调。
func TestGenerateTrajectoryShape(t *testing.T) {
- pts := generateTrajectory(200)
- if len(pts) != 6 {
- t.Fatalf("参考三阶段轨迹应生成 6 个高层点,got %d", len(pts))
+ // pts 是本次生成的轨迹采样点,用于核验水平移动的边界与顺序。
+ pts := generateTrajectory(200, 34)
+ if len(pts) < 8 || len(pts) > 12 {
+ t.Fatalf("主引擎应生成 8 至 12 个高层点,got %d", len(pts))
}
- // 参考实现明确禁止超调,最后一点必须精确落在目标位置。
+ // last 是最后一个鼠标目标点;其 X 应位于可用距离外的受控超调范围。
last := pts[len(pts)-1]
- if math.Abs(last.x-200) > 1e-9 {
- t.Fatalf("末端 x 必须精确等于 distance,got %.6f", last.x)
+ if last.x < 204 || last.x > 220 {
+ t.Fatalf("末端 x 应超出 distance 4 至 20px,got %.6f", last.x)
}
- // 三阶段轨迹不超调,且保持向目标方向移动。
+ // 三阶段轨迹保持向目标方向移动;超调只允许落在最后的受控鼠标目标范围内。
for i := 1; i < len(pts); i++ {
if pts[i].x < pts[i-1].x {
t.Fatalf("轨迹 x 不单调: pts[%d]=%.1f < pts[%d]=%.1f", i, pts[i].x, i-1, pts[i-1].x)
}
- if pts[i].x > 200 {
- t.Fatalf("主引擎轨迹不应超调: pts[%d]=%.1f", i, pts[i].x)
+ if pts[i].x > 220 {
+ t.Fatalf("主引擎轨迹超出受控范围: pts[%d]=%.1f", i, pts[i].x)
}
}
}
+// TestGenerateTrajectoryDelay 验证曲线锚点的相对时长有效,连续拖动由后续微移动事件负责分发。
func TestGenerateTrajectoryDelay(t *testing.T) {
- pts := generateTrajectory(150)
+ // pts 是本次生成的曲线锚点,用于汇总相对时长权重。
+ pts := generateTrajectory(150, 34)
+ // total 汇总锚点相对时长。
var total time.Duration
+ // i 表示采样点下标;pt 是当前待检查的轨迹点。
for i, pt := range pts {
total += pt.delay
- if pt.delay <= 0 || pt.delay > 8*time.Millisecond {
+ if pt.delay <= 0 || pt.delay > 140*time.Millisecond {
t.Fatalf("delay[%d]=%v 超出合理范围", i, pt.delay)
}
- if pt.y < -1 || pt.y > 1 {
- t.Fatalf("y[%d]=%.2f 超出合理抖动", i, pt.y)
+ }
+ if total < 180*time.Millisecond || total > 1700*time.Millisecond {
+ t.Fatalf("总轨迹时长不合理: %s", total)
+ }
+}
+
+// TestExpandContinuousTrajectory 验证锚点间被拆为密集连续事件,且没有可见的中段静止间隔。
+func TestExpandContinuousTrajectory(t *testing.T) {
+ // anchors 是简化的三段曲线锚点,delay 仅用作时间权重。
+ anchors := []trajectoryPoint{
+ {x: 20, y: 3, delay: 40 * time.Millisecond},
+ {x: 110, y: -5, delay: 70 * time.Millisecond},
+ {x: 180, y: 0, delay: 50 * time.Millisecond},
+ }
+ // target 是提速后完整按住拖动的墙钟目标时长;points 是展开后的微移动事件。
+ target := 800 * time.Millisecond
+ points := expandContinuousTrajectory(anchors, target)
+ if len(points) <= len(anchors) {
+ t.Fatalf("连续事件数=%d,应多于锚点数=%d", len(points), len(anchors))
+ }
+ // total 汇总事件延时;previousX 用于确认鼠标全程只向目标方向前进;distinctDelays 检查节奏是否有变化。
+ var total time.Duration
+ previousX := 0.0
+ distinctDelays := make(map[time.Duration]struct{})
+ for pointIndex, point := range points {
+ if point.delay <= 0 || point.delay > sliderContinuousEventMaxInterval {
+ t.Fatalf("delay[%d]=%s,不应形成可感知停顿", pointIndex, point.delay)
+ }
+ if point.x < previousX {
+ t.Fatalf("x[%d]=%.3f 小于前一点 %.3f", pointIndex, point.x, previousX)
+ }
+ total += point.delay
+ previousX = point.x
+ distinctDelays[point.delay] = struct{}{}
+ }
+ if len(distinctDelays) < 2 {
+ t.Fatalf("连续事件间隔不应全部相同: %v", distinctDelays)
+ }
+ if points[len(points)-1].x != anchors[len(anchors)-1].x || points[len(points)-1].y != anchors[len(anchors)-1].y {
+ t.Fatalf("末点=(%.3f, %.3f),want=(%.3f, %.3f)", points[len(points)-1].x, points[len(points)-1].y, anchors[len(anchors)-1].x, anchors[len(anchors)-1].y)
+ }
+ if total > target || total < target-sliderContinuousEventMaxInterval {
+ t.Fatalf("连续事件计划总时长=%s,want 接近 %s", total, target)
+ }
+}
+
+// TestSliderMovementDurationRange 验证提速后的主引擎墙钟窗口仍有明确上下限。
+func TestSliderMovementDurationRange(t *testing.T) {
+ if sliderMovementMinDuration != 550*time.Millisecond || sliderMovementMaxDuration != 1050*time.Millisecond {
+ t.Fatalf("主引擎目标窗口=(%s,%s),want=(550ms,1050ms)", sliderMovementMinDuration, sliderMovementMaxDuration)
+ }
+}
+
+// TestGenerateTrajectoryVerticalDrift 验证纵向路径连续、非线性,并且实际峰峰值严格等于滑轨高度的一半。
+func TestGenerateTrajectoryVerticalDrift(t *testing.T) {
+ // trackHeight 是模拟标准 NC 轨道的像素高度;pts 是使用该高度生成的鼠标路径。
+ const trackHeight = 34.0
+ pts := generateTrajectory(258, trackHeight/2)
+ // minY、maxY 收集路径的纵向边界;hasDirectionChange 确认路径不是单向线性斜线。
+ minY, maxY := math.Inf(1), math.Inf(-1)
+ hasDirectionChange := false
+ // previousDelta 保存前一段的纵向增量;pointIndex、point 是当前遍历的路径位置和坐标。
+ previousDelta := 0.0
+ for pointIndex, point := range pts {
+ minY = min(minY, point.y)
+ maxY = max(maxY, point.y)
+ if pointIndex == 0 {
+ continue
+ }
+ // currentDelta 是当前段的纵向变化,符号改变表示连续曲线已穿过极值而非维持线性斜率。
+ currentDelta := point.y - pts[pointIndex-1].y
+ if previousDelta != 0 && currentDelta*previousDelta < 0 {
+ hasDirectionChange = true
+ }
+ if currentDelta != 0 {
+ previousDelta = currentDelta
}
}
- if total < 8*time.Millisecond || total > 35*time.Millisecond {
- t.Fatalf("总轨迹时长不合理: %s", total)
+ if math.Abs((maxY-minY)-trackHeight/2) > 1e-9 {
+ t.Fatalf("纵向峰峰值=%.6f want %.6f", maxY-minY, trackHeight/2)
+ }
+ if !hasDirectionChange || math.Abs(pts[0].y) > 1e-9 || math.Abs(pts[len(pts)-1].y) > 1e-9 {
+ t.Fatalf("纵向路径必须从中心出发并以连续非线性曲线回到中心: first=%.6f last=%.6f changed=%v", pts[0].y, pts[len(pts)-1].y, hasDirectionChange)
}
}
@@ -135,7 +218,7 @@ func TestSliderContainerStatesSucceeded(t *testing.T) {
}
func TestTrajectoryPhysics(t *testing.T) {
- pts := generateTrajectory(100)
+ pts := generateTrajectory(100, 34)
half := len(pts) / 2
frontIncrement := pts[half-1].x - pts[0].x
backIncrement := pts[len(pts)-1].x - pts[half].x
diff --git a/internal/browser/token_captcha_diagnostic.go b/internal/browser/token_captcha_diagnostic.go
index 0e80af8..db69d82 100644
--- a/internal/browser/token_captcha_diagnostic.go
+++ b/internal/browser/token_captcha_diagnostic.go
@@ -75,6 +75,8 @@ type tokenCaptchaDiagnosticNetworkEvent struct {
Status int `json:"status,omitempty"`
ContentType string `json:"content_type,omitempty"`
Failure string `json:"failure,omitempty"`
+ // BusinessResult 仅保存滑块接口响应中的脱敏业务结果,帮助区分轨迹被拒绝与网络失败;绝不保存滑块参数、Cookie 或响应正文。
+ BusinessResult string `json:"business_result,omitempty"`
}
// tokenCaptchaDiagnosticConsoleEvent 保存页面控制台输出,默认先去除可能出现的凭证和验证参数。
@@ -238,29 +240,95 @@ func (d *tokenCaptchaDiagnostic) recordRequest(request playwright.Request) {
})
}
-// recordResponse 在 d.mu 保护下记录一条脱敏响应元数据,不读取可能包含凭证的响应正文。
+// recordResponse 在 d.mu 保护下记录一条脱敏响应元数据;仅对 /slide 响应提取受限业务结果,不持久化响应正文。
func (d *tokenCaptchaDiagnostic) recordResponse(response playwright.Response) {
+ // request 是与响应关联的请求,只用于记录方法、资源类型与是否为滑块提交。
+ request := response.Request()
+ // businessResult 是从滑块接口响应提炼出的有限状态,空值表示非滑块请求或响应不可安全解析。
+ businessResult := ""
+ if isTokenCaptchaSlideResponse(response.URL()) {
+ // body、bodyErr 是 Playwright 已接收的响应副本及读取错误;只交给脱敏摘要器,不能写入诊断包或普通日志。
+ body, bodyErr := response.Body()
+ if bodyErr == nil {
+ businessResult = tokenCaptchaSlideBusinessResult(body)
+ }
+ }
d.mu.Lock()
defer d.mu.Unlock()
if len(d.responses) >= tokenCaptchaDiagnosticMaxEvents {
return
}
- // request 是与响应关联的请求,只用于记录方法和资源类型;contentType 只记录公开的响应媒体类型。
- request := response.Request()
// contentType 记录响应的公开媒体类型,不读取可能携带账号数据的响应正文。
contentType := response.Headers()["content-type"]
d.responses = append(d.responses, tokenCaptchaDiagnosticNetworkEvent{
- Kind: "response",
- At: time.Now().UTC().Format(time.RFC3339Nano),
- URL: d.safeURL(response.URL()),
- Method: request.Method(),
- ResourceType: request.ResourceType(),
- Navigation: request.IsNavigationRequest(),
- Status: response.Status(),
- ContentType: contentType,
+ Kind: "response",
+ At: time.Now().UTC().Format(time.RFC3339Nano),
+ URL: d.safeURL(response.URL()),
+ Method: request.Method(),
+ ResourceType: request.ResourceType(),
+ Navigation: request.IsNavigationRequest(),
+ Status: response.Status(),
+ ContentType: contentType,
+ BusinessResult: businessResult,
})
}
+// isTokenCaptchaSlideResponse 判断 URL 是否为当前 token 风控的滑块提交接口;只匹配路径,避免读取其他账号接口的响应体。
+func isTokenCaptchaSlideResponse(rawURL string) bool {
+ // parsed 是结构化后的请求地址;err 表示地址无法解析,此时按非滑块接口处理以保持诊断最小化。
+ parsed, err := url.Parse(strings.TrimSpace(rawURL))
+ return err == nil && strings.HasSuffix(strings.TrimRight(parsed.Path, "/"), "/slide")
+}
+
+// tokenCaptchaSlideBusinessResult 从 /slide JSON 响应中提取顶层 ret、code 与 success 的脱敏摘要;body 只在函数栈内存在,返回值不含正文和验证参数。
+func tokenCaptchaSlideBusinessResult(body []byte) string {
+ // decoded 只声明平台响应中允许诊断的顶层状态字段,未知字段包括滑块数据与会话信息均不会被解码或输出。
+ decoded := struct {
+ // Ret 是 MTOP 风格的业务结果数组,通常说明风控验证接受或拒绝原因。
+ Ret []string `json:"ret"`
+ // Code 是部分响应使用的数值或字符串状态码;RawMessage 防止把嵌套业务数据展开。
+ Code json.RawMessage `json:"code"`
+ // Success 是部分响应使用的顶层布尔成功标志。
+ Success *bool `json:"success"`
+ }{}
+ // decodeErr 表示响应不是预期 JSON,诊断保持空而不把原文误写入工件。
+ if decodeErr := json.Unmarshal(body, &decoded); decodeErr != nil {
+ return ""
+ }
+ // parts 以固定、少量字段构成诊断摘要,禁止从 data 等嵌套字段拷贝内容。
+ parts := make([]string, 0, 3)
+ if len(decoded.Ret) > 0 {
+ // retValues 是逐项脱敏后的 MTOP 结果,最多记录前三项以限制诊断大小与信息范围。
+ retValues := make([]string, 0, min(3, len(decoded.Ret)))
+ // retIndex、retValue 分别表示当前结果位置和原始结果文本;只把脱敏后的文本写入摘要。
+ for retIndex, retValue := range decoded.Ret {
+ if retIndex >= 3 {
+ break
+ }
+ retValues = append(retValues, redactDiagnosticText(retValue))
+ }
+ parts = append(parts, "ret="+strings.Join(retValues, ","))
+ }
+ if len(decoded.Code) > 0 && string(decoded.Code) != "null" {
+ // code 是顶层原始 JSON 标量;先验证其为字符串或数字,避免嵌套对象进入诊断。
+ code := ""
+ if json.Unmarshal(decoded.Code, &code) == nil {
+ parts = append(parts, "code="+redactDiagnosticText(code))
+ } else {
+ // numericCode 是仅接受数字的备选状态码,其他 JSON 形状保持不记录。
+ var numericCode json.Number
+ if json.Unmarshal(decoded.Code, &numericCode) == nil {
+ parts = append(parts, "code="+numericCode.String())
+ }
+ }
+ }
+ if decoded.Success != nil {
+ // success 是明确的布尔结果,格式化后不携带平台任意文本。
+ parts = append(parts, fmt.Sprintf("success=%t", *decoded.Success))
+ }
+ return strings.Join(parts, "; ")
+}
+
// safeURL 在默认模式删除 URL 查询值与 fragment,仅保留排序后的参数名和查询摘要;敏感模式由显式环境授权才原样返回。
func (d *tokenCaptchaDiagnostic) safeURL(raw string) string {
if d.includeSensitive {
diff --git a/internal/browser/token_captcha_diagnostic_test.go b/internal/browser/token_captcha_diagnostic_test.go
index d6a1566..ab40583 100644
--- a/internal/browser/token_captcha_diagnostic_test.go
+++ b/internal/browser/token_captcha_diagnostic_test.go
@@ -35,6 +35,37 @@ func TestTokenCaptchaDiagnosticRedactsSensitiveValues(t *testing.T) {
}
}
+// TestTokenCaptchaSlideBusinessResult 验证滑块响应诊断只保留受限顶层结果,并且不会将嵌套滑块数据或秘密值写入工件。
+func TestTokenCaptchaSlideBusinessResult(t *testing.T) {
+ // body 是包含业务结果、敏感嵌套数据和无关字段的模拟滑块响应,测试仅允许前者进入摘要。
+ body := []byte(`{"ret":["FAIL_SYS_USER_VALIDATE::x5secdata=secret-value","SECOND"],"code":403,"success":false,"data":{"slidedata":"secret-slide"}}`)
+ // got 是默认诊断模式下的业务摘要。
+ got := tokenCaptchaSlideBusinessResult(body)
+ if !strings.Contains(got, "ret=FAIL_SYS_USER_VALIDATE::x5secdata=
,SECOND") || !strings.Contains(got, "code=403") || !strings.Contains(got, "success=false") {
+ t.Fatalf("unexpected slide business result: %q", got)
+ }
+ if strings.Contains(got, "secret-value") || strings.Contains(got, "secret-slide") {
+ t.Fatalf("slide business result leaked sensitive data: %q", got)
+ }
+ // nonSlideURL 是普通 MTOP 地址,不得触发任何响应正文读取。
+ nonSlideURL := "https://h5api.m.goofish.com/h5/mtop.taobao.idlemessage.pc.login.token/1.0/report"
+ if isTokenCaptchaSlideResponse(nonSlideURL) {
+ t.Fatalf("ordinary response incorrectly treated as slide: %q", nonSlideURL)
+ }
+ // slideURL 是真实接口形状的滑块地址,尾部斜杠也必须被正确识别。
+ slideURL := "https://h5api.m.goofish.com/h5/mtop.taobao.idlemessage.pc.login.token/1.0/slide/"
+ if !isTokenCaptchaSlideResponse(slideURL) {
+ t.Fatalf("slide response was not recognized: %q", slideURL)
+ }
+ // malformedBody 不能被当作可诊断 JSON,必须返回空摘要而非回显原文。
+ malformedBody := []byte("secret malformed response")
+ // malformedResult 是无法解析的响应摘要,必须保持为空以避免泄漏原始文本。
+ malformedResult := tokenCaptchaSlideBusinessResult(malformedBody)
+ if malformedResult != "" {
+ t.Fatalf("malformed response should not be recorded: %q", malformedResult)
+ }
+}
+
// TestTokenCaptchaDiagnosticBundleBrowserIntegration 在真实 Chromium 中验证诊断包包含必要现场且默认不泄漏验证码查询值;仅在显式浏览器集成模式运行。
func TestTokenCaptchaDiagnosticBundleBrowserIntegration(t *testing.T) {
if os.Getenv("RUN_BROWSER_INTEGRATION") != "1" {
diff --git a/internal/browser/token_captcha_fallback.go b/internal/browser/token_captcha_fallback.go
index 9a9e15f..95b7ebb 100644
--- a/internal/browser/token_captcha_fallback.go
+++ b/internal/browser/token_captcha_fallback.go
@@ -221,6 +221,9 @@ func fallbackChromiumArgs(profileDir string, headless bool, headlessUserAgent ..
if captchaIgnoreCertificateErrors() {
args = append(args, "--ignore-certificate-errors")
}
+ if proxy := captchaBrowserProxy(); proxy != "" {
+ args = append(args, "--proxy-server="+proxy)
+ }
if headless && len(headlessUserAgent) > 0 && headlessUserAgent[0] != nil {
if userAgent := normalizeHeadlessUserAgent(*headlessUserAgent[0]); userAgent != "" {
args = append(args, "--user-agent="+userAgent)
diff --git a/internal/browser/token_captcha_fallback_integration_test.go b/internal/browser/token_captcha_fallback_integration_test.go
index 8931cad..6051a7d 100644
--- a/internal/browser/token_captcha_fallback_integration_test.go
+++ b/internal/browser/token_captcha_fallback_integration_test.go
@@ -8,7 +8,9 @@ import (
"net/http"
"net/http/httptest"
"os"
+ "strconv"
"strings"
+ "sync/atomic"
"testing"
"time"
@@ -32,12 +34,27 @@ const slider = document.querySelector('#nc_1_n1z');
let pressed = false;
let released = false;
let startX = 0;
+let dragMoveCount = 0;
+let dragStartedAt = 0;
+let dragEndedAt = 0;
+let dragMinY = Infinity;
+let dragMaxY = -Infinity;
+let dragMaxX = -Infinity;
slider.addEventListener('mousedown', event => {
pressed = true;
startX = event.clientX;
+ dragStartedAt = performance.now();
+});
+document.addEventListener('mousemove', event => {
+ if (!pressed) return;
+ dragMoveCount++;
+ dragMinY = Math.min(dragMinY, event.clientY);
+ dragMaxY = Math.max(dragMaxY, event.clientY);
+ dragMaxX = Math.max(dragMaxX, event.clientX);
});
window.addEventListener('mouseup', () => {
released = pressed;
+ if (released) dragEndedAt = performance.now();
});
slider.addEventListener('click', event => {
if (!released || event.clientX - startX < 300) return;
@@ -86,13 +103,37 @@ slider.addEventListener('click', event => {
if _, fresh := freshX5Cookies(cookies, nil); !fresh || isPunishURL(page.URL()) {
t.Fatalf("slider did not complete reference success flow: url=%s cookies=%v", page.URL(), cookies)
}
+ // motionState 记录页面实际观察到的按下后移动数和拖动耗时,用真实 Chromium 防止轨迹退回固定短促动作。
+ motionState, err := page.Evaluate(`() => ({ dragMoveCount, dragDuration: dragEndedAt - dragStartedAt, dragVerticalSpan: dragMaxY - dragMinY, dragOvershoot: dragMaxX - startX - 376 })`)
+ if err != nil {
+ t.Fatalf("读取真实滑动轨迹状态: %v", err)
+ }
+ // motionValues 是页面返回的可序列化状态,后续只读取非敏感的事件计数与耗时。
+ motionValues, ok := motionState.(map[string]any)
+ if !ok {
+ t.Fatalf("真实滑动状态类型=%T", motionState)
+ }
+ // moveCount、durationMS、verticalSpan、overshoot 分别是按下后事件数、墙钟毫秒数、实际纵向峰峰值和超出可用轨道的鼠标距离;Playwright 可能把 JS 数字解码为不同 Go 数字类型。
+ moveCount, moveCountErr := strconv.ParseFloat(fmt.Sprint(motionValues["dragMoveCount"]), 64)
+ durationMS, durationErr := strconv.ParseFloat(fmt.Sprint(motionValues["dragDuration"]), 64)
+ verticalSpan, verticalSpanErr := strconv.ParseFloat(fmt.Sprint(motionValues["dragVerticalSpan"]), 64)
+ overshoot, overshootErr := strconv.ParseFloat(fmt.Sprint(motionValues["dragOvershoot"]), 64)
+ if moveCountErr != nil || durationErr != nil || verticalSpanErr != nil || overshootErr != nil {
+ t.Fatalf("真实滑动状态字段无效: %#v", motionValues)
+ }
+ if moveCount < 8 || durationMS < 450 || durationMS > 1300 || verticalSpan < 20 || verticalSpan > 24 || overshoot < 4 || overshoot > 20 {
+ t.Fatalf("真实轨迹应包含连续多点、提速后的墙钟范围、半轨道高度纵向范围和受控超调: moves=%.0f duration_ms=%.0f vertical_span=%.0f overshoot=%.0f", moveCount, durationMS, verticalSpan, overshoot)
+ }
}
func TestPlaywrightSliderRecoversFromHiddenFailureState(t *testing.T) {
if os.Getenv("RUN_BROWSER_INTEGRATION") != "1" {
t.Skip("set RUN_BROWSER_INTEGRATION=1 to exercise slider failure recovery")
}
+ // requestCount 统计验证页文档请求次数,已滑动失败后的重试必须保持为一次请求,不能通过 reload 恢复。
+ var requestCount atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ requestCount.Add(1)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = io.WriteString(w, `验证码拦截
@@ -168,6 +209,11 @@ document.addEventListener('click', event => {
if !ok || fmt.Sprint(values["dragAttempts"]) != "2" || fmt.Sprint(values["retryClicks"]) != "1" {
t.Fatalf("unexpected retry state: %#v", state)
}
+ // requests 是测试期间导航验证页的文档请求数;第二次请求意味着恢复逻辑错误地刷新了页面。
+ requests := requestCount.Load()
+ if requests != 1 {
+ t.Fatalf("滑动失败后应点击失败按钮直接重试,验证页请求数=%d", requests)
+ }
}
func TestTokenCaptchaDirectErrorPageBrowserIntegration(t *testing.T) {
diff --git a/internal/db/chat.go b/internal/db/chat.go
index fe37b57..13f8d6e 100644
--- a/internal/db/chat.go
+++ b/internal/db/chat.go
@@ -204,6 +204,29 @@ func (s *ChatStore) SaveMessage(ctx context.Context, session ChatSession, messag
// inserted 保存inserted,供当前处理流程使用
inserted, _ := res.RowsAffected()
if inserted > 0 {
+ // inheritErr 保存买家后续消息确认此前出站消息已读时的失败;同一会话中的后续回复是已读历史的确定证据。
+ if message.Direction == "incoming" && message.MessageType != "system" {
+ _, inheritErr := tx.ExecContext(ctx, `UPDATE chat_messages SET read_status=2,
+ read_at=CASE WHEN read_status=2 AND read_at>0 THEN read_at ELSE ? END
+ WHERE cookie_id=? AND chat_id=? AND direction='outgoing' AND sent_at<=?`, message.SentAt, message.CookieID, message.ChatID, message.SentAt)
+ if inheritErr != nil {
+ return nil, false, fmt.Errorf("按后续消息确认聊天已读: %w", inheritErr)
+ }
+ }
+ // inheritErr 保存平台消息补入历史时继承本地临时消息已读回执的失败,避免同一消息因键不同长期显示未读。
+ if message.Direction == "outgoing" && strings.HasSuffix(message.MessageKey, ".PNM") {
+ _, inheritErr := tx.ExecContext(ctx, `UPDATE chat_messages AS platform SET read_status=2,read_at=(SELECT local.read_at FROM chat_messages AS local
+ WHERE local.cookie_id=platform.cookie_id AND local.chat_id=platform.chat_id AND local.direction='outgoing'
+ AND local.message_key NOT LIKE '%.PNM' AND local.content=platform.content AND local.read_status=2
+ AND ABS(local.sent_at-platform.sent_at)<=10000 ORDER BY local.read_at DESC LIMIT 1)
+ WHERE platform.cookie_id=? AND platform.message_key=? AND platform.read_status<>2 AND EXISTS (SELECT 1 FROM chat_messages AS local
+ WHERE local.cookie_id=platform.cookie_id AND local.chat_id=platform.chat_id AND local.direction='outgoing'
+ AND local.message_key NOT LIKE '%.PNM' AND local.content=platform.content AND local.read_status=2
+ AND ABS(local.sent_at-platform.sent_at)<=10000)`, message.CookieID, message.MessageKey)
+ if inheritErr != nil {
+ return nil, false, fmt.Errorf("继承聊天已读回执: %w", inheritErr)
+ }
+ }
// unreadDelta 保存unreadDelta,供当前处理流程使用
unreadDelta := 0
if unread {
@@ -363,14 +386,24 @@ func (s *ChatStore) UpdateMessageStatus(ctx context.Context, cookieID, key, stat
return s.GetMessageByKey(ctx, cookieID, key)
}
-// MarkMessageRead 按平台回执把一条出站消息标记为已读,并返回更新后的消息。
+// MarkMessageRead 按平台回执把目标出站消息及同会话中更早的出站消息标记为已读,并返回目标消息。
func (s *ChatStore) MarkMessageRead(ctx context.Context, cookieID, key string, readAt int64) (*ChatMessage, error) {
+ // message 保存平台回执对应的出站消息;其会话和发送时间界定本次批量确认范围。
+ message, err := s.GetMessageByKey(ctx, cookieID, key)
+ if err != nil {
+ return nil, err
+ }
+ if message.Direction != "outgoing" {
+ return nil, ErrNotFound
+ }
// readAt 保存平台已读时间;缺失时使用本机 UTC 时间作为展示回退。
if readAt <= 0 {
readAt = time.Now().UTC().UnixMilli()
}
- // err 保存只更新出站消息的数据库错误,防止错误改写入站状态。
- if _, err := s.DB.ExecContext(ctx, `UPDATE chat_messages SET read_status=2,read_at=? WHERE cookie_id=? AND message_key=? AND direction='outgoing'`, readAt, cookieID, key); err != nil {
+ // err 保存按回执水位更新同会话出站历史的错误;对方读到目标消息时更早消息也已被阅读。
+ if _, err = s.DB.ExecContext(ctx, `UPDATE chat_messages SET read_status=2,
+ read_at=CASE WHEN read_status=2 AND read_at>0 THEN read_at ELSE ? END
+ WHERE cookie_id=? AND chat_id=? AND direction='outgoing' AND sent_at<=?`, readAt, cookieID, message.ChatID, message.SentAt); err != nil {
return nil, err
}
return s.GetMessageByKey(ctx, cookieID, key)
diff --git a/internal/db/chat_read_test.go b/internal/db/chat_read_test.go
new file mode 100644
index 0000000..2618ac5
--- /dev/null
+++ b/internal/db/chat_read_test.go
@@ -0,0 +1,99 @@
+package db
+
+import (
+ "context"
+ "testing"
+)
+
+// TestMarkMessageReadMarksPriorOutgoingHistory 验证平台对目标出站消息的已读回执会确认同会话中更早的出站历史。
+func TestMarkMessageReadMarksPriorOutgoingHistory(t *testing.T) {
+ // store、cleanup 分别保存隔离的 SQLite 存储和关闭函数。
+ store, cleanup := newTestDB(t)
+ defer cleanup()
+ // ctx 是本测试数据库调用共用的上下文。
+ ctx := context.Background()
+ // userID 保存测试账号的数据库主键,用于建立会话所属账号。
+ var userID int64
+ if err := store.DB.QueryRowContext(ctx, `INSERT INTO users (username,email,password_hash) VALUES (?,?,?) RETURNING id`, "chat-read-owner", "chat-read-owner@example.com", "test-hash").Scan(&userID); err != nil {
+ t.Fatalf("创建测试用户: %v", err)
+ }
+ // cookieID 是测试聊天所属的非敏感账号标识。
+ const cookieID = "chat-read-account"
+ if err := store.Cookies.CreateOwned(ctx, cookieID, "test-cookie", userID); err != nil {
+ t.Fatalf("创建测试账号: %v", err)
+ }
+ // session 保存三条出站消息共同所属的聊天会话。
+ session := ChatSession{CookieID: cookieID, ChatID: "chat-read-session", BuyerID: "buyer-1", BuyerName: "买家"}
+ // messages 按发送顺序构造两条应被确认的历史消息和一条仍未确认的新消息。
+ messages := []ChatMessage{
+ {MessageKey: "outgoing-1.PNM", Direction: "outgoing", MessageType: "text", Content: "第一条", Status: "sent", SentAt: 100},
+ {MessageKey: "outgoing-2.PNM", Direction: "outgoing", MessageType: "text", Content: "第二条", Status: "sent", SentAt: 200},
+ {MessageKey: "outgoing-3.PNM", Direction: "outgoing", MessageType: "text", Content: "第三条", Status: "sent", SentAt: 300},
+ }
+ for _, message := range messages {
+ // inserted、saveErr 分别表示本条测试消息是否首次保存及保存失败原因。
+ if _, inserted, saveErr := store.Chats.SaveMessage(ctx, session, message, false); saveErr != nil || !inserted {
+ t.Fatalf("保存测试消息 key=%s inserted=%v err=%v", message.MessageKey, inserted, saveErr)
+ }
+ }
+ // updated、readErr 分别保存回执目标消息及处理回执失败原因。
+ updated, readErr := store.Chats.MarkMessageRead(ctx, cookieID, "outgoing-2.PNM", 999)
+ if readErr != nil || updated.ReadStatus != 2 || updated.ReadAt != 999 {
+ t.Fatalf("处理已读回执 message=%+v err=%v", updated, readErr)
+ }
+ // saved 保存从数据库重新读取的消息,用来验证批量已读水位的实际持久化结果。
+ saved, listErr := store.Chats.ListMessages(ctx, userID, cookieID, session.ChatID, 0, 10)
+ if listErr != nil || len(saved) != 3 {
+ t.Fatalf("读取确认结果 messages=%+v err=%v", saved, listErr)
+ }
+ if saved[0].ReadStatus != 2 || saved[1].ReadStatus != 2 || saved[2].ReadStatus != 0 {
+ t.Fatalf("已读水位错误 statuses=%d,%d,%d", saved[0].ReadStatus, saved[1].ReadStatus, saved[2].ReadStatus)
+ }
+ if saved[0].ReadAt != 999 || saved[1].ReadAt != 999 || saved[2].ReadAt != 0 {
+ t.Fatalf("已读时间错误 timestamps=%d,%d,%d", saved[0].ReadAt, saved[1].ReadAt, saved[2].ReadAt)
+ }
+}
+
+// TestSaveIncomingMessageMarksPriorOutgoingHistoryRead 验证买家后续发言会确认此前出站历史已读,且不会确认其后的出站消息。
+func TestSaveIncomingMessageMarksPriorOutgoingHistoryRead(t *testing.T) {
+ // store、cleanup 分别保存隔离的 SQLite 存储和关闭函数。
+ store, cleanup := newTestDB(t)
+ defer cleanup()
+ // ctx 是本测试数据库调用共用的上下文。
+ ctx := context.Background()
+ // userID 保存测试账号的数据库主键,用于建立会话所属账号。
+ var userID int64
+ if err := store.DB.QueryRowContext(ctx, `INSERT INTO users (username,email,password_hash) VALUES (?,?,?) RETURNING id`, "chat-history-owner", "chat-history-owner@example.com", "test-hash").Scan(&userID); err != nil {
+ t.Fatalf("创建测试用户: %v", err)
+ }
+ // cookieID 是测试聊天所属的非敏感账号标识。
+ const cookieID = "chat-history-account"
+ if err := store.Cookies.CreateOwned(ctx, cookieID, "test-cookie", userID); err != nil {
+ t.Fatalf("创建测试账号: %v", err)
+ }
+ // session 保存测试消息共同所属的聊天会话。
+ session := ChatSession{CookieID: cookieID, ChatID: "chat-history-session", BuyerID: "buyer-1", BuyerName: "买家"}
+ // first 保存买家回复之前的出站消息,应被后续回复确认已读。
+ first := ChatMessage{MessageKey: "history-first.PNM", Direction: "outgoing", MessageType: "text", Content: "第一条", Status: "sent", SentAt: 100}
+ if _, inserted, saveErr := store.Chats.SaveMessage(ctx, session, first, false); saveErr != nil || !inserted {
+ t.Fatalf("保存第一条出站消息 inserted=%v err=%v", inserted, saveErr)
+ }
+ // reply 保存买家后续消息,其到达表明此前出站内容已被阅读。
+ reply := ChatMessage{MessageKey: "history-reply.PNM", Direction: "incoming", MessageType: "text", Content: "收到", Status: "received", SentAt: 200}
+ if _, inserted, saveErr := store.Chats.SaveMessage(ctx, session, reply, true); saveErr != nil || !inserted {
+ t.Fatalf("保存买家回复 inserted=%v err=%v", inserted, saveErr)
+ }
+ // last 保存买家回复之后的出站消息,不能被此前回复错误确认。
+ last := ChatMessage{MessageKey: "history-last.PNM", Direction: "outgoing", MessageType: "text", Content: "第三条", Status: "sent", SentAt: 300}
+ if _, inserted, saveErr := store.Chats.SaveMessage(ctx, session, last, false); saveErr != nil || !inserted {
+ t.Fatalf("保存最后一条出站消息 inserted=%v err=%v", inserted, saveErr)
+ }
+ // saved 保存从数据库读取的最终已读状态。
+ saved, listErr := store.Chats.ListMessages(ctx, userID, cookieID, session.ChatID, 0, 10)
+ if listErr != nil || len(saved) != 3 {
+ t.Fatalf("读取历史确认结果 messages=%+v err=%v", saved, listErr)
+ }
+ if saved[0].ReadStatus != 2 || saved[0].ReadAt != 200 || saved[2].ReadStatus != 0 || saved[2].ReadAt != 0 {
+ t.Fatalf("历史已读确认错误 first=%+v last=%+v", saved[0], saved[2])
+ }
+}
diff --git a/internal/server/chat_handlers.go b/internal/server/chat_handlers.go
index ad24749..301704b 100644
--- a/internal/server/chat_handlers.go
+++ b/internal/server/chat_handlers.go
@@ -434,7 +434,7 @@ func (s *Server) chatWebSocket(w http.ResponseWriter, r *http.Request) {
return
case // event、ok 保存event、ok,供当前处理流程使用
event, ok := <-events:
- if !ok || wsjson.Write(ctx, conn, event) != nil {
+ if !ok || wsjson.Write(ctx, conn, newChatEventDTOFromApplication(event)) != nil {
return
}
}
diff --git a/internal/server/success_contract.go b/internal/server/success_contract.go
index 8675f5e..bf331cc 100644
--- a/internal/server/success_contract.go
+++ b/internal/server/success_contract.go
@@ -130,6 +130,10 @@ type chatMessageDTO struct {
Content string `json:"content"`
// Status 是消息投递状态。
Status string `json:"status"`
+ // ReadStatus 是平台已读回执状态;值为 2 时表示对方已读。
+ ReadStatus int `json:"read_status"`
+ // ReadAt 是平台确认已读的 Unix 毫秒时间戳;零值表示尚未确认。
+ ReadAt int64 `json:"read_at"`
// SentAt 是消息发送时间的 Unix 秒。
SentAt int64 `json:"sent_at"`
}
@@ -144,7 +148,7 @@ func newChatMessageDTOFromApplication(message *chatapp.Message) chatMessageDTO {
MessageKey: message.MessageKey, Direction: message.Direction,
SenderID: message.SenderID, SenderName: message.SenderName,
MessageType: message.MessageType, Content: message.Content,
- Status: message.Status, SentAt: message.SentAt,
+ Status: message.Status, ReadStatus: message.ReadStatus, ReadAt: message.ReadAt, SentAt: message.SentAt,
}
}
@@ -158,12 +162,39 @@ func newChatMessageDTOsFromApplication(messages []chatapp.Message) []chatMessage
ID: message.ID, AccountID: message.AccountID, ChatID: message.ChatID,
MessageKey: message.MessageKey, Direction: message.Direction, SenderID: message.SenderID,
SenderName: message.SenderName, MessageType: message.MessageType, Content: message.Content,
- Status: message.Status, SentAt: message.SentAt,
+ Status: message.Status, ReadStatus: message.ReadStatus, ReadAt: message.ReadAt, SentAt: message.SentAt,
})
}
return result
}
+// chatEventDTO 是聊天实时推送的具名传输契约,确保 WebSocket 与 HTTP 使用相同的 snake_case 消息字段。
+type chatEventDTO struct {
+ // Type 是实时事件类别,例如 message.created。
+ Type string `json:"type"`
+ // Message 是本次事件关联的非敏感聊天消息;非消息事件可以为空。
+ Message *chatMessageDTO `json:"message,omitempty"`
+ // Session 是本次事件关联的非敏感会话摘要;无需更新会话时可以为空。
+ Session *chatSessionDTO `json:"session,omitempty"`
+}
+
+// newChatEventDTOFromApplication 将应用层实时事件转换为浏览器稳定使用的 WebSocket DTO。
+func newChatEventDTOFromApplication(event chatapp.Event) chatEventDTO {
+ // result 保存转换后的实时事件;指针字段只在应用事件提供对应实体时设置。
+ result := chatEventDTO{Type: event.Type}
+ if event.Message != nil {
+ // message 保存避免 WebSocket 直接序列化应用层 PascalCase 字段的消息 DTO。
+ message := newChatMessageDTOFromApplication(event.Message)
+ result.Message = &message
+ }
+ if event.Session != nil {
+ // session 保存与 HTTP 会话接口一致的 snake_case 会话 DTO。
+ session := newChatSessionDTOFromApplication(*event.Session)
+ result.Session = &session
+ }
+ return result
+}
+
// chatSessionPageResponse 是聊天会话分页接口的具名响应 DTO。
type chatSessionPageResponse struct {
// Sessions 是当前页聊天会话。
diff --git a/internal/server/success_contract_test.go b/internal/server/success_contract_test.go
new file mode 100644
index 0000000..57773c6
--- /dev/null
+++ b/internal/server/success_contract_test.go
@@ -0,0 +1,54 @@
+package server
+
+import (
+ "encoding/json"
+ "testing"
+
+ chatapp "xianyu-go/internal/application/chat"
+)
+
+// TestChatMessageDTOKeepsReadReceipt 验证聊天传输 DTO 不会丢弃平台出站已读回执。
+func TestChatMessageDTOKeepsReadReceipt(t *testing.T) {
+ // message 保存带已读确认的应用层出站消息。
+ message := chatapp.Message{ID: 7, AccountID: "account-1", ChatID: "chat-1", MessageKey: "message-1", Direction: "outgoing", Status: "sent", ReadStatus: 2, ReadAt: 88, SentAt: 99}
+ // single 保存单消息接口使用的传输 DTO。
+ single := newChatMessageDTOFromApplication(&message)
+ if single.ReadStatus != 2 || single.ReadAt != 88 {
+ t.Fatalf("单消息响应丢失已读回执: got=%+v", single)
+ }
+ // page 保存历史消息接口使用的传输 DTO 列表。
+ page := newChatMessageDTOsFromApplication([]chatapp.Message{message})
+ if len(page) != 1 || page[0].ReadStatus != 2 || page[0].ReadAt != 88 {
+ t.Fatalf("消息分页响应丢失已读回执: got=%+v", page)
+ }
+}
+
+// TestChatEventDTOUsesFrontendContract 验证 WebSocket 实时事件沿用聊天 HTTP 接口的 snake_case 字段契约。
+func TestChatEventDTOUsesFrontendContract(t *testing.T) {
+ // event 保存带消息与会话的应用层实时事件。
+ event := chatapp.Event{
+ Type: "message.created",
+ Message: &chatapp.Message{AccountID: "account-1", ChatID: "chat-1", MessageKey: "message-1", Direction: "incoming", Status: "received", SentAt: 9},
+ Session: &chatapp.Session{AccountID: "account-1", ChatID: "chat-1", BuyerID: "buyer-1", BuyerName: "买家"},
+ }
+ // encoded、marshalErr 分别保存 DTO 编码结果和编码错误。
+ encoded, marshalErr := json.Marshal(newChatEventDTOFromApplication(event))
+ if marshalErr != nil {
+ t.Fatalf("编码聊天实时事件: %v", marshalErr)
+ }
+ // payload 保存浏览器实际接收的 JSON 对象。
+ var payload map[string]any
+ if unmarshalErr := json.Unmarshal(encoded, &payload); unmarshalErr != nil {
+ t.Fatalf("解码聊天实时事件: %v", unmarshalErr)
+ }
+ // message 保存事件中的消息对象,必须保留前端读取的 snake_case 账号和会话字段。
+ message, messageOK := payload["message"].(map[string]any)
+ if !messageOK || message["account_id"] != "account-1" || message["chat_id"] != "chat-1" || message["AccountID"] != nil {
+ t.Fatalf("消息 WebSocket 契约错误: %#v", payload["message"])
+ }
+ // session 保存事件中的会话对象,也必须使用同一命名约定。
+ session, sessionOK := payload["session"].(map[string]any)
+ if !sessionOK || session["account_id"] != "account-1" || session["chat_id"] != "chat-1" || session["AccountID"] != nil {
+ t.Fatalf("会话 WebSocket 契约错误: %#v", payload["session"])
+ }
+}
diff --git a/internal/webui/static/assets/AccountList-Bb-tGjAS.js b/internal/webui/static/assets/AccountList-Dpo8D419.js
similarity index 99%
rename from internal/webui/static/assets/AccountList-Bb-tGjAS.js
rename to internal/webui/static/assets/AccountList-Dpo8D419.js
index f3e9864..ebd84ed 100644
--- a/internal/webui/static/assets/AccountList-Bb-tGjAS.js
+++ b/internal/webui/static/assets/AccountList-Dpo8D419.js
@@ -1,3 +1,3 @@
-import{r as n,j as e,b as ie,c as Oe}from"./react-vendor-C_od1ZSF.js";import{g as X,p as ae,a as ce,d as Pe}from"./index-hByDAHGj.js";import{c as Le,o as ke}from"./contract-COFcZjyb.js";import{X as de,n as ze,L as J,o as Ge,p as Ie,q as Te,r as $e,s as te,t as De,K as We,u as Ve,v as Je,e as Ke,w as ue,f as He,U as Ee,x as Xe,k as _e,Q as ve,R as Ye,y as Ze,z as Fe,F as Ne,H as es}from"./icons-vendor-CvzvbbIV.js";const ss=(s,t)=>{const r=s.avatar_url||"";if(!r)return"";try{const a=new URL(r,window.location.origin);return a.hostname.endsWith("alicdn.com")&&a.searchParams.set("_v",t),a.toString()}catch{return r}},ts=async s=>{const t=await X("/api/v1/accounts/details",void 0,s),r=Le(t,["data","accounts","details"]),a=Date.now().toString();return r.map(l=>({id:l.id,cookie_configured:l.has_cookie===!0,enabled:l.enabled,auto_confirm:l.auto_confirm,remark:l.remark,pause_duration:l.pause_duration,paused_until:Number(l.paused_until||0),paused:l.paused===!0,username:l.username||"",login_password_configured:void 0,show_browser:l.show_browser===!0||l.show_browser===1||l.show_browser==="1"||l.show_browser==="true",nickname:l.nickname||l.remark||`账号 ${l.id.substring(0,6)}`,avatar_url:ss(l,a),profile_error:l.profile_error||"",ai_enabled:!1,auto_rate_enabled:l.auto_rate_enabled,rate_content:l.rate_content||"不错的买家,交易愉快",auto_polish_enabled:l.auto_polish_enabled,polish_time:l.polish_time||"03:00",last_rate_scan_at:Number(l.last_rate_scan_at||0),last_polish_date:l.last_polish_date||"",last_polish_at:Number(l.last_polish_at||0)}))},as=async s=>{const t=await X("/api/v1/accounts/runtime-status",void 0,s);return ke(t,["statuses","data","result"])||{}},rs=async s=>ce("/api/v1/qr-login/generate",void 0,{...s,timeoutMs:(s==null?void 0:s.timeoutMs)??13e4}),ns=async(s,t)=>X(`/api/v1/qr-login/check/${s}`,void 0,{signal:t,timeoutMs:1e4}),ls=async(s,t)=>ce(`/api/v1/qr-login/complete-verification/${s}`,{target_account_id:t||""}),os=async(s,t)=>ae(`/api/v1/accounts/${s}/status`,{enabled:t}),is=async s=>Pe(`/api/v1/accounts/${s}`),cs=async(s,t,r)=>ae(`/api/v1/accounts/${s}/pause-duration`,{pause_duration:t},r),ds=async(s,t,r)=>ae(`/api/v1/accounts/${s}/settings`,t,r),us=async(s,t)=>X(`/api/v1/accounts/${s}/long-login`,void 0,t),xs=async(s,t,r)=>ae(`/api/v1/accounts/${s}/long-login`,{enabled:t},r),ms=async(s,t)=>ce("/api/v1/password-login",s,t),bs=async(s,t)=>X(`/api/v1/password-login/check/${s}`,void 0,{signal:t,timeoutMs:1e4}),hs=async(s,t)=>Pe(`/api/v1/password-login/cancel/${s}`,void 0,t),gs=async s=>ce(`/api/v1/accounts/${s}/refresh-profile`,{}),ps=async s=>{const t=await X("/api/v1/settings/ai-reply",void 0,s);return ke(t,["settings","data","result"])||{}},fs=async(s,t)=>X(`/api/v1/settings/ai-reply/${s}`,void 0,t),ys=async(s,t,r)=>{const a={ai_enabled:t.ai_enabled??!1,max_discount_percent:t.max_discount_percent??10,max_discount_amount:t.max_discount_amount??100,max_bargain_rounds:t.max_bargain_rounds??3,custom_prompts:t.custom_prompts??""};return ae(`/api/v1/settings/ai-reply/${s}`,a,r)},js=s=>{if(Array.isArray(s))return s.filter(Boolean);if(typeof s!="string"||!s.trim())return[];try{const t=JSON.parse(s);if(Array.isArray(t))return t.filter(Boolean)}catch{}return s.split(/[,\s;]+/).map(t=>t.trim()).filter(Boolean)},ws=async s=>{const t=await X("/api/v1/notifications/channels",void 0,s);return{success:!0,data:Le(t,["data","channels","items"]).map(a=>{let l;try{l=typeof a.config=="string"?JSON.parse(a.config):a.config}catch{l={}}const c=a.type==="ding_talk"?"dingtalk":a.type==="lark"?"feishu":a.type;return{id:String(a.id),name:a.name,type:c,config:l,event_types:js(a.event_types),enabled:a.enabled,created_at:a.created_at,updated_at:a.updated_at}})}},_s=async(s,t)=>{const r=await X(`/api/v1/notifications/accounts/${s}/bindings`,void 0,t),a=ke(r,["data","result"])||{};return Array.isArray(a.channel_ids)?a.channel_ids:[]},Ce=async(s,t)=>X(`/api/v1/account-tasks/${s}`,void 0,t),Se=async(s,t,r)=>ae(`/api/v1/account-tasks/${s}`,t,r),vs=async(s,t,r)=>ce(`/api/v1/account-tasks/${s}/run`,{task_type:t},{timeoutMs:12e4,...r}),Re=s=>({account_id:s.id,auto_rate_enabled:s.auto_rate_enabled===!0,rate_content:s.rate_content||"不错的买家,交易愉快",auto_polish_enabled:s.auto_polish_enabled===!0,polish_time:s.polish_time||"03:00",last_rate_scan_at:s.last_rate_scan_at,last_polish_date:s.last_polish_date,last_polish_at:s.last_polish_at}),Y=(s,t,r)=>s===t&&!r.aborted,je=(s,t)=>s instanceof Error?s.message:t,we=s=>s instanceof Error&&s.message==="请求已取消",Ae=(s,t)=>!s&&t==="",Ns=({account:s,onSaved:t})=>{const[r,a]=n.useState(()=>Re(s)),[l,c]=n.useState(!0),[i,d]=n.useState(!1),[b,m]=n.useState(""),[f,h]=n.useState(""),[u,A]=n.useState(null),[k,g]=n.useState(null),p=n.useRef(0),L=n.useRef(null);n.useEffect(()=>{var v;const S=++p.current;(v=L.current)==null||v.abort();const j=new AbortController;return L.current=j,a(Re(s)),A(null),h(""),d(!1),m(""),g(null),c(!0),Ce(s.id,{signal:j.signal}).then(R=>{Y(p.current,S,j.signal)&&a(R)}).catch(R=>{Y(p.current,S,j.signal)&&!we(R)&&h(je(R,"加载任务设置失败"))}).finally(()=>{Y(p.current,S,j.signal)&&c(!1)}),(()=>j.abort())},[s.id]),n.useEffect(()=>(()=>{var S;return(S=L.current)==null?void 0:S.abort()}),[]);const U=n.useCallback(async()=>{var v;if(!Ae(i,b))return;const S=++p.current;(v=L.current)==null||v.abort();const j=new AbortController;L.current=j,d(!0),h(""),g(null);try{const R=await Se(s.id,r,{signal:j.signal});if(!Y(p.current,S,j.signal))return;a(R),t(R)}catch(R){Y(p.current,S,j.signal)&&!we(R)&&(h(je(R,"保存失败")),g(()=>U))}finally{Y(p.current,S,j.signal)&&d(!1)}},[s.id,r,t,b,i]),M=n.useCallback(async S=>{var R;if(!Ae(i,b)||!s.enabled)return;const j=++p.current;(R=L.current)==null||R.abort();const v=new AbortController;L.current=v,m(S),h(""),A(null),g(null);try{await Se(s.id,r,{signal:v.signal});const w=await vs(s.id,S,{signal:v.signal}),q=await Ce(s.id,{signal:v.signal});if(!Y(p.current,j,v.signal))return;A(w.summary),a(q),t(q)}catch(w){Y(p.current,j,v.signal)&&!we(w)&&(h(je(w,"任务执行失败")),g(()=>(()=>M(S))))}finally{Y(p.current,j,v.signal)&&m("")}},[s.enabled,s.id,r,t,b,i]),T=n.useCallback(async()=>{k&&await k()},[k]);return{form:r,loading:l,saving:i,running:b,summary:u,error:f,retryAvailable:k!==null,setForm:a,save:U,run:M,retry:T}},qe=({checked:s,onChange:t,label:r})=>e.jsx("button",{type:"button","aria-label":r,"aria-pressed":s,onClick:t,className:`relative h-8 w-14 shrink-0 rounded-full transition-colors ${s?"bg-sky-500":"bg-slate-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-sm transition-transform ${s?"translate-x-6":""}`})}),ks=({account:s,onClose:t,onSaved:r})=>{const{form:a,loading:l,saving:c,running:i,error:d,summary:b,retryAvailable:m,setForm:f,save:h,run:u,retry:A}=Ns({account:s,onSaved:r});return e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"640px"},role:"dialog","aria-modal":"true","aria-labelledby":"account-task-title",children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"account-task-title",className:"text-2xl font-extrabold text-slate-950",children:"账号自动任务"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:s.nickname||s.remark||s.id})]}),e.jsx("button",{type:"button",onClick:t,className:"rounded-xl p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700","aria-label":"关闭",children:e.jsx(de,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[l&&e.jsx("div",{className:"rounded-xl bg-slate-50 px-4 py-3 text-sm text-slate-500",children:"正在读取任务设置..."}),e.jsx("section",{className:"rounded-2xl border border-slate-200 bg-white p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-emerald-50 text-emerald-600",children:e.jsx(ze,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-slate-900",children:"自动评价"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-slate-500",children:"持续扫描待评价订单,按订单执行;不是每日任务。"})]}),e.jsx(qe,{checked:a.auto_rate_enabled,onChange:(()=>f(k=>({...k,auto_rate_enabled:!k.auto_rate_enabled}))),label:"自动评价"})]}),e.jsx("label",{className:"mt-4 block text-xs font-extrabold text-slate-600",children:"统一好评文案"}),e.jsx("textarea",{"aria-label":"统一好评文案",value:a.rate_content,maxLength:500,onChange:(k=>f(g=>({...g,rate_content:k.target.value}))),className:"mt-2 h-24 w-full resize-none rounded-xl border border-slate-200 bg-slate-50 px-3 py-2.5 text-sm leading-6 text-slate-800 placeholder:text-slate-400 outline-none focus:border-sky-400 focus:ring-2 focus:ring-sky-100"}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-xs text-slate-400",children:["最近扫描:",a.last_rate_scan_at?new Date(a.last_rate_scan_at*1e3).toLocaleString("zh-CN"):"尚未执行"]}),e.jsxs("button",{type:"button",disabled:i!==""||!s.enabled,onClick:(()=>void u("auto_rate")),className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-3 py-2 text-xs font-extrabold text-emerald-700 hover:bg-emerald-100 disabled:opacity-50",children:[i==="auto_rate"?e.jsx(J,{className:"h-4 w-4 animate-spin"}):e.jsx(Ge,{className:"h-4 w-4"}),"立即评价"]})]})]})]})}),e.jsx("section",{className:"rounded-2xl border border-slate-200 bg-white p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-amber-50 text-amber-600",children:e.jsx(Ie,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-slate-900",children:"每日自动擦亮"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-slate-500",children:"每个账号每天最多执行一次,按北京时间判断。"})]}),e.jsx(qe,{checked:a.auto_polish_enabled,onChange:(()=>f(k=>({...k,auto_polish_enabled:!k.auto_polish_enabled}))),label:"每日自动擦亮"})]}),e.jsxs("div",{className:"mt-4 flex items-end justify-between gap-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-extrabold text-slate-600",children:"每日执行时间"}),e.jsx("input",{type:"time",value:a.polish_time,onChange:(k=>f(g=>({...g,polish_time:k.target.value}))),className:"mt-2 block rounded-xl border border-slate-200 bg-slate-50 px-3 py-2 text-sm font-bold text-slate-800 outline-none focus:border-sky-400"})]}),e.jsxs("button",{type:"button",disabled:i!==""||!s.enabled,onClick:(()=>void u("auto_polish")),className:"flex items-center gap-2 rounded-xl bg-amber-50 px-3 py-2 text-xs font-extrabold text-amber-700 hover:bg-amber-100 disabled:opacity-50",children:[i==="auto_polish"?e.jsx(J,{className:"h-4 w-4 animate-spin"}):e.jsx(Te,{className:"h-4 w-4"}),"立即擦亮"]})]}),e.jsxs("div",{className:"mt-3 text-xs text-slate-400",children:["上次完成:",a.last_polish_at?new Date(a.last_polish_at*1e3).toLocaleString("zh-CN"):"尚未执行"]})]})]})}),b&&e.jsxs("div",{className:"rounded-xl border border-sky-100 bg-sky-50 px-4 py-3 text-sm text-sky-900",children:["本次发现 ",b.found," 项,成功 ",b.success,",失败 ",b.failed,",跳过 ",b.skipped,"。",b.message||""]}),d&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm font-medium text-red-700",children:[e.jsx("span",{children:d}),m&&e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>void A()),children:"重试"})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex w-full gap-3",children:[e.jsx("button",{type:"button",onClick:t,disabled:c||i!=="",className:"flex-1 rounded-xl bg-gray-100 px-6 py-3 font-bold text-gray-700 transition-colors hover:bg-gray-200 disabled:opacity-50",children:"关闭"}),e.jsxs("button",{type:"button",onClick:(()=>void h()),disabled:c||i!==""||a.auto_rate_enabled&&!a.rate_content.trim(),className:"ios-btn-primary flex flex-1 items-center justify-center gap-2 rounded-xl px-6 py-3 font-bold disabled:opacity-50",children:[c?e.jsx(J,{className:"h-4 w-4 animate-spin"}):e.jsx($e,{className:"h-4 w-4"}),"保存"]})]})})]})})},Qe=({src:s,alt:t,className:r=""})=>e.jsx("img",{src:s,alt:t,className:`block aspect-square h-auto w-full object-contain ${r}`.trim()}),Cs=({account:s,editForm:t,setEditForm:r,saving:a,onClose:l,onSave:c,onRestartPause:i,longLogin:d,onToggleLongLogin:b,passwordLoginView:m,onPasswordLogin:f,onCancelPasswordLogin:h,notifChannels:u,selectedChannelIds:A,bindingsLoaded:k,bindingsLoading:g,bindingsLoadError:p,onRetryBindings:L,onToggleChannel:U,onSettingsDirty:M})=>{const T=(C,W)=>{r(ee=>({...ee,[C]:W}))},S=()=>void l(),j=()=>void c(),v=C=>T("remark",C.target.value),R=C=>T("cookie",C.target.value),w=()=>T("auto_confirm",!t.auto_confirm),q=C=>T("pause_duration",parseInt(C.target.value,10)||0),D=()=>void i(),H=()=>void b(),K=C=>T("username",C.target.value),G=C=>r(W=>({...W,login_password:C.target.value,clear_password:!1})),V=()=>T("showLoginPassword",!t.showLoginPassword),O=C=>r(W=>({...W,clear_password:C.target.checked,login_password:C.target.checked?"":W.login_password})),I=()=>T("show_browser",!t.show_browser),z=()=>void h(),E=()=>void f(),Q=()=>void L(),F=C=>{k&&(U(C),M())},re=C=>{const W=A.includes(Number(C.id)),ee=()=>F(Number(C.id));return e.jsxs("label",{className:"flex items-center gap-3 p-3 rounded-xl border border-gray-200 hover:bg-gray-50 cursor-pointer transition-colors",children:[e.jsx("button",{type:"button",onClick:ee,disabled:!k,className:`w-5 h-5 rounded-md border-2 flex items-center justify-center transition-colors flex-shrink-0 ${W?"bg-brand border-brand":"bg-white border-gray-300"}`,children:W&&e.jsx(te,{className:"w-3.5 h-3.5 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm",children:C.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:[C.type,C.enabled?"":" · 已停用"]})]})]},C.id)};return ie.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"600px"},children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑账号"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:s.nickname||s.remark||s.id})]}),e.jsx("button",{onClick:S,className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",children:e.jsx(de,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"账号ID"}),e.jsx("input",{type:"text",value:s.id,disabled:!0,className:"w-full ios-input px-4 py-3 rounded-xl bg-gray-50 text-gray-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注"}),e.jsx("input",{type:"text",value:t.remark,onChange:v,placeholder:"为账号添加备注",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"Cookie"}),e.jsx("textarea",{value:t.cookie,onChange:R,placeholder:"更新账号Cookie",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none font-mono text-xs"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["当前Cookie长度: ",t.cookie.length," 字符"]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(te,{className:"w-4 h-4 text-green-500"}),"自动确认发货"]}),e.jsx("div",{className:"text-xs text-gray-500",children:"自动将闲鱼订单标记为已发货"})]}),e.jsx("button",{type:"button",onClick:w,className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${t.auto_confirm?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${t.auto_confirm?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2 flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4 text-blue-500"}),"暂停处理时长(分钟)"]}),e.jsx("input",{type:"number",value:t.pause_duration,onChange:q,placeholder:"0",min:"0",max:"1440",className:"w-full ios-input px-4 py-3 rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"设置后会暂停处理该账号的订单,到时间后自动恢复"}),t.pause_duration>0&&!s.paused&&t.pause_duration===(s.pause_duration||0)&&e.jsx("button",{type:"button",disabled:a,onClick:D,className:"mt-3 px-4 py-2 rounded-xl bg-amber-50 text-amber-700 hover:bg-amber-100 text-sm font-bold disabled:opacity-50",children:"立即按当前时长重新暂停"})]}),e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsxs("h3",{className:"text-lg font-bold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(We,{className:"w-5 h-5 text-blue-500"}),"登录信息"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl bg-blue-50 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"保存登录信息"}),e.jsx("div",{className:"mt-1 text-xs text-gray-500",children:"状态直接读取并修改闲鱼官方长登录设置"}),d.error&&e.jsx("div",{className:"mt-1 text-xs text-red-600",children:d.error})]}),e.jsx("button",{type:"button","aria-label":"保存登录信息",disabled:d.loading||d.saving||!d.canOpen,onClick:H,className:`relative h-8 w-14 flex-shrink-0 rounded-full transition-colors ${d.enabled?"bg-brand":"bg-gray-300"} disabled:cursor-not-allowed disabled:opacity-50`,children:e.jsx("span",{className:`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-md transition-transform ${d.enabled?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"用户名"}),e.jsx("input",{type:"text",value:t.username,onChange:K,placeholder:"闲鱼账号/手机号",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"登录密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:t.showLoginPassword?"text":"password",value:t.login_password,onChange:G,placeholder:"用于自动登录",className:"w-full ios-input px-4 py-3 rounded-xl pr-12"}),e.jsx("button",{type:"button",onClick:V,className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:t.showLoginPassword?e.jsx(Ve,{className:"w-5 h-5"}):e.jsx(Je,{className:"w-5 h-5"})})]}),e.jsxs("label",{className:"mt-3 flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:t.clear_password,onChange:O,className:"w-4 h-4 accent-brand"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:"清空已保存密码"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"登录时显示浏览器"}),e.jsx("div",{className:"text-xs text-gray-500",children:"调试时可开启查看登录过程"})]}),e.jsx("button",{type:"button",onClick:I,className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${t.show_browser?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${t.show_browser?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{className:"rounded-xl border border-blue-100 bg-blue-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-blue-950",children:"立即执行账号密码登录"}),e.jsx("div",{className:"text-xs text-blue-700 mt-1",children:"需要在上方重新输入本次登录密码;成功后后端会更新 Cookie 和保存的登录信息。"})]}),m.status==="processing"||m.status==="verification_required"?e.jsx("button",{type:"button",onClick:z,className:"px-4 py-2 rounded-xl bg-white text-red-600 font-bold text-sm border border-red-100",children:"取消登录"}):e.jsx("button",{type:"button",onClick:E,className:"px-4 py-2 rounded-xl bg-blue-600 text-white font-bold text-sm whitespace-nowrap",children:"密码登录刷新授权"})]}),m.message&&e.jsx("div",{className:`text-sm font-medium ${m.status==="failed"?"text-red-700":m.status==="success"?"text-green-700":"text-blue-800"}`,children:m.message}),m.status==="verification_required"&&e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-3 text-amber-900",children:[e.jsx("div",{className:"font-extrabold",children:"账号已触发平台风控,需要完成人脸识别"}),e.jsx("div",{className:"text-xs mt-1 leading-5",children:"请在闲鱼 App 或已打开的登录浏览器中按提示完成验证。本页面不会提供可直接打开的风控链接。"}),m.qrCodeUrl&&e.jsx("div",{className:"mt-3 aspect-square w-48 overflow-hidden rounded-xl border bg-white",children:e.jsx(Qe,{src:m.qrCodeUrl,alt:"密码登录风控二维码",className:"p-2"})})]})]})]})]}),(u.length>0||g||p)&&e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsxs("h3",{className:"text-lg font-bold text-gray-900 mb-1 flex items-center gap-2",children:[e.jsx(Ke,{className:"w-5 h-5 text-blue-500"}),"通知渠道绑定"]}),e.jsx("p",{className:"text-xs text-gray-500 mb-4",children:"勾选后,该账号的 token 失效、自动恢复失败、风控验证等事件会推送到这些渠道"}),g&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"正在加载通知绑定"]}),p&&!g&&e.jsxs("div",{className:"mb-3 rounded-xl bg-amber-50 p-3 text-sm text-amber-800 flex items-center justify-between gap-3",children:[e.jsx("span",{children:p}),e.jsx("button",{type:"button",className:"font-bold whitespace-nowrap",onClick:Q,children:"重试"})]}),e.jsx("div",{className:"space-y-2",children:u.map(re)})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:S,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:a,children:"取消"}),e.jsxs("button",{onClick:j,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:a,children:[a?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(te,{className:"w-4 h-4"}),a?"保存中...":"保存"]})]})})]})}),document.body)},Ss=({account:s,settings:t,saving:r,onChange:a,onClose:l,onSave:c})=>{const i=u=>a({...t,...u}),d=()=>i({ai_enabled:!t.ai_enabled}),b=u=>i({max_discount_percent:parseInt(u.target.value,10)||0}),m=u=>i({max_discount_amount:parseInt(u.target.value,10)||0}),f=u=>i({max_bargain_rounds:parseInt(u.target.value,10)||1}),h=u=>i({custom_prompts:u.target.value});return ie.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"600px"},children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-2xl font-extrabold text-gray-900 flex items-center gap-2",children:[e.jsx(ue,{className:"w-6 h-6 text-purple-500"}),"AI助手设置"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:s.nickname||s.remark||s.id})]}),e.jsx("button",{onClick:l,className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0","aria-label":"关闭 AI 设置",children:e.jsx(de,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-purple-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(ue,{className:"w-4 h-4 text-purple-500"}),"启用AI自动回复"]}),e.jsx("div",{className:"text-xs text-gray-500",children:"AI将自动处理买家的砍价消息"})]}),e.jsx("button",{type:"button",onClick:d,className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${t.ai_enabled?"bg-brand":"bg-gray-300"}`,"aria-label":"切换 AI 自动回复",children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${t.ai_enabled?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsx("h3",{className:"text-lg font-bold text-gray-900 mb-4",children:"砍价策略"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大折扣比例 (%)"}),e.jsx("input",{type:"number",value:t.max_discount_percent,onChange:b,className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"100"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"例如:10 表示最多降价 10%;设为 0 表示不允许降价"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大折扣金额 (元)"}),e.jsx("input",{type:"number",value:t.max_discount_amount,onChange:m,className:"w-full ios-input px-4 py-3 rounded-xl",min:"0"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"例如:100 表示最多降价 100 元;设为 0 表示不允许降价"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大砍价轮次"}),e.jsx("input",{type:"number",value:t.max_bargain_rounds,onChange:f,className:"w-full ios-input px-4 py-3 rounded-xl",min:"1",max:"10"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"买家最多可以砍价的次数"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"自定义提示词(可选)"}),e.jsx("textarea",{value:t.custom_prompts,onChange:h,placeholder:`输入自定义的AI回复规则或风格指引...
+import{r as n,j as e,b as ie,c as Oe}from"./react-vendor-C_od1ZSF.js";import{g as X,p as ae,a as ce,d as Pe}from"./index-CNzF_I4S.js";import{c as Le,o as ke}from"./contract-COFcZjyb.js";import{X as de,n as ze,L as J,o as Ge,p as Ie,q as Te,r as $e,s as te,t as De,K as We,u as Ve,v as Je,e as Ke,w as ue,f as He,U as Ee,x as Xe,k as _e,Q as ve,R as Ye,y as Ze,z as Fe,F as Ne,H as es}from"./icons-vendor-CvzvbbIV.js";const ss=(s,t)=>{const r=s.avatar_url||"";if(!r)return"";try{const a=new URL(r,window.location.origin);return a.hostname.endsWith("alicdn.com")&&a.searchParams.set("_v",t),a.toString()}catch{return r}},ts=async s=>{const t=await X("/api/v1/accounts/details",void 0,s),r=Le(t,["data","accounts","details"]),a=Date.now().toString();return r.map(l=>({id:l.id,cookie_configured:l.has_cookie===!0,enabled:l.enabled,auto_confirm:l.auto_confirm,remark:l.remark,pause_duration:l.pause_duration,paused_until:Number(l.paused_until||0),paused:l.paused===!0,username:l.username||"",login_password_configured:void 0,show_browser:l.show_browser===!0||l.show_browser===1||l.show_browser==="1"||l.show_browser==="true",nickname:l.nickname||l.remark||`账号 ${l.id.substring(0,6)}`,avatar_url:ss(l,a),profile_error:l.profile_error||"",ai_enabled:!1,auto_rate_enabled:l.auto_rate_enabled,rate_content:l.rate_content||"不错的买家,交易愉快",auto_polish_enabled:l.auto_polish_enabled,polish_time:l.polish_time||"03:00",last_rate_scan_at:Number(l.last_rate_scan_at||0),last_polish_date:l.last_polish_date||"",last_polish_at:Number(l.last_polish_at||0)}))},as=async s=>{const t=await X("/api/v1/accounts/runtime-status",void 0,s);return ke(t,["statuses","data","result"])||{}},rs=async s=>ce("/api/v1/qr-login/generate",void 0,{...s,timeoutMs:(s==null?void 0:s.timeoutMs)??13e4}),ns=async(s,t)=>X(`/api/v1/qr-login/check/${s}`,void 0,{signal:t,timeoutMs:1e4}),ls=async(s,t)=>ce(`/api/v1/qr-login/complete-verification/${s}`,{target_account_id:t||""}),os=async(s,t)=>ae(`/api/v1/accounts/${s}/status`,{enabled:t}),is=async s=>Pe(`/api/v1/accounts/${s}`),cs=async(s,t,r)=>ae(`/api/v1/accounts/${s}/pause-duration`,{pause_duration:t},r),ds=async(s,t,r)=>ae(`/api/v1/accounts/${s}/settings`,t,r),us=async(s,t)=>X(`/api/v1/accounts/${s}/long-login`,void 0,t),xs=async(s,t,r)=>ae(`/api/v1/accounts/${s}/long-login`,{enabled:t},r),ms=async(s,t)=>ce("/api/v1/password-login",s,t),bs=async(s,t)=>X(`/api/v1/password-login/check/${s}`,void 0,{signal:t,timeoutMs:1e4}),hs=async(s,t)=>Pe(`/api/v1/password-login/cancel/${s}`,void 0,t),gs=async s=>ce(`/api/v1/accounts/${s}/refresh-profile`,{}),ps=async s=>{const t=await X("/api/v1/settings/ai-reply",void 0,s);return ke(t,["settings","data","result"])||{}},fs=async(s,t)=>X(`/api/v1/settings/ai-reply/${s}`,void 0,t),ys=async(s,t,r)=>{const a={ai_enabled:t.ai_enabled??!1,max_discount_percent:t.max_discount_percent??10,max_discount_amount:t.max_discount_amount??100,max_bargain_rounds:t.max_bargain_rounds??3,custom_prompts:t.custom_prompts??""};return ae(`/api/v1/settings/ai-reply/${s}`,a,r)},js=s=>{if(Array.isArray(s))return s.filter(Boolean);if(typeof s!="string"||!s.trim())return[];try{const t=JSON.parse(s);if(Array.isArray(t))return t.filter(Boolean)}catch{}return s.split(/[,\s;]+/).map(t=>t.trim()).filter(Boolean)},ws=async s=>{const t=await X("/api/v1/notifications/channels",void 0,s);return{success:!0,data:Le(t,["data","channels","items"]).map(a=>{let l;try{l=typeof a.config=="string"?JSON.parse(a.config):a.config}catch{l={}}const c=a.type==="ding_talk"?"dingtalk":a.type==="lark"?"feishu":a.type;return{id:String(a.id),name:a.name,type:c,config:l,event_types:js(a.event_types),enabled:a.enabled,created_at:a.created_at,updated_at:a.updated_at}})}},_s=async(s,t)=>{const r=await X(`/api/v1/notifications/accounts/${s}/bindings`,void 0,t),a=ke(r,["data","result"])||{};return Array.isArray(a.channel_ids)?a.channel_ids:[]},Ce=async(s,t)=>X(`/api/v1/account-tasks/${s}`,void 0,t),Se=async(s,t,r)=>ae(`/api/v1/account-tasks/${s}`,t,r),vs=async(s,t,r)=>ce(`/api/v1/account-tasks/${s}/run`,{task_type:t},{timeoutMs:12e4,...r}),Re=s=>({account_id:s.id,auto_rate_enabled:s.auto_rate_enabled===!0,rate_content:s.rate_content||"不错的买家,交易愉快",auto_polish_enabled:s.auto_polish_enabled===!0,polish_time:s.polish_time||"03:00",last_rate_scan_at:s.last_rate_scan_at,last_polish_date:s.last_polish_date,last_polish_at:s.last_polish_at}),Y=(s,t,r)=>s===t&&!r.aborted,je=(s,t)=>s instanceof Error?s.message:t,we=s=>s instanceof Error&&s.message==="请求已取消",Ae=(s,t)=>!s&&t==="",Ns=({account:s,onSaved:t})=>{const[r,a]=n.useState(()=>Re(s)),[l,c]=n.useState(!0),[i,d]=n.useState(!1),[b,m]=n.useState(""),[f,h]=n.useState(""),[u,A]=n.useState(null),[k,g]=n.useState(null),p=n.useRef(0),L=n.useRef(null);n.useEffect(()=>{var v;const S=++p.current;(v=L.current)==null||v.abort();const j=new AbortController;return L.current=j,a(Re(s)),A(null),h(""),d(!1),m(""),g(null),c(!0),Ce(s.id,{signal:j.signal}).then(R=>{Y(p.current,S,j.signal)&&a(R)}).catch(R=>{Y(p.current,S,j.signal)&&!we(R)&&h(je(R,"加载任务设置失败"))}).finally(()=>{Y(p.current,S,j.signal)&&c(!1)}),(()=>j.abort())},[s.id]),n.useEffect(()=>(()=>{var S;return(S=L.current)==null?void 0:S.abort()}),[]);const U=n.useCallback(async()=>{var v;if(!Ae(i,b))return;const S=++p.current;(v=L.current)==null||v.abort();const j=new AbortController;L.current=j,d(!0),h(""),g(null);try{const R=await Se(s.id,r,{signal:j.signal});if(!Y(p.current,S,j.signal))return;a(R),t(R)}catch(R){Y(p.current,S,j.signal)&&!we(R)&&(h(je(R,"保存失败")),g(()=>U))}finally{Y(p.current,S,j.signal)&&d(!1)}},[s.id,r,t,b,i]),M=n.useCallback(async S=>{var R;if(!Ae(i,b)||!s.enabled)return;const j=++p.current;(R=L.current)==null||R.abort();const v=new AbortController;L.current=v,m(S),h(""),A(null),g(null);try{await Se(s.id,r,{signal:v.signal});const w=await vs(s.id,S,{signal:v.signal}),q=await Ce(s.id,{signal:v.signal});if(!Y(p.current,j,v.signal))return;A(w.summary),a(q),t(q)}catch(w){Y(p.current,j,v.signal)&&!we(w)&&(h(je(w,"任务执行失败")),g(()=>(()=>M(S))))}finally{Y(p.current,j,v.signal)&&m("")}},[s.enabled,s.id,r,t,b,i]),T=n.useCallback(async()=>{k&&await k()},[k]);return{form:r,loading:l,saving:i,running:b,summary:u,error:f,retryAvailable:k!==null,setForm:a,save:U,run:M,retry:T}},qe=({checked:s,onChange:t,label:r})=>e.jsx("button",{type:"button","aria-label":r,"aria-pressed":s,onClick:t,className:`relative h-8 w-14 shrink-0 rounded-full transition-colors ${s?"bg-sky-500":"bg-slate-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-sm transition-transform ${s?"translate-x-6":""}`})}),ks=({account:s,onClose:t,onSaved:r})=>{const{form:a,loading:l,saving:c,running:i,error:d,summary:b,retryAvailable:m,setForm:f,save:h,run:u,retry:A}=Ns({account:s,onSaved:r});return e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"640px"},role:"dialog","aria-modal":"true","aria-labelledby":"account-task-title",children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"account-task-title",className:"text-2xl font-extrabold text-slate-950",children:"账号自动任务"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:s.nickname||s.remark||s.id})]}),e.jsx("button",{type:"button",onClick:t,className:"rounded-xl p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700","aria-label":"关闭",children:e.jsx(de,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[l&&e.jsx("div",{className:"rounded-xl bg-slate-50 px-4 py-3 text-sm text-slate-500",children:"正在读取任务设置..."}),e.jsx("section",{className:"rounded-2xl border border-slate-200 bg-white p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-emerald-50 text-emerald-600",children:e.jsx(ze,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-slate-900",children:"自动评价"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-slate-500",children:"持续扫描待评价订单,按订单执行;不是每日任务。"})]}),e.jsx(qe,{checked:a.auto_rate_enabled,onChange:(()=>f(k=>({...k,auto_rate_enabled:!k.auto_rate_enabled}))),label:"自动评价"})]}),e.jsx("label",{className:"mt-4 block text-xs font-extrabold text-slate-600",children:"统一好评文案"}),e.jsx("textarea",{"aria-label":"统一好评文案",value:a.rate_content,maxLength:500,onChange:(k=>f(g=>({...g,rate_content:k.target.value}))),className:"mt-2 h-24 w-full resize-none rounded-xl border border-slate-200 bg-slate-50 px-3 py-2.5 text-sm leading-6 text-slate-800 placeholder:text-slate-400 outline-none focus:border-sky-400 focus:ring-2 focus:ring-sky-100"}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-xs text-slate-400",children:["最近扫描:",a.last_rate_scan_at?new Date(a.last_rate_scan_at*1e3).toLocaleString("zh-CN"):"尚未执行"]}),e.jsxs("button",{type:"button",disabled:i!==""||!s.enabled,onClick:(()=>void u("auto_rate")),className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-3 py-2 text-xs font-extrabold text-emerald-700 hover:bg-emerald-100 disabled:opacity-50",children:[i==="auto_rate"?e.jsx(J,{className:"h-4 w-4 animate-spin"}):e.jsx(Ge,{className:"h-4 w-4"}),"立即评价"]})]})]})]})}),e.jsx("section",{className:"rounded-2xl border border-slate-200 bg-white p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-amber-50 text-amber-600",children:e.jsx(Ie,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-slate-900",children:"每日自动擦亮"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-slate-500",children:"每个账号每天最多执行一次,按北京时间判断。"})]}),e.jsx(qe,{checked:a.auto_polish_enabled,onChange:(()=>f(k=>({...k,auto_polish_enabled:!k.auto_polish_enabled}))),label:"每日自动擦亮"})]}),e.jsxs("div",{className:"mt-4 flex items-end justify-between gap-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-extrabold text-slate-600",children:"每日执行时间"}),e.jsx("input",{type:"time",value:a.polish_time,onChange:(k=>f(g=>({...g,polish_time:k.target.value}))),className:"mt-2 block rounded-xl border border-slate-200 bg-slate-50 px-3 py-2 text-sm font-bold text-slate-800 outline-none focus:border-sky-400"})]}),e.jsxs("button",{type:"button",disabled:i!==""||!s.enabled,onClick:(()=>void u("auto_polish")),className:"flex items-center gap-2 rounded-xl bg-amber-50 px-3 py-2 text-xs font-extrabold text-amber-700 hover:bg-amber-100 disabled:opacity-50",children:[i==="auto_polish"?e.jsx(J,{className:"h-4 w-4 animate-spin"}):e.jsx(Te,{className:"h-4 w-4"}),"立即擦亮"]})]}),e.jsxs("div",{className:"mt-3 text-xs text-slate-400",children:["上次完成:",a.last_polish_at?new Date(a.last_polish_at*1e3).toLocaleString("zh-CN"):"尚未执行"]})]})]})}),b&&e.jsxs("div",{className:"rounded-xl border border-sky-100 bg-sky-50 px-4 py-3 text-sm text-sky-900",children:["本次发现 ",b.found," 项,成功 ",b.success,",失败 ",b.failed,",跳过 ",b.skipped,"。",b.message||""]}),d&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm font-medium text-red-700",children:[e.jsx("span",{children:d}),m&&e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>void A()),children:"重试"})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex w-full gap-3",children:[e.jsx("button",{type:"button",onClick:t,disabled:c||i!=="",className:"flex-1 rounded-xl bg-gray-100 px-6 py-3 font-bold text-gray-700 transition-colors hover:bg-gray-200 disabled:opacity-50",children:"关闭"}),e.jsxs("button",{type:"button",onClick:(()=>void h()),disabled:c||i!==""||a.auto_rate_enabled&&!a.rate_content.trim(),className:"ios-btn-primary flex flex-1 items-center justify-center gap-2 rounded-xl px-6 py-3 font-bold disabled:opacity-50",children:[c?e.jsx(J,{className:"h-4 w-4 animate-spin"}):e.jsx($e,{className:"h-4 w-4"}),"保存"]})]})})]})})},Qe=({src:s,alt:t,className:r=""})=>e.jsx("img",{src:s,alt:t,className:`block aspect-square h-auto w-full object-contain ${r}`.trim()}),Cs=({account:s,editForm:t,setEditForm:r,saving:a,onClose:l,onSave:c,onRestartPause:i,longLogin:d,onToggleLongLogin:b,passwordLoginView:m,onPasswordLogin:f,onCancelPasswordLogin:h,notifChannels:u,selectedChannelIds:A,bindingsLoaded:k,bindingsLoading:g,bindingsLoadError:p,onRetryBindings:L,onToggleChannel:U,onSettingsDirty:M})=>{const T=(C,W)=>{r(ee=>({...ee,[C]:W}))},S=()=>void l(),j=()=>void c(),v=C=>T("remark",C.target.value),R=C=>T("cookie",C.target.value),w=()=>T("auto_confirm",!t.auto_confirm),q=C=>T("pause_duration",parseInt(C.target.value,10)||0),D=()=>void i(),H=()=>void b(),K=C=>T("username",C.target.value),G=C=>r(W=>({...W,login_password:C.target.value,clear_password:!1})),V=()=>T("showLoginPassword",!t.showLoginPassword),O=C=>r(W=>({...W,clear_password:C.target.checked,login_password:C.target.checked?"":W.login_password})),I=()=>T("show_browser",!t.show_browser),z=()=>void h(),E=()=>void f(),Q=()=>void L(),F=C=>{k&&(U(C),M())},re=C=>{const W=A.includes(Number(C.id)),ee=()=>F(Number(C.id));return e.jsxs("label",{className:"flex items-center gap-3 p-3 rounded-xl border border-gray-200 hover:bg-gray-50 cursor-pointer transition-colors",children:[e.jsx("button",{type:"button",onClick:ee,disabled:!k,className:`w-5 h-5 rounded-md border-2 flex items-center justify-center transition-colors flex-shrink-0 ${W?"bg-brand border-brand":"bg-white border-gray-300"}`,children:W&&e.jsx(te,{className:"w-3.5 h-3.5 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm",children:C.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:[C.type,C.enabled?"":" · 已停用"]})]})]},C.id)};return ie.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"600px"},children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑账号"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:s.nickname||s.remark||s.id})]}),e.jsx("button",{onClick:S,className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",children:e.jsx(de,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"账号ID"}),e.jsx("input",{type:"text",value:s.id,disabled:!0,className:"w-full ios-input px-4 py-3 rounded-xl bg-gray-50 text-gray-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注"}),e.jsx("input",{type:"text",value:t.remark,onChange:v,placeholder:"为账号添加备注",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"Cookie"}),e.jsx("textarea",{value:t.cookie,onChange:R,placeholder:"更新账号Cookie",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none font-mono text-xs"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["当前Cookie长度: ",t.cookie.length," 字符"]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(te,{className:"w-4 h-4 text-green-500"}),"自动确认发货"]}),e.jsx("div",{className:"text-xs text-gray-500",children:"自动将闲鱼订单标记为已发货"})]}),e.jsx("button",{type:"button",onClick:w,className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${t.auto_confirm?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${t.auto_confirm?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2 flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4 text-blue-500"}),"暂停处理时长(分钟)"]}),e.jsx("input",{type:"number",value:t.pause_duration,onChange:q,placeholder:"0",min:"0",max:"1440",className:"w-full ios-input px-4 py-3 rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"设置后会暂停处理该账号的订单,到时间后自动恢复"}),t.pause_duration>0&&!s.paused&&t.pause_duration===(s.pause_duration||0)&&e.jsx("button",{type:"button",disabled:a,onClick:D,className:"mt-3 px-4 py-2 rounded-xl bg-amber-50 text-amber-700 hover:bg-amber-100 text-sm font-bold disabled:opacity-50",children:"立即按当前时长重新暂停"})]}),e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsxs("h3",{className:"text-lg font-bold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(We,{className:"w-5 h-5 text-blue-500"}),"登录信息"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl bg-blue-50 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"保存登录信息"}),e.jsx("div",{className:"mt-1 text-xs text-gray-500",children:"状态直接读取并修改闲鱼官方长登录设置"}),d.error&&e.jsx("div",{className:"mt-1 text-xs text-red-600",children:d.error})]}),e.jsx("button",{type:"button","aria-label":"保存登录信息",disabled:d.loading||d.saving||!d.canOpen,onClick:H,className:`relative h-8 w-14 flex-shrink-0 rounded-full transition-colors ${d.enabled?"bg-brand":"bg-gray-300"} disabled:cursor-not-allowed disabled:opacity-50`,children:e.jsx("span",{className:`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-md transition-transform ${d.enabled?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"用户名"}),e.jsx("input",{type:"text",value:t.username,onChange:K,placeholder:"闲鱼账号/手机号",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"登录密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:t.showLoginPassword?"text":"password",value:t.login_password,onChange:G,placeholder:"用于自动登录",className:"w-full ios-input px-4 py-3 rounded-xl pr-12"}),e.jsx("button",{type:"button",onClick:V,className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:t.showLoginPassword?e.jsx(Ve,{className:"w-5 h-5"}):e.jsx(Je,{className:"w-5 h-5"})})]}),e.jsxs("label",{className:"mt-3 flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:t.clear_password,onChange:O,className:"w-4 h-4 accent-brand"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:"清空已保存密码"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"登录时显示浏览器"}),e.jsx("div",{className:"text-xs text-gray-500",children:"调试时可开启查看登录过程"})]}),e.jsx("button",{type:"button",onClick:I,className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${t.show_browser?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${t.show_browser?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{className:"rounded-xl border border-blue-100 bg-blue-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-blue-950",children:"立即执行账号密码登录"}),e.jsx("div",{className:"text-xs text-blue-700 mt-1",children:"需要在上方重新输入本次登录密码;成功后后端会更新 Cookie 和保存的登录信息。"})]}),m.status==="processing"||m.status==="verification_required"?e.jsx("button",{type:"button",onClick:z,className:"px-4 py-2 rounded-xl bg-white text-red-600 font-bold text-sm border border-red-100",children:"取消登录"}):e.jsx("button",{type:"button",onClick:E,className:"px-4 py-2 rounded-xl bg-blue-600 text-white font-bold text-sm whitespace-nowrap",children:"密码登录刷新授权"})]}),m.message&&e.jsx("div",{className:`text-sm font-medium ${m.status==="failed"?"text-red-700":m.status==="success"?"text-green-700":"text-blue-800"}`,children:m.message}),m.status==="verification_required"&&e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-3 text-amber-900",children:[e.jsx("div",{className:"font-extrabold",children:"账号已触发平台风控,需要完成人脸识别"}),e.jsx("div",{className:"text-xs mt-1 leading-5",children:"请在闲鱼 App 或已打开的登录浏览器中按提示完成验证。本页面不会提供可直接打开的风控链接。"}),m.qrCodeUrl&&e.jsx("div",{className:"mt-3 aspect-square w-48 overflow-hidden rounded-xl border bg-white",children:e.jsx(Qe,{src:m.qrCodeUrl,alt:"密码登录风控二维码",className:"p-2"})})]})]})]})]}),(u.length>0||g||p)&&e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsxs("h3",{className:"text-lg font-bold text-gray-900 mb-1 flex items-center gap-2",children:[e.jsx(Ke,{className:"w-5 h-5 text-blue-500"}),"通知渠道绑定"]}),e.jsx("p",{className:"text-xs text-gray-500 mb-4",children:"勾选后,该账号的 token 失效、自动恢复失败、风控验证等事件会推送到这些渠道"}),g&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"正在加载通知绑定"]}),p&&!g&&e.jsxs("div",{className:"mb-3 rounded-xl bg-amber-50 p-3 text-sm text-amber-800 flex items-center justify-between gap-3",children:[e.jsx("span",{children:p}),e.jsx("button",{type:"button",className:"font-bold whitespace-nowrap",onClick:Q,children:"重试"})]}),e.jsx("div",{className:"space-y-2",children:u.map(re)})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:S,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:a,children:"取消"}),e.jsxs("button",{onClick:j,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:a,children:[a?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(te,{className:"w-4 h-4"}),a?"保存中...":"保存"]})]})})]})}),document.body)},Ss=({account:s,settings:t,saving:r,onChange:a,onClose:l,onSave:c})=>{const i=u=>a({...t,...u}),d=()=>i({ai_enabled:!t.ai_enabled}),b=u=>i({max_discount_percent:parseInt(u.target.value,10)||0}),m=u=>i({max_discount_amount:parseInt(u.target.value,10)||0}),f=u=>i({max_bargain_rounds:parseInt(u.target.value,10)||1}),h=u=>i({custom_prompts:u.target.value});return ie.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"600px"},children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-2xl font-extrabold text-gray-900 flex items-center gap-2",children:[e.jsx(ue,{className:"w-6 h-6 text-purple-500"}),"AI助手设置"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:s.nickname||s.remark||s.id})]}),e.jsx("button",{onClick:l,className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0","aria-label":"关闭 AI 设置",children:e.jsx(de,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-purple-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(ue,{className:"w-4 h-4 text-purple-500"}),"启用AI自动回复"]}),e.jsx("div",{className:"text-xs text-gray-500",children:"AI将自动处理买家的砍价消息"})]}),e.jsx("button",{type:"button",onClick:d,className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${t.ai_enabled?"bg-brand":"bg-gray-300"}`,"aria-label":"切换 AI 自动回复",children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${t.ai_enabled?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsx("h3",{className:"text-lg font-bold text-gray-900 mb-4",children:"砍价策略"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大折扣比例 (%)"}),e.jsx("input",{type:"number",value:t.max_discount_percent,onChange:b,className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"100"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"例如:10 表示最多降价 10%;设为 0 表示不允许降价"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大折扣金额 (元)"}),e.jsx("input",{type:"number",value:t.max_discount_amount,onChange:m,className:"w-full ios-input px-4 py-3 rounded-xl",min:"0"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"例如:100 表示最多降价 100 元;设为 0 表示不允许降价"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大砍价轮次"}),e.jsx("input",{type:"number",value:t.max_bargain_rounds,onChange:f,className:"w-full ios-input px-4 py-3 rounded-xl",min:"1",max:"10"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"买家最多可以砍价的次数"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"自定义提示词(可选)"}),e.jsx("textarea",{value:t.custom_prompts,onChange:h,placeholder:`输入自定义的AI回复规则或风格指引...
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(He,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:l,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:r,children:"取消"}),e.jsxs("button",{onClick:(()=>void c()),className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:r,children:[r?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx($e,{className:"w-4 h-4"}),r?"保存中...":"保存"]})]})})]})}),document.body)},Rs=(s,t)=>{if(!s||!t)return!1;const r=Date.parse(s),a=Date.parse(t);return Number.isFinite(r)&&Number.isFinite(a)&&as.map(r=>{const a=t[r.id];return!a||Rs(r.runtime_updated_at,a.updated_at)?r:{...r,runtime_state:a.state,runtime_message:a.message||"",runtime_connected:a.connected,runtime_updated_at:a.updated_at}}),qs=s=>{if(!s.enabled||s.runtime_state==="disabled")return{label:"已停用",badge:"bg-gray-100 text-gray-500",dot:"bg-gray-300"};switch(s.runtime_state){case"online":return{label:"在线",badge:"bg-green-100 text-green-700",dot:"bg-green-500"};case"starting":case"connecting":return{label:"连接中",badge:"bg-blue-100 text-blue-700",dot:"bg-blue-500"};case"reconnecting":return{label:"重连中",badge:"bg-amber-100 text-amber-700",dot:"bg-amber-500"};case"auth_expired":return{label:"登录已失效",badge:"bg-red-100 text-red-700",dot:"bg-red-500"};case"verification_required":return{label:"需要验证",badge:"bg-orange-100 text-orange-700",dot:"bg-orange-500"};case"error":case"stopped":return{label:"运行异常",badge:"bg-red-100 text-red-700",dot:"bg-red-500"};default:return{label:"状态检测中",badge:"bg-gray-100 text-gray-600",dot:"bg-gray-400"}}},Ps=Oe.memo(function({account:t,refreshing:r,deleting:a,onRefreshProfile:l,onReauthorize:c,onEdit:i,onAI:d,onTasks:b,onToggle:m,onDelete:f}){const h=qs(t),u=t.runtime_state==="auth_expired"||t.runtime_state==="verification_required";return e.jsx("div",{className:"ios-card rounded-xl p-6 group transition-all duration-300 hover:border-brand",children:e.jsxs("div",{className:"flex min-w-0 items-start gap-5 sm:gap-8",children:[e.jsxs("div",{className:"relative",children:[t.avatar_url?e.jsx("img",{src:t.avatar_url,alt:t.nickname||"账号头像",className:"w-20 h-20 rounded-full object-cover shadow-md ring-4 ring-white bg-gray-100"}):e.jsx("div",{className:"w-20 h-20 rounded-full bg-gray-100 text-gray-400 shadow-md ring-4 ring-white flex items-center justify-center",children:e.jsx(Ee,{className:"w-9 h-9"})}),e.jsx("div",{className:`absolute -bottom-1 -right-1 w-6 h-6 rounded-full border-4 border-white flex items-center justify-center ${h.dot}`,children:t.runtime_state==="online"&&e.jsx(te,{className:"w-3 h-3 text-white"})})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5 mb-1",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900 break-words",children:t.nickname||t.remark||`账号 ${t.id.substring(0,6)}...`}),e.jsx("span",{className:`px-2.5 py-0.5 rounded-lg text-xs font-bold ${h.badge}`,children:h.label}),t.ai_enabled&&e.jsxs("span",{className:"px-2.5 py-0.5 rounded-lg bg-purple-100 text-purple-700 text-xs font-bold flex items-center gap-1",children:[e.jsx(ue,{className:"w-3 h-3"})," AI"]}),t.auto_rate_enabled&&e.jsxs("span",{className:"flex items-center gap-1 rounded-lg bg-emerald-100 px-2.5 py-0.5 text-xs font-bold text-emerald-700",children:[e.jsx(Xe,{className:"h-3 w-3"})," 自动评价"]}),t.auto_polish_enabled&&e.jsxs("span",{className:"flex items-center gap-1 rounded-lg bg-amber-100 px-2.5 py-0.5 text-xs font-bold text-amber-700",children:[e.jsx(Ie,{className:"h-3 w-3"})," 每日擦亮"]}),t.auto_confirm&&e.jsxs("span",{className:"flex items-center gap-1 rounded-lg bg-blue-50 px-2.5 py-0.5 text-xs font-bold text-blue-700",children:[e.jsx(te,{className:"h-3 w-3"})," 自动确认发货"]}),t.profile_error&&e.jsxs("span",{className:"px-2.5 py-0.5 rounded-lg bg-amber-100 text-amber-700 text-xs font-bold flex items-center gap-1",title:t.profile_error,children:[e.jsx(_e,{className:"w-3 h-3"})," 资料未同步"]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-500",children:[e.jsx("p",{children:t.remark||"暂无备注"}),e.jsxs("p",{className:"font-mono text-xs text-gray-400",children:["ID: ",t.id]})]}),t.runtime_message&&t.runtime_state!=="online"&&t.runtime_state!=="disabled"&&e.jsxs("div",{className:`mb-3 flex flex-wrap items-center gap-2 text-sm font-medium ${u?"text-red-700":"text-amber-700"}`,children:[e.jsx(_e,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{children:t.runtime_message}),u&&e.jsxs("button",{type:"button",onClick:(()=>c(t)),className:"inline-flex items-center gap-1.5 rounded-lg bg-red-50 px-2.5 py-1 text-xs font-bold text-red-700 hover:bg-red-100",children:[e.jsx(ve,{className:"w-3.5 h-3.5"})," 重新授权"]})]}),t.paused&&e.jsxs("span",{className:"flex items-center gap-1.5 rounded-lg bg-blue-50 px-3 py-1.5 text-xs font-bold text-blue-700",children:[e.jsx(De,{className:"h-3 w-3"})," 暂停处理中"]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{onClick:(()=>l(t)),disabled:r,className:"p-3 rounded-xl transition-colors text-gray-600 hover:bg-gray-100 disabled:opacity-50",title:"刷新昵称和头像",children:e.jsx(Ye,{className:`w-5 h-5 ${r?"animate-spin":""}`})}),e.jsx("button",{onClick:(()=>c(t)),className:`p-3 rounded-xl transition-colors ${u?"text-red-600 bg-red-50 hover:bg-red-100":"text-blue-600 hover:bg-blue-50"}`,title:"重新扫码授权当前账号",children:e.jsx(ve,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>i(t)),className:"p-3 rounded-xl hover:bg-gray-100 transition-colors text-gray-600",title:"编辑账号",children:e.jsx(Ze,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>d(t)),className:"p-3 rounded-xl hover:bg-purple-100 transition-colors text-purple-600",title:"AI设置",children:e.jsx(ue,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>b(t)),className:"p-3 rounded-xl hover:bg-amber-100 transition-colors text-amber-600",title:"自动评价与每日擦亮",children:e.jsx(Te,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>m(t.id,t.enabled)),className:`p-3 rounded-xl transition-colors ${t.enabled?"text-green-600 hover:bg-green-50":"text-gray-400 hover:bg-gray-100"}`,title:t.enabled?"停用账号":"启用账号",children:e.jsx(Fe,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>f(t)),disabled:a,className:"p-3 rounded-xl hover:bg-red-100 transition-colors text-red-500 disabled:cursor-not-allowed disabled:opacity-40",title:a?"删除中…":`删除账号 ${t.nickname||t.remark||t.id}`,children:a?e.jsx(J,{className:"w-5 h-5 animate-spin"}):e.jsx(Ne,{className:"w-5 h-5"})})]})]})]})]})})}),Ls=({account:s,deleting:t,error:r,onClose:a,onConfirm:l})=>ie.createPortal(e.jsx("div",{className:"modal-overlay-centered",role:"presentation",children:e.jsxs("div",{className:"h-fit w-full max-w-[400px] self-center overflow-hidden rounded-2xl border border-white/80 bg-white shadow-modal",role:"dialog","aria-modal":"true","aria-labelledby":"delete-account-title","aria-describedby":"delete-account-description",children:[e.jsxs("div",{className:"relative overflow-hidden border-b border-red-100 bg-gradient-to-br from-red-50 via-white to-orange-50 px-5 py-5",children:[e.jsx("div",{className:"absolute -right-12 -top-16 h-36 w-36 rounded-full bg-red-200/35 blur-2xl"}),e.jsxs("div",{className:"relative flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-red-600 text-white shadow-md shadow-red-200",children:e.jsx(Ne,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{id:"delete-account-title",className:"text-lg font-extrabold tracking-tight text-gray-950",children:"删除这个账号?"}),e.jsx("p",{id:"delete-account-description",className:"mt-1 text-xs leading-5 text-gray-600",children:"删除后,该账号的关联配置也会一并清理,此操作无法撤销。"})]}),e.jsx("button",{type:"button",onClick:a,disabled:t,className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-white hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"关闭删除确认",children:e.jsx(de,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"rounded-xl border border-gray-100 bg-gray-50/80 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:s.nickname||s.remark||"未命名账号"}),s.remark&&s.nickname&&e.jsxs("div",{className:"mt-1 text-sm text-gray-500",children:["备注:",s.remark]}),e.jsxs("div",{className:"mt-1.5 break-all font-mono text-[11px] text-gray-400",children:["ID: ",s.id]})]}),t&&e.jsxs("div",{className:"mt-4 flex items-center gap-3 rounded-xl border border-blue-100 bg-blue-50 px-4 py-3",role:"progressbar","aria-label":"正在删除账号",children:[e.jsx(J,{className:"h-5 w-5 flex-shrink-0 animate-spin text-brand"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-blue-950",children:"正在删除账号"}),e.jsx("div",{className:"mt-0.5 text-xs text-blue-700",children:"正在清理关联数据,请保持页面打开…"})]})]}),r&&e.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3",role:"alert",children:[e.jsx(_e,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-red-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-red-800",children:"删除失败"}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-red-700",children:r})]})]})]}),e.jsxs("div",{className:"flex gap-3 border-t border-gray-100 bg-gray-50/70 px-5 py-4",children:[e.jsx("button",{type:"button",onClick:a,disabled:t,className:"flex-1 rounded-xl bg-white px-5 py-3 text-sm font-extrabold text-gray-700 ring-1 ring-gray-200 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",children:"取消"}),e.jsx("button",{type:"button",onClick:(()=>void l()),disabled:t,className:"flex flex-1 items-center justify-center gap-2 rounded-xl bg-red-600 px-5 py-3 text-sm font-extrabold text-white shadow-lg shadow-red-200 transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:bg-red-400",children:t?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"h-4 w-4 animate-spin"}),"处理中"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"h-4 w-4"}),"确认删除"]})})]})]})}),document.body),Is=({faceQrUrl:s,verificationScreenshot:t})=>e.jsxs("div",{className:"w-full min-w-0 max-h-[min(64vh,28rem)] overflow-y-auto overscroll-contain px-1 py-2 text-center",children:[e.jsx("div",{className:"mx-auto mb-2 flex h-10 w-10 items-center justify-center rounded-full bg-amber-100 text-amber-700",children:e.jsx(es,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("h4",{className:"break-words text-base font-extrabold leading-6 text-amber-900",children:"需要完成安全风控验证"}),e.jsx("p",{className:"mx-auto mt-1 max-w-[15rem] break-words text-xs leading-5 text-amber-800",children:"当前账号触发了闲鱼平台风控。请使用手机闲鱼 App 扫描下方二维码,并按 App 提示完成人脸识别。"}),e.jsx("div",{className:"mx-auto mt-3 flex min-h-36 w-full max-w-[12rem] items-center justify-center overflow-hidden rounded-xl border border-amber-200 bg-white p-2 shadow-sm",children:s?e.jsx("img",{src:s,alt:"闲鱼安全风控验证二维码",className:"block max-h-44 w-full object-contain"}):t?e.jsx("img",{src:t,alt:"闲鱼风控验证页面",className:"block max-h-44 w-full object-contain"}):e.jsxs("div",{className:"flex flex-col items-center gap-2 text-amber-700",children:[e.jsx(J,{className:"h-6 w-6 animate-spin","aria-hidden":"true"}),e.jsx("span",{className:"text-xs font-bold",children:"正在准备风控二维码…"})]})}),e.jsx("p",{className:"mx-auto mt-2 max-w-[15rem] break-words text-[11px] leading-4 text-gray-500",children:"请勿在浏览器中打开验证链接。完成验证后系统会自动检测并刷新登录状态,无需手动确认。"})]}),Ts=({target:s,status:t,codeUrl:r,errorMessage:a,faceQrUrl:l,verificationScreenshot:c,onClose:i})=>ie.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container relative",style:{maxWidth:"26rem"},children:[e.jsx("button",{onClick:i,className:"absolute top-4 right-4 z-10 w-9 h-9 flex items-center justify-center bg-gray-100 hover:bg-gray-200 rounded-full transition-colors","aria-label":"关闭二维码登录",children:e.jsx(de,{className:"w-5 h-5 text-gray-600"})}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900 mb-2",children:s?"重新授权账号":"扫码添加账号"}),e.jsx("p",{className:"text-gray-500 mb-8 font-medium",children:s?`请用闲鱼APP扫码,为「${s.nickname||s.remark||s.id}」刷新授权`:"请打开闲鱼APP扫描下方二维码"}),e.jsxs("div",{className:`w-full bg-surface-subtle rounded-xl mx-auto flex items-center justify-center overflow-hidden border-4 border-white shadow-inner mb-6 relative ${t==="verification"?"max-w-72 min-h-64 h-auto p-2":"max-w-64 aspect-square"}`,children:[t==="loading"&&e.jsx(J,{className:"w-10 h-10 text-brand animate-spin"}),t==="waiting"&&e.jsx(Qe,{src:r,alt:"闲鱼登录二维码",className:"p-2"}),t==="success"&&e.jsxs("div",{className:"absolute inset-0 bg-white/95 flex flex-col items-center justify-center text-green-600 animate-fade-in",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mb-4",children:e.jsx(te,{className:"w-8 h-8"})}),e.jsx("span",{className:"font-bold text-lg",children:"登录成功"})]}),t==="error"&&e.jsxs("div",{className:"px-5 text-center",children:[e.jsx("span",{className:"block text-red-600 font-bold",children:"二维码获取失败"}),e.jsx("span",{className:"mt-2 block text-xs leading-5 text-gray-500",children:a||"请关闭窗口后重新发起扫码登录。"})]}),t==="verification"&&e.jsx(Is,{faceQrUrl:l,verificationScreenshot:c})]}),t!=="verification"&&e.jsx("p",{className:"text-xs text-gray-400 font-medium bg-gray-50 py-2 rounded-xl",children:"二维码有效期为5分钟,请尽快扫码。"})]})})]})}),document.body),$s=(s,t)=>s.map(r=>{var a,l,c,i,d;return{...r,ai_enabled:((a=t[r.id])==null?void 0:a.ai_enabled)??!1,max_discount_percent:((l=t[r.id])==null?void 0:l.max_discount_percent)??10,max_discount_amount:((c=t[r.id])==null?void 0:c.max_discount_amount)??100,max_bargain_rounds:((i=t[r.id])==null?void 0:i.max_bargain_rounds)??3,custom_prompts:((d=t[r.id])==null?void 0:d.custom_prompts)??""}}),Ds=()=>{const[s,t]=n.useState([]),[r,a]=n.useState(!0),l=n.useRef(0),c=n.useRef(null),i=n.useCallback(async()=>{var m;const d=++l.current;(m=c.current)==null||m.abort();const b=new AbortController;c.current=b,a(!0);try{const f={signal:b.signal},[h,u]=await Promise.allSettled([ts(f),ps(f)]);if(d!==l.current)return;if(h.status==="rejected")throw h.reason;const A=u.status==="fulfilled"?u.value:{};u.status==="rejected"&&console.error("加载 AI 设置失败:",u.reason),t($s(h.value,A))}catch(f){d===l.current&&!b.signal.aborted&&console.error("加载账号失败:",f)}finally{d===l.current&&a(!1)}},[]);return n.useEffect(()=>{let d=!1,b=null;const m=new AbortController,f=async()=>{try{const u=await as({signal:m.signal,timeoutMs:1e4});d||t(A=>As(A,u))}catch(u){d||console.error("加载账号运行状态失败:",u)}finally{d||(b=window.setTimeout(()=>void f(),2e3))}};return i().finally(()=>{d||f()}),()=>{var u;d=!0,m.abort(),l.current+=1,(u=c.current)==null||u.abort(),b!==null&&window.clearTimeout(b)}},[i]),{accounts:s,setAccounts:t,loading:r,loadAccounts:i}},Es=new Set(["expired","cancelled","error","not_found"]),Qs=()=>{let s=0;return{next:()=>(s+=1,s),cancel:()=>{s+=1},isCurrent:(t=>t===s)}},Us=(s={setInterval:globalThis.setInterval.bind(globalThis),clearInterval:globalThis.clearInterval.bind(globalThis)})=>{let t=null,r=null,a=-1,l=0;const c=()=>{l+=1,r==null||r.abort(),r=null,t!==null&&(s.clearInterval(t),t=null)};return{start:(d,b,m,f=2e3)=>{c();const h=l;r=new AbortController;const u=r.signal;t=s.setInterval(()=>{a===h||h!==l||(a=h,(async()=>{var A,k;try{const g=await b(d,u);if(g.status==="success"){c(),await m.onSuccess(g);return}if(g.status==="scanned"){(A=m.onScanned)==null||A.call(m,g);return}if(g.status==="verification_required"){(k=m.onVerificationRequired)==null||k.call(m,g);return}g.status&&Es.has(g.status)&&(c(),m.onTerminalError(g))}catch(g){if(u.aborted||h!==l)return;c(),m.onPollError(g)}finally{a===h&&(a=-1)}})())},f)},stop:c,isActive:(()=>t!==null)}},Ms=({onLoginSuccess:s})=>{const[t,r]=n.useState(!1),[a,l]=n.useState(""),[c,i]=n.useState("pending"),[d,b]=n.useState(""),[m,f]=n.useState(""),[h,u]=n.useState(""),[A,k]=n.useState(null),g=n.useRef(null),p=n.useRef(null),L=n.useRef(null),U=n.useRef(null);g.current===null&&(g.current=Us()),p.current===null&&(p.current=Qs());const M=()=>{U.current!==null&&(window.clearTimeout(U.current),U.current=null)},T=()=>{var w;(w=g.current)==null||w.stop()},S=()=>{var w,q;(w=L.current)==null||w.abort(),(q=p.current)==null||q.cancel(),T(),M(),r(!1)},j=()=>{M(),U.current=window.setTimeout(()=>{U.current=null,r(!1),s()},1e3)};n.useEffect(()=>()=>{var q,D;T(),(q=p.current)==null||q.cancel(),(D=L.current)==null||D.abort(),M()},[]);const v=async(w,q)=>{const D=await ls(w,q==null?void 0:q.id);if(!D.success||!D.account_id)throw new Error(D.message||"保存扫码授权失败");return D.account_id};return{showQRModal:t,qrCodeUrl:a,qrStatus:c,qrErrorMessage:d,verificationScreenshot:m,faceQrUrl:h,qrReauthTarget:A,startQRLogin:async w=>{var K,G,V,O;T(),(K=L.current)==null||K.abort();const q=new AbortController;L.current=q;const D=p.current.next();M();const H=w||null;k(H),r(!0),i("loading"),b(""),l(""),f(""),u("");try{const I=await rs({signal:q.signal});if(!((G=p.current)!=null&&G.isCurrent(D)))return;if(!I.success||!I.qr_code_url||!I.session_id)throw new Error(I.message||"闲鱼未返回可用的登录二维码");const z=I.session_id;l(I.qr_code_url),i("waiting"),(V=g.current)==null||V.start(z,ns,{onSuccess:(async()=>{try{await v(z,H)}catch(E){console.error("保存扫码授权失败",E),i("error");return}i("success"),j()}),onScanned:(()=>{i("waiting")}),onTerminalError:(()=>{i("error")}),onPollError:(E=>{console.error("轮询扫码状态失败",E),i("error")}),onVerificationRequired:(E=>{i("verification"),E.face_qr_url&&u(E.face_qr_url),E.verification_screenshot&&f(E.verification_screenshot)})})}catch(I){if(!((O=p.current)!=null&&O.isCurrent(D))||q.signal.aborted)return;b(I instanceof Error?I.message:"二维码获取失败,请稍后重试"),i("error")}finally{L.current===q&&(L.current=null)}},closeQRModal:S}},Bs=(s,t)=>s!==(t.pause_duration||0),Os=(s,t)=>{const r=t.username!==(s.username||""),a=t.show_browser!==(s.show_browser||!1),l=t.login_password!=="",c=t.clear_password===!0;if(!r&&!a&&!l&&!c)return null;const i={username:t.username,show_browser:t.show_browser};return c?i.clear_password=!0:l&&(i.login_password=t.login_password),i},Z=(s,t,r,a)=>s===t&&r===a,zs=s=>s.status==="success"?{sessionId:"",status:"success",message:s.message||"账号密码登录成功,授权信息已更新",qrCodeUrl:""}:s.status==="processing"||s.status==="verification_required"?{sessionId:"",status:s.status,message:s.message||(s.status==="verification_required"?"账号触发风控,需要完成人脸识别":"登录处理中"),qrCodeUrl:s.qr_code_url||""}:{sessionId:"",status:"failed",message:s.error||s.message||"密码登录失败,请检查账号信息后重试",qrCodeUrl:""},Gs=(s,t)=>s&&t,Ws=({editingAccount:s,setEditingAccount:t,setActiveModal:r,editForm:a,setEditForm:l,loadAccounts:c})=>{const[i,d]=n.useState({loading:!1,saving:!1,canOpen:!1,enabled:!1,error:""}),[b,m]=n.useState([]),[f,h]=n.useState([]),[u,A]=n.useState(!1),[k,g]=n.useState(!1),[p,L]=n.useState(!1),[U,M]=n.useState(""),[T,S]=n.useState({ai_enabled:!1,max_discount_percent:10,max_discount_amount:100,max_bargain_rounds:3,custom_prompts:""}),[j,v]=n.useState(!1),[R,w]=n.useState({sessionId:"",status:"idle",message:"",qrCodeUrl:""}),q=n.useRef(0),D=n.useRef(null),H=n.useRef(0),K=n.useRef(null),G=n.useRef(0),V=n.useRef(null),O=n.useRef(0),I=n.useRef(""),z=n.useRef(null),E=n.useRef(null),Q=n.useCallback(()=>{E.current!==null&&(window.clearTimeout(E.current),E.current=null)},[]),F=n.useCallback(async o=>{var B;const x=++q.current;(B=D.current)==null||B.abort();const N=new AbortController;D.current=N,g(!0),A(!1),L(!1),M("");const[$,_]=await Promise.allSettled([ws({signal:N.signal}),_s(o,{signal:N.signal})]);Z(x,q.current,o,o)&&($.status==="fulfilled"?m($.value.data||[]):(m([]),M("通知渠道列表加载失败,请重试")),_.status==="fulfilled"?(h(_.value||[]),A(!0)):(h([]),M("通知绑定加载失败;本次保存不会修改现有绑定")),g(!1))},[]),re=n.useCallback(o=>{h(x=>x.includes(o)?x.filter(N=>N!==o):[...x,o]),L(!0)},[]),C=n.useCallback(async o=>{var _,B;const x=++H.current;(_=K.current)==null||_.abort();const N=new AbortController;K.current=N,O.current+=1,I.current=o.id,(B=z.current)==null||B.abort(),Q(),w({sessionId:"",status:"idle",message:"",qrCodeUrl:""}),t(o),l({remark:o.remark||"",cookie:"",auto_confirm:o.auto_confirm||!1,pause_duration:o.pause_duration||0,username:o.username||"",login_password:"",show_browser:o.show_browser||!1,showLoginPassword:!1,clear_password:!1}),r("edit"),d({loading:!0,saving:!1,canOpen:!1,enabled:!1,error:""});const[,$]=await Promise.allSettled([F(o.id),us(o.id,{signal:N.signal})]);x===H.current&&($.status==="fulfilled"?d({loading:!1,saving:!1,canOpen:$.value.can_open_long_login,enabled:$.value.enabled,error:""}):d({loading:!1,saving:!1,canOpen:!1,enabled:!1,error:"无法读取闲鱼保存登录信息状态"}))},[Q,F,r,l,t]),W=n.useCallback(async()=>{if(!s||i.loading||i.saving||!i.canOpen)return;const o=!i.enabled;d(x=>({...x,saving:!0,error:""}));try{const x=await xs(s.id,o);d({loading:!1,saving:!1,canOpen:x.can_open_long_login,enabled:x.enabled,error:""})}catch(x){d(N=>({...N,saving:!1,error:x instanceof Error?x.message:"保存登录信息设置失败"}))}},[s,i]),ee=n.useCallback(async o=>{var $;const x=++G.current;($=V.current)==null||$.abort();const N=new AbortController;V.current=N,t(o),r("ai-settings"),v(!0);try{const _=await fs(o.id,{signal:N.signal});if(!Z(x,G.current,o.id,o.id))return;S({ai_enabled:_.ai_enabled??!1,max_discount_percent:_.max_discount_percent??10,max_discount_amount:_.max_discount_amount??100,max_bargain_rounds:_.max_bargain_rounds??3,custom_prompts:_.custom_prompts??""})}catch(_){Z(x,G.current,o.id,o.id)&&console.error("加载 AI 设置失败:",_)}finally{Z(x,G.current,o.id,o.id)&&v(!1)}},[r,t]),xe=n.useCallback(async()=>{if(!(!s||j)){v(!0);try{await ys(s.id,T),r(null),await c()}catch(o){console.error("更新 AI 设置失败:",o)}finally{v(!1)}}},[T,s,c,j,r]),me=n.useCallback(async()=>{if(!(!s||j)){v(!0);try{const o={};a.remark!==(s.remark||"")&&(o.remark=a.remark),a.cookie&&(o.cookie=a.cookie),a.auto_confirm!==s.auto_confirm&&(o.auto_confirm=a.auto_confirm),Bs(a.pause_duration,s)&&(o.pause_duration=a.pause_duration);const x=Os(s,a);x&&Object.assign(o,x),Gs(u,p)&&(o.channel_ids=f),Object.keys(o).length>0&&await ds(s.id,o),r(null),await c()}catch(o){console.error("更新账号失败:",o)}finally{v(!1)}}},[p,u,a,s,c,f,j,r]),be=n.useCallback(async()=>{if(!(!s||a.pause_duration<=0||j)){v(!0);try{const o=await cs(s.id,a.pause_duration);t(x=>x&&{...x,pause_duration:a.pause_duration,paused:(o==null?void 0:o.paused)===!0,paused_until:Number((o==null?void 0:o.paused_until)||0)}),await c()}catch(o){console.error("重新暂停失败:",o)}finally{v(!1)}}},[a.pause_duration,s,c,j,t]),ne=n.useCallback(async(o,x,N)=>{var _;(_=z.current)==null||_.abort();const $=new AbortController;z.current=$;try{const B=await bs(o,$.signal);if(!Z(x,O.current,N,I.current))return;const oe={...zs(B),sessionId:o};if(B.status==="success"){Q(),w(oe),l(fe=>({...fe,login_password:"",showLoginPassword:!1})),await c();return}if(B.status==="processing"||B.status==="verification_required"){w(oe),Q(),E.current=window.setTimeout(()=>void ne(o,x,N),1500);return}Q(),w(oe)}catch(B){if(!Z(x,O.current,N,I.current))return;Q(),w({sessionId:o,status:"failed",message:B instanceof Error?B.message:"查询密码登录状态失败",qrCodeUrl:""})}},[Q,c,l]),he=n.useCallback(async()=>{var $;if(!s)return;const o=a.username.trim();if(!o||!a.login_password)return;Q(),($=z.current)==null||$.abort();const x=++O.current;I.current=s.id;const N=new AbortController;z.current=N,w({sessionId:"",status:"processing",message:"正在启动密码登录…",qrCodeUrl:""});try{const _=await ms({account_id:s.id,account:o,password:a.login_password,show_browser:a.show_browser},{signal:N.signal});if(!Z(x,O.current,s.id,I.current))return;if(!_.success||!_.session_id)throw new Error(_.message||"无法启动密码登录");w({sessionId:_.session_id,status:"processing",message:_.message||"登录处理中",qrCodeUrl:""}),await ne(_.session_id,x,s.id)}catch(_){if(!Z(x,O.current,s.id,I.current))return;w({sessionId:"",status:"failed",message:_ instanceof Error?_.message:"启动密码登录失败",qrCodeUrl:""})}},[Q,a.login_password,a.show_browser,a.username,s,ne]),le=n.useCallback(async()=>{var x;const o=R.sessionId;O.current+=1,I.current="",(x=z.current)==null||x.abort(),Q(),o&&await hs(o).catch(()=>{}),w({sessionId:"",status:"idle",message:"",qrCodeUrl:""})},[Q,R.sessionId]),ge=n.useCallback(async()=>{var o,x,N;(o=D.current)==null||o.abort(),H.current+=1,(x=K.current)==null||x.abort(),(N=V.current)==null||N.abort(),(R.status==="processing"||R.status==="verification_required")&&await le(),r(null)},[le,R.status,r]),pe=n.useCallback(()=>{var o;G.current+=1,(o=V.current)==null||o.abort(),r(null)},[r]);return n.useEffect(()=>(()=>{var o,x,N,$;(o=D.current)==null||o.abort(),(x=K.current)==null||x.abort(),(N=V.current)==null||N.abort(),($=z.current)==null||$.abort(),Q()}),[Q]),{longLogin:i,notifChannels:b,selectedChannelIds:f,bindingsLoaded:u,bindingsLoading:k,bindingsDirty:p,bindingsLoadError:U,aiSettings:T,saving:j,passwordLoginView:R,setAiSettings:S,setBindingsDirty:L,setEditForm:l,openEditModal:C,closeEditModal:ge,openAIModal:ee,closeAIModal:pe,loadNotificationBindings:F,toggleNotificationChannel:re,handleLongLoginToggle:W,handleSaveAISettings:xe,handleSaveEdit:me,handleRestartPause:be,handlePasswordLogin:he,handleCancelPasswordLogin:le}},Xs=()=>{const{accounts:s,setAccounts:t,loading:r,loadAccounts:a}=Ds(),[l,c]=n.useState(""),[i,d]=n.useState(""),[b,m]=n.useState(""),[f,h]=n.useState(null),[u,A]=n.useState(""),[k,g]=n.useState(null),[p,L]=n.useState(null),[U,M]=n.useState(null),[T,S]=n.useState({remark:"",cookie:"",auto_confirm:!1,pause_duration:0,username:"",login_password:"",show_browser:!1,showLoginPassword:!1,clear_password:!1}),j=Ws({editingAccount:p,setEditingAccount:L,setActiveModal:g,editForm:T,setEditForm:S,loadAccounts:a}),{longLogin:v,notifChannels:R,selectedChannelIds:w,bindingsLoaded:q,bindingsLoading:D,bindingsLoadError:H,aiSettings:K,saving:G,passwordLoginView:V,setAiSettings:O,setBindingsDirty:I,openEditModal:z,closeEditModal:E,openAIModal:Q,closeAIModal:F,loadNotificationBindings:re,toggleNotificationChannel:C,handleLongLoginToggle:W,handleSaveAISettings:ee,handleSaveEdit:xe,handleRestartPause:me,handlePasswordLogin:be,handleCancelPasswordLogin:ne}=j,he=Ms({onLoginSuccess:a}),{showQRModal:le,qrCodeUrl:ge,qrStatus:pe,qrErrorMessage:o,verificationScreenshot:x,faceQrUrl:N,qrReauthTarget:$,startQRLogin:_,closeQRModal:B}=he,oe=async(y,P)=>{await os(y,!P),a()},fe=y=>{b||(A(""),h(y))},Ue=()=>{b||(A(""),h(null))},Me=async()=>{const y=f;if(!(!y||b)){m(y.id),A("");try{await is(y.id),t(P=>P.filter(se=>se.id!==y.id)),h(null)}catch(P){console.error("删除账号失败:",P),A((P==null?void 0:P.message)||"删除账号失败,请稍后重试")}finally{m("")}}},Be=async y=>{d(y.id);try{const P=await gs(y.id);P!=null&&P.profile_error&&alert("资料刷新失败:"+P.profile_error),await a()}catch(P){console.error("刷新账号资料失败:",P),alert((P==null?void 0:P.message)||"刷新账号资料失败,请先重新授权该账号")}finally{d("")}};if(r)return e.jsx("div",{className:"p-20 flex justify-center",children:e.jsx(J,{className:"w-8 h-8 text-brand animate-spin"})});const ye=s.filter(y=>{const P=l.trim().toLowerCase();return P?[y.id,y.nickname,y.remark,y.username,y.runtime_message].some(se=>(se||"").toLowerCase().includes(P)):!0});return e.jsxs("div",{className:"space-y-8 animate-fade-in relative",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"账号管理"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理您的闲鱼授权账号及设置。建议给账号填写备注,便于多账号区分。"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsx("input",{value:l,onChange:(y=>c(y.target.value)),placeholder:"搜索昵称 / 备注 / 账号ID",className:"ios-input px-4 py-3 rounded-2xl text-sm w-full sm:w-72"}),e.jsxs("button",{onClick:(()=>_()),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(ve,{className:"w-5 h-5"}),"扫码添加新账号"]})]})]}),e.jsxs("div",{className:"rounded-2xl border border-blue-100 bg-blue-50 px-5 py-4 text-sm text-blue-900 flex flex-col md:flex-row md:items-center md:justify-between gap-2",children:[e.jsxs("div",{className:"font-bold",children:["当前显示 ",ye.length," / ",s.length," 个账号"]}),e.jsx("div",{className:"text-blue-700",children:"如果某个账号只显示 ID,点该账号右侧“刷新资料”;若刷新失败,先点二维码重新授权。"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6",children:[ye.map(y=>e.jsx(Ps,{account:y,refreshing:i===y.id,deleting:b===y.id,onRefreshProfile:Be,onReauthorize:_,onEdit:z,onAI:Q,onTasks:M,onToggle:oe,onDelete:fe},y.id)),s.length===0&&e.jsxs("div",{className:"ios-card p-12 text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(Ee,{className:"w-10 h-10 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:"暂无账号"}),e.jsx("p",{className:"text-gray-500 mt-1",children:"请点击右上角扫码添加您的闲鱼账号"})]}),s.length>0&&ye.length===0&&e.jsxs("div",{className:"ios-card p-12 text-center",children:[e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:"没有匹配的账号"}),e.jsx("p",{className:"text-gray-500 mt-1",children:"换一个关键词搜索昵称、备注或账号ID。"})]})]}),U&&ie.createPortal(e.jsx(ks,{account:U,onClose:(()=>M(null)),onSaved:(y=>{t(P=>P.map(se=>se.id===U.id?{...se,auto_rate_enabled:y.auto_rate_enabled,rate_content:y.rate_content,auto_polish_enabled:y.auto_polish_enabled,polish_time:y.polish_time,last_rate_scan_at:y.last_rate_scan_at,last_polish_date:y.last_polish_date,last_polish_at:y.last_polish_at}:se))})}),document.body),f&&e.jsx(Ls,{account:f,deleting:b===f.id,error:u,onClose:Ue,onConfirm:Me}),le&&e.jsx(Ts,{target:$,status:pe,codeUrl:ge,errorMessage:o,faceQrUrl:N,verificationScreenshot:x,onClose:B}),k==="edit"&&p&&e.jsx(Cs,{account:p,editForm:T,setEditForm:S,saving:G,onClose:E,onSave:xe,onRestartPause:me,longLogin:v,onToggleLongLogin:W,passwordLoginView:V,onPasswordLogin:be,onCancelPasswordLogin:ne,notifChannels:R,selectedChannelIds:w,bindingsLoaded:q,bindingsLoading:D,bindingsLoadError:H,onRetryBindings:(()=>re(p.id)),onToggleChannel:C,onSettingsDirty:(()=>I(!0))}),k==="ai-settings"&&p&&e.jsx(Ss,{account:p,settings:K,saving:G,onChange:O,onClose:F,onSave:ee})]})};export{Xs as default};
diff --git a/internal/webui/static/assets/CardList-D43xNKm6.js b/internal/webui/static/assets/CardList-e8gkiR9S.js
similarity index 99%
rename from internal/webui/static/assets/CardList-D43xNKm6.js
rename to internal/webui/static/assets/CardList-e8gkiR9S.js
index a6a2c1c..a6b07eb 100644
--- a/internal/webui/static/assets/CardList-D43xNKm6.js
+++ b/internal/webui/static/assets/CardList-e8gkiR9S.js
@@ -1,4 +1,4 @@
-import{b as z,j as e,r as i}from"./react-vendor-C_od1ZSF.js";import{X as G,W as Z,J as D,Y as ee,L as U,N as V,C as H,_ as te,$ as W,a0 as X,a1 as ae,I as se,a2 as le,V as ne,F as re,P as oe,r as ie}from"./icons-vendor-CvzvbbIV.js";import{g as ce,p as de,d as xe,a as Y,b as pe}from"./index-hByDAHGj.js";import{c as me}from"./contract-COFcZjyb.js";const he=({dataCards:l,downloadCardTemplate:n,...a})=>{var x;const u=s=>{var h;a.setBatchFile(((h=s.target.files)==null?void 0:h[0])||null)},m=s=>{a.setAppendContent(s.target.value)},_=s=>{a.setAppendTargetId(s.target.value)},f=()=>a.closeBatchModal(),j=()=>a.setBatchTab("create"),d=()=>a.setBatchTab("append"),A=()=>void a.handleRetryBatchCreate(),c=()=>void a.handleRetryBatchAppend(),y=a.batchResult&&"rows"in a.batchResult?a.batchResult:null,N=s=>e.jsxs("option",{value:String(s.id),children:[s.name,"(ID: ",s.id,")"]},s.id),b=()=>void a.handleBatchCreate(),r=()=>void a.handleBatchAppend();return a.showBatchModal?z.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:f,className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(G,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:j,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${a.batchTab==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Z,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:d,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${a.batchTab==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(D,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),a.batchTab==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),"。 类型填 text/data/image;data 类型的“内容”按行存卡密(CSV 单元格内换行需用引号包裹)。"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:n,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transition-colors",children:[e.jsx(ee,{className:"w-4 h-4"}),"下载模板"]}),e.jsxs("label",{className:"flex-1 px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm cursor-pointer transition-colors",children:[e.jsx(D,{className:"w-4 h-4"}),a.batchFile?a.batchFile.name:"选择 .xlsx / .csv / .tsv",e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv",className:"hidden",onChange:u})]})]}),((x=a.batchResult)==null?void 0:x.error)&&e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 p-4 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:a.batchResult.error}),e.jsx("button",{type:"button",onClick:A,disabled:!a.batchFile||a.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),y&&e.jsxs("div",{className:"rounded-xl border border-gray-200 p-4 space-y-2",children:[e.jsxs("div",{className:"text-sm font-bold text-gray-900",children:["共 ",y.total," 行 · 成功 ",y.created," · 失败 ",y.failed]}),y.failed>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:y.rows.filter(s=>!s.success).map(s=>e.jsxs("div",{className:"text-xs text-red-600",children:["第 ",s.row_no," 行「",s.name,"」:",s.error]},s.row_no))})]})]}):e.jsx("div",{className:"space-y-4",children:l.length===0?e.jsx("div",{className:"rounded-xl bg-amber-50 border border-amber-200 p-4 text-sm text-amber-800",children:"暂无 data(批量卡密)类型的卡密组,请先创建一个再充卡密。"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"选择卡密组"}),e.jsx("select",{value:a.appendTargetId,onChange:_,className:"w-full ios-input px-4 py-3 rounded-xl text-sm",children:l.map(N)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"卡密号(每行一个)"}),e.jsx("textarea",{value:a.appendContent,onChange:m,placeholder:`VIP-001
+import{b as z,j as e,r as i}from"./react-vendor-C_od1ZSF.js";import{X as G,W as Z,J as D,Y as ee,L as U,N as V,C as H,_ as te,$ as W,a0 as X,a1 as ae,I as se,a2 as le,V as ne,F as re,P as oe,r as ie}from"./icons-vendor-CvzvbbIV.js";import{g as ce,p as de,d as xe,a as Y,b as pe}from"./index-CNzF_I4S.js";import{c as me}from"./contract-COFcZjyb.js";const he=({dataCards:l,downloadCardTemplate:n,...a})=>{var x;const u=s=>{var h;a.setBatchFile(((h=s.target.files)==null?void 0:h[0])||null)},m=s=>{a.setAppendContent(s.target.value)},_=s=>{a.setAppendTargetId(s.target.value)},f=()=>a.closeBatchModal(),j=()=>a.setBatchTab("create"),d=()=>a.setBatchTab("append"),A=()=>void a.handleRetryBatchCreate(),c=()=>void a.handleRetryBatchAppend(),y=a.batchResult&&"rows"in a.batchResult?a.batchResult:null,N=s=>e.jsxs("option",{value:String(s.id),children:[s.name,"(ID: ",s.id,")"]},s.id),b=()=>void a.handleBatchCreate(),r=()=>void a.handleBatchAppend();return a.showBatchModal?z.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:f,className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(G,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:j,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${a.batchTab==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Z,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:d,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${a.batchTab==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(D,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),a.batchTab==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),"。 类型填 text/data/image;data 类型的“内容”按行存卡密(CSV 单元格内换行需用引号包裹)。"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:n,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transition-colors",children:[e.jsx(ee,{className:"w-4 h-4"}),"下载模板"]}),e.jsxs("label",{className:"flex-1 px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm cursor-pointer transition-colors",children:[e.jsx(D,{className:"w-4 h-4"}),a.batchFile?a.batchFile.name:"选择 .xlsx / .csv / .tsv",e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv",className:"hidden",onChange:u})]})]}),((x=a.batchResult)==null?void 0:x.error)&&e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 p-4 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:a.batchResult.error}),e.jsx("button",{type:"button",onClick:A,disabled:!a.batchFile||a.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),y&&e.jsxs("div",{className:"rounded-xl border border-gray-200 p-4 space-y-2",children:[e.jsxs("div",{className:"text-sm font-bold text-gray-900",children:["共 ",y.total," 行 · 成功 ",y.created," · 失败 ",y.failed]}),y.failed>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:y.rows.filter(s=>!s.success).map(s=>e.jsxs("div",{className:"text-xs text-red-600",children:["第 ",s.row_no," 行「",s.name,"」:",s.error]},s.row_no))})]})]}):e.jsx("div",{className:"space-y-4",children:l.length===0?e.jsx("div",{className:"rounded-xl bg-amber-50 border border-amber-200 p-4 text-sm text-amber-800",children:"暂无 data(批量卡密)类型的卡密组,请先创建一个再充卡密。"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"选择卡密组"}),e.jsx("select",{value:a.appendTargetId,onChange:_,className:"w-full ios-input px-4 py-3 rounded-xl text-sm",children:l.map(N)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"卡密号(每行一个)"}),e.jsx("textarea",{value:a.appendContent,onChange:m,placeholder:`VIP-001
VIP-002
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["预览:",a.appendPreview.length," 个有效卡密,空行自动忽略。"]})]}),a.appendError&&e.jsxs("div",{className:"rounded-xl bg-red-50 border border-red-200 p-3 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:a.appendError}),e.jsx("button",{type:"button",onClick:c,disabled:a.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),a.appendResult&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",a.appendResult.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:f,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),a.batchTab==="create"?e.jsxs("button",{onClick:b,disabled:!a.batchFile||a.batchBusy,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(U,{className:"w-4 h-4 animate-spin"}):e.jsx(D,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:r,disabled:!a.appendTargetId||a.appendPreview.length===0||a.batchBusy||l.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(U,{className:"w-4 h-4 animate-spin"}):e.jsx(V,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},ue=({type:l})=>{switch(l){case"text":return e.jsx(X,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(W,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(te,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(H,{className:"w-5 h-5 text-gray-500"})}},be=l=>{let n=l.api_config;if(typeof n=="string"&&n.trim())try{n=JSON.parse(n)}catch{n=void 0}return{...l,api_config:n||void 0}},K=l=>({...l,api_config:l.api_config?JSON.stringify(l.api_config):""}),ge=async l=>{const n=await ce("/api/v1/cards",void 0,l);return me(n,["cards","data","items"]).map(be)},ye=async l=>Y("/api/v1/cards",K(l)),J=async(l,n)=>de(`/api/v1/cards/${l}`,K(n)),fe=async l=>xe(`/api/v1/cards/${l}`),je=async(l,n)=>{const a=new FormData;return a.append("file",l),pe("/api/v1/cards/batch",a,n)},Ne=async(l,n,a)=>Y(`/api/v1/cards/${l}/append-data`,{content:n},a),ve=(l,n,a)=>{const u=a.trim().toLocaleLowerCase();return l.filter(m=>(!n||m.type===n)&&(!u||m.name.toLocaleLowerCase().includes(u)))},Q=l=>l.split(`
`).map(n=>n.trim()).filter(Boolean),we=(l,n,a)=>!!(l&&Q(n).length>0&&!a),F=(l,n,a,u)=>l===n&&a===u,Ce=()=>{const[l,n]=i.useState([]),[a,u]=i.useState(!0),m=i.useRef(0),_=i.useRef(null),f=i.useCallback(async()=>{var A;const j=++m.current;(A=_.current)==null||A.abort();const d=new AbortController;_.current=d,u(!0);try{const c=await ge({signal:d.signal});if(j!==m.current)return;n(c)}catch(c){j===m.current&&!d.signal.aborted&&console.error("加载卡密库存失败:",c)}finally{j===m.current&&u(!1)}},[]);return i.useEffect(()=>(f(),()=>{var d;m.current+=1,(d=_.current)==null||d.abort()}),[f]),{cards:l,setCards:n,loading:a,loadCards:f}},_e=l=>{const n=l.dataCards,a=l.loadCards,[u,m]=i.useState(!1),[_,f]=i.useState("create"),[j,d]=i.useState(null),[A,c]=i.useState(null),[y,N]=i.useState(!1),[b,r]=i.useState(""),[x,s]=i.useState(""),[h,E]=i.useState(null),[M,R]=i.useState(""),v=i.useRef(0),T=i.useRef(null),P=i.useRef("");i.useEffect(()=>(()=>{var p;v.current+=1,(p=T.current)==null||p.abort()}),[]);const $=i.useMemo(()=>Q(x),[x]),o=i.useCallback(()=>{var p;f("create"),d(null),c(null),r((p=n[0])!=null&&p.id?String(n[0].id):""),s(""),E(null),R(""),m(!0)},[n]),t=i.useCallback(()=>{var p;v.current+=1,(p=T.current)==null||p.abort(),N(!1),m(!1)},[]),g=i.useCallback(async()=>{var w;if(!j||y)return;const p=++v.current;(w=T.current)==null||w.abort();const B=new AbortController;T.current=B,N(!0),c(null);try{const I=await je(j,{signal:B.signal});if(!F(p,v.current,"",""))return;c(I),I.created>0&&await a()}catch(I){if(!F(p,v.current,"",""))return;c({error:(I==null?void 0:I.message)||"上传失败"})}finally{F(p,v.current,"","")&&N(!1)}},[y,j,a]),k=i.useCallback(async()=>{var I;if(!we(b,x,y))return;const p=b,B=++v.current;P.current=p,(I=T.current)==null||I.abort();const w=new AbortController;T.current=w,N(!0),E(null),R("");try{const O=await Ne(p,x,{signal:w.signal});if(!F(B,v.current,p,b))return;E({added:O.added}),s(""),await a()}catch(O){if(!F(B,v.current,p,b))return;R((O==null?void 0:O.message)||"追加失败")}finally{F(B,v.current,p,b)&&N(!1)}},[x,b,y,a]),S=i.useCallback(async()=>{await g()},[g]),C=i.useCallback(async()=>{P.current&&b!==P.current||await k()},[b,k]);return{showBatchModal:u,setShowBatchModal:m,batchTab:_,setBatchTab:f,batchFile:j,setBatchFile:d,batchResult:A,batchBusy:y,appendTargetId:b,setAppendTargetId:r,appendContent:x,setAppendContent:s,appendResult:h,appendError:M,appendPreview:$,openBatchModal:o,closeBatchModal:t,handleBatchCreate:g,handleBatchAppend:k,handleRetryBatchCreate:S,handleRetryBatchAppend:C}},q=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),L=(l,n)=>l instanceof Error?l.message:n,ke=({cards:l,loadCards:n})=>{const[a,u]=i.useState(!1),[m,_]=i.useState(!1),[f,j]=i.useState(null),[d,A]=i.useState({}),[c,y]=i.useState(q),[N,b]=i.useState(""),[r,x]=i.useState(""),s=i.useMemo(()=>l.filter(o=>o.type==="data"),[l]),h=i.useMemo(()=>ve(l,N,r),[l,r,N]),E=i.useCallback(o=>{var t,g,k,S,C;j(o),A({id:o.id,name:o.name||"",type:o.type||"text",api_url:((t=o.api_config)==null?void 0:t.url)||"",api_method:((g=o.api_config)==null?void 0:g.method)||"GET",api_timeout:((k=o.api_config)==null?void 0:k.timeout)||10,api_headers:((S=o.api_config)==null?void 0:S.headers)||"",api_params:((C=o.api_config)==null?void 0:C.params)||"",text_content:o.text_content||"",data_content:o.data_content||"",image_url:o.image_url||"",delay_seconds:o.delay_seconds||0,description:o.description||"",enabled:o.enabled}),u(!0)},[]),M=i.useCallback(async()=>{var o,t,g,k,S,C,p,B;if(f){if(!((o=d.name)!=null&&o.trim())){alert("请输入卡密名称");return}if(!d.type){alert("请选择卡密类型");return}try{const w={name:d.name.trim(),type:d.type,description:(t=d.description)==null?void 0:t.trim(),delay_seconds:d.delay_seconds||0,enabled:d.enabled??!0};d.type==="api"?w.api_config={url:((g=d.api_url)==null?void 0:g.trim())||"",method:d.api_method||"GET",timeout:d.api_timeout||10,headers:((k=d.api_headers)==null?void 0:k.trim())||void 0,params:((S=d.api_params)==null?void 0:S.trim())||void 0}:d.type==="text"?w.text_content=((C=d.text_content)==null?void 0:C.trim())||"":d.type==="data"?w.data_content=((p=d.data_content)==null?void 0:p.trim())||"":d.type==="image"&&(w.image_url=((B=d.image_url)==null?void 0:B.trim())||""),await J(f.id,w),u(!1),await n()}catch(w){console.error("更新卡密失败:",w),alert(L(w,"更新失败,请重试"))}}},[d,n,f]),R=i.useCallback(async o=>{if(confirm("确认删除该卡密吗?"))try{await fe(o),await n()}catch(t){console.error("删除卡密失败:",t),alert(L(t,"删除失败,请重试"))}},[n]),v=i.useCallback(async()=>{if(!c.name.trim()){alert("请输入卡密名称");return}if(!c.content.trim()){alert(c.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const o={name:c.name.trim(),type:c.type,description:c.description.trim(),enabled:c.enabled,delay_seconds:c.delay_seconds};c.type==="text"&&(o.text_content=c.content.trim()),c.type==="data"&&(o.data_content=c.content.trim()),c.type==="image"&&(o.image_url=c.content.trim()),c.type==="api"&&(o.api_config={url:c.content.trim(),method:c.api_method,timeout:c.api_timeout,headers:c.api_headers.trim()||void 0,params:c.api_params.trim()||void 0}),await ye(o),_(!1),y(q()),await n()}catch(o){console.error("添加卡密失败:",o),alert(L(o,"添加失败,请重试"))}},[c,n]),T=i.useCallback(async o=>{try{await J(o.id,{...o,enabled:!o.enabled}),await n()}catch(t){console.error("切换状态失败:",t)}},[n]),P=i.useCallback(async o=>{try{await navigator.clipboard.writeText(String(o)),alert(`已复制卡密组ID:${o}`)}catch{prompt("复制卡密组ID",String(o))}},[]),$=i.useCallback(()=>{const g=[["名称","类型","内容","描述","启用","延迟秒","多规格","规格名","规格值"],...[["VIP月卡","data",`VIP-MONTH-001
diff --git a/internal/webui/static/assets/Chat-CMwR5q9e.js b/internal/webui/static/assets/Chat-CMwR5q9e.js
new file mode 100644
index 0000000..57074e4
--- /dev/null
+++ b/internal/webui/static/assets/Chat-CMwR5q9e.js
@@ -0,0 +1 @@
+import{j as e,c as ae,r as i}from"./react-vendor-C_od1ZSF.js";import{g as b0,a as Q0,b as ie}from"./index-CNzF_I4S.js";import{o as Z0}from"./contract-COFcZjyb.js";import{L as c0,ak as ne,al as re,M as U0,I as ce,R as le,ad as I0,k as oe,am as pe,s as A0,an as me,ao as ge,ah as de}from"./icons-vendor-CvzvbbIV.js";const P0=[["尊嘟假嘟","https://img.alicdn.com/imgextra/i2/O1CN01hWzOgD1KcmFEIaGwE_!!6000000001185-2-tps-64-64.png_110x10000.jpg_.webp"],["鸡哔你","https://img.alicdn.com/imgextra/i1/O1CN01P9TVJl1JCqCZcQIdW_!!6000000000993-2-tps-64-64.png_110x10000.jpg_.webp"],["谁懂啊","https://img.alicdn.com/imgextra/i1/O1CN01r9qUnx1g3tcrtSmcs_!!6000000004087-2-tps-64-64.png_110x10000.jpg_.webp"],["吗喽","https://img.alicdn.com/imgextra/i4/O1CN01dTynZh1LnbIYTHI1D_!!6000000001344-2-tps-64-64.png_110x10000.jpg_.webp"],["功德+1","https://img.alicdn.com/imgextra/i1/O1CN01l1G5pS1IVn37pfQJi_!!6000000000899-2-tps-64-64.png_110x10000.jpg_.webp"],["city不city啊","https://img.alicdn.com/imgextra/i2/O1CN01zRjPTR29lWHqabmDA_!!6000000008108-2-tps-64-64.png_110x10000.jpg_.webp"],["激推","https://img.alicdn.com/imgextra/i3/O1CN01ADTJ6u1khypfxbfnQ_!!6000000004716-2-tps-64-64.png_110x10000.jpg_.webp"],["微笑","https://img.alicdn.com/imgextra/i1/O1CN017b61R51wRk2lVV7vx_!!6000000006305-2-tps-980-980.png_110x10000.jpg_.webp"],["龇牙","https://img.alicdn.com/imgextra/i2/O1CN01nmOh4S22Yxz8IdEVf_!!6000000007133-2-tps-980-980.png_110x10000.jpg_.webp"],["流泪","https://img.alicdn.com/imgextra/i2/O1CN01Ec1EaL1zqQETcM2dX_!!6000000006765-2-tps-980-980.png_110x10000.jpg_.webp"],["尴尬","https://img.alicdn.com/imgextra/i2/O1CN01UrWH7a1ZVBrgRYXlc_!!6000000003199-2-tps-980-980.png_110x10000.jpg_.webp"],["撇嘴","https://img.alicdn.com/imgextra/i2/O1CN01Sr7o2b1lUWg5KfOD8_!!6000000004822-2-tps-980-980.png_110x10000.jpg_.webp"],["破涕为笑","https://img.alicdn.com/imgextra/i4/O1CN01pPetah1gkwndfn7Fs_!!6000000004181-2-tps-980-980.png_110x10000.jpg_.webp"],["捂脸哭","https://img.alicdn.com/imgextra/i2/O1CN0170KgpE1dE1TuQgd66_!!6000000003703-2-tps-980-980.png_110x10000.jpg_.webp"],["害羞","https://img.alicdn.com/imgextra/i3/O1CN01ZoB0Lb1ps7XpqP8PQ_!!6000000005415-2-tps-980-980.png_110x10000.jpg_.webp"],["感动","https://img.alicdn.com/imgextra/i2/O1CN01wqD4ly29yndR3Qp3A_!!6000000008137-2-tps-980-980.png_110x10000.jpg_.webp"],["滴泪","https://img.alicdn.com/imgextra/i1/O1CN01MpkJ3L1oUTTqfryOn_!!6000000005228-2-tps-980-980.png_110x10000.jpg_.webp"],["暗中观察","https://img.alicdn.com/imgextra/i1/O1CN010LO9yj272W07GlLls_!!6000000007739-2-tps-980-980.png_110x10000.jpg_.webp"],["偷笑","https://img.alicdn.com/imgextra/i4/O1CN01vJtO031g818IuYO7x_!!6000000004096-2-tps-980-980.png_110x10000.jpg_.webp"],["ok","https://img.alicdn.com/imgextra/i3/O1CN01QRkqDF25tz0WcANje_!!6000000007585-2-tps-980-980.png_110x10000.jpg_.webp"],["送花","https://img.alicdn.com/imgextra/i2/O1CN01PpzBNX1JNpeJBWnvr_!!6000000001017-2-tps-980-980.png_110x10000.jpg_.webp"],["大哭","https://img.alicdn.com/imgextra/i4/O1CN014TiaNb1ViEgNvRrTB_!!6000000002686-2-tps-980-980.png_110x10000.jpg_.webp"],["色","https://img.alicdn.com/imgextra/i2/O1CN01840t1B1JaCLGvHnBK_!!6000000001044-2-tps-980-980.png_110x10000.jpg_.webp"],["惊慌","https://img.alicdn.com/imgextra/i1/O1CN01mnqO7G1LAfUnfAN2U_!!6000000001259-2-tps-980-980.png_110x10000.jpg_.webp"],["惊讶","https://img.alicdn.com/imgextra/i3/O1CN0127IeyS1Kw0p0P4jzI_!!6000000001227-2-tps-980-980.png_110x10000.jpg_.webp"],["得意","https://img.alicdn.com/imgextra/i4/O1CN018QUnFv1WpOUES9POZ_!!6000000002837-2-tps-980-980.png_110x10000.jpg_.webp"],["睡","https://img.alicdn.com/imgextra/i2/O1CN01RprGZl1lqVgnEJLCx_!!6000000004870-2-tps-980-980.png_110x10000.jpg_.webp"],["不好意思","https://img.alicdn.com/imgextra/i3/O1CN01rMJJgn1SUXzuVpUhO_!!6000000002250-2-tps-980-980.png_110x10000.jpg_.webp"],["托腮","https://img.alicdn.com/imgextra/i1/O1CN01w3reBU1d3wlgOBtyZ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["发怒","https://img.alicdn.com/imgextra/i2/O1CN013Wzy8d2A8PxGJZPpT_!!6000000008158-2-tps-980-980.png_110x10000.jpg_.webp"],["难过","https://img.alicdn.com/imgextra/i2/O1CN01zcwaSh1G9gZCFuFal_!!6000000000580-2-tps-980-980.png_110x10000.jpg_.webp"],["调皮","https://img.alicdn.com/imgextra/i3/O1CN01Zd1YHi1TI0lwpBe8c_!!6000000002358-2-tps-980-980.png_110x10000.jpg_.webp"],["愉快","https://img.alicdn.com/imgextra/i2/O1CN0145wDk21SWpyjTvsvA_!!6000000002255-2-tps-980-980.png_110x10000.jpg_.webp"],["白眼","https://img.alicdn.com/imgextra/i4/O1CN01nexGth1hwEAT1SHO2_!!6000000004341-2-tps-980-980.png_110x10000.jpg_.webp"],["拒绝","https://img.alicdn.com/imgextra/i2/O1CN01nqusqS1uHXzoUcpXr_!!6000000006012-2-tps-980-980.png_110x10000.jpg_.webp"],["期待","https://img.alicdn.com/imgextra/i3/O1CN01M44QY11Oh8Q5PdMIx_!!6000000001736-2-tps-980-980.png_110x10000.jpg_.webp"],["困","https://img.alicdn.com/imgextra/i4/O1CN01J4hFFz1Y9pmNdBq76_!!6000000003017-2-tps-980-980.png_110x10000.jpg_.webp"],["流汗","https://img.alicdn.com/imgextra/i4/O1CN01BU3NZ21gdcSjkqnST_!!6000000004165-2-tps-980-980.png_110x10000.jpg_.webp"],["憨笑","https://img.alicdn.com/imgextra/i2/O1CN01Pee9Ql1SJ661eH9By_!!6000000002225-2-tps-980-980.png_110x10000.jpg_.webp"],["耶","https://img.alicdn.com/imgextra/i2/O1CN01pFicsL1ipBhIqzcgs_!!6000000004461-2-tps-980-980.png_110x10000.jpg_.webp"],["奋斗","https://img.alicdn.com/imgextra/i3/O1CN01ZhQ4AV25xBmTK3CnF_!!6000000007592-2-tps-980-980.png_110x10000.jpg_.webp"],["咒骂","https://img.alicdn.com/imgextra/i3/O1CN01r1Zh9927QKb4pnf7k_!!6000000007791-2-tps-980-980.png_110x10000.jpg_.webp"],["疑问","https://img.alicdn.com/imgextra/i4/O1CN01UZqbzt29MmlNctCQS_!!6000000008054-2-tps-980-980.png_110x10000.jpg_.webp"],["嘘","https://img.alicdn.com/imgextra/i1/O1CN01qBlYkM1ojaYF75On5_!!6000000005261-2-tps-980-980.png_110x10000.jpg_.webp"],["晕","https://img.alicdn.com/imgextra/i2/O1CN014zhM2h1wPuSUFoMwV_!!6000000006301-2-tps-980-980.png_110x10000.jpg_.webp"],["开心到模糊","https://img.alicdn.com/imgextra/i1/O1CN01T1Dy271j6akZWo7Vr_!!6000000004499-2-tps-980-980.png_110x10000.jpg_.webp"],["衰","https://img.alicdn.com/imgextra/i1/O1CN01aOXsNr1LmgMvtyzOO_!!6000000001342-2-tps-980-980.png_110x10000.jpg_.webp"],["委屈","https://img.alicdn.com/imgextra/i2/O1CN013J0bMk1QNYih3UFTk_!!6000000001964-2-tps-980-980.png_110x10000.jpg_.webp"],["再见","https://img.alicdn.com/imgextra/i2/O1CN01IHKsQx1UdpFgeTHcA_!!6000000002541-2-tps-980-980.png_110x10000.jpg_.webp"],["鼓掌","https://img.alicdn.com/imgextra/i4/O1CN01DHxB5s1G1RRBxekIu_!!6000000000562-2-tps-980-980.png_110x10000.jpg_.webp"],["吐","https://img.alicdn.com/imgextra/i1/O1CN01xyVxH21LNUaMgW4hh_!!6000000001287-2-tps-980-980.png_110x10000.jpg_.webp"],["坏笑","https://img.alicdn.com/imgextra/i1/O1CN01zV7opv1bIU6iI8OhM_!!6000000003442-2-tps-980-980.png_110x10000.jpg_.webp"],["抠鼻","https://img.alicdn.com/imgextra/i1/O1CN01QOanju1sNqCrtYstu_!!6000000005755-2-tps-980-980.png_110x10000.jpg_.webp"],["叹气","https://img.alicdn.com/imgextra/i3/O1CN01RElx7R1QD1c8ZN07f_!!6000000001941-2-tps-980-980.png_110x10000.jpg_.webp"],["无聊","https://img.alicdn.com/imgextra/i2/O1CN01d91LnZ1UJDQjKCouC_!!6000000002496-2-tps-980-980.png_110x10000.jpg_.webp"],["思考","https://img.alicdn.com/imgextra/i2/O1CN01wQjg2f1tO84ZWitn9_!!6000000005891-2-tps-980-980.png_110x10000.jpg_.webp"],["呆","https://img.alicdn.com/imgextra/i1/O1CN01GLqBWC1DGbhqmpD2L_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["哇哦","https://img.alicdn.com/imgextra/i2/O1CN01MtLpS21qRO2bnAA5k_!!6000000005492-2-tps-980-980.png_110x10000.jpg_.webp"],["飞吻","https://img.alicdn.com/imgextra/i4/O1CN01q1WpFE25ljsNKjvHX_!!6000000007567-2-tps-980-980.png_110x10000.jpg_.webp"],["好喜欢","https://img.alicdn.com/imgextra/i2/O1CN01mD4iQM1O57XyQ5SHD_!!6000000001653-2-tps-980-980.png_110x10000.jpg_.webp"],["拜托","https://img.alicdn.com/imgextra/i4/O1CN01SQgrTH1dzCH3pIyRN_!!6000000003806-2-tps-980-980.png_110x10000.jpg_.webp"],["真棒","https://img.alicdn.com/imgextra/i2/O1CN017fcAmd1SCgYCj9Upk_!!6000000002211-2-tps-980-980.png_110x10000.jpg_.webp"],["流鼻血","https://img.alicdn.com/imgextra/i3/O1CN0139JscY1rC6RS9GR4j_!!6000000005594-2-tps-980-980.png_110x10000.jpg_.webp"],["费解","https://img.alicdn.com/imgextra/i1/O1CN01FqAVvR1tyJMPj13ie_!!6000000005970-2-tps-980-980.png_110x10000.jpg_.webp"],["秃头","https://img.alicdn.com/imgextra/i4/O1CN01ZF4bV11thMhqm2Z1h_!!6000000005933-2-tps-980-980.png_110x10000.jpg_.webp"],["嘿哈","https://img.alicdn.com/imgextra/i4/O1CN01ObcOw61FOVlvQg7Mw_!!6000000000477-2-tps-980-980.png_110x10000.jpg_.webp"],["吃土","https://img.alicdn.com/imgextra/i3/O1CN01Z6nJ1b1ZYr22YseHN_!!6000000003207-2-tps-980-980.png_110x10000.jpg_.webp"],["机智","https://img.alicdn.com/imgextra/i1/O1CN01rfKY351zDUZJlBiir_!!6000000006680-2-tps-980-980.png_110x10000.jpg_.webp"],["举杯","https://img.alicdn.com/imgextra/i4/O1CN01R2tn4F1mn8NuEIE8J_!!6000000004998-2-tps-980-980.png_110x10000.jpg_.webp"],["握手","https://img.alicdn.com/imgextra/i4/O1CN01NDcA251JDkvuFhSDb_!!6000000000995-2-tps-980-980.png_110x10000.jpg_.webp"],["挥手","https://img.alicdn.com/imgextra/i4/O1CN01iVN0ht1TmEuSwauGt_!!6000000002424-2-tps-980-980.png_110x10000.jpg_.webp"],["yeah","https://img.alicdn.com/imgextra/i3/O1CN01opt7hh27Wk8omjR4t_!!6000000007805-2-tps-980-980.png_110x10000.jpg_.webp"],["666","https://img.alicdn.com/imgextra/i3/O1CN01YRWDPF1OjQOpXeuTC_!!6000000001741-2-tps-980-980.png_110x10000.jpg_.webp"],["棒","https://img.alicdn.com/imgextra/i3/O1CN01agprvs1HU7rPRxOnB_!!6000000000760-2-tps-980-980.png_110x10000.jpg_.webp"],["爱你","https://img.alicdn.com/imgextra/i1/O1CN01SzxgcH1GSSo6Lwmwk_!!6000000000621-2-tps-980-980.png_110x10000.jpg_.webp"],["比心","https://img.alicdn.com/imgextra/i1/O1CN01YHZ39t1DeQIeb0TWQ_!!6000000000241-2-tps-980-980.png_110x10000.jpg_.webp"],["感谢","https://img.alicdn.com/imgextra/i3/O1CN01ywacF81baLYNeyK1n_!!6000000003481-2-tps-980-980.png_110x10000.jpg_.webp"],["拍手","https://img.alicdn.com/imgextra/i4/O1CN01wbj4wv1K7ArD9AU44_!!6000000001116-2-tps-980-980.png_110x10000.jpg_.webp"],["拉钩","https://img.alicdn.com/imgextra/i1/O1CN01dePkKH1HOd6ivAcu8_!!6000000000748-2-tps-980-980.png_110x10000.jpg_.webp"],["没钱","https://img.alicdn.com/imgextra/i3/O1CN01qhxGjp1zD2AfqmWx5_!!6000000006679-2-tps-980-980.png_110x10000.jpg_.webp"],["小刀","https://img.alicdn.com/imgextra/i3/O1CN01tFVx5Y1T2thPjhR6b_!!6000000002325-2-tps-980-980.png_110x10000.jpg_.webp"],["不刀","https://img.alicdn.com/imgextra/i4/O1CN01zTxff61clcvOcTS3n_!!6000000003641-2-tps-980-980.png_110x10000.jpg_.webp"],["同出","https://img.alicdn.com/imgextra/i3/O1CN01URKas6249R8ozS98O_!!6000000007348-2-tps-980-980.png_110x10000.jpg_.webp"],["递钱","https://img.alicdn.com/imgextra/i4/O1CN01PzhgV51FLlOaZHZ6n_!!6000000000471-2-tps-980-980.png_110x10000.jpg_.webp"],["数钱","https://img.alicdn.com/imgextra/i3/O1CN01CzXXvp23khkljToQH_!!6000000007294-2-tps-980-980.png_110x10000.jpg_.webp"],["打call","https://img.alicdn.com/imgextra/i1/O1CN01X7VUVm1il48IYv8Qw_!!6000000004452-2-tps-980-980.png_110x10000.jpg_.webp"],["号外","https://img.alicdn.com/imgextra/i2/O1CN01vg6xSM1Vxo9EKyfjR_!!6000000002720-2-tps-980-980.png_110x10000.jpg_.webp"],["包邮","https://img.alicdn.com/imgextra/i3/O1CN01yVS7ys24jA22oVZ2T_!!6000000007426-2-tps-980-980.png_110x10000.jpg_.webp"],["求赞","https://img.alicdn.com/imgextra/i1/O1CN01Xwqi5A1giCQMRcX6N_!!6000000004175-2-tps-980-980.png_110x10000.jpg_.webp"],["非主流","https://img.alicdn.com/imgextra/i1/O1CN013wyI1j1hlEfDUoATI_!!6000000004317-2-tps-980-980.png_110x10000.jpg_.webp"],["吃瓜","https://img.alicdn.com/imgextra/i1/O1CN01LLOFsh1UUCw0deZba_!!6000000002520-2-tps-980-980.png_110x10000.jpg_.webp"],["种草","https://img.alicdn.com/imgextra/i2/O1CN01ooeRC81hA8a4x9S3q_!!6000000004236-2-tps-980-980.png_110x10000.jpg_.webp"],["佛系","https://img.alicdn.com/imgextra/i4/O1CN01BYXEe321GMHMZ9w66_!!6000000006957-2-tps-980-980.png_110x10000.jpg_.webp"],["超便宜","https://img.alicdn.com/imgextra/i4/O1CN01mqgSZi1Er4rOIDiP7_!!6000000000404-2-tps-980-980.png_110x10000.jpg_.webp"],["拥抱","https://img.alicdn.com/imgextra/i1/O1CN01yuGD9c1hJkttfKHAm_!!6000000004257-2-tps-980-980.png_110x10000.jpg_.webp"],["摊手","https://img.alicdn.com/imgextra/i2/O1CN014AiIqE1o9repE6STR_!!6000000005183-2-tps-980-980.png_110x10000.jpg_.webp"],["举手","https://img.alicdn.com/imgextra/i1/O1CN01xizuHZ1WPkJCogbuj_!!6000000002781-2-tps-980-980.png_110x10000.jpg_.webp"],["蹲","https://img.alicdn.com/imgextra/i3/O1CN01Midjjn1FrMj2CWer6_!!6000000000540-2-tps-980-980.png_110x10000.jpg_.webp"],["跪了","https://img.alicdn.com/imgextra/i3/O1CN01F2y52j24E16L6RIjF_!!6000000007358-2-tps-980-980.png_110x10000.jpg_.webp"],["拜","https://img.alicdn.com/imgextra/i4/O1CN01Jldd1G1oXDrEHH2qr_!!6000000005234-2-tps-980-980.png_110x10000.jpg_.webp"],["排","https://img.alicdn.com/imgextra/i3/O1CN01uSUmYD1jD0IJf0UVU_!!6000000004513-2-tps-980-980.png_110x10000.jpg_.webp"],["旺财","https://img.alicdn.com/imgextra/i3/O1CN01A25Mv01DKjGseAmuP_!!6000000000198-2-tps-980-980.png_110x10000.jpg_.webp"],["招财猫","https://img.alicdn.com/imgextra/i3/O1CN01WmJ7Sr20EhDyp86Bd_!!6000000006818-2-tps-980-980.png_110x10000.jpg_.webp"],["酸了","https://img.alicdn.com/imgextra/i3/O1CN01UFgjn61JJi5Iqxdk7_!!6000000001008-2-tps-980-980.png_110x10000.jpg_.webp"],["鸭鸭","https://img.alicdn.com/imgextra/i3/O1CN01pHSCSQ1deaS8WDiqG_!!6000000003761-2-tps-980-980.png_110x10000.jpg_.webp"],["方了","https://img.alicdn.com/imgextra/i3/O1CN01br7g711whlu8xOPUt_!!6000000006340-2-tps-980-980.png_110x10000.jpg_.webp"],["白菜","https://img.alicdn.com/imgextra/i1/O1CN01KABFLt24WKwXjVp08_!!6000000007398-2-tps-980-980.png_110x10000.jpg_.webp"],["桃子","https://img.alicdn.com/imgextra/i1/O1CN01CQhhPH1vJfRjDGBv5_!!6000000006152-2-tps-980-980.png_110x10000.jpg_.webp"],["打包","https://img.alicdn.com/imgextra/i3/O1CN01oYOkUI1VT7c0ivZHV_!!6000000002653-2-tps-980-980.png_110x10000.jpg_.webp"],["沙发","https://img.alicdn.com/imgextra/i4/O1CN018qUFaE1DGbhqpMIit_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["南","https://img.alicdn.com/imgextra/i1/O1CN01ZSA6wg1PEZKf4h99R_!!6000000001809-2-tps-980-980.png_110x10000.jpg_.webp"],["盯","https://img.alicdn.com/imgextra/i4/O1CN01OWB1Gx1s01bzBhHN6_!!6000000005703-2-tps-980-980.png_110x10000.jpg_.webp"],["hot","https://img.alicdn.com/imgextra/i4/O1CN01DDD9uA22cAl7VDH7d_!!6000000007140-2-tps-980-980.png_110x10000.jpg_.webp"],["new","https://img.alicdn.com/imgextra/i3/O1CN01rRJXJo1qwzN4YnOHX_!!6000000005561-2-tps-980-980.png_110x10000.jpg_.webp"],["cool","https://img.alicdn.com/imgextra/i4/O1CN013bUubF2855qb2Qt5l_!!6000000007880-2-tps-980-980.png_110x10000.jpg_.webp"],["1","https://img.alicdn.com/imgextra/i1/O1CN01U8XG5y1Ie22frQHCQ_!!6000000000917-2-tps-980-980.png_110x10000.jpg_.webp"],["可","https://img.alicdn.com/imgextra/i2/O1CN01SMjtPG1iJaN17p94N_!!6000000004392-2-tps-980-980.png_110x10000.jpg_.webp"],["搬砖","https://img.alicdn.com/imgextra/i1/O1CN01GbqW6G1LOrm0Gllcb_!!6000000001290-2-tps-980-980.png_110x10000.jpg_.webp"],["菜狗","https://img.alicdn.com/imgextra/i2/O1CN01VtN0t91USNLmvfmol_!!6000000002516-2-tps-980-980.png_110x10000.jpg_.webp"],["开心面具","https://img.alicdn.com/imgextra/i3/O1CN017elkpk22EoYlBPKd3_!!6000000007089-2-tps-980-980.png_110x10000.jpg_.webp"],["快递","https://img.alicdn.com/imgextra/i2/O1CN01AmUZXk1d3wle5O8IJ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["裂开","https://img.alicdn.com/imgextra/i1/O1CN01BihwvO1a5N9bFt0LU_!!6000000003278-2-tps-980-980.png_110x10000.jpg_.webp"],["啤酒","https://img.alicdn.com/imgextra/i4/O1CN01jDkgEj1WvLdXUVBDx_!!6000000002850-2-tps-980-980.png_110x10000.jpg_.webp"],["瑞思拜","https://img.alicdn.com/imgextra/i4/O1CN011gR0Um1K3VgpYjPOi_!!6000000001108-2-tps-980-980.png_110x10000.jpg_.webp"],["小丑","https://img.alicdn.com/imgextra/i3/O1CN01jMikhO1NJUM15XKTf_!!6000000001549-2-tps-980-980.png_110x10000.jpg_.webp"],["爱心","https://img.alicdn.com/imgextra/i1/O1CN015RVSWf23s25eETJqO_!!6000000007310-2-tps-980-980.png_110x10000.jpg_.webp"]],xe=r=>r,_e=new Map(P0.map(([r,o])=>[r,o])),ue=r=>r.split(/(\[[^\]]+\])/g).map((o,t)=>{const n=o.startsWith("[")?_e.get(o.slice(1,-1)):void 0;return n?e.jsx("img",{src:n,alt:o,title:o,className:"mx-0.5 inline-block h-7 w-7 align-middle"},t):e.jsx(ae.Fragment,{children:o},t)}),he=async r=>b0("/api/v1/accounts/details",void 0,r),F0=async r=>b0("/api/v1/accounts/runtime-status",void 0,r),M0=async(r,o,t,n=!1)=>{const x=await b0("/api/v1/chat/sessions",{account_id:r,cursor:o,refresh:n?1:void 0},n?{timeoutMs:6e4,...t}:t),w=Z0(x,["data","result"])||{};return{sessions:w.sessions||[],has_more:w.has_more===!0,next_cursor:w.next_cursor}},H0=async(r,o,t,n,x)=>{const w=await b0("/api/v1/chat/messages",{account_id:r,chat_id:o,cursor:t,before_id:n},x),u=Z0(w,["data","result"])||{};return{messages:u.messages||[],has_more:u.has_more===!0,next_cursor:u.next_cursor,session:u.session}},be=async(r,o)=>Q0("/api/v1/chat/messages",r,o),fe=async(r,o)=>{const t=new FormData;return Object.entries(r).forEach(([n,x])=>t.append(n,x)),ie("/api/v1/chat/images",t,{timeoutMs:12e4,...o})},B0=async(r,o,t,n)=>Q0("/api/v1/chat/read",{account_id:r,chat_id:o,message_ids:t},n),q0=r=>{const o=Number.isFinite(r)?Math.max(0,Math.floor(r)):0;return o>99?"99+":String(o)},J0=r=>(Number.isFinite(r)?Math.max(0,Math.floor(r)):0)<10?"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-red-500 text-[10px] font-bold leading-none text-white":"inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full bg-red-500 px-1.5 text-[10px] font-bold leading-none text-white",z0=(r,o)=>r.filter(t=>t.direction==="incoming"&&t.message_type!=="system"&&!t.message_key.startsWith("in-")).map(t=>({messageId:t.message_key,sessionId:o,cid:`${o}@goofish`,conversationType:1})),je=(r,o,t)=>{const n=o.trim().toLowerCase();return r.filter(x=>t&&x.unread_count<=0?!1:n?[x.buyer_name,x.buyer_id,x.item_title,x.last_message].some(w=>(w||"").toLowerCase().includes(n)):!0)},we=(r,o)=>{const t=new Set(r.map(n=>n.message_key));return[...o.filter(n=>!t.has(n.message_key)),...r]},L0=(r,o)=>{const t=r.findIndex(n=>n.message_key===o.message_key);return t<0?[...r,o]:r.map((n,x)=>x===t?o:n)},N=(r,o,t)=>r===o&&!t.aborted,V=r=>r instanceof Error&&r.message==="请求已取消",Ne=r=>{if(!r)return"";const o=new Date(r<1e10?r*1e3:r),t=new Date;return o.toDateString()===t.toDateString()?o.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit",hour12:!1}):o.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"})},Ce=r=>new Date(r<1e10?r*1e3:r).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}),ye=()=>{const[r,o]=i.useState([]),[t,n]=i.useState(""),[x,w]=i.useState({}),[u,W]=i.useState(""),[D,S]=i.useState([]),[G,f0]=i.useState(""),[M,j0]=i.useState(!1),[q,l0]=i.useState(""),[w0,L]=i.useState(!0),[F,I]=i.useState(!1),[X,Y]=i.useState(!1),[K,o0]=i.useState(!1),[p0,m0]=i.useState(),[$,H]=i.useState({}),[e0,t0]=i.useState({}),[s0,g0]=i.useState(!1),[d0,N0]=i.useState(!1),[y,B]=i.useState(!1),[C0,C]=i.useState(""),[y0,J]=i.useState("connecting"),[z,a0]=i.useState(null),[a,j]=i.useState(null),O=i.useRef(""),T=i.useRef(""),Q=i.useRef(null),O0=i.useRef({accountID:"",chatID:""}),v0=i.useRef(!0),Z=i.useRef(!1),k0=i.useRef(null),T0=i.useRef(new Set),S0=i.useRef(0),R0=i.useRef(null),U=i.useRef(0),E0=i.useRef(null),A=i.useRef(0),i0=i.useRef(null),n0=i.useRef(0),x0=i.useRef(null),R=i.useRef(0),P=i.useRef(null);i.useEffect(()=>{O.current=t},[t]),i.useEffect(()=>{T.current=u},[u]);const r0=i.useCallback(async s=>{var l;const p=++S0.current;(l=R0.current)==null||l.abort();const m=new AbortController;R0.current=m;try{const c=await M0(s,void 0,{signal:m.signal},!0);if(!N(S0.current,p,m.signal))return[];const d=c.sessions.map(g=>s===O.current&&g.chat_id===T.current?{...g,unread_count:0}:g);return w(g=>({...g,[s]:d})),H(g=>({...g,[s]:c.next_cursor})),t0(g=>({...g,[s]:c.has_more})),d}catch(c){return N(S0.current,p,m.signal)&&!V(c)&&C(c instanceof Error?c.message:"同步会话失败"),[]}},[]);i.useEffect(()=>{const s=new AbortController;return(async()=>{var m;L(!0);try{const[l,c]=await Promise.all([he({signal:s.signal}),F0({signal:s.signal})]),g=l.map(h=>{var v,D0;return{...h,runtime_state:((v=c[h.id])==null?void 0:v.state)||(h.enabled?"connecting":"disabled"),runtime_connected:((D0=c[h.id])==null?void 0:D0.connected)===!0}}).filter(h=>h.enabled),f=await Promise.all(g.map(async h=>[h.id,await M0(h.id,void 0,{signal:s.signal})]));if(s.signal.aborted)return;o(g),w(Object.fromEntries(f.map(([h,v])=>[h,v.sessions]))),H(Object.fromEntries(f.map(([h,v])=>[h,v.next_cursor]))),t0(Object.fromEntries(f.map(([h,v])=>[h,v.has_more])));const _=window.localStorage.getItem("ydisks.chat.account.v1")||"",k=g.some(h=>h.id===_)?_:((m=g[0])==null?void 0:m.id)||"";n(k)}catch(l){s.signal.aborted||C(l instanceof Error?l.message:"加载聊天数据失败")}finally{s.signal.aborted||L(!1)}})(),(()=>s.abort())},[]),i.useEffect(()=>{let s=!1,p=0,m=null;const l=async()=>{m=new AbortController;try{const c=await F0({signal:m.signal,timeoutMs:1e4});s||o(d=>d.map(g=>{var f,_;return{...g,runtime_state:((f=c[g.id])==null?void 0:f.state)||g.runtime_state,runtime_connected:((_=c[g.id])==null?void 0:_.connected)??g.runtime_connected}}))}catch{}finally{s||(p=window.setTimeout(l,3e3))}};return p=window.setTimeout(l,3e3),(()=>{s=!0,window.clearTimeout(p),m==null||m.abort()})},[]),i.useEffect(()=>{if(!t)return;window.localStorage.setItem("ydisks.chat.account.v1",t);const s=x[t]||[];W(p=>{var m;return s.some(l=>l.chat_id===p)?p:((m=s[0])==null?void 0:m.chat_id)||""})},[t,x]),i.useEffect(()=>{!t||T0.current.has(t)||(T0.current.add(t),r0(t))},[t,r0]),i.useEffect(()=>{var m,l;if(!t||!u){U.current+=1,A.current+=1,(m=i0.current)==null||m.abort(),Z.current=!1,S([]);return}const s=++U.current;(l=E0.current)==null||l.abort();const p=new AbortController;return E0.current=p,I(!0),H0(t,u,void 0,void 0,{signal:p.signal}).then(c=>{if(!N(U.current,s,p.signal))return;const d=z0(c.messages,u);B0(t,u,d,{signal:p.signal}),S(c.messages),o0(c.has_more),m0(c.next_cursor),c.session&&w(g=>({...g,[t]:(g[t]||[]).map(f=>{var _;return f.chat_id===((_=c.session)==null?void 0:_.chat_id)?c.session:f})})),w(g=>({...g,[t]:(g[t]||[]).map(f=>f.chat_id===u?{...f,unread_count:0}:f)}))}).catch(c=>{N(U.current,s,p.signal)&&!V(c)&&C(c instanceof Error?c.message:"加载消息失败")}).finally(()=>{N(U.current,s,p.signal)&&I(!1)}),(()=>p.abort())},[t,u]),i.useEffect(()=>{var s;(s=x0.current)==null||s.abort(),n0.current+=1},[t]),i.useEffect(()=>{var s;(s=P.current)==null||s.abort(),R.current+=1},[t,u]),i.useEffect(()=>{var s;A.current+=1,(s=i0.current)==null||s.abort(),Z.current=!1},[t,u]),i.useEffect(()=>(()=>{var s,p,m,l,c;(s=R0.current)==null||s.abort(),(p=E0.current)==null||p.abort(),A.current+=1,(m=i0.current)==null||m.abort(),(l=x0.current)==null||l.abort(),(c=P.current)==null||c.abort()}),[]);const V0=i.useCallback(async()=>{var d,g;if(!t||!u||X||!K)return;const s=Q.current,p=(s==null?void 0:s.scrollHeight)||0,m=U.current,l=++A.current;(d=i0.current)==null||d.abort();const c=new AbortController;i0.current=c,Z.current=!0,Y(!0),C("");try{const f=(g=D[0])==null?void 0:g.id,_=await H0(t,u,p0,f,{signal:c.signal});if(!N(U.current,m,c.signal)||l!==A.current)return;S(k=>we(k,_.messages)),o0(_.has_more),m0(_.next_cursor),requestAnimationFrame(()=>{l===A.current&&!c.signal.aborted&&s&&(s.scrollTop+=s.scrollHeight-p)})}catch(f){Z.current=!1,V(f)||C(f instanceof Error?f.message:"加载历史消息失败")}finally{l===A.current&&Y(!1)}},[t,u,K,p0,D,X]);i.useEffect(()=>{let s=!1,p=0,m=0,l=null;const c=()=>{if(s)return;J("connecting");const d=window.location.protocol==="https:"?"wss:":"ws:";l=new WebSocket(`${d}//${window.location.host}/api/v1/chat/ws`),l.onopen=()=>{m=0,J("online")},l.onmessage=g=>{try{const _=JSON.parse(g.data).message;if(!_)return;const k=_.account_id;if(w(h=>{const v=h[k]||[];return v.some(E=>E.chat_id===_.chat_id)?{...h,[k]:v.map(E=>E.chat_id===_.chat_id?{...E,last_message:_.content,last_message_at:_.sent_at,unread_count:_.direction==="incoming"&&_.message_type!=="system"&&(O.current!==k||T.current!==_.chat_id)?E.unread_count+1:E.unread_count}:E).sort((E,se)=>se.last_message_at-E.last_message_at)}:(r0(k),h)}),O.current===k&&T.current===_.chat_id&&(S(h=>L0(h,_)),_.direction==="incoming"&&_.message_type!=="system")){const h=z0([_],_.chat_id);B0(k,_.chat_id,h)}}catch{}},l.onclose=()=>{if(s)return;J("offline");const g=Math.min(15e3,1e3*2**Math.min(m++,4));p=window.setTimeout(c,g)},l.onerror=()=>l==null?void 0:l.close()};return c(),(()=>{s=!0,window.clearTimeout(p),l==null||l.close()})},[r0]);const W0=i.useCallback(()=>{const s=Q.current;if(!s)return;const p=s.scrollHeight-s.scrollTop-s.clientHeight;v0.current=p<=48},[]);i.useLayoutEffect(()=>{const s=O0.current.accountID!==t||O0.current.chatID!==u;O0.current={accountID:t,chatID:u},s&&(v0.current=!0);const p=Q.current;if(p){if(Z.current){Z.current=!1;return}(F||v0.current)&&(p.scrollTop=p.scrollHeight)}},[t,u,D,F]);const G0=r.find(s=>s.id===t),_0=x[t]||[],b=_0.find(s=>s.chat_id===u),X0=i.useMemo(()=>je(_0,G,M),[_0,G,M]),Y0=i.useCallback(s=>(x[s]||[]).reduce((p,m)=>p+m.unread_count,0),[x]),K0=i.useCallback(async()=>{var l;if(!t||s0||!e0[t])return;const s=++n0.current;(l=x0.current)==null||l.abort();const p=new AbortController;x0.current=p;const m=t;g0(!0),C("");try{const c=await M0(m,$[m],{signal:p.signal},!0);if(!N(n0.current,s,p.signal))return;w(d=>({...d,[m]:c.sessions})),H(d=>({...d,[m]:c.next_cursor})),t0(d=>({...d,[m]:c.has_more}))}catch(c){N(n0.current,s,p.signal)&&!V(c)&&C(c instanceof Error?c.message:"加载历史联系人失败")}finally{N(n0.current,s,p.signal)&&g0(!1)}},[t,$,s0,e0]),u0=i.useCallback(async(s,p)=>{var c;if(!b||!t||y)return;const m=++R.current;(c=P.current)==null||c.abort();const l=new AbortController;P.current=l,B(!0),C("");try{const d=await be({account_id:t,chat_id:b.chat_id,buyer_id:b.buyer_id,buyer_name:b.buyer_name,item_id:b.item_id,item_title:b.item_title,text:s},{signal:l.signal});if(!N(R.current,m,l.signal))return;l0(""),a0(null),S(g=>L0(g,d.message))}catch(d){N(R.current,m,l.signal)&&(p&&a0(s),V(d)||C(d instanceof Error?d.message:"消息发送失败"))}finally{N(R.current,m,l.signal)&&B(!1)}},[t,b,y]),h0=i.useCallback(async(s,p)=>{var c;if(!b||!t||y)return;const m=++R.current;(c=P.current)==null||c.abort();const l=new AbortController;P.current=l,B(!0),C("");try{const d=await fe({account_id:t,chat_id:b.chat_id,buyer_id:b.buyer_id,buyer_name:b.buyer_name,buyer_avatar_url:b.buyer_avatar_url,item_id:b.item_id,item_title:b.item_title,image:s},{signal:l.signal});if(!N(R.current,m,l.signal))return;j(null),S(g=>L0(g,d.message))}catch(d){N(R.current,m,l.signal)&&(p&&j(s),V(d)||C(d instanceof Error?d.message:"图片发送失败"))}finally{N(R.current,m,l.signal)&&(B(!1),k0.current&&(k0.current.value=""))}},[t,b,y]),$0=i.useCallback(async()=>{const s=q.trim();!s||!b||!t||y||await u0(s,!0)},[t,q,b,u0,y]),ee=i.useCallback(async s=>{!s||!b||!t||y||await h0(s,!0)},[t,b,h0,y]),te=i.useCallback(async()=>{z?await u0(z,!1):a&&await h0(a,!1)},[a,z,h0,u0]);return{accounts:r,activeAccountID:t,activeSessions:_0,selectedSession:b,activeAccount:G0,messages:D,search:G,unreadOnly:M,draft:q,loading:w0,messagesLoading:F,olderLoading:X,hasOlder:K,contactsLoading:s0,hasMoreContacts:e0[t]===!0,emojiOpen:d0,sending:y,error:C0,liveState:y0,activeChatID:u,filteredSessions:X0,scrollRef:Q,imageInputRef:k0,setActiveAccountID:n,setActiveChatID:W,setSearch:f0,setUnreadOnly:j0,setDraft:l0,setEmojiOpen:N0,reloadSessions:r0,loadMoreContacts:K0,loadOlderMessages:V0,handleMessageScroll:W0,handleSend:$0,handleImage:ee,retrySend:te,retryAvailable:!!(z||a),unreadForAccount:Y0,emojiURL:xe,xianyuEmojis:P0,renderXianyuText:ue,formatClock:Ne,messageTime:Ce}},Re=()=>{const{accounts:r,activeAccountID:o,activeChatID:t,activeAccount:n,selectedSession:x,filteredSessions:w,messages:u,search:W,unreadOnly:D,draft:S,loading:G,messagesLoading:f0,olderLoading:M,hasOlder:j0,contactsLoading:q,hasMoreContacts:l0,emojiOpen:w0,sending:L,error:F,liveState:I,scrollRef:X,imageInputRef:Y,setActiveAccountID:K,setActiveChatID:o0,setSearch:p0,setUnreadOnly:m0,setDraft:$,setEmojiOpen:H,reloadSessions:e0,loadMoreContacts:t0,loadOlderMessages:s0,handleMessageScroll:g0,handleSend:d0,handleImage:N0,retrySend:y,retryAvailable:B,unreadForAccount:C0,emojiURL:C,xianyuEmojis:y0,renderXianyuText:J,formatClock:z,messageTime:a0}=ye();return G?e.jsx("div",{className:"flex h-[calc(100vh-4rem)] items-center justify-center",children:e.jsx(c0,{className:"h-8 w-8 animate-spin text-sky-500"})}):e.jsxs("section",{className:"flex h-[calc(100vh-4rem)] min-h-[560px] flex-col overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-chat",children:[e.jsxs("header",{className:"border-b border-slate-200 bg-slate-50/70 px-5 pt-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-black tracking-tight text-slate-950",children:"在线聊天"}),e.jsx("p",{className:"mt-0.5 text-xs font-medium text-slate-500",children:"复用账号实时连接,消息按账号完全隔离"})]}),e.jsxs("div",{className:`flex items-center gap-2 rounded-full px-3 py-1.5 text-xs font-bold ${I==="online"?"bg-emerald-50 text-emerald-700":I==="connecting"?"bg-amber-50 text-amber-700":"bg-red-50 text-red-700"}`,children:[I==="online"?e.jsx(ne,{className:"h-3.5 w-3.5"}):e.jsx(re,{className:"h-3.5 w-3.5"}),I==="online"?"实时同步中":I==="connecting"?"正在连接":"连接已断开"]})]}),e.jsx("div",{className:"flex gap-1 overflow-x-auto pb-0",role:"tablist","aria-label":"聊天账号",children:r.map(a=>{const j=a.id===o,O=C0(a.id),T=q0(O),Q=a.runtime_state==="online";return e.jsxs("button",{type:"button",role:"tab","aria-selected":j,onClick:(()=>K(a.id)),className:`relative flex h-11 shrink-0 items-center gap-2 border-b-2 px-3 text-sm font-extrabold transition-colors ${j?"border-sky-500 text-sky-700":"border-transparent text-slate-500 hover:text-slate-900"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${Q?"bg-emerald-500":"bg-slate-300"}`}),e.jsx("span",{className:"max-w-36 truncate",children:a.nickname||a.remark||a.id}),O>0&&e.jsx("span",{"aria-label":`未读消息 ${T} 条`,className:J0(O),children:T})]},a.id)})})]}),r.length===0?e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(U0,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-800",children:"暂无启用账号"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"先在账号管理中启用账号,聊天会话会自动出现。"})]}):e.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden grid-cols-[320px_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"flex min-h-0 flex-col border-r border-slate-200 bg-slate-50/40",children:[e.jsxs("div",{className:"space-y-3 border-b border-slate-200 p-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx("input",{value:W,onChange:(a=>p0(a.target.value)),placeholder:"搜索用户、商品或消息",className:"h-10 w-full rounded-xl border border-slate-200 bg-white pl-9 pr-3 text-sm outline-none transition focus:border-sky-400 focus:ring-2 focus:ring-sky-100"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:(()=>m0(a=>!a)),className:`rounded-lg px-2.5 py-1.5 text-xs font-bold ${D?"bg-sky-100 text-sky-700":"text-slate-500 hover:bg-slate-100"}`,children:D?"只看未读":"全部会话"}),e.jsx("button",{type:"button",title:"刷新会话",onClick:(()=>void e0(o)),className:"rounded-lg p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700",children:e.jsx(le,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[w.map(a=>e.jsxs("button",{type:"button",onClick:(()=>o0(a.chat_id)),className:`flex w-full gap-3 border-b border-slate-100 p-4 text-left transition-colors ${a.chat_id===t?"bg-white shadow-chat-active":"hover:bg-white/80"}`,children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-full bg-slate-200 text-slate-500",children:a.buyer_avatar_url?e.jsx("img",{src:a.buyer_avatar_url,alt:"",className:"h-full w-full object-cover"}):e.jsx(I0,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-extrabold text-slate-900",children:a.buyer_name||`用户 ${a.buyer_id}`}),e.jsx("span",{className:"ml-auto shrink-0 text-[10px] font-medium text-slate-400",children:z(a.last_message_at)})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-xs text-slate-500",children:a.last_message||"暂无消息"}),a.unread_count>0&&e.jsx("span",{"aria-label":`未读消息 ${q0(a.unread_count)} 条`,className:`ml-auto ${J0(a.unread_count)}`,children:q0(a.unread_count)})]}),a.item_title&&e.jsxs("div",{className:"mt-1.5 truncate text-[10px] font-medium text-sky-700",children:["商品 · ",a.item_title]})]})]},a.chat_id)),w.length===0&&e.jsx("div",{className:"px-6 py-16 text-center text-sm text-slate-400",children:"当前账号暂无匹配会话"}),l0&&!W&&!D&&e.jsx("div",{className:"flex justify-center p-4",children:e.jsxs("button",{type:"button",onClick:(()=>void t0()),disabled:q,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-2 text-xs font-bold text-slate-500 shadow-sm hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[q&&e.jsx(c0,{className:"h-3.5 w-3.5 animate-spin"}),q?"正在加载":"加载更多历史联系人"]})})]})]}),e.jsx("main",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-surface-subtle",children:x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-16 shrink-0 items-center border-b border-slate-200 bg-white px-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-black text-slate-950",children:x.buyer_name||x.buyer_id}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-slate-500",children:["用户 ID:",x.buyer_id]})]}),e.jsx("span",{className:`ml-auto rounded-full px-2.5 py-1 text-[10px] font-bold ${(n==null?void 0:n.runtime_state)==="online"?"bg-emerald-50 text-emerald-700":"bg-slate-100 text-slate-500"}`,children:(n==null?void 0:n.runtime_state)==="online"?"账号在线":"账号离线"})]}),e.jsx("div",{ref:X,onScroll:g0,className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:f0?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(c0,{className:"h-6 w-6 animate-spin text-sky-500"})}):e.jsxs(e.Fragment,{children:[j0&&e.jsx("div",{className:"flex justify-center pb-1",children:e.jsxs("button",{type:"button",onClick:(()=>void s0()),disabled:M,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-1.5 text-xs font-bold text-slate-500 shadow-sm transition hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[M&&e.jsx(c0,{className:"h-3.5 w-3.5 animate-spin"}),M?"正在加载":"加载更早消息"]})}),u.map(a=>{const j=a.direction==="outgoing";return a.message_type==="system"?e.jsx("div",{className:"flex justify-center py-1",children:e.jsxs("div",{className:"max-w-[82%] rounded-xl border border-slate-200 bg-slate-100 px-4 py-2 text-center text-xs leading-5 text-slate-500",children:[J(a.content),e.jsx("div",{className:"mt-1 text-[10px] text-slate-400",children:a0(a.sent_at)})]})},a.message_key):e.jsxs("div",{className:`flex items-end gap-2.5 ${j?"justify-end":"justify-start"}`,children:[!j&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-slate-200 ring-2 ring-white",children:x.buyer_avatar_url?e.jsx("img",{src:x.buyer_avatar_url,alt:x.buyer_name||"用户",className:"h-full w-full object-cover"}):e.jsx(I0,{className:"m-2 h-5 w-5 text-slate-500"})}),e.jsxs("div",{className:`max-w-[72%] ${j?"items-end":"items-start"} flex flex-col`,children:[e.jsx("div",{className:"mb-1 px-1 text-[10px] font-semibold text-slate-400",children:j?(n==null?void 0:n.nickname)||(n==null?void 0:n.remark)||"我":x.buyer_name||a.sender_name||x.buyer_id}),a.message_type==="image"?e.jsx("a",{href:a.content,target:"_blank",rel:"noreferrer",className:`block overflow-hidden rounded-2xl border bg-white p-1 shadow-sm ${j?"rounded-br-md border-sky-200":"rounded-bl-md border-slate-200"}`,children:e.jsx("img",{src:a.content,alt:"聊天图片",className:"max-h-80 max-w-full rounded-xl object-contain"})}):a.message_type==="video"?e.jsx("video",{src:a.content,controls:!0,preload:"metadata",className:"max-h-80 max-w-full rounded-2xl bg-black"}):e.jsx("div",{className:`rounded-2xl px-4 py-2.5 text-sm leading-6 shadow-sm ${j?"rounded-br-md bg-sky-500 text-white":"rounded-bl-md border border-slate-200 bg-white text-slate-800"}`,children:J(a.content)}),e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] text-slate-400",children:[a0(a.sent_at),j&&(a.status==="failed"?e.jsx(oe,{className:"h-3 w-3 text-red-500","aria-label":"发送失败"}):a.read_status===2?e.jsx(pe,{className:"h-3 w-3 text-sky-500","aria-label":"对方已读"}):a.status==="sent"?e.jsx(A0,{className:"h-3 w-3 text-sky-500","aria-label":"已发送未读"}):e.jsx(A0,{className:"h-3 w-3","aria-label":"发送中"}))]})]}),j&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-sky-100 ring-2 ring-white",children:n!=null&&n.avatar_url?e.jsx("img",{src:n.avatar_url,alt:"我",className:"h-full w-full object-cover"}):e.jsx(I0,{className:"m-2 h-5 w-5 text-sky-600"})})]},a.message_key)})]})}),F&&e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-red-100 bg-red-50 px-5 py-2 text-xs font-medium text-red-700",children:[e.jsx("span",{children:F}),B&&e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>void y()),children:"重试发送"})]}),e.jsxs("div",{className:"relative z-10 shrink-0 border-t border-slate-200 bg-white p-4 shadow-chat-input",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1",children:[e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:(()=>H(a=>!a)),disabled:L||(n==null?void 0:n.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"闲鱼表情",children:e.jsx(me,{className:"h-5 w-5"})}),w0&&e.jsxs("div",{className:"absolute bottom-11 left-0 z-30 w-[360px] rounded-2xl border border-slate-200 bg-white p-3 shadow-2xl",children:[e.jsx("div",{className:"mb-2 text-xs font-bold text-slate-500",children:"全部表情"}),e.jsx("div",{className:"grid max-h-72 grid-cols-8 gap-1 overflow-y-auto",children:y0.map(([a,j])=>e.jsx("button",{type:"button",title:`[${a}]`,onClick:(()=>{$(O=>O+`[${a}]`),H(!1)}),className:"flex h-10 w-10 items-center justify-center rounded-lg hover:bg-slate-100",children:e.jsx("img",{src:C(j),alt:`[${a}]`,className:"h-8 w-8 object-contain"})},a))})]})]}),e.jsx("input",{ref:Y,type:"file",accept:"image/*",className:"hidden",onChange:(a=>{var j;return void N0((j=a.target.files)==null?void 0:j[0])})}),e.jsx("button",{type:"button",onClick:(()=>{var a;return(a=Y.current)==null?void 0:a.click()}),disabled:L||(n==null?void 0:n.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 transition hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"发送图片(最大 10MB)",children:e.jsx(ge,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"flex items-end gap-3 rounded-2xl border border-slate-200 bg-slate-50 p-2 transition focus-within:border-sky-400 focus-within:ring-2 focus-within:ring-sky-100",children:[e.jsx("textarea",{value:S,onChange:(a=>$(a.target.value)),rows:2,maxLength:2e3,onKeyDown:(a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),d0())}),disabled:(n==null?void 0:n.runtime_state)!=="online",placeholder:(n==null?void 0:n.runtime_state)==="online"?"输入消息,Enter 发送,Shift + Enter 换行":"账号离线,暂时无法发送",className:"max-h-32 min-h-12 flex-1 resize-none bg-transparent px-2 py-2 text-sm leading-6 outline-none disabled:cursor-not-allowed"}),e.jsx("button",{type:"button",onClick:(()=>void d0()),disabled:!S.trim()||L||(n==null?void 0:n.runtime_state)!=="online",className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-sky-500 text-white shadow-md shadow-sky-100 transition hover:bg-sky-600 disabled:cursor-not-allowed disabled:bg-slate-300 disabled:shadow-none","aria-label":"发送消息",children:L?e.jsx(c0,{className:"h-4 w-4 animate-spin"}):e.jsx(de,{className:"h-4 w-4"})})]})]})]}):e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(U0,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-700",children:"选择一个用户开始聊天"}),e.jsx("p",{className:"mt-1 text-sm text-slate-400",children:"该账号的新消息会实时出现在左侧列表。"})]})})]})]})};export{Re as default};
diff --git a/internal/webui/static/assets/Chat-DSkOtUaB.js b/internal/webui/static/assets/Chat-DSkOtUaB.js
deleted file mode 100644
index ba897df..0000000
--- a/internal/webui/static/assets/Chat-DSkOtUaB.js
+++ /dev/null
@@ -1 +0,0 @@
-import{j as e,c as ee,r as i}from"./react-vendor-C_od1ZSF.js";import{g as b0,a as J0,b as te}from"./index-hByDAHGj.js";import{o as B0}from"./contract-COFcZjyb.js";import{L as r0,ak as se,al as ae,M as L0,I as ie,R as ne,ad as I0,k as re,am as ce,s as le,an as oe,ao as pe,ah as me}from"./icons-vendor-CvzvbbIV.js";const Q0=[["尊嘟假嘟","https://img.alicdn.com/imgextra/i2/O1CN01hWzOgD1KcmFEIaGwE_!!6000000001185-2-tps-64-64.png_110x10000.jpg_.webp"],["鸡哔你","https://img.alicdn.com/imgextra/i1/O1CN01P9TVJl1JCqCZcQIdW_!!6000000000993-2-tps-64-64.png_110x10000.jpg_.webp"],["谁懂啊","https://img.alicdn.com/imgextra/i1/O1CN01r9qUnx1g3tcrtSmcs_!!6000000004087-2-tps-64-64.png_110x10000.jpg_.webp"],["吗喽","https://img.alicdn.com/imgextra/i4/O1CN01dTynZh1LnbIYTHI1D_!!6000000001344-2-tps-64-64.png_110x10000.jpg_.webp"],["功德+1","https://img.alicdn.com/imgextra/i1/O1CN01l1G5pS1IVn37pfQJi_!!6000000000899-2-tps-64-64.png_110x10000.jpg_.webp"],["city不city啊","https://img.alicdn.com/imgextra/i2/O1CN01zRjPTR29lWHqabmDA_!!6000000008108-2-tps-64-64.png_110x10000.jpg_.webp"],["激推","https://img.alicdn.com/imgextra/i3/O1CN01ADTJ6u1khypfxbfnQ_!!6000000004716-2-tps-64-64.png_110x10000.jpg_.webp"],["微笑","https://img.alicdn.com/imgextra/i1/O1CN017b61R51wRk2lVV7vx_!!6000000006305-2-tps-980-980.png_110x10000.jpg_.webp"],["龇牙","https://img.alicdn.com/imgextra/i2/O1CN01nmOh4S22Yxz8IdEVf_!!6000000007133-2-tps-980-980.png_110x10000.jpg_.webp"],["流泪","https://img.alicdn.com/imgextra/i2/O1CN01Ec1EaL1zqQETcM2dX_!!6000000006765-2-tps-980-980.png_110x10000.jpg_.webp"],["尴尬","https://img.alicdn.com/imgextra/i2/O1CN01UrWH7a1ZVBrgRYXlc_!!6000000003199-2-tps-980-980.png_110x10000.jpg_.webp"],["撇嘴","https://img.alicdn.com/imgextra/i2/O1CN01Sr7o2b1lUWg5KfOD8_!!6000000004822-2-tps-980-980.png_110x10000.jpg_.webp"],["破涕为笑","https://img.alicdn.com/imgextra/i4/O1CN01pPetah1gkwndfn7Fs_!!6000000004181-2-tps-980-980.png_110x10000.jpg_.webp"],["捂脸哭","https://img.alicdn.com/imgextra/i2/O1CN0170KgpE1dE1TuQgd66_!!6000000003703-2-tps-980-980.png_110x10000.jpg_.webp"],["害羞","https://img.alicdn.com/imgextra/i3/O1CN01ZoB0Lb1ps7XpqP8PQ_!!6000000005415-2-tps-980-980.png_110x10000.jpg_.webp"],["感动","https://img.alicdn.com/imgextra/i2/O1CN01wqD4ly29yndR3Qp3A_!!6000000008137-2-tps-980-980.png_110x10000.jpg_.webp"],["滴泪","https://img.alicdn.com/imgextra/i1/O1CN01MpkJ3L1oUTTqfryOn_!!6000000005228-2-tps-980-980.png_110x10000.jpg_.webp"],["暗中观察","https://img.alicdn.com/imgextra/i1/O1CN010LO9yj272W07GlLls_!!6000000007739-2-tps-980-980.png_110x10000.jpg_.webp"],["偷笑","https://img.alicdn.com/imgextra/i4/O1CN01vJtO031g818IuYO7x_!!6000000004096-2-tps-980-980.png_110x10000.jpg_.webp"],["ok","https://img.alicdn.com/imgextra/i3/O1CN01QRkqDF25tz0WcANje_!!6000000007585-2-tps-980-980.png_110x10000.jpg_.webp"],["送花","https://img.alicdn.com/imgextra/i2/O1CN01PpzBNX1JNpeJBWnvr_!!6000000001017-2-tps-980-980.png_110x10000.jpg_.webp"],["大哭","https://img.alicdn.com/imgextra/i4/O1CN014TiaNb1ViEgNvRrTB_!!6000000002686-2-tps-980-980.png_110x10000.jpg_.webp"],["色","https://img.alicdn.com/imgextra/i2/O1CN01840t1B1JaCLGvHnBK_!!6000000001044-2-tps-980-980.png_110x10000.jpg_.webp"],["惊慌","https://img.alicdn.com/imgextra/i1/O1CN01mnqO7G1LAfUnfAN2U_!!6000000001259-2-tps-980-980.png_110x10000.jpg_.webp"],["惊讶","https://img.alicdn.com/imgextra/i3/O1CN0127IeyS1Kw0p0P4jzI_!!6000000001227-2-tps-980-980.png_110x10000.jpg_.webp"],["得意","https://img.alicdn.com/imgextra/i4/O1CN018QUnFv1WpOUES9POZ_!!6000000002837-2-tps-980-980.png_110x10000.jpg_.webp"],["睡","https://img.alicdn.com/imgextra/i2/O1CN01RprGZl1lqVgnEJLCx_!!6000000004870-2-tps-980-980.png_110x10000.jpg_.webp"],["不好意思","https://img.alicdn.com/imgextra/i3/O1CN01rMJJgn1SUXzuVpUhO_!!6000000002250-2-tps-980-980.png_110x10000.jpg_.webp"],["托腮","https://img.alicdn.com/imgextra/i1/O1CN01w3reBU1d3wlgOBtyZ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["发怒","https://img.alicdn.com/imgextra/i2/O1CN013Wzy8d2A8PxGJZPpT_!!6000000008158-2-tps-980-980.png_110x10000.jpg_.webp"],["难过","https://img.alicdn.com/imgextra/i2/O1CN01zcwaSh1G9gZCFuFal_!!6000000000580-2-tps-980-980.png_110x10000.jpg_.webp"],["调皮","https://img.alicdn.com/imgextra/i3/O1CN01Zd1YHi1TI0lwpBe8c_!!6000000002358-2-tps-980-980.png_110x10000.jpg_.webp"],["愉快","https://img.alicdn.com/imgextra/i2/O1CN0145wDk21SWpyjTvsvA_!!6000000002255-2-tps-980-980.png_110x10000.jpg_.webp"],["白眼","https://img.alicdn.com/imgextra/i4/O1CN01nexGth1hwEAT1SHO2_!!6000000004341-2-tps-980-980.png_110x10000.jpg_.webp"],["拒绝","https://img.alicdn.com/imgextra/i2/O1CN01nqusqS1uHXzoUcpXr_!!6000000006012-2-tps-980-980.png_110x10000.jpg_.webp"],["期待","https://img.alicdn.com/imgextra/i3/O1CN01M44QY11Oh8Q5PdMIx_!!6000000001736-2-tps-980-980.png_110x10000.jpg_.webp"],["困","https://img.alicdn.com/imgextra/i4/O1CN01J4hFFz1Y9pmNdBq76_!!6000000003017-2-tps-980-980.png_110x10000.jpg_.webp"],["流汗","https://img.alicdn.com/imgextra/i4/O1CN01BU3NZ21gdcSjkqnST_!!6000000004165-2-tps-980-980.png_110x10000.jpg_.webp"],["憨笑","https://img.alicdn.com/imgextra/i2/O1CN01Pee9Ql1SJ661eH9By_!!6000000002225-2-tps-980-980.png_110x10000.jpg_.webp"],["耶","https://img.alicdn.com/imgextra/i2/O1CN01pFicsL1ipBhIqzcgs_!!6000000004461-2-tps-980-980.png_110x10000.jpg_.webp"],["奋斗","https://img.alicdn.com/imgextra/i3/O1CN01ZhQ4AV25xBmTK3CnF_!!6000000007592-2-tps-980-980.png_110x10000.jpg_.webp"],["咒骂","https://img.alicdn.com/imgextra/i3/O1CN01r1Zh9927QKb4pnf7k_!!6000000007791-2-tps-980-980.png_110x10000.jpg_.webp"],["疑问","https://img.alicdn.com/imgextra/i4/O1CN01UZqbzt29MmlNctCQS_!!6000000008054-2-tps-980-980.png_110x10000.jpg_.webp"],["嘘","https://img.alicdn.com/imgextra/i1/O1CN01qBlYkM1ojaYF75On5_!!6000000005261-2-tps-980-980.png_110x10000.jpg_.webp"],["晕","https://img.alicdn.com/imgextra/i2/O1CN014zhM2h1wPuSUFoMwV_!!6000000006301-2-tps-980-980.png_110x10000.jpg_.webp"],["开心到模糊","https://img.alicdn.com/imgextra/i1/O1CN01T1Dy271j6akZWo7Vr_!!6000000004499-2-tps-980-980.png_110x10000.jpg_.webp"],["衰","https://img.alicdn.com/imgextra/i1/O1CN01aOXsNr1LmgMvtyzOO_!!6000000001342-2-tps-980-980.png_110x10000.jpg_.webp"],["委屈","https://img.alicdn.com/imgextra/i2/O1CN013J0bMk1QNYih3UFTk_!!6000000001964-2-tps-980-980.png_110x10000.jpg_.webp"],["再见","https://img.alicdn.com/imgextra/i2/O1CN01IHKsQx1UdpFgeTHcA_!!6000000002541-2-tps-980-980.png_110x10000.jpg_.webp"],["鼓掌","https://img.alicdn.com/imgextra/i4/O1CN01DHxB5s1G1RRBxekIu_!!6000000000562-2-tps-980-980.png_110x10000.jpg_.webp"],["吐","https://img.alicdn.com/imgextra/i1/O1CN01xyVxH21LNUaMgW4hh_!!6000000001287-2-tps-980-980.png_110x10000.jpg_.webp"],["坏笑","https://img.alicdn.com/imgextra/i1/O1CN01zV7opv1bIU6iI8OhM_!!6000000003442-2-tps-980-980.png_110x10000.jpg_.webp"],["抠鼻","https://img.alicdn.com/imgextra/i1/O1CN01QOanju1sNqCrtYstu_!!6000000005755-2-tps-980-980.png_110x10000.jpg_.webp"],["叹气","https://img.alicdn.com/imgextra/i3/O1CN01RElx7R1QD1c8ZN07f_!!6000000001941-2-tps-980-980.png_110x10000.jpg_.webp"],["无聊","https://img.alicdn.com/imgextra/i2/O1CN01d91LnZ1UJDQjKCouC_!!6000000002496-2-tps-980-980.png_110x10000.jpg_.webp"],["思考","https://img.alicdn.com/imgextra/i2/O1CN01wQjg2f1tO84ZWitn9_!!6000000005891-2-tps-980-980.png_110x10000.jpg_.webp"],["呆","https://img.alicdn.com/imgextra/i1/O1CN01GLqBWC1DGbhqmpD2L_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["哇哦","https://img.alicdn.com/imgextra/i2/O1CN01MtLpS21qRO2bnAA5k_!!6000000005492-2-tps-980-980.png_110x10000.jpg_.webp"],["飞吻","https://img.alicdn.com/imgextra/i4/O1CN01q1WpFE25ljsNKjvHX_!!6000000007567-2-tps-980-980.png_110x10000.jpg_.webp"],["好喜欢","https://img.alicdn.com/imgextra/i2/O1CN01mD4iQM1O57XyQ5SHD_!!6000000001653-2-tps-980-980.png_110x10000.jpg_.webp"],["拜托","https://img.alicdn.com/imgextra/i4/O1CN01SQgrTH1dzCH3pIyRN_!!6000000003806-2-tps-980-980.png_110x10000.jpg_.webp"],["真棒","https://img.alicdn.com/imgextra/i2/O1CN017fcAmd1SCgYCj9Upk_!!6000000002211-2-tps-980-980.png_110x10000.jpg_.webp"],["流鼻血","https://img.alicdn.com/imgextra/i3/O1CN0139JscY1rC6RS9GR4j_!!6000000005594-2-tps-980-980.png_110x10000.jpg_.webp"],["费解","https://img.alicdn.com/imgextra/i1/O1CN01FqAVvR1tyJMPj13ie_!!6000000005970-2-tps-980-980.png_110x10000.jpg_.webp"],["秃头","https://img.alicdn.com/imgextra/i4/O1CN01ZF4bV11thMhqm2Z1h_!!6000000005933-2-tps-980-980.png_110x10000.jpg_.webp"],["嘿哈","https://img.alicdn.com/imgextra/i4/O1CN01ObcOw61FOVlvQg7Mw_!!6000000000477-2-tps-980-980.png_110x10000.jpg_.webp"],["吃土","https://img.alicdn.com/imgextra/i3/O1CN01Z6nJ1b1ZYr22YseHN_!!6000000003207-2-tps-980-980.png_110x10000.jpg_.webp"],["机智","https://img.alicdn.com/imgextra/i1/O1CN01rfKY351zDUZJlBiir_!!6000000006680-2-tps-980-980.png_110x10000.jpg_.webp"],["举杯","https://img.alicdn.com/imgextra/i4/O1CN01R2tn4F1mn8NuEIE8J_!!6000000004998-2-tps-980-980.png_110x10000.jpg_.webp"],["握手","https://img.alicdn.com/imgextra/i4/O1CN01NDcA251JDkvuFhSDb_!!6000000000995-2-tps-980-980.png_110x10000.jpg_.webp"],["挥手","https://img.alicdn.com/imgextra/i4/O1CN01iVN0ht1TmEuSwauGt_!!6000000002424-2-tps-980-980.png_110x10000.jpg_.webp"],["yeah","https://img.alicdn.com/imgextra/i3/O1CN01opt7hh27Wk8omjR4t_!!6000000007805-2-tps-980-980.png_110x10000.jpg_.webp"],["666","https://img.alicdn.com/imgextra/i3/O1CN01YRWDPF1OjQOpXeuTC_!!6000000001741-2-tps-980-980.png_110x10000.jpg_.webp"],["棒","https://img.alicdn.com/imgextra/i3/O1CN01agprvs1HU7rPRxOnB_!!6000000000760-2-tps-980-980.png_110x10000.jpg_.webp"],["爱你","https://img.alicdn.com/imgextra/i1/O1CN01SzxgcH1GSSo6Lwmwk_!!6000000000621-2-tps-980-980.png_110x10000.jpg_.webp"],["比心","https://img.alicdn.com/imgextra/i1/O1CN01YHZ39t1DeQIeb0TWQ_!!6000000000241-2-tps-980-980.png_110x10000.jpg_.webp"],["感谢","https://img.alicdn.com/imgextra/i3/O1CN01ywacF81baLYNeyK1n_!!6000000003481-2-tps-980-980.png_110x10000.jpg_.webp"],["拍手","https://img.alicdn.com/imgextra/i4/O1CN01wbj4wv1K7ArD9AU44_!!6000000001116-2-tps-980-980.png_110x10000.jpg_.webp"],["拉钩","https://img.alicdn.com/imgextra/i1/O1CN01dePkKH1HOd6ivAcu8_!!6000000000748-2-tps-980-980.png_110x10000.jpg_.webp"],["没钱","https://img.alicdn.com/imgextra/i3/O1CN01qhxGjp1zD2AfqmWx5_!!6000000006679-2-tps-980-980.png_110x10000.jpg_.webp"],["小刀","https://img.alicdn.com/imgextra/i3/O1CN01tFVx5Y1T2thPjhR6b_!!6000000002325-2-tps-980-980.png_110x10000.jpg_.webp"],["不刀","https://img.alicdn.com/imgextra/i4/O1CN01zTxff61clcvOcTS3n_!!6000000003641-2-tps-980-980.png_110x10000.jpg_.webp"],["同出","https://img.alicdn.com/imgextra/i3/O1CN01URKas6249R8ozS98O_!!6000000007348-2-tps-980-980.png_110x10000.jpg_.webp"],["递钱","https://img.alicdn.com/imgextra/i4/O1CN01PzhgV51FLlOaZHZ6n_!!6000000000471-2-tps-980-980.png_110x10000.jpg_.webp"],["数钱","https://img.alicdn.com/imgextra/i3/O1CN01CzXXvp23khkljToQH_!!6000000007294-2-tps-980-980.png_110x10000.jpg_.webp"],["打call","https://img.alicdn.com/imgextra/i1/O1CN01X7VUVm1il48IYv8Qw_!!6000000004452-2-tps-980-980.png_110x10000.jpg_.webp"],["号外","https://img.alicdn.com/imgextra/i2/O1CN01vg6xSM1Vxo9EKyfjR_!!6000000002720-2-tps-980-980.png_110x10000.jpg_.webp"],["包邮","https://img.alicdn.com/imgextra/i3/O1CN01yVS7ys24jA22oVZ2T_!!6000000007426-2-tps-980-980.png_110x10000.jpg_.webp"],["求赞","https://img.alicdn.com/imgextra/i1/O1CN01Xwqi5A1giCQMRcX6N_!!6000000004175-2-tps-980-980.png_110x10000.jpg_.webp"],["非主流","https://img.alicdn.com/imgextra/i1/O1CN013wyI1j1hlEfDUoATI_!!6000000004317-2-tps-980-980.png_110x10000.jpg_.webp"],["吃瓜","https://img.alicdn.com/imgextra/i1/O1CN01LLOFsh1UUCw0deZba_!!6000000002520-2-tps-980-980.png_110x10000.jpg_.webp"],["种草","https://img.alicdn.com/imgextra/i2/O1CN01ooeRC81hA8a4x9S3q_!!6000000004236-2-tps-980-980.png_110x10000.jpg_.webp"],["佛系","https://img.alicdn.com/imgextra/i4/O1CN01BYXEe321GMHMZ9w66_!!6000000006957-2-tps-980-980.png_110x10000.jpg_.webp"],["超便宜","https://img.alicdn.com/imgextra/i4/O1CN01mqgSZi1Er4rOIDiP7_!!6000000000404-2-tps-980-980.png_110x10000.jpg_.webp"],["拥抱","https://img.alicdn.com/imgextra/i1/O1CN01yuGD9c1hJkttfKHAm_!!6000000004257-2-tps-980-980.png_110x10000.jpg_.webp"],["摊手","https://img.alicdn.com/imgextra/i2/O1CN014AiIqE1o9repE6STR_!!6000000005183-2-tps-980-980.png_110x10000.jpg_.webp"],["举手","https://img.alicdn.com/imgextra/i1/O1CN01xizuHZ1WPkJCogbuj_!!6000000002781-2-tps-980-980.png_110x10000.jpg_.webp"],["蹲","https://img.alicdn.com/imgextra/i3/O1CN01Midjjn1FrMj2CWer6_!!6000000000540-2-tps-980-980.png_110x10000.jpg_.webp"],["跪了","https://img.alicdn.com/imgextra/i3/O1CN01F2y52j24E16L6RIjF_!!6000000007358-2-tps-980-980.png_110x10000.jpg_.webp"],["拜","https://img.alicdn.com/imgextra/i4/O1CN01Jldd1G1oXDrEHH2qr_!!6000000005234-2-tps-980-980.png_110x10000.jpg_.webp"],["排","https://img.alicdn.com/imgextra/i3/O1CN01uSUmYD1jD0IJf0UVU_!!6000000004513-2-tps-980-980.png_110x10000.jpg_.webp"],["旺财","https://img.alicdn.com/imgextra/i3/O1CN01A25Mv01DKjGseAmuP_!!6000000000198-2-tps-980-980.png_110x10000.jpg_.webp"],["招财猫","https://img.alicdn.com/imgextra/i3/O1CN01WmJ7Sr20EhDyp86Bd_!!6000000006818-2-tps-980-980.png_110x10000.jpg_.webp"],["酸了","https://img.alicdn.com/imgextra/i3/O1CN01UFgjn61JJi5Iqxdk7_!!6000000001008-2-tps-980-980.png_110x10000.jpg_.webp"],["鸭鸭","https://img.alicdn.com/imgextra/i3/O1CN01pHSCSQ1deaS8WDiqG_!!6000000003761-2-tps-980-980.png_110x10000.jpg_.webp"],["方了","https://img.alicdn.com/imgextra/i3/O1CN01br7g711whlu8xOPUt_!!6000000006340-2-tps-980-980.png_110x10000.jpg_.webp"],["白菜","https://img.alicdn.com/imgextra/i1/O1CN01KABFLt24WKwXjVp08_!!6000000007398-2-tps-980-980.png_110x10000.jpg_.webp"],["桃子","https://img.alicdn.com/imgextra/i1/O1CN01CQhhPH1vJfRjDGBv5_!!6000000006152-2-tps-980-980.png_110x10000.jpg_.webp"],["打包","https://img.alicdn.com/imgextra/i3/O1CN01oYOkUI1VT7c0ivZHV_!!6000000002653-2-tps-980-980.png_110x10000.jpg_.webp"],["沙发","https://img.alicdn.com/imgextra/i4/O1CN018qUFaE1DGbhqpMIit_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["南","https://img.alicdn.com/imgextra/i1/O1CN01ZSA6wg1PEZKf4h99R_!!6000000001809-2-tps-980-980.png_110x10000.jpg_.webp"],["盯","https://img.alicdn.com/imgextra/i4/O1CN01OWB1Gx1s01bzBhHN6_!!6000000005703-2-tps-980-980.png_110x10000.jpg_.webp"],["hot","https://img.alicdn.com/imgextra/i4/O1CN01DDD9uA22cAl7VDH7d_!!6000000007140-2-tps-980-980.png_110x10000.jpg_.webp"],["new","https://img.alicdn.com/imgextra/i3/O1CN01rRJXJo1qwzN4YnOHX_!!6000000005561-2-tps-980-980.png_110x10000.jpg_.webp"],["cool","https://img.alicdn.com/imgextra/i4/O1CN013bUubF2855qb2Qt5l_!!6000000007880-2-tps-980-980.png_110x10000.jpg_.webp"],["1","https://img.alicdn.com/imgextra/i1/O1CN01U8XG5y1Ie22frQHCQ_!!6000000000917-2-tps-980-980.png_110x10000.jpg_.webp"],["可","https://img.alicdn.com/imgextra/i2/O1CN01SMjtPG1iJaN17p94N_!!6000000004392-2-tps-980-980.png_110x10000.jpg_.webp"],["搬砖","https://img.alicdn.com/imgextra/i1/O1CN01GbqW6G1LOrm0Gllcb_!!6000000001290-2-tps-980-980.png_110x10000.jpg_.webp"],["菜狗","https://img.alicdn.com/imgextra/i2/O1CN01VtN0t91USNLmvfmol_!!6000000002516-2-tps-980-980.png_110x10000.jpg_.webp"],["开心面具","https://img.alicdn.com/imgextra/i3/O1CN017elkpk22EoYlBPKd3_!!6000000007089-2-tps-980-980.png_110x10000.jpg_.webp"],["快递","https://img.alicdn.com/imgextra/i2/O1CN01AmUZXk1d3wle5O8IJ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["裂开","https://img.alicdn.com/imgextra/i1/O1CN01BihwvO1a5N9bFt0LU_!!6000000003278-2-tps-980-980.png_110x10000.jpg_.webp"],["啤酒","https://img.alicdn.com/imgextra/i4/O1CN01jDkgEj1WvLdXUVBDx_!!6000000002850-2-tps-980-980.png_110x10000.jpg_.webp"],["瑞思拜","https://img.alicdn.com/imgextra/i4/O1CN011gR0Um1K3VgpYjPOi_!!6000000001108-2-tps-980-980.png_110x10000.jpg_.webp"],["小丑","https://img.alicdn.com/imgextra/i3/O1CN01jMikhO1NJUM15XKTf_!!6000000001549-2-tps-980-980.png_110x10000.jpg_.webp"],["爱心","https://img.alicdn.com/imgextra/i1/O1CN015RVSWf23s25eETJqO_!!6000000007310-2-tps-980-980.png_110x10000.jpg_.webp"]],ge=r=>r,de=new Map(Q0.map(([r,m])=>[r,m])),xe=r=>r.split(/(\[[^\]]+\])/g).map((m,t)=>{const n=m.startsWith("[")?de.get(m.slice(1,-1)):void 0;return n?e.jsx("img",{src:n,alt:m,title:m,className:"mx-0.5 inline-block h-7 w-7 align-middle"},t):e.jsx(ee.Fragment,{children:m},t)}),_e=async r=>b0("/api/v1/accounts/details",void 0,r),U0=async r=>b0("/api/v1/accounts/runtime-status",void 0,r),M0=async(r,m,t,n=!1)=>{const x=await b0("/api/v1/chat/sessions",{account_id:r,cursor:m,refresh:n?1:void 0},n?{timeoutMs:6e4,...t}:t),w=B0(x,["data","result"])||{};return{sessions:w.sessions||[],has_more:w.has_more===!0,next_cursor:w.next_cursor}},A0=async(r,m,t,n,x)=>{const w=await b0("/api/v1/chat/messages",{account_id:r,chat_id:m,cursor:t,before_id:n},x),u=B0(w,["data","result"])||{};return{messages:u.messages||[],has_more:u.has_more===!0,next_cursor:u.next_cursor,session:u.session}},ue=async(r,m)=>J0("/api/v1/chat/messages",r,m),he=async(r,m)=>{const t=new FormData;return Object.entries(r).forEach(([n,x])=>t.append(n,x)),te("/api/v1/chat/images",t,{timeoutMs:12e4,...m})},H0=async(r,m,t,n)=>J0("/api/v1/chat/read",{account_id:r,chat_id:m,message_ids:t},n),F0=(r,m)=>r.filter(t=>t.direction==="incoming"&&t.message_type!=="system"&&!t.message_key.startsWith("in-")).map(t=>({messageId:t.message_key,sessionId:m,cid:`${m}@goofish`,conversationType:1})),be=(r,m,t)=>{const n=m.trim().toLowerCase();return r.filter(x=>t&&x.unread_count<=0?!1:n?[x.buyer_name,x.buyer_id,x.item_title,x.last_message].some(w=>(w||"").toLowerCase().includes(n)):!0)},fe=(r,m)=>{const t=new Set(r.map(n=>n.message_key));return[...m.filter(n=>!t.has(n.message_key)),...r]},q0=(r,m)=>{const t=r.findIndex(n=>n.message_key===m.message_key);return t<0?[...r,m]:r.map((n,x)=>x===t?m:n)},N=(r,m,t)=>r===m&&!t.aborted,P=r=>r instanceof Error&&r.message==="请求已取消",je=r=>{if(!r)return"";const m=new Date(r<1e10?r*1e3:r),t=new Date;return m.toDateString()===t.toDateString()?m.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit",hour12:!1}):m.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"})},we=r=>new Date(r<1e10?r*1e3:r).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}),Ne=()=>{const[r,m]=i.useState([]),[t,n]=i.useState(""),[x,w]=i.useState({}),[u,V]=i.useState(""),[D,S]=i.useState([]),[W,f0]=i.useState(""),[M,j0]=i.useState(!1),[q,c0]=i.useState(""),[w0,T]=i.useState(!0),[A,I]=i.useState(!1),[G,X]=i.useState(!1),[Y,l0]=i.useState(!1),[o0,p0]=i.useState(),[K,H]=i.useState({}),[$,e0]=i.useState({}),[t0,m0]=i.useState(!1),[g0,N0]=i.useState(!1),[y,F]=i.useState(!1),[C0,C]=i.useState(""),[y0,J]=i.useState("connecting"),[B,s0]=i.useState(null),[a,j]=i.useState(null),O=i.useRef(""),Q=i.useRef(""),d0=i.useRef(null),O0=i.useRef({accountID:"",chatID:""}),v0=i.useRef(!0),Z=i.useRef(!1),k0=i.useRef(null),T0=i.useRef(new Set),S0=i.useRef(0),R0=i.useRef(null),L=i.useRef(0),E0=i.useRef(null),U=i.useRef(0),a0=i.useRef(null),i0=i.useRef(0),x0=i.useRef(null),R=i.useRef(0),z=i.useRef(null);i.useEffect(()=>{O.current=t},[t]),i.useEffect(()=>{Q.current=u},[u]);const n0=i.useCallback(async s=>{var l;const o=++S0.current;(l=R0.current)==null||l.abort();const p=new AbortController;R0.current=p;try{const c=await M0(s,void 0,{signal:p.signal},!0);if(!N(S0.current,o,p.signal))return[];const d=c.sessions.map(g=>s===O.current&&g.chat_id===Q.current?{...g,unread_count:0}:g);return w(g=>({...g,[s]:d})),H(g=>({...g,[s]:c.next_cursor})),e0(g=>({...g,[s]:c.has_more})),d}catch(c){return N(S0.current,o,p.signal)&&!P(c)&&C(c instanceof Error?c.message:"同步会话失败"),[]}},[]);i.useEffect(()=>{const s=new AbortController;return(async()=>{var p;T(!0);try{const[l,c]=await Promise.all([_e({signal:s.signal}),U0({signal:s.signal})]),g=l.map(h=>{var v,D0;return{...h,runtime_state:((v=c[h.id])==null?void 0:v.state)||(h.enabled?"connecting":"disabled"),runtime_connected:((D0=c[h.id])==null?void 0:D0.connected)===!0}}).filter(h=>h.enabled),f=await Promise.all(g.map(async h=>[h.id,await M0(h.id,void 0,{signal:s.signal})]));if(s.signal.aborted)return;m(g),w(Object.fromEntries(f.map(([h,v])=>[h,v.sessions]))),H(Object.fromEntries(f.map(([h,v])=>[h,v.next_cursor]))),e0(Object.fromEntries(f.map(([h,v])=>[h,v.has_more])));const _=window.localStorage.getItem("ydisks.chat.account.v1")||"",k=g.some(h=>h.id===_)?_:((p=g[0])==null?void 0:p.id)||"";n(k)}catch(l){s.signal.aborted||C(l instanceof Error?l.message:"加载聊天数据失败")}finally{s.signal.aborted||T(!1)}})(),(()=>s.abort())},[]),i.useEffect(()=>{let s=!1,o=0,p=null;const l=async()=>{p=new AbortController;try{const c=await U0({signal:p.signal,timeoutMs:1e4});s||m(d=>d.map(g=>{var f,_;return{...g,runtime_state:((f=c[g.id])==null?void 0:f.state)||g.runtime_state,runtime_connected:((_=c[g.id])==null?void 0:_.connected)??g.runtime_connected}}))}catch{}finally{s||(o=window.setTimeout(l,3e3))}};return o=window.setTimeout(l,3e3),(()=>{s=!0,window.clearTimeout(o),p==null||p.abort()})},[]),i.useEffect(()=>{if(!t)return;window.localStorage.setItem("ydisks.chat.account.v1",t);const s=x[t]||[];V(o=>{var p;return s.some(l=>l.chat_id===o)?o:((p=s[0])==null?void 0:p.chat_id)||""})},[t,x]),i.useEffect(()=>{!t||T0.current.has(t)||(T0.current.add(t),n0(t))},[t,n0]),i.useEffect(()=>{var p,l;if(!t||!u){L.current+=1,U.current+=1,(p=a0.current)==null||p.abort(),Z.current=!1,S([]);return}const s=++L.current;(l=E0.current)==null||l.abort();const o=new AbortController;return E0.current=o,I(!0),A0(t,u,void 0,void 0,{signal:o.signal}).then(c=>{if(!N(L.current,s,o.signal))return;const d=F0(c.messages,u);H0(t,u,d,{signal:o.signal}),S(c.messages),l0(c.has_more),p0(c.next_cursor),c.session&&w(g=>({...g,[t]:(g[t]||[]).map(f=>{var _;return f.chat_id===((_=c.session)==null?void 0:_.chat_id)?c.session:f})})),w(g=>({...g,[t]:(g[t]||[]).map(f=>f.chat_id===u?{...f,unread_count:0}:f)}))}).catch(c=>{N(L.current,s,o.signal)&&!P(c)&&C(c instanceof Error?c.message:"加载消息失败")}).finally(()=>{N(L.current,s,o.signal)&&I(!1)}),(()=>o.abort())},[t,u]),i.useEffect(()=>{var s;(s=x0.current)==null||s.abort(),i0.current+=1},[t]),i.useEffect(()=>{var s;(s=z.current)==null||s.abort(),R.current+=1},[t,u]),i.useEffect(()=>{var s;U.current+=1,(s=a0.current)==null||s.abort(),Z.current=!1},[t,u]),i.useEffect(()=>(()=>{var s,o,p,l,c;(s=R0.current)==null||s.abort(),(o=E0.current)==null||o.abort(),U.current+=1,(p=a0.current)==null||p.abort(),(l=x0.current)==null||l.abort(),(c=z.current)==null||c.abort()}),[]);const Z0=i.useCallback(async()=>{var d,g;if(!t||!u||G||!Y)return;const s=d0.current,o=(s==null?void 0:s.scrollHeight)||0,p=L.current,l=++U.current;(d=a0.current)==null||d.abort();const c=new AbortController;a0.current=c,Z.current=!0,X(!0),C("");try{const f=(g=D[0])==null?void 0:g.id,_=await A0(t,u,o0,f,{signal:c.signal});if(!N(L.current,p,c.signal)||l!==U.current)return;S(k=>fe(k,_.messages)),l0(_.has_more),p0(_.next_cursor),requestAnimationFrame(()=>{l===U.current&&!c.signal.aborted&&s&&(s.scrollTop+=s.scrollHeight-o)})}catch(f){Z.current=!1,P(f)||C(f instanceof Error?f.message:"加载历史消息失败")}finally{l===U.current&&X(!1)}},[t,u,Y,o0,D,G]);i.useEffect(()=>{let s=!1,o=0,p=0,l=null;const c=()=>{if(s)return;J("connecting");const d=window.location.protocol==="https:"?"wss:":"ws:";l=new WebSocket(`${d}//${window.location.host}/api/v1/chat/ws`),l.onopen=()=>{p=0,J("online")},l.onmessage=g=>{try{const _=JSON.parse(g.data).message;if(!_)return;const k=_.account_id;if(w(h=>{const v=h[k]||[];return v.some(E=>E.chat_id===_.chat_id)?{...h,[k]:v.map(E=>E.chat_id===_.chat_id?{...E,last_message:_.content,last_message_at:_.sent_at,unread_count:_.direction==="incoming"&&_.message_type!=="system"&&(O.current!==k||Q.current!==_.chat_id)?E.unread_count+1:E.unread_count}:E).sort((E,$0)=>$0.last_message_at-E.last_message_at)}:(n0(k),h)}),O.current===k&&Q.current===_.chat_id&&(S(h=>q0(h,_)),_.direction==="incoming"&&_.message_type!=="system")){const h=F0([_],_.chat_id);H0(k,_.chat_id,h)}}catch{}},l.onclose=()=>{if(s)return;J("offline");const g=Math.min(15e3,1e3*2**Math.min(p++,4));o=window.setTimeout(c,g)},l.onerror=()=>l==null?void 0:l.close()};return c(),(()=>{s=!0,window.clearTimeout(o),l==null||l.close()})},[n0]);const z0=i.useCallback(()=>{const s=d0.current;if(!s)return;const o=s.scrollHeight-s.scrollTop-s.clientHeight;v0.current=o<=48},[]);i.useLayoutEffect(()=>{const s=O0.current.accountID!==t||O0.current.chatID!==u;O0.current={accountID:t,chatID:u},s&&(v0.current=!0);const o=d0.current;if(o){if(Z.current){Z.current=!1;return}(A||v0.current)&&(o.scrollTop=o.scrollHeight)}},[t,u,D,A]);const P0=r.find(s=>s.id===t),_0=x[t]||[],b=_0.find(s=>s.chat_id===u),V0=i.useMemo(()=>be(_0,W,M),[_0,W,M]),W0=i.useCallback(s=>(x[s]||[]).reduce((o,p)=>o+p.unread_count,0),[x]),G0=i.useCallback(async()=>{var l;if(!t||t0||!$[t])return;const s=++i0.current;(l=x0.current)==null||l.abort();const o=new AbortController;x0.current=o;const p=t;m0(!0),C("");try{const c=await M0(p,K[p],{signal:o.signal},!0);if(!N(i0.current,s,o.signal))return;w(d=>({...d,[p]:c.sessions})),H(d=>({...d,[p]:c.next_cursor})),e0(d=>({...d,[p]:c.has_more}))}catch(c){N(i0.current,s,o.signal)&&!P(c)&&C(c instanceof Error?c.message:"加载历史联系人失败")}finally{N(i0.current,s,o.signal)&&m0(!1)}},[t,K,t0,$]),u0=i.useCallback(async(s,o)=>{var c;if(!b||!t||y)return;const p=++R.current;(c=z.current)==null||c.abort();const l=new AbortController;z.current=l,F(!0),C("");try{const d=await ue({account_id:t,chat_id:b.chat_id,buyer_id:b.buyer_id,buyer_name:b.buyer_name,item_id:b.item_id,item_title:b.item_title,text:s},{signal:l.signal});if(!N(R.current,p,l.signal))return;c0(""),s0(null),S(g=>q0(g,d.message))}catch(d){N(R.current,p,l.signal)&&(o&&s0(s),P(d)||C(d instanceof Error?d.message:"消息发送失败"))}finally{N(R.current,p,l.signal)&&F(!1)}},[t,b,y]),h0=i.useCallback(async(s,o)=>{var c;if(!b||!t||y)return;const p=++R.current;(c=z.current)==null||c.abort();const l=new AbortController;z.current=l,F(!0),C("");try{const d=await he({account_id:t,chat_id:b.chat_id,buyer_id:b.buyer_id,buyer_name:b.buyer_name,buyer_avatar_url:b.buyer_avatar_url,item_id:b.item_id,item_title:b.item_title,image:s},{signal:l.signal});if(!N(R.current,p,l.signal))return;j(null),S(g=>q0(g,d.message))}catch(d){N(R.current,p,l.signal)&&(o&&j(s),P(d)||C(d instanceof Error?d.message:"图片发送失败"))}finally{N(R.current,p,l.signal)&&(F(!1),k0.current&&(k0.current.value=""))}},[t,b,y]),X0=i.useCallback(async()=>{const s=q.trim();!s||!b||!t||y||await u0(s,!0)},[t,q,b,u0,y]),Y0=i.useCallback(async s=>{!s||!b||!t||y||await h0(s,!0)},[t,b,h0,y]),K0=i.useCallback(async()=>{B?await u0(B,!1):a&&await h0(a,!1)},[a,B,h0,u0]);return{accounts:r,activeAccountID:t,activeSessions:_0,selectedSession:b,activeAccount:P0,messages:D,search:W,unreadOnly:M,draft:q,loading:w0,messagesLoading:A,olderLoading:G,hasOlder:Y,contactsLoading:t0,hasMoreContacts:$[t]===!0,emojiOpen:g0,sending:y,error:C0,liveState:y0,activeChatID:u,filteredSessions:V0,scrollRef:d0,imageInputRef:k0,setActiveAccountID:n,setActiveChatID:V,setSearch:f0,setUnreadOnly:j0,setDraft:c0,setEmojiOpen:N0,reloadSessions:n0,loadMoreContacts:G0,loadOlderMessages:Z0,handleMessageScroll:z0,handleSend:X0,handleImage:Y0,retrySend:K0,retryAvailable:!!(B||a),unreadForAccount:W0,emojiURL:ge,xianyuEmojis:Q0,renderXianyuText:xe,formatClock:je,messageTime:we}},ke=()=>{const{accounts:r,activeAccountID:m,activeChatID:t,activeAccount:n,selectedSession:x,filteredSessions:w,messages:u,search:V,unreadOnly:D,draft:S,loading:W,messagesLoading:f0,olderLoading:M,hasOlder:j0,contactsLoading:q,hasMoreContacts:c0,emojiOpen:w0,sending:T,error:A,liveState:I,scrollRef:G,imageInputRef:X,setActiveAccountID:Y,setActiveChatID:l0,setSearch:o0,setUnreadOnly:p0,setDraft:K,setEmojiOpen:H,reloadSessions:$,loadMoreContacts:e0,loadOlderMessages:t0,handleMessageScroll:m0,handleSend:g0,handleImage:N0,retrySend:y,retryAvailable:F,unreadForAccount:C0,emojiURL:C,xianyuEmojis:y0,renderXianyuText:J,formatClock:B,messageTime:s0}=Ne();return W?e.jsx("div",{className:"flex h-[calc(100vh-4rem)] items-center justify-center",children:e.jsx(r0,{className:"h-8 w-8 animate-spin text-sky-500"})}):e.jsxs("section",{className:"flex h-[calc(100vh-4rem)] min-h-[560px] flex-col overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-chat",children:[e.jsxs("header",{className:"border-b border-slate-200 bg-slate-50/70 px-5 pt-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-black tracking-tight text-slate-950",children:"在线聊天"}),e.jsx("p",{className:"mt-0.5 text-xs font-medium text-slate-500",children:"复用账号实时连接,消息按账号完全隔离"})]}),e.jsxs("div",{className:`flex items-center gap-2 rounded-full px-3 py-1.5 text-xs font-bold ${I==="online"?"bg-emerald-50 text-emerald-700":I==="connecting"?"bg-amber-50 text-amber-700":"bg-red-50 text-red-700"}`,children:[I==="online"?e.jsx(se,{className:"h-3.5 w-3.5"}):e.jsx(ae,{className:"h-3.5 w-3.5"}),I==="online"?"实时同步中":I==="connecting"?"正在连接":"连接已断开"]})]}),e.jsx("div",{className:"flex gap-1 overflow-x-auto pb-0",role:"tablist","aria-label":"聊天账号",children:r.map(a=>{const j=a.id===m,O=C0(a.id),Q=a.runtime_state==="online";return e.jsxs("button",{type:"button",role:"tab","aria-selected":j,onClick:(()=>Y(a.id)),className:`relative flex h-11 shrink-0 items-center gap-2 border-b-2 px-3 text-sm font-extrabold transition-colors ${j?"border-sky-500 text-sky-700":"border-transparent text-slate-500 hover:text-slate-900"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${Q?"bg-emerald-500":"bg-slate-300"}`}),e.jsx("span",{className:"max-w-36 truncate",children:a.nickname||a.remark||a.id}),O>0&&e.jsx("span",{className:"min-w-5 rounded-full bg-red-500 px-1.5 py-0.5 text-[10px] text-white",children:O>99?"99+":O})]},a.id)})})]}),r.length===0?e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(L0,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-800",children:"暂无启用账号"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"先在账号管理中启用账号,聊天会话会自动出现。"})]}):e.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden grid-cols-[320px_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"flex min-h-0 flex-col border-r border-slate-200 bg-slate-50/40",children:[e.jsxs("div",{className:"space-y-3 border-b border-slate-200 p-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ie,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx("input",{value:V,onChange:(a=>o0(a.target.value)),placeholder:"搜索用户、商品或消息",className:"h-10 w-full rounded-xl border border-slate-200 bg-white pl-9 pr-3 text-sm outline-none transition focus:border-sky-400 focus:ring-2 focus:ring-sky-100"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:(()=>p0(a=>!a)),className:`rounded-lg px-2.5 py-1.5 text-xs font-bold ${D?"bg-sky-100 text-sky-700":"text-slate-500 hover:bg-slate-100"}`,children:D?"只看未读":"全部会话"}),e.jsx("button",{type:"button",title:"刷新会话",onClick:(()=>void $(m)),className:"rounded-lg p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700",children:e.jsx(ne,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[w.map(a=>e.jsxs("button",{type:"button",onClick:(()=>l0(a.chat_id)),className:`flex w-full gap-3 border-b border-slate-100 p-4 text-left transition-colors ${a.chat_id===t?"bg-white shadow-chat-active":"hover:bg-white/80"}`,children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-full bg-slate-200 text-slate-500",children:a.buyer_avatar_url?e.jsx("img",{src:a.buyer_avatar_url,alt:"",className:"h-full w-full object-cover"}):e.jsx(I0,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-extrabold text-slate-900",children:a.buyer_name||`用户 ${a.buyer_id}`}),e.jsx("span",{className:"ml-auto shrink-0 text-[10px] font-medium text-slate-400",children:B(a.last_message_at)})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-xs text-slate-500",children:a.last_message||"暂无消息"}),a.unread_count>0&&e.jsx("span",{className:"ml-auto min-w-5 shrink-0 rounded-full bg-red-500 px-1.5 py-0.5 text-center text-[10px] font-bold text-white",children:a.unread_count})]}),a.item_title&&e.jsxs("div",{className:"mt-1.5 truncate text-[10px] font-medium text-sky-700",children:["商品 · ",a.item_title]})]})]},a.chat_id)),w.length===0&&e.jsx("div",{className:"px-6 py-16 text-center text-sm text-slate-400",children:"当前账号暂无匹配会话"}),c0&&!V&&!D&&e.jsx("div",{className:"flex justify-center p-4",children:e.jsxs("button",{type:"button",onClick:(()=>void e0()),disabled:q,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-2 text-xs font-bold text-slate-500 shadow-sm hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[q&&e.jsx(r0,{className:"h-3.5 w-3.5 animate-spin"}),q?"正在加载":"加载更多历史联系人"]})})]})]}),e.jsx("main",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-surface-subtle",children:x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-16 shrink-0 items-center border-b border-slate-200 bg-white px-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-black text-slate-950",children:x.buyer_name||x.buyer_id}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-slate-500",children:["用户 ID:",x.buyer_id]})]}),e.jsx("span",{className:`ml-auto rounded-full px-2.5 py-1 text-[10px] font-bold ${(n==null?void 0:n.runtime_state)==="online"?"bg-emerald-50 text-emerald-700":"bg-slate-100 text-slate-500"}`,children:(n==null?void 0:n.runtime_state)==="online"?"账号在线":"账号离线"})]}),e.jsx("div",{ref:G,onScroll:m0,className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:f0?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(r0,{className:"h-6 w-6 animate-spin text-sky-500"})}):e.jsxs(e.Fragment,{children:[j0&&e.jsx("div",{className:"flex justify-center pb-1",children:e.jsxs("button",{type:"button",onClick:(()=>void t0()),disabled:M,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-1.5 text-xs font-bold text-slate-500 shadow-sm transition hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[M&&e.jsx(r0,{className:"h-3.5 w-3.5 animate-spin"}),M?"正在加载":"加载更早消息"]})}),u.map(a=>{const j=a.direction==="outgoing";return a.message_type==="system"?e.jsx("div",{className:"flex justify-center py-1",children:e.jsxs("div",{className:"max-w-[82%] rounded-xl border border-slate-200 bg-slate-100 px-4 py-2 text-center text-xs leading-5 text-slate-500",children:[J(a.content),e.jsx("div",{className:"mt-1 text-[10px] text-slate-400",children:s0(a.sent_at)})]})},a.message_key):e.jsxs("div",{className:`flex items-end gap-2.5 ${j?"justify-end":"justify-start"}`,children:[!j&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-slate-200 ring-2 ring-white",children:x.buyer_avatar_url?e.jsx("img",{src:x.buyer_avatar_url,alt:x.buyer_name||"用户",className:"h-full w-full object-cover"}):e.jsx(I0,{className:"m-2 h-5 w-5 text-slate-500"})}),e.jsxs("div",{className:`max-w-[72%] ${j?"items-end":"items-start"} flex flex-col`,children:[e.jsx("div",{className:"mb-1 px-1 text-[10px] font-semibold text-slate-400",children:j?(n==null?void 0:n.nickname)||(n==null?void 0:n.remark)||"我":x.buyer_name||a.sender_name||x.buyer_id}),a.message_type==="image"?e.jsx("a",{href:a.content,target:"_blank",rel:"noreferrer",className:`block overflow-hidden rounded-2xl border bg-white p-1 shadow-sm ${j?"rounded-br-md border-sky-200":"rounded-bl-md border-slate-200"}`,children:e.jsx("img",{src:a.content,alt:"聊天图片",className:"max-h-80 max-w-full rounded-xl object-contain"})}):a.message_type==="video"?e.jsx("video",{src:a.content,controls:!0,preload:"metadata",className:"max-h-80 max-w-full rounded-2xl bg-black"}):e.jsx("div",{className:`rounded-2xl px-4 py-2.5 text-sm leading-6 shadow-sm ${j?"rounded-br-md bg-sky-500 text-white":"rounded-bl-md border border-slate-200 bg-white text-slate-800"}`,children:J(a.content)}),e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] text-slate-400",children:[s0(a.sent_at),j&&(a.status==="failed"?e.jsx(re,{className:"h-3 w-3 text-red-500"}):a.status==="sent"?e.jsx(ce,{className:"h-3 w-3 text-sky-500"}):e.jsx(le,{className:"h-3 w-3"}))]})]}),j&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-sky-100 ring-2 ring-white",children:n!=null&&n.avatar_url?e.jsx("img",{src:n.avatar_url,alt:"我",className:"h-full w-full object-cover"}):e.jsx(I0,{className:"m-2 h-5 w-5 text-sky-600"})})]},a.message_key)})]})}),A&&e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-red-100 bg-red-50 px-5 py-2 text-xs font-medium text-red-700",children:[e.jsx("span",{children:A}),F&&e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>void y()),children:"重试发送"})]}),e.jsxs("div",{className:"relative z-10 shrink-0 border-t border-slate-200 bg-white p-4 shadow-chat-input",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1",children:[e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:(()=>H(a=>!a)),disabled:T||(n==null?void 0:n.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"闲鱼表情",children:e.jsx(oe,{className:"h-5 w-5"})}),w0&&e.jsxs("div",{className:"absolute bottom-11 left-0 z-30 w-[360px] rounded-2xl border border-slate-200 bg-white p-3 shadow-2xl",children:[e.jsx("div",{className:"mb-2 text-xs font-bold text-slate-500",children:"全部表情"}),e.jsx("div",{className:"grid max-h-72 grid-cols-8 gap-1 overflow-y-auto",children:y0.map(([a,j])=>e.jsx("button",{type:"button",title:`[${a}]`,onClick:(()=>{K(O=>O+`[${a}]`),H(!1)}),className:"flex h-10 w-10 items-center justify-center rounded-lg hover:bg-slate-100",children:e.jsx("img",{src:C(j),alt:`[${a}]`,className:"h-8 w-8 object-contain"})},a))})]})]}),e.jsx("input",{ref:X,type:"file",accept:"image/*",className:"hidden",onChange:(a=>{var j;return void N0((j=a.target.files)==null?void 0:j[0])})}),e.jsx("button",{type:"button",onClick:(()=>{var a;return(a=X.current)==null?void 0:a.click()}),disabled:T||(n==null?void 0:n.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 transition hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"发送图片(最大 10MB)",children:e.jsx(pe,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"flex items-end gap-3 rounded-2xl border border-slate-200 bg-slate-50 p-2 transition focus-within:border-sky-400 focus-within:ring-2 focus-within:ring-sky-100",children:[e.jsx("textarea",{value:S,onChange:(a=>K(a.target.value)),rows:2,maxLength:2e3,onKeyDown:(a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),g0())}),disabled:(n==null?void 0:n.runtime_state)!=="online",placeholder:(n==null?void 0:n.runtime_state)==="online"?"输入消息,Enter 发送,Shift + Enter 换行":"账号离线,暂时无法发送",className:"max-h-32 min-h-12 flex-1 resize-none bg-transparent px-2 py-2 text-sm leading-6 outline-none disabled:cursor-not-allowed"}),e.jsx("button",{type:"button",onClick:(()=>void g0()),disabled:!S.trim()||T||(n==null?void 0:n.runtime_state)!=="online",className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-sky-500 text-white shadow-md shadow-sky-100 transition hover:bg-sky-600 disabled:cursor-not-allowed disabled:bg-slate-300 disabled:shadow-none","aria-label":"发送消息",children:T?e.jsx(r0,{className:"h-4 w-4 animate-spin"}):e.jsx(me,{className:"h-4 w-4"})})]})]})]}):e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(L0,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-700",children:"选择一个用户开始聊天"}),e.jsx("p",{className:"mt-1 text-sm text-slate-400",children:"该账号的新消息会实时出现在左侧列表。"})]})})]})]})};export{ke as default};
diff --git a/internal/webui/static/assets/Dashboard-MmgsZAic.js b/internal/webui/static/assets/Dashboard-Di77mWD7.js
similarity index 99%
rename from internal/webui/static/assets/Dashboard-MmgsZAic.js
rename to internal/webui/static/assets/Dashboard-Di77mWD7.js
index 22cfcbf..aa341c6 100644
--- a/internal/webui/static/assets/Dashboard-MmgsZAic.js
+++ b/internal/webui/static/assets/Dashboard-Di77mWD7.js
@@ -1 +1 @@
-import{r as c,j as e}from"./react-vendor-C_od1ZSF.js";import{f as me}from"./dateTime-DDi7rqpW.js";import{g as q}from"./index-hByDAHGj.js";import{c as de,o as ge}from"./contract-COFcZjyb.js";import{j as xe,k as he,l as te,D as pe,c as be,P as fe,m as se,E as ye,T as je}from"./icons-vendor-CvzvbbIV.js";import{R as E,B as ve,X as ae,Y as re,T as F,a as Ne,C as U,A as we,b as _e,c as ke,P as ne,d as le,L as De}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";const M=t=>{const a=t.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0");return`${a}-${s}-${l}`},H=(t,a)=>{const s=new Date(t);return s.setHours(12,0,0,0),s.setDate(s.getDate()+a),s},X=(t,a)=>({startDate:M(H(t,-(a-1))),endDate:M(t)}),ue=(t,a=new Date,s="",l="")=>{if(t==="custom"&&s&&l){if(s>l)throw new Error("开始日期不能晚于结束日期");return{startDate:s,endDate:l}}return t==="yesterday"?X(H(a,-1),1):X(a,t==="3days"?3:t==="30days"?30:t==="today"?1:7)},Se=t=>{const a=new Date(`${t.startDate}T12:00:00`),s=new Date(`${t.endDate}T12:00:00`),l=Math.round((s.getTime()-a.getTime())/864e5)+1,n=H(a,-1);return X(n,l)},Ce=t=>{const a={};return t.forEach(s=>{a[s.item_id]=s.item_title||s.item_id}),a},$e=t=>{var a;return((a=t.daily_stats)==null?void 0:a.map(s=>({name:s.date.slice(5),amount:s.amount,orders:s.order_count,avgAmount:s.order_count>0?(s.amount/s.order_count).toFixed(2):0})))||[]},Re=(t,a)=>(t.item_stats||[]).map(s=>{const l=a[s.item_id]||s.item_id;return{name:l.length>12?`${l.substring(0,12)}...`:l,sales:s.order_count}}).sort((s,l)=>l.sales-s.sales).slice(0,10),Le=(t,a,s)=>{const l=t.revenue_stats.total_orders||0;return(t.item_stats||[]).map(n=>{const o=a[n.item_id]||n.item_id;return{name:o.length>10?`${o.substring(0,10)}...`:o,value:n.order_count,percent:l>0?n.order_count/l*100:0}}).sort((n,o)=>o.value-n.value).slice(0,6).map((n,o)=>({...n,color:s[o%s.length]}))},Ae=(t,a,s)=>{const l=t.revenue_stats.total_amount||0;return(t.item_stats||[]).map(n=>{const o=a[n.item_id]||n.item_id;return{name:o.length>12?`${o.substring(0,12)}...`:o,value:n.total_amount,orderCount:n.order_count,percentage:l>0?n.total_amount/l*100:0}}).sort((n,o)=>o.value-n.value).slice(0,5).map((n,o)=>({...n,color:s[o%s.length],percentage:n.percentage.toFixed(1)}))},Oe=(t,a)=>{if(!t||!a)return null;const s=t.revenue_stats.total_amount,l=a.revenue_stats.total_amount;if(l===0)return s>0?"+100%":"0%";const n=(s-l)/l*100;return`${n>=0?"+":""}${n.toFixed(1)}%`},Te=t=>({today:"今天",yesterday:"昨天","3days":"三天内","7days":"7天内","30days":"一个月内",custom:"自定义"})[t.range]||"所选范围",ze=t=>Math.max(...t.map(a=>a.sales),1),P=(t,a,s)=>t===a&&!s.aborted,oe=t=>{const a=String(t||"");return a==="paid"?"pending_ship":["processing","pending_ship","shipped","completed","cancelled","refunding"].includes(a)?a:"unknown"},Pe=async t=>q("/api/v1/analytics/dashboard",void 0,t),We=async(t,a)=>{const s=await q("/api/v1/items",void 0,a);return de(s,["items","data","results"]).map(n=>({...n,id:n.id||`${n.cookie_id}-${n.item_id}`,is_multi_spec:n.is_multi_spec===!0||n.is_multi_spec===1,multi_quantity_delivery:n.multi_quantity_delivery===!0||n.multi_quantity_delivery===1}))},ie=async(t=7,a)=>{let s;if(typeof t=="number"){const l=new Date,n=new Date;n.setDate(n.getDate()-t),s={start_date:M(n),end_date:M(l)}}else s=t;return q("/api/v1/analytics/orders",{...s,timezone_offset_minutes:-new Date().getTimezoneOffset()},a)},Ee=async(t,a)=>{const s=await q("/api/v1/analytics/orders/valid",{...t,timezone_offset_minutes:-new Date().getTimezoneOffset()},a),l=ge(s,["data","result"])||{},o=de(s,["orders","data","items"]).map(b=>({...b,id:b.order_id,status:oe(b.status||b.order_status),order_status:oe(b.order_status),quantity:Number(b.quantity||1)}));return{orders:o,total:Number(l.total??o.length),truncated:l.truncated===!0}},ce=t=>t instanceof Error&&t.message==="请求已取消",G=(t,a)=>t instanceof Error?t.message:a,Fe=t=>{const{range:a,customStartDate:s,customEndDate:l,customRangeVersion:n}=t,[o,b]=c.useState(null),[_,I]=c.useState(null),[K,v]=c.useState({overview:"idle",range:"idle",error:""}),[d,T]=c.useState(0),R=c.useRef(0),S=c.useRef(0),L=c.useMemo(()=>({range:a,customStartDate:s,customEndDate:l}),[l,s,a]),D=c.useCallback(()=>T(u=>u+1),[]);c.useEffect(()=>{const u=++S.current,h=new AbortController;return v(m=>({...m,overview:"loading",error:""})),Promise.all([Pe({signal:h.signal}),We(void 0,{signal:h.signal})]).then(([m,g])=>{P(S.current,u,h.signal)&&(b({stats:m,items:g,itemNames:Ce(g)}),v(p=>({...p,overview:"success"})))}).catch(m=>{!P(S.current,u,h.signal)||ce(m)||v(g=>({...g,overview:"error",error:G(m,"概览加载失败")}))}),(()=>h.abort())},[d]),c.useEffect(()=>{let u;try{u=ue(a,new Date,s,l)}catch(p){v(w=>({...w,range:"error",error:G(p,"日期范围无效")}));return}const h=Se(u),m=++R.current,g=new AbortController;return v(p=>({...p,range:"loading",error:""})),Promise.all([ie({start_date:u.startDate,end_date:u.endDate},{signal:g.signal}),ie({start_date:h.startDate,end_date:h.endDate},{signal:g.signal}),Ee({start_date:u.startDate,end_date:u.endDate},{signal:g.signal})]).then(([p,w,Y])=>{P(R.current,m,g.signal)&&(I({analytics:p,previousAnalytics:w,validOrders:Y,dateRange:u}),v($=>({...$,range:"success"})))}).catch(p=>{!P(R.current,m,g.signal)||ce(p)||v(w=>({...w,range:"error",error:G(p,"经营数据加载失败")}))}),(()=>g.abort())},[n,a,d]);const C=c.useMemo(()=>o&&_?{...o,..._}:null,[o,_]),k=(o==null?void 0:o.itemNames)||{},x=(_==null?void 0:_.analytics)||null,z=c.useMemo(()=>x?$e(x):[],[x]),N=c.useMemo(()=>x?Re(x,k):[],[x,k]),f=c.useMemo(()=>["rgb(var(--color-brand))","rgb(var(--color-brand-highlight))","rgb(var(--color-success-500))","rgb(var(--color-warning-500))","rgb(var(--color-accent-500))"],[]),A=c.useMemo(()=>x?Le(x,k,f):[],[x,f,k]),B=c.useMemo(()=>x?Ae(x,k,f):[],[x,f,k]),V=c.useMemo(()=>ze(N),[N]);return{data:C,status:K,chartData:z,productSalesData:N,sourceData:A,categoryData:B,maxProductSales:V,trendPercent:Oe(x,(C==null?void 0:C.previousAnalytics)||null),selectedRangeLabel:Te(L),refresh:D}},i=(t,a)=>a===void 0?`rgb(var(--color-${t}))`:`rgb(var(--color-${t}) / ${a})`,Me=({chartData:t,selectedRangeLabel:a,totalAmount:s})=>e.jsxs("div",{className:"ios-card p-8 rounded-xl",children:[e.jsxs("div",{className:"mb-10",children:[e.jsx("h3",{className:"text-xl font-bold text-gray-900",children:"营收趋势分析"}),e.jsxs("p",{className:"text-sm text-gray-400 mt-1",children:[a,"的销售额走势"]})]}),e.jsx("div",{className:"dashboard-revenue-chart h-[350px] w-full",children:t.length===0||s===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[e.jsx(xe,{className:"w-16 h-16 mb-4 opacity-20"}),e.jsx("p",{className:"text-lg font-medium",children:"暂无营收数据"}),e.jsx("p",{className:"text-sm mt-2",children:"所选时间范围内暂无订单记录"})]}):t.length<=2?e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(ve,{data:t,margin:{top:30,right:20,left:0,bottom:30},barCategoryGap:"45%",children:[e.jsx(ae,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:i("neutral-700"),fontSize:14,fontWeight:600},dy:10}),e.jsx(re,{axisLine:!1,tickLine:!1,tick:{fill:i("neutral-400"),fontSize:13,fontWeight:500},tickFormatter:(l=>`¥${l}`)}),e.jsx(F,{contentStyle:{backgroundColor:i("white"),borderRadius:"8px",border:`1px solid ${i("neutral-200")}`,boxShadow:"var(--shadow-xl)",padding:"12px 16px"},labelStyle:{color:i("neutral-500"),fontWeight:500},itemStyle:{color:i("brand"),fontWeight:600},cursor:{fill:i("brand",.08)},formatter:(l=>[`¥${Number(l).toFixed(2)}`,"营收"])}),e.jsx(Ne,{dataKey:"amount",fill:i("brand"),maxBarSize:72,radius:[12,12,0,0],activeBar:!1,stroke:"none",strokeWidth:0,children:t.map((l,n)=>e.jsx(U,{fill:i("brand"),stroke:"none",strokeWidth:0},`cell-${n}`))})]})}):e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(we,{data:t,margin:{top:10,right:10,left:-20,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"colorAmount",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:i("brand"),stopOpacity:.5}),e.jsx("stop",{offset:"95%",stopColor:i("brand"),stopOpacity:0})]})}),e.jsx(ae,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:i("neutral-400"),fontSize:13,fontWeight:500},dy:15}),e.jsx(re,{axisLine:!1,tickLine:!1,tick:{fill:i("neutral-400"),fontSize:13,fontWeight:500}}),e.jsx(_e,{vertical:!1,stroke:i("neutral-100"),strokeDasharray:"3 3"}),e.jsx(F,{contentStyle:{backgroundColor:i("white"),borderRadius:"8px",border:`1px solid ${i("neutral-200")}`,boxShadow:"var(--shadow-xl)",padding:"12px 16px"},labelStyle:{color:i("neutral-500"),fontWeight:500},itemStyle:{color:i("brand"),fontWeight:600},cursor:{stroke:i("brand"),strokeWidth:2,strokeDasharray:"4 4"}}),e.jsx(ke,{type:"monotone",dataKey:"amount",stroke:i("brand"),strokeWidth:4,fillOpacity:1,fill:"url(#colorAmount)",activeDot:{r:8,fill:i("white"),stroke:i("brand"),strokeWidth:2}})]})})})]}),j=(t,a)=>`rgb(var(--color-${t}))`,qe=({status:t})=>{const a={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},s={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`inline-flex items-center justify-center whitespace-nowrap px-3 py-1.5 rounded-lg text-xs leading-none font-bold ${a[t]||a.cancelled}`,children:s[t]||t})},W=({title:t,value:a,icon:s,colorClass:l,trend:n})=>e.jsxs("div",{className:"ios-card p-6 rounded-xl flex flex-col justify-between hover:translate-y-[-4px] transition-all duration-300 h-full relative overflow-hidden group border-0",children:[e.jsx("div",{className:`absolute -right-6 -top-6 w-32 h-32 ${l} opacity-10 rounded-full group-hover:scale-125 transition-transform duration-500 blur-2xl`}),e.jsxs("div",{className:"flex justify-between items-start mb-6",children:[e.jsx("div",{className:`p-4 rounded-2xl ${l} bg-opacity-10 backdrop-blur-sm`,children:e.jsx(s,{className:`w-6 h-6 ${l.replace("bg-","text-")}`})}),n&&e.jsxs("span",{className:"text-xs font-bold text-white bg-brand px-3 py-1.5 rounded-full flex items-center gap-1 shadow-sm",children:[e.jsx(je,{className:"w-3 h-3"})," ",n]})]}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("h3",{className:"text-3xl font-extrabold text-gray-900 tracking-tight font-feature-settings-tnum",children:a}),e.jsx("p",{className:"text-gray-500 text-sm font-medium mt-1",children:t})]})]}),Xe=()=>{const[t,a]=c.useState("7days"),[s,l]=c.useState(""),[n,o]=c.useState(""),[b,_]=c.useState(""),[I,K]=c.useState(0),v=Fe({range:t,customStartDate:s,customEndDate:n,customRangeVersion:I}),{data:d,status:T,chartData:R,productSalesData:S,sourceData:L,categoryData:D,maxProductSales:C,trendPercent:k,selectedRangeLabel:x,refresh:z}=v,N=(d==null?void 0:d.stats)||null,f=(d==null?void 0:d.analytics)||null;d!=null&&d.previousAnalytics;const A=(d==null?void 0:d.validOrders.orders)||[],B=(d==null?void 0:d.validOrders.total)||0,V=(d==null?void 0:d.validOrders.truncated)||!1,u=T.range==="loading",h=T.error,m=[j("brand"),j("brand-highlight"),j("success-500"),j("warning-500"),j("accent-500")],g=r=>`¥${Number(r||0).toLocaleString("zh-CN",{maximumFractionDigits:2})}`;if(h&&(!N||!f))return e.jsxs("div",{className:"p-8 flex flex-col items-center gap-3 text-red-600",children:[e.jsx(he,{className:"w-8 h-8"}),e.jsx("span",{children:h}),e.jsx("button",{type:"button",className:"ios-btn-primary px-4 py-2 rounded-xl",onClick:z,children:"重新加载"})]});if(!N||!f)return e.jsx("div",{className:"p-8 flex justify-center text-gray-400",children:e.jsx(te,{className:"w-8 h-8 animate-spin text-brand"})});const p=f.revenue_stats.total_orders||0,w=f.revenue_stats.total_amount||0,Y=[{key:"today",label:"今天"},{key:"yesterday",label:"昨天"},{key:"3days",label:"三天内"},{key:"7days",label:"7天内"},{key:"30days",label:"一个月内"},{key:"custom",label:"自定义"}];let $;try{$=ue(t,new Date,s,n)}catch{$={startDate:s,endDate:n}}const O=b.trim().toLowerCase(),J=A.filter(r=>{var y,Q,Z,ee;return((y=r.order_id)==null?void 0:y.toLowerCase().includes(O))||((Q=r.item_id)==null?void 0:Q.toLowerCase().includes(O))||((Z=r.item_title)==null?void 0:Z.toLowerCase().includes(O))||((ee=r.buyer_id)==null?void 0:ee.toLowerCase().includes(O))});return e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[h&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:h}),e.jsx("button",{type:"button",className:"font-bold underline",onClick:z,children:"重试"})]}),e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"运营概览"}),e.jsx("p",{className:"text-gray-500 mt-2 text-base",children:"欢迎回来,以下是闲鱼店铺的实时经营数据。"})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"text-sm font-bold text-gray-700 bg-white px-5 py-2.5 rounded-full shadow-sm border border-gray-100 flex items-center gap-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 bg-green-500 rounded-full animate-pulse"}),"系统正常运行"]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[Y.map(r=>e.jsx("button",{onClick:(()=>a(r.key)),className:`px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${t===r.key?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:r.label},r.key)),t==="custom"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"date",value:s,onChange:(r=>l(r.target.value)),className:"px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-brand"}),e.jsx("span",{className:"self-center text-gray-400",children:"-"}),e.jsx("input",{type:"date",value:n,onChange:(r=>o(r.target.value)),className:"px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-brand"}),e.jsx("button",{onClick:(()=>K(r=>r+1)),className:"px-4 py-2 rounded-xl text-sm font-bold bg-black text-white hover:bg-gray-800 transition-colors",children:"应用"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsx(W,{title:"累计营收 (CNY)",value:`¥${f.revenue_stats.total_amount.toLocaleString("zh-CN",{minimumFractionDigits:2})}`,icon:pe,colorClass:"bg-blue-400",trend:k||void 0}),e.jsx(W,{title:"活跃账号 / 总数",value:`${N.active_cookies} / ${N.total_cookies}`,icon:be,colorClass:"bg-blue-500"}),e.jsx(W,{title:"订单数",value:f.revenue_stats.total_orders.toLocaleString(),icon:xe,colorClass:"bg-blue-500"}),e.jsx(W,{title:"库存卡密余量",value:N.available_card_stock,icon:fe,colorClass:"bg-purple-500"})]}),e.jsx(Me,{chartData:R,selectedRangeLabel:x,totalAmount:w}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"ios-card p-6 rounded-xl",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900 mb-6",children:"商品销量排行"}),e.jsx("div",{className:"h-[280px]",children:S.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:"暂无数据"}):e.jsx("div",{className:"h-full space-y-4 overflow-y-auto pr-2",children:S.map((r,y)=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:`w-7 h-7 rounded-xl flex items-center justify-center text-xs font-extrabold ${y<3?"bg-blue-600 text-white":"bg-gray-100 text-gray-500"}`,children:y+1}),e.jsx("span",{className:"font-bold text-gray-800 text-sm truncate",children:r.name})]}),e.jsxs("span",{className:"font-mono text-sm font-extrabold text-gray-900",children:[r.sales," 单"]})]}),e.jsx("div",{className:"h-3 rounded-full bg-gray-100 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-brand",style:{width:`${Math.max(8,r.sales/C*100)}%`}})})]},`${r.name}-${y}`))})})]}),e.jsxs("div",{className:"ios-card p-6 rounded-xl",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900 mb-6",children:"商品下单占比"}),e.jsx("div",{className:"dashboard-pie-chart h-[280px] relative",role:"img","aria-label":`商品下单占比,共 ${p} 单`,children:L.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:"暂无数据"}):e.jsxs(e.Fragment,{children:[e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(ne,{accessibilityLayer:!1,children:[e.jsx(le,{data:L,cx:"50%",cy:"45%",innerRadius:60,outerRadius:90,paddingAngle:2,dataKey:"value",activeShape:{outerRadius:96,stroke:"none",strokeWidth:0},rootTabIndex:-1,label:!1,labelLine:!1,children:L.map((r,y)=>e.jsx(U,{fill:r.color},`cell-${y}`))}),e.jsx(F,{formatter:(r=>`${Number(r||0)} 单`),wrapperStyle:{zIndex:30,outline:"none"},contentStyle:{backgroundColor:j("white"),border:`1px solid ${j("neutral-200")}`,borderRadius:"10px",boxShadow:"var(--shadow-md)"}}),e.jsx(De,{verticalAlign:"bottom",height:36,iconType:"circle",formatter:(r=>e.jsx("span",{style:{color:j("neutral-500"),fontWeight:500},children:r}))})]})}),e.jsxs("div",{className:"pointer-events-none absolute inset-0 z-10 flex flex-col items-center justify-center pb-9",children:[e.jsx("span",{className:"text-2xl font-extrabold text-gray-900 tabular-nums",children:p}),e.jsx("span",{className:"text-xs font-medium text-gray-400 mt-0.5",children:"总订单"})]})]})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsxs("div",{className:"lg:col-span-2 ios-card p-0 rounded-xl border-0 bg-white overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-gray-50 flex justify-between items-center bg-surface-muted",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900",children:"参与统计的订单"}),V&&e.jsxs("p",{className:"text-xs text-amber-700 mt-1",children:["当前显示最近 ",A.length," / ",B," 条,搜索仅覆盖已加载明细。"]})]}),e.jsx("div",{className:"relative",children:e.jsx("input",{placeholder:"搜索订单号/商品/买家...",value:b,onChange:(r=>_(r.target.value)),className:"pl-4 pr-4 py-2 rounded-xl bg-white border border-gray-100 text-sm focus:border-blue-400 outline-none w-48",type:"text"})})]}),e.jsx("div",{className:"overflow-x-auto flex-1 max-h-[400px]",children:u?e.jsxs("div",{className:"flex items-center justify-center py-20 text-gray-400",children:[e.jsx(te,{className:"w-6 h-6 animate-spin mr-2"}),"加载中..."]}):J.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-8 text-center",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gray-100 flex items-center justify-center mb-4",children:e.jsx(se,{className:"w-7 h-7 text-gray-300"})}),O?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"没有匹配的订单"}),e.jsxs("div",{className:"text-xs text-gray-400 mt-2 max-w-md",children:["当前共有 ",A.length," 单参与统计,但没有订单号、商品、买家匹配“",b,"”。"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"当前范围内没有参与统计的订单"}),e.jsxs("div",{className:"text-xs text-gray-400 mt-2 max-w-lg leading-6",children:["日期范围:",$.startDate," 至 ",$.endDate,"; 统计口径:待发货、已发货、已完成,且订单金额不为空。 当前统计卡片订单数:",f.revenue_stats.total_orders," 单。"]})]})]}):e.jsxs("table",{className:"w-full min-w-[760px] text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"px-6 py-4",children:"订单信息"}),e.jsx("th",{className:"px-6 py-4",children:"买家信息"}),e.jsx("th",{className:"px-6 py-4",children:"金额"}),e.jsx("th",{className:"px-6 py-4 whitespace-nowrap",children:"状态"}),e.jsx("th",{className:"px-6 py-4 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:J.map(r=>e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gray-100 overflow-hidden shadow-sm border border-gray-100 flex-shrink-0",children:e.jsx(se,{className:"w-full h-full text-gray-300 p-2"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm line-clamp-1",children:r.item_title||r.item_id||"未知商品"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 font-mono",children:r.order_id}),e.jsxs("div",{className:"text-xs text-gray-400 mt-0.5",children:["数量: ",r.quantity||1]})]})]})}),e.jsxs("td",{className:"px-6 py-4",children:[e.jsx("div",{className:"text-sm font-bold text-gray-800",children:r.buyer_id}),r.created_at&&e.jsx("div",{className:"text-xs text-gray-400 mt-1",children:me(r.created_at)})]}),e.jsxs("td",{className:"px-6 py-4 text-base font-extrabold text-gray-900 font-feature-settings-tnum",children:["¥",r.amount||"0.00"]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx(qe,{status:r.status||r.order_status||"unknown"})}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsx("a",{href:`https://www.goofish.com/order-detail?orderId=${r.order_id}&role=seller`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看闲鱼详情",children:e.jsx(ye,{className:"w-4 h-4"})})})]},r.order_id))})]})})]}),e.jsxs("div",{className:"ios-card p-6 rounded-xl bg-white",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900 mb-6",children:"商品金额分析 (TOP5)"}),D.length===0?e.jsx("div",{className:"flex items-center justify-center h-[300px] text-gray-400",children:"暂无数据"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dashboard-pie-chart h-[280px] relative",role:"img","aria-label":`商品金额分析,总金额 ${g(w)}`,children:[e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(ne,{accessibilityLayer:!1,children:[e.jsx(le,{data:D,cx:"50%",cy:"50%",innerRadius:60,outerRadius:92,paddingAngle:2,dataKey:"value",activeShape:{outerRadius:98,stroke:"none",strokeWidth:0},rootTabIndex:-1,label:!1,labelLine:!1,children:D.map((r,y)=>e.jsx(U,{fill:r.color||m[y%m.length]},`cell-${y}`))}),e.jsx(F,{wrapperStyle:{zIndex:30,outline:"none"},contentStyle:{backgroundColor:j("white"),border:`1px solid ${j("neutral-200")}`,borderRadius:"6px",boxShadow:"var(--shadow-md)"},formatter:(r=>`¥${Number(r||0).toLocaleString()}`)})]})}),e.jsxs("div",{className:"pointer-events-none absolute inset-0 z-10 flex flex-col items-center justify-center",children:[e.jsx("span",{className:"text-lg font-extrabold text-gray-900 tabular-nums",children:g(w)}),e.jsx("span",{className:"text-xs font-medium text-gray-400 mt-0.5",children:"总金额"})]})]}),e.jsx("div",{className:"space-y-3 mt-4",children:D.map(r=>e.jsxs("div",{className:"flex justify-between items-center gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("div",{className:"w-3 h-3 rounded-full shrink-0",style:{backgroundColor:r.color||m[D.indexOf(r)%m.length]}}),e.jsx("span",{className:"text-gray-600 font-medium truncate",title:r.name,children:r.name})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0 whitespace-nowrap",children:[e.jsxs("span",{className:"font-bold text-gray-900",children:["¥",r.value.toLocaleString()]}),e.jsxs("span",{className:"text-xs text-gray-500 bg-gray-100 px-2 py-0.5 rounded",children:[r.percentage,"%"]})]})]},r.name))})]})]})]})]})};export{qe as StatusBadge,Xe as default};
+import{r as c,j as e}from"./react-vendor-C_od1ZSF.js";import{f as me}from"./dateTime-DDi7rqpW.js";import{g as q}from"./index-CNzF_I4S.js";import{c as de,o as ge}from"./contract-COFcZjyb.js";import{j as xe,k as he,l as te,D as pe,c as be,P as fe,m as se,E as ye,T as je}from"./icons-vendor-CvzvbbIV.js";import{R as E,B as ve,X as ae,Y as re,T as F,a as Ne,C as U,A as we,b as _e,c as ke,P as ne,d as le,L as De}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";const M=t=>{const a=t.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0");return`${a}-${s}-${l}`},H=(t,a)=>{const s=new Date(t);return s.setHours(12,0,0,0),s.setDate(s.getDate()+a),s},X=(t,a)=>({startDate:M(H(t,-(a-1))),endDate:M(t)}),ue=(t,a=new Date,s="",l="")=>{if(t==="custom"&&s&&l){if(s>l)throw new Error("开始日期不能晚于结束日期");return{startDate:s,endDate:l}}return t==="yesterday"?X(H(a,-1),1):X(a,t==="3days"?3:t==="30days"?30:t==="today"?1:7)},Se=t=>{const a=new Date(`${t.startDate}T12:00:00`),s=new Date(`${t.endDate}T12:00:00`),l=Math.round((s.getTime()-a.getTime())/864e5)+1,n=H(a,-1);return X(n,l)},Ce=t=>{const a={};return t.forEach(s=>{a[s.item_id]=s.item_title||s.item_id}),a},$e=t=>{var a;return((a=t.daily_stats)==null?void 0:a.map(s=>({name:s.date.slice(5),amount:s.amount,orders:s.order_count,avgAmount:s.order_count>0?(s.amount/s.order_count).toFixed(2):0})))||[]},Re=(t,a)=>(t.item_stats||[]).map(s=>{const l=a[s.item_id]||s.item_id;return{name:l.length>12?`${l.substring(0,12)}...`:l,sales:s.order_count}}).sort((s,l)=>l.sales-s.sales).slice(0,10),Le=(t,a,s)=>{const l=t.revenue_stats.total_orders||0;return(t.item_stats||[]).map(n=>{const o=a[n.item_id]||n.item_id;return{name:o.length>10?`${o.substring(0,10)}...`:o,value:n.order_count,percent:l>0?n.order_count/l*100:0}}).sort((n,o)=>o.value-n.value).slice(0,6).map((n,o)=>({...n,color:s[o%s.length]}))},Ae=(t,a,s)=>{const l=t.revenue_stats.total_amount||0;return(t.item_stats||[]).map(n=>{const o=a[n.item_id]||n.item_id;return{name:o.length>12?`${o.substring(0,12)}...`:o,value:n.total_amount,orderCount:n.order_count,percentage:l>0?n.total_amount/l*100:0}}).sort((n,o)=>o.value-n.value).slice(0,5).map((n,o)=>({...n,color:s[o%s.length],percentage:n.percentage.toFixed(1)}))},Oe=(t,a)=>{if(!t||!a)return null;const s=t.revenue_stats.total_amount,l=a.revenue_stats.total_amount;if(l===0)return s>0?"+100%":"0%";const n=(s-l)/l*100;return`${n>=0?"+":""}${n.toFixed(1)}%`},Te=t=>({today:"今天",yesterday:"昨天","3days":"三天内","7days":"7天内","30days":"一个月内",custom:"自定义"})[t.range]||"所选范围",ze=t=>Math.max(...t.map(a=>a.sales),1),P=(t,a,s)=>t===a&&!s.aborted,oe=t=>{const a=String(t||"");return a==="paid"?"pending_ship":["processing","pending_ship","shipped","completed","cancelled","refunding"].includes(a)?a:"unknown"},Pe=async t=>q("/api/v1/analytics/dashboard",void 0,t),We=async(t,a)=>{const s=await q("/api/v1/items",void 0,a);return de(s,["items","data","results"]).map(n=>({...n,id:n.id||`${n.cookie_id}-${n.item_id}`,is_multi_spec:n.is_multi_spec===!0||n.is_multi_spec===1,multi_quantity_delivery:n.multi_quantity_delivery===!0||n.multi_quantity_delivery===1}))},ie=async(t=7,a)=>{let s;if(typeof t=="number"){const l=new Date,n=new Date;n.setDate(n.getDate()-t),s={start_date:M(n),end_date:M(l)}}else s=t;return q("/api/v1/analytics/orders",{...s,timezone_offset_minutes:-new Date().getTimezoneOffset()},a)},Ee=async(t,a)=>{const s=await q("/api/v1/analytics/orders/valid",{...t,timezone_offset_minutes:-new Date().getTimezoneOffset()},a),l=ge(s,["data","result"])||{},o=de(s,["orders","data","items"]).map(b=>({...b,id:b.order_id,status:oe(b.status||b.order_status),order_status:oe(b.order_status),quantity:Number(b.quantity||1)}));return{orders:o,total:Number(l.total??o.length),truncated:l.truncated===!0}},ce=t=>t instanceof Error&&t.message==="请求已取消",G=(t,a)=>t instanceof Error?t.message:a,Fe=t=>{const{range:a,customStartDate:s,customEndDate:l,customRangeVersion:n}=t,[o,b]=c.useState(null),[_,I]=c.useState(null),[K,v]=c.useState({overview:"idle",range:"idle",error:""}),[d,T]=c.useState(0),R=c.useRef(0),S=c.useRef(0),L=c.useMemo(()=>({range:a,customStartDate:s,customEndDate:l}),[l,s,a]),D=c.useCallback(()=>T(u=>u+1),[]);c.useEffect(()=>{const u=++S.current,h=new AbortController;return v(m=>({...m,overview:"loading",error:""})),Promise.all([Pe({signal:h.signal}),We(void 0,{signal:h.signal})]).then(([m,g])=>{P(S.current,u,h.signal)&&(b({stats:m,items:g,itemNames:Ce(g)}),v(p=>({...p,overview:"success"})))}).catch(m=>{!P(S.current,u,h.signal)||ce(m)||v(g=>({...g,overview:"error",error:G(m,"概览加载失败")}))}),(()=>h.abort())},[d]),c.useEffect(()=>{let u;try{u=ue(a,new Date,s,l)}catch(p){v(w=>({...w,range:"error",error:G(p,"日期范围无效")}));return}const h=Se(u),m=++R.current,g=new AbortController;return v(p=>({...p,range:"loading",error:""})),Promise.all([ie({start_date:u.startDate,end_date:u.endDate},{signal:g.signal}),ie({start_date:h.startDate,end_date:h.endDate},{signal:g.signal}),Ee({start_date:u.startDate,end_date:u.endDate},{signal:g.signal})]).then(([p,w,Y])=>{P(R.current,m,g.signal)&&(I({analytics:p,previousAnalytics:w,validOrders:Y,dateRange:u}),v($=>({...$,range:"success"})))}).catch(p=>{!P(R.current,m,g.signal)||ce(p)||v(w=>({...w,range:"error",error:G(p,"经营数据加载失败")}))}),(()=>g.abort())},[n,a,d]);const C=c.useMemo(()=>o&&_?{...o,..._}:null,[o,_]),k=(o==null?void 0:o.itemNames)||{},x=(_==null?void 0:_.analytics)||null,z=c.useMemo(()=>x?$e(x):[],[x]),N=c.useMemo(()=>x?Re(x,k):[],[x,k]),f=c.useMemo(()=>["rgb(var(--color-brand))","rgb(var(--color-brand-highlight))","rgb(var(--color-success-500))","rgb(var(--color-warning-500))","rgb(var(--color-accent-500))"],[]),A=c.useMemo(()=>x?Le(x,k,f):[],[x,f,k]),B=c.useMemo(()=>x?Ae(x,k,f):[],[x,f,k]),V=c.useMemo(()=>ze(N),[N]);return{data:C,status:K,chartData:z,productSalesData:N,sourceData:A,categoryData:B,maxProductSales:V,trendPercent:Oe(x,(C==null?void 0:C.previousAnalytics)||null),selectedRangeLabel:Te(L),refresh:D}},i=(t,a)=>a===void 0?`rgb(var(--color-${t}))`:`rgb(var(--color-${t}) / ${a})`,Me=({chartData:t,selectedRangeLabel:a,totalAmount:s})=>e.jsxs("div",{className:"ios-card p-8 rounded-xl",children:[e.jsxs("div",{className:"mb-10",children:[e.jsx("h3",{className:"text-xl font-bold text-gray-900",children:"营收趋势分析"}),e.jsxs("p",{className:"text-sm text-gray-400 mt-1",children:[a,"的销售额走势"]})]}),e.jsx("div",{className:"dashboard-revenue-chart h-[350px] w-full",children:t.length===0||s===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[e.jsx(xe,{className:"w-16 h-16 mb-4 opacity-20"}),e.jsx("p",{className:"text-lg font-medium",children:"暂无营收数据"}),e.jsx("p",{className:"text-sm mt-2",children:"所选时间范围内暂无订单记录"})]}):t.length<=2?e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(ve,{data:t,margin:{top:30,right:20,left:0,bottom:30},barCategoryGap:"45%",children:[e.jsx(ae,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:i("neutral-700"),fontSize:14,fontWeight:600},dy:10}),e.jsx(re,{axisLine:!1,tickLine:!1,tick:{fill:i("neutral-400"),fontSize:13,fontWeight:500},tickFormatter:(l=>`¥${l}`)}),e.jsx(F,{contentStyle:{backgroundColor:i("white"),borderRadius:"8px",border:`1px solid ${i("neutral-200")}`,boxShadow:"var(--shadow-xl)",padding:"12px 16px"},labelStyle:{color:i("neutral-500"),fontWeight:500},itemStyle:{color:i("brand"),fontWeight:600},cursor:{fill:i("brand",.08)},formatter:(l=>[`¥${Number(l).toFixed(2)}`,"营收"])}),e.jsx(Ne,{dataKey:"amount",fill:i("brand"),maxBarSize:72,radius:[12,12,0,0],activeBar:!1,stroke:"none",strokeWidth:0,children:t.map((l,n)=>e.jsx(U,{fill:i("brand"),stroke:"none",strokeWidth:0},`cell-${n}`))})]})}):e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(we,{data:t,margin:{top:10,right:10,left:-20,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"colorAmount",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:i("brand"),stopOpacity:.5}),e.jsx("stop",{offset:"95%",stopColor:i("brand"),stopOpacity:0})]})}),e.jsx(ae,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:i("neutral-400"),fontSize:13,fontWeight:500},dy:15}),e.jsx(re,{axisLine:!1,tickLine:!1,tick:{fill:i("neutral-400"),fontSize:13,fontWeight:500}}),e.jsx(_e,{vertical:!1,stroke:i("neutral-100"),strokeDasharray:"3 3"}),e.jsx(F,{contentStyle:{backgroundColor:i("white"),borderRadius:"8px",border:`1px solid ${i("neutral-200")}`,boxShadow:"var(--shadow-xl)",padding:"12px 16px"},labelStyle:{color:i("neutral-500"),fontWeight:500},itemStyle:{color:i("brand"),fontWeight:600},cursor:{stroke:i("brand"),strokeWidth:2,strokeDasharray:"4 4"}}),e.jsx(ke,{type:"monotone",dataKey:"amount",stroke:i("brand"),strokeWidth:4,fillOpacity:1,fill:"url(#colorAmount)",activeDot:{r:8,fill:i("white"),stroke:i("brand"),strokeWidth:2}})]})})})]}),j=(t,a)=>`rgb(var(--color-${t}))`,qe=({status:t})=>{const a={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},s={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`inline-flex items-center justify-center whitespace-nowrap px-3 py-1.5 rounded-lg text-xs leading-none font-bold ${a[t]||a.cancelled}`,children:s[t]||t})},W=({title:t,value:a,icon:s,colorClass:l,trend:n})=>e.jsxs("div",{className:"ios-card p-6 rounded-xl flex flex-col justify-between hover:translate-y-[-4px] transition-all duration-300 h-full relative overflow-hidden group border-0",children:[e.jsx("div",{className:`absolute -right-6 -top-6 w-32 h-32 ${l} opacity-10 rounded-full group-hover:scale-125 transition-transform duration-500 blur-2xl`}),e.jsxs("div",{className:"flex justify-between items-start mb-6",children:[e.jsx("div",{className:`p-4 rounded-2xl ${l} bg-opacity-10 backdrop-blur-sm`,children:e.jsx(s,{className:`w-6 h-6 ${l.replace("bg-","text-")}`})}),n&&e.jsxs("span",{className:"text-xs font-bold text-white bg-brand px-3 py-1.5 rounded-full flex items-center gap-1 shadow-sm",children:[e.jsx(je,{className:"w-3 h-3"})," ",n]})]}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("h3",{className:"text-3xl font-extrabold text-gray-900 tracking-tight font-feature-settings-tnum",children:a}),e.jsx("p",{className:"text-gray-500 text-sm font-medium mt-1",children:t})]})]}),Xe=()=>{const[t,a]=c.useState("7days"),[s,l]=c.useState(""),[n,o]=c.useState(""),[b,_]=c.useState(""),[I,K]=c.useState(0),v=Fe({range:t,customStartDate:s,customEndDate:n,customRangeVersion:I}),{data:d,status:T,chartData:R,productSalesData:S,sourceData:L,categoryData:D,maxProductSales:C,trendPercent:k,selectedRangeLabel:x,refresh:z}=v,N=(d==null?void 0:d.stats)||null,f=(d==null?void 0:d.analytics)||null;d!=null&&d.previousAnalytics;const A=(d==null?void 0:d.validOrders.orders)||[],B=(d==null?void 0:d.validOrders.total)||0,V=(d==null?void 0:d.validOrders.truncated)||!1,u=T.range==="loading",h=T.error,m=[j("brand"),j("brand-highlight"),j("success-500"),j("warning-500"),j("accent-500")],g=r=>`¥${Number(r||0).toLocaleString("zh-CN",{maximumFractionDigits:2})}`;if(h&&(!N||!f))return e.jsxs("div",{className:"p-8 flex flex-col items-center gap-3 text-red-600",children:[e.jsx(he,{className:"w-8 h-8"}),e.jsx("span",{children:h}),e.jsx("button",{type:"button",className:"ios-btn-primary px-4 py-2 rounded-xl",onClick:z,children:"重新加载"})]});if(!N||!f)return e.jsx("div",{className:"p-8 flex justify-center text-gray-400",children:e.jsx(te,{className:"w-8 h-8 animate-spin text-brand"})});const p=f.revenue_stats.total_orders||0,w=f.revenue_stats.total_amount||0,Y=[{key:"today",label:"今天"},{key:"yesterday",label:"昨天"},{key:"3days",label:"三天内"},{key:"7days",label:"7天内"},{key:"30days",label:"一个月内"},{key:"custom",label:"自定义"}];let $;try{$=ue(t,new Date,s,n)}catch{$={startDate:s,endDate:n}}const O=b.trim().toLowerCase(),J=A.filter(r=>{var y,Q,Z,ee;return((y=r.order_id)==null?void 0:y.toLowerCase().includes(O))||((Q=r.item_id)==null?void 0:Q.toLowerCase().includes(O))||((Z=r.item_title)==null?void 0:Z.toLowerCase().includes(O))||((ee=r.buyer_id)==null?void 0:ee.toLowerCase().includes(O))});return e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[h&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:h}),e.jsx("button",{type:"button",className:"font-bold underline",onClick:z,children:"重试"})]}),e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"运营概览"}),e.jsx("p",{className:"text-gray-500 mt-2 text-base",children:"欢迎回来,以下是闲鱼店铺的实时经营数据。"})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"text-sm font-bold text-gray-700 bg-white px-5 py-2.5 rounded-full shadow-sm border border-gray-100 flex items-center gap-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 bg-green-500 rounded-full animate-pulse"}),"系统正常运行"]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[Y.map(r=>e.jsx("button",{onClick:(()=>a(r.key)),className:`px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${t===r.key?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:r.label},r.key)),t==="custom"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"date",value:s,onChange:(r=>l(r.target.value)),className:"px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-brand"}),e.jsx("span",{className:"self-center text-gray-400",children:"-"}),e.jsx("input",{type:"date",value:n,onChange:(r=>o(r.target.value)),className:"px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-brand"}),e.jsx("button",{onClick:(()=>K(r=>r+1)),className:"px-4 py-2 rounded-xl text-sm font-bold bg-black text-white hover:bg-gray-800 transition-colors",children:"应用"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsx(W,{title:"累计营收 (CNY)",value:`¥${f.revenue_stats.total_amount.toLocaleString("zh-CN",{minimumFractionDigits:2})}`,icon:pe,colorClass:"bg-blue-400",trend:k||void 0}),e.jsx(W,{title:"活跃账号 / 总数",value:`${N.active_cookies} / ${N.total_cookies}`,icon:be,colorClass:"bg-blue-500"}),e.jsx(W,{title:"订单数",value:f.revenue_stats.total_orders.toLocaleString(),icon:xe,colorClass:"bg-blue-500"}),e.jsx(W,{title:"库存卡密余量",value:N.available_card_stock,icon:fe,colorClass:"bg-purple-500"})]}),e.jsx(Me,{chartData:R,selectedRangeLabel:x,totalAmount:w}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"ios-card p-6 rounded-xl",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900 mb-6",children:"商品销量排行"}),e.jsx("div",{className:"h-[280px]",children:S.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:"暂无数据"}):e.jsx("div",{className:"h-full space-y-4 overflow-y-auto pr-2",children:S.map((r,y)=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:`w-7 h-7 rounded-xl flex items-center justify-center text-xs font-extrabold ${y<3?"bg-blue-600 text-white":"bg-gray-100 text-gray-500"}`,children:y+1}),e.jsx("span",{className:"font-bold text-gray-800 text-sm truncate",children:r.name})]}),e.jsxs("span",{className:"font-mono text-sm font-extrabold text-gray-900",children:[r.sales," 单"]})]}),e.jsx("div",{className:"h-3 rounded-full bg-gray-100 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-brand",style:{width:`${Math.max(8,r.sales/C*100)}%`}})})]},`${r.name}-${y}`))})})]}),e.jsxs("div",{className:"ios-card p-6 rounded-xl",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900 mb-6",children:"商品下单占比"}),e.jsx("div",{className:"dashboard-pie-chart h-[280px] relative",role:"img","aria-label":`商品下单占比,共 ${p} 单`,children:L.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:"暂无数据"}):e.jsxs(e.Fragment,{children:[e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(ne,{accessibilityLayer:!1,children:[e.jsx(le,{data:L,cx:"50%",cy:"45%",innerRadius:60,outerRadius:90,paddingAngle:2,dataKey:"value",activeShape:{outerRadius:96,stroke:"none",strokeWidth:0},rootTabIndex:-1,label:!1,labelLine:!1,children:L.map((r,y)=>e.jsx(U,{fill:r.color},`cell-${y}`))}),e.jsx(F,{formatter:(r=>`${Number(r||0)} 单`),wrapperStyle:{zIndex:30,outline:"none"},contentStyle:{backgroundColor:j("white"),border:`1px solid ${j("neutral-200")}`,borderRadius:"10px",boxShadow:"var(--shadow-md)"}}),e.jsx(De,{verticalAlign:"bottom",height:36,iconType:"circle",formatter:(r=>e.jsx("span",{style:{color:j("neutral-500"),fontWeight:500},children:r}))})]})}),e.jsxs("div",{className:"pointer-events-none absolute inset-0 z-10 flex flex-col items-center justify-center pb-9",children:[e.jsx("span",{className:"text-2xl font-extrabold text-gray-900 tabular-nums",children:p}),e.jsx("span",{className:"text-xs font-medium text-gray-400 mt-0.5",children:"总订单"})]})]})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsxs("div",{className:"lg:col-span-2 ios-card p-0 rounded-xl border-0 bg-white overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-gray-50 flex justify-between items-center bg-surface-muted",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900",children:"参与统计的订单"}),V&&e.jsxs("p",{className:"text-xs text-amber-700 mt-1",children:["当前显示最近 ",A.length," / ",B," 条,搜索仅覆盖已加载明细。"]})]}),e.jsx("div",{className:"relative",children:e.jsx("input",{placeholder:"搜索订单号/商品/买家...",value:b,onChange:(r=>_(r.target.value)),className:"pl-4 pr-4 py-2 rounded-xl bg-white border border-gray-100 text-sm focus:border-blue-400 outline-none w-48",type:"text"})})]}),e.jsx("div",{className:"overflow-x-auto flex-1 max-h-[400px]",children:u?e.jsxs("div",{className:"flex items-center justify-center py-20 text-gray-400",children:[e.jsx(te,{className:"w-6 h-6 animate-spin mr-2"}),"加载中..."]}):J.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-8 text-center",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gray-100 flex items-center justify-center mb-4",children:e.jsx(se,{className:"w-7 h-7 text-gray-300"})}),O?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"没有匹配的订单"}),e.jsxs("div",{className:"text-xs text-gray-400 mt-2 max-w-md",children:["当前共有 ",A.length," 单参与统计,但没有订单号、商品、买家匹配“",b,"”。"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"当前范围内没有参与统计的订单"}),e.jsxs("div",{className:"text-xs text-gray-400 mt-2 max-w-lg leading-6",children:["日期范围:",$.startDate," 至 ",$.endDate,"; 统计口径:待发货、已发货、已完成,且订单金额不为空。 当前统计卡片订单数:",f.revenue_stats.total_orders," 单。"]})]})]}):e.jsxs("table",{className:"w-full min-w-[760px] text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"px-6 py-4",children:"订单信息"}),e.jsx("th",{className:"px-6 py-4",children:"买家信息"}),e.jsx("th",{className:"px-6 py-4",children:"金额"}),e.jsx("th",{className:"px-6 py-4 whitespace-nowrap",children:"状态"}),e.jsx("th",{className:"px-6 py-4 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:J.map(r=>e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gray-100 overflow-hidden shadow-sm border border-gray-100 flex-shrink-0",children:e.jsx(se,{className:"w-full h-full text-gray-300 p-2"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm line-clamp-1",children:r.item_title||r.item_id||"未知商品"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 font-mono",children:r.order_id}),e.jsxs("div",{className:"text-xs text-gray-400 mt-0.5",children:["数量: ",r.quantity||1]})]})]})}),e.jsxs("td",{className:"px-6 py-4",children:[e.jsx("div",{className:"text-sm font-bold text-gray-800",children:r.buyer_id}),r.created_at&&e.jsx("div",{className:"text-xs text-gray-400 mt-1",children:me(r.created_at)})]}),e.jsxs("td",{className:"px-6 py-4 text-base font-extrabold text-gray-900 font-feature-settings-tnum",children:["¥",r.amount||"0.00"]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx(qe,{status:r.status||r.order_status||"unknown"})}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsx("a",{href:`https://www.goofish.com/order-detail?orderId=${r.order_id}&role=seller`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看闲鱼详情",children:e.jsx(ye,{className:"w-4 h-4"})})})]},r.order_id))})]})})]}),e.jsxs("div",{className:"ios-card p-6 rounded-xl bg-white",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900 mb-6",children:"商品金额分析 (TOP5)"}),D.length===0?e.jsx("div",{className:"flex items-center justify-center h-[300px] text-gray-400",children:"暂无数据"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dashboard-pie-chart h-[280px] relative",role:"img","aria-label":`商品金额分析,总金额 ${g(w)}`,children:[e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(ne,{accessibilityLayer:!1,children:[e.jsx(le,{data:D,cx:"50%",cy:"50%",innerRadius:60,outerRadius:92,paddingAngle:2,dataKey:"value",activeShape:{outerRadius:98,stroke:"none",strokeWidth:0},rootTabIndex:-1,label:!1,labelLine:!1,children:D.map((r,y)=>e.jsx(U,{fill:r.color||m[y%m.length]},`cell-${y}`))}),e.jsx(F,{wrapperStyle:{zIndex:30,outline:"none"},contentStyle:{backgroundColor:j("white"),border:`1px solid ${j("neutral-200")}`,borderRadius:"6px",boxShadow:"var(--shadow-md)"},formatter:(r=>`¥${Number(r||0).toLocaleString()}`)})]})}),e.jsxs("div",{className:"pointer-events-none absolute inset-0 z-10 flex flex-col items-center justify-center",children:[e.jsx("span",{className:"text-lg font-extrabold text-gray-900 tabular-nums",children:g(w)}),e.jsx("span",{className:"text-xs font-medium text-gray-400 mt-0.5",children:"总金额"})]})]}),e.jsx("div",{className:"space-y-3 mt-4",children:D.map(r=>e.jsxs("div",{className:"flex justify-between items-center gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("div",{className:"w-3 h-3 rounded-full shrink-0",style:{backgroundColor:r.color||m[D.indexOf(r)%m.length]}}),e.jsx("span",{className:"text-gray-600 font-medium truncate",title:r.name,children:r.name})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0 whitespace-nowrap",children:[e.jsxs("span",{className:"font-bold text-gray-900",children:["¥",r.value.toLocaleString()]}),e.jsxs("span",{className:"text-xs text-gray-500 bg-gray-100 px-2 py-0.5 rounded",children:[r.percentage,"%"]})]})]},r.name))})]})]})]})]})};export{qe as StatusBadge,Xe as default};
diff --git a/internal/webui/static/assets/ItemList-BHJwErgP.js b/internal/webui/static/assets/ItemList-Di4uiKj1.js
similarity index 99%
rename from internal/webui/static/assets/ItemList-BHJwErgP.js
rename to internal/webui/static/assets/ItemList-Di4uiKj1.js
index bf9f8af..82645a4 100644
--- a/internal/webui/static/assets/ItemList-BHJwErgP.js
+++ b/internal/webui/static/assets/ItemList-Di4uiKj1.js
@@ -1,2 +1,2 @@
-import{r as l,j as e,b as ge}from"./react-vendor-C_od1ZSF.js";import{g as de,a as te,b as Ge,d as Ve,p as ot}from"./index-hByDAHGj.js";import{c as We}from"./contract-COFcZjyb.js";import{a3 as xt,U as Ee,R as we,N as Re,a4 as _e,a5 as be,V as mt,F as ht,B as ut,a6 as $e,a7 as pt,a8 as gt,A as bt,d as yt,X as re,r as ft,a9 as De,I as qe}from"./icons-vendor-CvzvbbIV.js";const Ue="ydisks-amap-js-api",jt="c9b68d4ce9a2a97f22a4a439404488ca";let ce=null;const Nt=()=>jt,vt=()=>window.AMap?Promise.resolve(window.AMap):ce||(ce=new Promise((s,a)=>{const x=document.getElementById(Ue),o=x||document.createElement("script"),d=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(P)},g=()=>{window.AMap?(d(),s(window.AMap)):(d(),a(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},P=window.setTimeout(()=>{d(),a(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=g,o.id=Ue,o.async=!0,o.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(Nt())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,o.onerror=()=>{d(),a(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},x||document.head.appendChild(o)}).catch(s=>{throw ce=null,s}),ce),ye=s=>Number.isFinite(s)&&s!==0,wt=s=>{var d,g;const a=Number((d=s.location)==null?void 0:d.lng),x=Number((g=s.location)==null?void 0:g.lat),o={area:String(s.adname||"").trim(),city:String(s.cityname||"").trim(),division_id:String(s.adcode||"").trim(),longitude:a,latitude:x,poi_id:String(s.id||"").trim(),poi_name:String(s.name||"").trim(),province:String(s.pname||"").trim()};return!o.division_id||!o.province||!o.city||!o.poi_id||!o.poi_name||!ye(a)||!ye(x)||a<-180||a>180||x<-90||x>90?null:o},_t=async(s,a)=>{if(!ye(s)||!ye(a)||s<-180||s>180||a<-90||a>90)throw new Error("经纬度无效");const x=await vt();return new Promise((o,d)=>{new x.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[s,a],1e3,(P,f)=>{var w;if(P!=="complete"){if(P==="no_data"){o([]);return}d(new Error("高德地图附近地址查询失败,请稍后重试"));return}const L=(((w=f==null?void 0:f.poiList)==null?void 0:w.pois)||[]).map(wt).filter(T=>T!==null);o(L)})})},kt=async s=>de("/api/v1/accounts/details",void 0,s),ze=async()=>de("/api/v1/automation-rules"),ke=s=>s===!0||s===1||s==="1",Oe=async(s,a)=>{const x=await de("/api/v1/items",void 0,a);return We(x,["items","data","results"]).map(d=>({...d,id:d.id||`${d.cookie_id}-${d.item_id}`,is_multi_spec:ke(d.is_multi_spec),is_multi_qty_ship:ke(d.is_multi_qty_ship??d.multi_quantity_delivery),multi_quantity_delivery:ke(d.multi_quantity_delivery??d.is_multi_qty_ship)}))},Ct=async s=>te("/api/v1/items/get-all-from-account",{cookie_id:s}),It=async(s,a)=>Ve(`/api/v1/items/${s}/${a}`),St=async(s,a)=>te(`/api/v1/items/${s}`,a),Pt=async s=>{const a=new FormData;a.set("cookie_id",s.cookie_id),a.set("title",s.title),a.set("description",s.description),a.set("price",s.price),a.set("original_price",s.original_price||""),a.set("quantity",String(s.quantity)),a.set("postage_mode",s.postage_mode),a.set("postage",s.postage||""),s.location&&a.set("location",JSON.stringify(s.location));for(const x of s.images)a.append("images",x);return Ge("/api/v1/items/publish",a)},Bt=async(s,a)=>te("/api/v1/items/publish-categories/recommend",{cookie_id:s,keyword:a}),Ft=async s=>{const a=new FormData;return a.set("file",s.file),s.imagesZip&&a.set("images_zip",s.imagesZip),s.defaultCookieId&&a.set("default_cookie_id",s.defaultCookieId),a.set("fallback_category_id",s.fallbackCategory.catId),a.set("fallback_category_name",s.fallbackCategory.catName),a.set("fallback_channel_category_id",s.fallbackCategory.channelCatId||""),a.set("fallback_tb_category_id",s.fallbackCategory.tbCatId||""),s.location&&a.set("location",JSON.stringify(s.location)),Ge("/api/v1/items/publish-batches/preview",a)},Lt=async s=>te("/api/v1/items/publish-batches",{preview_id:s}),ee=async s=>de(`/api/v1/items/publish-batches/${s}`),Ye=async(s=20)=>{const a=await de("/api/v1/items/publish-batches",{limit:s});return We(a,["batches","data","items"])},At=async s=>Ve(`/api/v1/items/publish-batches/${s}`),Mt=async s=>te(`/api/v1/items/publish-batches/${s}/cancel`,{}),Et=async s=>te(`/api/v1/items/publish-batches/${s}/retry-failed`,{}),Rt=async(s,a,x)=>ot(`/api/v1/items/${s}/${a}`,x),$t=s=>s.find(a=>a.status==="running"||a.status==="canceling"),Ie=s=>s==="running"||s==="canceling",Dt=s=>!!(s!=null&&s.preview_id&&Number(s.valid||0)>0),qt=s=>!!(s!=null&&s.id&&Number(s.retryable||0)>0&&!Ie(s.status)),Ut=(s,a)=>s===a,Te=s=>{switch(s){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return s||"-"}},Ke=s=>{switch(s){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},zt=s=>{const[a,x]=l.useState(!1),[o,d]=l.useState("upload"),[g,P]=l.useState(null),[f,L]=l.useState(null),[w,T]=l.useState(""),[K,J]=l.useState(!1),[R,G]=l.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[y,N]=l.useState(null),[c,_]=l.useState(null),[I,$]=l.useState(null),[V,D]=l.useState([]),[q,B]=l.useState(null),[U,p]=l.useState(!1),k=l.useRef(!1),m=l.useRef(0),A=l.useCallback(async()=>{d("upload"),N(null),_(null),P(null),L(null),T(""),G({catId:"",catName:"",channelCatId:"",tbCatId:""}),D([]),B(null),x(!0),p(!0);try{const r=await Ye(20),h=$t(r);if(h!=null&&h.id){const S=await ee(h.id);$(S),_(S),d(["running","canceling"].includes(S.status)?"running":"done")}}catch(r){console.error("恢复最近批量铺货任务失败:",r)}finally{p(!1)}},[]),u=l.useCallback(async()=>{const r=w.trim();if(!s.selectedAccount){alert("请先选择默认发布账号");return}if(!r){alert("请输入类目关键词");return}J(!0);try{const S=(await Bt(s.selectedAccount,r)).category;G({catId:S.cat_id,catName:S.cat_name,channelCatId:S.channel_cat_id,tbCatId:S.tb_cat_id||""})}catch(h){console.error("获取推荐类目失败:",h),alert((h==null?void 0:h.message)||"没有匹配到类目,请换一个更具体的关键词")}finally{J(!1)}},[w,s.selectedAccount]),M=l.useCallback(async()=>{if(I!=null&&I.id){p(!0),x(!0);try{const r=await ee(I.id);_(r),d(["running","canceling"].includes(r.status)?"running":"done")}catch(r){console.error("加载最近批量铺货结果失败:",r)}finally{p(!1)}}},[I==null?void 0:I.id]),se=l.useCallback(async()=>{if(!g){alert("请先上传商品表格");return}if(!s.selectedAccount){alert("请先选择默认发布账号");return}p(!0);try{const r=await Ft({file:g,imagesZip:f,defaultCookieId:s.selectedAccount,fallbackCategory:R,location:q||void 0});N(r),_(null),d("preview")}catch(r){console.error("批量铺货预检失败:",r),alert((r==null?void 0:r.message)||"预检失败,请检查表格和图片 zip")}finally{p(!1)}},[R,g,f,q,s.selectedAccount]),W=l.useCallback(async()=>{if(y!=null&&y.preview_id){if(!Dt(y)){alert("没有可发布的商品行");return}p(!0);try{const r=await Lt(y.preview_id),h=await ee(r.batch_id||y.preview_id);_(h),$(h),d(h.status==="running"?"running":"done")}catch(r){console.error("启动批量铺货失败:",r),alert((r==null?void 0:r.message)||"启动发布任务失败")}finally{p(!1)}}},[y]),Y=l.useCallback(async()=>{if(c!=null&&c.id&&confirm("确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。")){p(!0);try{const r=await Mt(c.id),h=await ee(c.id);_(h),d((r==null?void 0:r.status)==="canceling"||h.status==="canceling"?"running":"done")}catch(r){alert((r==null?void 0:r.message)||"取消失败")}finally{p(!1)}}},[c==null?void 0:c.id]),H=l.useCallback(async()=>{const r=y==null?void 0:y.preview_id;if(r&&o==="preview")try{await At(r)}catch(h){console.error("清理批量铺货预检失败:",h)}N(null),d("upload")},[o,y==null?void 0:y.preview_id]),Q=l.useCallback(async()=>{await H(),x(!1)},[H]),ae=l.useCallback(async()=>{if(!(!(c!=null&&c.id)||!qt(c))){p(!0);try{await Et(c.id),_(await ee(c.id)),d("running")}catch(r){alert((r==null?void 0:r.message)||"重试失败")}finally{p(!1)}}},[c]);return l.useEffect(()=>{if(!a||!(c!=null&&c.id)||!Ie(c.status))return;const r=++m.current,h=async()=>{if(!k.current){k.current=!0;try{const z=await ee(c.id);if(!Ut(r,m.current))return;_(z),$(z),Ie(z.status)||(d("done"),await Promise.all([s.loadItems(),s.loadShippingRules()]))}catch(z){console.error("刷新批量铺货进度失败:",z)}finally{k.current=!1}}},S=window.setInterval(()=>void h(),3e3);return(()=>{window.clearInterval(S),m.current+=1})},[c==null?void 0:c.id,c==null?void 0:c.status,s.loadItems,s.loadShippingRules,a]),{showBatchModal:a,setShowBatchModal:x,batchLoading:U,batchPhase:o,setBatchPhase:d,batchFile:g,setBatchFile:P,batchImagesZip:f,setBatchImagesZip:L,batchCategoryKeyword:w,setBatchCategoryKeyword:T,batchCategoryLoading:K,batchFallbackCategory:R,setBatchFallbackCategory:G,batchPreview:y,setBatchPreview:N,batchDetail:c,setBatchDetail:_,recentBatch:I,setRecentBatch:$,batchLocations:V,batchLocation:q,setBatchLocations:D,setBatchLocation:B,openBatchModal:A,handleRecommendBatchCategory:u,openRecentBatchResult:M,handlePreviewBatch:se,handleStartBatch:W,handleCancelBatch:Y,abandonBatchPreview:H,closeBatchModal:Q,handleRetryBatchFailed:ae}},Je=()=>({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),Ze=(s="")=>({cookie_id:s,title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),Ce=(s,a)=>{if(s instanceof Error)return s.message;const x=typeof s=="object"&&s!==null&&"message"in s?s.message:void 0;return typeof x=="string"?x:a},Ot=({selectedAccount:s,setSelectedAccount:a,setItems:x,loadItems:o,loadShippingRules:d,onConfigureDelivery:g,setBatchLocations:P,setBatchLocation:f})=>{const[L,w]=l.useState(!1),[T,K]=l.useState(!1),[J,R]=l.useState(!1),[G,y]=l.useState(!1),[N,c]=l.useState(!1),[_,I]=l.useState(!1),[$,V]=l.useState([]),[D,q]=l.useState(null),[B,U]=l.useState(null),[p,k]=l.useState({}),[m,A]=l.useState(Je),[u,M]=l.useState(Ze),[se,W]=l.useState([]);l.useEffect(()=>{if(!N||u.images.length===0){W([]);return}const i=u.images.map((j,C)=>({key:j.name+C,url:URL.createObjectURL(j)}));return W(i),(()=>i.forEach(j=>URL.revokeObjectURL(j.url)))},[u.images,N]);const Y=l.useCallback(async()=>{if(!s)return alert("请先选择账号");w(!0);try{const i=await Ct(s);await o(),alert((i==null?void 0:i.message)||"商品同步完成")}catch(i){console.error("同步商品失败:",i),alert(Ce(i,"同步失败,请重试"))}finally{w(!1)}},[o,s]),H=l.useCallback(i=>{U(i),k({...i}),R(!0)},[]),Q=l.useCallback(async()=>{if(B)try{await Rt(B.cookie_id,B.item_id,{item_title:p.item_title||"",item_description:p.item_description||"",item_category:p.item_category||"",item_price:p.item_price||"",item_detail:p.item_detail||B.item_detail||""}),await o(),await d(),R(!1),U(null)}catch(i){console.error("更新商品失败:",i),alert("更新失败,请重试")}},[p,o,d,B]),ae=l.useCallback(async i=>{if(confirm(`确认删除商品"${i.item_title}"吗?`))try{await It(i.cookie_id,i.item_id),x(j=>j.filter(C=>!(C.cookie_id===i.cookie_id&&C.item_id===i.item_id)))}catch(j){console.error("删除商品失败:",j),alert("删除失败,请重试")}},[x]),oe=l.useCallback(async()=>{try{if(!m.cookie_id||!m.item_id){alert("请选择账号并填写商品ID");return}await St(m.cookie_id,{item_id:m.item_id,item_title:m.item_title,item_price:m.item_price,item_detail:m.item_image?JSON.stringify({item_image:m.item_image}):""}),await o(),y(!1),A(Je())}catch(i){console.error("添加商品失败:",i),alert("添加失败,请重试")}},[m,o]),r=l.useCallback(async()=>{if(!u.cookie_id)return alert("请选择发布账号");if(!u.title.trim())return alert("请填写商品标题");if(!u.price.trim())return alert("请填写商品价格");if(!u.quantity||Number(u.quantity)<=0)return alert("库存数量必须大于 0");if(u.images.length===0)return alert("至少上传 1 张商品图片");if(u.postage_mode==="fixed"&&!u.postage.trim())return alert("请填写一口价邮费");K(!0);try{const i=await Pt({...u,location:D||void 0});if(await o(),c(!1),M(Ze(s||"")),V([]),q(null),i!=null&&i.item_id){const j={id:i.item_id,cookie_id:u.cookie_id,item_id:i.item_id,item_title:i.item_title||u.title,item_price:i.item_price||u.price,item_image:i.item_image};g(j),alert("商品发布成功,ID: "+i.item_id+",已为你打开发货规则配置")}else alert("商品发布成功")}catch(i){console.error("发布商品失败:",i);const j=i==null?void 0:i.payload;if((j==null?void 0:j.code)==="stock_permission_missing"){alert("发布失败:该账号没有库存发布权限,无法按库存数量发布商品。请换账号或先在闲鱼确认库存能力。");return}alert(Ce(i,"发布失败,请重试"))}finally{K(!1)}},[o,g,u,D,s]),h=l.useCallback(()=>{const C=[["账号ID","标题","描述","价格","原价","库存","邮费模式","邮费","图片","类目ID","类目名称","频道类目ID","淘宝类目ID","付款发货启用","付款发货内容","评价赠品启用","评价赠品内容","求评价启用","求评价等待小时","求评价文案","求评价最多次数"],...[["","会员组合包自动发货","下单后发送主卡和附赠卡。","19.90","29.90","10","free","","images/bundle-1.jpg;images/bundle-2.jpg","","","","","是","101:1;102:1","是","201:1;202:2","是","72","亲,满意的话麻烦给个评价,谢谢~","1"],["","普通商品","仅发布商品,不创建自动化规则。","49.90","","10","fixed","8.00","https://example.com/product.jpg","","","","","否","","否","","否","","",""]]].map(je=>je.map(Ne=>`"${String(Ne).replace(/"/g,'""')}"`).join(",")).join(`
+import{r as l,j as e,b as ge}from"./react-vendor-C_od1ZSF.js";import{g as de,a as te,b as Ge,d as Ve,p as ot}from"./index-CNzF_I4S.js";import{c as We}from"./contract-COFcZjyb.js";import{a3 as xt,U as Ee,R as we,N as Re,a4 as _e,a5 as be,V as mt,F as ht,B as ut,a6 as $e,a7 as pt,a8 as gt,A as bt,d as yt,X as re,r as ft,a9 as De,I as qe}from"./icons-vendor-CvzvbbIV.js";const Ue="ydisks-amap-js-api",jt="c9b68d4ce9a2a97f22a4a439404488ca";let ce=null;const Nt=()=>jt,vt=()=>window.AMap?Promise.resolve(window.AMap):ce||(ce=new Promise((s,a)=>{const x=document.getElementById(Ue),o=x||document.createElement("script"),d=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(P)},g=()=>{window.AMap?(d(),s(window.AMap)):(d(),a(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},P=window.setTimeout(()=>{d(),a(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=g,o.id=Ue,o.async=!0,o.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(Nt())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,o.onerror=()=>{d(),a(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},x||document.head.appendChild(o)}).catch(s=>{throw ce=null,s}),ce),ye=s=>Number.isFinite(s)&&s!==0,wt=s=>{var d,g;const a=Number((d=s.location)==null?void 0:d.lng),x=Number((g=s.location)==null?void 0:g.lat),o={area:String(s.adname||"").trim(),city:String(s.cityname||"").trim(),division_id:String(s.adcode||"").trim(),longitude:a,latitude:x,poi_id:String(s.id||"").trim(),poi_name:String(s.name||"").trim(),province:String(s.pname||"").trim()};return!o.division_id||!o.province||!o.city||!o.poi_id||!o.poi_name||!ye(a)||!ye(x)||a<-180||a>180||x<-90||x>90?null:o},_t=async(s,a)=>{if(!ye(s)||!ye(a)||s<-180||s>180||a<-90||a>90)throw new Error("经纬度无效");const x=await vt();return new Promise((o,d)=>{new x.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[s,a],1e3,(P,f)=>{var w;if(P!=="complete"){if(P==="no_data"){o([]);return}d(new Error("高德地图附近地址查询失败,请稍后重试"));return}const L=(((w=f==null?void 0:f.poiList)==null?void 0:w.pois)||[]).map(wt).filter(T=>T!==null);o(L)})})},kt=async s=>de("/api/v1/accounts/details",void 0,s),ze=async()=>de("/api/v1/automation-rules"),ke=s=>s===!0||s===1||s==="1",Oe=async(s,a)=>{const x=await de("/api/v1/items",void 0,a);return We(x,["items","data","results"]).map(d=>({...d,id:d.id||`${d.cookie_id}-${d.item_id}`,is_multi_spec:ke(d.is_multi_spec),is_multi_qty_ship:ke(d.is_multi_qty_ship??d.multi_quantity_delivery),multi_quantity_delivery:ke(d.multi_quantity_delivery??d.is_multi_qty_ship)}))},Ct=async s=>te("/api/v1/items/get-all-from-account",{cookie_id:s}),It=async(s,a)=>Ve(`/api/v1/items/${s}/${a}`),St=async(s,a)=>te(`/api/v1/items/${s}`,a),Pt=async s=>{const a=new FormData;a.set("cookie_id",s.cookie_id),a.set("title",s.title),a.set("description",s.description),a.set("price",s.price),a.set("original_price",s.original_price||""),a.set("quantity",String(s.quantity)),a.set("postage_mode",s.postage_mode),a.set("postage",s.postage||""),s.location&&a.set("location",JSON.stringify(s.location));for(const x of s.images)a.append("images",x);return Ge("/api/v1/items/publish",a)},Bt=async(s,a)=>te("/api/v1/items/publish-categories/recommend",{cookie_id:s,keyword:a}),Ft=async s=>{const a=new FormData;return a.set("file",s.file),s.imagesZip&&a.set("images_zip",s.imagesZip),s.defaultCookieId&&a.set("default_cookie_id",s.defaultCookieId),a.set("fallback_category_id",s.fallbackCategory.catId),a.set("fallback_category_name",s.fallbackCategory.catName),a.set("fallback_channel_category_id",s.fallbackCategory.channelCatId||""),a.set("fallback_tb_category_id",s.fallbackCategory.tbCatId||""),s.location&&a.set("location",JSON.stringify(s.location)),Ge("/api/v1/items/publish-batches/preview",a)},Lt=async s=>te("/api/v1/items/publish-batches",{preview_id:s}),ee=async s=>de(`/api/v1/items/publish-batches/${s}`),Ye=async(s=20)=>{const a=await de("/api/v1/items/publish-batches",{limit:s});return We(a,["batches","data","items"])},At=async s=>Ve(`/api/v1/items/publish-batches/${s}`),Mt=async s=>te(`/api/v1/items/publish-batches/${s}/cancel`,{}),Et=async s=>te(`/api/v1/items/publish-batches/${s}/retry-failed`,{}),Rt=async(s,a,x)=>ot(`/api/v1/items/${s}/${a}`,x),$t=s=>s.find(a=>a.status==="running"||a.status==="canceling"),Ie=s=>s==="running"||s==="canceling",Dt=s=>!!(s!=null&&s.preview_id&&Number(s.valid||0)>0),qt=s=>!!(s!=null&&s.id&&Number(s.retryable||0)>0&&!Ie(s.status)),Ut=(s,a)=>s===a,Te=s=>{switch(s){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return s||"-"}},Ke=s=>{switch(s){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},zt=s=>{const[a,x]=l.useState(!1),[o,d]=l.useState("upload"),[g,P]=l.useState(null),[f,L]=l.useState(null),[w,T]=l.useState(""),[K,J]=l.useState(!1),[R,G]=l.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[y,N]=l.useState(null),[c,_]=l.useState(null),[I,$]=l.useState(null),[V,D]=l.useState([]),[q,B]=l.useState(null),[U,p]=l.useState(!1),k=l.useRef(!1),m=l.useRef(0),A=l.useCallback(async()=>{d("upload"),N(null),_(null),P(null),L(null),T(""),G({catId:"",catName:"",channelCatId:"",tbCatId:""}),D([]),B(null),x(!0),p(!0);try{const r=await Ye(20),h=$t(r);if(h!=null&&h.id){const S=await ee(h.id);$(S),_(S),d(["running","canceling"].includes(S.status)?"running":"done")}}catch(r){console.error("恢复最近批量铺货任务失败:",r)}finally{p(!1)}},[]),u=l.useCallback(async()=>{const r=w.trim();if(!s.selectedAccount){alert("请先选择默认发布账号");return}if(!r){alert("请输入类目关键词");return}J(!0);try{const S=(await Bt(s.selectedAccount,r)).category;G({catId:S.cat_id,catName:S.cat_name,channelCatId:S.channel_cat_id,tbCatId:S.tb_cat_id||""})}catch(h){console.error("获取推荐类目失败:",h),alert((h==null?void 0:h.message)||"没有匹配到类目,请换一个更具体的关键词")}finally{J(!1)}},[w,s.selectedAccount]),M=l.useCallback(async()=>{if(I!=null&&I.id){p(!0),x(!0);try{const r=await ee(I.id);_(r),d(["running","canceling"].includes(r.status)?"running":"done")}catch(r){console.error("加载最近批量铺货结果失败:",r)}finally{p(!1)}}},[I==null?void 0:I.id]),se=l.useCallback(async()=>{if(!g){alert("请先上传商品表格");return}if(!s.selectedAccount){alert("请先选择默认发布账号");return}p(!0);try{const r=await Ft({file:g,imagesZip:f,defaultCookieId:s.selectedAccount,fallbackCategory:R,location:q||void 0});N(r),_(null),d("preview")}catch(r){console.error("批量铺货预检失败:",r),alert((r==null?void 0:r.message)||"预检失败,请检查表格和图片 zip")}finally{p(!1)}},[R,g,f,q,s.selectedAccount]),W=l.useCallback(async()=>{if(y!=null&&y.preview_id){if(!Dt(y)){alert("没有可发布的商品行");return}p(!0);try{const r=await Lt(y.preview_id),h=await ee(r.batch_id||y.preview_id);_(h),$(h),d(h.status==="running"?"running":"done")}catch(r){console.error("启动批量铺货失败:",r),alert((r==null?void 0:r.message)||"启动发布任务失败")}finally{p(!1)}}},[y]),Y=l.useCallback(async()=>{if(c!=null&&c.id&&confirm("确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。")){p(!0);try{const r=await Mt(c.id),h=await ee(c.id);_(h),d((r==null?void 0:r.status)==="canceling"||h.status==="canceling"?"running":"done")}catch(r){alert((r==null?void 0:r.message)||"取消失败")}finally{p(!1)}}},[c==null?void 0:c.id]),H=l.useCallback(async()=>{const r=y==null?void 0:y.preview_id;if(r&&o==="preview")try{await At(r)}catch(h){console.error("清理批量铺货预检失败:",h)}N(null),d("upload")},[o,y==null?void 0:y.preview_id]),Q=l.useCallback(async()=>{await H(),x(!1)},[H]),ae=l.useCallback(async()=>{if(!(!(c!=null&&c.id)||!qt(c))){p(!0);try{await Et(c.id),_(await ee(c.id)),d("running")}catch(r){alert((r==null?void 0:r.message)||"重试失败")}finally{p(!1)}}},[c]);return l.useEffect(()=>{if(!a||!(c!=null&&c.id)||!Ie(c.status))return;const r=++m.current,h=async()=>{if(!k.current){k.current=!0;try{const z=await ee(c.id);if(!Ut(r,m.current))return;_(z),$(z),Ie(z.status)||(d("done"),await Promise.all([s.loadItems(),s.loadShippingRules()]))}catch(z){console.error("刷新批量铺货进度失败:",z)}finally{k.current=!1}}},S=window.setInterval(()=>void h(),3e3);return(()=>{window.clearInterval(S),m.current+=1})},[c==null?void 0:c.id,c==null?void 0:c.status,s.loadItems,s.loadShippingRules,a]),{showBatchModal:a,setShowBatchModal:x,batchLoading:U,batchPhase:o,setBatchPhase:d,batchFile:g,setBatchFile:P,batchImagesZip:f,setBatchImagesZip:L,batchCategoryKeyword:w,setBatchCategoryKeyword:T,batchCategoryLoading:K,batchFallbackCategory:R,setBatchFallbackCategory:G,batchPreview:y,setBatchPreview:N,batchDetail:c,setBatchDetail:_,recentBatch:I,setRecentBatch:$,batchLocations:V,batchLocation:q,setBatchLocations:D,setBatchLocation:B,openBatchModal:A,handleRecommendBatchCategory:u,openRecentBatchResult:M,handlePreviewBatch:se,handleStartBatch:W,handleCancelBatch:Y,abandonBatchPreview:H,closeBatchModal:Q,handleRetryBatchFailed:ae}},Je=()=>({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),Ze=(s="")=>({cookie_id:s,title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),Ce=(s,a)=>{if(s instanceof Error)return s.message;const x=typeof s=="object"&&s!==null&&"message"in s?s.message:void 0;return typeof x=="string"?x:a},Ot=({selectedAccount:s,setSelectedAccount:a,setItems:x,loadItems:o,loadShippingRules:d,onConfigureDelivery:g,setBatchLocations:P,setBatchLocation:f})=>{const[L,w]=l.useState(!1),[T,K]=l.useState(!1),[J,R]=l.useState(!1),[G,y]=l.useState(!1),[N,c]=l.useState(!1),[_,I]=l.useState(!1),[$,V]=l.useState([]),[D,q]=l.useState(null),[B,U]=l.useState(null),[p,k]=l.useState({}),[m,A]=l.useState(Je),[u,M]=l.useState(Ze),[se,W]=l.useState([]);l.useEffect(()=>{if(!N||u.images.length===0){W([]);return}const i=u.images.map((j,C)=>({key:j.name+C,url:URL.createObjectURL(j)}));return W(i),(()=>i.forEach(j=>URL.revokeObjectURL(j.url)))},[u.images,N]);const Y=l.useCallback(async()=>{if(!s)return alert("请先选择账号");w(!0);try{const i=await Ct(s);await o(),alert((i==null?void 0:i.message)||"商品同步完成")}catch(i){console.error("同步商品失败:",i),alert(Ce(i,"同步失败,请重试"))}finally{w(!1)}},[o,s]),H=l.useCallback(i=>{U(i),k({...i}),R(!0)},[]),Q=l.useCallback(async()=>{if(B)try{await Rt(B.cookie_id,B.item_id,{item_title:p.item_title||"",item_description:p.item_description||"",item_category:p.item_category||"",item_price:p.item_price||"",item_detail:p.item_detail||B.item_detail||""}),await o(),await d(),R(!1),U(null)}catch(i){console.error("更新商品失败:",i),alert("更新失败,请重试")}},[p,o,d,B]),ae=l.useCallback(async i=>{if(confirm(`确认删除商品"${i.item_title}"吗?`))try{await It(i.cookie_id,i.item_id),x(j=>j.filter(C=>!(C.cookie_id===i.cookie_id&&C.item_id===i.item_id)))}catch(j){console.error("删除商品失败:",j),alert("删除失败,请重试")}},[x]),oe=l.useCallback(async()=>{try{if(!m.cookie_id||!m.item_id){alert("请选择账号并填写商品ID");return}await St(m.cookie_id,{item_id:m.item_id,item_title:m.item_title,item_price:m.item_price,item_detail:m.item_image?JSON.stringify({item_image:m.item_image}):""}),await o(),y(!1),A(Je())}catch(i){console.error("添加商品失败:",i),alert("添加失败,请重试")}},[m,o]),r=l.useCallback(async()=>{if(!u.cookie_id)return alert("请选择发布账号");if(!u.title.trim())return alert("请填写商品标题");if(!u.price.trim())return alert("请填写商品价格");if(!u.quantity||Number(u.quantity)<=0)return alert("库存数量必须大于 0");if(u.images.length===0)return alert("至少上传 1 张商品图片");if(u.postage_mode==="fixed"&&!u.postage.trim())return alert("请填写一口价邮费");K(!0);try{const i=await Pt({...u,location:D||void 0});if(await o(),c(!1),M(Ze(s||"")),V([]),q(null),i!=null&&i.item_id){const j={id:i.item_id,cookie_id:u.cookie_id,item_id:i.item_id,item_title:i.item_title||u.title,item_price:i.item_price||u.price,item_image:i.item_image};g(j),alert("商品发布成功,ID: "+i.item_id+",已为你打开发货规则配置")}else alert("商品发布成功")}catch(i){console.error("发布商品失败:",i);const j=i==null?void 0:i.payload;if((j==null?void 0:j.code)==="stock_permission_missing"){alert("发布失败:该账号没有库存发布权限,无法按库存数量发布商品。请换账号或先在闲鱼确认库存能力。");return}alert(Ce(i,"发布失败,请重试"))}finally{K(!1)}},[o,g,u,D,s]),h=l.useCallback(()=>{const C=[["账号ID","标题","描述","价格","原价","库存","邮费模式","邮费","图片","类目ID","类目名称","频道类目ID","淘宝类目ID","付款发货启用","付款发货内容","评价赠品启用","评价赠品内容","求评价启用","求评价等待小时","求评价文案","求评价最多次数"],...[["","会员组合包自动发货","下单后发送主卡和附赠卡。","19.90","29.90","10","free","","images/bundle-1.jpg;images/bundle-2.jpg","","","","","是","101:1;102:1","是","201:1;202:2","是","72","亲,满意的话麻烦给个评价,谢谢~","1"],["","普通商品","仅发布商品,不创建自动化规则。","49.90","","10","fixed","8.00","https://example.com/product.jpg","","","","","否","","否","","否","","",""]]].map(je=>je.map(Ne=>`"${String(Ne).replace(/"/g,'""')}"`).join(",")).join(`
`),F=new Blob(["\uFEFF"+C],{type:"text/csv;charset=utf-8"}),xe=URL.createObjectURL(F),X=document.createElement("a");X.href=xe,X.download="批量铺货模板.csv",document.body.appendChild(X),X.click(),X.remove(),URL.revokeObjectURL(xe)},[]),S=l.useCallback(()=>{A(i=>({...i,cookie_id:s||i.cookie_id})),y(!0)},[s]),z=l.useCallback(()=>{M(i=>({...i,cookie_id:s||i.cookie_id})),c(!0)},[s]),fe=l.useCallback(async i=>{if(!(i?s:u.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");I(!0),navigator.geolocation.getCurrentPosition(async C=>{try{const F=await _t(C.coords.longitude,C.coords.latitude);if(!F.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");i?(P(F),f(F[0])):(V(F),q(F[0]))}catch(F){alert(Ce(F,"获取发货地失败"))}finally{I(!1)}},C=>{I(!1),alert(C.code===C.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},[u.cookie_id,s,f,P]);return{selectedAccount:s,setSelectedAccount:a,loading:L,publishing:T,showEditModal:J,setShowEditModal:R,showAddModal:G,setShowAddModal:y,showPublishModal:N,setShowPublishModal:c,locationLoading:_,publishLocations:$,setPublishLocations:V,publishLocation:D,setPublishLocation:q,selectedItem:B,editForm:p,setEditForm:k,addForm:m,setAddForm:A,publishForm:u,setPublishForm:M,publishImagePreviews:se,handleSync:Y,handleEdit:H,handleSaveEdit:Q,handleDelete:ae,handleAddItem:oe,handlePublishItem:r,downloadPublishTemplate:h,openAddModal:S,openPublishModal:z,locateForPublish:fe}},Tt=({phase:s})=>{const a=[["upload","1 上传"],["preview","2 预检"],["running","3 发布"],["done","4 结果"]];return e.jsx("div",{className:"grid grid-cols-4 gap-2",children:a.map(([x,o])=>e.jsx("div",{className:`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${s===x?"bg-blue-600 text-white border-blue-600":"bg-gray-50 text-gray-500 border-gray-100"}`,children:o},x))})},Kt=s=>{const a=String(s||"").trim();return a?/^[¥¥]/.test(a)?a:`¥${a}`:"-"},Wt=({onConfigureDelivery:s})=>{const[a,x]=l.useState([]),[o,d]=l.useState([]),[g,P]=l.useState([]),[f,L]=l.useState(""),[w,T]=l.useState(""),K=l.useCallback(async()=>{const t=await Oe();x(t)},[]),J=l.useCallback(async()=>{d(await ze())},[]),R=zt({selectedAccount:f,loadItems:K,loadShippingRules:J}),{showBatchModal:G,setShowBatchModal:y,batchLoading:N,batchPhase:c,batchFile:_,setBatchFile:I,batchImagesZip:$,setBatchImagesZip:V,batchCategoryKeyword:D,setBatchCategoryKeyword:q,batchCategoryLoading:B,batchFallbackCategory:U,setBatchFallbackCategory:p,batchPreview:k,batchDetail:m,recentBatch:A,setRecentBatch:u,batchLocations:M,batchLocation:se,setBatchLocations:W,setBatchLocation:Y,openBatchModal:H,handleRecommendBatchCategory:Q,openRecentBatchResult:ae,handlePreviewBatch:oe,handleStartBatch:r,handleCancelBatch:h,abandonBatchPreview:S,closeBatchModal:z,handleRetryBatchFailed:fe}=R,i=Ot({selectedAccount:f,setSelectedAccount:L,setItems:x,loadItems:K,loadShippingRules:J,onConfigureDelivery:s,setBatchLocations:W,setBatchLocation:Y}),{loading:j,publishing:C,showEditModal:F,setShowEditModal:xe,showAddModal:X,setShowAddModal:je,showPublishModal:Ne,setShowPublishModal:He,locationLoading:me,publishLocations:he,setPublishLocations:Xe,publishLocation:Qe,setPublishLocation:Se,selectedItem:Pe,editForm:Z,setEditForm:ue,addForm:E,setAddForm:le,publishForm:b,setPublishForm:O,publishImagePreviews:Be,handleSync:et,handleEdit:tt,handleSaveEdit:st,handleDelete:at,handleAddItem:lt,handlePublishItem:it,downloadPublishTemplate:nt,openAddModal:rt,openPublishModal:ct,locateForPublish:Fe}=i;l.useEffect(()=>{Promise.all([kt(),Oe(),ze(),Ye(20)]).then(([t,n,v,ne])=>{P(t),x(n),d(v);const pe=ne.find(ve=>["running","canceling"].includes(ve.status))||ne.find(ve=>ve.status!=="preview");u(pe||null)}).catch(t=>console.error("加载商品配置失败:",t))},[]);const dt=t=>o.filter(n=>n.cookie_id===t.cookie_id&&n.item_id===t.item_id).length>0?o.filter(n=>n.cookie_id===t.cookie_id&&n.item_id===t.item_id):o.filter(n=>n.cookie_id===t.cookie_id&&!n.item_id),Le=l.useMemo(()=>new Map(g.map(t=>[t.id,t])),[g]),Ae=l.useMemo(()=>w?a.filter(t=>t.cookie_id===w):a,[w,a]),ie=t=>{const n=Le.get(t),v=(n==null?void 0:n.remark)||(n==null?void 0:n.nickname);return v?`${v} · ${t.slice(0,6)}`:`账号 ${t.slice(0,8)}`},Me=t=>{const n=Le.get(t);return(n==null?void 0:n.remark)||(n==null?void 0:n.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:w,onChange:(t=>T(t.target.value)),children:[e.jsx("option",{value:"",children:"全部账号"}),g.map(t=>e.jsx("option",{value:t.id,children:ie(t.id)},t.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(Ee,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:f,onChange:(t=>L(t.target.value)),children:[e.jsx("option",{value:"",children:"请选择账号"}),g.map(t=>e.jsx("option",{value:t.id,children:ie(t.id)},t.id))]})]})]}),e.jsxs("button",{onClick:et,disabled:j||!f,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(we,{className:`w-4 h-4 ${j?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:rt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(Re,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:ct,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(_e,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:(()=>void H()),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(be,{className:"w-4 h-4"}),A&&["running","canceling"].includes(A.status)?"继续批量任务":"批量铺货"]}),A&&!["running","canceling"].includes(A.status)&&e.jsx("button",{onClick:(()=>void ae()),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[Ae.map(t=>{const n=dt(t),v=n.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex flex-col",children:[e.jsxs("div",{className:"absolute top-2 right-2 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:[e.jsx("button",{onClick:(()=>tt(t)),className:"p-1.5 bg-white/90 backdrop-blur rounded-lg shadow-md text-gray-600 hover:bg-brand hover:text-white transition-colors",title:"编辑",children:e.jsx(mt,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:(()=>at(t)),className:"p-1.5 bg-white/90 backdrop-blur rounded-lg shadow-md hover:bg-red-100 text-red-500 transition-colors",title:"删除",children:e.jsx(ht,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"aspect-square bg-gray-100 rounded-xl mb-2.5 overflow-hidden relative",children:[t.item_image?e.jsx("img",{src:t.item_image,alt:"",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-300",children:e.jsx(ut,{className:"w-8 h-8"})}),e.jsx("div",{className:"absolute top-1.5 left-1.5 bg-black/50 backdrop-blur-md text-white text-[10px] font-bold px-1.5 py-0.5 rounded-md",children:Kt(t.item_price)})]}),e.jsx("h3",{className:"font-bold text-gray-900 line-clamp-2 text-xs mb-1.5 h-8 leading-4",children:t.item_title}),e.jsxs("div",{className:"mb-2 inline-flex min-w-0 max-w-full items-center gap-1 self-start rounded-md bg-blue-50 px-2 py-1 text-[10px] font-extrabold text-blue-700",title:Me(t.cookie_id),children:[e.jsx(Ee,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:Me(t.cookie_id)})]}),e.jsxs("div",{className:"flex justify-between items-center text-[10px] text-gray-500 mb-2",children:[e.jsxs("span",{className:"bg-gray-100 px-1.5 py-0.5 rounded truncate max-w-[80px]",children:["ID: ",t.item_id]}),e.jsxs("span",{className:`inline-flex items-center gap-1 font-bold ${v?"text-emerald-600":"text-amber-600"}`,children:[v?e.jsx($e,{className:"w-3 h-3"}):e.jsx(pt,{className:"w-3 h-3"}),v?`${n.length} 规则`:"未配置"]})]}),e.jsx("div",{className:"space-y-2 mt-auto",children:e.jsxs("button",{onClick:(()=>s(t)),className:`w-full flex items-center justify-between gap-1 px-2.5 py-2 rounded-lg text-[11px] font-extrabold transition-all ${v?"bg-gray-900 text-white hover:bg-black":"bg-brand text-white hover:bg-brand-highlight shadow-md shadow-blue-100"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(gt,{className:"w-3.5 h-3.5"}),v?"查看发货规则":"关联发货规则"]}),e.jsx(bt,{className:"w-3.5 h-3.5"})]})})]},`${t.cookie_id}-${t.item_id}`)}),Ae.length===0&&e.jsxs("div",{className:"col-span-full py-20 text-center text-gray-400",children:[e.jsx(yt,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),w?"该账号暂无商品数据":"暂无商品数据,请选择账号进行同步"]})]}),F&&Pe&&ge.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"560px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"编辑商品"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["ID: ",Pe.item_id]})]}),e.jsx("button",{onClick:(()=>xe(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(re,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-4",children:[e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"商品标题",value:Z.item_title||"",onChange:(t=>ue({...Z,item_title:t.target.value}))}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"价格",value:Z.item_price||"",onChange:(t=>ue({...Z,item_price:t.target.value}))}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"分类",value:Z.item_category||"",onChange:(t=>ue({...Z,item_category:t.target.value}))}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述",value:Z.item_description||"",onChange:(t=>ue({...Z,item_description:t.target.value}))})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:st,className:"w-full ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(ft,{className:"w-4 h-4"}),"保存"]})})]})}),document.body),X&&ge.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"720px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"添加商品"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"手动建立商品与自动发货规则的关联"})]}),e.jsx("button",{onClick:(()=>je(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(re,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"所属账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:E.cookie_id,onChange:(t=>le({...E,cookie_id:t.target.value})),children:[e.jsx("option",{value:"",children:"选择账号"}),g.map(t=>e.jsx("option",{value:t.id,children:ie(t.id)},t.id))]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品 ID"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"输入闲鱼商品 ID",value:E.item_id,onChange:(t=>le({...E,item_id:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品价格"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如 99.00",value:E.item_price,onChange:(t=>le({...E,item_price:t.target.value}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品标题"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"输入商品标题",value:E.item_title,onChange:(t=>le({...E,item_title:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"图片 URL"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"https://...",value:E.item_image,onChange:(t=>le({...E,item_image:t.target.value}))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:lt,className:"w-full ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Re,{className:"w-4 h-4"}),"添加商品"]})})]})}),document.body),Ne&&ge.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"820px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"发布商品到闲鱼"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"普通单规格发布;库存数量会写入闲鱼发布参数,用于判断账号库存能力。"})]}),e.jsx("button",{onClick:(()=>He(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(re,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx("div",{className:"rounded-2xl border border-amber-200 bg-amber-50 p-4 text-sm text-amber-800 leading-6",children:"发布时必须填写库存。若账号没有库存发布能力,后端会返回明确的“库存权限不足”错误,不会误报为普通发布失败。"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"发布账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:b.cookie_id,onChange:(t=>{O({...b,cookie_id:t.target.value}),Xe([]),Se(null)}),children:[e.jsx("option",{value:"",children:"选择账号"}),g.map(t=>e.jsx("option",{value:t.id,children:ie(t.id)},t.id))]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品标题"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:会员月卡自动发货",value:b.title,onChange:(t=>O({...b,title:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"库存数量"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",type:"number",min:"1",placeholder:"必须大于 0",value:b.quantity,onChange:(t=>O({...b,quantity:t.target.value}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品描述"}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述会用于自动识别类目;留空时使用标题",value:b.description,onChange:(t=>O({...b,description:t.target.value}))})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"售价"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"99.00",value:b.price,onChange:(t=>O({...b,price:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"原价(可选)"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"129.00",value:b.original_price,onChange:(t=>O({...b,original_price:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"运费方式"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:b.postage_mode,onChange:(t=>O({...b,postage_mode:t.target.value})),children:[e.jsx("option",{value:"free",children:"包邮"}),e.jsx("option",{value:"distance",children:"按距离计费"}),e.jsx("option",{value:"fixed",children:"一口价邮费"}),e.jsx("option",{value:"none",children:"无需邮寄"})]})]})]}),b.postage_mode==="fixed"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"一口价邮费"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如 8.00",value:b.postage,onChange:(t=>O({...b,postage:t.target.value}))})]}),e.jsxs("div",{className:"rounded-2xl border border-sky-200 bg-sky-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"发货地(可选)"}),e.jsx("p",{className:"mt-1 text-xs text-sky-800",children:"虚拟商品无需发货地;发布失败时可再定位并作为补充信息提交。"})]}),e.jsxs("button",{type:"button",disabled:me||!b.cookie_id,onClick:(()=>void Fe(!1)),className:"ios-btn-primary flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-bold disabled:opacity-50",children:[e.jsx(De,{className:"h-4 w-4"}),me?"定位中...":"获取当前位置"]})]}),he.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,he.indexOf(Qe))),onChange:(t=>Se(he[Number(t.target.value)]||null)),children:he.map((t,n)=>e.jsx("option",{value:String(n),children:[t.province,t.city,t.area,t.poi_name].filter(Boolean).join(" ")},`${t.division_id}-${t.poi_id}-${n}`))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品图片(1-9 张)"}),e.jsxs("label",{className:"flex min-h-[120px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-emerald-300 hover:bg-emerald-50/50 transition-colors",children:[e.jsx(be,{className:"w-8 h-8 text-emerald-600 mb-2"}),e.jsx("span",{className:"text-sm font-bold text-gray-800",children:"选择图片"}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:b.images.length?"已选择 "+b.images.length+" 张":"支持 JPG / PNG / GIF"}),e.jsx("input",{className:"hidden",type:"file",accept:"image/*",multiple:!0,onChange:(t=>O({...b,images:Array.from(t.target.files||[]).slice(0,9)}))})]}),Be.length>0&&e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-3",children:Be.map(t=>e.jsx("div",{className:"aspect-square rounded-xl bg-gray-100 overflow-hidden border border-gray-100",children:e.jsx("img",{src:t.url,alt:"",className:"w-full h-full object-cover"})},t.key))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{disabled:C,onClick:it,className:"w-full bg-emerald-500 hover:bg-emerald-600 disabled:opacity-60 text-white px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(_e,{className:"w-4 h-4"}),C?"正在发布...":"发布到闲鱼"]})})]})}),document.body),G&&ge.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"980px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量铺货"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"上传商品表格和图片 zip,先预检,再逐条发布到闲鱼。"})]}),e.jsx("button",{onClick:(()=>void z()),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(re,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx(Tt,{phase:c}),c==="upload"&&e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"rounded-2xl border border-blue-100 bg-blue-50 p-4 text-sm text-blue-900 leading-6",children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:"先下载模板,再按字段填写。"}),e.jsxs("div",{children:["图片字段写 zip 内相对路径,多个图片用英文分号分隔,例如 ",e.jsx("span",{className:"font-mono font-bold",children:"images/a.jpg;images/b.jpg"}),"。也支持直接填写图片 URL。"]})]}),e.jsx("button",{type:"button",onClick:nt,className:"shrink-0 rounded-xl bg-blue-600 px-4 py-2 text-sm font-extrabold text-white hover:bg-blue-700",children:"下载CSV模板"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"默认发布账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:f,onChange:(t=>{L(t.target.value),W([]),Y(null)}),children:[e.jsx("option",{value:"",children:"选择账号"}),g.map(t=>e.jsx("option",{value:t.id,children:ie(t.id)},t.id))]}),e.jsx("p",{className:"text-xs text-gray-500",children:"表格中“账号ID”为空时,会使用这里选择的账号。"})]}),e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50/70 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-extrabold text-gray-900",children:["默认类目 ",e.jsx("span",{className:"font-medium text-gray-500",children:"(可为空)"})]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-amber-800",children:"填写后优先使用该类目;留空时由闲鱼根据每件商品自动识别。仍无法识别时,系统最终使用“电子资料”兜底。"})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs("label",{className:"relative flex-1",children:[e.jsx("span",{className:"sr-only",children:"类目关键词"}),e.jsx(qe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"w-full ios-input rounded-xl bg-white py-2.5 pl-10 pr-3",placeholder:"输入关键词,例如:课程资料、设计素材",value:D,onChange:(t=>q(t.target.value)),onKeyDown:(t=>{t.key==="Enter"&&(t.preventDefault(),Q())})})]}),e.jsxs("button",{type:"button",disabled:!f||!D.trim()||B,onClick:(()=>void Q()),className:"ios-btn-primary flex min-h-[42px] items-center justify-center gap-2 rounded-xl px-4 text-sm font-bold disabled:opacity-50",children:[e.jsx(qe,{className:"h-4 w-4"}),B?"匹配中...":"获取类目"]})]}),U.catId?e.jsxs("div",{className:"flex min-h-[46px] items-center justify-between gap-3 border-t border-amber-200 pt-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-bold text-gray-900",children:[e.jsx($e,{className:"h-4 w-4 shrink-0 text-emerald-600"}),e.jsx("span",{className:"truncate",children:U.catName})]}),e.jsxs("div",{className:"mt-1 font-mono text-xs text-gray-500",children:["类目 ",U.catId," · 频道 ",U.channelCatId]})]}),e.jsx("button",{type:"button",title:"清除默认类目",onClick:(()=>p({catId:"",catName:"",channelCatId:"",tbCatId:""})),className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg text-gray-500 hover:bg-white hover:text-gray-900",children:e.jsx(re,{className:"h-4 w-4"})})]}):null]}),e.jsxs("div",{className:"rounded-xl border border-sky-200 bg-sky-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"批次发货地(可选)"}),e.jsx("p",{className:"mt-1 text-xs text-sky-800",children:"虚拟商品可留空;填写后整个批次使用同一个发货地,并随任务保存用于恢复和重试。"})]}),e.jsxs("button",{type:"button",disabled:me||!f,onClick:(()=>void Fe(!0)),className:"ios-btn-primary flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-bold disabled:opacity-50",children:[e.jsx(De,{className:"h-4 w-4"}),me?"定位中...":"获取当前位置"]})]}),M.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,M.indexOf(se))),onChange:(t=>Y(M[Number(t.target.value)]||null)),children:M.map((t,n)=>e.jsx("option",{value:String(n),children:[t.province,t.city,t.area,t.poi_name].filter(Boolean).join(" ")},`${t.division_id}-${t.poi_id}-${n}`))})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("label",{className:"flex min-h-[150px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-blue-300 hover:bg-blue-50 transition-colors",children:[e.jsx(be,{className:"w-9 h-9 text-blue-600 mb-3"}),e.jsx("span",{className:"text-sm font-extrabold text-gray-900",children:"上传商品表格"}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:_?_.name:"支持 .xlsx / .csv / .tsv"}),e.jsx("input",{className:"hidden",type:"file",accept:".xlsx,.csv,.tsv",onChange:(t=>{var n;return I(((n=t.target.files)==null?void 0:n[0])||null)})})]}),e.jsxs("label",{className:"flex min-h-[150px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-emerald-300 hover:bg-emerald-50 transition-colors",children:[e.jsx(be,{className:"w-9 h-9 text-emerald-600 mb-3"}),e.jsx("span",{className:"text-sm font-extrabold text-gray-900",children:"上传图片 zip(可选)"}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:$?$.name:"表格图片字段使用 zip 内相对路径"}),e.jsx("input",{className:"hidden",type:"file",accept:".zip",onChange:(t=>{var n;return V(((n=t.target.files)==null?void 0:n[0])||null)})})]})]}),e.jsxs("div",{className:"rounded-2xl bg-gray-50 border border-gray-100 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"字段说明"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"照着下面的“什么时候填写”处理即可。预检发现问题时,会指出具体哪一行需要修改。"})]}),e.jsxs("div",{className:"rounded-xl border border-blue-100 bg-blue-50 p-4 text-xs text-blue-950",children:[e.jsx("div",{className:"text-sm font-extrabold",children:"“付款后发送的卡密”怎么填"}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-3 lg:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg bg-white/80 p-3",children:[e.jsx("code",{className:"font-bold text-blue-700",children:"101"}),e.jsx("p",{className:"mt-1 leading-5",children:"从卡密组 101 立即发送 1 份。卡密组 ID 可以在“卡密库存”页面查看。"})]}),e.jsxs("div",{className:"rounded-lg bg-white/80 p-3",children:[e.jsx("code",{className:"font-bold text-blue-700",children:"101:2"}),e.jsx("p",{className:"mt-1 leading-5",children:"每购买 1 件,就从卡密组 101 发送 2 份。买家购买 3 件时会发送 6 份。"})]}),e.jsxs("div",{className:"rounded-lg bg-white/80 p-3",children:[e.jsx("code",{className:"font-bold text-blue-700",children:"101:1:0;102:2:3"}),e.jsx("p",{className:"mt-1 leading-5",children:"先立即发送卡密组 101 的 1 份,再等待 3 秒发送卡密组 102 的 2 份。"})]})]}),e.jsxs("p",{className:"mt-3 leading-5 text-blue-800",children:["每一组依次写“卡密组 ID : 每件发送几份 : 等待几秒”。份数不写时按 1 份处理,等待时间不写时立即发送。需要发送多种卡密时,用英文分号 ",e.jsx("code",{className:"font-bold",children:";"})," 隔开。"]})]}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-gray-100 bg-white",children:e.jsxs("table",{className:"w-full text-left text-xs",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"字段"}),e.jsx("th",{className:"px-3 py-2",children:"什么时候填写"}),e.jsx("th",{className:"px-3 py-2",children:"填写方法"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 text-gray-700",children:[["账号ID","需要覆盖默认账号时填写","上方默认发布账号为必选;本列留空时使用默认账号,填写后仅覆盖当前行"],["标题","每个商品都要填","填写买家能看到的商品标题"],["描述","可以留空","留空时会使用商品标题作为描述"],["价格","每个商品都要填","只填数字,例如 19.90"],["原价","可以留空","需要展示划线原价时填写,例如 29.90"],["库存","可以留空","留空按 1 件处理;填写时必须大于 0"],["邮费模式","可以留空","留空表示包邮;包邮填 free,固定邮费填 fixed"],["邮费","邮费模式填 fixed 时填写","只填数字,例如 8.00"],["图片","每个商品都要填","填写 zip 内图片路径或图片网址;多张图片用英文分号隔开"],["类目ID","需要指定当前行默认类目时填写","必须和“类目名称、频道类目ID”同时填写;优先于自动识别"],["类目名称","填写了“类目ID”时必填","填写该 ID 对应的准确类目名称"],["频道类目ID","覆盖类目时必填","必须填写闲鱼返回的准确频道类目 ID"],["淘宝类目ID","按闲鱼返回填写","“电子资料”无淘宝类目 ID,保持为空"],["付款发货启用","需要付款后自动发货时填写","填“是”表示开启;不需要时填“否”或留空"],["付款发货内容","“付款发货启用”填“是”时填写","从“卡密库存”页面取得卡密组 ID,按上方示例填写"],["评价赠品启用","需要评价赠品时填写","填“是”表示开启;不需要时填“否”或留空"],["评价赠品内容","“评价赠品启用”填“是”时填写","格式和付款发货内容相同,也可以同时发送多个卡密组"],["求评价启用","需要自动求评价时填写","填“是”表示开启;不需要时填“否”或留空"],["求评价等待小时","“求评价启用”填“是”时填写","填写等待小时数;留空按 72 小时处理"],["求评价文案","“求评价启用”填“是”时填写","填写要发送给买家的求评价消息"],["求评价最多次数","可以留空","留空只提醒 1 次"]].map(([t,n,v])=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-bold text-gray-900 whitespace-nowrap",children:t}),e.jsx("td",{className:`px-3 py-2 min-w-[210px] font-bold ${n==="每个商品都要填"?"text-red-600":n==="可以留空"?"text-gray-500":"text-amber-700"}`,children:n}),e.jsx("td",{className:"px-3 py-2 min-w-[260px]",children:v})]},t))})]})})]})]}),c==="preview"&&k&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-2xl bg-gray-50 p-4 border border-gray-100",children:[e.jsx("div",{className:"text-xs font-bold text-gray-500",children:"总行数"}),e.jsx("div",{className:"text-2xl font-extrabold text-gray-900 mt-1",children:k.total})]}),e.jsxs("div",{className:"rounded-2xl bg-emerald-50 p-4 border border-emerald-100",children:[e.jsx("div",{className:"text-xs font-bold text-emerald-700",children:"可发布"}),e.jsx("div",{className:"text-2xl font-extrabold text-emerald-700 mt-1",children:k.valid})]}),e.jsxs("div",{className:"rounded-2xl bg-red-50 p-4 border border-red-100",children:[e.jsx("div",{className:"text-xs font-bold text-red-700",children:"有问题"}),e.jsx("div",{className:"text-2xl font-extrabold text-red-700 mt-1",children:k.invalid})]})]}),e.jsx("div",{className:"max-h-[380px] overflow-y-auto rounded-2xl border border-gray-100",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-white text-xs text-gray-400 border-b border-gray-100",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"行号"}),e.jsx("th",{className:"px-4 py-3",children:"状态"}),e.jsx("th",{className:"px-4 py-3",children:"标题"}),e.jsx("th",{className:"px-4 py-3",children:"价格/库存"}),e.jsx("th",{className:"px-4 py-3",children:"类目策略"}),e.jsx("th",{className:"px-4 py-3",children:"图片"}),e.jsx("th",{className:"px-4 py-3",children:"问题"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:k.rows.map(t=>{var n,v,ne,pe;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:t.row_no}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex px-2 py-1 rounded-lg border text-xs font-extrabold ${t.valid?"bg-emerald-50 text-emerald-700 border-emerald-100":"bg-red-50 text-red-700 border-red-100"}`,children:t.valid?"可发布":"需修正"})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[240px] truncate",children:t.title||"-"}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:["¥",t.price||"-"," / ",t.quantity||1]}),e.jsxs("td",{className:"px-4 py-3 text-xs text-gray-600 min-w-[150px]",children:[e.jsx("div",{className:"font-bold text-gray-800",children:((n=t.category)==null?void 0:n.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((v=t.category)==null?void 0:v.cat_id)||"失败后使用电子资料"})]}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:[((ne=t.images)==null?void 0:ne.length)||0," 张"]}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[280px]",children:((pe=t.errors)==null?void 0:pe.join(";"))||"-"})]},t.row_no)})})]})})]}),(c==="running"||c==="done")&&m&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[e.jsxs("div",{className:`rounded-2xl p-4 border ${Ke(m.status)}`,children:[e.jsx("div",{className:"text-xs font-bold opacity-70",children:"任务状态"}),e.jsx("div",{className:"text-xl font-extrabold mt-1",children:Te(m.status)})]}),e.jsxs("div",{className:"rounded-2xl bg-gray-50 p-4 border border-gray-100",children:[e.jsx("div",{className:"text-xs font-bold text-gray-500",children:"总数"}),e.jsx("div",{className:"text-xl font-extrabold text-gray-900 mt-1",children:m.total})]}),e.jsxs("div",{className:"rounded-2xl bg-emerald-50 p-4 border border-emerald-100",children:[e.jsx("div",{className:"text-xs font-bold text-emerald-700",children:"成功"}),e.jsx("div",{className:"text-xl font-extrabold text-emerald-700 mt-1",children:m.success})]}),e.jsxs("div",{className:"rounded-2xl bg-red-50 p-4 border border-red-100",children:[e.jsx("div",{className:"text-xs font-bold text-red-700",children:"失败"}),e.jsx("div",{className:"text-xl font-extrabold text-red-700 mt-1",children:m.failed})]}),e.jsxs("div",{className:"rounded-2xl bg-blue-50 p-4 border border-blue-100",children:[e.jsx("div",{className:"text-xs font-bold text-blue-700",children:"等待"}),e.jsx("div",{className:"text-xl font-extrabold text-blue-700 mt-1",children:m.pending})]})]}),e.jsx("div",{className:"max-h-[420px] overflow-y-auto rounded-2xl border border-gray-100",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-white text-xs text-gray-400 border-b border-gray-100",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"行号"}),e.jsx("th",{className:"px-4 py-3",children:"状态"}),e.jsx("th",{className:"px-4 py-3",children:"标题"}),e.jsx("th",{className:"px-4 py-3",children:"类目策略"}),e.jsx("th",{className:"px-4 py-3",children:"商品ID"}),e.jsx("th",{className:"px-4 py-3",children:"错误原因"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:m.rows.map(t=>{var n,v;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:t.row_no}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex px-2 py-1 rounded-lg border text-xs font-extrabold ${Ke(t.status)}`,children:Te(t.status)})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[260px] truncate",children:t.title}),e.jsxs("td",{className:"px-4 py-3 text-xs text-gray-600 min-w-[150px]",children:[e.jsx("div",{className:"font-bold text-gray-800",children:((n=t.category)==null?void 0:n.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((v=t.category)==null?void 0:v.cat_id)||"失败后使用电子资料"})]}),e.jsx("td",{className:"px-4 py-3 text-xs font-mono",children:t.item_url?e.jsx("a",{href:t.item_url,target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline",children:t.item_id}):t.item_id||"-"}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[340px]",children:t.error_message||"-"})]},t.id)})})]})})]})]}),e.jsxs("div",{className:"modal-footer",children:[c==="upload"&&e.jsxs("button",{disabled:N||!_||!f,onClick:oe,className:"w-full ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(we,{className:`w-4 h-4 ${N?"animate-spin":""}`}),N?"正在预检...":"开始预检"]}),c==="preview"&&k&&e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{disabled:N,onClick:(()=>void S()),className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold",children:"返回修改"}),e.jsxs("button",{disabled:N||k.valid<=0,onClick:r,className:"flex-1 ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(_e,{className:"w-4 h-4"}),N?"启动中...":`确认发布 ${k.valid} 个商品`]})]}),(c==="running"||c==="done")&&m&&e.jsxs("div",{className:"flex gap-3 w-full",children:[m.status==="running"?e.jsx("button",{disabled:N,onClick:h,className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"取消任务"}):m.status==="canceling"?e.jsx("button",{disabled:!0,className:"flex-1 px-6 py-3.5 rounded-xl bg-amber-100 text-amber-800 font-bold",children:"正在保存远端结果并安全取消…"}):e.jsx("button",{onClick:(()=>window.open(`/api/v1/items/publish-batches/${m.id}/result.csv`,"_blank")),className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"下载结果"}),m.retryable>0&&!["running","canceling"].includes(m.status)&&e.jsxs("button",{disabled:N,onClick:fe,className:"flex-1 ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(we,{className:`w-4 h-4 ${N?"animate-spin":""}`}),"重试失败项"]}),!["running","canceling"].includes(m.status)&&e.jsx("button",{onClick:(()=>{y(!1),K(),J()}),className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold",children:"完成"})]})]})]})}),document.body)]})};export{Wt as default};
diff --git a/internal/webui/static/assets/Notifications-Dvclt-gX.js b/internal/webui/static/assets/Notifications-BXiIO06V.js
similarity index 99%
rename from internal/webui/static/assets/Notifications-Dvclt-gX.js
rename to internal/webui/static/assets/Notifications-BXiIO06V.js
index a0b6de7..c9c198d 100644
--- a/internal/webui/static/assets/Notifications-Dvclt-gX.js
+++ b/internal/webui/static/assets/Notifications-BXiIO06V.js
@@ -1 +1 @@
-import{j as e,b as _e,r as d}from"./react-vendor-C_od1ZSF.js";import{ai as ee,ah as se,aj as Ne,x as K,e as W,L as I,y as ve,F as ke,s as Q,X as te,u as ae,v as ne,r as we,R as Se,N as Ce}from"./icons-vendor-CvzvbbIV.js";import{g as re,p as le,a as oe,d as Te}from"./index-hByDAHGj.js";const H=["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from_name","smtp_from_address","smtp_use_tls","smtp_use_ssl"],G=(s,t)=>{if(typeof s=="boolean")return s;if(typeof s=="string"){if(["true","1","yes","on"].includes(s.toLowerCase()))return!0;if(["false","0","no","off"].includes(s.toLowerCase()))return!1}return t},ie=s=>{const t=Object.prototype.hasOwnProperty.call(s,"use_custom_smtp"),a=H.some(n=>String(s[n]??"").trim()!=="");return{...s,use_custom_smtp:t?G(s.use_custom_smtp,!1):a}},ce=(s,t)=>{const a={...s,use_custom_smtp:!0};for(const n of H)String(a[n]??"").trim()===""&&t[n]!==void 0&&(a[n]=t[n]);return a.smtp_port||(a.smtp_port=587),a.smtp_from_address||(a.smtp_from_address=a.smtp_user||""),a.smtp_use_tls=G(a.smtp_use_tls,!0),a.smtp_use_ssl=G(a.smtp_use_ssl,!1),a},de=s=>{const t=ie(s),a={to_email:String(t.to_email??"").trim(),use_custom_smtp:t.use_custom_smtp===!0};if(a.use_custom_smtp)for(const n of H)a[n]=t[n];return a},B={bark:{label:"Bark",icon:W,fields:[{key:"server_url",label:"Bark 服务器",placeholder:"https://api.day.app",required:!0},{key:"device_key",label:"Device Key",placeholder:"你的 Bark 设备 Key",required:!0},{key:"title",label:"标题(可选)",placeholder:"Ydisks闲鱼助手"},{key:"sound",label:"铃声(可选)",placeholder:"default"},{key:"group",label:"分组(可选)",placeholder:"xianyu"}],guide:{steps:["App Store 搜索并安装 Bark(免费)","打开 Bark App,首页会显示一条测试 URL,形如 https://api.day.app//这是测试推送内容","URL 路径里 那一段就是 Device Key,复制填入","服务器地址默认 https://api.day.app,自建服务端则填自建域名"],urlFormat:"https://api.day.app/<你的key>/测试内容",note:"不需要 secret,Device Key 本身就是唯一凭证。"}},dingtalk:{label:"钉钉机器人",icon:K,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://oapi.dingtalk.com/robot/send?access_token=...",required:!0},{key:"secret",label:"加签密钥",placeholder:"SEC...",help:"安全设置勾选「加签」后生成,SEC 开头"}],guide:{steps:["钉钉进入一个群(可建单人群)→ 右上角 群设置","机器人 → 添加机器人 → 选择「自定义机器人」","安全设置勾选「加签」","完成页同时展示 Webhook 地址和 SEC 开头的 Secret,两个都复制","Webhook URL 填上面,Secret 填加签密钥"],urlFormat:"https://oapi.dingtalk.com/robot/send?access_token=XXX",note:"加签密钥可选,但强烈建议启用,否则机器人可能被滥用。"}},feishu:{label:"飞书机器人",icon:K,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://open.feishu.cn/open-apis/bot/v2/hook/...",required:!0},{key:"secret",label:"签名校验密钥",placeholder:"sec-...",help:"安全设置选「签名校验」后生成"}],guide:{steps:["飞书进入目标群 → 右上角 更多 → 设置","群机器人 → 添加机器人 → 自定义机器人","安全设置选择「签名校验」,复制生成的秘钥","完成会给 Webhook 地址,复制","Webhook URL 填上面,秘钥填签名校验密钥"],urlFormat:"https://open.feishu.cn/open-apis/bot/v2/hook/xxx",note:"签名密钥可选,建议启用。频率限制:单机器人 100 次/分钟。"}},wechat:{label:"企业微信机器人",icon:K,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...",required:!0}],guide:{steps:["企业微信进入一个内部群 → 右上角 … → 群设置","找到「群机器人」(新版可能叫「消息推送」)","添加 → 选择自定义机器人","完成给 Webhook 地址(含 ?key=),复制填入"],urlFormat:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXX",note:"不需要 secret,URL 里的 key 就是唯一凭证,注意不要泄露。频率限制 20 条/分钟。"}},webhook:{label:"自定义 Webhook",icon:Ne,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://your-server/notify",required:!0}],guide:{steps:["仅适用于自己有服务器的用户:在你自己的机器上起一个 HTTP 接口收 JSON","系统会 POST 这个 URL,Content-Type: application/json","请求体固定为右侧 JSON 格式,按需解析 message 字段"],urlFormat:'{"message":"告警正文","timestamp":"2026-07-05 12:00:00","source":"xianyu-auto-reply"}',note:"若用 Server酱 / PushPlus 等第三方推送服务,格式不兼容,需写中间脚本转发,或改用对应专用渠道。"}},telegram:{label:"Telegram",icon:se,fields:[{key:"bot_token",label:"Bot Token",placeholder:"123456:ABC-DEF...",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"-1001234567890 或你的用户 ID",required:!0}],guide:{steps:["在 Telegram 搜索 @BotFather,发送 /newbot,按提示创建机器人,拿到 Bot Token","把你的 Bot 拉进一个群,或私聊它发一条消息","浏览器访问 https://api.telegram.org/bot<你的Token>/getUpdates",'从返回 JSON 里找 "chat":{"id":xxx},xxx 就是 Chat ID(群是负数,私聊是正数)'],urlFormat:"Bot Token: 123456:ABC-DEF... Chat ID: -1001234567890",note:"群聊需先把 Bot 设为管理员才能发消息。"}},email:{label:"邮件",icon:ee,fields:[{key:"to_email",label:"收件邮箱",placeholder:"receiver@example.com",required:!0}],guide:{steps:["通常先保存页面中的系统 SMTP 配置","邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP","只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置"],note:"继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。"}}},pe=[{value:"account_offline",label:"掉线通知",description:"账号过期、断线或登录态失效"},{value:"account_recovered",label:"恢复通知",description:"自动恢复成功并重新在线"},{value:"account_disabled",label:"禁用通知",description:"连续失败、账密错误等导致账号停用"},{value:"security_verification",label:"风控验证",description:"滑块、人脸、扫码验证等安全校验"},{value:"delivery_result",label:"交易通知",description:"订单发货、卡密发送等交易结果"},{value:"token_renewal",label:"续期通知",description:"Cookie/token 续期和自动恢复过程"},{value:"system_error",label:"系统错误",description:"后台任务或系统级异常"}],Y=()=>({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),Pe=s=>!s||s.length===0?"全部事件":s.map(t=>{var a;return((a=pe.find(n=>n.value===t))==null?void 0:a.label)||t}).join("、"),Ee=(s,t)=>{const a=s.type==="email"?ie({...s.config||{}}):null,n=a?a.use_custom_smtp===!0?ce(a,t):a:{...s.config||{}};return{name:s.name,type:s.type,enabled:s.enabled,config:n,event_types:s.event_types||[]}},Me=s=>{const a=B[s.type].fields.find(n=>n.required&&!String(s.config[n.key]||"").trim());if(a)return`请填写 ${a.label}`;if(!s.name.trim())return"请填写渠道名称";if(s.type==="email"){const n=de(s.config);if(n.use_custom_smtp){const k=[["smtp_server","独立 SMTP 服务器"],["smtp_port","独立 SMTP 端口"],["smtp_user","独立 SMTP 登录邮箱"],["smtp_password","独立 SMTP 密码 / 授权码"],["smtp_from_address","独立 SMTP 发件地址"]].find(([h])=>!String(n[h]||"").trim());if(k)return`请填写 ${k[1]}`}}return""},qe=s=>({name:s.name.trim(),type:s.type,config:s.type==="email"?de(s.config):s.config,event_types:s.event_types,enabled:s.enabled}),g=(s,t)=>s===t,O=(s,t)=>s instanceof Error&&s.message?s.message:t,Ae=({channels:s,testingId:t,onEdit:a,onDelete:n,onToggleEnabled:b,onTest:k})=>{const h=l=>s.find(o=>o.id===l.currentTarget.dataset.channelId)||null,_=l=>{const o=h(l);o&&b(o)},S=l=>{const o=h(l);o&&k(o)},E=l=>{const o=h(l);o&&a(o)},j=l=>{const o=h(l);o&&n(o)},M=l=>{const o=B[l.type]||B.webhook,P=o.icon;return e.jsxs("div",{className:"ios-card rounded-xl p-5 bg-white flex items-center gap-4",children:[e.jsx("div",{className:"w-11 h-11 rounded-xl bg-gray-100 flex items-center justify-center flex-shrink-0",children:e.jsx(P,{className:"w-5 h-5 text-gray-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-bold text-gray-900 truncate",children:l.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium",children:o.label}),!l.enabled&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium",children:"已停用"})]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 truncate",children:o.fields.map(x=>{var w;return(w=l.config)==null?void 0:w[x.key]}).filter(Boolean).map((x,w)=>e.jsx("span",{className:"mr-3",children:String(x).length>40?`${String(x).slice(0,40)}…`:String(x)},w))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",Pe(l.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{"data-channel-id":l.id,onClick:_,className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${l.enabled?"bg-green-50 text-green-700 hover:bg-green-100":"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:l.enabled?"启用中":"已停用"}),e.jsxs("button",{"data-channel-id":l.id,onClick:S,disabled:t===l.id,className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-brand hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50",children:[t===l.id?e.jsx(I,{className:"w-3 h-3 animate-spin"}):e.jsx(se,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{"data-channel-id":l.id,onClick:E,className:"w-8 h-8 rounded-lg bg-gray-100 hover:bg-gray-200 flex items-center justify-center text-gray-600 transition-colors",title:"编辑",children:e.jsx(ve,{className:"w-4 h-4"})}),e.jsx("button",{"data-channel-id":l.id,onClick:j,className:"w-8 h-8 rounded-lg bg-red-50 hover:bg-red-100 flex items-center justify-center text-red-500 transition-colors",title:"删除",children:e.jsx(ke,{className:"w-4 h-4"})})]})]},l.id)};return s.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(W,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-500 font-medium",children:"还没有配置任何通知渠道"}),e.jsx("p",{className:"text-gray-400 text-sm mt-1",children:"点击右上角「新建渠道」开始配置"})]}):e.jsx("div",{className:"space-y-3",children:s.map(M)})},Le=({selectedEvents:s,onToggleEvent:t})=>{const a=n=>{const b=n.currentTarget.dataset.event;b&&t(b)};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"通知内容"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"不选择表示接收全部通知;选择后仅接收勾选类型。"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:pe.map(n=>{const b=s.includes(n.value);return e.jsxs("button",{type:"button","data-event":n.value,onClick:a,className:`text-left rounded-xl border px-3 py-2.5 transition-colors ${b?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center ${b?"bg-brand border-brand":"border-gray-300"}`,children:b&&e.jsx(Q,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${b?"text-brand":"text-gray-800"}`,children:n.label})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 pl-6 leading-5",children:n.description})]},n.value)})})]})},Re=({showModal:s,editing:t,form:a,setForm:n,smtp:b,showChannelSmtpPassword:k,setShowChannelSmtpPassword:h,saving:_,onClose:S,onSave:E})=>{const j=B[a.type],M=r=>n(p=>({...p,name:r.target.value})),l=r=>{const p=r.currentTarget.dataset.type;p&&n(N=>({...N,type:p,config:{}}))},o=r=>{const p=r.currentTarget.dataset.field;p&&n(N=>({...N,config:{...N.config,[p]:r.target.value}}))},P=()=>n(r=>({...r,config:r.config.use_custom_smtp===!0?{...r.config,use_custom_smtp:!1}:ce(r.config,b)})),x=r=>n(p=>({...p,config:{...p.config,smtp_use_tls:r.target.checked,smtp_use_ssl:r.target.checked?!1:p.config.smtp_use_ssl}})),w=r=>n(p=>({...p,config:{...p.config,smtp_use_ssl:r.target.checked,smtp_use_tls:r.target.checked?!1:p.config.smtp_use_tls}})),U=r=>n(p=>({...p,event_types:p.event_types.includes(r)?p.event_types.filter(N=>N!==r):[...p.event_types,r]})),F=()=>n(r=>({...r,enabled:!r.enabled})),J=()=>h(r=>!r),X=(r,p)=>e.jsx("li",{children:r},p);return s?_e.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"36rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:t?"编辑通知渠道":"新建通知渠道"}),e.jsx("button",{onClick:S,className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(te,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5 overflow-y-auto flex-1 min-h-0",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道名称"}),e.jsx("input",{type:"text",value:a.name,onChange:M,placeholder:"例如:我的 Bark",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道类型"}),e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-2",children:Object.keys(B).map(r=>{const p=B[r],N=p.icon,q=a.type===r;return e.jsxs("button",{"data-type":r,type:"button",onClick:l,className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${q?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(N,{className:`w-5 h-5 ${q?"text-brand":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${q?"text-brand":"text-gray-600"}`,children:p.label})]},r)})})]}),e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-200 p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",j.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:j.guide.steps.map(X)}),j.guide.urlFormat&&e.jsxs("div",{className:"text-xs text-amber-900/90",children:[e.jsx("span",{className:"font-bold",children:"格式示例:"}),e.jsx("code",{className:"mt-1 block bg-amber-100/70 px-2.5 py-1.5 rounded-lg break-all font-mono text-[11px]",children:j.guide.urlFormat})]}),j.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",j.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:j.fields.map(r=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:[r.label,r.required&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),e.jsx("input",{"data-field":r.key,type:r.type==="password"?"password":r.type==="number"?"number":"text",value:String(a.config[r.key]||""),onChange:o,placeholder:r.placeholder,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),r.help&&e.jsx("p",{className:"text-xs text-gray-500",children:r.help})]},r.key))}),a.type==="email"&&e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-blue-100 bg-blue-50/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"SMTP 来源"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-gray-500",children:a.config.use_custom_smtp===!0?"当前渠道使用一套完整、独立的发件配置。":"当前渠道完整继承系统 SMTP,只单独设置收件邮箱。"})]}),e.jsx("button",{type:"button",onClick:P,className:`relative h-7 w-12 shrink-0 rounded-full transition-colors ${a.config.use_custom_smtp===!0?"bg-brand":"bg-gray-300"}`,"aria-label":"使用独立 SMTP",children:e.jsx("span",{className:`absolute left-1 top-1 h-5 w-5 rounded-full bg-white shadow-sm transition-transform ${a.config.use_custom_smtp===!0?"translate-x-5":""}`})})]}),a.config.use_custom_smtp===!0&&e.jsxs("div",{className:"space-y-4 border-t border-blue-100 bg-white/80 p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 服务器 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_server",type:"text",value:String(a.config.smtp_server||""),onChange:o,placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 端口 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_port",type:"number",value:String(a.config.smtp_port||587),onChange:o,placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["登录邮箱 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_user",type:"email",value:String(a.config.smtp_user||""),onChange:o,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["密码 / 授权码 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{"data-field":"smtp_password",type:k?"text":"password",value:String(a.config.smtp_password||""),onChange:o,placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:J,className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",children:k?e.jsx(ae,{className:"w-4 h-4"}):e.jsx(ne,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{"data-field":"smtp_from_name",type:"text",value:String(a.config.smtp_from_name||""),onChange:o,placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["发件邮箱地址 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_from_address",type:"email",value:String(a.config.smtp_from_address||""),onChange:o,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:a.config.smtp_use_tls!==!1,onChange:x}),"STARTTLS(常用于 587)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:a.config.smtp_use_ssl===!0,onChange:w}),"SSL/TLS 直连(常用于 465)"]})]})]})]}),e.jsx(Le,{selectedEvents:a.event_types,onToggleEvent:U}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("button",{type:"button",onClick:F,className:`relative w-11 h-6 rounded-full transition-colors ${a.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform ${a.enabled?"translate-x-5":""}`})}),e.jsx("span",{className:"text-sm font-bold text-gray-800",children:"启用此渠道"})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:S,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"取消"}),e.jsxs("button",{onClick:E,disabled:_,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[_?e.jsx(I,{className:"w-4 h-4 animate-spin"}):e.jsx(Q,{className:"w-4 h-4"}),_?"保存中...":"保存"]})]})]})}),document.body):null},Be=({smtp:s,setSmtp:t,smtpSaving:a,showPassword:n,setShowPassword:b,onSave:k})=>{const h=l=>{const o=l.currentTarget.dataset.field;o&&t(P=>({...P,[o]:l.target.value}))},_=l=>{t(o=>({...o,smtp_port:parseInt(l.target.value,10)||587}))},S=l=>{t(o=>({...o,smtp_use_tls:l.target.checked,smtp_use_ssl:l.target.checked?!1:o.smtp_use_ssl}))},E=l=>{t(o=>({...o,smtp_use_ssl:l.target.checked,smtp_use_tls:l.target.checked?!1:o.smtp_use_tls}))},j=l=>{t(o=>({...o,smtp_password:l.target.value}))},M=()=>b(l=>!l);return e.jsxs("section",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-extrabold text-gray-800",children:"SMTP 邮件配置"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"系统级邮件发送服务,供邮件通知渠道复用"})]}),e.jsx("div",{className:"p-2 rounded-xl bg-blue-50 text-blue-600",children:e.jsx(ee,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 服务器"}),e.jsx("input",{"data-field":"smtp_server",type:"text",value:s.smtp_server||"",onChange:h,placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 端口"}),e.jsx("input",{type:"number",value:s.smtp_port||587,onChange:_,placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱"}),e.jsx("input",{"data-field":"smtp_user",type:"email",value:s.smtp_user||"",onChange:h,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"邮箱密码 / 授权码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:n?"text":"password",value:s.smtp_password||"",onChange:j,placeholder:s.smtp_password_configured?"已配置,如需替换请输入新密码":"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:M,className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:n?e.jsx(ae,{className:"w-4 h-4"}):e.jsx(ne,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"QQ 邮箱需使用授权码(QQ 邮箱设置 → 账号 → 开启 SMTP → 生成授权码)"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{"data-field":"smtp_from_name",type:"text",value:s.smtp_from_name||"",onChange:h,placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱地址"}),e.jsx("input",{"data-field":"smtp_from_address",type:"email",value:s.smtp_from_address||s.smtp_user||"",onChange:h,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:s.smtp_use_tls!==!1,onChange:S}),"STARTTLS(常用于 587 端口)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:s.smtp_use_ssl===!0,onChange:E}),"SSL/TLS 直连(常用于 465 端口)"]})]}),e.jsxs("button",{onClick:k,disabled:a,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a?e.jsx(I,{className:"w-4 h-4 animate-spin"}):e.jsx(we,{className:"w-4 h-4"}),a?"保存中...":"保存 SMTP 配置"]})]})},$e=s=>{if(Array.isArray(s))return s.filter(Boolean);if(typeof s!="string"||!s.trim())return[];try{const t=JSON.parse(s);if(Array.isArray(t))return t.filter(Boolean)}catch{}return s.split(/[,\s;]+/).map(t=>t.trim()).filter(Boolean)},me=s=>{const t=Array.from(new Set((s||[]).filter(Boolean)));return t.length>0?JSON.stringify(t):""},Oe=s=>{let t={};try{const n=typeof s.config=="string"?JSON.parse(s.config):s.config;n&&typeof n=="object"&&!Array.isArray(n)&&(t=n)}catch{}const a=s.type==="ding_talk"?"dingtalk":s.type==="lark"?"feishu":s.type;return{id:String(s.id),name:s.name,type:a,config:t,event_types:$e(s.event_types),enabled:s.enabled,created_at:s.created_at,updated_at:s.updated_at}},Fe=async s=>{const t=await re("/api/v1/notifications/channels",void 0,s);return{success:!0,data:(Array.isArray(t)?t:t.data||t.channels||[]).map(Oe)}},De=async(s,t)=>oe("/api/v1/notifications/channels",{...s,config:JSON.stringify(s.config),event_types:me(s.event_types)},t),Z=async(s,t,a)=>{const n={...t};return"config"in t&&(n.config=JSON.stringify(t.config)),"event_types"in t&&(n.event_types=me(t.event_types)),le(`/api/v1/notifications/channels/${s}`,n,a)},We=async(s,t)=>Te(`/api/v1/notifications/channels/${s}`,void 0,t),Ie=async(s,t)=>oe(`/api/v1/notifications/channels/${s}/test`,{},t),Ue=s=>{const t={...s};if("renewal_log_retention_days"in t){const a=Number(t.renewal_log_retention_days);t.renewal_log_retention_days=Number.isFinite(a)?a:10}return t},Je=async s=>{const t=await re("/api/v1/settings/system",void 0,s);return Ue(t.data||t.settings||t)},Xe=async(s,t)=>le("/api/v1/settings/system",s,t),ze=s=>{const[t,a]=d.useState([]),[n,b]=d.useState(!0),[k,h]=d.useState(!1),[_,S]=d.useState(null),[E,j]=d.useState(!1),[M,l]=d.useState(""),[o,P]=d.useState(null),[x,w]=d.useState({}),[U,F]=d.useState(!1),[J,X]=d.useState(!1),[r,p]=d.useState(!1),[N,q]=d.useState(Y),$=d.useRef(0),z=d.useRef(null),C=d.useRef(0),L=d.useRef(null),y=d.useRef(0),T=d.useRef(null),R=d.useRef(null),f=d.useCallback((i,c)=>{P({type:i,text:c}),R.current!==null&&window.clearTimeout(R.current),R.current=window.setTimeout(()=>{R.current=null,P(null)},3e3)},[]),A=d.useCallback(async()=>{var m;const i=++$.current;(m=z.current)==null||m.abort();const c=new AbortController;z.current=c,b(!0);try{const u=await Fe({signal:c.signal});if(!g(i,$.current))return;a(u.data||[])}catch(u){g(i,$.current)&&!c.signal.aborted&&console.error("加载通知渠道失败",u)}finally{g(i,$.current)&&b(!1)}},[]),V=d.useCallback(async()=>{var m;const i=++C.current;(m=L.current)==null||m.abort();const c=new AbortController;L.current=c;try{const u=await Je({signal:c.signal});g(i,C.current)&&w(u||{})}catch(u){g(i,C.current)&&!c.signal.aborted&&console.error("加载 SMTP 配置失败",u)}},[]);d.useEffect(()=>{var i;return A(),s?V():(C.current+=1,(i=L.current)==null||i.abort(),w({})),(()=>{var c,m;$.current+=1,(c=z.current)==null||c.abort(),C.current+=1,(m=L.current)==null||m.abort()})},[s,A,V]),d.useEffect(()=>(()=>{R.current!==null&&window.clearTimeout(R.current)}),[]);const ue=d.useCallback(()=>{S(null),q(Y()),p(!1),h(!0)},[]),xe=d.useCallback(i=>{S(i),q(Ee(i,x)),p(!1),h(!0)},[x]),ge=d.useCallback(()=>{var i;y.current+=1,(i=T.current)==null||i.abort(),j(!1),h(!1)},[]),he=d.useCallback(async()=>{var u;const i=Me(N);if(i){f("error",i);return}const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m,j(!0);try{const v=qe(N);if(_?await Z(_.id,v,{signal:m.signal}):await De(v,{signal:m.signal}),!g(c,y.current)||(h(!1),await A(),!g(c,y.current)))return;f("success",_?"已更新":"已创建")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",O(v,"保存失败"))}finally{g(c,y.current)&&j(!1)}},[_,N,A,f]),be=d.useCallback(async i=>{var u;if(!confirm(`确认删除渠道「${i.name}」吗?已绑定该渠道的账号会自动解绑。`))return;const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{if(await We(i.id,{signal:m.signal}),!g(c,y.current)||(await A(),!g(c,y.current)))return;f("success","已删除")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",O(v,"删除失败"))}},[A,f]),ye=d.useCallback(async i=>{var u;const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{if(await Z(i.id,{enabled:!i.enabled},{signal:m.signal}),!g(c,y.current))return;a(v=>v.map(D=>D.id===i.id?{...D,enabled:!D.enabled}:D))}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",O(v,"切换失败"))}},[f]),fe=d.useCallback(async i=>{var u;l(i.id);const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{await Ie(i.id,{signal:m.signal}),g(c,y.current)&&f("success","测试通知已发送,请检查对应渠道")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",O(v,"发送失败"))}finally{g(c,y.current)&&l("")}},[f]),je=d.useCallback(async()=>{var m;const i=++C.current;(m=L.current)==null||m.abort();const c=new AbortController;L.current=c,F(!0);try{const u={smtp_server:x.smtp_server||"",smtp_port:x.smtp_port||587,smtp_user:x.smtp_user||"",smtp_from_name:x.smtp_from_name||"",smtp_from_address:x.smtp_from_address||x.smtp_user||"",smtp_use_tls:x.smtp_use_tls!==!1,smtp_use_ssl:x.smtp_use_ssl===!0};Object.prototype.hasOwnProperty.call(x,"smtp_password")&&(u.smtp_password=x.smtp_password),await Xe(u,{signal:c.signal}),g(i,C.current)&&f("success","SMTP 配置已保存")}catch(u){g(i,C.current)&&!c.signal.aborted&&f("error",O(u,"保存失败"))}finally{g(i,C.current)&&F(!1)}},[f,x]);return{channels:t,loading:n,showModal:k,editing:_,saving:E,testingId:M,toast:o,smtp:x,smtpSaving:U,showSmtpPassword:J,showChannelSmtpPassword:r,form:N,setForm:q,setSmtp:w,setShowSmtpPassword:X,setShowChannelSmtpPassword:p,loadChannels:A,openCreate:ue,openEdit:xe,closeModal:ge,showToast:f,handleSave:he,handleDelete:be,handleToggleEnabled:ye,handleTest:fe,handleSaveSmtp:je}},He=({isAdmin:s=!1})=>{const t=ze(s);return e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"通知设置"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"配置通知渠道,账号异常时主动推送告警"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:t.loadChannels,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Se,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:t.openCreate,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(Ce,{className:"w-4 h-4"}),"新建渠道"]})]})]}),e.jsx("div",{className:"ios-card rounded-xl p-5 bg-blue-50/50 border border-blue-100",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(W,{className:"w-5 h-5 text-brand mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-gray-700 leading-6",children:["配置通知渠道并在「账号管理 → 编辑」里绑定后,以下事件会主动推送到该账号绑定的渠道:",e.jsxs("ul",{className:"mt-2 space-y-1 text-gray-600",children:[e.jsxs("li",{children:["• ",e.jsx("strong",{children:"账号 session 失效"}),":系统正在尝试自动恢复(警告)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"自动恢复失败"}),":账号已停止,需人工处理(严重)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),t.loading?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(I,{className:"w-8 h-8 text-brand animate-spin"})}):e.jsx(Ae,{channels:t.channels,testingId:t.testingId,onEdit:t.openEdit,onDelete:t.handleDelete,onToggleEnabled:t.handleToggleEnabled,onTest:t.handleTest}),s&&e.jsx(Be,{smtp:t.smtp,setSmtp:t.setSmtp,smtpSaving:t.smtpSaving,showPassword:t.showSmtpPassword,setShowPassword:t.setShowSmtpPassword,onSave:t.handleSaveSmtp}),e.jsx(Re,{showModal:t.showModal,editing:t.editing,form:t.form,setForm:t.setForm,smtp:t.smtp,showChannelSmtpPassword:t.showChannelSmtpPassword,setShowChannelSmtpPassword:t.setShowChannelSmtpPassword,saving:t.saving,onClose:t.closeModal,onSave:t.handleSave}),t.toast&&e.jsxs("div",{className:`fixed bottom-8 left-1/2 -translate-x-1/2 z-[10000] px-5 py-3 rounded-xl shadow-lg font-bold text-sm flex items-center gap-2 animate-fade-in text-white ${t.toast.type==="success"?"bg-success-500":"bg-danger-500"}`,children:[t.toast.type==="success"?e.jsx(Q,{className:"w-4 h-4"}):e.jsx(te,{className:"w-4 h-4"}),t.toast.text]})]})};export{He as default};
+import{j as e,b as _e,r as d}from"./react-vendor-C_od1ZSF.js";import{ai as ee,ah as se,aj as Ne,x as K,e as W,L as I,y as ve,F as ke,s as Q,X as te,u as ae,v as ne,r as we,R as Se,N as Ce}from"./icons-vendor-CvzvbbIV.js";import{g as re,p as le,a as oe,d as Te}from"./index-CNzF_I4S.js";const H=["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from_name","smtp_from_address","smtp_use_tls","smtp_use_ssl"],G=(s,t)=>{if(typeof s=="boolean")return s;if(typeof s=="string"){if(["true","1","yes","on"].includes(s.toLowerCase()))return!0;if(["false","0","no","off"].includes(s.toLowerCase()))return!1}return t},ie=s=>{const t=Object.prototype.hasOwnProperty.call(s,"use_custom_smtp"),a=H.some(n=>String(s[n]??"").trim()!=="");return{...s,use_custom_smtp:t?G(s.use_custom_smtp,!1):a}},ce=(s,t)=>{const a={...s,use_custom_smtp:!0};for(const n of H)String(a[n]??"").trim()===""&&t[n]!==void 0&&(a[n]=t[n]);return a.smtp_port||(a.smtp_port=587),a.smtp_from_address||(a.smtp_from_address=a.smtp_user||""),a.smtp_use_tls=G(a.smtp_use_tls,!0),a.smtp_use_ssl=G(a.smtp_use_ssl,!1),a},de=s=>{const t=ie(s),a={to_email:String(t.to_email??"").trim(),use_custom_smtp:t.use_custom_smtp===!0};if(a.use_custom_smtp)for(const n of H)a[n]=t[n];return a},B={bark:{label:"Bark",icon:W,fields:[{key:"server_url",label:"Bark 服务器",placeholder:"https://api.day.app",required:!0},{key:"device_key",label:"Device Key",placeholder:"你的 Bark 设备 Key",required:!0},{key:"title",label:"标题(可选)",placeholder:"Ydisks闲鱼助手"},{key:"sound",label:"铃声(可选)",placeholder:"default"},{key:"group",label:"分组(可选)",placeholder:"xianyu"}],guide:{steps:["App Store 搜索并安装 Bark(免费)","打开 Bark App,首页会显示一条测试 URL,形如 https://api.day.app//这是测试推送内容","URL 路径里 那一段就是 Device Key,复制填入","服务器地址默认 https://api.day.app,自建服务端则填自建域名"],urlFormat:"https://api.day.app/<你的key>/测试内容",note:"不需要 secret,Device Key 本身就是唯一凭证。"}},dingtalk:{label:"钉钉机器人",icon:K,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://oapi.dingtalk.com/robot/send?access_token=...",required:!0},{key:"secret",label:"加签密钥",placeholder:"SEC...",help:"安全设置勾选「加签」后生成,SEC 开头"}],guide:{steps:["钉钉进入一个群(可建单人群)→ 右上角 群设置","机器人 → 添加机器人 → 选择「自定义机器人」","安全设置勾选「加签」","完成页同时展示 Webhook 地址和 SEC 开头的 Secret,两个都复制","Webhook URL 填上面,Secret 填加签密钥"],urlFormat:"https://oapi.dingtalk.com/robot/send?access_token=XXX",note:"加签密钥可选,但强烈建议启用,否则机器人可能被滥用。"}},feishu:{label:"飞书机器人",icon:K,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://open.feishu.cn/open-apis/bot/v2/hook/...",required:!0},{key:"secret",label:"签名校验密钥",placeholder:"sec-...",help:"安全设置选「签名校验」后生成"}],guide:{steps:["飞书进入目标群 → 右上角 更多 → 设置","群机器人 → 添加机器人 → 自定义机器人","安全设置选择「签名校验」,复制生成的秘钥","完成会给 Webhook 地址,复制","Webhook URL 填上面,秘钥填签名校验密钥"],urlFormat:"https://open.feishu.cn/open-apis/bot/v2/hook/xxx",note:"签名密钥可选,建议启用。频率限制:单机器人 100 次/分钟。"}},wechat:{label:"企业微信机器人",icon:K,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...",required:!0}],guide:{steps:["企业微信进入一个内部群 → 右上角 … → 群设置","找到「群机器人」(新版可能叫「消息推送」)","添加 → 选择自定义机器人","完成给 Webhook 地址(含 ?key=),复制填入"],urlFormat:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXX",note:"不需要 secret,URL 里的 key 就是唯一凭证,注意不要泄露。频率限制 20 条/分钟。"}},webhook:{label:"自定义 Webhook",icon:Ne,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://your-server/notify",required:!0}],guide:{steps:["仅适用于自己有服务器的用户:在你自己的机器上起一个 HTTP 接口收 JSON","系统会 POST 这个 URL,Content-Type: application/json","请求体固定为右侧 JSON 格式,按需解析 message 字段"],urlFormat:'{"message":"告警正文","timestamp":"2026-07-05 12:00:00","source":"xianyu-auto-reply"}',note:"若用 Server酱 / PushPlus 等第三方推送服务,格式不兼容,需写中间脚本转发,或改用对应专用渠道。"}},telegram:{label:"Telegram",icon:se,fields:[{key:"bot_token",label:"Bot Token",placeholder:"123456:ABC-DEF...",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"-1001234567890 或你的用户 ID",required:!0}],guide:{steps:["在 Telegram 搜索 @BotFather,发送 /newbot,按提示创建机器人,拿到 Bot Token","把你的 Bot 拉进一个群,或私聊它发一条消息","浏览器访问 https://api.telegram.org/bot<你的Token>/getUpdates",'从返回 JSON 里找 "chat":{"id":xxx},xxx 就是 Chat ID(群是负数,私聊是正数)'],urlFormat:"Bot Token: 123456:ABC-DEF... Chat ID: -1001234567890",note:"群聊需先把 Bot 设为管理员才能发消息。"}},email:{label:"邮件",icon:ee,fields:[{key:"to_email",label:"收件邮箱",placeholder:"receiver@example.com",required:!0}],guide:{steps:["通常先保存页面中的系统 SMTP 配置","邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP","只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置"],note:"继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。"}}},pe=[{value:"account_offline",label:"掉线通知",description:"账号过期、断线或登录态失效"},{value:"account_recovered",label:"恢复通知",description:"自动恢复成功并重新在线"},{value:"account_disabled",label:"禁用通知",description:"连续失败、账密错误等导致账号停用"},{value:"security_verification",label:"风控验证",description:"滑块、人脸、扫码验证等安全校验"},{value:"delivery_result",label:"交易通知",description:"订单发货、卡密发送等交易结果"},{value:"token_renewal",label:"续期通知",description:"Cookie/token 续期和自动恢复过程"},{value:"system_error",label:"系统错误",description:"后台任务或系统级异常"}],Y=()=>({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),Pe=s=>!s||s.length===0?"全部事件":s.map(t=>{var a;return((a=pe.find(n=>n.value===t))==null?void 0:a.label)||t}).join("、"),Ee=(s,t)=>{const a=s.type==="email"?ie({...s.config||{}}):null,n=a?a.use_custom_smtp===!0?ce(a,t):a:{...s.config||{}};return{name:s.name,type:s.type,enabled:s.enabled,config:n,event_types:s.event_types||[]}},Me=s=>{const a=B[s.type].fields.find(n=>n.required&&!String(s.config[n.key]||"").trim());if(a)return`请填写 ${a.label}`;if(!s.name.trim())return"请填写渠道名称";if(s.type==="email"){const n=de(s.config);if(n.use_custom_smtp){const k=[["smtp_server","独立 SMTP 服务器"],["smtp_port","独立 SMTP 端口"],["smtp_user","独立 SMTP 登录邮箱"],["smtp_password","独立 SMTP 密码 / 授权码"],["smtp_from_address","独立 SMTP 发件地址"]].find(([h])=>!String(n[h]||"").trim());if(k)return`请填写 ${k[1]}`}}return""},qe=s=>({name:s.name.trim(),type:s.type,config:s.type==="email"?de(s.config):s.config,event_types:s.event_types,enabled:s.enabled}),g=(s,t)=>s===t,O=(s,t)=>s instanceof Error&&s.message?s.message:t,Ae=({channels:s,testingId:t,onEdit:a,onDelete:n,onToggleEnabled:b,onTest:k})=>{const h=l=>s.find(o=>o.id===l.currentTarget.dataset.channelId)||null,_=l=>{const o=h(l);o&&b(o)},S=l=>{const o=h(l);o&&k(o)},E=l=>{const o=h(l);o&&a(o)},j=l=>{const o=h(l);o&&n(o)},M=l=>{const o=B[l.type]||B.webhook,P=o.icon;return e.jsxs("div",{className:"ios-card rounded-xl p-5 bg-white flex items-center gap-4",children:[e.jsx("div",{className:"w-11 h-11 rounded-xl bg-gray-100 flex items-center justify-center flex-shrink-0",children:e.jsx(P,{className:"w-5 h-5 text-gray-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-bold text-gray-900 truncate",children:l.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium",children:o.label}),!l.enabled&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium",children:"已停用"})]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 truncate",children:o.fields.map(x=>{var w;return(w=l.config)==null?void 0:w[x.key]}).filter(Boolean).map((x,w)=>e.jsx("span",{className:"mr-3",children:String(x).length>40?`${String(x).slice(0,40)}…`:String(x)},w))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",Pe(l.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{"data-channel-id":l.id,onClick:_,className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${l.enabled?"bg-green-50 text-green-700 hover:bg-green-100":"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:l.enabled?"启用中":"已停用"}),e.jsxs("button",{"data-channel-id":l.id,onClick:S,disabled:t===l.id,className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-brand hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50",children:[t===l.id?e.jsx(I,{className:"w-3 h-3 animate-spin"}):e.jsx(se,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{"data-channel-id":l.id,onClick:E,className:"w-8 h-8 rounded-lg bg-gray-100 hover:bg-gray-200 flex items-center justify-center text-gray-600 transition-colors",title:"编辑",children:e.jsx(ve,{className:"w-4 h-4"})}),e.jsx("button",{"data-channel-id":l.id,onClick:j,className:"w-8 h-8 rounded-lg bg-red-50 hover:bg-red-100 flex items-center justify-center text-red-500 transition-colors",title:"删除",children:e.jsx(ke,{className:"w-4 h-4"})})]})]},l.id)};return s.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(W,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-500 font-medium",children:"还没有配置任何通知渠道"}),e.jsx("p",{className:"text-gray-400 text-sm mt-1",children:"点击右上角「新建渠道」开始配置"})]}):e.jsx("div",{className:"space-y-3",children:s.map(M)})},Le=({selectedEvents:s,onToggleEvent:t})=>{const a=n=>{const b=n.currentTarget.dataset.event;b&&t(b)};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"通知内容"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"不选择表示接收全部通知;选择后仅接收勾选类型。"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:pe.map(n=>{const b=s.includes(n.value);return e.jsxs("button",{type:"button","data-event":n.value,onClick:a,className:`text-left rounded-xl border px-3 py-2.5 transition-colors ${b?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center ${b?"bg-brand border-brand":"border-gray-300"}`,children:b&&e.jsx(Q,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${b?"text-brand":"text-gray-800"}`,children:n.label})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 pl-6 leading-5",children:n.description})]},n.value)})})]})},Re=({showModal:s,editing:t,form:a,setForm:n,smtp:b,showChannelSmtpPassword:k,setShowChannelSmtpPassword:h,saving:_,onClose:S,onSave:E})=>{const j=B[a.type],M=r=>n(p=>({...p,name:r.target.value})),l=r=>{const p=r.currentTarget.dataset.type;p&&n(N=>({...N,type:p,config:{}}))},o=r=>{const p=r.currentTarget.dataset.field;p&&n(N=>({...N,config:{...N.config,[p]:r.target.value}}))},P=()=>n(r=>({...r,config:r.config.use_custom_smtp===!0?{...r.config,use_custom_smtp:!1}:ce(r.config,b)})),x=r=>n(p=>({...p,config:{...p.config,smtp_use_tls:r.target.checked,smtp_use_ssl:r.target.checked?!1:p.config.smtp_use_ssl}})),w=r=>n(p=>({...p,config:{...p.config,smtp_use_ssl:r.target.checked,smtp_use_tls:r.target.checked?!1:p.config.smtp_use_tls}})),U=r=>n(p=>({...p,event_types:p.event_types.includes(r)?p.event_types.filter(N=>N!==r):[...p.event_types,r]})),F=()=>n(r=>({...r,enabled:!r.enabled})),J=()=>h(r=>!r),X=(r,p)=>e.jsx("li",{children:r},p);return s?_e.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"36rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:t?"编辑通知渠道":"新建通知渠道"}),e.jsx("button",{onClick:S,className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(te,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5 overflow-y-auto flex-1 min-h-0",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道名称"}),e.jsx("input",{type:"text",value:a.name,onChange:M,placeholder:"例如:我的 Bark",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道类型"}),e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-2",children:Object.keys(B).map(r=>{const p=B[r],N=p.icon,q=a.type===r;return e.jsxs("button",{"data-type":r,type:"button",onClick:l,className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${q?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(N,{className:`w-5 h-5 ${q?"text-brand":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${q?"text-brand":"text-gray-600"}`,children:p.label})]},r)})})]}),e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-200 p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",j.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:j.guide.steps.map(X)}),j.guide.urlFormat&&e.jsxs("div",{className:"text-xs text-amber-900/90",children:[e.jsx("span",{className:"font-bold",children:"格式示例:"}),e.jsx("code",{className:"mt-1 block bg-amber-100/70 px-2.5 py-1.5 rounded-lg break-all font-mono text-[11px]",children:j.guide.urlFormat})]}),j.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",j.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:j.fields.map(r=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:[r.label,r.required&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),e.jsx("input",{"data-field":r.key,type:r.type==="password"?"password":r.type==="number"?"number":"text",value:String(a.config[r.key]||""),onChange:o,placeholder:r.placeholder,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),r.help&&e.jsx("p",{className:"text-xs text-gray-500",children:r.help})]},r.key))}),a.type==="email"&&e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-blue-100 bg-blue-50/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"SMTP 来源"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-gray-500",children:a.config.use_custom_smtp===!0?"当前渠道使用一套完整、独立的发件配置。":"当前渠道完整继承系统 SMTP,只单独设置收件邮箱。"})]}),e.jsx("button",{type:"button",onClick:P,className:`relative h-7 w-12 shrink-0 rounded-full transition-colors ${a.config.use_custom_smtp===!0?"bg-brand":"bg-gray-300"}`,"aria-label":"使用独立 SMTP",children:e.jsx("span",{className:`absolute left-1 top-1 h-5 w-5 rounded-full bg-white shadow-sm transition-transform ${a.config.use_custom_smtp===!0?"translate-x-5":""}`})})]}),a.config.use_custom_smtp===!0&&e.jsxs("div",{className:"space-y-4 border-t border-blue-100 bg-white/80 p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 服务器 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_server",type:"text",value:String(a.config.smtp_server||""),onChange:o,placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 端口 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_port",type:"number",value:String(a.config.smtp_port||587),onChange:o,placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["登录邮箱 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_user",type:"email",value:String(a.config.smtp_user||""),onChange:o,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["密码 / 授权码 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{"data-field":"smtp_password",type:k?"text":"password",value:String(a.config.smtp_password||""),onChange:o,placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:J,className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",children:k?e.jsx(ae,{className:"w-4 h-4"}):e.jsx(ne,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{"data-field":"smtp_from_name",type:"text",value:String(a.config.smtp_from_name||""),onChange:o,placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["发件邮箱地址 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{"data-field":"smtp_from_address",type:"email",value:String(a.config.smtp_from_address||""),onChange:o,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:a.config.smtp_use_tls!==!1,onChange:x}),"STARTTLS(常用于 587)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:a.config.smtp_use_ssl===!0,onChange:w}),"SSL/TLS 直连(常用于 465)"]})]})]})]}),e.jsx(Le,{selectedEvents:a.event_types,onToggleEvent:U}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("button",{type:"button",onClick:F,className:`relative w-11 h-6 rounded-full transition-colors ${a.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform ${a.enabled?"translate-x-5":""}`})}),e.jsx("span",{className:"text-sm font-bold text-gray-800",children:"启用此渠道"})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:S,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"取消"}),e.jsxs("button",{onClick:E,disabled:_,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[_?e.jsx(I,{className:"w-4 h-4 animate-spin"}):e.jsx(Q,{className:"w-4 h-4"}),_?"保存中...":"保存"]})]})]})}),document.body):null},Be=({smtp:s,setSmtp:t,smtpSaving:a,showPassword:n,setShowPassword:b,onSave:k})=>{const h=l=>{const o=l.currentTarget.dataset.field;o&&t(P=>({...P,[o]:l.target.value}))},_=l=>{t(o=>({...o,smtp_port:parseInt(l.target.value,10)||587}))},S=l=>{t(o=>({...o,smtp_use_tls:l.target.checked,smtp_use_ssl:l.target.checked?!1:o.smtp_use_ssl}))},E=l=>{t(o=>({...o,smtp_use_ssl:l.target.checked,smtp_use_tls:l.target.checked?!1:o.smtp_use_tls}))},j=l=>{t(o=>({...o,smtp_password:l.target.value}))},M=()=>b(l=>!l);return e.jsxs("section",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-extrabold text-gray-800",children:"SMTP 邮件配置"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"系统级邮件发送服务,供邮件通知渠道复用"})]}),e.jsx("div",{className:"p-2 rounded-xl bg-blue-50 text-blue-600",children:e.jsx(ee,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 服务器"}),e.jsx("input",{"data-field":"smtp_server",type:"text",value:s.smtp_server||"",onChange:h,placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 端口"}),e.jsx("input",{type:"number",value:s.smtp_port||587,onChange:_,placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱"}),e.jsx("input",{"data-field":"smtp_user",type:"email",value:s.smtp_user||"",onChange:h,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"邮箱密码 / 授权码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:n?"text":"password",value:s.smtp_password||"",onChange:j,placeholder:s.smtp_password_configured?"已配置,如需替换请输入新密码":"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:M,className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:n?e.jsx(ae,{className:"w-4 h-4"}):e.jsx(ne,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"QQ 邮箱需使用授权码(QQ 邮箱设置 → 账号 → 开启 SMTP → 生成授权码)"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{"data-field":"smtp_from_name",type:"text",value:s.smtp_from_name||"",onChange:h,placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱地址"}),e.jsx("input",{"data-field":"smtp_from_address",type:"email",value:s.smtp_from_address||s.smtp_user||"",onChange:h,placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:s.smtp_use_tls!==!1,onChange:S}),"STARTTLS(常用于 587 端口)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:s.smtp_use_ssl===!0,onChange:E}),"SSL/TLS 直连(常用于 465 端口)"]})]}),e.jsxs("button",{onClick:k,disabled:a,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a?e.jsx(I,{className:"w-4 h-4 animate-spin"}):e.jsx(we,{className:"w-4 h-4"}),a?"保存中...":"保存 SMTP 配置"]})]})},$e=s=>{if(Array.isArray(s))return s.filter(Boolean);if(typeof s!="string"||!s.trim())return[];try{const t=JSON.parse(s);if(Array.isArray(t))return t.filter(Boolean)}catch{}return s.split(/[,\s;]+/).map(t=>t.trim()).filter(Boolean)},me=s=>{const t=Array.from(new Set((s||[]).filter(Boolean)));return t.length>0?JSON.stringify(t):""},Oe=s=>{let t={};try{const n=typeof s.config=="string"?JSON.parse(s.config):s.config;n&&typeof n=="object"&&!Array.isArray(n)&&(t=n)}catch{}const a=s.type==="ding_talk"?"dingtalk":s.type==="lark"?"feishu":s.type;return{id:String(s.id),name:s.name,type:a,config:t,event_types:$e(s.event_types),enabled:s.enabled,created_at:s.created_at,updated_at:s.updated_at}},Fe=async s=>{const t=await re("/api/v1/notifications/channels",void 0,s);return{success:!0,data:(Array.isArray(t)?t:t.data||t.channels||[]).map(Oe)}},De=async(s,t)=>oe("/api/v1/notifications/channels",{...s,config:JSON.stringify(s.config),event_types:me(s.event_types)},t),Z=async(s,t,a)=>{const n={...t};return"config"in t&&(n.config=JSON.stringify(t.config)),"event_types"in t&&(n.event_types=me(t.event_types)),le(`/api/v1/notifications/channels/${s}`,n,a)},We=async(s,t)=>Te(`/api/v1/notifications/channels/${s}`,void 0,t),Ie=async(s,t)=>oe(`/api/v1/notifications/channels/${s}/test`,{},t),Ue=s=>{const t={...s};if("renewal_log_retention_days"in t){const a=Number(t.renewal_log_retention_days);t.renewal_log_retention_days=Number.isFinite(a)?a:10}return t},Je=async s=>{const t=await re("/api/v1/settings/system",void 0,s);return Ue(t.data||t.settings||t)},Xe=async(s,t)=>le("/api/v1/settings/system",s,t),ze=s=>{const[t,a]=d.useState([]),[n,b]=d.useState(!0),[k,h]=d.useState(!1),[_,S]=d.useState(null),[E,j]=d.useState(!1),[M,l]=d.useState(""),[o,P]=d.useState(null),[x,w]=d.useState({}),[U,F]=d.useState(!1),[J,X]=d.useState(!1),[r,p]=d.useState(!1),[N,q]=d.useState(Y),$=d.useRef(0),z=d.useRef(null),C=d.useRef(0),L=d.useRef(null),y=d.useRef(0),T=d.useRef(null),R=d.useRef(null),f=d.useCallback((i,c)=>{P({type:i,text:c}),R.current!==null&&window.clearTimeout(R.current),R.current=window.setTimeout(()=>{R.current=null,P(null)},3e3)},[]),A=d.useCallback(async()=>{var m;const i=++$.current;(m=z.current)==null||m.abort();const c=new AbortController;z.current=c,b(!0);try{const u=await Fe({signal:c.signal});if(!g(i,$.current))return;a(u.data||[])}catch(u){g(i,$.current)&&!c.signal.aborted&&console.error("加载通知渠道失败",u)}finally{g(i,$.current)&&b(!1)}},[]),V=d.useCallback(async()=>{var m;const i=++C.current;(m=L.current)==null||m.abort();const c=new AbortController;L.current=c;try{const u=await Je({signal:c.signal});g(i,C.current)&&w(u||{})}catch(u){g(i,C.current)&&!c.signal.aborted&&console.error("加载 SMTP 配置失败",u)}},[]);d.useEffect(()=>{var i;return A(),s?V():(C.current+=1,(i=L.current)==null||i.abort(),w({})),(()=>{var c,m;$.current+=1,(c=z.current)==null||c.abort(),C.current+=1,(m=L.current)==null||m.abort()})},[s,A,V]),d.useEffect(()=>(()=>{R.current!==null&&window.clearTimeout(R.current)}),[]);const ue=d.useCallback(()=>{S(null),q(Y()),p(!1),h(!0)},[]),xe=d.useCallback(i=>{S(i),q(Ee(i,x)),p(!1),h(!0)},[x]),ge=d.useCallback(()=>{var i;y.current+=1,(i=T.current)==null||i.abort(),j(!1),h(!1)},[]),he=d.useCallback(async()=>{var u;const i=Me(N);if(i){f("error",i);return}const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m,j(!0);try{const v=qe(N);if(_?await Z(_.id,v,{signal:m.signal}):await De(v,{signal:m.signal}),!g(c,y.current)||(h(!1),await A(),!g(c,y.current)))return;f("success",_?"已更新":"已创建")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",O(v,"保存失败"))}finally{g(c,y.current)&&j(!1)}},[_,N,A,f]),be=d.useCallback(async i=>{var u;if(!confirm(`确认删除渠道「${i.name}」吗?已绑定该渠道的账号会自动解绑。`))return;const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{if(await We(i.id,{signal:m.signal}),!g(c,y.current)||(await A(),!g(c,y.current)))return;f("success","已删除")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",O(v,"删除失败"))}},[A,f]),ye=d.useCallback(async i=>{var u;const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{if(await Z(i.id,{enabled:!i.enabled},{signal:m.signal}),!g(c,y.current))return;a(v=>v.map(D=>D.id===i.id?{...D,enabled:!D.enabled}:D))}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",O(v,"切换失败"))}},[f]),fe=d.useCallback(async i=>{var u;l(i.id);const c=++y.current;(u=T.current)==null||u.abort();const m=new AbortController;T.current=m;try{await Ie(i.id,{signal:m.signal}),g(c,y.current)&&f("success","测试通知已发送,请检查对应渠道")}catch(v){g(c,y.current)&&!m.signal.aborted&&f("error",O(v,"发送失败"))}finally{g(c,y.current)&&l("")}},[f]),je=d.useCallback(async()=>{var m;const i=++C.current;(m=L.current)==null||m.abort();const c=new AbortController;L.current=c,F(!0);try{const u={smtp_server:x.smtp_server||"",smtp_port:x.smtp_port||587,smtp_user:x.smtp_user||"",smtp_from_name:x.smtp_from_name||"",smtp_from_address:x.smtp_from_address||x.smtp_user||"",smtp_use_tls:x.smtp_use_tls!==!1,smtp_use_ssl:x.smtp_use_ssl===!0};Object.prototype.hasOwnProperty.call(x,"smtp_password")&&(u.smtp_password=x.smtp_password),await Xe(u,{signal:c.signal}),g(i,C.current)&&f("success","SMTP 配置已保存")}catch(u){g(i,C.current)&&!c.signal.aborted&&f("error",O(u,"保存失败"))}finally{g(i,C.current)&&F(!1)}},[f,x]);return{channels:t,loading:n,showModal:k,editing:_,saving:E,testingId:M,toast:o,smtp:x,smtpSaving:U,showSmtpPassword:J,showChannelSmtpPassword:r,form:N,setForm:q,setSmtp:w,setShowSmtpPassword:X,setShowChannelSmtpPassword:p,loadChannels:A,openCreate:ue,openEdit:xe,closeModal:ge,showToast:f,handleSave:he,handleDelete:be,handleToggleEnabled:ye,handleTest:fe,handleSaveSmtp:je}},He=({isAdmin:s=!1})=>{const t=ze(s);return e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"通知设置"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"配置通知渠道,账号异常时主动推送告警"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:t.loadChannels,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Se,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:t.openCreate,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(Ce,{className:"w-4 h-4"}),"新建渠道"]})]})]}),e.jsx("div",{className:"ios-card rounded-xl p-5 bg-blue-50/50 border border-blue-100",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(W,{className:"w-5 h-5 text-brand mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-gray-700 leading-6",children:["配置通知渠道并在「账号管理 → 编辑」里绑定后,以下事件会主动推送到该账号绑定的渠道:",e.jsxs("ul",{className:"mt-2 space-y-1 text-gray-600",children:[e.jsxs("li",{children:["• ",e.jsx("strong",{children:"账号 session 失效"}),":系统正在尝试自动恢复(警告)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"自动恢复失败"}),":账号已停止,需人工处理(严重)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),t.loading?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(I,{className:"w-8 h-8 text-brand animate-spin"})}):e.jsx(Ae,{channels:t.channels,testingId:t.testingId,onEdit:t.openEdit,onDelete:t.handleDelete,onToggleEnabled:t.handleToggleEnabled,onTest:t.handleTest}),s&&e.jsx(Be,{smtp:t.smtp,setSmtp:t.setSmtp,smtpSaving:t.smtpSaving,showPassword:t.showSmtpPassword,setShowPassword:t.setShowSmtpPassword,onSave:t.handleSaveSmtp}),e.jsx(Re,{showModal:t.showModal,editing:t.editing,form:t.form,setForm:t.setForm,smtp:t.smtp,showChannelSmtpPassword:t.showChannelSmtpPassword,setShowChannelSmtpPassword:t.setShowChannelSmtpPassword,saving:t.saving,onClose:t.closeModal,onSave:t.handleSave}),t.toast&&e.jsxs("div",{className:`fixed bottom-8 left-1/2 -translate-x-1/2 z-[10000] px-5 py-3 rounded-xl shadow-lg font-bold text-sm flex items-center gap-2 animate-fade-in text-white ${t.toast.type==="success"?"bg-success-500":"bg-danger-500"}`,children:[t.toast.type==="success"?e.jsx(Q,{className:"w-4 h-4"}):e.jsx(te,{className:"w-4 h-4"}),t.toast.text]})]})};export{He as default};
diff --git a/internal/webui/static/assets/OrderList-BAnpJSM4.js b/internal/webui/static/assets/OrderList-DMp8cMZ2.js
similarity index 99%
rename from internal/webui/static/assets/OrderList-BAnpJSM4.js
rename to internal/webui/static/assets/OrderList-DMp8cMZ2.js
index 28874e7..6a0a1ce 100644
--- a/internal/webui/static/assets/OrderList-BAnpJSM4.js
+++ b/internal/webui/static/assets/OrderList-DMp8cMZ2.js
@@ -1 +1 @@
-import{j as e,b as J,r as a}from"./react-vendor-C_od1ZSF.js";import{U as te,I as re,X as W,J as ne,R as H,N as ie,O as Y,m as Z,E as ce,v as oe,V as de,F as xe,h as me,g as ue,r as he}from"./icons-vendor-CvzvbbIV.js";import{g as X,b as ae,a as K,p as ge,d as pe}from"./index-hByDAHGj.js";import{o as be,c as ye}from"./contract-COFcZjyb.js";import{f as ee}from"./dateTime-DDi7rqpW.js";const fe=[{key:"all",label:"全部"},{key:"processing",label:"处理中"},{key:"shipped",label:"已发货"},{key:"pending_ship",label:"待发货"},{key:"completed",label:"已完成"},{key:"cancelled",label:"已取消"},{key:"refunding",label:"退款中"}],je=s=>{const t=typeof s=="object"&&s!==null?s:{},c=Array.isArray(t.results)?t.results:[];return{total:Number(t.total||0),success_count:Number(t.success_count||0),failed_count:Number(t.failed_count||0),results:c.map(ve)}},ve=s=>{const t=typeof s=="object"&&s!==null?s:{};return{order_id:String(t.order_id||"unknown"),success:t.success===!0,message:String(t.message||"")}},Ne=s=>(s==null?void 0:s.results.filter(we))||[],we=s=>!s.success,_e=(s,t)=>s!==null&&!t,ke=s=>{if(!s)return"请选择订单文件";const t=s.name.toLowerCase().split(".").pop()||"";return["xlsx","csv","tsv","json"].includes(t)?"":"仅支持 .xlsx、.csv、.tsv、.json 格式"},T=(s,t)=>s===t,Ce=(s,t)=>s instanceof Error&&s.message?s.message:t,Se=({filter:s,onFilterChange:t,accountFilter:c,onAccountFilterChange:h,accounts:g,accountName:m,searchText:u,onSearchChange:p})=>{const b=r=>t(r.currentTarget.dataset.status||"all"),_=r=>h(r.target.value),y=r=>p(r.target.value);return e.jsxs("div",{className:"p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted",children:[e.jsx("div",{className:"flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full",children:fe.map(r=>e.jsx("button",{"data-status":r.key,onClick:b,className:`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${s===r.key?"bg-white text-black shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:r.label},r.key))}),e.jsxs("div",{className:"flex w-full md:w-auto flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(te,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{"aria-label":"按账号筛选订单",value:c,onChange:_,className:"ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm",children:[e.jsx("option",{value:"",children:"全部账号"}),g.map(r=>e.jsx("option",{value:r.id,children:m(r.id)},r.id))]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(re,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors"}),e.jsx("input",{type:"text",placeholder:"搜索订单号/商品/买家...",value:u,onChange:y,className:"ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"})]})]})]})},Ee=s=>{const t=m=>{var u;s.setImportFile(((u=m.target.files)==null?void 0:u[0])||null)},c=()=>s.closeImportModal(),h=()=>void s.handleImportOrders(),g=()=>void s.handleRetryImport();return s.showImportModal?J.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"插入订单"}),e.jsx("button",{onClick:c,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(W,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"选择Excel文件"}),e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv,.json",onChange:t,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持 .xlsx、.csv、.tsv、.json 格式"})]}),s.importFile&&e.jsx("div",{className:"p-3 bg-blue-50 rounded-xl",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"w-4 h-4 text-blue-600"}),e.jsx("span",{className:"text-sm font-medium text-blue-900",children:s.importFile.name})]})}),s.importError&&e.jsxs("div",{className:"rounded-xl bg-red-50 border border-red-100 p-3 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:s.importError}),e.jsx("button",{type:"button",onClick:g,disabled:s.importing||!s.importFile,className:"font-bold whitespace-nowrap",children:"重试"})]}),s.importResult&&s.importResult.failed_count>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-100 p-3 text-sm font-bold text-amber-800",children:["导入完成:成功 ",s.importResult.success_count," 条,失败 ",s.importResult.failed_count," 条"]}),e.jsx("div",{className:"max-h-64 overflow-y-auto rounded-xl border border-gray-100",children:e.jsxs("table",{className:"w-full text-left text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-gray-50 text-gray-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"订单ID"}),e.jsx("th",{className:"px-3 py-2",children:"失败原因"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:Ne(s.importResult).map((m,u)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-mono",children:m.order_id}),e.jsx("td",{className:"px-3 py-2 text-red-600",children:m.message||"导入失败"})]},`${m.order_id}-${u}`))})]})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:c,className:"flex-1 px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors",children:"取消"}),e.jsx("button",{onClick:h,disabled:!s.importFile||s.importing,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:s.importing?"正在导入…":"导入订单"})]})})]})}),document.body):null},Ie=async s=>X("/api/v1/accounts/details",void 0,s),Oe=async(s,t)=>X("/api/v1/items",void 0,t),Fe=s=>{const t=String(s||"");return t==="paid"?"pending_ship":["processing","pending_ship","shipped","completed","cancelled","refunding"].includes(t)?t:"unknown"},Me=async(s,t,c=1,h=20,g,m)=>{const u={page:c,page_size:h};s&&(u.cookie_id=s),t&&t!=="all"&&(u.status=t),g!=null&&g.trim()&&(u.search=g.trim());const p=await X("/api/v1/orders",u,m),b=be(p,["data","result"])||{},y=(Array.isArray(b.orders)?b.orders:ye(b.data,["data","orders","items"])).map(r=>({...r,id:r.id||r.order_id,status:Fe(r.status||r.order_status),quantity:Number(r.quantity||1)}));return{success:!0,data:y,total:b.total||y.length,page:b.page||c,page_size:b.page_size||h,total_pages:b.total_pages||1}},De=async(s,t)=>ge(`/api/v1/orders/${s}`,t),Re=async s=>pe(`/api/v1/orders/${s}`),$e=async(s,t,c)=>{const h=new FormData;s&&h.append("cookie_id",s),t&&h.append("status",t);const g=await ae("/api/v1/orders/refresh",h,c),m=180;let u=0;try{for(;u{const r=()=>{globalThis.clearTimeout(i),y(new Error("请求已取消"))},i=globalThis.setTimeout(()=>{var C;(C=c==null?void 0:c.signal)==null||C.removeEventListener("abort",r),_()},b);c!=null&&c.signal&&(c.signal.aborted?r():c.signal.addEventListener("abort",r,{once:!0}))}),u+=1}}finally{}throw new Error("订单刷新任务等待超时")},Ae=async s=>K(`/api/v1/orders/${s}/refresh`),Le=async(s,t)=>K("/api/v1/orders/manual-ship",{order_ids:s,ship_mode:t}),Pe=async(s,t)=>s instanceof FormData?ae("/api/v1/orders/import",s,t):K("/api/v1/orders/import",s,t),Te=(s={pageSize:20})=>{const[t,c]=a.useState([]),[h,g]=a.useState([]),[m,u]=a.useState([]),[p,b]=a.useState("all"),[_,y]=a.useState(""),[r,i]=a.useState(""),[C,$]=a.useState(""),[O,S]=a.useState(1),[w,A]=a.useState(1),[F,o]=a.useState(!1),N=a.useRef(0),f=a.useRef(null),M=a.useRef(null),D=a.useCallback(async()=>{var j;const d=++N.current;(j=f.current)==null||j.abort();const x=new AbortController;f.current=x,o(!0);try{const E=await Me(_||void 0,p,O,s.pageSize,C,{signal:x.signal});if(!T(d,N.current))return;c(E.data),A(E.total_pages)}catch(E){T(d,N.current)&&!x.signal.aborted&&console.error("加载订单失败:",E)}finally{T(d,N.current)&&o(!1)}},[_,C,p,s.pageSize,O]);a.useEffect(()=>{const d=window.setTimeout(()=>{S(1),$(r.trim())},300);return(()=>window.clearTimeout(d))},[r]),a.useEffect(()=>(D(),(()=>{var d;N.current+=1,(d=f.current)==null||d.abort()})),[D]),a.useEffect(()=>{var x;const d=new AbortController;return(x=M.current)==null||x.abort(),M.current=d,Promise.all([Ie({signal:d.signal}),Oe(void 0,{signal:d.signal})]).then(([j,E])=>{d.signal.aborted||(u(j),g(E))}).catch(j=>{d.signal.aborted||console.error("加载订单辅助数据失败:",j)}),(()=>d.abort())},[]);const k=a.useMemo(()=>new Map(m.map(d=>[d.id,d])),[m]),P=a.useMemo(()=>{const d={};return h.forEach(x=>{x.item_id&&(d[`${x.cookie_id}:${x.item_id}`]=x.item_title||x.item_id)}),d},[h]),U=a.useCallback(d=>{const x=k.get(d),j=(x==null?void 0:x.remark)||(x==null?void 0:x.nickname);return j?`${j} · ${d.slice(0,6)}`:`账号 ${d.slice(0,8)}`},[k]),V=a.useCallback(d=>{const x=k.get(d);return(x==null?void 0:x.remark)||(x==null?void 0:x.nickname)||"未命名账号"},[k]),q=a.useCallback((d,x,j)=>{if(j!=null&&j.trim())return j;const E=P[`${d}:${x}`];if(E)return E;const I=h.find(z=>{if(!j||!z.item_title)return!1;const B=j.toLowerCase(),L=z.item_title.toLowerCase();return L.includes(B)||B.includes(L)});return(I==null?void 0:I.item_title)||"未知商品"},[P,h]);return{orders:t,items:h,accounts:m,filter:p,setFilter:b,accountFilter:_,setAccountFilter:y,searchText:r,setSearchText:i,page:O,setPage:S,totalPages:w,loading:F,loadOrders:D,accountName:U,accountNickname:V,getItemNameById:q}},qe=s=>{const[t,c]=a.useState(!1),[h,g]=a.useState(null),[m,u]=a.useState(null),[p,b]=a.useState(!1),[_,y]=a.useState(""),r=a.useRef(0),i=a.useRef(null);a.useEffect(()=>(()=>{var w;r.current+=1,(w=i.current)==null||w.abort()}),[]);const C=a.useCallback(()=>{g(null),u(null),y(""),c(!0)},[]),$=a.useCallback(()=>{var w;r.current+=1,(w=i.current)==null||w.abort(),b(!1),c(!1),g(null),u(null),y("")},[]),O=a.useCallback(async()=>{var N;if(!_e(h,p))return;const w=h;if(!w)return;const A=ke(w);if(A){y(A);return}const F=++r.current;(N=i.current)==null||N.abort();const o=new AbortController;i.current=o,b(!0),u(null),y("");try{const f=new FormData;f.append("file",w);const M=je(await Pe(f,{signal:o.signal}));if(!T(F,r.current))return;u(M),g(null),await s(),M.failed_count===0&&T(F,r.current)&&(alert(`订单导入成功,共 ${M.success_count} 条`),c(!1),u(null))}catch(f){T(F,r.current)&&!o.signal.aborted&&y(Ce(f,"导入失败,请检查文件格式"))}finally{T(F,r.current)&&b(!1)}},[h,p,s]),S=a.useCallback(async()=>{await O()},[O]);return{showImportModal:t,importFile:h,setImportFile:g,importResult:m,importing:p,importError:_,openImportModal:C,closeImportModal:$,handleImportOrders:O,handleRetryImport:S}},Q=(s,t)=>s instanceof Error?s.message:t,ze=({orders:s,page:t,accountFilter:c,filter:h,setPage:g,loadOrders:m})=>{const[u,p]=a.useState(!1),[b,_]=a.useState(null),[y,r]=a.useState(!1),[i,C]=a.useState(null),[$,O]=a.useState(!1),[S,w]=a.useState(""),[A,F]=a.useState(!1),[o,N]=a.useState(null),[f,M]=a.useState(null),[D,k]=a.useState(null),P=a.useCallback(async()=>{try{const n=await $e(c||void 0,h);await m(),n.message&&alert(n.message)}catch(n){console.error("同步订单失败:",n),alert(Q(n,"同步失败,请重试"))}},[c,h,m]),U=a.useCallback(n=>{w(n),N(null),O(!0)},[]),V=a.useCallback(async n=>{var v;F(!0),N(null);try{const R=(v=(await Le([S],n)).results)==null?void 0:v[0];R!=null&&R.success?(N({success:!0,message:R.message}),m()):N({success:!1,message:(R==null?void 0:R.message)||"发货失败"})}catch(G){N({success:!1,message:Q(G,"请求失败")})}finally{F(!1)}},[m,S]),q=a.useCallback(n=>{_(n),p(!0)},[]),d=a.useCallback(n=>{C({...n}),r(!0)},[]),x=a.useCallback(n=>{C(v=>v&&{...v,...n})},[]),j=a.useCallback(async()=>{if(i!=null&&i.order_id)try{const n={};i.status!==void 0&&(n.order_status=i.status),i.buyer_id!==void 0&&(n.buyer_id=i.buyer_id),i.amount!==void 0&&(n.amount=i.amount),i.receiver_name!==void 0&&(n.receiver_name=i.receiver_name),i.receiver_phone!==void 0&&(n.receiver_phone=i.receiver_phone),i.receiver_address!==void 0&&(n.receiver_address=i.receiver_address),i.item_id!==void 0&&(n.item_id=i.item_id),i.quantity!==void 0&&(n.quantity=i.quantity),i.item_title!==void 0&&(n.item_title=i.item_title),await De(i.order_id,n),r(!1),C(null),await m()}catch(n){console.error("更新订单失败:",n),alert("更新失败,请重试")}},[i,m]),E=a.useCallback(async n=>{M(n);try{const v=await Ae(n);v.success?await m():alert(v.message||"同步失败")}catch(v){console.error("同步订单失败:",v),alert(Q(v,"同步失败,请重试"))}finally{M(null)}},[m]),I=a.useCallback(async n=>{if(confirm("确认删除该订单吗?删除后无法恢复。")){k(n);try{await Re(n),s.length===1&&t>1?g(v=>v-1):await m()}catch(v){console.error("删除订单失败:",v),alert(Q(v,"删除失败,请重试")),await m()}finally{k(null)}}},[m,s.length,t,g]),z=a.useCallback(()=>p(!1),[]),B=a.useCallback(()=>r(!1),[]),L=a.useCallback(()=>{O(!1),N(null)},[]);return{showDetailModal:u,selectedOrder:b,showEditModal:y,editingOrder:i,showShipModal:$,shipOrderId:S,shipLoading:A,shipResult:o,syncingOrderId:f,deletingOrderId:D,handleSync:P,handleShip:U,executeShip:V,handleViewDetail:q,handleEdit:d,handleSaveEdit:j,updateEditingOrder:x,handleSyncSingle:E,handleDelete:I,closeDetailModal:z,closeEditModal:B,closeShipModal:L}},se=({status:s})=>{const t={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},c={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${t[s]||t.cancelled}`,children:c[s]||s})},Je=()=>{const s=Te(),t=qe(s.loadOrders),{orders:c,accounts:h,filter:g,setFilter:m,accountFilter:u,setAccountFilter:p,searchText:b,setSearchText:_,page:y,setPage:r,totalPages:i,loading:C,loadOrders:$,accountName:O,accountNickname:S,getItemNameById:w}=s,A=ze({orders:c,page:y,accountFilter:u,filter:g,setPage:r,loadOrders:$}),{showDetailModal:F,selectedOrder:o,showEditModal:N,editingOrder:f,showShipModal:M,shipLoading:D,shipResult:k,syncingOrderId:P,deletingOrderId:U,handleSync:V,handleShip:q,executeShip:d,handleViewDetail:x,handleEdit:j,handleSaveEdit:E,updateEditingOrder:I,handleSyncSingle:z,handleDelete:B,closeDetailModal:L,closeEditModal:n,closeShipModal:v}=A,G=l=>{m(l),r(1),_("")},R=l=>{p(l),r(1)},le=l=>{_(l),r(1)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"订单中心"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"查看所有闲鱼交易记录与状态。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:$,className:"p-3 rounded-2xl bg-white border border-gray-100 text-gray-600 hover:bg-gray-50 hover:text-black transition-colors shadow-sm",children:e.jsx(H,{className:`w-5 h-5 ${C?"animate-spin":""}`})}),e.jsxs("button",{onClick:t.openImportModal,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors text-sm flex items-center gap-2 shadow-lg",children:[e.jsx(ie,{className:"w-4 h-4"}),"插入订单"]}),e.jsxs("button",{onClick:V,className:"ios-btn-primary px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 text-sm flex items-center gap-2",children:[e.jsx(Y,{className:"w-5 h-5"}),"一键同步订单"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsx(Se,{filter:g,onFilterChange:G,accountFilter:u,onAccountFilterChange:R,accounts:h,accountName:O,searchText:b,onSearchChange:le}),e.jsx("div",{className:"overflow-x-auto min-h-[400px]",children:e.jsxs("table",{className:"w-full text-left border-collapse table-fixed",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"px-6 py-5",style:{width:"28%"},children:"订单信息"}),e.jsx("th",{className:"px-6 py-5",style:{width:"26%"},children:"买家信息"}),e.jsx("th",{className:"px-6 py-5",style:{width:"11%"},children:"实付金额"}),e.jsx("th",{className:"px-6 py-5",style:{width:"13%"},children:"当前状态"}),e.jsx("th",{className:"px-6 py-5 text-right",style:{width:"22%"},children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:c.map(l=>e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-6 py-5",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-gray-100 overflow-hidden shadow-sm border border-gray-100 flex-shrink-0",children:l.item_image?e.jsx("img",{src:l.item_image,alt:"",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-300",children:e.jsx(Z,{})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 line-clamp-1 text-sm",children:w(l.cookie_id,l.item_id,l.item_title)}),e.jsxs("div",{className:"mt-1 flex w-fit min-w-0 max-w-full items-center gap-1 rounded-md bg-blue-50 px-2 py-1 text-[10px] font-extrabold text-blue-700",title:S(l.cookie_id),children:[e.jsx(te,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:S(l.cookie_id)})]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1 font-medium",children:["订单ID: ",l.order_id]}),e.jsxs("div",{className:"text-xs text-gray-400 mt-0.5",children:["数量: ",l.quantity," • ",ee(l.created_at)]})]})]})}),e.jsx("td",{className:"px-6 py-5",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"text-xs text-gray-500",children:"买家ID"}),e.jsx("div",{className:"text-sm font-bold text-gray-800",children:l.buyer_id}),l.receiver_name&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-gray-500",children:"收货人"}),e.jsx("div",{className:"text-xs text-gray-600",children:l.receiver_name})]}),l.receiver_phone&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-gray-500",children:"联系电话"}),e.jsx("div",{className:"text-xs text-gray-600 font-mono",children:l.receiver_phone})]}),l.receiver_address&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-gray-500",children:"收货地址"}),e.jsx("div",{className:"text-xs text-gray-600 line-clamp-1",children:l.receiver_address})]})]})}),e.jsx("td",{className:"px-6 py-5 text-base font-extrabold text-gray-900 font-feature-settings-tnum",children:l.amount?`¥${l.amount}`:e.jsx("span",{className:"text-xs text-amber-600 font-bold",children:"待获取"})}),e.jsx("td",{className:"px-6 py-5",children:e.jsx(se,{status:l.status})}),e.jsxs("td",{className:"px-6 py-5 text-right",children:[l.status==="pending_ship"&&e.jsx("button",{onClick:(()=>q(l.order_id)),className:"mr-2 text-white bg-black hover:bg-gray-800 shadow-lg shadow-gray-200 text-xs font-bold px-3 py-2 rounded-xl transition-all active:scale-95",children:"立即发货"}),e.jsx("a",{href:`https://www.goofish.com/order-detail?orderId=${l.order_id}&role=seller`,target:"_blank",rel:"noopener noreferrer",className:"mr-2 inline-flex text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看闲鱼详情",children:e.jsx(ce,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>x(l)),className:"mr-2 text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看详情",children:e.jsx(oe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>j(l)),className:"mr-2 text-gray-400 hover:text-black p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"编辑订单",children:e.jsx(de,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>z(l.order_id)),disabled:P===l.order_id,className:"mr-2 text-gray-400 hover:text-green-600 p-2 rounded-xl hover:bg-green-50 transition-colors disabled:opacity-50",title:"同步订单",children:e.jsx(H,{className:`w-4 h-4 ${P===l.order_id?"animate-spin":""}`})}),e.jsx("button",{onClick:(()=>B(l.order_id)),disabled:U===l.order_id,className:"text-gray-400 hover:text-red-500 p-2 rounded-xl hover:bg-red-50 transition-colors disabled:opacity-50",title:"删除订单",children:e.jsx(xe,{className:"w-4 h-4"})})]})]},l.id))})]})}),e.jsxs("div",{className:"p-4 border-t border-gray-50 flex items-center justify-between bg-white",children:[e.jsxs("div",{className:"text-sm text-gray-500 font-medium pl-2",children:["第 ",y," 页 / 共 ",i," 页"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:y<=1,onClick:(()=>r(l=>l-1)),"aria-label":"上一页",className:"p-2.5 rounded-xl bg-gray-50 hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed text-gray-600 transition-colors",children:e.jsx(me,{className:"w-5 h-5"})}),e.jsx("button",{disabled:y>=i,onClick:(()=>r(l=>l+1)),"aria-label":"下一页",className:"p-2.5 rounded-xl bg-gray-50 hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed text-gray-600 transition-colors",children:e.jsx(ue,{className:"w-5 h-5"})})]})]})]}),F&&o&&J.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"订单详情"}),e.jsx("button",{onClick:L,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(W,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-800",children:"订单信息"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"订单号"}),e.jsx("div",{className:"font-mono text-sm font-bold text-gray-900",children:o.order_id})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"所属账号"}),e.jsx("div",{className:"truncate whitespace-nowrap text-sm font-bold text-blue-700",title:S(o.cookie_id),children:S(o.cookie_id)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"状态"}),e.jsx(se,{status:o.status})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"实付金额"}),e.jsx("div",{className:"text-lg font-extrabold text-gray-900",children:o.amount?`¥${o.amount}`:"待获取"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"数量"}),e.jsx("div",{className:"font-bold text-gray-900",children:o.quantity})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"创建时间"}),e.jsx("div",{className:"text-sm font-medium text-gray-700",children:ee(o.created_at)})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-800",children:"商品信息"}),e.jsxs("div",{className:"p-4 bg-gray-50 rounded-xl flex items-center gap-4",children:[o.item_image&&e.jsx("img",{src:o.item_image,alt:"",className:"w-20 h-20 rounded-xl object-cover border border-gray-200"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-bold text-gray-900 mb-1",children:w(o.cookie_id,o.item_id,o.item_title)}),e.jsxs("div",{className:"text-sm text-gray-500",children:["商品ID: ",o.item_id]}),o.item_price&&e.jsxs("div",{className:"text-sm text-gray-500 mt-1",children:["标价: ¥",o.item_price]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-800",children:"买家信息"}),e.jsxs("div",{className:"p-4 bg-gray-50 rounded-xl space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"买家ID"}),e.jsx("div",{className:"font-bold text-gray-900",children:o.buyer_id})]}),o.receiver_name&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"收货人"}),e.jsx("div",{className:"font-medium text-gray-700",children:o.receiver_name})]}),o.receiver_phone&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"联系电话"}),e.jsx("div",{className:"font-mono text-sm text-gray-700",children:o.receiver_phone})]}),o.receiver_address&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"收货地址"}),e.jsx("div",{className:"text-sm text-gray-700",children:o.receiver_address})]})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:L,className:"flex-1 px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors",children:"关闭"}),o.status==="pending_ship"&&e.jsx("button",{onClick:(()=>{L(),q(o.order_id)}),className:"flex-1 px-6 py-3 rounded-xl ios-btn-primary font-bold shadow-lg shadow-blue-200",children:"立即发货"})]})})]})}),document.body),e.jsx(Ee,{...t}),M&&J.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"480px"},children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"立即发货"}),e.jsx("button",{onClick:v,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(W,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-4",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"请选择发货方式:"}),e.jsx("button",{onClick:(()=>d("status_only")),disabled:D,className:"w-full text-left p-4 rounded-xl border-2 border-gray-200 hover:border-gray-400 hover:bg-gray-50 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-100 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(Y,{className:"w-5 h-5 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm",children:"仅修改闲鱼发货状态"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 leading-relaxed",children:'不实际扣除或发送卡券,仅在闲鱼平台将订单标记为"已发货"。 适用于已经给客户发过货、只是忘记在闲鱼修改状态的情况。'})]})]})}),e.jsx("button",{onClick:(()=>d("full_delivery")),disabled:D,className:"w-full text-left p-4 rounded-xl border-2 border-gray-200 hover:border-brand hover:bg-blue-50 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-100 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(Z,{className:"w-5 h-5 text-blue-700"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm",children:"完整发货(匹配卡券并发送)"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 leading-relaxed",children:"自动匹配发货规则、获取卡券、发送卡券信息给买家,并修改发货状态。 适用于订单既没有发送卡券给买家、也没有修改发货状态的情况。"})]})]})}),D&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-3",children:[e.jsx(H,{className:"w-4 h-4 animate-spin text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"正在处理中..."})]}),k&&e.jsxs("div",{className:`p-3 rounded-xl text-sm ${k.success?"bg-green-50 text-green-800":"bg-red-50 text-red-800"}`,children:[k.success?"✓ ":"✗ ",k.message]})]}),e.jsx("div",{className:"modal-footer",children:e.jsx("button",{onClick:v,className:"w-full px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors",children:k!=null&&k.success?"完成":"取消"})})]})}),document.body),N&&f&&J.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑订单"}),e.jsx("button",{onClick:n,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(W,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"订单号"}),e.jsx("input",{type:"text",value:f.order_id,disabled:!0,className:"w-full ios-input px-4 py-3 rounded-xl bg-gray-50 text-gray-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"订单状态"}),e.jsxs("select",{value:f.status,onChange:(l=>I({status:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"processing",children:"处理中"}),e.jsx("option",{value:"pending_ship",children:"待发货"}),e.jsx("option",{value:"shipped",children:"已发货"}),e.jsx("option",{value:"completed",children:"已完成"}),e.jsx("option",{value:"cancelled",children:"已取消"}),e.jsx("option",{value:"refunding",children:"退款中"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"买家ID"}),e.jsx("input",{type:"text",value:f.buyer_id,onChange:(l=>I({buyer_id:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"实付金额"}),e.jsx("input",{type:"number",value:f.amount,onChange:(l=>I({amount:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"收货人"}),e.jsx("input",{type:"text",value:f.receiver_name||"",onChange:(l=>I({receiver_name:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"联系电话"}),e.jsx("input",{type:"text",value:f.receiver_phone||"",onChange:(l=>I({receiver_phone:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"收货地址"}),e.jsx("textarea",{value:f.receiver_address||"",onChange:(l=>I({receiver_address:l.target.value})),rows:2,className:"w-full ios-input px-4 py-3 rounded-xl resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"商品标题"}),e.jsx("input",{type:"text",value:f.item_title||"",onChange:(l=>I({item_title:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:n,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:E,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(he,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body)]})};export{Je as default};
+import{j as e,b as J,r as a}from"./react-vendor-C_od1ZSF.js";import{U as te,I as re,X as W,J as ne,R as H,N as ie,O as Y,m as Z,E as ce,v as oe,V as de,F as xe,h as me,g as ue,r as he}from"./icons-vendor-CvzvbbIV.js";import{g as X,b as ae,a as K,p as ge,d as pe}from"./index-CNzF_I4S.js";import{o as be,c as ye}from"./contract-COFcZjyb.js";import{f as ee}from"./dateTime-DDi7rqpW.js";const fe=[{key:"all",label:"全部"},{key:"processing",label:"处理中"},{key:"shipped",label:"已发货"},{key:"pending_ship",label:"待发货"},{key:"completed",label:"已完成"},{key:"cancelled",label:"已取消"},{key:"refunding",label:"退款中"}],je=s=>{const t=typeof s=="object"&&s!==null?s:{},c=Array.isArray(t.results)?t.results:[];return{total:Number(t.total||0),success_count:Number(t.success_count||0),failed_count:Number(t.failed_count||0),results:c.map(ve)}},ve=s=>{const t=typeof s=="object"&&s!==null?s:{};return{order_id:String(t.order_id||"unknown"),success:t.success===!0,message:String(t.message||"")}},Ne=s=>(s==null?void 0:s.results.filter(we))||[],we=s=>!s.success,_e=(s,t)=>s!==null&&!t,ke=s=>{if(!s)return"请选择订单文件";const t=s.name.toLowerCase().split(".").pop()||"";return["xlsx","csv","tsv","json"].includes(t)?"":"仅支持 .xlsx、.csv、.tsv、.json 格式"},T=(s,t)=>s===t,Ce=(s,t)=>s instanceof Error&&s.message?s.message:t,Se=({filter:s,onFilterChange:t,accountFilter:c,onAccountFilterChange:h,accounts:g,accountName:m,searchText:u,onSearchChange:p})=>{const b=r=>t(r.currentTarget.dataset.status||"all"),_=r=>h(r.target.value),y=r=>p(r.target.value);return e.jsxs("div",{className:"p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted",children:[e.jsx("div",{className:"flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full",children:fe.map(r=>e.jsx("button",{"data-status":r.key,onClick:b,className:`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${s===r.key?"bg-white text-black shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:r.label},r.key))}),e.jsxs("div",{className:"flex w-full md:w-auto flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(te,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{"aria-label":"按账号筛选订单",value:c,onChange:_,className:"ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm",children:[e.jsx("option",{value:"",children:"全部账号"}),g.map(r=>e.jsx("option",{value:r.id,children:m(r.id)},r.id))]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(re,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors"}),e.jsx("input",{type:"text",placeholder:"搜索订单号/商品/买家...",value:u,onChange:y,className:"ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"})]})]})]})},Ee=s=>{const t=m=>{var u;s.setImportFile(((u=m.target.files)==null?void 0:u[0])||null)},c=()=>s.closeImportModal(),h=()=>void s.handleImportOrders(),g=()=>void s.handleRetryImport();return s.showImportModal?J.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"插入订单"}),e.jsx("button",{onClick:c,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(W,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"选择Excel文件"}),e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv,.json",onChange:t,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持 .xlsx、.csv、.tsv、.json 格式"})]}),s.importFile&&e.jsx("div",{className:"p-3 bg-blue-50 rounded-xl",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"w-4 h-4 text-blue-600"}),e.jsx("span",{className:"text-sm font-medium text-blue-900",children:s.importFile.name})]})}),s.importError&&e.jsxs("div",{className:"rounded-xl bg-red-50 border border-red-100 p-3 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:s.importError}),e.jsx("button",{type:"button",onClick:g,disabled:s.importing||!s.importFile,className:"font-bold whitespace-nowrap",children:"重试"})]}),s.importResult&&s.importResult.failed_count>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-100 p-3 text-sm font-bold text-amber-800",children:["导入完成:成功 ",s.importResult.success_count," 条,失败 ",s.importResult.failed_count," 条"]}),e.jsx("div",{className:"max-h-64 overflow-y-auto rounded-xl border border-gray-100",children:e.jsxs("table",{className:"w-full text-left text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-gray-50 text-gray-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"订单ID"}),e.jsx("th",{className:"px-3 py-2",children:"失败原因"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:Ne(s.importResult).map((m,u)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-mono",children:m.order_id}),e.jsx("td",{className:"px-3 py-2 text-red-600",children:m.message||"导入失败"})]},`${m.order_id}-${u}`))})]})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:c,className:"flex-1 px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors",children:"取消"}),e.jsx("button",{onClick:h,disabled:!s.importFile||s.importing,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:s.importing?"正在导入…":"导入订单"})]})})]})}),document.body):null},Ie=async s=>X("/api/v1/accounts/details",void 0,s),Oe=async(s,t)=>X("/api/v1/items",void 0,t),Fe=s=>{const t=String(s||"");return t==="paid"?"pending_ship":["processing","pending_ship","shipped","completed","cancelled","refunding"].includes(t)?t:"unknown"},Me=async(s,t,c=1,h=20,g,m)=>{const u={page:c,page_size:h};s&&(u.cookie_id=s),t&&t!=="all"&&(u.status=t),g!=null&&g.trim()&&(u.search=g.trim());const p=await X("/api/v1/orders",u,m),b=be(p,["data","result"])||{},y=(Array.isArray(b.orders)?b.orders:ye(b.data,["data","orders","items"])).map(r=>({...r,id:r.id||r.order_id,status:Fe(r.status||r.order_status),quantity:Number(r.quantity||1)}));return{success:!0,data:y,total:b.total||y.length,page:b.page||c,page_size:b.page_size||h,total_pages:b.total_pages||1}},De=async(s,t)=>ge(`/api/v1/orders/${s}`,t),Re=async s=>pe(`/api/v1/orders/${s}`),$e=async(s,t,c)=>{const h=new FormData;s&&h.append("cookie_id",s),t&&h.append("status",t);const g=await ae("/api/v1/orders/refresh",h,c),m=180;let u=0;try{for(;u{const r=()=>{globalThis.clearTimeout(i),y(new Error("请求已取消"))},i=globalThis.setTimeout(()=>{var C;(C=c==null?void 0:c.signal)==null||C.removeEventListener("abort",r),_()},b);c!=null&&c.signal&&(c.signal.aborted?r():c.signal.addEventListener("abort",r,{once:!0}))}),u+=1}}finally{}throw new Error("订单刷新任务等待超时")},Ae=async s=>K(`/api/v1/orders/${s}/refresh`),Le=async(s,t)=>K("/api/v1/orders/manual-ship",{order_ids:s,ship_mode:t}),Pe=async(s,t)=>s instanceof FormData?ae("/api/v1/orders/import",s,t):K("/api/v1/orders/import",s,t),Te=(s={pageSize:20})=>{const[t,c]=a.useState([]),[h,g]=a.useState([]),[m,u]=a.useState([]),[p,b]=a.useState("all"),[_,y]=a.useState(""),[r,i]=a.useState(""),[C,$]=a.useState(""),[O,S]=a.useState(1),[w,A]=a.useState(1),[F,o]=a.useState(!1),N=a.useRef(0),f=a.useRef(null),M=a.useRef(null),D=a.useCallback(async()=>{var j;const d=++N.current;(j=f.current)==null||j.abort();const x=new AbortController;f.current=x,o(!0);try{const E=await Me(_||void 0,p,O,s.pageSize,C,{signal:x.signal});if(!T(d,N.current))return;c(E.data),A(E.total_pages)}catch(E){T(d,N.current)&&!x.signal.aborted&&console.error("加载订单失败:",E)}finally{T(d,N.current)&&o(!1)}},[_,C,p,s.pageSize,O]);a.useEffect(()=>{const d=window.setTimeout(()=>{S(1),$(r.trim())},300);return(()=>window.clearTimeout(d))},[r]),a.useEffect(()=>(D(),(()=>{var d;N.current+=1,(d=f.current)==null||d.abort()})),[D]),a.useEffect(()=>{var x;const d=new AbortController;return(x=M.current)==null||x.abort(),M.current=d,Promise.all([Ie({signal:d.signal}),Oe(void 0,{signal:d.signal})]).then(([j,E])=>{d.signal.aborted||(u(j),g(E))}).catch(j=>{d.signal.aborted||console.error("加载订单辅助数据失败:",j)}),(()=>d.abort())},[]);const k=a.useMemo(()=>new Map(m.map(d=>[d.id,d])),[m]),P=a.useMemo(()=>{const d={};return h.forEach(x=>{x.item_id&&(d[`${x.cookie_id}:${x.item_id}`]=x.item_title||x.item_id)}),d},[h]),U=a.useCallback(d=>{const x=k.get(d),j=(x==null?void 0:x.remark)||(x==null?void 0:x.nickname);return j?`${j} · ${d.slice(0,6)}`:`账号 ${d.slice(0,8)}`},[k]),V=a.useCallback(d=>{const x=k.get(d);return(x==null?void 0:x.remark)||(x==null?void 0:x.nickname)||"未命名账号"},[k]),q=a.useCallback((d,x,j)=>{if(j!=null&&j.trim())return j;const E=P[`${d}:${x}`];if(E)return E;const I=h.find(z=>{if(!j||!z.item_title)return!1;const B=j.toLowerCase(),L=z.item_title.toLowerCase();return L.includes(B)||B.includes(L)});return(I==null?void 0:I.item_title)||"未知商品"},[P,h]);return{orders:t,items:h,accounts:m,filter:p,setFilter:b,accountFilter:_,setAccountFilter:y,searchText:r,setSearchText:i,page:O,setPage:S,totalPages:w,loading:F,loadOrders:D,accountName:U,accountNickname:V,getItemNameById:q}},qe=s=>{const[t,c]=a.useState(!1),[h,g]=a.useState(null),[m,u]=a.useState(null),[p,b]=a.useState(!1),[_,y]=a.useState(""),r=a.useRef(0),i=a.useRef(null);a.useEffect(()=>(()=>{var w;r.current+=1,(w=i.current)==null||w.abort()}),[]);const C=a.useCallback(()=>{g(null),u(null),y(""),c(!0)},[]),$=a.useCallback(()=>{var w;r.current+=1,(w=i.current)==null||w.abort(),b(!1),c(!1),g(null),u(null),y("")},[]),O=a.useCallback(async()=>{var N;if(!_e(h,p))return;const w=h;if(!w)return;const A=ke(w);if(A){y(A);return}const F=++r.current;(N=i.current)==null||N.abort();const o=new AbortController;i.current=o,b(!0),u(null),y("");try{const f=new FormData;f.append("file",w);const M=je(await Pe(f,{signal:o.signal}));if(!T(F,r.current))return;u(M),g(null),await s(),M.failed_count===0&&T(F,r.current)&&(alert(`订单导入成功,共 ${M.success_count} 条`),c(!1),u(null))}catch(f){T(F,r.current)&&!o.signal.aborted&&y(Ce(f,"导入失败,请检查文件格式"))}finally{T(F,r.current)&&b(!1)}},[h,p,s]),S=a.useCallback(async()=>{await O()},[O]);return{showImportModal:t,importFile:h,setImportFile:g,importResult:m,importing:p,importError:_,openImportModal:C,closeImportModal:$,handleImportOrders:O,handleRetryImport:S}},Q=(s,t)=>s instanceof Error?s.message:t,ze=({orders:s,page:t,accountFilter:c,filter:h,setPage:g,loadOrders:m})=>{const[u,p]=a.useState(!1),[b,_]=a.useState(null),[y,r]=a.useState(!1),[i,C]=a.useState(null),[$,O]=a.useState(!1),[S,w]=a.useState(""),[A,F]=a.useState(!1),[o,N]=a.useState(null),[f,M]=a.useState(null),[D,k]=a.useState(null),P=a.useCallback(async()=>{try{const n=await $e(c||void 0,h);await m(),n.message&&alert(n.message)}catch(n){console.error("同步订单失败:",n),alert(Q(n,"同步失败,请重试"))}},[c,h,m]),U=a.useCallback(n=>{w(n),N(null),O(!0)},[]),V=a.useCallback(async n=>{var v;F(!0),N(null);try{const R=(v=(await Le([S],n)).results)==null?void 0:v[0];R!=null&&R.success?(N({success:!0,message:R.message}),m()):N({success:!1,message:(R==null?void 0:R.message)||"发货失败"})}catch(G){N({success:!1,message:Q(G,"请求失败")})}finally{F(!1)}},[m,S]),q=a.useCallback(n=>{_(n),p(!0)},[]),d=a.useCallback(n=>{C({...n}),r(!0)},[]),x=a.useCallback(n=>{C(v=>v&&{...v,...n})},[]),j=a.useCallback(async()=>{if(i!=null&&i.order_id)try{const n={};i.status!==void 0&&(n.order_status=i.status),i.buyer_id!==void 0&&(n.buyer_id=i.buyer_id),i.amount!==void 0&&(n.amount=i.amount),i.receiver_name!==void 0&&(n.receiver_name=i.receiver_name),i.receiver_phone!==void 0&&(n.receiver_phone=i.receiver_phone),i.receiver_address!==void 0&&(n.receiver_address=i.receiver_address),i.item_id!==void 0&&(n.item_id=i.item_id),i.quantity!==void 0&&(n.quantity=i.quantity),i.item_title!==void 0&&(n.item_title=i.item_title),await De(i.order_id,n),r(!1),C(null),await m()}catch(n){console.error("更新订单失败:",n),alert("更新失败,请重试")}},[i,m]),E=a.useCallback(async n=>{M(n);try{const v=await Ae(n);v.success?await m():alert(v.message||"同步失败")}catch(v){console.error("同步订单失败:",v),alert(Q(v,"同步失败,请重试"))}finally{M(null)}},[m]),I=a.useCallback(async n=>{if(confirm("确认删除该订单吗?删除后无法恢复。")){k(n);try{await Re(n),s.length===1&&t>1?g(v=>v-1):await m()}catch(v){console.error("删除订单失败:",v),alert(Q(v,"删除失败,请重试")),await m()}finally{k(null)}}},[m,s.length,t,g]),z=a.useCallback(()=>p(!1),[]),B=a.useCallback(()=>r(!1),[]),L=a.useCallback(()=>{O(!1),N(null)},[]);return{showDetailModal:u,selectedOrder:b,showEditModal:y,editingOrder:i,showShipModal:$,shipOrderId:S,shipLoading:A,shipResult:o,syncingOrderId:f,deletingOrderId:D,handleSync:P,handleShip:U,executeShip:V,handleViewDetail:q,handleEdit:d,handleSaveEdit:j,updateEditingOrder:x,handleSyncSingle:E,handleDelete:I,closeDetailModal:z,closeEditModal:B,closeShipModal:L}},se=({status:s})=>{const t={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},c={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${t[s]||t.cancelled}`,children:c[s]||s})},Je=()=>{const s=Te(),t=qe(s.loadOrders),{orders:c,accounts:h,filter:g,setFilter:m,accountFilter:u,setAccountFilter:p,searchText:b,setSearchText:_,page:y,setPage:r,totalPages:i,loading:C,loadOrders:$,accountName:O,accountNickname:S,getItemNameById:w}=s,A=ze({orders:c,page:y,accountFilter:u,filter:g,setPage:r,loadOrders:$}),{showDetailModal:F,selectedOrder:o,showEditModal:N,editingOrder:f,showShipModal:M,shipLoading:D,shipResult:k,syncingOrderId:P,deletingOrderId:U,handleSync:V,handleShip:q,executeShip:d,handleViewDetail:x,handleEdit:j,handleSaveEdit:E,updateEditingOrder:I,handleSyncSingle:z,handleDelete:B,closeDetailModal:L,closeEditModal:n,closeShipModal:v}=A,G=l=>{m(l),r(1),_("")},R=l=>{p(l),r(1)},le=l=>{_(l),r(1)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"订单中心"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"查看所有闲鱼交易记录与状态。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:$,className:"p-3 rounded-2xl bg-white border border-gray-100 text-gray-600 hover:bg-gray-50 hover:text-black transition-colors shadow-sm",children:e.jsx(H,{className:`w-5 h-5 ${C?"animate-spin":""}`})}),e.jsxs("button",{onClick:t.openImportModal,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors text-sm flex items-center gap-2 shadow-lg",children:[e.jsx(ie,{className:"w-4 h-4"}),"插入订单"]}),e.jsxs("button",{onClick:V,className:"ios-btn-primary px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 text-sm flex items-center gap-2",children:[e.jsx(Y,{className:"w-5 h-5"}),"一键同步订单"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsx(Se,{filter:g,onFilterChange:G,accountFilter:u,onAccountFilterChange:R,accounts:h,accountName:O,searchText:b,onSearchChange:le}),e.jsx("div",{className:"overflow-x-auto min-h-[400px]",children:e.jsxs("table",{className:"w-full text-left border-collapse table-fixed",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"px-6 py-5",style:{width:"28%"},children:"订单信息"}),e.jsx("th",{className:"px-6 py-5",style:{width:"26%"},children:"买家信息"}),e.jsx("th",{className:"px-6 py-5",style:{width:"11%"},children:"实付金额"}),e.jsx("th",{className:"px-6 py-5",style:{width:"13%"},children:"当前状态"}),e.jsx("th",{className:"px-6 py-5 text-right",style:{width:"22%"},children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:c.map(l=>e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-6 py-5",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-gray-100 overflow-hidden shadow-sm border border-gray-100 flex-shrink-0",children:l.item_image?e.jsx("img",{src:l.item_image,alt:"",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-300",children:e.jsx(Z,{})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 line-clamp-1 text-sm",children:w(l.cookie_id,l.item_id,l.item_title)}),e.jsxs("div",{className:"mt-1 flex w-fit min-w-0 max-w-full items-center gap-1 rounded-md bg-blue-50 px-2 py-1 text-[10px] font-extrabold text-blue-700",title:S(l.cookie_id),children:[e.jsx(te,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:S(l.cookie_id)})]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1 font-medium",children:["订单ID: ",l.order_id]}),e.jsxs("div",{className:"text-xs text-gray-400 mt-0.5",children:["数量: ",l.quantity," • ",ee(l.created_at)]})]})]})}),e.jsx("td",{className:"px-6 py-5",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"text-xs text-gray-500",children:"买家ID"}),e.jsx("div",{className:"text-sm font-bold text-gray-800",children:l.buyer_id}),l.receiver_name&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-gray-500",children:"收货人"}),e.jsx("div",{className:"text-xs text-gray-600",children:l.receiver_name})]}),l.receiver_phone&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-gray-500",children:"联系电话"}),e.jsx("div",{className:"text-xs text-gray-600 font-mono",children:l.receiver_phone})]}),l.receiver_address&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-gray-500",children:"收货地址"}),e.jsx("div",{className:"text-xs text-gray-600 line-clamp-1",children:l.receiver_address})]})]})}),e.jsx("td",{className:"px-6 py-5 text-base font-extrabold text-gray-900 font-feature-settings-tnum",children:l.amount?`¥${l.amount}`:e.jsx("span",{className:"text-xs text-amber-600 font-bold",children:"待获取"})}),e.jsx("td",{className:"px-6 py-5",children:e.jsx(se,{status:l.status})}),e.jsxs("td",{className:"px-6 py-5 text-right",children:[l.status==="pending_ship"&&e.jsx("button",{onClick:(()=>q(l.order_id)),className:"mr-2 text-white bg-black hover:bg-gray-800 shadow-lg shadow-gray-200 text-xs font-bold px-3 py-2 rounded-xl transition-all active:scale-95",children:"立即发货"}),e.jsx("a",{href:`https://www.goofish.com/order-detail?orderId=${l.order_id}&role=seller`,target:"_blank",rel:"noopener noreferrer",className:"mr-2 inline-flex text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看闲鱼详情",children:e.jsx(ce,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>x(l)),className:"mr-2 text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看详情",children:e.jsx(oe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>j(l)),className:"mr-2 text-gray-400 hover:text-black p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"编辑订单",children:e.jsx(de,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>z(l.order_id)),disabled:P===l.order_id,className:"mr-2 text-gray-400 hover:text-green-600 p-2 rounded-xl hover:bg-green-50 transition-colors disabled:opacity-50",title:"同步订单",children:e.jsx(H,{className:`w-4 h-4 ${P===l.order_id?"animate-spin":""}`})}),e.jsx("button",{onClick:(()=>B(l.order_id)),disabled:U===l.order_id,className:"text-gray-400 hover:text-red-500 p-2 rounded-xl hover:bg-red-50 transition-colors disabled:opacity-50",title:"删除订单",children:e.jsx(xe,{className:"w-4 h-4"})})]})]},l.id))})]})}),e.jsxs("div",{className:"p-4 border-t border-gray-50 flex items-center justify-between bg-white",children:[e.jsxs("div",{className:"text-sm text-gray-500 font-medium pl-2",children:["第 ",y," 页 / 共 ",i," 页"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:y<=1,onClick:(()=>r(l=>l-1)),"aria-label":"上一页",className:"p-2.5 rounded-xl bg-gray-50 hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed text-gray-600 transition-colors",children:e.jsx(me,{className:"w-5 h-5"})}),e.jsx("button",{disabled:y>=i,onClick:(()=>r(l=>l+1)),"aria-label":"下一页",className:"p-2.5 rounded-xl bg-gray-50 hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed text-gray-600 transition-colors",children:e.jsx(ue,{className:"w-5 h-5"})})]})]})]}),F&&o&&J.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"订单详情"}),e.jsx("button",{onClick:L,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(W,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-800",children:"订单信息"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"订单号"}),e.jsx("div",{className:"font-mono text-sm font-bold text-gray-900",children:o.order_id})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"所属账号"}),e.jsx("div",{className:"truncate whitespace-nowrap text-sm font-bold text-blue-700",title:S(o.cookie_id),children:S(o.cookie_id)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"状态"}),e.jsx(se,{status:o.status})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"实付金额"}),e.jsx("div",{className:"text-lg font-extrabold text-gray-900",children:o.amount?`¥${o.amount}`:"待获取"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"数量"}),e.jsx("div",{className:"font-bold text-gray-900",children:o.quantity})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"创建时间"}),e.jsx("div",{className:"text-sm font-medium text-gray-700",children:ee(o.created_at)})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-800",children:"商品信息"}),e.jsxs("div",{className:"p-4 bg-gray-50 rounded-xl flex items-center gap-4",children:[o.item_image&&e.jsx("img",{src:o.item_image,alt:"",className:"w-20 h-20 rounded-xl object-cover border border-gray-200"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-bold text-gray-900 mb-1",children:w(o.cookie_id,o.item_id,o.item_title)}),e.jsxs("div",{className:"text-sm text-gray-500",children:["商品ID: ",o.item_id]}),o.item_price&&e.jsxs("div",{className:"text-sm text-gray-500 mt-1",children:["标价: ¥",o.item_price]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-800",children:"买家信息"}),e.jsxs("div",{className:"p-4 bg-gray-50 rounded-xl space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"买家ID"}),e.jsx("div",{className:"font-bold text-gray-900",children:o.buyer_id})]}),o.receiver_name&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"收货人"}),e.jsx("div",{className:"font-medium text-gray-700",children:o.receiver_name})]}),o.receiver_phone&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"联系电话"}),e.jsx("div",{className:"font-mono text-sm text-gray-700",children:o.receiver_phone})]}),o.receiver_address&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"收货地址"}),e.jsx("div",{className:"text-sm text-gray-700",children:o.receiver_address})]})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:L,className:"flex-1 px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors",children:"关闭"}),o.status==="pending_ship"&&e.jsx("button",{onClick:(()=>{L(),q(o.order_id)}),className:"flex-1 px-6 py-3 rounded-xl ios-btn-primary font-bold shadow-lg shadow-blue-200",children:"立即发货"})]})})]})}),document.body),e.jsx(Ee,{...t}),M&&J.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"480px"},children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"立即发货"}),e.jsx("button",{onClick:v,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(W,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-4",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"请选择发货方式:"}),e.jsx("button",{onClick:(()=>d("status_only")),disabled:D,className:"w-full text-left p-4 rounded-xl border-2 border-gray-200 hover:border-gray-400 hover:bg-gray-50 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-100 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(Y,{className:"w-5 h-5 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm",children:"仅修改闲鱼发货状态"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 leading-relaxed",children:'不实际扣除或发送卡券,仅在闲鱼平台将订单标记为"已发货"。 适用于已经给客户发过货、只是忘记在闲鱼修改状态的情况。'})]})]})}),e.jsx("button",{onClick:(()=>d("full_delivery")),disabled:D,className:"w-full text-left p-4 rounded-xl border-2 border-gray-200 hover:border-brand hover:bg-blue-50 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-100 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(Z,{className:"w-5 h-5 text-blue-700"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm",children:"完整发货(匹配卡券并发送)"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 leading-relaxed",children:"自动匹配发货规则、获取卡券、发送卡券信息给买家,并修改发货状态。 适用于订单既没有发送卡券给买家、也没有修改发货状态的情况。"})]})]})}),D&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-3",children:[e.jsx(H,{className:"w-4 h-4 animate-spin text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"正在处理中..."})]}),k&&e.jsxs("div",{className:`p-3 rounded-xl text-sm ${k.success?"bg-green-50 text-green-800":"bg-red-50 text-red-800"}`,children:[k.success?"✓ ":"✗ ",k.message]})]}),e.jsx("div",{className:"modal-footer",children:e.jsx("button",{onClick:v,className:"w-full px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors",children:k!=null&&k.success?"完成":"取消"})})]})}),document.body),N&&f&&J.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑订单"}),e.jsx("button",{onClick:n,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(W,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"订单号"}),e.jsx("input",{type:"text",value:f.order_id,disabled:!0,className:"w-full ios-input px-4 py-3 rounded-xl bg-gray-50 text-gray-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"订单状态"}),e.jsxs("select",{value:f.status,onChange:(l=>I({status:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"processing",children:"处理中"}),e.jsx("option",{value:"pending_ship",children:"待发货"}),e.jsx("option",{value:"shipped",children:"已发货"}),e.jsx("option",{value:"completed",children:"已完成"}),e.jsx("option",{value:"cancelled",children:"已取消"}),e.jsx("option",{value:"refunding",children:"退款中"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"买家ID"}),e.jsx("input",{type:"text",value:f.buyer_id,onChange:(l=>I({buyer_id:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"实付金额"}),e.jsx("input",{type:"number",value:f.amount,onChange:(l=>I({amount:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"收货人"}),e.jsx("input",{type:"text",value:f.receiver_name||"",onChange:(l=>I({receiver_name:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"联系电话"}),e.jsx("input",{type:"text",value:f.receiver_phone||"",onChange:(l=>I({receiver_phone:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"收货地址"}),e.jsx("textarea",{value:f.receiver_address||"",onChange:(l=>I({receiver_address:l.target.value})),rows:2,className:"w-full ios-input px-4 py-3 rounded-xl resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"商品标题"}),e.jsx("input",{type:"text",value:f.item_title||"",onChange:(l=>I({item_title:l.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:n,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:E,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(he,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body)]})};export{Je as default};
diff --git a/internal/webui/static/assets/Rules-BplaKbZv.js b/internal/webui/static/assets/Rules-Dt-wqBt3.js
similarity index 99%
rename from internal/webui/static/assets/Rules-BplaKbZv.js
rename to internal/webui/static/assets/Rules-Dt-wqBt3.js
index 2e7ce2d..aba78d9 100644
--- a/internal/webui/static/assets/Rules-BplaKbZv.js
+++ b/internal/webui/static/assets/Rules-Dt-wqBt3.js
@@ -1 +1 @@
-import{j as e,r as o,b as De}from"./react-vendor-C_od1ZSF.js";import{k as Je,ae as it,af as vt,m as Nt,R as Te,N as Ye,Z as He,x as wt,w as et,I as kt,a1 as Ct,X as ke,V as ze,F as Ce,h as St,g as Rt,a6 as At,ag as $t,r as tt,ah as Mt}from"./icons-vendor-CvzvbbIV.js";import{g as Z,p as Ge,a as fe,d as Ke}from"./index-hByDAHGj.js";import{o as Ae,c as Ue}from"./contract-COFcZjyb.js";const Ee=(t,a)=>t.allowed_resolutions.includes(a),Pt=(t,a)=>({runs:t.runs.filter(i=>!a||i.cookie_id===a),pending_tasks:t.pending_tasks.filter(i=>!a||i.cookie_id===a)}),Lt=t=>({external_result_unknown:"外部动作结果未知",invalid_snapshot:"历史数据无法恢复",rule_unavailable:"规则不可用",partial_failure:"部分动作失败",execution_failed:"动作执行失败"})[t]||"自动化异常",It=({runs:t,pendingTasks:a,onResolveRun:i,onResolveDeferredTask:u})=>e.jsxs("section",{className:"rounded-2xl border border-red-200 bg-red-50 p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Je,{className:"w-5 h-5 text-red-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-black text-red-900",children:"需要人工处理的自动化任务"}),e.jsx("p",{className:"text-sm text-red-700 mt-1",children:"请先在闲鱼聊天、订单或商品列表中核对真实结果,再选择继续或重试。"})]})]}),e.jsxs("div",{className:"space-y-3",children:[t.map(r=>e.jsxs("div",{className:"rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-bold text-gray-900",children:["账号 ",r.cookie_id," · 订单 ",r.order_id||"-"," · 已记录发送 ",r.sent_count," 条"]}),e.jsx("div",{className:"text-xs font-bold text-red-800 mt-1",children:Lt(r.issue_kind)}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:r.error_message})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 shrink-0",children:[Ee(r,"continue")&&e.jsx("button",{onClick:(()=>i(r.id,"continue")),className:"px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold",children:"已执行,继续下一步"}),Ee(r,"retry")&&e.jsx("button",{onClick:(()=>i(r.id,"retry")),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"未执行,安全重试"}),Ee(r,"cancel")&&e.jsx("button",{onClick:(()=>i(r.id,"cancel")),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"终止"})]})]},`run-${r.id}`)),a.map(r=>e.jsxs("div",{className:"rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-bold text-gray-900",children:["账号 ",r.cookie_id," · 延迟任务重试已达 ",r.attempt_count," 次"]}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:r.error_message})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:(()=>u(r.id,"retry")),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"重新入队"}),e.jsx("button",{onClick:(()=>u(r.id,"dismiss")),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"忽略"})]})]},`task-${r.id}`))]})]}),Ft=async t=>Z("/api/v1/accounts/details",void 0,t),ot=async t=>Z("/api/v1/cards",void 0,t),dt=async(t,a)=>Z("/api/v1/items",void 0,a),ct=t=>t.map(a=>{var i,u;return{id:String(a.id),name:a.name||"",trigger_type:a.trigger_type||"order_paid",item_keyword:a.item_title||a.item_id||"",cookie_id:a.cookie_id||"",item_id:a.item_id||"",item_title:a.item_title||"",card_group_id:Number(((i=(a.actions||[]).find(r=>r.action_type==="send_card"))==null?void 0:i.card_id)||0),card_group_name:((u=(a.actions||[]).find(r=>r.action_type==="send_card"))==null?void 0:u.card_name)||"",priority:a.priority||100,enabled:a.enabled||!1,config_json:a.config_json||"{}",actions:(a.actions||[]).map(r=>({id:r.id?String(r.id):void 0,action_type:r.action_type,card_id:Number(r.card_id||0),card_name:r.card_name||"",delivery_count:Number(r.delivery_count||1),message_template:r.message_template||"",delay_seconds:Number(r.delay_seconds||0),config_json:r.config_json||"{}",enabled:r.enabled!==!1,sort_order:Number(r.sort_order||0)})),variants:(a.actions||[]).filter(r=>r.action_type==="send_card").map(r=>{let y={};try{y=JSON.parse(r.config_json||"{}")}catch{}return{id:r.id?String(r.id):void 0,spec_name:y.spec_name||"",spec_value:y.spec_value||"",card_id:Number(r.card_id||0),card_name:r.card_name||"",delivery_count:Number(r.delivery_count||1),enabled:r.enabled!==!1,delay_override:y.delay_override===!0,delay_seconds:Number(r.delay_seconds||0),config_json:r.config_json||"{}"}})}}),Dt=async()=>{const t=await Z("/api/v1/automation-rules"),a=Ue(t,["data","rules","items"]);return ct(a)},Tt=async({cookieId:t,triggerType:a,enabled:i,search:u,page:r=1,pageSize:y=10}={})=>{const A=await Z("/api/v1/automation-rules",{page:r,page_size:y,cookie_id:t||void 0,trigger_type:a||void 0,enabled:i,search:(u==null?void 0:u.trim())||void 0}),C=Ae(A,["data","result"])||{},m=ct(Ue(A,["data","rules","items"]));return{success:!0,data:m,total:Number(C.total??m.length),page:Number(C.page??r),page_size:Number(C.page_size??y),total_pages:Number(C.total_pages??(m.length?1:0)),trigger_counts:Object.fromEntries(Object.entries(C.trigger_counts||{}).map(([I,T])=>[I,Number(T)]))}},zt=(t,a)=>{if(t!=="order_paid")return a.map((r,y)=>({...r,sort_order:r.sort_order||y+1}));const i=a.filter(r=>r.action_type==="send_card").map((r,y)=>({...r,sort_order:y+1})),u=a.filter(r=>r.action_type!=="send_card"&&r.action_type!=="confirm_shipment");return[...i,...u.map((r,y)=>({...r,sort_order:i.length+y+1})),{action_type:"confirm_shipment",enabled:!0,sort_order:i.length+u.length+1}]},st=async t=>{const a=t.trigger_type||"order_paid",u=[{order_paid:"付款后自动发货",buyer_reviewed:"评价后发送赠品",review_missing_timeout:"超时未评价求评价"}[a]||"自动化规则",t.item_title||t.item_id||t.cookie_id||""].filter(Boolean).join(" - "),r=(t.actions||[]).filter(m=>m.action_type!=="send_card"&&m.action_type!=="confirm_shipment"),y=t.variants&&t.variants.length>0?[...t.variants.map((m,I)=>({action_type:"send_card",card_id:m.card_id,delivery_count:m.delivery_count||1,enabled:m.enabled!==!1,sort_order:I+1,delay_seconds:m.delay_seconds||0,config_json:JSON.stringify({spec_name:m.spec_name||"",spec_value:m.spec_value||"",delay_override:m.delay_override===!0})})),...r]:t.actions&&t.actions.length>0?t.actions:[{action_type:"send_card",card_id:t.card_group_id||0,delivery_count:1,enabled:!0,sort_order:1}],A=zt(a,y),C={cookie_id:t.cookie_id||"",item_id:t.item_id||"",name:(t.name||"").trim()||u||"自动化规则",trigger_type:a,enabled:t.enabled??!0,priority:t.priority||100,config_json:t.config_json||"{}",actions:A.map((m,I)=>({action_type:m.action_type,card_id:m.card_id||0,delivery_count:m.delivery_count||1,message_template:m.message_template||"",delay_seconds:m.delay_seconds||0,config_json:m.config_json||"{}",enabled:m.enabled!==!1,sort_order:m.sort_order||I+1}))};return t.id?Ge(`/api/v1/automation-rules/${t.id}`,C):fe("/api/v1/automation-rules",C)},Et=async t=>Ke(`/api/v1/automation-rules/${t}`),Ot=async()=>{const t=await Z("/api/v1/automation-issues"),a=Ae(t,["data","result"])||{};return{runs:Array.isArray(a==null?void 0:a.runs)?a.runs:[],pending_tasks:Array.isArray(a==null?void 0:a.pending_tasks)?a.pending_tasks:[]}},qt=async(t,a)=>fe(`/api/v1/automation-runs/${t}/resolve`,{resolution:a}),Vt=async(t,a)=>fe(`/api/v1/automation-pending-tasks/${t}/resolve`,{resolution:a}),Bt=t=>({id:String((t==null?void 0:t.id)||""),keyword:(t==null?void 0:t.keyword)||"",reply:(t==null?void 0:t.reply)||"",item_id:(t==null?void 0:t.item_id)||"",type:(t==null?void 0:t.type)==="image"?"image":"text",image_url:(t==null?void 0:t.image_url)||""}),Jt=async t=>{const a=await Z(`/api/v1/reply-rules/${t}/typed`);return Ue(a,["data","items","rules"]).map(Bt)},Gt=async t=>t?(await Jt(t)).map(i=>({id:i.id,keyword:i.keyword||"",reply_content:i.reply||"",match_type:"fuzzy",enabled:!0,item_id:i.item_id||"",type:i.type==="image"?"image":"text",image_url:i.image_url||""})):[],Kt=async(t,a)=>{const i=t.type||"text",u={keyword:t.keyword||"",reply:i==="text"&&t.reply_content||"",item_id:t.item_id||"",type:i,image_url:i==="image"&&t.image_url||""};return t.id?Ge(`/api/v1/reply-rules/${a}/typed/${t.id}`,u):fe(`/api/v1/reply-rules/${a}/items`,u)},Ut=async(t,a)=>Ke(`/api/v1/reply-rules/${a}/typed/${t}`),at=async()=>{const t=await Z("/api/v1/default-replies");return Ae(t,["data","replies","items"])||{}},Wt=async t=>{const a=await Z(`/api/v1/default-replies/${t}`),i=Ae(a,["data","result"])||{};return{cookie_id:t,enabled:i.enabled||!1,reply_content:i.reply_content||"",reply_once:i.reply_once||!1,reply_image_url:i.reply_image_url||""}},Zt=async(t,a)=>Ge(`/api/v1/default-replies/${t}`,{enabled:a.enabled??!1,reply_content:a.reply_content||"",reply_once:a.reply_once??!1,reply_image_url:a.reply_image_url||""}),Xt=async t=>Ke(`/api/v1/default-replies/${t}`),Qt=async t=>fe(`/api/v1/default-replies/${t}/clear-records`,{}),Oe=()=>({submitting:!1,result:"idle"}),qe=t=>t.submitting?t:{submitting:!0,result:"idle"},Ve=(t,a)=>({submitting:!1,result:a?"success":"failure"}),rt=t=>t+1,Be=(t,a,i,u)=>t===a&&i===u,Yt=t=>{const[a,i]=o.useState([]),[u,r]=o.useState({runs:[],pending_tasks:[]}),[y,A]=o.useState([]),[C,m]=o.useState({}),[I,T]=o.useState([]),[J,w]=o.useState([]),[G,F]=o.useState([]),[v,X]=o.useState(!1),q=o.useRef(0),re=o.useRef(0),[Q,K]=o.useState(0),[le,Y]=o.useState(0),[V,H]=o.useState({}),U=o.useCallback(async()=>{const P=Promise.all([Ft(),ot(),dt(),at()]),[_,j,D,ee]=await P;T(_),w(j),F(D),m(ee),t.setSelectedAccountId(ne=>{var E;return ne||((E=_[0])==null?void 0:E.id)||""})},[t.setSelectedAccountId]),n=o.useCallback(async()=>{var ee;const P=rt(q.current);q.current=P;const _=Ot().catch(ne=>(console.warn("加载自动化异常列表失败,不阻断规则展示",ne),null)),j=await Tt({cookieId:t.selectedAccountId||void 0,triggerType:t.automationTriggerFilter,enabled:t.automationStatusFilter==="all"?void 0:t.automationStatusFilter==="enabled",search:t.debouncedAutomationSearch,page:t.automationPage,pageSize:t.automationPageSize});if(!Be(P,q.current,t.selectedAccountId,t.selectedAccountId))return;i(j.data),K(j.total),Y(j.total_pages),H(j.trigger_counts||{}),j.page!==t.automationPage&&((ee=t.onAutomationPageChange)==null||ee.call(t,j.page));const D=await _;Be(P,q.current,t.selectedAccountId,t.selectedAccountId)&&D&&r(D)},[t.automationPage,t.automationPageSize,t.automationStatusFilter,t.automationTriggerFilter,t.debouncedAutomationSearch,t.onAutomationPageChange,t.selectedAccountId]),$=o.useCallback(async()=>{const P=rt(re.current);re.current=P;const _=t.selectedAccountId;if(A([]),!_)return;const j=await Gt(_);Be(P,re.current,_,t.selectedAccountId)&&A(j)},[t.selectedAccountId]),R=o.useCallback(async()=>{m(await at())},[]),z=o.useCallback(async()=>{X(!0);try{t.activeTab==="automation"?await n():t.activeTab==="reply"?await $():await R()}finally{X(!1)}},[n,R,$,t.activeTab]);return{automationRules:a,automationIssues:u,replyRules:y,defaultReplies:C,accounts:I,cards:J,items:G,automationTotal:Q,automationTotalPages:le,automationTriggerCounts:V,loading:v,setLoading:X,setAutomationRules:i,setCards:w,setItems:F,loadReferenceData:U,loadAutomationRules:n,loadReplyRules:$,loadDefaultReplies:R,refresh:z}},ae={order_paid:{label:"付款后自动发货",shortLabel:"自动发货",description:"闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。",flow:["付款系统卡片","匹配商品/规格","发送卡密","确认发货"],accent:"blue",icon:Nt},buyer_reviewed:{label:"评价后发送赠品",shortLabel:"评价赠品",description:"闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。",flow:["评价系统卡片","匹配商品/规格","发送赠品"],accent:"emerald",icon:vt},review_missing_timeout:{label:"超时未评价求评价",shortLabel:"求评价",description:"计划任务扫描已发货未评价订单,到期后发送求评价文案。",flow:["计划任务扫描","已发货未评价","达到等待时间","发送提醒"],accent:"amber",icon:it}},Se=["order_paid","buyer_reviewed","review_missing_timeout"],Ht="亲,商品使用满意的话,麻烦给个评价,谢谢~",he=()=>({spec_name:"",spec_value:"",card_id:0,delivery_count:1,enabled:!0,delay_override:!1,delay_seconds:0}),mt=t=>{if(!t)return{};try{const a=JSON.parse(t);return a&&typeof a=="object"&&!Array.isArray(a)?a:{}}catch{return{}}},ce=(t,a={})=>{const i=mt(t);return JSON.stringify({after_shipped_hours:Number(i.after_shipped_hours||72),repeat_interval_hours:Number(i.repeat_interval_hours||24),max_attempts:Number(i.max_attempts||1),...a})},ye=(t,a)=>{var u;const i=((u=ae[t])==null?void 0:u.label)||"自动化规则";return a?`${i} - ${a}`:i},lt=t=>{const a=(t||"").trim();return a?Object.values(ae).some(i=>a===i.label||a.startsWith(`${i.label} -`)):!0},_e=(t,a=0)=>{if(t==="review_missing_timeout")return[{action_type:"send_text",message_template:Ht,enabled:!0,sort_order:1}];const i={action_type:"send_card",card_id:a,delivery_count:1,enabled:!0,sort_order:1};return t==="order_paid"?[i,{action_type:"confirm_shipment",enabled:!0,sort_order:2}]:[i]},es=t=>{var i,u;if(t.trigger_type==="review_missing_timeout")return((u=(i=t.actions)==null?void 0:i.find(r=>r.action_type==="send_text"))==null?void 0:u.message_template)||"发送求评价文案";const a=(t.actions||[]).filter(r=>r.action_type==="send_card");return a.length?a.map(r=>r.card_name||`卡密 ${r.card_id}`).join(" / "):"未配置卡密库存"},nt=(t,a=!1)=>{const i={blue:a?"border-blue-500 bg-blue-50 text-blue-700":"border-blue-100 bg-blue-50/60 text-blue-700 hover:border-blue-300",emerald:a?"border-emerald-500 bg-emerald-50 text-emerald-700":"border-emerald-100 bg-emerald-50/60 text-emerald-700 hover:border-emerald-300",amber:a?"border-amber-500 bg-amber-50 text-amber-700":"border-amber-100 bg-amber-50/60 text-amber-700 hover:border-amber-300"};return i[t]||i.blue},ts=t=>t?"bg-emerald-100 text-emerald-700":"bg-gray-200 text-gray-500",Re=t=>(t==null?void 0:t.nickname)||(t==null?void 0:t.remark)||(t==null?void 0:t.id)||"未知账号",ss=t=>t===!0||t===1||t==="1",as=({selectedAccountId:t,setSelectedAccountId:a,setActiveTab:i,items:u,setAutomationRules:r,setCards:y,setItems:A,setLoading:C,loadAutomationRules:m,loadReferenceData:I,loadReplyRules:T,loadDefaultReplies:J,initialDeliveryTarget:w,onDeliveryTargetHandled:G})=>{var xe;const[F,v]=o.useState(!1),[X,q]=o.useState(!1),[re,Q]=o.useState(!1),[K,le]=o.useState(Oe),[Y,V]=o.useState(Oe),[H,U]=o.useState(Oe),[n,$]=o.useState(null),[R,z]=o.useState(null),[M,P]=o.useState({cookie_id:"",enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""}),_=o.useMemo(()=>n!=null&&n.cookie_id&&n.item_id?u.find(l=>l.cookie_id===n.cookie_id&&l.item_id===n.item_id):void 0,[n==null?void 0:n.cookie_id,n==null?void 0:n.item_id,u]),j=ss(_==null?void 0:_.is_multi_spec),D=(n==null?void 0:n.trigger_type)||"order_paid",ee=ae[D],ne=mt(n==null?void 0:n.config_json),E=(xe=n==null?void 0:n.variants)!=null&&xe.length?n.variants:[he()],W=o.useCallback((l="order_paid",d=t,b="")=>{const p=u.find(N=>N.cookie_id===d&&N.item_id===b),h=(p==null?void 0:p.item_title)||b;return{name:ye(l,h),trigger_type:l,cookie_id:d,item_id:b,item_title:(p==null?void 0:p.item_title)||"",item_keyword:h,card_group_id:0,priority:100,enabled:!0,config_json:l==="review_missing_timeout"?ce():"{}",actions:_e(l),variants:l==="review_missing_timeout"?[]:[he()]}},[u,t]),ue=o.useCallback(l=>{var b,p;const d=l.trigger_type||"order_paid";$({...l,trigger_type:d,config_json:d==="review_missing_timeout"?ce(l.config_json):l.config_json||"{}",actions:(b=l.actions)!=null&&b.length?l.actions.map(h=>({...h})):_e(d,l.card_group_id),variants:(p=l.variants)!=null&&p.length?l.variants.map(h=>({...h})):d==="review_missing_timeout"?[]:[he()]}),v(!0)},[]);o.useEffect(()=>{if(!w)return;let l=!1;return(async()=>{i("automation"),a(w.cookieId),C(!0);try{const[b,p,h]=await Promise.all([Dt(),dt(),ot().catch(f=>(console.warn("加载卡密库存失败,不阻断打开自动化规则",f),[]))]);if(l)return;r(b),A(p),y(h);const N=b.find(f=>f.cookie_id===w.cookieId&&f.item_id===w.itemId&&f.trigger_type==="order_paid");if(N)ue(N);else{const f=p.find(B=>B.cookie_id===w.cookieId&&B.item_id===w.itemId);$({...W("order_paid",w.cookieId,w.itemId),item_title:(f==null?void 0:f.item_title)||"",item_keyword:(f==null?void 0:f.item_title)||w.itemId,name:ye("order_paid",(f==null?void 0:f.item_title)||w.itemId)}),v(!0)}}catch(b){console.error("打开商品自动化规则失败",b),alert("无法加载该商品的自动化规则")}finally{l||(C(!1),G==null||G())}})(),(()=>{l=!0})},[W,w,G,ue,i,r,y,A,C,a]);const $e=o.useCallback((l="order_paid")=>{if(!t){alert("请先选择账号");return}$(W(l)),v(!0)},[W,t]),je=o.useCallback(l=>{var p,h,N,f,B;if(!n)return;const d=((h=(p=n.variants)==null?void 0:p.find(se=>se.card_id))==null?void 0:h.card_id)||((f=(N=n.actions)==null?void 0:N.find(se=>se.action_type==="send_card"))==null?void 0:f.card_id)||n.card_group_id||0,b=(_==null?void 0:_.item_title)||n.item_title||n.item_id||"";$({...n,trigger_type:l,name:lt(n.name)?ye(l,b):n.name,card_group_id:d,config_json:l==="review_missing_timeout"?ce(n.config_json):"{}",actions:_e(l,d),variants:l==="review_missing_timeout"?[]:(B=n.variants)!=null&&B.length?n.variants:[{...he(),card_id:d}]})},[n,_]),Me=o.useCallback(l=>{if(!n)return;const d=u.find(p=>p.cookie_id===(n.cookie_id||t)&&p.item_id===l),b=(d==null?void 0:d.item_title)||l;$({...n,item_id:l,item_title:(d==null?void 0:d.item_title)||"",item_keyword:b,name:lt(n.name)?ye(D,b):n.name})},[D,n,u,t]),pe=o.useCallback((l,d)=>{var p;if(!n)return;const b=E.map((h,N)=>N===l?{...h,...d}:h);$({...n,variants:b,card_group_id:((p=b[0])==null?void 0:p.card_id)||0})},[E,n]),Pe=o.useCallback(()=>{if(!n)return;const l=E[E.length-1];$({...n,variants:[...E,{...he(),spec_name:j&&(l==null?void 0:l.spec_name)||"",spec_value:j&&(l==null?void 0:l.spec_value)||""}]})},[E,n,j]),ve=o.useCallback(async()=>{var h,N,f,B,se;if(!n||K.submitting)return;const l=n.trigger_type||"order_paid";if(!n.cookie_id)return alert("请选择账号");const d=(h=n.variants)!=null&&h.length?n.variants:[];if(l!=="review_missing_timeout"){if(!d.length||d.some(k=>!k.card_id))return alert(l==="buyer_reviewed"?"请选择评价赠品卡密库存":"请选择发货卡密库存");if(j&&d.some(k=>!k.spec_name.trim()||!k.spec_value.trim()))return alert("多规格商品必须填写每一行的规格名称和规格值")}if(l==="review_missing_timeout"&&!(((f=(N=n.actions)==null?void 0:N.find(Le=>Le.action_type==="send_text"))==null?void 0:f.message_template)||"").trim())return alert("请填写求评价文案");const b=l==="review_missing_timeout"?[]:d.map(k=>({...k,spec_name:j?k.spec_name.trim():"",spec_value:j?k.spec_value.trim():"",delivery_count:Math.max(1,Number(k.delivery_count)||1),enabled:k.enabled!==!1}));le(qe(K));let p=!1;try{await st({...n,trigger_type:l,name:(n.name||"").trim()||ye(l,(_==null?void 0:_.item_title)||n.item_id||""),config_json:l==="review_missing_timeout"?ce(n.config_json):n.config_json||"{}",actions:(B=n.actions)!=null&&B.length?n.actions:_e(l,((se=b[0])==null?void 0:se.card_id)||n.card_group_id||0),variants:b}),v(!1),await Promise.all([m(),I()]),alert("保存成功"),p=!0}catch(k){console.error("保存自动化规则失败:",k),alert("保存失败:"+k.message)}finally{le(k=>Ve(k,p))}},[K,n,j,m,I,_]),g=o.useCallback(async l=>{if(confirm("确定删除该自动化规则吗?"))try{await Et(l),await m(),alert("删除成功")}catch(d){alert("删除失败:"+d.message)}},[m]),O=o.useCallback(async l=>{try{await st({...l,enabled:!l.enabled}),await m()}catch(d){alert("操作失败:"+d.message)}},[m]),S=o.useCallback(async(l,d)=>{if(confirm(d==="continue"?"确认外部动作已经执行成功,并跳到下一步吗?":d==="retry"?"确认外部动作没有执行,可以安全重试吗?错误判断可能造成重复发送。":"确认终止该自动化运行吗?"))try{await qt(l,d),await m()}catch(p){alert("处理失败:"+p.message)}},[m]),te=o.useCallback(async(l,d)=>{if(confirm(d==="retry"?"确认重新执行该任务吗?":"确认忽略并删除该异常任务吗?"))try{await Vt(l,d),await m()}catch(b){alert("处理失败:"+b.message)}},[m]),L=o.useCallback(()=>{if(!t)return alert("请先选择账号");z({keyword:"",reply_content:"",image_url:"",item_id:"",type:"text",match_type:"fuzzy",enabled:!0}),q(!0)},[t]),ie=o.useCallback(async()=>{var b,p,h;if(!R||!t||Y.submitting)return;const l=R.type==="image"?!!((b=R.image_url)!=null&&b.trim()):!!((p=R.reply_content)!=null&&p.trim());if(!((h=R.keyword)!=null&&h.trim())||!l)return alert("请填写关键词和回复内容");V(qe(Y));let d=!1;try{await Kt({...R,match_type:"fuzzy",enabled:!0},t),q(!1),await T(),alert("保存成功"),d=!0}catch(N){alert("保存失败:"+N.message)}finally{V(N=>Ve(N,d))}},[R,T,Y,t]),ge=o.useCallback(async l=>{if(!(!t||!confirm("确定删除该回复规则吗?")))try{await Ut(l,t),await T(),alert("删除成功")}catch(d){alert("删除失败:"+d.message)}},[T,t]),oe=o.useCallback(async(l=t)=>{if(!l)return alert("请先选择账号");try{const d=await Wt(l);P({cookie_id:l,enabled:d.enabled,reply_content:d.reply_content,reply_once:d.reply_once,reply_image_url:d.reply_image_url||""})}catch{P({cookie_id:l,enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""})}Q(!0)},[t]),me=o.useCallback(async()=>{if(H.submitting)return;if(!M.cookie_id)return alert("请先选择账号");if(M.enabled&&!M.reply_content.trim()&&!M.reply_image_url.trim())return alert("启用默认回复时,请填写回复内容或图片 URL");U(qe(H));let l=!1;try{await Zt(M.cookie_id,{enabled:M.enabled,reply_content:M.reply_content,reply_once:M.reply_once,reply_image_url:M.reply_image_url}),Q(!1),await J(),alert("保存成功"),l=!0}catch(d){alert("保存失败:"+d.message)}finally{U(d=>Ve(d,l))}},[M,H,J]),Ne=o.useCallback(async l=>{if(confirm("确定删除该账号默认回复吗?"))try{await Xt(l),await J(),alert("删除成功")}catch(d){alert("删除失败:"+d.message)}},[J]),be=o.useCallback(async l=>{if(confirm("确定清空该账号的默认回复记录吗?清空后可重新对所有会话使用“只回复一次”。"))try{await Qt(l),alert("清空成功")}catch(d){alert("清空失败:"+d.message)}},[]);return{showAutomationModal:F,setShowAutomationModal:v,showReplyModal:X,setShowReplyModal:q,showDefaultModal:re,setShowDefaultModal:Q,automationSubmitState:K,replySubmitState:Y,defaultReplySubmitState:H,editingAutomationRule:n,setEditingAutomationRule:$,editingReplyRule:R,setEditingReplyRule:z,defaultForm:M,setDefaultForm:P,selectedRuleItem:_,isMultiSpecRule:j,currentTrigger:D,currentMeta:ee,reviewConfig:ne,displayVariants:E,buildAutomationDraft:W,openAutomationRule:ue,openNewAutomationRule:$e,handleTriggerChange:je,handleAutomationItemChange:Me,updateVariant:pe,appendDeliveryContent:Pe,handleSaveAutomationRule:ve,handleDeleteAutomation:g,handleToggleAutomation:O,handleResolveRunIssue:S,handleResolveDeferredIssue:te,handleAddReplyRule:L,handleSaveReplyRule:ie,handleDeleteReply:ge,openDefaultReplyModal:oe,handleSaveDefaultReply:me,handleDeleteDefaultReply:Ne,handleClearDefaultReplyRecords:be}},os=({initialDeliveryTarget:t,onDeliveryTargetHandled:a})=>{var Xe,Qe;const[i,u]=o.useState("automation"),[r,y]=o.useState(""),[A,C]=o.useState(""),[m,I]=o.useState(""),[T,J]=o.useState(""),[w,G]=o.useState("all"),[F,v]=o.useState(1),[X,q]=o.useState(10),re=Yt({activeTab:i,selectedAccountId:r,automationTriggerFilter:T,automationStatusFilter:w,debouncedAutomationSearch:m,automationPage:F,automationPageSize:X,setSelectedAccountId:y,onAutomationPageChange:v}),{automationRules:Q,automationIssues:K,replyRules:le,defaultReplies:Y,accounts:V,cards:H,items:U,loading:n,setLoading:$,automationTotal:R,automationTotalPages:z,automationTriggerCounts:M,setAutomationRules:P,setCards:_,setItems:j,loadReferenceData:D,loadAutomationRules:ee,loadReplyRules:ne,loadDefaultReplies:E,refresh:W}=re,ue=as({selectedAccountId:r,setSelectedAccountId:y,setActiveTab:u,items:U,setAutomationRules:P,setCards:_,setItems:j,setLoading:$,loadAutomationRules:ee,loadReferenceData:D,loadReplyRules:ne,loadDefaultReplies:E,initialDeliveryTarget:t,onDeliveryTargetHandled:a}),{showAutomationModal:$e,setShowAutomationModal:je,showReplyModal:Me,setShowReplyModal:pe,showDefaultModal:Pe,setShowDefaultModal:ve,editingAutomationRule:g,setEditingAutomationRule:O,editingReplyRule:S,setEditingReplyRule:te,defaultForm:L,setDefaultForm:ie,selectedRuleItem:ge,isMultiSpecRule:oe,currentTrigger:me,currentMeta:Ne,reviewConfig:be,displayVariants:xe,openAutomationRule:l,openNewAutomationRule:d,handleTriggerChange:b,handleAutomationItemChange:p,updateVariant:h,appendDeliveryContent:N,handleSaveAutomationRule:f,handleDeleteAutomation:B,handleToggleAutomation:se,handleResolveRunIssue:k,handleResolveDeferredIssue:Le,handleAddReplyRule:xt,handleSaveReplyRule:ut,handleDeleteReply:pt,openDefaultReplyModal:We,handleSaveDefaultReply:gt,handleDeleteDefaultReply:bt,handleClearDefaultReplyRecords:ht}=ue;o.useEffect(()=>{const s=window.setTimeout(()=>{v(1),I(A.trim())},300);return(()=>window.clearTimeout(s))},[A]),o.useEffect(()=>{D().catch(s=>console.error("加载规则参考数据失败",s))},[D]),o.useEffect(()=>{W().catch(s=>console.error("刷新规则页面失败",s))},[W]);const Ie=o.useMemo(()=>Q.filter(s=>!r||s.cookie_id===r),[Q,r]),we=o.useMemo(()=>Pt(K,r),[K,r]),Ze=o.useMemo(()=>V.filter(s=>!r||s.id===r),[V,r]),yt=o.useMemo(()=>{if(z<=1)return[];const s=Math.max(1,Math.min(F-2,z-4)),c=Math.min(z,s+4);return Array.from({length:c-s+1},(x,de)=>s+de)},[F,z]),Fe=!!(A.trim()||T||w!=="all"),_t=()=>{C(""),I(""),J(""),G("all"),v(1)},ft=o.useMemo(()=>{const s=(g==null?void 0:g.cookie_id)||r;return U.filter(c=>c.cookie_id===s)},[g==null?void 0:g.cookie_id,U,r]),jt=i==="automation"?"新建自动化":i==="reply"?"新增关键词":"编辑默认回复";return e.jsxs("div",{className:"min-w-0 space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row justify-between xl:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"系统通知卡片只进入自动化判断;买家消息进入关键词、默认或 AI 回复。"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:flex-wrap gap-3",children:[e.jsxs("select",{value:r,onChange:(s=>{y(s.target.value),v(1)}),className:"ios-input w-full px-4 py-3 rounded-2xl text-sm sm:w-64",children:[e.jsx("option",{value:"",children:"全部账号"}),V.map(s=>e.jsx("option",{value:s.id,children:Re(s)},s.id))]}),e.jsxs("button",{onClick:W,className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 hover:bg-gray-200 text-gray-700 flex items-center justify-center gap-2 whitespace-nowrap transition-colors",children:[e.jsx(Te,{className:`w-4 h-4 ${n?"animate-spin":""}`}),"刷新"]}),e.jsxs("button",{onClick:i==="automation"?(()=>d("order_paid")):i==="reply"?xt:(()=>void We()),disabled:!r,className:"ios-btn-primary px-5 py-3 rounded-2xl text-sm font-extrabold flex items-center justify-center gap-2 whitespace-nowrap disabled:opacity-50",children:[e.jsx(Ye,{className:"w-4 h-4"}),jt]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[{id:"automation",label:"交易自动化",icon:He},{id:"reply",label:"关键词回复",icon:wt},{id:"default",label:"账号默认回复",icon:et}].map(s=>{const c=s.icon;return e.jsxs("button",{onClick:(()=>u(s.id)),className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${i===s.id?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:[e.jsx(c,{className:"w-4 h-4"}),s.label]},s.id)})}),i==="automation"&&(we.runs.length>0||we.pending_tasks.length>0)&&e.jsx(It,{runs:we.runs,pendingTasks:we.pending_tasks,onResolveRun:((s,c)=>void k(s,c)),onResolveDeferredTask:((s,c)=>void Le(s,c))}),i==="automation"&&e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-6 xl:grid-cols-[minmax(270px,0.72fr)_minmax(0,1.28fr)]",children:[e.jsxs("aside",{className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-gray-100 shadow-sm",children:[e.jsx("h3",{className:"font-black text-gray-900 mb-1",children:"新建规则"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"先选自动化类型,再配置对应动作。"}),e.jsx("div",{className:"space-y-3",children:Se.map(s=>{const c=ae[s],x=c.icon;return e.jsx("button",{type:"button",onClick:(()=>d(s)),className:`w-full text-left rounded-2xl border p-4 transition-colors ${nt(c.accent)}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-white/80 flex items-center justify-center shrink-0",children:e.jsx(x,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:c.label}),e.jsx("div",{className:"text-xs opacity-75 mt-1 leading-5",children:c.description})]})]})},s)})})]}),e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-gray-100 shadow-sm",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"font-black text-gray-900",children:"筛选结果构成"}),e.jsxs("span",{className:"text-xs font-bold text-gray-400",children:["共 ",R," 条"]})]}),e.jsx("div",{className:"space-y-3",children:Se.map(s=>{const c=ae[s],x=c.icon;return e.jsxs("div",{className:"flex items-center justify-between rounded-2xl bg-gray-50 p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(x,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:c.shortLabel})]}),e.jsx("span",{className:"text-sm font-black text-gray-900",children:M[s]||0})]},s)})})]})]}),e.jsxs("section",{className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-gray-100 bg-surface-muted p-4 shadow-sm",children:[e.jsxs("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(kt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"搜索自动化规则",placeholder:"搜索规则名、商品名或商品 ID...",value:A,onChange:(s=>{C(s.target.value),v(1)}),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]}),e.jsxs("div",{className:"relative xl:w-52",children:[e.jsx(Ct,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按自动化类型筛选",value:T,onChange:(s=>{J(s.target.value),v(1)}),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部自动化类型"}),Se.map(s=>e.jsx("option",{value:s,children:ae[s].shortLabel},s))]})]}),e.jsxs("select",{"aria-label":"按启用状态筛选",value:w,onChange:(s=>{G(s.target.value),v(1)}),className:"ios-input rounded-xl border-none bg-white px-4 py-2.5 text-sm shadow-sm xl:w-36",children:[e.jsx("option",{value:"all",children:"全部状态"}),e.jsx("option",{value:"enabled",children:"已启用"}),e.jsx("option",{value:"disabled",children:"已禁用"})]}),Fe&&e.jsx("button",{type:"button",onClick:_t,className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-white text-gray-500 shadow-sm transition-colors hover:bg-gray-100 hover:text-gray-900",title:"清除筛选","aria-label":"清除筛选",children:e.jsx(ke,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-xs font-bold text-gray-400",children:[e.jsxs("span",{children:["找到 ",R," 条规则"]}),n&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}),"正在更新"]})]})]}),n&&Ie.length===0?e.jsxs("div",{className:"flex min-h-56 items-center justify-center rounded-xl border border-gray-100 bg-white text-sm font-bold text-gray-400",children:[e.jsx(Te,{className:"mr-2 h-4 w-4 animate-spin"}),"正在加载规则"]}):Ie.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-dashed border-gray-200 p-16 text-center",children:[e.jsx(He,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-black text-gray-900",children:Fe?"没有匹配的自动化规则":"还没有自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2",children:Fe?"调整或清除筛选条件后再试。":"从左侧选择一个模板开始配置。"})]}):Ie.map(s=>{const c=ae[s.trigger_type],x=c.icon;return e.jsx("article",{className:"bg-white rounded-xl border border-gray-100 p-5 shadow-sm hover:shadow-lg transition-all",children:e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-4 min-w-0",children:[e.jsx("div",{className:`w-12 h-12 rounded-2xl flex items-center justify-center shrink-0 ${nt(c.accent,!0)}`,children:e.jsx(x,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("h3",{className:"text-lg font-black text-gray-900 truncate",children:s.name}),e.jsx("span",{className:`px-2.5 py-1 rounded-full text-xs font-bold ${ts(s.enabled)}`,children:s.enabled?"已启用":"已禁用"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-bold",children:[e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:c.label}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:s.item_title||s.item_id||"账号级规则"}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-blue-50 text-blue-700",children:es(s)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:(()=>l(s)),className:"px-4 py-2 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-700 text-sm font-bold flex items-center gap-2",children:[e.jsx(ze,{className:"w-4 h-4"}),"编辑"]}),e.jsx("button",{onClick:(()=>se(s)),className:`px-4 py-2 rounded-xl text-sm font-bold ${s.enabled?"bg-amber-50 text-amber-700 hover:bg-amber-100":"bg-emerald-50 text-emerald-700 hover:bg-emerald-100"}`,children:s.enabled?"禁用":"启用"}),e.jsx("button",{onClick:(()=>B(s.id)),className:"p-2.5 rounded-xl text-red-500 hover:bg-red-50",title:"删除",children:e.jsx(Ce,{className:"w-4 h-4"})})]})]})},s.id)}),R>0&&e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-gray-100 bg-white px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm font-medium text-gray-500",children:[e.jsxs("span",{children:["第 ",F," / ",Math.max(z,1)," 页"]}),e.jsx("span",{className:"h-4 w-px bg-gray-200"}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"sr-only",children:"每页显示数量"}),e.jsx("select",{value:X,onChange:(s=>{q(Number(s.target.value)),v(1)}),className:"ios-input rounded-lg border-none bg-gray-50 px-2.5 py-2 text-sm",children:[10,20,50].map(s=>e.jsxs("option",{value:s,children:[s," 条/页"]},s))})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",disabled:F<=1||n,onClick:(()=>v(s=>Math.max(1,s-1))),className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-50 text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"上一页",title:"上一页",children:e.jsx(St,{className:"h-4 w-4"})}),yt.map(s=>e.jsx("button",{type:"button",disabled:n,onClick:(()=>v(s)),className:`h-9 min-w-9 rounded-lg px-2 text-sm font-bold transition-colors ${s===F?"bg-brand text-white":"bg-gray-50 text-gray-600 hover:bg-gray-100"} disabled:cursor-not-allowed disabled:opacity-60`,"aria-label":`第 ${s} 页`,"aria-current":s===F?"page":void 0,children:s},s)),e.jsx("button",{type:"button",disabled:F>=z||n,onClick:(()=>v(s=>Math.min(z,s+1))),className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-50 text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"下一页",title:"下一页",children:e.jsx(Rt,{className:"h-4 w-4"})})]})]})]})]}),i==="reply"&&e.jsxs("section",{className:"bg-white rounded-xl border border-gray-100 p-6 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-blue-700 bg-blue-50 px-4 py-2 rounded-xl mb-5 w-fit",children:[e.jsx(Je,{className:"w-4 h-4"}),"这里只处理买家用户消息;系统通知不会进入关键词或 AI 回复。"]}),e.jsxs("div",{className:"space-y-3",children:[le.map(s=>e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border border-gray-100 bg-surface-subtle hover:bg-white hover:shadow-lg transition-all gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"px-3 py-1 bg-black text-white rounded-lg text-xs font-bold",children:"包含匹配"}),e.jsxs("h3",{className:"font-bold text-gray-900",children:["“",s.keyword,"”"]})]}),e.jsx("div",{className:"bg-white p-3 rounded-xl border border-gray-100 text-sm text-gray-600 leading-relaxed",children:s.type==="image"&&s.image_url?s.image_url:s.reply_content})]}),e.jsxs("div",{className:"flex items-center gap-3 border-t md:border-t-0 md:border-l border-gray-200 pt-4 md:pt-0 md:pl-6",children:[e.jsx("button",{onClick:(()=>{te({...s}),pe(!0)}),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(ze,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>pt(s.id)),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Ce,{className:"w-5 h-5"})})]})]},s.id)),le.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无关键词回复规则"})]})]}),i==="default"&&e.jsxs("section",{className:"bg-white rounded-xl border border-gray-100 p-6 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-blue-700 bg-blue-50 px-4 py-2 rounded-xl mb-5 w-fit",children:[e.jsx(Je,{className:"w-4 h-4"}),"默认回复只处理买家用户消息;关键词未命中且 AI 未接管时才会使用。"]}),e.jsxs("div",{className:"space-y-3",children:[Ze.map(s=>{const c=Y[s.id],x=!!(c!=null&&c.enabled);return e.jsxs("div",{className:`flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border transition-all gap-4 ${x?"border-purple-100 bg-purple-50/50 hover:bg-white hover:shadow-lg":"border-gray-100 bg-surface-subtle hover:bg-white hover:shadow-lg"}`,children:[e.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[e.jsx("div",{className:`w-12 h-12 rounded-2xl flex items-center justify-center ${x?"bg-purple-600 text-white":"bg-gray-200 text-gray-400"}`,children:e.jsx(et,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h3",{className:"font-bold text-gray-900 text-lg truncate",children:Re(s)}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-xs font-bold ${x?"bg-green-100 text-green-700":"bg-gray-200 text-gray-500"}`,children:x?"已启用":"未启用"}),(c==null?void 0:c.reply_once)&&e.jsx("span",{className:"px-2 py-0.5 rounded-lg text-xs font-bold bg-purple-100 text-purple-700",children:"只回复一次"})]}),e.jsx("div",{className:"text-sm text-gray-600 line-clamp-2",children:x?c.reply_content||c.reply_image_url||"已配置默认回复":"未配置默认回复"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 border-t md:border-t-0 md:border-l border-gray-200 pt-4 md:pt-0 md:pl-6",children:[e.jsx("button",{onClick:(()=>void We(s.id)),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(ze,{className:"w-4 h-4"})}),x&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:(()=>void ht(s.id)),className:"px-3 py-2 text-xs font-bold text-blue-600 hover:bg-blue-50 rounded-xl transition-colors",children:"清空记录"}),e.jsx("button",{onClick:(()=>void bt(s.id)),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Ce,{className:"w-5 h-5"})})]})]})]},s.id)}),Ze.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无账号"})]})]}),$e&&g&&De.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"72rem",maxHeight:"92vh"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-black text-gray-900",children:g.id?"编辑自动化规则":"新建自动化规则"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:Ne.description})]}),e.jsx("button",{onClick:(()=>je(!1)),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",title:"关闭",children:e.jsx(ke,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[320px_1fr] min-h-0",children:[e.jsxs("aside",{className:"bg-slate-900 text-white p-5 overflow-y-auto",children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 mb-3",children:"选择自动化类型"}),e.jsx("div",{className:"space-y-3",children:Se.map(s=>{const c=ae[s],x=c.icon,de=me===s;return e.jsx("button",{type:"button",onClick:(()=>b(s)),className:`w-full rounded-2xl p-4 text-left border transition-all ${de?"bg-white text-slate-950 border-white":"bg-white/5 text-white border-white/10 hover:bg-white/10"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(x,{className:`w-5 h-5 mt-0.5 ${de?"text-brand":"text-white"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black",children:c.label}),e.jsx("div",{className:`text-xs mt-1 leading-5 ${de?"text-gray-500":"text-gray-400"}`,children:c.description})]})]})},s)})}),e.jsxs("div",{className:"mt-6 rounded-2xl bg-white/5 border border-white/10 p-4",children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 mb-3",children:"执行流程"}),e.jsx("div",{className:"space-y-3",children:Ne.flow.map((s,c)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-white text-slate-950 text-xs font-black flex items-center justify-center",children:c+1}),e.jsx("span",{className:"text-sm font-bold text-gray-100",children:s})]},s))})]})]}),e.jsx("div",{className:"p-6 overflow-y-auto bg-surface-subtle",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(At,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:"生效范围"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"规则名称"}),e.jsx("input",{type:"text",value:g.name||"",onChange:(s=>O({...g,name:s.target.value})),placeholder:"不填时按类型和商品自动生成",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"闲鱼账号"}),e.jsxs("select",{value:g.cookie_id||"",onChange:(s=>O({...g,cookie_id:s.target.value,item_id:"",item_title:"",item_keyword:""})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),V.map(s=>e.jsx("option",{value:s.id,children:Re(s)},s.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:g.item_id||"",onChange:(s=>p(s.target.value)),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级规则(不限定商品)"}),ft.map(s=>e.jsx("option",{value:s.item_id,children:s.item_title||s.item_id},`${s.cookie_id}-${s.item_id}`))]})]})]}),ge&&me!=="review_missing_timeout"&&e.jsxs("div",{className:"mt-4 rounded-2xl bg-gray-50 border border-gray-100 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("span",{className:"px-3 py-1.5 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:ge.item_title||ge.item_id}),e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${oe?"bg-blue-50 text-blue-700":"bg-gray-100 text-gray-500"}`,children:oe?"多规格商品":"普通商品"}),e.jsx("span",{className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-emerald-50 text-emerald-700",children:"按订单购买数量自动发货"})]}),e.jsx("p",{className:"text-xs leading-5 text-gray-500",children:"多规格状态来自闲鱼商品本身,发布后不能在这里修改;系统会在买家付款后读取订单详情,按实际购买规格和数量匹配下面的发货规则。"})]})]}),me!=="review_missing_timeout"?e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($t,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:me==="buyer_reviewed"?"赠品库存":"发货库存"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:oe?"每条发货内容绑定一个订单规格;同一规格可添加多条内容并全部发送。":"可添加多条发货内容,买家付款后会按顺序全部发送。"})]}),e.jsxs("button",{type:"button",onClick:N,className:"px-3 py-2 rounded-xl bg-gray-900 text-white text-xs font-bold hover:bg-black flex items-center gap-1.5",children:[e.jsx(Ye,{className:"w-3.5 h-3.5"}),"添加发货内容"]})]}),e.jsx("div",{className:"space-y-3",children:xe.map((s,c)=>e.jsxs("div",{className:`grid grid-cols-1 gap-3 items-end rounded-2xl border border-gray-200 p-4 ${oe?"md:grid-cols-[1fr_1fr_1.4fr_110px_40px]":"md:grid-cols-[1.4fr_110px_40px]"}`,children:[oe&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"规格名称"}),e.jsx("input",{value:s.spec_name,onChange:(x=>h(c,{spec_name:x.target.value})),className:"w-full ios-input px-3 py-2.5 rounded-lg",placeholder:"例如:套餐"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"规格值"}),e.jsx("input",{value:s.spec_value,onChange:(x=>h(c,{spec_value:x.target.value})),className:"w-full ios-input px-3 py-2.5 rounded-lg",placeholder:"例如:30天"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"卡密库存"}),e.jsxs("select",{value:s.card_id||"",onChange:(x=>h(c,{card_id:Number(x.target.value)})),className:"w-full ios-input px-3 py-2.5 rounded-lg",children:[e.jsx("option",{value:"",children:"请选择卡密库存"}),H.filter(x=>x.enabled&&x.type!=="api").map(x=>e.jsx("option",{value:x.id,children:x.name},x.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"每件份数"}),e.jsx("input",{type:"number",min:"1",max:"100",value:s.delivery_count,onChange:(x=>h(c,{delivery_count:Math.max(1,Number(x.target.value)||1)})),className:"w-full ios-input px-3 py-2.5 rounded-lg"})]}),e.jsxs("div",{className:"md:col-span-full flex flex-wrap items-center gap-3 rounded-xl bg-gray-50 px-3 py-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold text-gray-600 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:s.delay_override===!0,onChange:(x=>h(c,{delay_override:x.target.checked})),className:"accent-brand"}),"覆盖卡密默认延时"]}),s.delay_override&&e.jsx("input",{type:"number",min:"0",max:"3600",value:s.delay_seconds||0,onChange:(x=>h(c,{delay_seconds:Math.max(0,Number(x.target.value)||0)})),className:"w-28 ios-input px-2 py-1.5 rounded-lg text-xs","aria-label":"动作延时秒数"}),e.jsx("span",{className:"text-xs text-gray-500",children:s.delay_override?`本动作延时 ${s.delay_seconds||0} 秒`:"使用卡密默认延时"})]}),e.jsx("button",{type:"button",disabled:xe.length===1,onClick:(()=>O({...g,variants:xe.filter((x,de)=>de!==c)})),className:"w-10 h-10 flex items-center justify-center rounded-lg text-red-500 hover:bg-red-50 disabled:opacity-25",title:"删除发货内容",children:e.jsx(Ce,{className:"w-4 h-4"})})]},s.id||c))})]}):e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(it,{className:"w-5 h-5 text-amber-600"}),e.jsx("h4",{className:"font-black text-gray-900",children:"求评价计划"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"发货后等待小时"}),e.jsx("input",{type:"number",min:"1",value:Number(be.after_shipped_hours||72),onChange:(s=>O({...g,config_json:ce(g.config_json,{after_shipped_hours:Math.max(1,Number(s.target.value)||72)})})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"再次求评间隔小时"}),e.jsx("input",{type:"number",min:"1",value:Number(be.repeat_interval_hours||24),onChange:(s=>O({...g,config_json:ce(g.config_json,{repeat_interval_hours:Math.max(1,Number(s.target.value)||24)})})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最多求评次数"}),e.jsx("input",{type:"number",min:"1",value:Number(be.max_attempts||1),onChange:(s=>O({...g,config_json:ce(g.config_json,{max_attempts:Math.max(1,Number(s.target.value)||1)})})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"md:col-span-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"求评价文案"}),e.jsx("textarea",{value:((Qe=(Xe=g.actions)==null?void 0:Xe.find(s=>s.action_type==="send_text"))==null?void 0:Qe.message_template)||"",onChange:(s=>{var c;return O({...g,actions:((c=g.actions)!=null&&c.length?g.actions:_e("review_missing_timeout")).map(x=>x.action_type==="send_text"?{...x,message_template:s.target.value}:x)})}),className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none"})]})]})]}),e.jsx("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[180px_1fr] gap-4 items-end",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"优先级"}),e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:"数字越小优先级越高;同一账号、商品和触发条件只执行优先级最高的一条规则。"}),e.jsx("input",{type:"number",value:g.priority||100,onChange:(s=>O({...g,priority:Number(s.target.value)||100})),min:"1",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("label",{className:"h-[48px] flex items-center gap-3 px-4 bg-gray-50 rounded-xl text-sm font-bold text-gray-800",children:[e.jsx("input",{type:"checkbox",checked:g.enabled!==!1,onChange:(s=>O({...g,enabled:s.target.checked})),className:"w-4 h-4 rounded"}),"启用规则"]})]})})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 bg-white flex gap-3",children:[e.jsx("button",{onClick:(()=>je(!1)),className:"flex-1 px-6 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200",children:"取消"}),e.jsxs("button",{onClick:f,className:"flex-1 ios-btn-primary px-6 py-3 rounded-2xl font-bold flex items-center justify-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"}),"保存自动化规则"]})]})]})}),document.body),Me&&S&&De.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:S.id?"编辑回复规则":"新增回复规则"}),e.jsx("button",{onClick:(()=>pe(!1)),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(ke,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:S.item_id||"",onChange:(s=>te({...S,item_id:s.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级回复"}),U.filter(s=>!r||s.cookie_id===r).map(s=>e.jsx("option",{value:s.item_id,children:s.item_title||s.item_id},`${s.cookie_id}-${s.item_id}`))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复类型"}),e.jsxs("select",{value:S.type||"text",onChange:(s=>{const c=s.target.value;te({...S,type:c,reply_content:c==="text"?S.reply_content:"",image_url:c==="image"?S.image_url:""})}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"文字"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关键词"}),e.jsx("input",{type:"text",value:S.keyword||"",onChange:(s=>te({...S,keyword:s.target.value})),placeholder:"买家发送的关键词",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),S.type==="image"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{value:S.image_url||"",onChange:(s=>te({...S,image_url:s.target.value})),placeholder:"https://...",className:"w-full ios-input px-4 py-3 rounded-xl"})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复内容"}),e.jsx("textarea",{value:S.reply_content||"",onChange:(s=>te({...S,reply_content:s.target.value})),placeholder:"自动回复的内容",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:(()=>pe(!1)),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:ut,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Mt,{className:"w-4 h-4"}),"保存规则"]})]})]})]})}),document.body),Pe&&De.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"账号默认回复"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"关键词和 AI 都未处理时,才会使用默认回复。"})]}),e.jsx("button",{onClick:(()=>ve(!1)),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",title:"关闭",children:e.jsx(ke,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"闲鱼账号"}),e.jsxs("select",{value:L.cookie_id,onChange:(s=>ie({...L,cookie_id:s.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),V.map(s=>e.jsx("option",{value:s.id,children:Re(s)},s.id))]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"启用默认回复"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"启用后,未命中关键词时自动发送"})]}),e.jsx("button",{type:"button",onClick:(()=>ie({...L,enabled:!L.enabled})),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${L.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${L.enabled?"translate-x-7":"translate-x-1"}`})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复内容"}),e.jsx("textarea",{value:L.reply_content,onChange:(s=>ie({...L,reply_content:s.target.value})),placeholder:"输入默认回复内容",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复图片 URL(可选)"}),e.jsx("input",{type:"text",value:L.reply_image_url,onChange:(s=>ie({...L,reply_image_url:s.target.value})),placeholder:"https://example.com/image.jpg",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("label",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl text-sm font-bold text-gray-800",children:[e.jsxs("span",{children:["只回复一次",e.jsx("span",{className:"block text-xs text-gray-500 font-medium mt-1",children:"同一会话只发送一次默认回复"})]}),e.jsx("input",{type:"checkbox",checked:L.reply_once,onChange:(s=>ie({...L,reply_once:s.target.checked})),className:"w-4 h-4 rounded"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:(()=>ve(!1)),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:gt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"}),"保存默认回复"]})]})]})]})}),document.body)]})};export{os as default};
+import{j as e,r as o,b as De}from"./react-vendor-C_od1ZSF.js";import{k as Je,ae as it,af as vt,m as Nt,R as Te,N as Ye,Z as He,x as wt,w as et,I as kt,a1 as Ct,X as ke,V as ze,F as Ce,h as St,g as Rt,a6 as At,ag as $t,r as tt,ah as Mt}from"./icons-vendor-CvzvbbIV.js";import{g as Z,p as Ge,a as fe,d as Ke}from"./index-CNzF_I4S.js";import{o as Ae,c as Ue}from"./contract-COFcZjyb.js";const Ee=(t,a)=>t.allowed_resolutions.includes(a),Pt=(t,a)=>({runs:t.runs.filter(i=>!a||i.cookie_id===a),pending_tasks:t.pending_tasks.filter(i=>!a||i.cookie_id===a)}),Lt=t=>({external_result_unknown:"外部动作结果未知",invalid_snapshot:"历史数据无法恢复",rule_unavailable:"规则不可用",partial_failure:"部分动作失败",execution_failed:"动作执行失败"})[t]||"自动化异常",It=({runs:t,pendingTasks:a,onResolveRun:i,onResolveDeferredTask:u})=>e.jsxs("section",{className:"rounded-2xl border border-red-200 bg-red-50 p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Je,{className:"w-5 h-5 text-red-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-black text-red-900",children:"需要人工处理的自动化任务"}),e.jsx("p",{className:"text-sm text-red-700 mt-1",children:"请先在闲鱼聊天、订单或商品列表中核对真实结果,再选择继续或重试。"})]})]}),e.jsxs("div",{className:"space-y-3",children:[t.map(r=>e.jsxs("div",{className:"rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-bold text-gray-900",children:["账号 ",r.cookie_id," · 订单 ",r.order_id||"-"," · 已记录发送 ",r.sent_count," 条"]}),e.jsx("div",{className:"text-xs font-bold text-red-800 mt-1",children:Lt(r.issue_kind)}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:r.error_message})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 shrink-0",children:[Ee(r,"continue")&&e.jsx("button",{onClick:(()=>i(r.id,"continue")),className:"px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold",children:"已执行,继续下一步"}),Ee(r,"retry")&&e.jsx("button",{onClick:(()=>i(r.id,"retry")),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"未执行,安全重试"}),Ee(r,"cancel")&&e.jsx("button",{onClick:(()=>i(r.id,"cancel")),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"终止"})]})]},`run-${r.id}`)),a.map(r=>e.jsxs("div",{className:"rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-bold text-gray-900",children:["账号 ",r.cookie_id," · 延迟任务重试已达 ",r.attempt_count," 次"]}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:r.error_message})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:(()=>u(r.id,"retry")),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"重新入队"}),e.jsx("button",{onClick:(()=>u(r.id,"dismiss")),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"忽略"})]})]},`task-${r.id}`))]})]}),Ft=async t=>Z("/api/v1/accounts/details",void 0,t),ot=async t=>Z("/api/v1/cards",void 0,t),dt=async(t,a)=>Z("/api/v1/items",void 0,a),ct=t=>t.map(a=>{var i,u;return{id:String(a.id),name:a.name||"",trigger_type:a.trigger_type||"order_paid",item_keyword:a.item_title||a.item_id||"",cookie_id:a.cookie_id||"",item_id:a.item_id||"",item_title:a.item_title||"",card_group_id:Number(((i=(a.actions||[]).find(r=>r.action_type==="send_card"))==null?void 0:i.card_id)||0),card_group_name:((u=(a.actions||[]).find(r=>r.action_type==="send_card"))==null?void 0:u.card_name)||"",priority:a.priority||100,enabled:a.enabled||!1,config_json:a.config_json||"{}",actions:(a.actions||[]).map(r=>({id:r.id?String(r.id):void 0,action_type:r.action_type,card_id:Number(r.card_id||0),card_name:r.card_name||"",delivery_count:Number(r.delivery_count||1),message_template:r.message_template||"",delay_seconds:Number(r.delay_seconds||0),config_json:r.config_json||"{}",enabled:r.enabled!==!1,sort_order:Number(r.sort_order||0)})),variants:(a.actions||[]).filter(r=>r.action_type==="send_card").map(r=>{let y={};try{y=JSON.parse(r.config_json||"{}")}catch{}return{id:r.id?String(r.id):void 0,spec_name:y.spec_name||"",spec_value:y.spec_value||"",card_id:Number(r.card_id||0),card_name:r.card_name||"",delivery_count:Number(r.delivery_count||1),enabled:r.enabled!==!1,delay_override:y.delay_override===!0,delay_seconds:Number(r.delay_seconds||0),config_json:r.config_json||"{}"}})}}),Dt=async()=>{const t=await Z("/api/v1/automation-rules"),a=Ue(t,["data","rules","items"]);return ct(a)},Tt=async({cookieId:t,triggerType:a,enabled:i,search:u,page:r=1,pageSize:y=10}={})=>{const A=await Z("/api/v1/automation-rules",{page:r,page_size:y,cookie_id:t||void 0,trigger_type:a||void 0,enabled:i,search:(u==null?void 0:u.trim())||void 0}),C=Ae(A,["data","result"])||{},m=ct(Ue(A,["data","rules","items"]));return{success:!0,data:m,total:Number(C.total??m.length),page:Number(C.page??r),page_size:Number(C.page_size??y),total_pages:Number(C.total_pages??(m.length?1:0)),trigger_counts:Object.fromEntries(Object.entries(C.trigger_counts||{}).map(([I,T])=>[I,Number(T)]))}},zt=(t,a)=>{if(t!=="order_paid")return a.map((r,y)=>({...r,sort_order:r.sort_order||y+1}));const i=a.filter(r=>r.action_type==="send_card").map((r,y)=>({...r,sort_order:y+1})),u=a.filter(r=>r.action_type!=="send_card"&&r.action_type!=="confirm_shipment");return[...i,...u.map((r,y)=>({...r,sort_order:i.length+y+1})),{action_type:"confirm_shipment",enabled:!0,sort_order:i.length+u.length+1}]},st=async t=>{const a=t.trigger_type||"order_paid",u=[{order_paid:"付款后自动发货",buyer_reviewed:"评价后发送赠品",review_missing_timeout:"超时未评价求评价"}[a]||"自动化规则",t.item_title||t.item_id||t.cookie_id||""].filter(Boolean).join(" - "),r=(t.actions||[]).filter(m=>m.action_type!=="send_card"&&m.action_type!=="confirm_shipment"),y=t.variants&&t.variants.length>0?[...t.variants.map((m,I)=>({action_type:"send_card",card_id:m.card_id,delivery_count:m.delivery_count||1,enabled:m.enabled!==!1,sort_order:I+1,delay_seconds:m.delay_seconds||0,config_json:JSON.stringify({spec_name:m.spec_name||"",spec_value:m.spec_value||"",delay_override:m.delay_override===!0})})),...r]:t.actions&&t.actions.length>0?t.actions:[{action_type:"send_card",card_id:t.card_group_id||0,delivery_count:1,enabled:!0,sort_order:1}],A=zt(a,y),C={cookie_id:t.cookie_id||"",item_id:t.item_id||"",name:(t.name||"").trim()||u||"自动化规则",trigger_type:a,enabled:t.enabled??!0,priority:t.priority||100,config_json:t.config_json||"{}",actions:A.map((m,I)=>({action_type:m.action_type,card_id:m.card_id||0,delivery_count:m.delivery_count||1,message_template:m.message_template||"",delay_seconds:m.delay_seconds||0,config_json:m.config_json||"{}",enabled:m.enabled!==!1,sort_order:m.sort_order||I+1}))};return t.id?Ge(`/api/v1/automation-rules/${t.id}`,C):fe("/api/v1/automation-rules",C)},Et=async t=>Ke(`/api/v1/automation-rules/${t}`),Ot=async()=>{const t=await Z("/api/v1/automation-issues"),a=Ae(t,["data","result"])||{};return{runs:Array.isArray(a==null?void 0:a.runs)?a.runs:[],pending_tasks:Array.isArray(a==null?void 0:a.pending_tasks)?a.pending_tasks:[]}},qt=async(t,a)=>fe(`/api/v1/automation-runs/${t}/resolve`,{resolution:a}),Vt=async(t,a)=>fe(`/api/v1/automation-pending-tasks/${t}/resolve`,{resolution:a}),Bt=t=>({id:String((t==null?void 0:t.id)||""),keyword:(t==null?void 0:t.keyword)||"",reply:(t==null?void 0:t.reply)||"",item_id:(t==null?void 0:t.item_id)||"",type:(t==null?void 0:t.type)==="image"?"image":"text",image_url:(t==null?void 0:t.image_url)||""}),Jt=async t=>{const a=await Z(`/api/v1/reply-rules/${t}/typed`);return Ue(a,["data","items","rules"]).map(Bt)},Gt=async t=>t?(await Jt(t)).map(i=>({id:i.id,keyword:i.keyword||"",reply_content:i.reply||"",match_type:"fuzzy",enabled:!0,item_id:i.item_id||"",type:i.type==="image"?"image":"text",image_url:i.image_url||""})):[],Kt=async(t,a)=>{const i=t.type||"text",u={keyword:t.keyword||"",reply:i==="text"&&t.reply_content||"",item_id:t.item_id||"",type:i,image_url:i==="image"&&t.image_url||""};return t.id?Ge(`/api/v1/reply-rules/${a}/typed/${t.id}`,u):fe(`/api/v1/reply-rules/${a}/items`,u)},Ut=async(t,a)=>Ke(`/api/v1/reply-rules/${a}/typed/${t}`),at=async()=>{const t=await Z("/api/v1/default-replies");return Ae(t,["data","replies","items"])||{}},Wt=async t=>{const a=await Z(`/api/v1/default-replies/${t}`),i=Ae(a,["data","result"])||{};return{cookie_id:t,enabled:i.enabled||!1,reply_content:i.reply_content||"",reply_once:i.reply_once||!1,reply_image_url:i.reply_image_url||""}},Zt=async(t,a)=>Ge(`/api/v1/default-replies/${t}`,{enabled:a.enabled??!1,reply_content:a.reply_content||"",reply_once:a.reply_once??!1,reply_image_url:a.reply_image_url||""}),Xt=async t=>Ke(`/api/v1/default-replies/${t}`),Qt=async t=>fe(`/api/v1/default-replies/${t}/clear-records`,{}),Oe=()=>({submitting:!1,result:"idle"}),qe=t=>t.submitting?t:{submitting:!0,result:"idle"},Ve=(t,a)=>({submitting:!1,result:a?"success":"failure"}),rt=t=>t+1,Be=(t,a,i,u)=>t===a&&i===u,Yt=t=>{const[a,i]=o.useState([]),[u,r]=o.useState({runs:[],pending_tasks:[]}),[y,A]=o.useState([]),[C,m]=o.useState({}),[I,T]=o.useState([]),[J,w]=o.useState([]),[G,F]=o.useState([]),[v,X]=o.useState(!1),q=o.useRef(0),re=o.useRef(0),[Q,K]=o.useState(0),[le,Y]=o.useState(0),[V,H]=o.useState({}),U=o.useCallback(async()=>{const P=Promise.all([Ft(),ot(),dt(),at()]),[_,j,D,ee]=await P;T(_),w(j),F(D),m(ee),t.setSelectedAccountId(ne=>{var E;return ne||((E=_[0])==null?void 0:E.id)||""})},[t.setSelectedAccountId]),n=o.useCallback(async()=>{var ee;const P=rt(q.current);q.current=P;const _=Ot().catch(ne=>(console.warn("加载自动化异常列表失败,不阻断规则展示",ne),null)),j=await Tt({cookieId:t.selectedAccountId||void 0,triggerType:t.automationTriggerFilter,enabled:t.automationStatusFilter==="all"?void 0:t.automationStatusFilter==="enabled",search:t.debouncedAutomationSearch,page:t.automationPage,pageSize:t.automationPageSize});if(!Be(P,q.current,t.selectedAccountId,t.selectedAccountId))return;i(j.data),K(j.total),Y(j.total_pages),H(j.trigger_counts||{}),j.page!==t.automationPage&&((ee=t.onAutomationPageChange)==null||ee.call(t,j.page));const D=await _;Be(P,q.current,t.selectedAccountId,t.selectedAccountId)&&D&&r(D)},[t.automationPage,t.automationPageSize,t.automationStatusFilter,t.automationTriggerFilter,t.debouncedAutomationSearch,t.onAutomationPageChange,t.selectedAccountId]),$=o.useCallback(async()=>{const P=rt(re.current);re.current=P;const _=t.selectedAccountId;if(A([]),!_)return;const j=await Gt(_);Be(P,re.current,_,t.selectedAccountId)&&A(j)},[t.selectedAccountId]),R=o.useCallback(async()=>{m(await at())},[]),z=o.useCallback(async()=>{X(!0);try{t.activeTab==="automation"?await n():t.activeTab==="reply"?await $():await R()}finally{X(!1)}},[n,R,$,t.activeTab]);return{automationRules:a,automationIssues:u,replyRules:y,defaultReplies:C,accounts:I,cards:J,items:G,automationTotal:Q,automationTotalPages:le,automationTriggerCounts:V,loading:v,setLoading:X,setAutomationRules:i,setCards:w,setItems:F,loadReferenceData:U,loadAutomationRules:n,loadReplyRules:$,loadDefaultReplies:R,refresh:z}},ae={order_paid:{label:"付款后自动发货",shortLabel:"自动发货",description:"闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。",flow:["付款系统卡片","匹配商品/规格","发送卡密","确认发货"],accent:"blue",icon:Nt},buyer_reviewed:{label:"评价后发送赠品",shortLabel:"评价赠品",description:"闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。",flow:["评价系统卡片","匹配商品/规格","发送赠品"],accent:"emerald",icon:vt},review_missing_timeout:{label:"超时未评价求评价",shortLabel:"求评价",description:"计划任务扫描已发货未评价订单,到期后发送求评价文案。",flow:["计划任务扫描","已发货未评价","达到等待时间","发送提醒"],accent:"amber",icon:it}},Se=["order_paid","buyer_reviewed","review_missing_timeout"],Ht="亲,商品使用满意的话,麻烦给个评价,谢谢~",he=()=>({spec_name:"",spec_value:"",card_id:0,delivery_count:1,enabled:!0,delay_override:!1,delay_seconds:0}),mt=t=>{if(!t)return{};try{const a=JSON.parse(t);return a&&typeof a=="object"&&!Array.isArray(a)?a:{}}catch{return{}}},ce=(t,a={})=>{const i=mt(t);return JSON.stringify({after_shipped_hours:Number(i.after_shipped_hours||72),repeat_interval_hours:Number(i.repeat_interval_hours||24),max_attempts:Number(i.max_attempts||1),...a})},ye=(t,a)=>{var u;const i=((u=ae[t])==null?void 0:u.label)||"自动化规则";return a?`${i} - ${a}`:i},lt=t=>{const a=(t||"").trim();return a?Object.values(ae).some(i=>a===i.label||a.startsWith(`${i.label} -`)):!0},_e=(t,a=0)=>{if(t==="review_missing_timeout")return[{action_type:"send_text",message_template:Ht,enabled:!0,sort_order:1}];const i={action_type:"send_card",card_id:a,delivery_count:1,enabled:!0,sort_order:1};return t==="order_paid"?[i,{action_type:"confirm_shipment",enabled:!0,sort_order:2}]:[i]},es=t=>{var i,u;if(t.trigger_type==="review_missing_timeout")return((u=(i=t.actions)==null?void 0:i.find(r=>r.action_type==="send_text"))==null?void 0:u.message_template)||"发送求评价文案";const a=(t.actions||[]).filter(r=>r.action_type==="send_card");return a.length?a.map(r=>r.card_name||`卡密 ${r.card_id}`).join(" / "):"未配置卡密库存"},nt=(t,a=!1)=>{const i={blue:a?"border-blue-500 bg-blue-50 text-blue-700":"border-blue-100 bg-blue-50/60 text-blue-700 hover:border-blue-300",emerald:a?"border-emerald-500 bg-emerald-50 text-emerald-700":"border-emerald-100 bg-emerald-50/60 text-emerald-700 hover:border-emerald-300",amber:a?"border-amber-500 bg-amber-50 text-amber-700":"border-amber-100 bg-amber-50/60 text-amber-700 hover:border-amber-300"};return i[t]||i.blue},ts=t=>t?"bg-emerald-100 text-emerald-700":"bg-gray-200 text-gray-500",Re=t=>(t==null?void 0:t.nickname)||(t==null?void 0:t.remark)||(t==null?void 0:t.id)||"未知账号",ss=t=>t===!0||t===1||t==="1",as=({selectedAccountId:t,setSelectedAccountId:a,setActiveTab:i,items:u,setAutomationRules:r,setCards:y,setItems:A,setLoading:C,loadAutomationRules:m,loadReferenceData:I,loadReplyRules:T,loadDefaultReplies:J,initialDeliveryTarget:w,onDeliveryTargetHandled:G})=>{var xe;const[F,v]=o.useState(!1),[X,q]=o.useState(!1),[re,Q]=o.useState(!1),[K,le]=o.useState(Oe),[Y,V]=o.useState(Oe),[H,U]=o.useState(Oe),[n,$]=o.useState(null),[R,z]=o.useState(null),[M,P]=o.useState({cookie_id:"",enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""}),_=o.useMemo(()=>n!=null&&n.cookie_id&&n.item_id?u.find(l=>l.cookie_id===n.cookie_id&&l.item_id===n.item_id):void 0,[n==null?void 0:n.cookie_id,n==null?void 0:n.item_id,u]),j=ss(_==null?void 0:_.is_multi_spec),D=(n==null?void 0:n.trigger_type)||"order_paid",ee=ae[D],ne=mt(n==null?void 0:n.config_json),E=(xe=n==null?void 0:n.variants)!=null&&xe.length?n.variants:[he()],W=o.useCallback((l="order_paid",d=t,b="")=>{const p=u.find(N=>N.cookie_id===d&&N.item_id===b),h=(p==null?void 0:p.item_title)||b;return{name:ye(l,h),trigger_type:l,cookie_id:d,item_id:b,item_title:(p==null?void 0:p.item_title)||"",item_keyword:h,card_group_id:0,priority:100,enabled:!0,config_json:l==="review_missing_timeout"?ce():"{}",actions:_e(l),variants:l==="review_missing_timeout"?[]:[he()]}},[u,t]),ue=o.useCallback(l=>{var b,p;const d=l.trigger_type||"order_paid";$({...l,trigger_type:d,config_json:d==="review_missing_timeout"?ce(l.config_json):l.config_json||"{}",actions:(b=l.actions)!=null&&b.length?l.actions.map(h=>({...h})):_e(d,l.card_group_id),variants:(p=l.variants)!=null&&p.length?l.variants.map(h=>({...h})):d==="review_missing_timeout"?[]:[he()]}),v(!0)},[]);o.useEffect(()=>{if(!w)return;let l=!1;return(async()=>{i("automation"),a(w.cookieId),C(!0);try{const[b,p,h]=await Promise.all([Dt(),dt(),ot().catch(f=>(console.warn("加载卡密库存失败,不阻断打开自动化规则",f),[]))]);if(l)return;r(b),A(p),y(h);const N=b.find(f=>f.cookie_id===w.cookieId&&f.item_id===w.itemId&&f.trigger_type==="order_paid");if(N)ue(N);else{const f=p.find(B=>B.cookie_id===w.cookieId&&B.item_id===w.itemId);$({...W("order_paid",w.cookieId,w.itemId),item_title:(f==null?void 0:f.item_title)||"",item_keyword:(f==null?void 0:f.item_title)||w.itemId,name:ye("order_paid",(f==null?void 0:f.item_title)||w.itemId)}),v(!0)}}catch(b){console.error("打开商品自动化规则失败",b),alert("无法加载该商品的自动化规则")}finally{l||(C(!1),G==null||G())}})(),(()=>{l=!0})},[W,w,G,ue,i,r,y,A,C,a]);const $e=o.useCallback((l="order_paid")=>{if(!t){alert("请先选择账号");return}$(W(l)),v(!0)},[W,t]),je=o.useCallback(l=>{var p,h,N,f,B;if(!n)return;const d=((h=(p=n.variants)==null?void 0:p.find(se=>se.card_id))==null?void 0:h.card_id)||((f=(N=n.actions)==null?void 0:N.find(se=>se.action_type==="send_card"))==null?void 0:f.card_id)||n.card_group_id||0,b=(_==null?void 0:_.item_title)||n.item_title||n.item_id||"";$({...n,trigger_type:l,name:lt(n.name)?ye(l,b):n.name,card_group_id:d,config_json:l==="review_missing_timeout"?ce(n.config_json):"{}",actions:_e(l,d),variants:l==="review_missing_timeout"?[]:(B=n.variants)!=null&&B.length?n.variants:[{...he(),card_id:d}]})},[n,_]),Me=o.useCallback(l=>{if(!n)return;const d=u.find(p=>p.cookie_id===(n.cookie_id||t)&&p.item_id===l),b=(d==null?void 0:d.item_title)||l;$({...n,item_id:l,item_title:(d==null?void 0:d.item_title)||"",item_keyword:b,name:lt(n.name)?ye(D,b):n.name})},[D,n,u,t]),pe=o.useCallback((l,d)=>{var p;if(!n)return;const b=E.map((h,N)=>N===l?{...h,...d}:h);$({...n,variants:b,card_group_id:((p=b[0])==null?void 0:p.card_id)||0})},[E,n]),Pe=o.useCallback(()=>{if(!n)return;const l=E[E.length-1];$({...n,variants:[...E,{...he(),spec_name:j&&(l==null?void 0:l.spec_name)||"",spec_value:j&&(l==null?void 0:l.spec_value)||""}]})},[E,n,j]),ve=o.useCallback(async()=>{var h,N,f,B,se;if(!n||K.submitting)return;const l=n.trigger_type||"order_paid";if(!n.cookie_id)return alert("请选择账号");const d=(h=n.variants)!=null&&h.length?n.variants:[];if(l!=="review_missing_timeout"){if(!d.length||d.some(k=>!k.card_id))return alert(l==="buyer_reviewed"?"请选择评价赠品卡密库存":"请选择发货卡密库存");if(j&&d.some(k=>!k.spec_name.trim()||!k.spec_value.trim()))return alert("多规格商品必须填写每一行的规格名称和规格值")}if(l==="review_missing_timeout"&&!(((f=(N=n.actions)==null?void 0:N.find(Le=>Le.action_type==="send_text"))==null?void 0:f.message_template)||"").trim())return alert("请填写求评价文案");const b=l==="review_missing_timeout"?[]:d.map(k=>({...k,spec_name:j?k.spec_name.trim():"",spec_value:j?k.spec_value.trim():"",delivery_count:Math.max(1,Number(k.delivery_count)||1),enabled:k.enabled!==!1}));le(qe(K));let p=!1;try{await st({...n,trigger_type:l,name:(n.name||"").trim()||ye(l,(_==null?void 0:_.item_title)||n.item_id||""),config_json:l==="review_missing_timeout"?ce(n.config_json):n.config_json||"{}",actions:(B=n.actions)!=null&&B.length?n.actions:_e(l,((se=b[0])==null?void 0:se.card_id)||n.card_group_id||0),variants:b}),v(!1),await Promise.all([m(),I()]),alert("保存成功"),p=!0}catch(k){console.error("保存自动化规则失败:",k),alert("保存失败:"+k.message)}finally{le(k=>Ve(k,p))}},[K,n,j,m,I,_]),g=o.useCallback(async l=>{if(confirm("确定删除该自动化规则吗?"))try{await Et(l),await m(),alert("删除成功")}catch(d){alert("删除失败:"+d.message)}},[m]),O=o.useCallback(async l=>{try{await st({...l,enabled:!l.enabled}),await m()}catch(d){alert("操作失败:"+d.message)}},[m]),S=o.useCallback(async(l,d)=>{if(confirm(d==="continue"?"确认外部动作已经执行成功,并跳到下一步吗?":d==="retry"?"确认外部动作没有执行,可以安全重试吗?错误判断可能造成重复发送。":"确认终止该自动化运行吗?"))try{await qt(l,d),await m()}catch(p){alert("处理失败:"+p.message)}},[m]),te=o.useCallback(async(l,d)=>{if(confirm(d==="retry"?"确认重新执行该任务吗?":"确认忽略并删除该异常任务吗?"))try{await Vt(l,d),await m()}catch(b){alert("处理失败:"+b.message)}},[m]),L=o.useCallback(()=>{if(!t)return alert("请先选择账号");z({keyword:"",reply_content:"",image_url:"",item_id:"",type:"text",match_type:"fuzzy",enabled:!0}),q(!0)},[t]),ie=o.useCallback(async()=>{var b,p,h;if(!R||!t||Y.submitting)return;const l=R.type==="image"?!!((b=R.image_url)!=null&&b.trim()):!!((p=R.reply_content)!=null&&p.trim());if(!((h=R.keyword)!=null&&h.trim())||!l)return alert("请填写关键词和回复内容");V(qe(Y));let d=!1;try{await Kt({...R,match_type:"fuzzy",enabled:!0},t),q(!1),await T(),alert("保存成功"),d=!0}catch(N){alert("保存失败:"+N.message)}finally{V(N=>Ve(N,d))}},[R,T,Y,t]),ge=o.useCallback(async l=>{if(!(!t||!confirm("确定删除该回复规则吗?")))try{await Ut(l,t),await T(),alert("删除成功")}catch(d){alert("删除失败:"+d.message)}},[T,t]),oe=o.useCallback(async(l=t)=>{if(!l)return alert("请先选择账号");try{const d=await Wt(l);P({cookie_id:l,enabled:d.enabled,reply_content:d.reply_content,reply_once:d.reply_once,reply_image_url:d.reply_image_url||""})}catch{P({cookie_id:l,enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""})}Q(!0)},[t]),me=o.useCallback(async()=>{if(H.submitting)return;if(!M.cookie_id)return alert("请先选择账号");if(M.enabled&&!M.reply_content.trim()&&!M.reply_image_url.trim())return alert("启用默认回复时,请填写回复内容或图片 URL");U(qe(H));let l=!1;try{await Zt(M.cookie_id,{enabled:M.enabled,reply_content:M.reply_content,reply_once:M.reply_once,reply_image_url:M.reply_image_url}),Q(!1),await J(),alert("保存成功"),l=!0}catch(d){alert("保存失败:"+d.message)}finally{U(d=>Ve(d,l))}},[M,H,J]),Ne=o.useCallback(async l=>{if(confirm("确定删除该账号默认回复吗?"))try{await Xt(l),await J(),alert("删除成功")}catch(d){alert("删除失败:"+d.message)}},[J]),be=o.useCallback(async l=>{if(confirm("确定清空该账号的默认回复记录吗?清空后可重新对所有会话使用“只回复一次”。"))try{await Qt(l),alert("清空成功")}catch(d){alert("清空失败:"+d.message)}},[]);return{showAutomationModal:F,setShowAutomationModal:v,showReplyModal:X,setShowReplyModal:q,showDefaultModal:re,setShowDefaultModal:Q,automationSubmitState:K,replySubmitState:Y,defaultReplySubmitState:H,editingAutomationRule:n,setEditingAutomationRule:$,editingReplyRule:R,setEditingReplyRule:z,defaultForm:M,setDefaultForm:P,selectedRuleItem:_,isMultiSpecRule:j,currentTrigger:D,currentMeta:ee,reviewConfig:ne,displayVariants:E,buildAutomationDraft:W,openAutomationRule:ue,openNewAutomationRule:$e,handleTriggerChange:je,handleAutomationItemChange:Me,updateVariant:pe,appendDeliveryContent:Pe,handleSaveAutomationRule:ve,handleDeleteAutomation:g,handleToggleAutomation:O,handleResolveRunIssue:S,handleResolveDeferredIssue:te,handleAddReplyRule:L,handleSaveReplyRule:ie,handleDeleteReply:ge,openDefaultReplyModal:oe,handleSaveDefaultReply:me,handleDeleteDefaultReply:Ne,handleClearDefaultReplyRecords:be}},os=({initialDeliveryTarget:t,onDeliveryTargetHandled:a})=>{var Xe,Qe;const[i,u]=o.useState("automation"),[r,y]=o.useState(""),[A,C]=o.useState(""),[m,I]=o.useState(""),[T,J]=o.useState(""),[w,G]=o.useState("all"),[F,v]=o.useState(1),[X,q]=o.useState(10),re=Yt({activeTab:i,selectedAccountId:r,automationTriggerFilter:T,automationStatusFilter:w,debouncedAutomationSearch:m,automationPage:F,automationPageSize:X,setSelectedAccountId:y,onAutomationPageChange:v}),{automationRules:Q,automationIssues:K,replyRules:le,defaultReplies:Y,accounts:V,cards:H,items:U,loading:n,setLoading:$,automationTotal:R,automationTotalPages:z,automationTriggerCounts:M,setAutomationRules:P,setCards:_,setItems:j,loadReferenceData:D,loadAutomationRules:ee,loadReplyRules:ne,loadDefaultReplies:E,refresh:W}=re,ue=as({selectedAccountId:r,setSelectedAccountId:y,setActiveTab:u,items:U,setAutomationRules:P,setCards:_,setItems:j,setLoading:$,loadAutomationRules:ee,loadReferenceData:D,loadReplyRules:ne,loadDefaultReplies:E,initialDeliveryTarget:t,onDeliveryTargetHandled:a}),{showAutomationModal:$e,setShowAutomationModal:je,showReplyModal:Me,setShowReplyModal:pe,showDefaultModal:Pe,setShowDefaultModal:ve,editingAutomationRule:g,setEditingAutomationRule:O,editingReplyRule:S,setEditingReplyRule:te,defaultForm:L,setDefaultForm:ie,selectedRuleItem:ge,isMultiSpecRule:oe,currentTrigger:me,currentMeta:Ne,reviewConfig:be,displayVariants:xe,openAutomationRule:l,openNewAutomationRule:d,handleTriggerChange:b,handleAutomationItemChange:p,updateVariant:h,appendDeliveryContent:N,handleSaveAutomationRule:f,handleDeleteAutomation:B,handleToggleAutomation:se,handleResolveRunIssue:k,handleResolveDeferredIssue:Le,handleAddReplyRule:xt,handleSaveReplyRule:ut,handleDeleteReply:pt,openDefaultReplyModal:We,handleSaveDefaultReply:gt,handleDeleteDefaultReply:bt,handleClearDefaultReplyRecords:ht}=ue;o.useEffect(()=>{const s=window.setTimeout(()=>{v(1),I(A.trim())},300);return(()=>window.clearTimeout(s))},[A]),o.useEffect(()=>{D().catch(s=>console.error("加载规则参考数据失败",s))},[D]),o.useEffect(()=>{W().catch(s=>console.error("刷新规则页面失败",s))},[W]);const Ie=o.useMemo(()=>Q.filter(s=>!r||s.cookie_id===r),[Q,r]),we=o.useMemo(()=>Pt(K,r),[K,r]),Ze=o.useMemo(()=>V.filter(s=>!r||s.id===r),[V,r]),yt=o.useMemo(()=>{if(z<=1)return[];const s=Math.max(1,Math.min(F-2,z-4)),c=Math.min(z,s+4);return Array.from({length:c-s+1},(x,de)=>s+de)},[F,z]),Fe=!!(A.trim()||T||w!=="all"),_t=()=>{C(""),I(""),J(""),G("all"),v(1)},ft=o.useMemo(()=>{const s=(g==null?void 0:g.cookie_id)||r;return U.filter(c=>c.cookie_id===s)},[g==null?void 0:g.cookie_id,U,r]),jt=i==="automation"?"新建自动化":i==="reply"?"新增关键词":"编辑默认回复";return e.jsxs("div",{className:"min-w-0 space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row justify-between xl:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"系统通知卡片只进入自动化判断;买家消息进入关键词、默认或 AI 回复。"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:flex-wrap gap-3",children:[e.jsxs("select",{value:r,onChange:(s=>{y(s.target.value),v(1)}),className:"ios-input w-full px-4 py-3 rounded-2xl text-sm sm:w-64",children:[e.jsx("option",{value:"",children:"全部账号"}),V.map(s=>e.jsx("option",{value:s.id,children:Re(s)},s.id))]}),e.jsxs("button",{onClick:W,className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 hover:bg-gray-200 text-gray-700 flex items-center justify-center gap-2 whitespace-nowrap transition-colors",children:[e.jsx(Te,{className:`w-4 h-4 ${n?"animate-spin":""}`}),"刷新"]}),e.jsxs("button",{onClick:i==="automation"?(()=>d("order_paid")):i==="reply"?xt:(()=>void We()),disabled:!r,className:"ios-btn-primary px-5 py-3 rounded-2xl text-sm font-extrabold flex items-center justify-center gap-2 whitespace-nowrap disabled:opacity-50",children:[e.jsx(Ye,{className:"w-4 h-4"}),jt]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[{id:"automation",label:"交易自动化",icon:He},{id:"reply",label:"关键词回复",icon:wt},{id:"default",label:"账号默认回复",icon:et}].map(s=>{const c=s.icon;return e.jsxs("button",{onClick:(()=>u(s.id)),className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${i===s.id?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:[e.jsx(c,{className:"w-4 h-4"}),s.label]},s.id)})}),i==="automation"&&(we.runs.length>0||we.pending_tasks.length>0)&&e.jsx(It,{runs:we.runs,pendingTasks:we.pending_tasks,onResolveRun:((s,c)=>void k(s,c)),onResolveDeferredTask:((s,c)=>void Le(s,c))}),i==="automation"&&e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-6 xl:grid-cols-[minmax(270px,0.72fr)_minmax(0,1.28fr)]",children:[e.jsxs("aside",{className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-gray-100 shadow-sm",children:[e.jsx("h3",{className:"font-black text-gray-900 mb-1",children:"新建规则"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"先选自动化类型,再配置对应动作。"}),e.jsx("div",{className:"space-y-3",children:Se.map(s=>{const c=ae[s],x=c.icon;return e.jsx("button",{type:"button",onClick:(()=>d(s)),className:`w-full text-left rounded-2xl border p-4 transition-colors ${nt(c.accent)}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-white/80 flex items-center justify-center shrink-0",children:e.jsx(x,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:c.label}),e.jsx("div",{className:"text-xs opacity-75 mt-1 leading-5",children:c.description})]})]})},s)})})]}),e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-gray-100 shadow-sm",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"font-black text-gray-900",children:"筛选结果构成"}),e.jsxs("span",{className:"text-xs font-bold text-gray-400",children:["共 ",R," 条"]})]}),e.jsx("div",{className:"space-y-3",children:Se.map(s=>{const c=ae[s],x=c.icon;return e.jsxs("div",{className:"flex items-center justify-between rounded-2xl bg-gray-50 p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(x,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:c.shortLabel})]}),e.jsx("span",{className:"text-sm font-black text-gray-900",children:M[s]||0})]},s)})})]})]}),e.jsxs("section",{className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-gray-100 bg-surface-muted p-4 shadow-sm",children:[e.jsxs("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(kt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"搜索自动化规则",placeholder:"搜索规则名、商品名或商品 ID...",value:A,onChange:(s=>{C(s.target.value),v(1)}),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]}),e.jsxs("div",{className:"relative xl:w-52",children:[e.jsx(Ct,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按自动化类型筛选",value:T,onChange:(s=>{J(s.target.value),v(1)}),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部自动化类型"}),Se.map(s=>e.jsx("option",{value:s,children:ae[s].shortLabel},s))]})]}),e.jsxs("select",{"aria-label":"按启用状态筛选",value:w,onChange:(s=>{G(s.target.value),v(1)}),className:"ios-input rounded-xl border-none bg-white px-4 py-2.5 text-sm shadow-sm xl:w-36",children:[e.jsx("option",{value:"all",children:"全部状态"}),e.jsx("option",{value:"enabled",children:"已启用"}),e.jsx("option",{value:"disabled",children:"已禁用"})]}),Fe&&e.jsx("button",{type:"button",onClick:_t,className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-white text-gray-500 shadow-sm transition-colors hover:bg-gray-100 hover:text-gray-900",title:"清除筛选","aria-label":"清除筛选",children:e.jsx(ke,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-xs font-bold text-gray-400",children:[e.jsxs("span",{children:["找到 ",R," 条规则"]}),n&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}),"正在更新"]})]})]}),n&&Ie.length===0?e.jsxs("div",{className:"flex min-h-56 items-center justify-center rounded-xl border border-gray-100 bg-white text-sm font-bold text-gray-400",children:[e.jsx(Te,{className:"mr-2 h-4 w-4 animate-spin"}),"正在加载规则"]}):Ie.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-dashed border-gray-200 p-16 text-center",children:[e.jsx(He,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-black text-gray-900",children:Fe?"没有匹配的自动化规则":"还没有自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2",children:Fe?"调整或清除筛选条件后再试。":"从左侧选择一个模板开始配置。"})]}):Ie.map(s=>{const c=ae[s.trigger_type],x=c.icon;return e.jsx("article",{className:"bg-white rounded-xl border border-gray-100 p-5 shadow-sm hover:shadow-lg transition-all",children:e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-4 min-w-0",children:[e.jsx("div",{className:`w-12 h-12 rounded-2xl flex items-center justify-center shrink-0 ${nt(c.accent,!0)}`,children:e.jsx(x,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("h3",{className:"text-lg font-black text-gray-900 truncate",children:s.name}),e.jsx("span",{className:`px-2.5 py-1 rounded-full text-xs font-bold ${ts(s.enabled)}`,children:s.enabled?"已启用":"已禁用"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-bold",children:[e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:c.label}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:s.item_title||s.item_id||"账号级规则"}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-blue-50 text-blue-700",children:es(s)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:(()=>l(s)),className:"px-4 py-2 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-700 text-sm font-bold flex items-center gap-2",children:[e.jsx(ze,{className:"w-4 h-4"}),"编辑"]}),e.jsx("button",{onClick:(()=>se(s)),className:`px-4 py-2 rounded-xl text-sm font-bold ${s.enabled?"bg-amber-50 text-amber-700 hover:bg-amber-100":"bg-emerald-50 text-emerald-700 hover:bg-emerald-100"}`,children:s.enabled?"禁用":"启用"}),e.jsx("button",{onClick:(()=>B(s.id)),className:"p-2.5 rounded-xl text-red-500 hover:bg-red-50",title:"删除",children:e.jsx(Ce,{className:"w-4 h-4"})})]})]})},s.id)}),R>0&&e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-gray-100 bg-white px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm font-medium text-gray-500",children:[e.jsxs("span",{children:["第 ",F," / ",Math.max(z,1)," 页"]}),e.jsx("span",{className:"h-4 w-px bg-gray-200"}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"sr-only",children:"每页显示数量"}),e.jsx("select",{value:X,onChange:(s=>{q(Number(s.target.value)),v(1)}),className:"ios-input rounded-lg border-none bg-gray-50 px-2.5 py-2 text-sm",children:[10,20,50].map(s=>e.jsxs("option",{value:s,children:[s," 条/页"]},s))})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",disabled:F<=1||n,onClick:(()=>v(s=>Math.max(1,s-1))),className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-50 text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"上一页",title:"上一页",children:e.jsx(St,{className:"h-4 w-4"})}),yt.map(s=>e.jsx("button",{type:"button",disabled:n,onClick:(()=>v(s)),className:`h-9 min-w-9 rounded-lg px-2 text-sm font-bold transition-colors ${s===F?"bg-brand text-white":"bg-gray-50 text-gray-600 hover:bg-gray-100"} disabled:cursor-not-allowed disabled:opacity-60`,"aria-label":`第 ${s} 页`,"aria-current":s===F?"page":void 0,children:s},s)),e.jsx("button",{type:"button",disabled:F>=z||n,onClick:(()=>v(s=>Math.min(z,s+1))),className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-50 text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"下一页",title:"下一页",children:e.jsx(Rt,{className:"h-4 w-4"})})]})]})]})]}),i==="reply"&&e.jsxs("section",{className:"bg-white rounded-xl border border-gray-100 p-6 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-blue-700 bg-blue-50 px-4 py-2 rounded-xl mb-5 w-fit",children:[e.jsx(Je,{className:"w-4 h-4"}),"这里只处理买家用户消息;系统通知不会进入关键词或 AI 回复。"]}),e.jsxs("div",{className:"space-y-3",children:[le.map(s=>e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border border-gray-100 bg-surface-subtle hover:bg-white hover:shadow-lg transition-all gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"px-3 py-1 bg-black text-white rounded-lg text-xs font-bold",children:"包含匹配"}),e.jsxs("h3",{className:"font-bold text-gray-900",children:["“",s.keyword,"”"]})]}),e.jsx("div",{className:"bg-white p-3 rounded-xl border border-gray-100 text-sm text-gray-600 leading-relaxed",children:s.type==="image"&&s.image_url?s.image_url:s.reply_content})]}),e.jsxs("div",{className:"flex items-center gap-3 border-t md:border-t-0 md:border-l border-gray-200 pt-4 md:pt-0 md:pl-6",children:[e.jsx("button",{onClick:(()=>{te({...s}),pe(!0)}),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(ze,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>pt(s.id)),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Ce,{className:"w-5 h-5"})})]})]},s.id)),le.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无关键词回复规则"})]})]}),i==="default"&&e.jsxs("section",{className:"bg-white rounded-xl border border-gray-100 p-6 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-blue-700 bg-blue-50 px-4 py-2 rounded-xl mb-5 w-fit",children:[e.jsx(Je,{className:"w-4 h-4"}),"默认回复只处理买家用户消息;关键词未命中且 AI 未接管时才会使用。"]}),e.jsxs("div",{className:"space-y-3",children:[Ze.map(s=>{const c=Y[s.id],x=!!(c!=null&&c.enabled);return e.jsxs("div",{className:`flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border transition-all gap-4 ${x?"border-purple-100 bg-purple-50/50 hover:bg-white hover:shadow-lg":"border-gray-100 bg-surface-subtle hover:bg-white hover:shadow-lg"}`,children:[e.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[e.jsx("div",{className:`w-12 h-12 rounded-2xl flex items-center justify-center ${x?"bg-purple-600 text-white":"bg-gray-200 text-gray-400"}`,children:e.jsx(et,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h3",{className:"font-bold text-gray-900 text-lg truncate",children:Re(s)}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-xs font-bold ${x?"bg-green-100 text-green-700":"bg-gray-200 text-gray-500"}`,children:x?"已启用":"未启用"}),(c==null?void 0:c.reply_once)&&e.jsx("span",{className:"px-2 py-0.5 rounded-lg text-xs font-bold bg-purple-100 text-purple-700",children:"只回复一次"})]}),e.jsx("div",{className:"text-sm text-gray-600 line-clamp-2",children:x?c.reply_content||c.reply_image_url||"已配置默认回复":"未配置默认回复"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 border-t md:border-t-0 md:border-l border-gray-200 pt-4 md:pt-0 md:pl-6",children:[e.jsx("button",{onClick:(()=>void We(s.id)),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(ze,{className:"w-4 h-4"})}),x&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:(()=>void ht(s.id)),className:"px-3 py-2 text-xs font-bold text-blue-600 hover:bg-blue-50 rounded-xl transition-colors",children:"清空记录"}),e.jsx("button",{onClick:(()=>void bt(s.id)),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Ce,{className:"w-5 h-5"})})]})]})]},s.id)}),Ze.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无账号"})]})]}),$e&&g&&De.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"72rem",maxHeight:"92vh"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-black text-gray-900",children:g.id?"编辑自动化规则":"新建自动化规则"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:Ne.description})]}),e.jsx("button",{onClick:(()=>je(!1)),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",title:"关闭",children:e.jsx(ke,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[320px_1fr] min-h-0",children:[e.jsxs("aside",{className:"bg-slate-900 text-white p-5 overflow-y-auto",children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 mb-3",children:"选择自动化类型"}),e.jsx("div",{className:"space-y-3",children:Se.map(s=>{const c=ae[s],x=c.icon,de=me===s;return e.jsx("button",{type:"button",onClick:(()=>b(s)),className:`w-full rounded-2xl p-4 text-left border transition-all ${de?"bg-white text-slate-950 border-white":"bg-white/5 text-white border-white/10 hover:bg-white/10"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(x,{className:`w-5 h-5 mt-0.5 ${de?"text-brand":"text-white"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black",children:c.label}),e.jsx("div",{className:`text-xs mt-1 leading-5 ${de?"text-gray-500":"text-gray-400"}`,children:c.description})]})]})},s)})}),e.jsxs("div",{className:"mt-6 rounded-2xl bg-white/5 border border-white/10 p-4",children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 mb-3",children:"执行流程"}),e.jsx("div",{className:"space-y-3",children:Ne.flow.map((s,c)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-white text-slate-950 text-xs font-black flex items-center justify-center",children:c+1}),e.jsx("span",{className:"text-sm font-bold text-gray-100",children:s})]},s))})]})]}),e.jsx("div",{className:"p-6 overflow-y-auto bg-surface-subtle",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(At,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:"生效范围"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"规则名称"}),e.jsx("input",{type:"text",value:g.name||"",onChange:(s=>O({...g,name:s.target.value})),placeholder:"不填时按类型和商品自动生成",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"闲鱼账号"}),e.jsxs("select",{value:g.cookie_id||"",onChange:(s=>O({...g,cookie_id:s.target.value,item_id:"",item_title:"",item_keyword:""})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),V.map(s=>e.jsx("option",{value:s.id,children:Re(s)},s.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:g.item_id||"",onChange:(s=>p(s.target.value)),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级规则(不限定商品)"}),ft.map(s=>e.jsx("option",{value:s.item_id,children:s.item_title||s.item_id},`${s.cookie_id}-${s.item_id}`))]})]})]}),ge&&me!=="review_missing_timeout"&&e.jsxs("div",{className:"mt-4 rounded-2xl bg-gray-50 border border-gray-100 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("span",{className:"px-3 py-1.5 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:ge.item_title||ge.item_id}),e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${oe?"bg-blue-50 text-blue-700":"bg-gray-100 text-gray-500"}`,children:oe?"多规格商品":"普通商品"}),e.jsx("span",{className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-emerald-50 text-emerald-700",children:"按订单购买数量自动发货"})]}),e.jsx("p",{className:"text-xs leading-5 text-gray-500",children:"多规格状态来自闲鱼商品本身,发布后不能在这里修改;系统会在买家付款后读取订单详情,按实际购买规格和数量匹配下面的发货规则。"})]})]}),me!=="review_missing_timeout"?e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($t,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:me==="buyer_reviewed"?"赠品库存":"发货库存"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:oe?"每条发货内容绑定一个订单规格;同一规格可添加多条内容并全部发送。":"可添加多条发货内容,买家付款后会按顺序全部发送。"})]}),e.jsxs("button",{type:"button",onClick:N,className:"px-3 py-2 rounded-xl bg-gray-900 text-white text-xs font-bold hover:bg-black flex items-center gap-1.5",children:[e.jsx(Ye,{className:"w-3.5 h-3.5"}),"添加发货内容"]})]}),e.jsx("div",{className:"space-y-3",children:xe.map((s,c)=>e.jsxs("div",{className:`grid grid-cols-1 gap-3 items-end rounded-2xl border border-gray-200 p-4 ${oe?"md:grid-cols-[1fr_1fr_1.4fr_110px_40px]":"md:grid-cols-[1.4fr_110px_40px]"}`,children:[oe&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"规格名称"}),e.jsx("input",{value:s.spec_name,onChange:(x=>h(c,{spec_name:x.target.value})),className:"w-full ios-input px-3 py-2.5 rounded-lg",placeholder:"例如:套餐"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"规格值"}),e.jsx("input",{value:s.spec_value,onChange:(x=>h(c,{spec_value:x.target.value})),className:"w-full ios-input px-3 py-2.5 rounded-lg",placeholder:"例如:30天"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"卡密库存"}),e.jsxs("select",{value:s.card_id||"",onChange:(x=>h(c,{card_id:Number(x.target.value)})),className:"w-full ios-input px-3 py-2.5 rounded-lg",children:[e.jsx("option",{value:"",children:"请选择卡密库存"}),H.filter(x=>x.enabled&&x.type!=="api").map(x=>e.jsx("option",{value:x.id,children:x.name},x.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"每件份数"}),e.jsx("input",{type:"number",min:"1",max:"100",value:s.delivery_count,onChange:(x=>h(c,{delivery_count:Math.max(1,Number(x.target.value)||1)})),className:"w-full ios-input px-3 py-2.5 rounded-lg"})]}),e.jsxs("div",{className:"md:col-span-full flex flex-wrap items-center gap-3 rounded-xl bg-gray-50 px-3 py-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold text-gray-600 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:s.delay_override===!0,onChange:(x=>h(c,{delay_override:x.target.checked})),className:"accent-brand"}),"覆盖卡密默认延时"]}),s.delay_override&&e.jsx("input",{type:"number",min:"0",max:"3600",value:s.delay_seconds||0,onChange:(x=>h(c,{delay_seconds:Math.max(0,Number(x.target.value)||0)})),className:"w-28 ios-input px-2 py-1.5 rounded-lg text-xs","aria-label":"动作延时秒数"}),e.jsx("span",{className:"text-xs text-gray-500",children:s.delay_override?`本动作延时 ${s.delay_seconds||0} 秒`:"使用卡密默认延时"})]}),e.jsx("button",{type:"button",disabled:xe.length===1,onClick:(()=>O({...g,variants:xe.filter((x,de)=>de!==c)})),className:"w-10 h-10 flex items-center justify-center rounded-lg text-red-500 hover:bg-red-50 disabled:opacity-25",title:"删除发货内容",children:e.jsx(Ce,{className:"w-4 h-4"})})]},s.id||c))})]}):e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(it,{className:"w-5 h-5 text-amber-600"}),e.jsx("h4",{className:"font-black text-gray-900",children:"求评价计划"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"发货后等待小时"}),e.jsx("input",{type:"number",min:"1",value:Number(be.after_shipped_hours||72),onChange:(s=>O({...g,config_json:ce(g.config_json,{after_shipped_hours:Math.max(1,Number(s.target.value)||72)})})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"再次求评间隔小时"}),e.jsx("input",{type:"number",min:"1",value:Number(be.repeat_interval_hours||24),onChange:(s=>O({...g,config_json:ce(g.config_json,{repeat_interval_hours:Math.max(1,Number(s.target.value)||24)})})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最多求评次数"}),e.jsx("input",{type:"number",min:"1",value:Number(be.max_attempts||1),onChange:(s=>O({...g,config_json:ce(g.config_json,{max_attempts:Math.max(1,Number(s.target.value)||1)})})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"md:col-span-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"求评价文案"}),e.jsx("textarea",{value:((Qe=(Xe=g.actions)==null?void 0:Xe.find(s=>s.action_type==="send_text"))==null?void 0:Qe.message_template)||"",onChange:(s=>{var c;return O({...g,actions:((c=g.actions)!=null&&c.length?g.actions:_e("review_missing_timeout")).map(x=>x.action_type==="send_text"?{...x,message_template:s.target.value}:x)})}),className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none"})]})]})]}),e.jsx("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[180px_1fr] gap-4 items-end",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"优先级"}),e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:"数字越小优先级越高;同一账号、商品和触发条件只执行优先级最高的一条规则。"}),e.jsx("input",{type:"number",value:g.priority||100,onChange:(s=>O({...g,priority:Number(s.target.value)||100})),min:"1",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("label",{className:"h-[48px] flex items-center gap-3 px-4 bg-gray-50 rounded-xl text-sm font-bold text-gray-800",children:[e.jsx("input",{type:"checkbox",checked:g.enabled!==!1,onChange:(s=>O({...g,enabled:s.target.checked})),className:"w-4 h-4 rounded"}),"启用规则"]})]})})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 bg-white flex gap-3",children:[e.jsx("button",{onClick:(()=>je(!1)),className:"flex-1 px-6 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200",children:"取消"}),e.jsxs("button",{onClick:f,className:"flex-1 ios-btn-primary px-6 py-3 rounded-2xl font-bold flex items-center justify-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"}),"保存自动化规则"]})]})]})}),document.body),Me&&S&&De.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:S.id?"编辑回复规则":"新增回复规则"}),e.jsx("button",{onClick:(()=>pe(!1)),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(ke,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:S.item_id||"",onChange:(s=>te({...S,item_id:s.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级回复"}),U.filter(s=>!r||s.cookie_id===r).map(s=>e.jsx("option",{value:s.item_id,children:s.item_title||s.item_id},`${s.cookie_id}-${s.item_id}`))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复类型"}),e.jsxs("select",{value:S.type||"text",onChange:(s=>{const c=s.target.value;te({...S,type:c,reply_content:c==="text"?S.reply_content:"",image_url:c==="image"?S.image_url:""})}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"文字"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关键词"}),e.jsx("input",{type:"text",value:S.keyword||"",onChange:(s=>te({...S,keyword:s.target.value})),placeholder:"买家发送的关键词",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),S.type==="image"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{value:S.image_url||"",onChange:(s=>te({...S,image_url:s.target.value})),placeholder:"https://...",className:"w-full ios-input px-4 py-3 rounded-xl"})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复内容"}),e.jsx("textarea",{value:S.reply_content||"",onChange:(s=>te({...S,reply_content:s.target.value})),placeholder:"自动回复的内容",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:(()=>pe(!1)),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:ut,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Mt,{className:"w-4 h-4"}),"保存规则"]})]})]})]})}),document.body),Pe&&De.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"账号默认回复"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"关键词和 AI 都未处理时,才会使用默认回复。"})]}),e.jsx("button",{onClick:(()=>ve(!1)),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",title:"关闭",children:e.jsx(ke,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"闲鱼账号"}),e.jsxs("select",{value:L.cookie_id,onChange:(s=>ie({...L,cookie_id:s.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),V.map(s=>e.jsx("option",{value:s.id,children:Re(s)},s.id))]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"启用默认回复"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"启用后,未命中关键词时自动发送"})]}),e.jsx("button",{type:"button",onClick:(()=>ie({...L,enabled:!L.enabled})),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${L.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${L.enabled?"translate-x-7":"translate-x-1"}`})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复内容"}),e.jsx("textarea",{value:L.reply_content,onChange:(s=>ie({...L,reply_content:s.target.value})),placeholder:"输入默认回复内容",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复图片 URL(可选)"}),e.jsx("input",{type:"text",value:L.reply_image_url,onChange:(s=>ie({...L,reply_image_url:s.target.value})),placeholder:"https://example.com/image.jpg",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("label",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl text-sm font-bold text-gray-800",children:[e.jsxs("span",{children:["只回复一次",e.jsx("span",{className:"block text-xs text-gray-500 font-medium mt-1",children:"同一会话只发送一次默认回复"})]}),e.jsx("input",{type:"checkbox",checked:L.reply_once,onChange:(s=>ie({...L,reply_once:s.target.checked})),className:"w-4 h-4 rounded"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:(()=>ve(!1)),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:gt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"}),"保存默认回复"]})]})]})]})}),document.body)]})};export{os as default};
diff --git a/internal/webui/static/assets/Settings-DUEkZoEv.js b/internal/webui/static/assets/Settings-BKbkBfLj.js
similarity index 99%
rename from internal/webui/static/assets/Settings-DUEkZoEv.js
rename to internal/webui/static/assets/Settings-BKbkBfLj.js
index dd53679..90cc6d8 100644
--- a/internal/webui/static/assets/Settings-DUEkZoEv.js
+++ b/internal/webui/static/assets/Settings-BKbkBfLj.js
@@ -1 +1 @@
-import{r,j as e}from"./react-vendor-C_od1ZSF.js";import{a as xe,g as re,p as le}from"./index-hByDAHGj.js";import{f as ue,R as se,aa as pe,p as me,u as R,v as O,ab as he,s as ge,S as te,ac as ae,ad as ye,r as fe}from"./icons-vendor-CvzvbbIV.js";const ne="https://dashscope.aliyuncs.com/compatible-mode/v1",be=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],we=new Set(["ai_api_key_configured","smtp_password_configured","qq_reply_secret_key_configured","captcha.remote_secret_key_configured","smtp_server","smtp_port","smtp_user","smtp_password","smtp_from","smtp_from_name","smtp_from_address","registration_enabled","show_default_login_info","login_captcha_enabled","item_sync_enabled","item_sync_interval","item_sync_max_pages","default_reply"]),oe=new Set(["ai_api_key","smtp_password","qq_reply_secret_key","captcha.remote_secret_key"]),je=s=>{if("values"in s||"secrets"in s)return s;const a={},o={};for(const[d,h]of Object.entries(s))if(h!=null){if(oe.has(d)){o[d]=h===""?{action:"clear"}:{action:"replace",value:String(h)};continue}a[d]=h}return Object.keys(o).length>0?{values:a,secrets:o}:a},ve=s=>{const a={...s};for(const o of oe){const d=`${o}_configured`;d in a&&(a[d]=a[d]===!0||a[d]==="true")}if("renewal_log_retention_days"in a){const o=Number(a.renewal_log_retention_days);a.renewal_log_retention_days=Number.isFinite(o)?o:10}return a},_e=async(s,a)=>le("/api/v1/session/credentials",s,a),Ne=async s=>{const a=await re("/api/v1/settings/system",void 0,s),o=a.data||a.settings||a;return ve(o)},Se=async(s,a)=>le("/api/v1/settings/system",je(s),a),ke=async(s,a="",o)=>{const d=await xe("/api/v1/settings/ai-models",{base_url:s,api_key:a},o);return Array.isArray(d.models)?d.models:[]},Ce=async s=>re("/api/v1/session",void 0,s),Ee=s=>Object.fromEntries(Object.entries(s).filter(([a,o])=>!we.has(a)&&o!==void 0&&o!==null)),Ae=s=>s.new_username.trim().length<3?"用户名至少需要 3 个字符":s.current_password?s.new_password&&s.new_password.length<8?"新密码至少需要 8 个字符":s.new_password!==s.confirm_password?"两次输入的新密码不一致":"":"请输入当前密码确认身份",f=(s,a,o)=>s===a&&!o.aborted,D=s=>s instanceof Error&&s.message==="请求已取消",K=(s,a)=>s instanceof Error?s.message:a,Ie=(s="")=>({new_username:s,current_password:"",new_password:"",confirm_password:""}),T=(s,a)=>({type:s,text:a}),Me=()=>{const[s,a]=r.useState(null),[o,d]=r.useState(!1),[h,p]=r.useState(""),[S,A]=r.useState(!1),[P,k]=r.useState(""),[C,w]=r.useState([]),[j,I]=r.useState(!1),[M,x]=r.useState(""),[$,v]=r.useState(!1),[U,q]=r.useState(!1),[z,u]=r.useState(!1),[b,F]=r.useState(!1),[G,V]=r.useState(!1),[Y,_]=r.useState(!1),[L,y]=r.useState(null),[t,X]=r.useState(()=>Ie()),[ce,J]=r.useState("idle"),Z=r.useRef(null),ee=r.useRef(null),m=r.useRef(0),W=r.useRef(null);ee.current=s;const E=r.useCallback(()=>{var c;(c=W.current)==null||c.abort();const n=new AbortController;return W.current=n,m.current+=1,{controller:n,sequence:m.current}},[]),B=r.useCallback(async(n,c=!1,l)=>{const i=n||ee.current,g=(i==null?void 0:i.ai_api_url)||(i==null?void 0:i.ai_base_url)||ne;I(!0),x("");try{const N=await ke(g,(i==null?void 0:i.ai_api_key)||"",{signal:l});if(l!=null&&l.aborted)return;w(N),v(c&&N.length>0),!(i!=null&&i.ai_model)&&N.length>0&&a(Q=>Q&&{...Q,ai_model:N[0]})}catch(N){if(l!=null&&l.aborted||D(N))return;w([]),v(!1),x(K(N,"读取模型失败"))}finally{l!=null&&l.aborted||I(!1)}},[]),H=r.useCallback(()=>{const{controller:n,sequence:c}=E();d(!0),J("loading"),p(""),Promise.all([Ne({signal:n.signal}),Ce({signal:n.signal})]).then(([l,i])=>{f(m.current,c,n.signal)&&(a(l),i.username&&X(g=>({...g,new_username:i.username||""})),B(l,!1,n.signal),J("success"))}).catch(l=>{!f(m.current,c,n.signal)||D(l)||(a(null),p(K(l,"加载配置失败")),J("error"))}).finally(()=>{f(m.current,c,n.signal)&&d(!1)})},[E,B]);r.useEffect(()=>(H(),(()=>{var n;return(n=W.current)==null?void 0:n.abort()})),[H]),r.useEffect(()=>{const n=c=>{var l;(l=Z.current)!=null&&l.contains(c.target)||v(!1)};return document.addEventListener("mousedown",n),(()=>document.removeEventListener("mousedown",n))},[]);const ie=r.useCallback(async()=>{if(!s||S)return;const{controller:n,sequence:c}=E();A(!0),k("");try{if(await Se(Ee(s),{signal:n.signal}),!f(m.current,c,n.signal))return;window.alert("系统配置已保存")}catch(l){if(!f(m.current,c,n.signal)||D(l))return;k(K(l,"保存配置失败"))}finally{f(m.current,c,n.signal)&&A(!1)}},[E,S,s]),de=r.useCallback(async n=>{n.preventDefault(),y(null);const c=Ae(t);if(c){y(T("error",c));return}const{controller:l,sequence:i}=E();_(!0);try{const g=await _e({current_password:t.current_password,new_username:t.new_username.trim(),new_password:t.new_password||void 0},{signal:l.signal});if(!f(m.current,i,l.signal))return;if(!g.success){y(T("error",g.message||"登录凭据更新失败"));return}y(T("success",g.message||"登录凭据已更新")),window.setTimeout(()=>window.location.reload(),1400)}catch(g){if(!f(m.current,i,l.signal)||D(g))return;y(T("error",K(g,"登录凭据更新失败")))}finally{f(m.current,i,l.signal)&&_(!1)}},[E,t]);return{settings:s,loading:o,loadError:h,saving:S,saveError:P,aiModels:C,modelsLoading:j,modelError:M,modelDropdownOpen:$,showApiKey:U,showCaptchaSecret:z,showCurrentPassword:b,showNewPassword:G,credentialsSaving:Y,credentialsMessage:L,credentials:t,requestStatus:ce,modelPickerRef:Z,loadSettings:H,loadAIModels:((n,c)=>void B(n,c)),handleSave:ie,handleCredentialsSave:de,setSettings:a,setModelDropdownOpen:v,setShowApiKey:q,setShowCaptchaSecret:u,setShowCurrentPassword:F,setShowNewPassword:V,setCredentials:X,setCredentialsMessage:y}},Re=()=>{const{settings:s,loading:a,loadError:o,saving:d,saveError:h,aiModels:p,modelsLoading:S,modelError:A,modelDropdownOpen:P,showApiKey:k,showCaptchaSecret:C,showCurrentPassword:w,showNewPassword:j,credentialsSaving:I,credentialsMessage:M,credentials:x,modelPickerRef:$,loadSettings:v,loadAIModels:U,handleSave:q,handleCredentialsSave:z,setSettings:u,setModelDropdownOpen:b,setShowApiKey:F,setShowCaptchaSecret:G,setShowCurrentPassword:V,setShowNewPassword:Y,setCredentials:_}=Me();if(!s)return e.jsxs("div",{className:"p-8 text-center text-gray-400 space-y-3",children:[o||(a?"加载配置中...":"暂无配置"),!a&&o&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ios-btn-primary px-4 py-2 rounded-xl",onClick:v,children:"重新加载"})})]});const L=s.ai_model||"",y=p;return e.jsxs("div",{className:"max-w-6xl mx-auto space-y-8 animate-fade-in pb-24",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-gray-100 rounded-2xl flex items-center justify-center",children:e.jsx(ue,{className:"w-6 h-6 text-gray-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900",children:"系统设置"}),e.jsx("p",{className:"text-gray-500 mt-1 text-sm font-medium",children:"配置全局自动化规则与系统参数"})]})]}),e.jsxs("button",{onClick:v,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(se,{className:"w-4 h-4"}),"刷新"]})]}),h&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:h}),e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>{}),children:"重试保存"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-100 text-gray-600",children:e.jsx(pe,{className:"w-4 h-4"})}),"基础设置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出等级"}),e.jsx("select",{value:s.log_level||"info",onChange:(t=>u({...s,log_level:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:be.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("p",{className:"text-xs text-gray-500",children:"等级越低输出越详细,Debug 适合排查问题"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出格式"}),e.jsxs("select",{value:s.log_format||"text",onChange:(t=>u({...s,log_format:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"JSON 适合接入集中式日志系统,保存后需重启服务生效"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"续期日志保留天数"}),e.jsx("input",{type:"number",value:s.renewal_log_retention_days??10,onChange:(t=>u({...s,renewal_log_retention_days:parseInt(t.target.value)||0})),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"365"}),e.jsx("p",{className:"text-xs text-gray-500",children:"0 表示不自动清理续期日志"})]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-brand text-white",children:e.jsx(me,{className:"w-4 h-4"})}),"AI 智能回复配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API 地址"}),e.jsx("input",{type:"text",value:s.ai_api_url||ne,onChange:(t=>u({...s,ai_api_url:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://api.openai.com/v1"}),e.jsx("p",{className:"text-xs text-gray-500",children:"无需补全 /chat/completions"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:k?"text":"password",value:s.ai_api_key||"",onChange:(t=>u({...s,ai_api_key:t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",placeholder:s.ai_api_key_configured?"已配置,如需替换请输入新密钥":"sk-..."}),e.jsx("button",{type:"button",onClick:(()=>F(!k)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:k?e.jsx(R,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"模型"}),e.jsxs("div",{ref:$,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:L,onFocus:(()=>p.length>0&&b(!0)),onChange:(t=>{u({...s,ai_model:t.target.value}),p.length>0&&b(!0)}),onKeyDown:(t=>{t.key==="Escape"&&b(!1),t.key==="ArrowDown"&&p.length>0&&b(!0)}),className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:(()=>p.length>0&&b(t=>!t)),disabled:p.length===0,className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 disabled:opacity-30","aria-label":"展开模型列表",children:e.jsx(he,{className:`w-4 h-4 transition-transform ${P?"rotate-180":""}`})}),P&&e.jsx("div",{className:"absolute left-0 right-0 top-[calc(100%+6px)] z-40 max-h-64 overflow-y-auto rounded-xl border border-gray-200 bg-white shadow-xl shadow-gray-200/70 py-1",children:y.length>0?y.map(t=>e.jsxs("button",{type:"button",onClick:(()=>{u({...s,ai_model:t}),b(!1)}),className:"w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-brand flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:t}),t===L&&e.jsx(ge,{className:"w-4 h-4 shrink-0 text-brand"})]},t)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:(()=>U(void 0,!0)),disabled:S,className:"px-4 py-3 rounded-xl bg-gray-100 text-gray-700 hover:bg-gray-200 disabled:opacity-60 font-bold flex items-center justify-center gap-2 whitespace-nowrap",children:[e.jsx(se,{className:`w-4 h-4 ${S?"animate-spin":""}`}),"读取模型"]})]}),A?e.jsx("p",{className:"text-xs text-red-500",children:A}):e.jsx("p",{className:"text-xs text-gray-500",children:p.length>0?`已从当前 API 地址读取到 ${p.length} 个模型`:"模型列表从当前 API 地址读取,也可以手动输入模型名"})]}),e.jsxs("div",{className:"p-3 bg-blue-50 rounded-xl text-xs text-blue-700",children:[e.jsx("strong",{children:"常见 AI 服务:"}),e.jsxs("ul",{className:"list-disc list-inside mt-1 space-y-0.5",children:[e.jsx("li",{children:"阿里云通义千问: https://dashscope.aliyuncs.com/compatible-mode/v1"}),e.jsx("li",{children:"OpenAI: https://api.openai.com/v1"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-amber-500 text-white",children:e.jsx(te,{className:"w-4 h-4"})}),"远程过滑块配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务地址"}),e.jsx("input",{type:"url",value:s["captcha.remote_service_url"]||"",onChange:(t=>u({...s,"captcha.remote_service_url":t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://example.com/internal/captcha/solve"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务秘钥"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:C?"text":"password",value:s["captcha.remote_secret_key"]||"",onChange:(t=>u({...s,"captcha.remote_secret_key":t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",autoComplete:"off",placeholder:s["captcha.remote_secret_key_configured"]?"已配置,如需替换请输入新密钥":"请输入服务秘钥"}),e.jsx("button",{type:"button",onClick:(()=>G(!C)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:C?"隐藏秘钥":"显示秘钥",children:C?e.jsx(R,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl bg-amber-50 p-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:String(s["captcha.remote_pass_cookies"]||"").toLowerCase()==="true",onChange:(t=>u({...s,"captcha.remote_pass_cookies":t.target.checked})),className:"mt-0.5 w-4 h-4 rounded border-gray-300"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-bold text-amber-900",children:"允许向远程服务传递账号 Cookie"}),e.jsx("span",{className:"block mt-1 text-xs text-amber-700",children:"默认关闭。仅在信任远程服务且需要由其自动重取过期验证链接时开启。"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"配置地址和秘钥后优先调用远程服务;只有网络不可用或超时才回退本机引擎,远程明确返回失败时不会重复触发本机验证。"})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-900 text-white",children:e.jsx(ae,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:z,className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"登录用户名"}),e.jsxs("div",{className:"relative",children:[e.jsx(ye,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:x.new_username,onChange:(t=>_({...x,new_username:t.target.value})),className:"w-full ios-input pl-11 pr-4 py-3 rounded-xl text-sm",autoComplete:"username"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"当前密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:w?"text":"password",value:x.current_password,onChange:(t=>_({...x,current_password:t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm",placeholder:"用于确认当前身份",autoComplete:"current-password"}),e.jsx("button",{type:"button",onClick:(()=>V(!w)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:w?"隐藏密码":"显示密码",children:w?e.jsx(R,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"新密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:j?"text":"password",value:x.new_password,onChange:(t=>_({...x,new_password:t.target.value})),className:"w-full ios-input px-4 py-3 pr-11 rounded-xl text-sm",placeholder:"不修改则留空",autoComplete:"new-password"}),e.jsx("button",{type:"button",onClick:(()=>Y(!j)),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:j?"隐藏密码":"显示密码",children:j?e.jsx(R,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"确认新密码"}),e.jsx("input",{type:j?"text":"password",value:x.confirm_password,onChange:(t=>_({...x,confirm_password:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),M&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${M.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(te,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:M.text})]}),e.jsxs("button",{type:"submit",disabled:I||!x.new_username||!x.current_password,className:"w-full bg-gray-900 hover:bg-black text-white px-5 py-3 rounded-xl font-bold text-sm flex items-center justify-center gap-2 transition-colors disabled:opacity-40",children:[e.jsx(ae,{className:"w-4 h-4"}),I?"正在更新...":"更新登录凭据"]})]})]})]})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:q,disabled:d,className:"ios-btn-primary px-10 py-5 rounded-xl text-lg shadow-2xl shadow-blue-200 flex items-center gap-3 transform hover:scale-105 active:scale-95 transition-all disabled:opacity-70",children:[e.jsx(fe,{className:"w-6 h-6"}),d?"保存中...":"保存所有配置"]})})]})};export{Re as default};
+import{r,j as e}from"./react-vendor-C_od1ZSF.js";import{a as xe,g as re,p as le}from"./index-CNzF_I4S.js";import{f as ue,R as se,aa as pe,p as me,u as R,v as O,ab as he,s as ge,S as te,ac as ae,ad as ye,r as fe}from"./icons-vendor-CvzvbbIV.js";const ne="https://dashscope.aliyuncs.com/compatible-mode/v1",be=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],we=new Set(["ai_api_key_configured","smtp_password_configured","qq_reply_secret_key_configured","captcha.remote_secret_key_configured","smtp_server","smtp_port","smtp_user","smtp_password","smtp_from","smtp_from_name","smtp_from_address","registration_enabled","show_default_login_info","login_captcha_enabled","item_sync_enabled","item_sync_interval","item_sync_max_pages","default_reply"]),oe=new Set(["ai_api_key","smtp_password","qq_reply_secret_key","captcha.remote_secret_key"]),je=s=>{if("values"in s||"secrets"in s)return s;const a={},o={};for(const[d,h]of Object.entries(s))if(h!=null){if(oe.has(d)){o[d]=h===""?{action:"clear"}:{action:"replace",value:String(h)};continue}a[d]=h}return Object.keys(o).length>0?{values:a,secrets:o}:a},ve=s=>{const a={...s};for(const o of oe){const d=`${o}_configured`;d in a&&(a[d]=a[d]===!0||a[d]==="true")}if("renewal_log_retention_days"in a){const o=Number(a.renewal_log_retention_days);a.renewal_log_retention_days=Number.isFinite(o)?o:10}return a},_e=async(s,a)=>le("/api/v1/session/credentials",s,a),Ne=async s=>{const a=await re("/api/v1/settings/system",void 0,s),o=a.data||a.settings||a;return ve(o)},Se=async(s,a)=>le("/api/v1/settings/system",je(s),a),ke=async(s,a="",o)=>{const d=await xe("/api/v1/settings/ai-models",{base_url:s,api_key:a},o);return Array.isArray(d.models)?d.models:[]},Ce=async s=>re("/api/v1/session",void 0,s),Ee=s=>Object.fromEntries(Object.entries(s).filter(([a,o])=>!we.has(a)&&o!==void 0&&o!==null)),Ae=s=>s.new_username.trim().length<3?"用户名至少需要 3 个字符":s.current_password?s.new_password&&s.new_password.length<8?"新密码至少需要 8 个字符":s.new_password!==s.confirm_password?"两次输入的新密码不一致":"":"请输入当前密码确认身份",f=(s,a,o)=>s===a&&!o.aborted,D=s=>s instanceof Error&&s.message==="请求已取消",K=(s,a)=>s instanceof Error?s.message:a,Ie=(s="")=>({new_username:s,current_password:"",new_password:"",confirm_password:""}),T=(s,a)=>({type:s,text:a}),Me=()=>{const[s,a]=r.useState(null),[o,d]=r.useState(!1),[h,p]=r.useState(""),[S,A]=r.useState(!1),[P,k]=r.useState(""),[C,w]=r.useState([]),[j,I]=r.useState(!1),[M,x]=r.useState(""),[$,v]=r.useState(!1),[U,q]=r.useState(!1),[z,u]=r.useState(!1),[b,F]=r.useState(!1),[G,V]=r.useState(!1),[Y,_]=r.useState(!1),[L,y]=r.useState(null),[t,X]=r.useState(()=>Ie()),[ce,J]=r.useState("idle"),Z=r.useRef(null),ee=r.useRef(null),m=r.useRef(0),W=r.useRef(null);ee.current=s;const E=r.useCallback(()=>{var c;(c=W.current)==null||c.abort();const n=new AbortController;return W.current=n,m.current+=1,{controller:n,sequence:m.current}},[]),B=r.useCallback(async(n,c=!1,l)=>{const i=n||ee.current,g=(i==null?void 0:i.ai_api_url)||(i==null?void 0:i.ai_base_url)||ne;I(!0),x("");try{const N=await ke(g,(i==null?void 0:i.ai_api_key)||"",{signal:l});if(l!=null&&l.aborted)return;w(N),v(c&&N.length>0),!(i!=null&&i.ai_model)&&N.length>0&&a(Q=>Q&&{...Q,ai_model:N[0]})}catch(N){if(l!=null&&l.aborted||D(N))return;w([]),v(!1),x(K(N,"读取模型失败"))}finally{l!=null&&l.aborted||I(!1)}},[]),H=r.useCallback(()=>{const{controller:n,sequence:c}=E();d(!0),J("loading"),p(""),Promise.all([Ne({signal:n.signal}),Ce({signal:n.signal})]).then(([l,i])=>{f(m.current,c,n.signal)&&(a(l),i.username&&X(g=>({...g,new_username:i.username||""})),B(l,!1,n.signal),J("success"))}).catch(l=>{!f(m.current,c,n.signal)||D(l)||(a(null),p(K(l,"加载配置失败")),J("error"))}).finally(()=>{f(m.current,c,n.signal)&&d(!1)})},[E,B]);r.useEffect(()=>(H(),(()=>{var n;return(n=W.current)==null?void 0:n.abort()})),[H]),r.useEffect(()=>{const n=c=>{var l;(l=Z.current)!=null&&l.contains(c.target)||v(!1)};return document.addEventListener("mousedown",n),(()=>document.removeEventListener("mousedown",n))},[]);const ie=r.useCallback(async()=>{if(!s||S)return;const{controller:n,sequence:c}=E();A(!0),k("");try{if(await Se(Ee(s),{signal:n.signal}),!f(m.current,c,n.signal))return;window.alert("系统配置已保存")}catch(l){if(!f(m.current,c,n.signal)||D(l))return;k(K(l,"保存配置失败"))}finally{f(m.current,c,n.signal)&&A(!1)}},[E,S,s]),de=r.useCallback(async n=>{n.preventDefault(),y(null);const c=Ae(t);if(c){y(T("error",c));return}const{controller:l,sequence:i}=E();_(!0);try{const g=await _e({current_password:t.current_password,new_username:t.new_username.trim(),new_password:t.new_password||void 0},{signal:l.signal});if(!f(m.current,i,l.signal))return;if(!g.success){y(T("error",g.message||"登录凭据更新失败"));return}y(T("success",g.message||"登录凭据已更新")),window.setTimeout(()=>window.location.reload(),1400)}catch(g){if(!f(m.current,i,l.signal)||D(g))return;y(T("error",K(g,"登录凭据更新失败")))}finally{f(m.current,i,l.signal)&&_(!1)}},[E,t]);return{settings:s,loading:o,loadError:h,saving:S,saveError:P,aiModels:C,modelsLoading:j,modelError:M,modelDropdownOpen:$,showApiKey:U,showCaptchaSecret:z,showCurrentPassword:b,showNewPassword:G,credentialsSaving:Y,credentialsMessage:L,credentials:t,requestStatus:ce,modelPickerRef:Z,loadSettings:H,loadAIModels:((n,c)=>void B(n,c)),handleSave:ie,handleCredentialsSave:de,setSettings:a,setModelDropdownOpen:v,setShowApiKey:q,setShowCaptchaSecret:u,setShowCurrentPassword:F,setShowNewPassword:V,setCredentials:X,setCredentialsMessage:y}},Re=()=>{const{settings:s,loading:a,loadError:o,saving:d,saveError:h,aiModels:p,modelsLoading:S,modelError:A,modelDropdownOpen:P,showApiKey:k,showCaptchaSecret:C,showCurrentPassword:w,showNewPassword:j,credentialsSaving:I,credentialsMessage:M,credentials:x,modelPickerRef:$,loadSettings:v,loadAIModels:U,handleSave:q,handleCredentialsSave:z,setSettings:u,setModelDropdownOpen:b,setShowApiKey:F,setShowCaptchaSecret:G,setShowCurrentPassword:V,setShowNewPassword:Y,setCredentials:_}=Me();if(!s)return e.jsxs("div",{className:"p-8 text-center text-gray-400 space-y-3",children:[o||(a?"加载配置中...":"暂无配置"),!a&&o&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ios-btn-primary px-4 py-2 rounded-xl",onClick:v,children:"重新加载"})})]});const L=s.ai_model||"",y=p;return e.jsxs("div",{className:"max-w-6xl mx-auto space-y-8 animate-fade-in pb-24",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-gray-100 rounded-2xl flex items-center justify-center",children:e.jsx(ue,{className:"w-6 h-6 text-gray-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900",children:"系统设置"}),e.jsx("p",{className:"text-gray-500 mt-1 text-sm font-medium",children:"配置全局自动化规则与系统参数"})]})]}),e.jsxs("button",{onClick:v,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(se,{className:"w-4 h-4"}),"刷新"]})]}),h&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:h}),e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>{}),children:"重试保存"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-100 text-gray-600",children:e.jsx(pe,{className:"w-4 h-4"})}),"基础设置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出等级"}),e.jsx("select",{value:s.log_level||"info",onChange:(t=>u({...s,log_level:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:be.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("p",{className:"text-xs text-gray-500",children:"等级越低输出越详细,Debug 适合排查问题"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出格式"}),e.jsxs("select",{value:s.log_format||"text",onChange:(t=>u({...s,log_format:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"JSON 适合接入集中式日志系统,保存后需重启服务生效"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"续期日志保留天数"}),e.jsx("input",{type:"number",value:s.renewal_log_retention_days??10,onChange:(t=>u({...s,renewal_log_retention_days:parseInt(t.target.value)||0})),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"365"}),e.jsx("p",{className:"text-xs text-gray-500",children:"0 表示不自动清理续期日志"})]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-brand text-white",children:e.jsx(me,{className:"w-4 h-4"})}),"AI 智能回复配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API 地址"}),e.jsx("input",{type:"text",value:s.ai_api_url||ne,onChange:(t=>u({...s,ai_api_url:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://api.openai.com/v1"}),e.jsx("p",{className:"text-xs text-gray-500",children:"无需补全 /chat/completions"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:k?"text":"password",value:s.ai_api_key||"",onChange:(t=>u({...s,ai_api_key:t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",placeholder:s.ai_api_key_configured?"已配置,如需替换请输入新密钥":"sk-..."}),e.jsx("button",{type:"button",onClick:(()=>F(!k)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:k?e.jsx(R,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"模型"}),e.jsxs("div",{ref:$,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:L,onFocus:(()=>p.length>0&&b(!0)),onChange:(t=>{u({...s,ai_model:t.target.value}),p.length>0&&b(!0)}),onKeyDown:(t=>{t.key==="Escape"&&b(!1),t.key==="ArrowDown"&&p.length>0&&b(!0)}),className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:(()=>p.length>0&&b(t=>!t)),disabled:p.length===0,className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 disabled:opacity-30","aria-label":"展开模型列表",children:e.jsx(he,{className:`w-4 h-4 transition-transform ${P?"rotate-180":""}`})}),P&&e.jsx("div",{className:"absolute left-0 right-0 top-[calc(100%+6px)] z-40 max-h-64 overflow-y-auto rounded-xl border border-gray-200 bg-white shadow-xl shadow-gray-200/70 py-1",children:y.length>0?y.map(t=>e.jsxs("button",{type:"button",onClick:(()=>{u({...s,ai_model:t}),b(!1)}),className:"w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-brand flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:t}),t===L&&e.jsx(ge,{className:"w-4 h-4 shrink-0 text-brand"})]},t)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:(()=>U(void 0,!0)),disabled:S,className:"px-4 py-3 rounded-xl bg-gray-100 text-gray-700 hover:bg-gray-200 disabled:opacity-60 font-bold flex items-center justify-center gap-2 whitespace-nowrap",children:[e.jsx(se,{className:`w-4 h-4 ${S?"animate-spin":""}`}),"读取模型"]})]}),A?e.jsx("p",{className:"text-xs text-red-500",children:A}):e.jsx("p",{className:"text-xs text-gray-500",children:p.length>0?`已从当前 API 地址读取到 ${p.length} 个模型`:"模型列表从当前 API 地址读取,也可以手动输入模型名"})]}),e.jsxs("div",{className:"p-3 bg-blue-50 rounded-xl text-xs text-blue-700",children:[e.jsx("strong",{children:"常见 AI 服务:"}),e.jsxs("ul",{className:"list-disc list-inside mt-1 space-y-0.5",children:[e.jsx("li",{children:"阿里云通义千问: https://dashscope.aliyuncs.com/compatible-mode/v1"}),e.jsx("li",{children:"OpenAI: https://api.openai.com/v1"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-amber-500 text-white",children:e.jsx(te,{className:"w-4 h-4"})}),"远程过滑块配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务地址"}),e.jsx("input",{type:"url",value:s["captcha.remote_service_url"]||"",onChange:(t=>u({...s,"captcha.remote_service_url":t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://example.com/internal/captcha/solve"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务秘钥"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:C?"text":"password",value:s["captcha.remote_secret_key"]||"",onChange:(t=>u({...s,"captcha.remote_secret_key":t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",autoComplete:"off",placeholder:s["captcha.remote_secret_key_configured"]?"已配置,如需替换请输入新密钥":"请输入服务秘钥"}),e.jsx("button",{type:"button",onClick:(()=>G(!C)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:C?"隐藏秘钥":"显示秘钥",children:C?e.jsx(R,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl bg-amber-50 p-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:String(s["captcha.remote_pass_cookies"]||"").toLowerCase()==="true",onChange:(t=>u({...s,"captcha.remote_pass_cookies":t.target.checked})),className:"mt-0.5 w-4 h-4 rounded border-gray-300"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-bold text-amber-900",children:"允许向远程服务传递账号 Cookie"}),e.jsx("span",{className:"block mt-1 text-xs text-amber-700",children:"默认关闭。仅在信任远程服务且需要由其自动重取过期验证链接时开启。"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"配置地址和秘钥后优先调用远程服务;只有网络不可用或超时才回退本机引擎,远程明确返回失败时不会重复触发本机验证。"})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-900 text-white",children:e.jsx(ae,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:z,className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"登录用户名"}),e.jsxs("div",{className:"relative",children:[e.jsx(ye,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:x.new_username,onChange:(t=>_({...x,new_username:t.target.value})),className:"w-full ios-input pl-11 pr-4 py-3 rounded-xl text-sm",autoComplete:"username"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"当前密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:w?"text":"password",value:x.current_password,onChange:(t=>_({...x,current_password:t.target.value})),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm",placeholder:"用于确认当前身份",autoComplete:"current-password"}),e.jsx("button",{type:"button",onClick:(()=>V(!w)),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:w?"隐藏密码":"显示密码",children:w?e.jsx(R,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"新密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:j?"text":"password",value:x.new_password,onChange:(t=>_({...x,new_password:t.target.value})),className:"w-full ios-input px-4 py-3 pr-11 rounded-xl text-sm",placeholder:"不修改则留空",autoComplete:"new-password"}),e.jsx("button",{type:"button",onClick:(()=>Y(!j)),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:j?"隐藏密码":"显示密码",children:j?e.jsx(R,{className:"w-4 h-4"}):e.jsx(O,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"确认新密码"}),e.jsx("input",{type:j?"text":"password",value:x.confirm_password,onChange:(t=>_({...x,confirm_password:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),M&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${M.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(te,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:M.text})]}),e.jsxs("button",{type:"submit",disabled:I||!x.new_username||!x.current_password,className:"w-full bg-gray-900 hover:bg-black text-white px-5 py-3 rounded-xl font-bold text-sm flex items-center justify-center gap-2 transition-colors disabled:opacity-40",children:[e.jsx(ae,{className:"w-4 h-4"}),I?"正在更新...":"更新登录凭据"]})]})]})]})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:q,disabled:d,className:"ios-btn-primary px-10 py-5 rounded-xl text-lg shadow-2xl shadow-blue-200 flex items-center gap-3 transform hover:scale-105 active:scale-95 transition-all disabled:opacity-70",children:[e.jsx(fe,{className:"w-6 h-6"}),d?"保存中...":"保存所有配置"]})})]})};export{Re as default};
diff --git a/internal/webui/static/assets/index-hByDAHGj.js b/internal/webui/static/assets/index-CNzF_I4S.js
similarity index 95%
rename from internal/webui/static/assets/index-hByDAHGj.js
rename to internal/webui/static/assets/index-CNzF_I4S.js
index 16357a7..d07ec69 100644
--- a/internal/webui/static/assets/index-hByDAHGj.js
+++ b/internal/webui/static/assets/index-CNzF_I4S.js
@@ -1,2 +1,2 @@
-const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Dashboard-MmgsZAic.js","assets/react-vendor-C_od1ZSF.js","assets/dateTime-DDi7rqpW.js","assets/contract-COFcZjyb.js","assets/icons-vendor-CvzvbbIV.js","assets/charts-vendor-BxxJOyEX.js","assets/vendor-D-Edl3pr.js","assets/AccountList-Bb-tGjAS.js","assets/OrderList-BAnpJSM4.js","assets/CardList-D43xNKm6.js","assets/ItemList-BHJwErgP.js","assets/Settings-DUEkZoEv.js","assets/Rules-BplaKbZv.js","assets/Notifications-Dvclt-gX.js","assets/Chat-DSkOtUaB.js"])))=>i.map(i=>d[i]);
-import{c as S,j as e,r as c,d as H}from"./react-vendor-C_od1ZSF.js";import{L as T,a as P,S as J,U as Y,A as K,b as Q,c as W,M as X,C as ee,B as te,d as se,Z as ne,e as re,f as ae,G as k,g as oe,h as ie,i as le}from"./icons-vendor-CvzvbbIV.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))d(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&d(a)}).observe(document,{childList:!0,subtree:!0});function s(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function d(r){if(r.ep)return;r.ep=!0;const i=s(r);fetch(r.href,i)}})();class ce extends S.Component{constructor(){super(...arguments),this.state={hasError:!1},this.handleReload=()=>{window.location.reload()}}static getDerivedStateFromError(){return{hasError:!0}}render(){const{hasError:n}=this.state,{children:s}=this.props;return n?e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-canvas p-6 text-ink",children:e.jsxs("section",{className:"max-w-md text-center",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"页面暂时无法显示"}),e.jsx("button",{className:"ios-btn-primary mt-6 px-4 py-2",type:"button",onClick:this.handleReload,children:"重新加载"})]})}):s}}const de=3e4,ue=10*6e4;let N=!1;const I=()=>{N||typeof window>"u"||(N=!0,window.dispatchEvent(new Event("auth:logout")),queueMicrotask(()=>{N=!1}))},he=t=>{if(!t)return"";const n=new URLSearchParams;for(const[d,r]of Object.entries(t))r!=null&&n.set(d,String(r));const s=n.toString();return s?`?${s}`:""},L=async(t,n,s={})=>{var o;const d=he(s.params),r=`${n}${d}`,i=$(s.signal,s.timeoutMs??de);let a;try{a=await fetch(r,{method:t,credentials:"include",signal:i.signal,headers:{...s.body===void 0?{}:{"Content-Type":"application/json"}},body:s.body===void 0?void 0:JSON.stringify(s.body)})}catch(m){throw i.signal.aborted?new Error((o=s.signal)!=null&&o.aborted?"请求已取消":"请求超时,请稍后重试"):m}finally{i.cleanup()}const h=(a.headers.get("content-type")||"").includes("application/json");if(!a.ok){a.status===401&&!s.skipAuthLogout&&I();const m=h?await a.json().catch(()=>{}):await a.text().catch(()=>{}),f=z(m,a.status);throw new Error(f)}return h?await a.json():await a.text()},D=async(t,n,s)=>L("GET",t,{params:n,...s}),_=async(t,n,s)=>L("POST",t,{body:n,...s}),Ve=async(t,n,s)=>L("PUT",t,{body:n,...s}),Ue=async(t,n,s)=>L("DELETE",t,{params:n,...s}),Ge=async(t,n,s={})=>{var h;const d=$(s.signal,s.timeoutMs??ue);let r;try{r=await fetch(t,{method:"POST",credentials:"include",signal:d.signal,body:n})}catch(o){throw d.signal.aborted?new Error((h=s.signal)!=null&&h.aborted?"请求已取消":"上传超时,请稍后重试"):o}finally{d.cleanup()}const l=(r.headers.get("content-type")||"").includes("application/json")?await r.json().catch(()=>{}):await r.text().catch(()=>{});if(!r.ok){r.status===401&&I();const o=z(l,r.status),m=new Error(o);throw m.payload=l,m}return l},$=(t,n)=>{const s=new AbortController,d=()=>s.abort(t==null?void 0:t.reason);t!=null&&t.aborted?d():t==null||t.addEventListener("abort",d,{once:!0});const r=globalThis.setTimeout(()=>s.abort(new DOMException("timeout","TimeoutError")),Math.max(1,n));return{signal:s.signal,cleanup:()=>{globalThis.clearTimeout(r),t==null||t.removeEventListener("abort",d)}}},me=t=>{if(typeof t!="object"||t===null)return!1;const n=t;return typeof n.code=="string"&&typeof n.message=="string"},z=(t,n)=>typeof t=="string"?t:me(t)?t.message:`请求失败: ${n}`,fe=async t=>_("/api/v1/session/login",t,{skipAuthLogout:!0}),xe=async t=>_("/api/v1/session/initialize",{password:t},{skipAuthLogout:!0}),pe=async t=>D("/api/v1/session",void 0,t),ge=async()=>_("/api/v1/session/logout",{}),M=c.createContext(void 0),be=({children:t})=>{const[n,s]=c.useState(!1),[d,r]=c.useState(!1),[i,a]=c.useState(!0),[l,h]=c.useState(!1),o=()=>{s(!1),r(!1)};c.useEffect(()=>{const b=new AbortController;let g=!0;pe({signal:b.signal}).then(p=>{if(g){if((p==null?void 0:p.initialized)===!1){h(!0),o();return}h(!1),p!=null&&p.authenticated?(s(!0),r(p.is_admin===!0)):o()}}).catch(p=>{!g||p instanceof DOMException&&p.name==="AbortError"||(h(!1),o())}).finally(()=>{g&&a(!1)});const u=()=>o();return window.addEventListener("auth:logout",u),(()=>{g=!1,b.abort(),window.removeEventListener("auth:logout",u)})},[]);const m=async b=>{const g=await fe(b);return g.success&&(h(!1),s(!0),r(g.is_admin===!0)),g},f=async b=>{const g=await xe(b);return g.success&&(h(!1),s(!0),r(g.is_admin===!0)),g},x=async()=>{try{await ge()}finally{o()}};return e.jsx(M.Provider,{value:{checkingAuth:i,isLoggedIn:n,isAdmin:d,needsInit:l,signIn:m,initialize:f,signOut:x},children:t})},B=()=>{const t=c.useContext(M);if(!t)throw new Error("useSession 必须在 SessionProvider 内使用");return t},q="ydisks.sidebar.v1",ye=()=>{try{return window.localStorage.getItem(q)==="collapsed"}catch{return!1}},ve=t=>{try{window.localStorage.setItem(q,t?"collapsed":"expanded")}catch{}},we=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),F=({sizeClass:t="w-12 h-12",logoClassName:n="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23.51 12.25 L 27.29 10.34 L 31.54 8.78 L 36.33 7.56 L 41.84 6.69 L 48.52 6.17 L 60.00 6.00 L 71.48 6.17 L 78.16 6.69 L 83.67 7.56 L 88.46 8.78 L 92.71 10.34 L 96.49 12.25 L 99.87 14.52 L 102.86 17.14 L 105.48 20.13 L 107.75 23.51 L 109.66 27.29 L 111.22 31.54 L 112.44 36.33 L 113.31 41.84 L 113.83 48.52 Z",fill:"url(#login-squircle-gradient)"})]}),e.jsx("div",{className:"relative z-10 flex items-center justify-center w-full h-full",children:e.jsx(we,{className:n})})]})]}),je=()=>{const{checkingAuth:t,needsInit:n,signIn:s,initialize:d}=B(),[r,i]=c.useState(""),[a,l]=c.useState(""),[h,o]=c.useState(""),[m,f]=c.useState(""),[x,b]=c.useState(!1),[g,u]=c.useState(""),p=async y=>{y.preventDefault(),b(!0),u("");try{const v=await s({username:r,password:a});v.success||u(v.message||"登录失败")}catch(v){u(v instanceof Error&&v.message||"登录失败")}finally{b(!1)}},j=async y=>{if(y.preventDefault(),u(""),h.length<8){u("密码至少需要 8 个字符");return}if(h!==m){u("两次输入的密码不一致");return}b(!0);try{const v=await d(h);if(!v.success){u(v.message||"初始化失败,请重试");return}o(""),f("")}catch(v){u(v instanceof Error&&v.message||"初始化失败,请重试")}finally{b(!1)}};if(t)return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-surface","aria-label":"正在校验会话",children:e.jsx(T,{className:"h-8 w-8 animate-spin text-brand"})});const G=n?"首次设置管理员密码":"欢迎回来",Z=n?"设置完成后会自动进入系统,管理员账号为 admin。":"Ydisks闲鱼助手 · 自动发货与管家系统";return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-canvas p-4 font-sans",children:e.jsxs("section",{className:"w-full max-w-lg rounded-xl border border-white bg-white/80 p-8 shadow-panel backdrop-blur-3xl md:p-12",children:[e.jsxs("header",{className:"mb-8 text-center",children:[e.jsx("div",{className:"mx-auto mb-6 flex justify-center",children:e.jsx(F,{sizeClass:"h-24 w-24"})}),e.jsx("h1",{className:"text-3xl font-extrabold text-gray-900",children:G}),e.jsx("p",{className:"mt-2 font-medium text-gray-600",children:Z})]}),n?e.jsxs("form",{className:"space-y-5",onSubmit:j,children:[e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"设置管理员密码"}),e.jsx(P,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{autoFocus:!0,className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(y=>o(y.target.value)),placeholder:"设置管理员密码(至少 8 个字符)",type:"password",value:h})]}),e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"确认管理员密码"}),e.jsx(J,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(y=>f(y.target.value)),placeholder:"再次输入密码",type:"password",value:m})]}),e.jsx(A,{submitting:x,text:"设置密码并进入系统"})]}):e.jsxs("form",{className:"space-y-5",onSubmit:p,children:[e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"管理员账号"}),e.jsx(Y,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{autoFocus:!0,className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(y=>i(y.target.value)),placeholder:"管理员账号",type:"text",value:r})]}),e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"管理员密码"}),e.jsx(P,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(y=>l(y.target.value)),placeholder:"密码",type:"password",value:a})]}),e.jsx(A,{submitting:x,text:"立即登录"})]}),g?e.jsx("p",{className:"mt-5 rounded-xl bg-red-50 p-3 text-center text-sm font-medium text-red-600",children:g}):null]})})},A=({submitting:t,text:n})=>e.jsx("button",{className:"ios-btn-primary flex h-14 w-full items-center justify-center gap-2 rounded-xl text-lg disabled:opacity-70",disabled:t,type:"submit",children:t?e.jsx(T,{className:"h-5 w-5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:n}),e.jsx(K,{className:"h-5 w-5"})]})}),Le="modulepreload",Ne=function(t){return"/static/"+t},O={},w=function(n,s,d){let r=Promise.resolve();if(s&&s.length>0){let a=function(o){return Promise.all(o.map(m=>Promise.resolve(m).then(f=>({status:"fulfilled",value:f}),f=>({status:"rejected",reason:f}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),h=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));r=a(s.map(o=>{if(o=Ne(o),o in O)return;O[o]=!0;const m=o.endsWith(".css"),f=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${o}"]${f}`))return;const x=document.createElement("link");if(x.rel=m?"stylesheet":Le,m||(x.as="script"),x.crossOrigin="",x.href=o,h&&x.setAttribute("nonce",h),document.head.appendChild(x),m)return new Promise((b,g)=>{x.addEventListener("load",b),x.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${o}`)))})}))}function i(a){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=a,window.dispatchEvent(l),!l.defaultPrevented)throw a}return r.then(a=>{for(const l of a||[])l.status==="rejected"&&i(l.reason);return n().catch(i)})},Ce=({activeTab:t,isAdmin:n=!1,collapsed:s,onToggleCollapsed:d,onNavigate:r,onLogout:i,buildInfo:a})=>{const l=[{id:"dashboard",icon:Q,label:"仪表盘"},{id:"accounts",icon:W,label:"账号管理"},{id:"chat",icon:X,label:"在线聊天"},{id:"cards",icon:ee,label:"卡密库存"},{id:"items",icon:te,label:"商品列表"},{id:"orders",icon:se,label:"订单管理"},{id:"rules",icon:ne,label:"自动化规则"},{id:"notifications",icon:re,label:"通知设置"},...n?[{id:"settings",icon:ae,label:"系统与AI"}]:[]],h=/^\d+\.\d+\.\d+$/.test(a.version)?`v${a.version}`:a.version;return e.jsxs("aside",{className:`fixed inset-y-0 left-0 z-20 flex flex-col border-r border-slate-200/80 bg-white/95 shadow-sidebar backdrop-blur-xl transition-[width] duration-300 ${s?"w-16":"w-64"}`,children:[e.jsxs("div",{className:`flex h-20 items-center border-b border-slate-100 ${s?"justify-center px-2":"gap-3 px-5"}`,children:[e.jsx(F,{sizeClass:"h-10 w-10"}),!s&&e.jsxs("div",{className:"min-w-0 leading-tight",children:[e.jsx("div",{className:"truncate text-base font-black tracking-tight text-slate-950",children:"Ydisks 闲鱼助手"}),e.jsx("div",{className:"mt-1 text-[10px] font-extrabold uppercase tracking-[0.22em] text-sky-600",children:"Operations"})]})]}),e.jsx("nav",{className:`flex-1 space-y-1.5 overflow-y-auto pt-5 ${s?"px-2":"px-3"}`,"aria-label":"主导航",children:l.map(o=>{const m=o.icon,f=t===o.id;return e.jsx(S.Fragment,{children:e.jsxs("button",{type:"button",title:s?o.label:void 0,"aria-label":o.label,"aria-current":f?"page":void 0,onClick:(()=>r(o.id)),className:`group relative flex h-11 w-full items-center rounded-xl transition-colors ${s?"justify-center":"gap-3 px-3.5"} ${f?"bg-brand text-white shadow-brand-active":"text-slate-500 hover:bg-slate-100 hover:text-slate-900"}`,children:[e.jsx(m,{className:`h-[19px] w-[19px] shrink-0 ${f?"text-white":"text-slate-400 group-hover:text-slate-700"}`}),!s&&e.jsx("span",{className:"truncate text-sm font-bold",children:o.label}),f&&!s&&e.jsx("span",{className:"ml-auto h-1.5 w-1.5 rounded-full bg-white/90"})]})},o.id)})}),e.jsxs("div",{children:[e.jsx("div",{title:s?`版本 ${a.version} · ${a.commit}`:void 0,className:`border-y border-slate-100 bg-slate-50/70 py-2.5 ${s?"flex justify-center px-1":"px-6"}`,children:s?e.jsx(k,{className:"h-[18px] w-[18px] text-slate-400","aria-label":`版本 ${a.version}`}):e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-extrabold uppercase tracking-[0.18em] text-slate-400",children:[e.jsx(k,{className:"h-3.5 w-3.5"}),"运行版本"]}),e.jsxs("div",{className:"mt-1 flex items-baseline gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs font-bold text-slate-700",children:h}),e.jsx("span",{className:"truncate font-mono text-[10px] text-slate-400",children:a.commit})]})]})}),e.jsxs("div",{className:`space-y-2 p-2 ${s?"":"p-3"}`,children:[e.jsxs("button",{type:"button",onClick:d,title:s?"展开侧边栏":"收起侧边栏","aria-label":s?"展开侧边栏":"收起侧边栏",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-900 ${s?"justify-center":"gap-3 px-3"}`,children:[s?e.jsx(oe,{className:"h-5 w-5"}):e.jsx(ie,{className:"h-5 w-5"}),!s&&e.jsx("span",{className:"text-sm font-bold",children:"收起侧边栏"})]}),e.jsxs("button",{type:"button",onClick:i,title:s?"退出登录":void 0,"aria-label":"退出登录",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-red-50 hover:text-red-600 ${s?"justify-center":"gap-3 px-3"}`,children:[e.jsx(le,{className:"h-5 w-5"}),!s&&e.jsx("span",{className:"text-sm font-bold",children:"退出登录"})]})]})]})]})},Ee=async t=>D("/health",void 0,t),C=c.lazy(()=>w(()=>import("./Dashboard-MmgsZAic.js"),__vite__mapDeps([0,1,2,3,4,5,6]))),Se=c.lazy(()=>w(()=>import("./AccountList-Bb-tGjAS.js"),__vite__mapDeps([7,1,3,4]))),_e=c.lazy(()=>w(()=>import("./OrderList-BAnpJSM4.js"),__vite__mapDeps([8,1,4,3,2]))),Pe=c.lazy(()=>w(()=>import("./CardList-D43xNKm6.js"),__vite__mapDeps([9,1,4,3]))),ke=c.lazy(()=>w(()=>import("./ItemList-BHJwErgP.js"),__vite__mapDeps([10,1,3,4]))),Ae=c.lazy(()=>w(()=>import("./Settings-DUEkZoEv.js"),__vite__mapDeps([11,1,4]))),Oe=c.lazy(()=>w(()=>import("./Rules-BplaKbZv.js"),__vite__mapDeps([12,1,4,3]))),Re=c.lazy(()=>w(()=>import("./Notifications-Dvclt-gX.js"),__vite__mapDeps([13,1,4]))),Te=c.lazy(()=>w(()=>import("./Chat-DSkOtUaB.js"),__vite__mapDeps([14,1,3,4]))),Ie=()=>e.jsx("div",{className:"flex min-h-[24rem] items-center justify-center",role:"status","aria-label":"正在加载页面",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-brand/20 border-t-brand"})}),De=({activeTab:t,isAdmin:n,deliveryRuleTarget:s,onConfigureDelivery:d,onDeliveryTargetHandled:r})=>{const i=l=>{d({cookieId:l.cookie_id,itemId:l.item_id,requestId:Date.now()})},a=()=>{switch(t){case"dashboard":return e.jsx(C,{});case"accounts":return e.jsx(Se,{});case"chat":return e.jsx(Te,{});case"orders":return e.jsx(_e,{});case"cards":return e.jsx(Pe,{});case"items":return e.jsx(ke,{onConfigureDelivery:i});case"rules":return e.jsx(Oe,{initialDeliveryTarget:s,onDeliveryTargetHandled:r});case"notifications":return e.jsx(Re,{isAdmin:n});case"settings":return n?e.jsx(Ae,{}):e.jsx(C,{});default:return e.jsx(C,{})}};return e.jsx(c.Suspense,{fallback:e.jsx(Ie,{}),children:a()})},$e=({activeTab:t,isAdmin:n,collapsed:s,deliveryRuleTarget:d,onToggleCollapsed:r,onNavigate:i,onLogout:a,onConfigureDelivery:l,onDeliveryTargetHandled:h})=>{const[o,m]=c.useState({version:"dev",commit:"unknown"});return c.useEffect(()=>{const f=new AbortController;return Ee({signal:f.signal}).then(x=>m({version:String(x.version||"dev"),commit:String(x.commit||"unknown")})).catch(x=>{x instanceof DOMException&&x.name}),(()=>f.abort())},[]),e.jsxs("div",{className:"flex min-h-screen bg-canvas text-ink",children:[e.jsx(Ce,{activeTab:t,isAdmin:n,collapsed:s,onToggleCollapsed:r,onNavigate:i,onLogout:a,buildInfo:o}),e.jsxs("main",{className:`h-screen min-w-0 flex-1 overflow-x-hidden overflow-y-auto scroll-smooth transition-[margin] duration-300 ${s?"ml-16":"ml-64"} ${t==="chat"?"p-4 md:p-6":"p-8 md:p-12"}`,children:[e.jsx("div",{className:"fixed top-0 right-0 -z-10 h-[800px] w-[800px] pointer-events-none rounded-full bg-gradient-to-bl from-blue-50 to-transparent opacity-60 blur-[120px]"}),e.jsx("div",{className:`${t==="chat"?"mx-auto max-w-[1680px]":"mx-auto max-w-[1400px] pb-10"}`,children:e.jsx(De,{activeTab:t,isAdmin:n,deliveryRuleTarget:d,onConfigureDelivery:l,onDeliveryTargetHandled:h})})]})]})},V={"/app/dashboard":"dashboard","/app/accounts":"accounts","/app/chat":"chat","/app/orders":"orders","/app/cards":"cards","/app/items":"items","/app/rules":"rules","/app/notifications":"notifications","/app/settings":"settings"},E=Object.fromEntries(Object.entries(V).map(([t,n])=>[n,t])),R=()=>V[window.location.pathname]??"dashboard",ze=()=>{const{isLoggedIn:t,isAdmin:n,signOut:s}=B(),[d,r]=c.useState(R),[i,a]=c.useState(),[l,h]=c.useState(ye);c.useEffect(()=>{const u=()=>r(R());return window.addEventListener("popstate",u),(()=>window.removeEventListener("popstate",u))},[]),c.useEffect(()=>{t&&!n&&d==="settings"&&(window.history.replaceState({},"",E.dashboard),r("dashboard"))},[d,n,t]);const o=u=>{const p=u==="settings"&&!n?"dashboard":u,j=E[p];j!==window.location.pathname&&window.history.pushState({},"",j),r(p)},m=u=>{const p=Object.prototype.hasOwnProperty.call(E,u)?u:"dashboard";o(p)},f=async()=>{try{await s()}catch(u){console.error("退出登录失败",u)}},x=()=>{h(u=>{const p=!u;return ve(p),p})},b=u=>{a(u),o("rules")},g=()=>a(void 0);return t?e.jsx($e,{activeTab:d,isAdmin:n,collapsed:l,deliveryRuleTarget:i,onToggleCollapsed:x,onNavigate:m,onLogout:f,onConfigureDelivery:b,onDeliveryTargetHandled:g}):e.jsx(je,{})},Me=()=>e.jsx(ce,{children:e.jsx(be,{children:e.jsx(ze,{})})}),U=document.getElementById("root");if(!U)throw new Error("Could not find root element to mount to");const Be=H.createRoot(U);Be.render(e.jsx(S.StrictMode,{children:e.jsx(Me,{})}));export{_ as a,Ge as b,Ue as d,D as g,Ve as p};
+const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Dashboard-Di77mWD7.js","assets/react-vendor-C_od1ZSF.js","assets/dateTime-DDi7rqpW.js","assets/contract-COFcZjyb.js","assets/icons-vendor-CvzvbbIV.js","assets/charts-vendor-BxxJOyEX.js","assets/vendor-D-Edl3pr.js","assets/AccountList-Dpo8D419.js","assets/OrderList-DMp8cMZ2.js","assets/CardList-e8gkiR9S.js","assets/ItemList-Di4uiKj1.js","assets/Settings-BKbkBfLj.js","assets/Rules-Dt-wqBt3.js","assets/Notifications-BXiIO06V.js","assets/Chat-CMwR5q9e.js"])))=>i.map(i=>d[i]);
+import{c as S,j as e,r as c,d as H}from"./react-vendor-C_od1ZSF.js";import{L as T,a as P,S as J,U as Y,A as K,b as Q,c as W,M as X,C as ee,B as te,d as se,Z as ne,e as re,f as ae,G as k,g as oe,h as ie,i as le}from"./icons-vendor-CvzvbbIV.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))d(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&d(a)}).observe(document,{childList:!0,subtree:!0});function s(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function d(r){if(r.ep)return;r.ep=!0;const i=s(r);fetch(r.href,i)}})();class ce extends S.Component{constructor(){super(...arguments),this.state={hasError:!1},this.handleReload=()=>{window.location.reload()}}static getDerivedStateFromError(){return{hasError:!0}}render(){const{hasError:n}=this.state,{children:s}=this.props;return n?e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-canvas p-6 text-ink",children:e.jsxs("section",{className:"max-w-md text-center",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"页面暂时无法显示"}),e.jsx("button",{className:"ios-btn-primary mt-6 px-4 py-2",type:"button",onClick:this.handleReload,children:"重新加载"})]})}):s}}const de=3e4,ue=10*6e4;let N=!1;const I=()=>{N||typeof window>"u"||(N=!0,window.dispatchEvent(new Event("auth:logout")),queueMicrotask(()=>{N=!1}))},he=t=>{if(!t)return"";const n=new URLSearchParams;for(const[d,r]of Object.entries(t))r!=null&&n.set(d,String(r));const s=n.toString();return s?`?${s}`:""},L=async(t,n,s={})=>{var o;const d=he(s.params),r=`${n}${d}`,i=$(s.signal,s.timeoutMs??de);let a;try{a=await fetch(r,{method:t,credentials:"include",signal:i.signal,headers:{...s.body===void 0?{}:{"Content-Type":"application/json"}},body:s.body===void 0?void 0:JSON.stringify(s.body)})}catch(m){throw i.signal.aborted?new Error((o=s.signal)!=null&&o.aborted?"请求已取消":"请求超时,请稍后重试"):m}finally{i.cleanup()}const h=(a.headers.get("content-type")||"").includes("application/json");if(!a.ok){a.status===401&&!s.skipAuthLogout&&I();const m=h?await a.json().catch(()=>{}):await a.text().catch(()=>{}),f=z(m,a.status);throw new Error(f)}return h?await a.json():await a.text()},D=async(t,n,s)=>L("GET",t,{params:n,...s}),_=async(t,n,s)=>L("POST",t,{body:n,...s}),Ve=async(t,n,s)=>L("PUT",t,{body:n,...s}),Ue=async(t,n,s)=>L("DELETE",t,{params:n,...s}),Ge=async(t,n,s={})=>{var h;const d=$(s.signal,s.timeoutMs??ue);let r;try{r=await fetch(t,{method:"POST",credentials:"include",signal:d.signal,body:n})}catch(o){throw d.signal.aborted?new Error((h=s.signal)!=null&&h.aborted?"请求已取消":"上传超时,请稍后重试"):o}finally{d.cleanup()}const l=(r.headers.get("content-type")||"").includes("application/json")?await r.json().catch(()=>{}):await r.text().catch(()=>{});if(!r.ok){r.status===401&&I();const o=z(l,r.status),m=new Error(o);throw m.payload=l,m}return l},$=(t,n)=>{const s=new AbortController,d=()=>s.abort(t==null?void 0:t.reason);t!=null&&t.aborted?d():t==null||t.addEventListener("abort",d,{once:!0});const r=globalThis.setTimeout(()=>s.abort(new DOMException("timeout","TimeoutError")),Math.max(1,n));return{signal:s.signal,cleanup:()=>{globalThis.clearTimeout(r),t==null||t.removeEventListener("abort",d)}}},me=t=>{if(typeof t!="object"||t===null)return!1;const n=t;return typeof n.code=="string"&&typeof n.message=="string"},z=(t,n)=>typeof t=="string"?t:me(t)?t.message:`请求失败: ${n}`,fe=async t=>_("/api/v1/session/login",t,{skipAuthLogout:!0}),xe=async t=>_("/api/v1/session/initialize",{password:t},{skipAuthLogout:!0}),pe=async t=>D("/api/v1/session",void 0,t),ge=async()=>_("/api/v1/session/logout",{}),M=c.createContext(void 0),be=({children:t})=>{const[n,s]=c.useState(!1),[d,r]=c.useState(!1),[i,a]=c.useState(!0),[l,h]=c.useState(!1),o=()=>{s(!1),r(!1)};c.useEffect(()=>{const b=new AbortController;let g=!0;pe({signal:b.signal}).then(p=>{if(g){if((p==null?void 0:p.initialized)===!1){h(!0),o();return}h(!1),p!=null&&p.authenticated?(s(!0),r(p.is_admin===!0)):o()}}).catch(p=>{!g||p instanceof DOMException&&p.name==="AbortError"||(h(!1),o())}).finally(()=>{g&&a(!1)});const u=()=>o();return window.addEventListener("auth:logout",u),(()=>{g=!1,b.abort(),window.removeEventListener("auth:logout",u)})},[]);const m=async b=>{const g=await fe(b);return g.success&&(h(!1),s(!0),r(g.is_admin===!0)),g},f=async b=>{const g=await xe(b);return g.success&&(h(!1),s(!0),r(g.is_admin===!0)),g},x=async()=>{try{await ge()}finally{o()}};return e.jsx(M.Provider,{value:{checkingAuth:i,isLoggedIn:n,isAdmin:d,needsInit:l,signIn:m,initialize:f,signOut:x},children:t})},B=()=>{const t=c.useContext(M);if(!t)throw new Error("useSession 必须在 SessionProvider 内使用");return t},q="ydisks.sidebar.v1",ye=()=>{try{return window.localStorage.getItem(q)==="collapsed"}catch{return!1}},ve=t=>{try{window.localStorage.setItem(q,t?"collapsed":"expanded")}catch{}},we=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),F=({sizeClass:t="w-12 h-12",logoClassName:n="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23.51 12.25 L 27.29 10.34 L 31.54 8.78 L 36.33 7.56 L 41.84 6.69 L 48.52 6.17 L 60.00 6.00 L 71.48 6.17 L 78.16 6.69 L 83.67 7.56 L 88.46 8.78 L 92.71 10.34 L 96.49 12.25 L 99.87 14.52 L 102.86 17.14 L 105.48 20.13 L 107.75 23.51 L 109.66 27.29 L 111.22 31.54 L 112.44 36.33 L 113.31 41.84 L 113.83 48.52 Z",fill:"url(#login-squircle-gradient)"})]}),e.jsx("div",{className:"relative z-10 flex items-center justify-center w-full h-full",children:e.jsx(we,{className:n})})]})]}),je=()=>{const{checkingAuth:t,needsInit:n,signIn:s,initialize:d}=B(),[r,i]=c.useState(""),[a,l]=c.useState(""),[h,o]=c.useState(""),[m,f]=c.useState(""),[x,b]=c.useState(!1),[g,u]=c.useState(""),p=async y=>{y.preventDefault(),b(!0),u("");try{const v=await s({username:r,password:a});v.success||u(v.message||"登录失败")}catch(v){u(v instanceof Error&&v.message||"登录失败")}finally{b(!1)}},j=async y=>{if(y.preventDefault(),u(""),h.length<8){u("密码至少需要 8 个字符");return}if(h!==m){u("两次输入的密码不一致");return}b(!0);try{const v=await d(h);if(!v.success){u(v.message||"初始化失败,请重试");return}o(""),f("")}catch(v){u(v instanceof Error&&v.message||"初始化失败,请重试")}finally{b(!1)}};if(t)return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-surface","aria-label":"正在校验会话",children:e.jsx(T,{className:"h-8 w-8 animate-spin text-brand"})});const G=n?"首次设置管理员密码":"欢迎回来",Z=n?"设置完成后会自动进入系统,管理员账号为 admin。":"Ydisks闲鱼助手 · 自动发货与管家系统";return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-canvas p-4 font-sans",children:e.jsxs("section",{className:"w-full max-w-lg rounded-xl border border-white bg-white/80 p-8 shadow-panel backdrop-blur-3xl md:p-12",children:[e.jsxs("header",{className:"mb-8 text-center",children:[e.jsx("div",{className:"mx-auto mb-6 flex justify-center",children:e.jsx(F,{sizeClass:"h-24 w-24"})}),e.jsx("h1",{className:"text-3xl font-extrabold text-gray-900",children:G}),e.jsx("p",{className:"mt-2 font-medium text-gray-600",children:Z})]}),n?e.jsxs("form",{className:"space-y-5",onSubmit:j,children:[e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"设置管理员密码"}),e.jsx(P,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{autoFocus:!0,className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(y=>o(y.target.value)),placeholder:"设置管理员密码(至少 8 个字符)",type:"password",value:h})]}),e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"确认管理员密码"}),e.jsx(J,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(y=>f(y.target.value)),placeholder:"再次输入密码",type:"password",value:m})]}),e.jsx(A,{submitting:x,text:"设置密码并进入系统"})]}):e.jsxs("form",{className:"space-y-5",onSubmit:p,children:[e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"管理员账号"}),e.jsx(Y,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{autoFocus:!0,className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(y=>i(y.target.value)),placeholder:"管理员账号",type:"text",value:r})]}),e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:"管理员密码"}),e.jsx(P,{className:"absolute left-5 top-1/2 h-5 w-5 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"ios-input h-14 w-full rounded-xl py-4 pl-14 pr-6",onChange:(y=>l(y.target.value)),placeholder:"密码",type:"password",value:a})]}),e.jsx(A,{submitting:x,text:"立即登录"})]}),g?e.jsx("p",{className:"mt-5 rounded-xl bg-red-50 p-3 text-center text-sm font-medium text-red-600",children:g}):null]})})},A=({submitting:t,text:n})=>e.jsx("button",{className:"ios-btn-primary flex h-14 w-full items-center justify-center gap-2 rounded-xl text-lg disabled:opacity-70",disabled:t,type:"submit",children:t?e.jsx(T,{className:"h-5 w-5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:n}),e.jsx(K,{className:"h-5 w-5"})]})}),Le="modulepreload",Ne=function(t){return"/static/"+t},O={},w=function(n,s,d){let r=Promise.resolve();if(s&&s.length>0){let a=function(o){return Promise.all(o.map(m=>Promise.resolve(m).then(f=>({status:"fulfilled",value:f}),f=>({status:"rejected",reason:f}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),h=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));r=a(s.map(o=>{if(o=Ne(o),o in O)return;O[o]=!0;const m=o.endsWith(".css"),f=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${o}"]${f}`))return;const x=document.createElement("link");if(x.rel=m?"stylesheet":Le,m||(x.as="script"),x.crossOrigin="",x.href=o,h&&x.setAttribute("nonce",h),document.head.appendChild(x),m)return new Promise((b,g)=>{x.addEventListener("load",b),x.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${o}`)))})}))}function i(a){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=a,window.dispatchEvent(l),!l.defaultPrevented)throw a}return r.then(a=>{for(const l of a||[])l.status==="rejected"&&i(l.reason);return n().catch(i)})},Ce=({activeTab:t,isAdmin:n=!1,collapsed:s,onToggleCollapsed:d,onNavigate:r,onLogout:i,buildInfo:a})=>{const l=[{id:"dashboard",icon:Q,label:"仪表盘"},{id:"accounts",icon:W,label:"账号管理"},{id:"chat",icon:X,label:"在线聊天"},{id:"cards",icon:ee,label:"卡密库存"},{id:"items",icon:te,label:"商品列表"},{id:"orders",icon:se,label:"订单管理"},{id:"rules",icon:ne,label:"自动化规则"},{id:"notifications",icon:re,label:"通知设置"},...n?[{id:"settings",icon:ae,label:"系统与AI"}]:[]],h=/^\d+\.\d+\.\d+$/.test(a.version)?`v${a.version}`:a.version;return e.jsxs("aside",{className:`fixed inset-y-0 left-0 z-20 flex flex-col border-r border-slate-200/80 bg-white/95 shadow-sidebar backdrop-blur-xl transition-[width] duration-300 ${s?"w-16":"w-64"}`,children:[e.jsxs("div",{className:`flex h-20 items-center border-b border-slate-100 ${s?"justify-center px-2":"gap-3 px-5"}`,children:[e.jsx(F,{sizeClass:"h-10 w-10"}),!s&&e.jsxs("div",{className:"min-w-0 leading-tight",children:[e.jsx("div",{className:"truncate text-base font-black tracking-tight text-slate-950",children:"Ydisks 闲鱼助手"}),e.jsx("div",{className:"mt-1 text-[10px] font-extrabold uppercase tracking-[0.22em] text-sky-600",children:"Operations"})]})]}),e.jsx("nav",{className:`flex-1 space-y-1.5 overflow-y-auto pt-5 ${s?"px-2":"px-3"}`,"aria-label":"主导航",children:l.map(o=>{const m=o.icon,f=t===o.id;return e.jsx(S.Fragment,{children:e.jsxs("button",{type:"button",title:s?o.label:void 0,"aria-label":o.label,"aria-current":f?"page":void 0,onClick:(()=>r(o.id)),className:`group relative flex h-11 w-full items-center rounded-xl transition-colors ${s?"justify-center":"gap-3 px-3.5"} ${f?"bg-brand text-white shadow-brand-active":"text-slate-500 hover:bg-slate-100 hover:text-slate-900"}`,children:[e.jsx(m,{className:`h-[19px] w-[19px] shrink-0 ${f?"text-white":"text-slate-400 group-hover:text-slate-700"}`}),!s&&e.jsx("span",{className:"truncate text-sm font-bold",children:o.label}),f&&!s&&e.jsx("span",{className:"ml-auto h-1.5 w-1.5 rounded-full bg-white/90"})]})},o.id)})}),e.jsxs("div",{children:[e.jsx("div",{title:s?`版本 ${a.version} · ${a.commit}`:void 0,className:`border-y border-slate-100 bg-slate-50/70 py-2.5 ${s?"flex justify-center px-1":"px-6"}`,children:s?e.jsx(k,{className:"h-[18px] w-[18px] text-slate-400","aria-label":`版本 ${a.version}`}):e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-extrabold uppercase tracking-[0.18em] text-slate-400",children:[e.jsx(k,{className:"h-3.5 w-3.5"}),"运行版本"]}),e.jsxs("div",{className:"mt-1 flex items-baseline gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs font-bold text-slate-700",children:h}),e.jsx("span",{className:"truncate font-mono text-[10px] text-slate-400",children:a.commit})]})]})}),e.jsxs("div",{className:`space-y-2 p-2 ${s?"":"p-3"}`,children:[e.jsxs("button",{type:"button",onClick:d,title:s?"展开侧边栏":"收起侧边栏","aria-label":s?"展开侧边栏":"收起侧边栏",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-900 ${s?"justify-center":"gap-3 px-3"}`,children:[s?e.jsx(oe,{className:"h-5 w-5"}):e.jsx(ie,{className:"h-5 w-5"}),!s&&e.jsx("span",{className:"text-sm font-bold",children:"收起侧边栏"})]}),e.jsxs("button",{type:"button",onClick:i,title:s?"退出登录":void 0,"aria-label":"退出登录",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-red-50 hover:text-red-600 ${s?"justify-center":"gap-3 px-3"}`,children:[e.jsx(le,{className:"h-5 w-5"}),!s&&e.jsx("span",{className:"text-sm font-bold",children:"退出登录"})]})]})]})]})},Ee=async t=>D("/health",void 0,t),C=c.lazy(()=>w(()=>import("./Dashboard-Di77mWD7.js"),__vite__mapDeps([0,1,2,3,4,5,6]))),Se=c.lazy(()=>w(()=>import("./AccountList-Dpo8D419.js"),__vite__mapDeps([7,1,3,4]))),_e=c.lazy(()=>w(()=>import("./OrderList-DMp8cMZ2.js"),__vite__mapDeps([8,1,4,3,2]))),Pe=c.lazy(()=>w(()=>import("./CardList-e8gkiR9S.js"),__vite__mapDeps([9,1,4,3]))),ke=c.lazy(()=>w(()=>import("./ItemList-Di4uiKj1.js"),__vite__mapDeps([10,1,3,4]))),Ae=c.lazy(()=>w(()=>import("./Settings-BKbkBfLj.js"),__vite__mapDeps([11,1,4]))),Oe=c.lazy(()=>w(()=>import("./Rules-Dt-wqBt3.js"),__vite__mapDeps([12,1,4,3]))),Re=c.lazy(()=>w(()=>import("./Notifications-BXiIO06V.js"),__vite__mapDeps([13,1,4]))),Te=c.lazy(()=>w(()=>import("./Chat-CMwR5q9e.js"),__vite__mapDeps([14,1,3,4]))),Ie=()=>e.jsx("div",{className:"flex min-h-[24rem] items-center justify-center",role:"status","aria-label":"正在加载页面",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-brand/20 border-t-brand"})}),De=({activeTab:t,isAdmin:n,deliveryRuleTarget:s,onConfigureDelivery:d,onDeliveryTargetHandled:r})=>{const i=l=>{d({cookieId:l.cookie_id,itemId:l.item_id,requestId:Date.now()})},a=()=>{switch(t){case"dashboard":return e.jsx(C,{});case"accounts":return e.jsx(Se,{});case"chat":return e.jsx(Te,{});case"orders":return e.jsx(_e,{});case"cards":return e.jsx(Pe,{});case"items":return e.jsx(ke,{onConfigureDelivery:i});case"rules":return e.jsx(Oe,{initialDeliveryTarget:s,onDeliveryTargetHandled:r});case"notifications":return e.jsx(Re,{isAdmin:n});case"settings":return n?e.jsx(Ae,{}):e.jsx(C,{});default:return e.jsx(C,{})}};return e.jsx(c.Suspense,{fallback:e.jsx(Ie,{}),children:a()})},$e=({activeTab:t,isAdmin:n,collapsed:s,deliveryRuleTarget:d,onToggleCollapsed:r,onNavigate:i,onLogout:a,onConfigureDelivery:l,onDeliveryTargetHandled:h})=>{const[o,m]=c.useState({version:"dev",commit:"unknown"});return c.useEffect(()=>{const f=new AbortController;return Ee({signal:f.signal}).then(x=>m({version:String(x.version||"dev"),commit:String(x.commit||"unknown")})).catch(x=>{x instanceof DOMException&&x.name}),(()=>f.abort())},[]),e.jsxs("div",{className:"flex min-h-screen bg-canvas text-ink",children:[e.jsx(Ce,{activeTab:t,isAdmin:n,collapsed:s,onToggleCollapsed:r,onNavigate:i,onLogout:a,buildInfo:o}),e.jsxs("main",{className:`h-screen min-w-0 flex-1 overflow-x-hidden overflow-y-auto scroll-smooth transition-[margin] duration-300 ${s?"ml-16":"ml-64"} ${t==="chat"?"p-4 md:p-6":"p-8 md:p-12"}`,children:[e.jsx("div",{className:"fixed top-0 right-0 -z-10 h-[800px] w-[800px] pointer-events-none rounded-full bg-gradient-to-bl from-blue-50 to-transparent opacity-60 blur-[120px]"}),e.jsx("div",{className:`${t==="chat"?"mx-auto max-w-[1680px]":"mx-auto max-w-[1400px] pb-10"}`,children:e.jsx(De,{activeTab:t,isAdmin:n,deliveryRuleTarget:d,onConfigureDelivery:l,onDeliveryTargetHandled:h})})]})]})},V={"/app/dashboard":"dashboard","/app/accounts":"accounts","/app/chat":"chat","/app/orders":"orders","/app/cards":"cards","/app/items":"items","/app/rules":"rules","/app/notifications":"notifications","/app/settings":"settings"},E=Object.fromEntries(Object.entries(V).map(([t,n])=>[n,t])),R=()=>V[window.location.pathname]??"dashboard",ze=()=>{const{isLoggedIn:t,isAdmin:n,signOut:s}=B(),[d,r]=c.useState(R),[i,a]=c.useState(),[l,h]=c.useState(ye);c.useEffect(()=>{const u=()=>r(R());return window.addEventListener("popstate",u),(()=>window.removeEventListener("popstate",u))},[]),c.useEffect(()=>{t&&!n&&d==="settings"&&(window.history.replaceState({},"",E.dashboard),r("dashboard"))},[d,n,t]);const o=u=>{const p=u==="settings"&&!n?"dashboard":u,j=E[p];j!==window.location.pathname&&window.history.pushState({},"",j),r(p)},m=u=>{const p=Object.prototype.hasOwnProperty.call(E,u)?u:"dashboard";o(p)},f=async()=>{try{await s()}catch(u){console.error("退出登录失败",u)}},x=()=>{h(u=>{const p=!u;return ve(p),p})},b=u=>{a(u),o("rules")},g=()=>a(void 0);return t?e.jsx($e,{activeTab:d,isAdmin:n,collapsed:l,deliveryRuleTarget:i,onToggleCollapsed:x,onNavigate:m,onLogout:f,onConfigureDelivery:b,onDeliveryTargetHandled:g}):e.jsx(je,{})},Me=()=>e.jsx(ce,{children:e.jsx(be,{children:e.jsx(ze,{})})}),U=document.getElementById("root");if(!U)throw new Error("Could not find root element to mount to");const Be=H.createRoot(U);Be.render(e.jsx(S.StrictMode,{children:e.jsx(Me,{})}));export{_ as a,Ge as b,Ue as d,D as g,Ve as p};
diff --git a/internal/webui/static/assets/index-DjsVeBHO.css b/internal/webui/static/assets/index-DjsVeBHO.css
new file mode 100644
index 0000000..8332198
--- /dev/null
+++ b/internal/webui/static/assets/index-DjsVeBHO.css
@@ -0,0 +1 @@
+*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.\!container{width:100%!important}.container{width:100%}@media(min-width:640px){.\!container{max-width:640px!important}.container{max-width:640px}}@media(min-width:768px){.\!container{max-width:768px!important}.container{max-width:768px}}@media(min-width:1024px){.\!container{max-width:1024px!important}.container{max-width:1024px}}@media(min-width:1280px){.\!container{max-width:1280px!important}.container{max-width:1280px}}@media(min-width:1536px){.\!container{max-width:1536px!important}.container{max-width:1536px}}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}.pointer-events-none{pointer-events:none}.visible{visibility:visible}.collapse{visibility:collapse}.static{position:static}.fixed{position:fixed}.absolute{position:absolute}.relative{position:relative}.sticky{position:sticky}.-inset-1{top:-.25rem;right:-.25rem;bottom:-.25rem;left:-.25rem}.inset-0{top:0;right:0;bottom:0;left:0}.inset-y-0{top:0;bottom:0}.-bottom-1{bottom:-.25rem}.-right-1{right:-.25rem}.-right-12{right:-3rem}.-right-6{right:-1.5rem}.-top-16{top:-4rem}.-top-6{top:-1.5rem}.bottom-10{bottom:2.5rem}.bottom-11{bottom:2.75rem}.bottom-8{bottom:2rem}.left-0{left:0}.left-0\.5{left:.125rem}.left-1{left:.25rem}.left-1\.5{left:.375rem}.left-1\/2{left:50%}.left-3{left:.75rem}.left-4{left:1rem}.left-5{left:1.25rem}.right-0{right:0}.right-10{right:2.5rem}.right-2{right:.5rem}.right-3{right:.75rem}.right-4{right:1rem}.top-0{top:0}.top-0\.5{top:.125rem}.top-1{top:.25rem}.top-1\.5{top:.375rem}.top-1\/2{top:50%}.top-2{top:.5rem}.top-4{top:1rem}.top-\[calc\(100\%\+6px\)\]{top:calc(100% + 6px)}.-z-10{z-index:-10}.z-10{z-index:10}.z-20{z-index:20}.z-30{z-index:30}.z-40{z-index:40}.z-\[10000\]{z-index:10000}.order-1{order:1}.order-2{order:2}.col-span-2{grid-column:span 2 / span 2}.col-span-full{grid-column:1 / -1}.m-2{margin:.5rem}.mx-0\.5{margin-left:.125rem;margin-right:.125rem}.mx-auto{margin-left:auto;margin-right:auto}.mb-1{margin-bottom:.25rem}.mb-1\.5{margin-bottom:.375rem}.mb-10{margin-bottom:2.5rem}.mb-2{margin-bottom:.5rem}.mb-2\.5{margin-bottom:.625rem}.mb-3{margin-bottom:.75rem}.mb-4{margin-bottom:1rem}.mb-5{margin-bottom:1.25rem}.mb-6{margin-bottom:1.5rem}.mb-8{margin-bottom:2rem}.ml-1{margin-left:.25rem}.ml-16{margin-left:4rem}.ml-64{margin-left:16rem}.ml-auto{margin-left:auto}.mr-2{margin-right:.5rem}.mr-3{margin-right:.75rem}.mt-0\.5{margin-top:.125rem}.mt-1{margin-top:.25rem}.mt-1\.5{margin-top:.375rem}.mt-2{margin-top:.5rem}.mt-3{margin-top:.75rem}.mt-4{margin-top:1rem}.mt-5{margin-top:1.25rem}.mt-6{margin-top:1.5rem}.mt-auto{margin-top:auto}.line-clamp-1{overflow:hidden;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:1}.line-clamp-2{overflow:hidden;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2}.line-clamp-3{overflow:hidden;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3}.block{display:block}.inline-block{display:inline-block}.inline{display:inline}.flex{display:flex}.inline-flex{display:inline-flex}.table{display:table}.grid{display:grid}.contents{display:contents}.hidden{display:none}.aspect-square{aspect-ratio:1 / 1}.h-1\.5{height:.375rem}.h-10{height:2.5rem}.h-11{height:2.75rem}.h-12{height:3rem}.h-14{height:3.5rem}.h-16{height:4rem}.h-2{height:.5rem}.h-2\.5{height:.625rem}.h-20{height:5rem}.h-24{height:6rem}.h-28{height:7rem}.h-3{height:.75rem}.h-3\.5{height:.875rem}.h-32{height:8rem}.h-36{height:9rem}.h-4{height:1rem}.h-40{height:10rem}.h-48{height:12rem}.h-5{height:1.25rem}.h-6{height:1.5rem}.h-7{height:1.75rem}.h-8{height:2rem}.h-80{height:20rem}.h-9{height:2.25rem}.h-\[18px\]{height:18px}.h-\[19px\]{height:19px}.h-\[280px\]{height:280px}.h-\[300px\]{height:300px}.h-\[350px\]{height:350px}.h-\[48px\]{height:48px}.h-\[800px\]{height:800px}.h-\[calc\(100vh-4rem\)\]{height:calc(100vh - 4rem)}.h-auto{height:auto}.h-fit{height:-moz-fit-content;height:fit-content}.h-full{height:100%}.h-screen{height:100vh}.max-h-32{max-height:8rem}.max-h-44{max-height:11rem}.max-h-48{max-height:12rem}.max-h-64{max-height:16rem}.max-h-72{max-height:18rem}.max-h-80{max-height:20rem}.max-h-\[380px\]{max-height:380px}.max-h-\[400px\]{max-height:400px}.max-h-\[420px\]{max-height:420px}.max-h-\[min\(64vh\,28rem\)\]{max-height:min(64vh,28rem)}.min-h-0{min-height:0px}.min-h-12{min-height:3rem}.min-h-36{min-height:9rem}.min-h-56{min-height:14rem}.min-h-64{min-height:16rem}.min-h-\[120px\]{min-height:120px}.min-h-\[150px\]{min-height:150px}.min-h-\[24rem\]{min-height:24rem}.min-h-\[400px\]{min-height:400px}.min-h-\[42px\]{min-height:42px}.min-h-\[46px\]{min-height:46px}.min-h-\[560px\]{min-height:560px}.min-h-screen{min-height:100vh}.w-1\.5{width:.375rem}.w-10{width:2.5rem}.w-11{width:2.75rem}.w-12{width:3rem}.w-14{width:3.5rem}.w-16{width:4rem}.w-2{width:.5rem}.w-2\.5{width:.625rem}.w-20{width:5rem}.w-24{width:6rem}.w-28{width:7rem}.w-3{width:.75rem}.w-3\.5{width:.875rem}.w-32{width:8rem}.w-36{width:9rem}.w-4{width:1rem}.w-48{width:12rem}.w-5{width:1.25rem}.w-6{width:1.5rem}.w-64{width:16rem}.w-7{width:1.75rem}.w-8{width:2rem}.w-9{width:2.25rem}.w-\[18px\]{width:18px}.w-\[19\%\]{width:19%}.w-\[19px\]{width:19px}.w-\[23\%\]{width:23%}.w-\[27\%\]{width:27%}.w-\[360px\]{width:360px}.w-\[7\%\]{width:7%}.w-\[8\%\]{width:8%}.w-\[800px\]{width:800px}.w-\[9\%\]{width:9%}.w-fit{width:-moz-fit-content;width:fit-content}.w-full{width:100%}.w-px{width:1px}.min-w-0{min-width:0px}.min-w-5{min-width:1.25rem}.min-w-9{min-width:2.25rem}.min-w-\[150px\]{min-width:150px}.min-w-\[200px\]{min-width:200px}.min-w-\[210px\]{min-width:210px}.min-w-\[260px\]{min-width:260px}.min-w-\[760px\]{min-width:760px}.max-w-36{max-width:9rem}.max-w-64{max-width:16rem}.max-w-6xl{max-width:72rem}.max-w-72{max-width:18rem}.max-w-\[12rem\]{max-width:12rem}.max-w-\[1400px\]{max-width:1400px}.max-w-\[15rem\]{max-width:15rem}.max-w-\[1680px\]{max-width:1680px}.max-w-\[240px\]{max-width:240px}.max-w-\[260px\]{max-width:260px}.max-w-\[280px\]{max-width:280px}.max-w-\[340px\]{max-width:340px}.max-w-\[400px\]{max-width:400px}.max-w-\[72\%\]{max-width:72%}.max-w-\[80px\]{max-width:80px}.max-w-\[82\%\]{max-width:82%}.max-w-full{max-width:100%}.max-w-lg{max-width:32rem}.max-w-md{max-width:28rem}.flex-1{flex:1 1 0%}.flex-shrink-0{flex-shrink:0}.shrink{flex-shrink:1}.shrink-0{flex-shrink:0}.table-fixed{table-layout:fixed}.border-collapse{border-collapse:collapse}.-translate-x-1\/2{--tw-translate-x: -50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-translate-y-1\/2{--tw-translate-y: -50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-0{--tw-translate-x: 0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-1{--tw-translate-x: .25rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-5{--tw-translate-x: 1.25rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-6{--tw-translate-x: 1.5rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-7{--tw-translate-x: 1.75rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rotate-180{--tw-rotate: 180deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes pulse{50%{opacity:.5}}@keyframes spin{to{transform:rotate(360deg)}}.cursor-pointer{cursor:pointer}.resize-none{resize:none}.resize-y{resize:vertical}.list-inside{list-style-position:inside}.list-decimal{list-style-type:decimal}.list-disc{list-style-type:disc}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.grid-cols-8{grid-template-columns:repeat(8,minmax(0,1fr))}.grid-cols-\[320px_minmax\(0\,1fr\)\]{grid-template-columns:320px minmax(0,1fr)}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-start{align-items:flex-start}.items-end{align-items:flex-end}.items-center{align-items:center}.items-baseline{align-items:baseline}.justify-start{justify-content:flex-start}.justify-end{justify-content:flex-end}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-0\.5{gap:.125rem}.gap-1{gap:.25rem}.gap-1\.5{gap:.375rem}.gap-2{gap:.5rem}.gap-2\.5{gap:.625rem}.gap-3{gap:.75rem}.gap-4{gap:1rem}.gap-5{gap:1.25rem}.gap-6{gap:1.5rem}.gap-8{gap:2rem}.space-y-0\.5>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.125rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.125rem * var(--tw-space-y-reverse))}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.25rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem * var(--tw-space-y-reverse))}.space-y-1\.5>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.375rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.375rem * var(--tw-space-y-reverse))}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.5rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.5rem * var(--tw-space-y-reverse))}.space-y-3>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.75rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.75rem * var(--tw-space-y-reverse))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem * var(--tw-space-y-reverse))}.space-y-5>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1.25rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1.25rem * var(--tw-space-y-reverse))}.space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1.5rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1.5rem * var(--tw-space-y-reverse))}.space-y-8>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(2rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(2rem * var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse: 0;border-top-width:calc(1px * calc(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px * var(--tw-divide-y-reverse))}.divide-gray-100>:not([hidden])~:not([hidden]){--tw-divide-opacity: 1;border-color:rgb(var(--color-neutral-100) / var(--tw-divide-opacity, 1))}.divide-gray-50>:not([hidden])~:not([hidden]){--tw-divide-opacity: 1;border-color:rgb(var(--color-neutral-50) / var(--tw-divide-opacity, 1))}.self-start{align-self:flex-start}.self-center{align-self:center}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.overflow-x-hidden{overflow-x:hidden}.overscroll-contain{overscroll-behavior:contain}.scroll-smooth{scroll-behavior:smooth}.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.whitespace-nowrap{white-space:nowrap}.break-words{overflow-wrap:break-word}.break-all{word-break:break-all}.rounded{border-radius:6px}.rounded-2xl,.rounded-3xl{border-radius:10px}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:7px}.rounded-md{border-radius:6px}.rounded-xl{border-radius:8px}.rounded-bl-md{border-bottom-left-radius:6px}.rounded-br-md{border-bottom-right-radius:6px}.border{border-width:1px}.border-0{border-width:0px}.border-2{border-width:2px}.border-4{border-width:4px}.border-y{border-top-width:1px;border-bottom-width:1px}.border-b{border-bottom-width:1px}.border-b-2{border-bottom-width:2px}.border-r{border-right-width:1px}.border-t{border-top-width:1px}.border-dashed{border-style:dashed}.border-none{border-style:none}.border-amber-100{--tw-border-opacity: 1;border-color:rgb(var(--color-warning-100) / var(--tw-border-opacity, 1))}.border-amber-200{--tw-border-opacity: 1;border-color:rgb(var(--color-warning-200) / var(--tw-border-opacity, 1))}.border-amber-500{--tw-border-opacity: 1;border-color:rgb(var(--color-warning-500) / var(--tw-border-opacity, 1))}.border-blue-100{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-100) / var(--tw-border-opacity, 1))}.border-blue-200{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-200) / var(--tw-border-opacity, 1))}.border-blue-500{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-500) / var(--tw-border-opacity, 1))}.border-blue-600{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-600) / var(--tw-border-opacity, 1))}.border-brand{--tw-border-opacity: 1;border-color:rgb(var(--color-brand) / var(--tw-border-opacity, 1))}.border-brand\/20{border-color:rgb(var(--color-brand) / .2)}.border-emerald-100{--tw-border-opacity: 1;border-color:rgb(var(--color-success-100) / var(--tw-border-opacity, 1))}.border-emerald-500{--tw-border-opacity: 1;border-color:rgb(var(--color-success-500) / var(--tw-border-opacity, 1))}.border-gray-100{--tw-border-opacity: 1;border-color:rgb(var(--color-neutral-100) / var(--tw-border-opacity, 1))}.border-gray-200{--tw-border-opacity: 1;border-color:rgb(var(--color-neutral-200) / var(--tw-border-opacity, 1))}.border-gray-300{--tw-border-opacity: 1;border-color:rgb(var(--color-neutral-300) / var(--tw-border-opacity, 1))}.border-gray-50{--tw-border-opacity: 1;border-color:rgb(var(--color-neutral-50) / var(--tw-border-opacity, 1))}.border-green-200{--tw-border-opacity: 1;border-color:rgb(var(--color-success-200) / var(--tw-border-opacity, 1))}.border-purple-100{--tw-border-opacity: 1;border-color:rgb(var(--color-accent-100) / var(--tw-border-opacity, 1))}.border-red-100{--tw-border-opacity: 1;border-color:rgb(var(--color-danger-100) / var(--tw-border-opacity, 1))}.border-red-200{--tw-border-opacity: 1;border-color:rgb(var(--color-danger-200) / var(--tw-border-opacity, 1))}.border-sky-100{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-100) / var(--tw-border-opacity, 1))}.border-sky-200{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-200) / var(--tw-border-opacity, 1))}.border-sky-500{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-500) / var(--tw-border-opacity, 1))}.border-slate-100{--tw-border-opacity: 1;border-color:rgb(var(--color-slate-100) / var(--tw-border-opacity, 1))}.border-slate-200{--tw-border-opacity: 1;border-color:rgb(var(--color-slate-200) / var(--tw-border-opacity, 1))}.border-slate-200\/80{border-color:rgb(var(--color-slate-200) / .8)}.border-transparent{border-color:var(--color-transparent)}.border-white{--tw-border-opacity: 1;border-color:rgb(var(--color-white) / var(--tw-border-opacity, 1))}.border-white\/10{border-color:rgb(var(--color-white) / .1)}.border-white\/80{border-color:rgb(var(--color-white) / .8)}.border-t-brand{--tw-border-opacity: 1;border-top-color:rgb(var(--color-brand) / var(--tw-border-opacity, 1))}.bg-amber-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-warning-100) / var(--tw-bg-opacity, 1))}.bg-amber-100\/70{background-color:rgb(var(--color-warning-100) / .7)}.bg-amber-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-warning-50) / var(--tw-bg-opacity, 1))}.bg-amber-50\/60{background-color:rgb(var(--color-warning-50) / .6)}.bg-amber-50\/70{background-color:rgb(var(--color-warning-50) / .7)}.bg-amber-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-warning-500) / var(--tw-bg-opacity, 1))}.bg-black{--tw-bg-opacity: 1;background-color:rgb(var(--color-black) / var(--tw-bg-opacity, 1))}.bg-black\/50{background-color:rgb(var(--color-black) / .5)}.bg-blue-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-100) / var(--tw-bg-opacity, 1))}.bg-blue-100\/70{background-color:rgb(var(--color-brand-100) / .7)}.bg-blue-400{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-400) / var(--tw-bg-opacity, 1))}.bg-blue-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-50) / var(--tw-bg-opacity, 1))}.bg-blue-50\/40{background-color:rgb(var(--color-brand-50) / .4)}.bg-blue-50\/50{background-color:rgb(var(--color-brand-50) / .5)}.bg-blue-50\/60{background-color:rgb(var(--color-brand-50) / .6)}.bg-blue-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-500) / var(--tw-bg-opacity, 1))}.bg-blue-500\/20{background-color:rgb(var(--color-brand-500) / .2)}.bg-blue-600{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-600) / var(--tw-bg-opacity, 1))}.bg-brand{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand) / var(--tw-bg-opacity, 1))}.bg-canvas{--tw-bg-opacity: 1;background-color:rgb(var(--color-canvas) / var(--tw-bg-opacity, 1))}.bg-danger-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-danger-500) / var(--tw-bg-opacity, 1))}.bg-emerald-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-100) / var(--tw-bg-opacity, 1))}.bg-emerald-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-50) / var(--tw-bg-opacity, 1))}.bg-emerald-50\/60{background-color:rgb(var(--color-success-50) / .6)}.bg-emerald-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-500) / var(--tw-bg-opacity, 1))}.bg-emerald-600{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-600) / var(--tw-bg-opacity, 1))}.bg-gray-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-100) / var(--tw-bg-opacity, 1))}.bg-gray-100\/50{background-color:rgb(var(--color-neutral-100) / .5)}.bg-gray-200{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-200) / var(--tw-bg-opacity, 1))}.bg-gray-200\/50{background-color:rgb(var(--color-neutral-200) / .5)}.bg-gray-300{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-300) / var(--tw-bg-opacity, 1))}.bg-gray-400{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-400) / var(--tw-bg-opacity, 1))}.bg-gray-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-50) / var(--tw-bg-opacity, 1))}.bg-gray-50\/70{background-color:rgb(var(--color-neutral-50) / .7)}.bg-gray-50\/80{background-color:rgb(var(--color-neutral-50) / .8)}.bg-gray-900{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-900) / var(--tw-bg-opacity, 1))}.bg-green-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-100) / var(--tw-bg-opacity, 1))}.bg-green-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-50) / var(--tw-bg-opacity, 1))}.bg-green-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-500) / var(--tw-bg-opacity, 1))}.bg-orange-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-warning-100) / var(--tw-bg-opacity, 1))}.bg-orange-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-warning-500) / var(--tw-bg-opacity, 1))}.bg-pink-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-accent-50) / var(--tw-bg-opacity, 1))}.bg-purple-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-accent-100) / var(--tw-bg-opacity, 1))}.bg-purple-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-accent-50) / var(--tw-bg-opacity, 1))}.bg-purple-50\/50{background-color:rgb(var(--color-accent-50) / .5)}.bg-purple-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-accent-500) / var(--tw-bg-opacity, 1))}.bg-purple-600{--tw-bg-opacity: 1;background-color:rgb(var(--color-accent-600) / var(--tw-bg-opacity, 1))}.bg-red-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-danger-100) / var(--tw-bg-opacity, 1))}.bg-red-200\/35{background-color:rgb(var(--color-danger-200) / .35)}.bg-red-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-danger-50) / var(--tw-bg-opacity, 1))}.bg-red-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-danger-500) / var(--tw-bg-opacity, 1))}.bg-red-600{--tw-bg-opacity: 1;background-color:rgb(var(--color-danger-600) / var(--tw-bg-opacity, 1))}.bg-sky-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-100) / var(--tw-bg-opacity, 1))}.bg-sky-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-50) / var(--tw-bg-opacity, 1))}.bg-sky-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-500) / var(--tw-bg-opacity, 1))}.bg-slate-100{--tw-bg-opacity: 1;background-color:rgb(var(--color-slate-100) / var(--tw-bg-opacity, 1))}.bg-slate-200{--tw-bg-opacity: 1;background-color:rgb(var(--color-slate-200) / var(--tw-bg-opacity, 1))}.bg-slate-300{--tw-bg-opacity: 1;background-color:rgb(var(--color-slate-300) / var(--tw-bg-opacity, 1))}.bg-slate-50{--tw-bg-opacity: 1;background-color:rgb(var(--color-slate-50) / var(--tw-bg-opacity, 1))}.bg-slate-50\/40{background-color:rgb(var(--color-slate-50) / .4)}.bg-slate-50\/70{background-color:rgb(var(--color-slate-50) / .7)}.bg-slate-900{--tw-bg-opacity: 1;background-color:rgb(var(--color-slate-900) / var(--tw-bg-opacity, 1))}.bg-success-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-500) / var(--tw-bg-opacity, 1))}.bg-surface{--tw-bg-opacity: 1;background-color:rgb(var(--color-surface) / var(--tw-bg-opacity, 1))}.bg-surface-muted{--tw-bg-opacity: 1;background-color:rgb(var(--color-surface-muted) / var(--tw-bg-opacity, 1))}.bg-surface-subtle{--tw-bg-opacity: 1;background-color:rgb(var(--color-surface-subtle) / var(--tw-bg-opacity, 1))}.bg-transparent{background-color:var(--color-transparent)}.bg-white{--tw-bg-opacity: 1;background-color:rgb(var(--color-white) / var(--tw-bg-opacity, 1))}.bg-white\/5{background-color:rgb(var(--color-white) / .05)}.bg-white\/80{background-color:rgb(var(--color-white) / .8)}.bg-white\/90{background-color:rgb(var(--color-white) / .9)}.bg-white\/95{background-color:rgb(var(--color-white) / .95)}.bg-opacity-10{--tw-bg-opacity: .1}.bg-gradient-to-bl{background-image:linear-gradient(to bottom left,var(--tw-gradient-stops))}.bg-gradient-to-br{background-image:linear-gradient(to bottom right,var(--tw-gradient-stops))}.from-blue-50{--tw-gradient-from: rgb(var(--color-brand-50) / 1) var(--tw-gradient-from-position);--tw-gradient-to: rgb(var(--color-brand-50) / 0) var(--tw-gradient-to-position);--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to)}.from-red-50{--tw-gradient-from: rgb(var(--color-danger-50) / 1) var(--tw-gradient-from-position);--tw-gradient-to: rgb(var(--color-danger-50) / 0) var(--tw-gradient-to-position);--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to)}.via-white{--tw-gradient-to: rgb(var(--color-white) / 0) var(--tw-gradient-to-position);--tw-gradient-stops: var(--tw-gradient-from), rgb(var(--color-white) / 1) var(--tw-gradient-via-position), var(--tw-gradient-to)}.to-orange-50{--tw-gradient-to: rgb(var(--color-warning-50) / 1) var(--tw-gradient-to-position)}.to-transparent{--tw-gradient-to: var(--color-transparent) var(--tw-gradient-to-position)}.object-contain{-o-object-fit:contain;object-fit:contain}.object-cover{-o-object-fit:cover;object-fit:cover}.p-0{padding:0}.p-1{padding:.25rem}.p-1\.5{padding:.375rem}.p-12{padding:3rem}.p-16{padding:4rem}.p-2{padding:.5rem}.p-2\.5{padding:.625rem}.p-20{padding:5rem}.p-3{padding:.75rem}.p-4{padding:1rem}.p-5{padding:1.25rem}.p-6{padding:1.5rem}.p-8{padding:2rem}.px-1{padding-left:.25rem;padding-right:.25rem}.px-1\.5{padding-left:.375rem;padding-right:.375rem}.px-10{padding-left:2.5rem;padding-right:2.5rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-2\.5{padding-left:.625rem;padding-right:.625rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-3\.5{padding-left:.875rem;padding-right:.875rem}.px-4{padding-left:1rem;padding-right:1rem}.px-5{padding-left:1.25rem;padding-right:1.25rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.px-8{padding-left:2rem;padding-right:2rem}.py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.py-12{padding-top:3rem;padding-bottom:3rem}.py-16{padding-top:4rem;padding-bottom:4rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.py-2\.5{padding-top:.625rem;padding-bottom:.625rem}.py-20{padding-top:5rem;padding-bottom:5rem}.py-3{padding-top:.75rem;padding-bottom:.75rem}.py-3\.5{padding-top:.875rem;padding-bottom:.875rem}.py-4{padding-top:1rem;padding-bottom:1rem}.py-5{padding-top:1.25rem;padding-bottom:1.25rem}.py-6{padding-top:1.5rem;padding-bottom:1.5rem}.pb-0{padding-bottom:0}.pb-1{padding-bottom:.25rem}.pb-10{padding-bottom:2.5rem}.pb-24{padding-bottom:6rem}.pb-9{padding-bottom:2.25rem}.pl-10{padding-left:2.5rem}.pl-11{padding-left:2.75rem}.pl-14{padding-left:3.5rem}.pl-2{padding-left:.5rem}.pl-4{padding-left:1rem}.pl-5{padding-left:1.25rem}.pl-6{padding-left:1.5rem}.pl-9{padding-left:2.25rem}.pr-10{padding-right:2.5rem}.pr-11{padding-right:2.75rem}.pr-12{padding-right:3rem}.pr-2{padding-right:.5rem}.pr-3{padding-right:.75rem}.pr-4{padding-right:1rem}.pr-6{padding-right:1.5rem}.pr-9{padding-right:2.25rem}.pt-1{padding-top:.25rem}.pt-3{padding-top:.75rem}.pt-4{padding-top:1rem}.pt-5{padding-top:1.25rem}.pt-6{padding-top:1.5rem}.text-left{text-align:left}.text-center{text-align:center}.text-right{text-align:right}.align-middle{vertical-align:middle}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.font-sans{font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif}.text-2xl{font-size:1.5rem;line-height:2rem}.text-3xl{font-size:1.875rem;line-height:2.25rem}.text-4xl{font-size:2.25rem;line-height:2.5rem}.text-\[10px\]{font-size:10px}.text-\[11px\]{font-size:11px}.text-\[13px\]{font-size:13px}.text-base{font-size:1rem;line-height:1.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-black{font-weight:900}.font-bold{font-weight:700}.font-extrabold{font-weight:800}.font-medium{font-weight:500}.font-semibold{font-weight:600}.uppercase{text-transform:uppercase}.tabular-nums{--tw-numeric-spacing: tabular-nums;font-variant-numeric:var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction)}.leading-4{line-height:1rem}.leading-5{line-height:1.25rem}.leading-6{line-height:1.5rem}.leading-none{line-height:1}.leading-relaxed{line-height:1.625}.leading-tight{line-height:1.25}.tracking-\[0\.18em\]{letter-spacing:.18em}.tracking-\[0\.22em\]{letter-spacing:.22em}.tracking-tight{letter-spacing:-.025em}.tracking-wide{letter-spacing:.025em}.tracking-wider{letter-spacing:.05em}.text-amber-600{--tw-text-opacity: 1;color:rgb(var(--color-warning-600) / var(--tw-text-opacity, 1))}.text-amber-700{--tw-text-opacity: 1;color:rgb(var(--color-warning-700) / var(--tw-text-opacity, 1))}.text-amber-800{--tw-text-opacity: 1;color:rgb(var(--color-warning-800) / var(--tw-text-opacity, 1))}.text-amber-800\/80{color:rgb(var(--color-warning-800) / .8)}.text-amber-900{--tw-text-opacity: 1;color:rgb(var(--color-warning-900) / var(--tw-text-opacity, 1))}.text-amber-900\/90{color:rgb(var(--color-warning-900) / .9)}.text-black{--tw-text-opacity: 1;color:rgb(var(--color-black) / var(--tw-text-opacity, 1))}.text-blue-500{--tw-text-opacity: 1;color:rgb(var(--color-brand-500) / var(--tw-text-opacity, 1))}.text-blue-600{--tw-text-opacity: 1;color:rgb(var(--color-brand-600) / var(--tw-text-opacity, 1))}.text-blue-700{--tw-text-opacity: 1;color:rgb(var(--color-brand-700) / var(--tw-text-opacity, 1))}.text-blue-800{--tw-text-opacity: 1;color:rgb(var(--color-brand-800) / var(--tw-text-opacity, 1))}.text-blue-900{--tw-text-opacity: 1;color:rgb(var(--color-brand-900) / var(--tw-text-opacity, 1))}.text-blue-950{--tw-text-opacity: 1;color:rgb(var(--color-brand-950) / var(--tw-text-opacity, 1))}.text-brand{--tw-text-opacity: 1;color:rgb(var(--color-brand) / var(--tw-text-opacity, 1))}.text-emerald-600{--tw-text-opacity: 1;color:rgb(var(--color-success-600) / var(--tw-text-opacity, 1))}.text-emerald-700{--tw-text-opacity: 1;color:rgb(var(--color-success-700) / var(--tw-text-opacity, 1))}.text-emerald-800{--tw-text-opacity: 1;color:rgb(var(--color-success-800) / var(--tw-text-opacity, 1))}.text-gray-100{--tw-text-opacity: 1;color:rgb(var(--color-neutral-100) / var(--tw-text-opacity, 1))}.text-gray-300{--tw-text-opacity: 1;color:rgb(var(--color-neutral-300) / var(--tw-text-opacity, 1))}.text-gray-400{--tw-text-opacity: 1;color:rgb(var(--color-neutral-400) / var(--tw-text-opacity, 1))}.text-gray-500{--tw-text-opacity: 1;color:rgb(var(--color-neutral-500) / var(--tw-text-opacity, 1))}.text-gray-600{--tw-text-opacity: 1;color:rgb(var(--color-neutral-600) / var(--tw-text-opacity, 1))}.text-gray-700{--tw-text-opacity: 1;color:rgb(var(--color-neutral-700) / var(--tw-text-opacity, 1))}.text-gray-800{--tw-text-opacity: 1;color:rgb(var(--color-neutral-800) / var(--tw-text-opacity, 1))}.text-gray-900{--tw-text-opacity: 1;color:rgb(var(--color-neutral-900) / var(--tw-text-opacity, 1))}.text-gray-950{--tw-text-opacity: 1;color:rgb(var(--color-neutral-950) / var(--tw-text-opacity, 1))}.text-green-500{--tw-text-opacity: 1;color:rgb(var(--color-success-500) / var(--tw-text-opacity, 1))}.text-green-600{--tw-text-opacity: 1;color:rgb(var(--color-success-600) / var(--tw-text-opacity, 1))}.text-green-700{--tw-text-opacity: 1;color:rgb(var(--color-success-700) / var(--tw-text-opacity, 1))}.text-green-800{--tw-text-opacity: 1;color:rgb(var(--color-success-800) / var(--tw-text-opacity, 1))}.text-ink{--tw-text-opacity: 1;color:rgb(var(--color-ink) / var(--tw-text-opacity, 1))}.text-orange-700{--tw-text-opacity: 1;color:rgb(var(--color-warning-700) / var(--tw-text-opacity, 1))}.text-pink-600{--tw-text-opacity: 1;color:rgb(var(--color-accent-600) / var(--tw-text-opacity, 1))}.text-purple-500{--tw-text-opacity: 1;color:rgb(var(--color-accent-500) / var(--tw-text-opacity, 1))}.text-purple-600{--tw-text-opacity: 1;color:rgb(var(--color-accent-600) / var(--tw-text-opacity, 1))}.text-purple-700{--tw-text-opacity: 1;color:rgb(var(--color-accent-700) / var(--tw-text-opacity, 1))}.text-red-500{--tw-text-opacity: 1;color:rgb(var(--color-danger-500) / var(--tw-text-opacity, 1))}.text-red-600{--tw-text-opacity: 1;color:rgb(var(--color-danger-600) / var(--tw-text-opacity, 1))}.text-red-700{--tw-text-opacity: 1;color:rgb(var(--color-danger-700) / var(--tw-text-opacity, 1))}.text-red-800{--tw-text-opacity: 1;color:rgb(var(--color-danger-800) / var(--tw-text-opacity, 1))}.text-red-900{--tw-text-opacity: 1;color:rgb(var(--color-danger-900) / var(--tw-text-opacity, 1))}.text-sky-500{--tw-text-opacity: 1;color:rgb(var(--color-brand-500) / var(--tw-text-opacity, 1))}.text-sky-600{--tw-text-opacity: 1;color:rgb(var(--color-brand-600) / var(--tw-text-opacity, 1))}.text-sky-700{--tw-text-opacity: 1;color:rgb(var(--color-brand-700) / var(--tw-text-opacity, 1))}.text-sky-800{--tw-text-opacity: 1;color:rgb(var(--color-brand-800) / var(--tw-text-opacity, 1))}.text-sky-900{--tw-text-opacity: 1;color:rgb(var(--color-brand-900) / var(--tw-text-opacity, 1))}.text-slate-300{--tw-text-opacity: 1;color:rgb(var(--color-slate-300) / var(--tw-text-opacity, 1))}.text-slate-400{--tw-text-opacity: 1;color:rgb(var(--color-slate-400) / var(--tw-text-opacity, 1))}.text-slate-500{--tw-text-opacity: 1;color:rgb(var(--color-slate-500) / var(--tw-text-opacity, 1))}.text-slate-600{--tw-text-opacity: 1;color:rgb(var(--color-slate-600) / var(--tw-text-opacity, 1))}.text-slate-700{--tw-text-opacity: 1;color:rgb(var(--color-slate-700) / var(--tw-text-opacity, 1))}.text-slate-800{--tw-text-opacity: 1;color:rgb(var(--color-slate-800) / var(--tw-text-opacity, 1))}.text-slate-900{--tw-text-opacity: 1;color:rgb(var(--color-slate-900) / var(--tw-text-opacity, 1))}.text-slate-950{--tw-text-opacity: 1;color:rgb(var(--color-slate-950) / var(--tw-text-opacity, 1))}.text-white{--tw-text-opacity: 1;color:rgb(var(--color-white) / var(--tw-text-opacity, 1))}.underline{text-decoration-line:underline}.accent-brand{accent-color:rgb(var(--color-brand) / 1)}.opacity-0{opacity:0}.opacity-10{opacity:.1}.opacity-20{opacity:.2}.opacity-25{opacity:.25}.opacity-30{opacity:.3}.opacity-60{opacity:.6}.opacity-70{opacity:.7}.opacity-75{opacity:.75}.shadow-2xl{--tw-shadow: var(--shadow-2xl);--tw-shadow-colored: var(--shadow-2xl);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-brand-active{--tw-shadow: var(--shadow-brand-active);--tw-shadow-colored: var(--shadow-brand-active);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-chat{--tw-shadow: var(--shadow-chat);--tw-shadow-colored: var(--shadow-chat);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-chat-active{--tw-shadow: var(--shadow-chat-active);--tw-shadow-colored: var(--shadow-chat-active);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-chat-input{--tw-shadow: var(--shadow-chat-input);--tw-shadow-colored: var(--shadow-chat-input);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-inner{--tw-shadow: var(--shadow-inner);--tw-shadow-colored: var(--shadow-inner);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-lg{--tw-shadow: var(--shadow-lg);--tw-shadow-colored: var(--shadow-lg);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-md{--tw-shadow: var(--shadow-md);--tw-shadow-colored: var(--shadow-md);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-modal{--tw-shadow: var(--shadow-modal);--tw-shadow-colored: var(--shadow-modal);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-panel{--tw-shadow: var(--shadow-panel);--tw-shadow-colored: var(--shadow-panel);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-sidebar{--tw-shadow: var(--shadow-sidebar);--tw-shadow-colored: var(--shadow-sidebar);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-sm{--tw-shadow: var(--shadow-sm);--tw-shadow-colored: var(--shadow-sm);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-xl{--tw-shadow: var(--shadow-xl);--tw-shadow-colored: var(--shadow-xl);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.shadow-blue-100{--tw-shadow-color: rgb(var(--color-brand-100) / 1);--tw-shadow: var(--tw-shadow-colored)}.shadow-blue-200{--tw-shadow-color: rgb(var(--color-brand-200) / 1);--tw-shadow: var(--tw-shadow-colored)}.shadow-emerald-100{--tw-shadow-color: rgb(var(--color-success-100) / 1);--tw-shadow: var(--tw-shadow-colored)}.shadow-gray-200{--tw-shadow-color: rgb(var(--color-neutral-200) / 1);--tw-shadow: var(--tw-shadow-colored)}.shadow-gray-200\/70{--tw-shadow-color: rgb(var(--color-neutral-200) / .7);--tw-shadow: var(--tw-shadow-colored)}.shadow-red-200{--tw-shadow-color: rgb(var(--color-danger-200) / 1);--tw-shadow: var(--tw-shadow-colored)}.shadow-sky-100{--tw-shadow-color: rgb(var(--color-brand-100) / 1);--tw-shadow: var(--tw-shadow-colored)}.outline-none{outline:2px solid transparent;outline-offset:2px}.outline{outline-style:solid}.ring-1{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.ring-2{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.ring-4{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.ring-gray-200{--tw-ring-opacity: 1;--tw-ring-color: rgb(var(--color-neutral-200) / var(--tw-ring-opacity, 1))}.ring-white{--tw-ring-opacity: 1;--tw-ring-color: rgb(var(--color-white) / var(--tw-ring-opacity, 1))}.blur{--tw-blur: blur(8px);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.blur-2xl{--tw-blur: blur(40px);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.blur-\[120px\]{--tw-blur: blur(120px);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.backdrop-blur{--tw-backdrop-blur: blur(8px);-webkit-backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)}.backdrop-blur-3xl{--tw-backdrop-blur: blur(64px);-webkit-backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)}.backdrop-blur-md{--tw-backdrop-blur: blur(12px);-webkit-backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)}.backdrop-blur-sm{--tw-backdrop-blur: blur(4px);-webkit-backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)}.backdrop-blur-xl{--tw-backdrop-blur: blur(24px);-webkit-backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)}.transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-\[margin\]{transition-property:margin;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-\[width\]{transition-property:width;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-opacity{transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-transform{transition-property:transform;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.duration-300{transition-duration:.3s}.duration-500{transition-duration:.5s}:root{--color-transparent: transparent;--color-black: 0 0 0;--color-white: 255 255 255;--color-brand: 0 148 247;--color-brand-highlight: 0 113 227;--color-brand-light: 40 126 254;--color-ink: 29 29 31;--color-muted: 134 134 139;--color-line: 210 210 215;--color-canvas: 244 245 247;--color-surface: 255 255 255;--color-surface-subtle: 247 248 250;--color-surface-muted: 250 250 250;--color-neutral-50: 249 250 251;--color-neutral-100: 243 244 246;--color-neutral-200: 229 231 235;--color-neutral-300: 209 213 219;--color-neutral-400: 156 163 175;--color-neutral-500: 107 114 128;--color-neutral-600: 75 85 99;--color-neutral-700: 55 65 81;--color-neutral-800: 31 41 55;--color-neutral-900: 17 24 39;--color-neutral-950: 3 7 18;--color-slate-50: 248 250 252;--color-slate-100: 241 245 249;--color-slate-200: 226 232 240;--color-slate-300: 203 213 225;--color-slate-400: 148 163 184;--color-slate-500: 100 116 139;--color-slate-600: 71 85 105;--color-slate-700: 51 65 85;--color-slate-800: 30 41 59;--color-slate-900: 15 23 42;--color-slate-950: 2 6 23;--color-brand-50: 239 248 255;--color-brand-100: 223 241 255;--color-brand-200: 191 229 255;--color-brand-300: 143 210 255;--color-brand-400: 83 184 251;--color-brand-500: 0 148 247;--color-brand-600: 0 148 247;--color-brand-700: 0 113 227;--color-brand-800: 0 91 181;--color-brand-900: 0 75 147;--color-brand-950: 0 53 107;--color-success-50: 236 253 245;--color-success-100: 209 250 229;--color-success-200: 167 243 208;--color-success-300: 110 231 183;--color-success-400: 52 211 153;--color-success-500: 16 185 129;--color-success-600: 5 150 105;--color-success-700: 4 120 87;--color-success-800: 6 95 70;--color-success-900: 6 78 59;--color-success-950: 2 44 34;--color-warning-50: 255 251 235;--color-warning-100: 254 243 199;--color-warning-200: 253 230 138;--color-warning-300: 252 211 77;--color-warning-400: 251 191 36;--color-warning-500: 245 158 11;--color-warning-600: 217 119 6;--color-warning-700: 180 83 9;--color-warning-800: 146 64 14;--color-warning-900: 120 53 15;--color-warning-950: 69 26 3;--color-danger-50: 254 242 242;--color-danger-100: 254 226 226;--color-danger-200: 254 202 202;--color-danger-300: 252 165 165;--color-danger-400: 248 113 113;--color-danger-500: 239 68 68;--color-danger-600: 220 38 38;--color-danger-700: 185 28 28;--color-danger-800: 153 27 27;--color-danger-900: 127 29 29;--color-danger-950: 69 10 10;--color-info-50: 239 246 255;--color-info-100: 219 234 254;--color-info-200: 191 219 254;--color-info-300: 147 197 253;--color-info-400: 96 165 250;--color-info-500: 59 130 246;--color-info-600: 37 99 235;--color-info-700: 29 78 216;--color-info-800: 30 64 175;--color-info-900: 30 58 138;--color-info-950: 23 37 84;--color-accent-50: 250 245 255;--color-accent-100: 243 232 255;--color-accent-200: 233 213 255;--color-accent-300: 216 180 254;--color-accent-400: 192 132 252;--color-accent-500: 168 85 247;--color-accent-600: 147 51 234;--color-accent-700: 126 34 206;--color-accent-800: 107 33 168;--color-accent-900: 88 28 135;--color-accent-950: 59 7 100;--shadow-none: 0 0 0 var(--color-transparent);--shadow-default: 0 1px 3px 0 rgb(var(--color-black) / .1), 0 1px 2px -1px rgb(var(--color-black) / .1);--shadow-sm: 0 1px 2px 0 rgb(var(--color-black) / .05);--shadow-md: 0 4px 6px -1px rgb(var(--color-black) / .1), 0 2px 4px -2px rgb(var(--color-black) / .1);--shadow-lg: 0 10px 15px -3px rgb(var(--color-black) / .1), 0 4px 6px -4px rgb(var(--color-black) / .1);--shadow-xl: 0 20px 25px -5px rgb(var(--color-black) / .1), 0 8px 10px -6px rgb(var(--color-black) / .1);--shadow-2xl: 0 25px 50px -12px rgb(var(--color-black) / .25);--shadow-inner: inset 0 2px 4px 0 rgb(var(--color-black) / .05);--shadow-card: 0 8px 24px rgb(var(--color-black) / .04);--shadow-panel: 0 20px 60px -15px rgb(var(--color-black) / .05);--shadow-modal: 0 25px 50px -12px rgb(var(--color-black) / .25);--shadow-sidebar: 4px 0 24px rgb(var(--color-slate-900) / .035);--shadow-chat: 0 16px 45px rgb(var(--color-slate-900) / .06);--shadow-chat-input: 0 -8px 24px rgb(var(--color-slate-900) / .04);--shadow-chat-active: inset 3px 0 0 rgb(var(--color-brand));--shadow-brand-soft: 0 2px 8px rgb(var(--color-brand) / .2);--shadow-brand-active: 0 8px 18px rgb(var(--color-brand) / .2);--shadow-brand-strong: 0 8px 20px rgb(var(--color-brand) / .3)}*,:before,:after{--tw-ring-offset-color: rgb(var(--color-white));--tw-ring-color: rgb(var(--color-brand-400) / .5);--tw-ring-offset-shadow: 0 0 0 var(--color-transparent);--tw-ring-shadow: 0 0 0 var(--color-transparent);--tw-shadow: 0 0 0 var(--color-transparent);--tw-shadow-colored: 0 0 0 var(--color-transparent)}.squircle{-webkit-mask-image:url(/static/assets/squircle-rb6SKa34.svg);mask-image:url(/static/assets/squircle-rb6SKa34.svg);-webkit-mask-size:contain;mask-size:contain;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center;border-radius:0}*{box-sizing:border-box;margin:0;padding:0}html,body,#root{height:100%;width:100%}body{font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;background-color:rgb(var(--color-canvas));color:rgb(var(--color-ink));-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.ios-card{background:rgb(var(--color-surface));border-radius:8px;border:1px solid rgb(var(--color-black) / .02);box-shadow:var(--shadow-card);transition:transform .2s ease,box-shadow .2s ease}.ios-card:hover{box-shadow:0 12px 32px rgb(var(--color-black) / .06)}.dashboard-pie-chart .recharts-surface:focus,.dashboard-pie-chart .recharts-pie:focus,.dashboard-pie-chart .recharts-pie-sector:focus,.dashboard-pie-chart .recharts-sector:focus{outline:none}.dashboard-revenue-chart .recharts-surface:focus,.dashboard-revenue-chart .recharts-bar-rectangle:focus,.dashboard-revenue-chart .recharts-rectangle:focus,.dashboard-revenue-chart .recharts-curve:focus,.dashboard-revenue-chart .recharts-dot:focus,.dashboard-revenue-chart [class*=recharts-zIndex-layer_]:focus{outline:none!important}.dashboard-revenue-chart .recharts-bar-rectangle,.dashboard-revenue-chart .recharts-rectangle{stroke:none!important}.ios-input{background:rgb(var(--color-surface-subtle));border:1px solid var(--color-transparent);transition:all .3s cubic-bezier(.25,.8,.25,1);color:rgb(var(--color-ink));font-weight:500}.ios-input:focus{background:rgb(var(--color-surface));border-color:rgb(var(--color-brand));box-shadow:0 0 0 4px rgb(var(--color-brand) / .3);outline:none}.ios-input::-moz-placeholder{color:rgb(var(--color-neutral-400));font-weight:400}.ios-input::placeholder{color:rgb(var(--color-neutral-400));font-weight:400}.ios-btn-primary{background:rgb(var(--color-brand));color:rgb(var(--color-white));font-weight:700;border:none;transition:all .2s cubic-bezier(.25,.8,.25,1);cursor:pointer}.ios-btn-primary:hover:not(:disabled){background:rgb(var(--color-brand-highlight));transform:translateY(-1px);box-shadow:var(--shadow-brand-strong)}.ios-btn-primary:active:not(:disabled){transform:translateY(1px);box-shadow:var(--shadow-brand-soft)}.ios-btn-primary:disabled{background:rgb(var(--color-neutral-100));color:rgb(var(--color-neutral-400));box-shadow:none;transform:none;cursor:not-allowed}.ios-btn-secondary{background:rgb(var(--color-surface-subtle));color:rgb(var(--color-ink));font-weight:600;border:1px solid var(--color-transparent);transition:all .2s ease;cursor:pointer}.ios-btn-secondary:hover{background:rgb(var(--color-neutral-200));border-color:rgb(var(--color-neutral-300))}.ios-btn-danger{background:rgb(var(--color-danger-100));color:rgb(var(--color-danger-600));font-weight:600;border:1px solid var(--color-transparent);transition:all .2s ease;cursor:pointer}.ios-btn-danger:hover{background:rgb(var(--color-danger-200));border-color:rgb(var(--color-danger-300))}::-webkit-scrollbar{width:6px;height:6px}::-webkit-scrollbar-track{background:var(--color-transparent)}::-webkit-scrollbar-thumb{background:rgb(var(--color-black) / .1);border-radius:10px}::-webkit-scrollbar-thumb:hover{background:rgb(var(--color-black) / .2)}@keyframes fadeIn{0%{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}.animate-fade-in{animation:fadeIn .5s cubic-bezier(.16,1,.3,1) forwards}@keyframes slideUp{0%{opacity:0;transform:translateY(30px) scale(.95)}to{opacity:1;transform:translateY(0) scale(1)}}.animate-slide-up{animation:slideUp .3s cubic-bezier(.16,1,.3,1) forwards}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.animate-spin{animation:spin 1s linear infinite}@keyframes pulse{0%,to{opacity:1}50%{opacity:.5}}.animate-pulse{animation:pulse 2s cubic-bezier(.4,0,.6,1) infinite}::-moz-selection{background:rgb(var(--color-brand));color:rgb(var(--color-white))}::selection{background:rgb(var(--color-brand));color:rgb(var(--color-white))}.text-brand{color:rgb(var(--color-brand))}.bg-brand{background-color:rgb(var(--color-brand))}.border-brand{border-color:rgb(var(--color-brand))}.status-badge{display:inline-flex;align-items:center;padding:4px 12px;border-radius:9999px;font-size:12px;font-weight:600}.status-badge-success{background-color:rgb(var(--color-success-100));color:rgb(var(--color-success-800))}.status-badge-warning{background-color:rgb(var(--color-warning-100));color:rgb(var(--color-warning-800))}.status-badge-error{background-color:rgb(var(--color-danger-100));color:rgb(var(--color-danger-800))}.status-badge-info{background-color:rgb(var(--color-info-100));color:rgb(var(--color-info-800))}.loading-skeleton{background:linear-gradient(90deg,rgb(var(--color-neutral-100)),rgb(var(--color-neutral-200)),rgb(var(--color-neutral-100)));background-size:200% 100%;animation:loading 1.5s ease-in-out infinite}@keyframes loading{0%{background-position:200% 0}to{background-position:-200% 0}}.modal-overlay{position:fixed;top:0;right:0;bottom:0;left:0;z-index:9999;display:flex;align-items:center;justify-content:center;background-color:rgb(var(--color-black) / .4);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);padding:1rem;overflow-y:auto}.modal-container{position:relative;width:100%;max-width:42rem;max-height:85vh;margin:auto;display:flex;flex-direction:column;background-color:rgb(var(--color-white));border-radius:10px;box-shadow:var(--shadow-modal);overflow:hidden}.modal-header{flex-shrink:0;padding:2rem 2rem 1.5rem;border-bottom:1px solid rgb(var(--color-neutral-100));background-color:rgb(var(--color-white));z-index:10}.modal-body{flex:1 1 auto;overflow-y:auto;overflow-x:hidden;padding:2rem}.modal-footer{flex-shrink:0;padding:1.5rem 2rem 2rem;border-top:1px solid rgb(var(--color-neutral-100));background-color:rgb(var(--color-white));z-index:10}.modal-container-lg{max-width:64rem}.modal-overlay-centered{position:fixed;top:0;right:0;bottom:0;left:0;z-index:9999;display:flex;justify-content:center;background-color:rgb(var(--color-black) / .4);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);padding:1rem;overflow-y:auto}.modal-overlay-centered .modal-container{position:relative;width:100%;max-width:42rem;max-height:85vh;margin:auto 0;display:flex;flex-direction:column;background-color:rgb(var(--color-white));border-radius:10px;box-shadow:var(--shadow-modal);overflow:hidden}@media(max-width:768px){.ios-card{border-radius:6px}.ios-input{font-size:16px}.modal-container{max-width:calc(100% - 2rem);max-height:90vh;border-radius:8px}.modal-header,.modal-body,.modal-footer{padding-left:1.5rem;padding-right:1.5rem}}.placeholder\:text-slate-400::-moz-placeholder{--tw-text-opacity: 1;color:rgb(var(--color-slate-400) / var(--tw-text-opacity, 1))}.placeholder\:text-slate-400::placeholder{--tw-text-opacity: 1;color:rgb(var(--color-slate-400) / var(--tw-text-opacity, 1))}.focus-within\:border-sky-400:focus-within{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-400) / var(--tw-border-opacity, 1))}.focus-within\:ring-2:focus-within{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.focus-within\:ring-sky-100:focus-within{--tw-ring-opacity: 1;--tw-ring-color: rgb(var(--color-brand-100) / var(--tw-ring-opacity, 1))}.hover\:translate-y-\[-4px\]:hover{--tw-translate-y: -4px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.hover\:scale-105:hover{--tw-scale-x: 1.05;--tw-scale-y: 1.05;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.hover\:border-amber-300:hover{--tw-border-opacity: 1;border-color:rgb(var(--color-warning-300) / var(--tw-border-opacity, 1))}.hover\:border-blue-300:hover{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-300) / var(--tw-border-opacity, 1))}.hover\:border-brand:hover{--tw-border-opacity: 1;border-color:rgb(var(--color-brand) / var(--tw-border-opacity, 1))}.hover\:border-emerald-300:hover{--tw-border-opacity: 1;border-color:rgb(var(--color-success-300) / var(--tw-border-opacity, 1))}.hover\:border-gray-300:hover{--tw-border-opacity: 1;border-color:rgb(var(--color-neutral-300) / var(--tw-border-opacity, 1))}.hover\:border-gray-400:hover{--tw-border-opacity: 1;border-color:rgb(var(--color-neutral-400) / var(--tw-border-opacity, 1))}.hover\:border-sky-200:hover{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-200) / var(--tw-border-opacity, 1))}.hover\:bg-amber-100:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-warning-100) / var(--tw-bg-opacity, 1))}.hover\:bg-black:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-black) / var(--tw-bg-opacity, 1))}.hover\:bg-blue-100:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-100) / var(--tw-bg-opacity, 1))}.hover\:bg-blue-50:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-50) / var(--tw-bg-opacity, 1))}.hover\:bg-blue-700:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-700) / var(--tw-bg-opacity, 1))}.hover\:bg-brand:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand) / var(--tw-bg-opacity, 1))}.hover\:bg-brand-highlight:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-highlight) / var(--tw-bg-opacity, 1))}.hover\:bg-emerald-100:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-100) / var(--tw-bg-opacity, 1))}.hover\:bg-emerald-50:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-50) / var(--tw-bg-opacity, 1))}.hover\:bg-emerald-50\/50:hover{background-color:rgb(var(--color-success-50) / .5)}.hover\:bg-emerald-600:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-600) / var(--tw-bg-opacity, 1))}.hover\:bg-emerald-700:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-700) / var(--tw-bg-opacity, 1))}.hover\:bg-gray-100:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-100) / var(--tw-bg-opacity, 1))}.hover\:bg-gray-200:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-200) / var(--tw-bg-opacity, 1))}.hover\:bg-gray-50:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-50) / var(--tw-bg-opacity, 1))}.hover\:bg-gray-800:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-neutral-800) / var(--tw-bg-opacity, 1))}.hover\:bg-green-100:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-100) / var(--tw-bg-opacity, 1))}.hover\:bg-green-50:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-50) / var(--tw-bg-opacity, 1))}.hover\:bg-purple-100:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-accent-100) / var(--tw-bg-opacity, 1))}.hover\:bg-red-100:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-danger-100) / var(--tw-bg-opacity, 1))}.hover\:bg-red-50:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-danger-50) / var(--tw-bg-opacity, 1))}.hover\:bg-red-700:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-danger-700) / var(--tw-bg-opacity, 1))}.hover\:bg-sky-50:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-50) / var(--tw-bg-opacity, 1))}.hover\:bg-sky-600:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-600) / var(--tw-bg-opacity, 1))}.hover\:bg-slate-100:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-slate-100) / var(--tw-bg-opacity, 1))}.hover\:bg-warning-50\/50:hover{background-color:rgb(var(--color-warning-50) / .5)}.hover\:bg-white:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-white) / var(--tw-bg-opacity, 1))}.hover\:bg-white\/10:hover{background-color:rgb(var(--color-white) / .1)}.hover\:bg-white\/80:hover{background-color:rgb(var(--color-white) / .8)}.hover\:text-black:hover{--tw-text-opacity: 1;color:rgb(var(--color-black) / var(--tw-text-opacity, 1))}.hover\:text-blue-600:hover{--tw-text-opacity: 1;color:rgb(var(--color-brand-600) / var(--tw-text-opacity, 1))}.hover\:text-brand:hover{--tw-text-opacity: 1;color:rgb(var(--color-brand) / var(--tw-text-opacity, 1))}.hover\:text-gray-600:hover{--tw-text-opacity: 1;color:rgb(var(--color-neutral-600) / var(--tw-text-opacity, 1))}.hover\:text-gray-700:hover{--tw-text-opacity: 1;color:rgb(var(--color-neutral-700) / var(--tw-text-opacity, 1))}.hover\:text-gray-900:hover{--tw-text-opacity: 1;color:rgb(var(--color-neutral-900) / var(--tw-text-opacity, 1))}.hover\:text-green-600:hover{--tw-text-opacity: 1;color:rgb(var(--color-success-600) / var(--tw-text-opacity, 1))}.hover\:text-red-500:hover{--tw-text-opacity: 1;color:rgb(var(--color-danger-500) / var(--tw-text-opacity, 1))}.hover\:text-red-600:hover{--tw-text-opacity: 1;color:rgb(var(--color-danger-600) / var(--tw-text-opacity, 1))}.hover\:text-sky-600:hover{--tw-text-opacity: 1;color:rgb(var(--color-brand-600) / var(--tw-text-opacity, 1))}.hover\:text-slate-700:hover{--tw-text-opacity: 1;color:rgb(var(--color-slate-700) / var(--tw-text-opacity, 1))}.hover\:text-slate-900:hover{--tw-text-opacity: 1;color:rgb(var(--color-slate-900) / var(--tw-text-opacity, 1))}.hover\:text-white:hover{--tw-text-opacity: 1;color:rgb(var(--color-white) / var(--tw-text-opacity, 1))}.hover\:underline:hover{text-decoration-line:underline}.hover\:shadow-lg:hover{--tw-shadow: var(--shadow-lg);--tw-shadow-colored: var(--shadow-lg);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.focus\:border-blue-400:focus{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-400) / var(--tw-border-opacity, 1))}.focus\:border-sky-400:focus{--tw-border-opacity: 1;border-color:rgb(var(--color-brand-400) / var(--tw-border-opacity, 1))}.focus\:outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\:ring-0:focus{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.focus\:ring-2:focus{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.focus\:ring-brand:focus{--tw-ring-opacity: 1;--tw-ring-color: rgb(var(--color-brand) / var(--tw-ring-opacity, 1))}.focus\:ring-sky-100:focus{--tw-ring-opacity: 1;--tw-ring-color: rgb(var(--color-brand-100) / var(--tw-ring-opacity, 1))}.active\:scale-95:active{--tw-scale-x: .95;--tw-scale-y: .95;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:bg-red-400:disabled{--tw-bg-opacity: 1;background-color:rgb(var(--color-danger-400) / var(--tw-bg-opacity, 1))}.disabled\:bg-slate-300:disabled{--tw-bg-opacity: 1;background-color:rgb(var(--color-slate-300) / var(--tw-bg-opacity, 1))}.disabled\:opacity-25:disabled{opacity:.25}.disabled\:opacity-30:disabled{opacity:.3}.disabled\:opacity-40:disabled{opacity:.4}.disabled\:opacity-50:disabled{opacity:.5}.disabled\:opacity-60:disabled{opacity:.6}.disabled\:opacity-70:disabled{opacity:.7}.disabled\:shadow-none:disabled{--tw-shadow: var(--shadow-none);--tw-shadow-colored: var(--shadow-none);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.group:focus-within .group-focus-within\:text-brand{--tw-text-opacity: 1;color:rgb(var(--color-brand) / var(--tw-text-opacity, 1))}.group:hover .group-hover\:scale-105{--tw-scale-x: 1.05;--tw-scale-y: 1.05;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.group:hover .group-hover\:scale-125{--tw-scale-x: 1.25;--tw-scale-y: 1.25;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.group:hover .group-hover\:bg-white{--tw-bg-opacity: 1;background-color:rgb(var(--color-white) / var(--tw-bg-opacity, 1))}.group:hover .group-hover\:text-slate-700{--tw-text-opacity: 1;color:rgb(var(--color-slate-700) / var(--tw-text-opacity, 1))}.group:hover .group-hover\:opacity-100{opacity:1}@media(min-width:640px){.sm\:w-48{width:12rem}.sm\:w-56{width:14rem}.sm\:w-64{width:16rem}.sm\:w-72{width:18rem}.sm\:max-w-sm{max-width:24rem}.sm\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.sm\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.sm\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.sm\:grid-cols-6{grid-template-columns:repeat(6,minmax(0,1fr))}.sm\:grid-cols-\[1fr_180px\]{grid-template-columns:1fr 180px}.sm\:flex-row{flex-direction:row}.sm\:flex-wrap{flex-wrap:wrap}.sm\:items-center{align-items:center}.sm\:justify-between{justify-content:space-between}.sm\:gap-8{gap:2rem}}@media(min-width:768px){.md\:col-span-2{grid-column:span 2 / span 2}.md\:col-span-3{grid-column:span 3 / span 3}.md\:col-span-full{grid-column:1 / -1}.md\:w-auto{width:auto}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.md\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.md\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.md\:grid-cols-\[1\.4fr_110px_40px\]{grid-template-columns:1.4fr 110px 40px}.md\:grid-cols-\[180px_1fr\]{grid-template-columns:180px 1fr}.md\:grid-cols-\[1fr_1fr_1\.4fr_110px_40px\]{grid-template-columns:1fr 1fr 1.4fr 110px 40px}.md\:flex-row{flex-direction:row}.md\:items-end{align-items:flex-end}.md\:items-center{align-items:center}.md\:justify-between{justify-content:space-between}.md\:border-l{border-left-width:1px}.md\:border-t-0{border-top-width:0px}.md\:p-12{padding:3rem}.md\:p-6{padding:1.5rem}.md\:pl-6{padding-left:1.5rem}.md\:pt-0{padding-top:0}}@media(min-width:1024px){.lg\:col-span-2{grid-column:span 2 / span 2}.lg\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.lg\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.lg\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.lg\:grid-cols-\[320px_1fr\]{grid-template-columns:320px 1fr}.lg\:flex-row{flex-direction:row}.lg\:items-center{align-items:center}}@media(min-width:1280px){.xl\:w-36{width:9rem}.xl\:w-52{width:13rem}.xl\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.xl\:grid-cols-\[minmax\(270px\,0\.72fr\)_minmax\(0\,1\.28fr\)\]{grid-template-columns:minmax(270px,.72fr) minmax(0,1.28fr)}.xl\:flex-row{flex-direction:row}.xl\:items-end{align-items:flex-end}.xl\:items-center{align-items:center}.xl\:justify-between{justify-content:space-between}}@media(min-width:1536px){.\32xl\:grid-cols-\[360px_1fr\]{grid-template-columns:360px 1fr}}
diff --git a/internal/webui/static/assets/index-ZQ7msDu9.css b/internal/webui/static/assets/index-ZQ7msDu9.css
deleted file mode 100644
index d1b8f6c..0000000
--- a/internal/webui/static/assets/index-ZQ7msDu9.css
+++ /dev/null
@@ -1 +0,0 @@
-*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.container{width:100%}@media(min-width:640px){.container{max-width:640px}}@media(min-width:768px){.container{max-width:768px}}@media(min-width:1024px){.container{max-width:1024px}}@media(min-width:1280px){.container{max-width:1280px}}@media(min-width:1536px){.container{max-width:1536px}}.collapse{visibility:collapse}.static{position:static}.relative{position:relative}.mx-0\.5{margin-left:.125rem;margin-right:.125rem}.inline-block{display:inline-block}.inline{display:inline}.contents{display:contents}.h-7{height:1.75rem}.h-screen{height:100vh}.min-h-0{min-height:0px}.w-16{width:4rem}.w-64{width:16rem}.w-7{width:1.75rem}.min-w-0{min-width:0px}.flex-1{flex:1 1 0%}.shrink{flex-shrink:1}.grid-cols-\[320px_minmax\(0\,1fr\)\]{grid-template-columns:320px minmax(0,1fr)}.flex-col{flex-direction:column}.justify-center{justify-content:center}.space-y-8>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(2rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(2rem * var(--tw-space-y-reverse))}.overflow-hidden{overflow:hidden}.overflow-x-hidden{overflow-x:hidden}.bg-blue-600{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-600) / var(--tw-bg-opacity, 1))}.bg-brand{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand) / var(--tw-bg-opacity, 1))}.bg-emerald-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-500) / var(--tw-bg-opacity, 1))}.bg-emerald-600{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-600) / var(--tw-bg-opacity, 1))}.bg-sky-500{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-500) / var(--tw-bg-opacity, 1))}.py-1{padding-top:.25rem;padding-bottom:.25rem}.align-middle{vertical-align:middle}.text-white{--tw-text-opacity: 1;color:rgb(var(--color-white) / var(--tw-text-opacity, 1))}.shadow-brand-active{--tw-shadow: var(--shadow-brand-active);--tw-shadow-colored: var(--shadow-brand-active);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}:root{--color-transparent: transparent;--color-black: 0 0 0;--color-white: 255 255 255;--color-brand: 0 148 247;--color-brand-highlight: 0 113 227;--color-brand-light: 40 126 254;--color-ink: 29 29 31;--color-muted: 134 134 139;--color-line: 210 210 215;--color-canvas: 244 245 247;--color-surface: 255 255 255;--color-surface-subtle: 247 248 250;--color-surface-muted: 250 250 250;--color-neutral-50: 249 250 251;--color-neutral-100: 243 244 246;--color-neutral-200: 229 231 235;--color-neutral-300: 209 213 219;--color-neutral-400: 156 163 175;--color-neutral-500: 107 114 128;--color-neutral-600: 75 85 99;--color-neutral-700: 55 65 81;--color-neutral-800: 31 41 55;--color-neutral-900: 17 24 39;--color-neutral-950: 3 7 18;--color-slate-50: 248 250 252;--color-slate-100: 241 245 249;--color-slate-200: 226 232 240;--color-slate-300: 203 213 225;--color-slate-400: 148 163 184;--color-slate-500: 100 116 139;--color-slate-600: 71 85 105;--color-slate-700: 51 65 85;--color-slate-800: 30 41 59;--color-slate-900: 15 23 42;--color-slate-950: 2 6 23;--color-brand-50: 239 248 255;--color-brand-100: 223 241 255;--color-brand-200: 191 229 255;--color-brand-300: 143 210 255;--color-brand-400: 83 184 251;--color-brand-500: 0 148 247;--color-brand-600: 0 148 247;--color-brand-700: 0 113 227;--color-brand-800: 0 91 181;--color-brand-900: 0 75 147;--color-brand-950: 0 53 107;--color-success-50: 236 253 245;--color-success-100: 209 250 229;--color-success-200: 167 243 208;--color-success-300: 110 231 183;--color-success-400: 52 211 153;--color-success-500: 16 185 129;--color-success-600: 5 150 105;--color-success-700: 4 120 87;--color-success-800: 6 95 70;--color-success-900: 6 78 59;--color-success-950: 2 44 34;--color-warning-50: 255 251 235;--color-warning-100: 254 243 199;--color-warning-200: 253 230 138;--color-warning-300: 252 211 77;--color-warning-400: 251 191 36;--color-warning-500: 245 158 11;--color-warning-600: 217 119 6;--color-warning-700: 180 83 9;--color-warning-800: 146 64 14;--color-warning-900: 120 53 15;--color-warning-950: 69 26 3;--color-danger-50: 254 242 242;--color-danger-100: 254 226 226;--color-danger-200: 254 202 202;--color-danger-300: 252 165 165;--color-danger-400: 248 113 113;--color-danger-500: 239 68 68;--color-danger-600: 220 38 38;--color-danger-700: 185 28 28;--color-danger-800: 153 27 27;--color-danger-900: 127 29 29;--color-danger-950: 69 10 10;--color-info-50: 239 246 255;--color-info-100: 219 234 254;--color-info-200: 191 219 254;--color-info-300: 147 197 253;--color-info-400: 96 165 250;--color-info-500: 59 130 246;--color-info-600: 37 99 235;--color-info-700: 29 78 216;--color-info-800: 30 64 175;--color-info-900: 30 58 138;--color-info-950: 23 37 84;--color-accent-50: 250 245 255;--color-accent-100: 243 232 255;--color-accent-200: 233 213 255;--color-accent-300: 216 180 254;--color-accent-400: 192 132 252;--color-accent-500: 168 85 247;--color-accent-600: 147 51 234;--color-accent-700: 126 34 206;--color-accent-800: 107 33 168;--color-accent-900: 88 28 135;--color-accent-950: 59 7 100;--shadow-none: 0 0 0 var(--color-transparent);--shadow-default: 0 1px 3px 0 rgb(var(--color-black) / .1), 0 1px 2px -1px rgb(var(--color-black) / .1);--shadow-sm: 0 1px 2px 0 rgb(var(--color-black) / .05);--shadow-md: 0 4px 6px -1px rgb(var(--color-black) / .1), 0 2px 4px -2px rgb(var(--color-black) / .1);--shadow-lg: 0 10px 15px -3px rgb(var(--color-black) / .1), 0 4px 6px -4px rgb(var(--color-black) / .1);--shadow-xl: 0 20px 25px -5px rgb(var(--color-black) / .1), 0 8px 10px -6px rgb(var(--color-black) / .1);--shadow-2xl: 0 25px 50px -12px rgb(var(--color-black) / .25);--shadow-inner: inset 0 2px 4px 0 rgb(var(--color-black) / .05);--shadow-card: 0 8px 24px rgb(var(--color-black) / .04);--shadow-panel: 0 20px 60px -15px rgb(var(--color-black) / .05);--shadow-modal: 0 25px 50px -12px rgb(var(--color-black) / .25);--shadow-sidebar: 4px 0 24px rgb(var(--color-slate-900) / .035);--shadow-chat: 0 16px 45px rgb(var(--color-slate-900) / .06);--shadow-chat-input: 0 -8px 24px rgb(var(--color-slate-900) / .04);--shadow-chat-active: inset 3px 0 0 rgb(var(--color-brand));--shadow-brand-soft: 0 2px 8px rgb(var(--color-brand) / .2);--shadow-brand-active: 0 8px 18px rgb(var(--color-brand) / .2);--shadow-brand-strong: 0 8px 20px rgb(var(--color-brand) / .3)}*,:before,:after{--tw-ring-offset-color: rgb(var(--color-white));--tw-ring-color: rgb(var(--color-brand-400) / .5);--tw-ring-offset-shadow: 0 0 0 var(--color-transparent);--tw-ring-shadow: 0 0 0 var(--color-transparent);--tw-shadow: 0 0 0 var(--color-transparent);--tw-shadow-colored: 0 0 0 var(--color-transparent)}.squircle{-webkit-mask-image:url(/static/assets/squircle-rb6SKa34.svg);mask-image:url(/static/assets/squircle-rb6SKa34.svg);-webkit-mask-size:contain;mask-size:contain;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center;border-radius:0}*{box-sizing:border-box;margin:0;padding:0}html,body,#root{height:100%;width:100%}body{font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;background-color:rgb(var(--color-canvas));color:rgb(var(--color-ink));-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.ios-card{background:rgb(var(--color-surface));border-radius:8px;border:1px solid rgb(var(--color-black) / .02);box-shadow:var(--shadow-card);transition:transform .2s ease,box-shadow .2s ease}.ios-card:hover{box-shadow:0 12px 32px rgb(var(--color-black) / .06)}.dashboard-pie-chart .recharts-surface:focus,.dashboard-pie-chart .recharts-pie:focus,.dashboard-pie-chart .recharts-pie-sector:focus,.dashboard-pie-chart .recharts-sector:focus{outline:none}.dashboard-revenue-chart .recharts-surface:focus,.dashboard-revenue-chart .recharts-bar-rectangle:focus,.dashboard-revenue-chart .recharts-rectangle:focus,.dashboard-revenue-chart .recharts-curve:focus,.dashboard-revenue-chart .recharts-dot:focus,.dashboard-revenue-chart [class*=recharts-zIndex-layer_]:focus{outline:none!important}.dashboard-revenue-chart .recharts-bar-rectangle,.dashboard-revenue-chart .recharts-rectangle{stroke:none!important}.ios-input{background:rgb(var(--color-surface-subtle));border:1px solid var(--color-transparent);transition:all .3s cubic-bezier(.25,.8,.25,1);color:rgb(var(--color-ink));font-weight:500}.ios-input:focus{background:rgb(var(--color-surface));border-color:rgb(var(--color-brand));box-shadow:0 0 0 4px rgb(var(--color-brand) / .3);outline:none}.ios-input::-moz-placeholder{color:rgb(var(--color-neutral-400));font-weight:400}.ios-input::placeholder{color:rgb(var(--color-neutral-400));font-weight:400}.ios-btn-primary{background:rgb(var(--color-brand));color:rgb(var(--color-white));font-weight:700;border:none;transition:all .2s cubic-bezier(.25,.8,.25,1);cursor:pointer}.ios-btn-primary:hover:not(:disabled){background:rgb(var(--color-brand-highlight));transform:translateY(-1px);box-shadow:var(--shadow-brand-strong)}.ios-btn-primary:active:not(:disabled){transform:translateY(1px);box-shadow:var(--shadow-brand-soft)}.ios-btn-primary:disabled{background:rgb(var(--color-neutral-100));color:rgb(var(--color-neutral-400));box-shadow:none;transform:none;cursor:not-allowed}.ios-btn-secondary{background:rgb(var(--color-surface-subtle));color:rgb(var(--color-ink));font-weight:600;border:1px solid var(--color-transparent);transition:all .2s ease;cursor:pointer}.ios-btn-secondary:hover{background:rgb(var(--color-neutral-200));border-color:rgb(var(--color-neutral-300))}.ios-btn-danger{background:rgb(var(--color-danger-100));color:rgb(var(--color-danger-600));font-weight:600;border:1px solid var(--color-transparent);transition:all .2s ease;cursor:pointer}.ios-btn-danger:hover{background:rgb(var(--color-danger-200));border-color:rgb(var(--color-danger-300))}::-webkit-scrollbar{width:6px;height:6px}::-webkit-scrollbar-track{background:var(--color-transparent)}::-webkit-scrollbar-thumb{background:rgb(var(--color-black) / .1);border-radius:10px}::-webkit-scrollbar-thumb:hover{background:rgb(var(--color-black) / .2)}@keyframes fadeIn{0%{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}.animate-fade-in{animation:fadeIn .5s cubic-bezier(.16,1,.3,1) forwards}@keyframes slideUp{0%{opacity:0;transform:translateY(30px) scale(.95)}to{opacity:1;transform:translateY(0) scale(1)}}.animate-slide-up{animation:slideUp .3s cubic-bezier(.16,1,.3,1) forwards}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.animate-spin{animation:spin 1s linear infinite}@keyframes pulse{0%,to{opacity:1}50%{opacity:.5}}.animate-pulse{animation:pulse 2s cubic-bezier(.4,0,.6,1) infinite}::-moz-selection{background:rgb(var(--color-brand));color:rgb(var(--color-white))}::selection{background:rgb(var(--color-brand));color:rgb(var(--color-white))}.text-brand{color:rgb(var(--color-brand))}.bg-brand{background-color:rgb(var(--color-brand))}.border-brand{border-color:rgb(var(--color-brand))}.status-badge{display:inline-flex;align-items:center;padding:4px 12px;border-radius:9999px;font-size:12px;font-weight:600}.status-badge-success{background-color:rgb(var(--color-success-100));color:rgb(var(--color-success-800))}.status-badge-warning{background-color:rgb(var(--color-warning-100));color:rgb(var(--color-warning-800))}.status-badge-error{background-color:rgb(var(--color-danger-100));color:rgb(var(--color-danger-800))}.status-badge-info{background-color:rgb(var(--color-info-100));color:rgb(var(--color-info-800))}.loading-skeleton{background:linear-gradient(90deg,rgb(var(--color-neutral-100)),rgb(var(--color-neutral-200)),rgb(var(--color-neutral-100)));background-size:200% 100%;animation:loading 1.5s ease-in-out infinite}@keyframes loading{0%{background-position:200% 0}to{background-position:-200% 0}}.modal-overlay{position:fixed;top:0;right:0;bottom:0;left:0;z-index:9999;display:flex;align-items:center;justify-content:center;background-color:rgb(var(--color-black) / .4);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);padding:1rem;overflow-y:auto}.modal-container{position:relative;width:100%;max-width:42rem;max-height:85vh;margin:auto;display:flex;flex-direction:column;background-color:rgb(var(--color-white));border-radius:10px;box-shadow:var(--shadow-modal);overflow:hidden}.modal-header{flex-shrink:0;padding:2rem 2rem 1.5rem;border-bottom:1px solid rgb(var(--color-neutral-100));background-color:rgb(var(--color-white));z-index:10}.modal-body{flex:1 1 auto;overflow-y:auto;overflow-x:hidden;padding:2rem}.modal-footer{flex-shrink:0;padding:1.5rem 2rem 2rem;border-top:1px solid rgb(var(--color-neutral-100));background-color:rgb(var(--color-white));z-index:10}.modal-container-lg{max-width:64rem}.modal-overlay-centered{position:fixed;top:0;right:0;bottom:0;left:0;z-index:9999;display:flex;justify-content:center;background-color:rgb(var(--color-black) / .4);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);padding:1rem;overflow-y:auto}.modal-overlay-centered .modal-container{position:relative;width:100%;max-width:42rem;max-height:85vh;margin:auto 0;display:flex;flex-direction:column;background-color:rgb(var(--color-white));border-radius:10px;box-shadow:var(--shadow-modal);overflow:hidden}@media(max-width:768px){.ios-card{border-radius:6px}.ios-input{font-size:16px}.modal-container{max-width:calc(100% - 2rem);max-height:90vh;border-radius:8px}.modal-header,.modal-body,.modal-footer{padding-left:1.5rem;padding-right:1.5rem}}.hover\:bg-blue-700:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-700) / var(--tw-bg-opacity, 1))}.hover\:bg-brand-highlight:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-brand-highlight) / var(--tw-bg-opacity, 1))}.hover\:bg-emerald-600:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-600) / var(--tw-bg-opacity, 1))}.hover\:bg-emerald-700:hover{--tw-bg-opacity: 1;background-color:rgb(var(--color-success-700) / var(--tw-bg-opacity, 1))}@media(min-width:1280px){.xl\:grid-cols-\[minmax\(270px\,0\.72fr\)_minmax\(0\,1\.28fr\)\]{grid-template-columns:minmax(270px,.72fr) minmax(0,1.28fr)}}@media(min-width:1536px){.\32xl\:grid-cols-\[360px_1fr\]{grid-template-columns:360px 1fr}}
diff --git a/internal/webui/static/index.html b/internal/webui/static/index.html
index b45c326..fb1e258 100644
--- a/internal/webui/static/index.html
+++ b/internal/webui/static/index.html
@@ -6,10 +6,10 @@
Ydisks闲鱼助手 - 自动发货与管家系统
-
+
-
+