From 1e6b0593b3558901b7930adffe4cc931ed9d952d Mon Sep 17 00:00:00 2001 From: Christ Date: Fri, 14 Aug 2026 18:49:24 +0800 Subject: [PATCH] =?UTF-8?q?API=E7=89=88=E6=9C=AC=E5=8C=96=EF=BC=9A?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=97=A7=E8=B0=83=E7=94=A8=E6=96=B9=E6=9C=80?= =?UTF-8?q?=E7=BB=88=E5=AE=A1=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .commentlint/frontend-baseline.json | 12 -- docs/architecture/api-versioning-migration.md | 5 +- docs/architecture/refactoring-master-plan.md | 10 +- frontend/components/ItemList.tsx | 2 +- frontend/vite.config.ts | 103 +----------------- frontend/viteConfig.test.ts | 16 ++- internal/server/versioned_item_routes.go | 3 + ...ersioned_remaining_routes_contract_test.go | 3 + .../{index-BN4uXegq.js => index-BBbP32Ar.js} | 2 +- internal/webui/static/index.html | 2 +- 10 files changed, 31 insertions(+), 127 deletions(-) rename internal/webui/static/assets/{index-BN4uXegq.js => index-BBbP32Ar.js} (60%) diff --git a/.commentlint/frontend-baseline.json b/.commentlint/frontend-baseline.json index 31de3c4..6cf4fe8 100644 --- a/.commentlint/frontend-baseline.json +++ b/.commentlint/frontend-baseline.json @@ -16469,18 +16469,6 @@ "kind": "member", "name": "unread_count" }, - { - "file": "vite.config.ts", - "line": 135, - "kind": "member", - "name": "manualChunks" - }, - { - "file": "vite.config.ts", - "line": 136, - "kind": "variable", - "name": "modulePath" - }, { "file": "viteConfig.test.ts", "line": 5, diff --git a/docs/architecture/api-versioning-migration.md b/docs/architecture/api-versioning-migration.md index f385801..b8f8b71 100644 --- a/docs/architecture/api-versioning-migration.md +++ b/docs/architecture/api-versioning-migration.md @@ -8,7 +8,7 @@ | --- | --- | --- | --- | | 会话 | `/login`、`/initialize`、`/verify`、`/logout`、`/change-password`、`/account/credentials` | `/api/v1/session/login`、`/api/v1/session/initialize`、`/api/v1/session`、`/api/v1/session/logout`、`/api/v1/session/password`、`/api/v1/session/credentials` | React 会话、密码修改和登录凭证调用已迁移到版本化入口;旧路径保留并由同一 handler 提供 | | 账号 | `/cookies`、`/cookies/details`、`/cookies/runtime-status`、`/cookies/{cid}/...` | `/api/v1/accounts`、`/api/v1/accounts/details`、`/api/v1/accounts/runtime-status`、`/api/v1/accounts/{cid}/...` | React 摘要、详情、运行状态、启停状态、设置、备注、暂停、自动确认、长登录、资料刷新、Cookie 更新、登录信息设置和删除调用已迁移;旧路径保留并由同一 handler 提供 | -| 商品 | `/items...` | `/api/v1/items...` | React 列表、详情、创建、发布、更新、删除、同步、类目推荐和批量发布调用已迁移;旧路径保留并由同一 handler 提供 | +| 商品 | `/items...` | `/api/v1/items...` | React 列表、按账号列表、详情、创建、发布、更新、删除、多规格/多数量设置、同步、类目推荐和批量发布调用已迁移;旧路径保留并由同一 handler 提供 | | 商品批量 | `/items/publish-batches...` | `/api/v1/items/publish-batches...` | 旧路径保留,类目推荐/预检/任务 DTO 已落地 | | 自动化 | `/automation-rules...`、`/automation-issues`、`/automation-runs...`、`/automation-pending-tasks...` | `/api/v1/automation-rules...`、`/api/v1/automation-issues`、`/api/v1/automation-runs...`、`/api/v1/automation-pending-tasks...` | React 规则分页、增删改、异常查询和异常处理调用已迁移;旧路径保留并由同一 handler 提供 | | 订单 | `/api/orders...` | `/api/v1/orders...` | React 列表、详情、更新、删除、刷新、单订单刷新、手动发货和导入调用已迁移;旧路径保留并由同一 handler 提供 | @@ -48,7 +48,7 @@ - 账号摘要、非敏感详情、运行状态、启停状态、设置、备注、暂停、自动确认、长登录、资料刷新、Cookie 更新和登录信息设置已由 React 请求层迁移到 `/api/v1/accounts...`;Go 契约测试确认账号详情与凭证变更响应不泄露 Cookie/密码,且旧详情、设置和登录信息入口仍可用。 - 订单列表、详情和更新已由 React 请求层迁移到 `/api/v1/orders...`;Go 契约测试确认版本化入口与旧更新入口共用 handler,订单归属校验和状态更新语义保持不变。 - 订单刷新、单订单刷新、手动发货和导入已由 React 请求层迁移到 `/api/v1/orders...`;Go 契约测试确认新旧批量入口保持状态码、具名响应和参数校验语义一致。 -- 商品列表、详情、发布、更新和删除已由 React 请求层迁移到 `/api/v1/items...`;Go 契约测试确认新旧入口保持商品所有权校验、具名响应和持久化语义一致。 +- 商品列表、按账号列表、详情、创建、发布、更新、删除、多规格/多数量设置已由版本化路由提供,React 请求层已迁移实际调用;Go 契约测试确认新旧入口保持商品所有权校验、具名响应和持久化语义一致。 - 商品同步、类目推荐、批量发布预检、任务查询、取消、重试和结果下载已由版本化路由提供;React 现有同步/批量发布调用已迁移,Go 契约测试确认新旧入口状态码和参数校验语义一致。 - 系统/用户/AI 设置、卡券 CRUD/批量/追加和通知渠道/消息/账号绑定已由版本化路由提供;React 设置、卡券和通知调用已迁移,Go 契约测试确认新旧入口权限、状态码和参数校验语义一致。 - 聊天会话、消息、图片、已读和 WebSocket,以及账号任务设置、运行记录和执行已由版本化路由提供;React REST/WebSocket 调用已迁移,Go 契约测试确认新旧入口权限、状态码和参数校验语义一致。 @@ -59,3 +59,4 @@ - 聊天会话、消息分页和发送结果使用独立 DTO,不直接暴露数据库模型。 - React `frontend/types.ts` 与 `frontend/services/api.ts` 已同步具名成功响应类型,同时保留旧字段归一逻辑。 - 会话、账号、订单、商品、自动化、设置、卡券、通知、聊天、账号任务、关键词、默认回复、管理员、统计、二维码登录和密码登录版本化入口已可用;旧路径继续保留。 +- 最终调用方审计确认 React 生产请求、批量结果下载和 Vite 开发代理均不再使用业务旧路径;旧路径仅作为服务端兼容入口保留,后续删除必须遵循调用方、发布日期和回滚条件记录。 diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index 5e1969d..2a9914f 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -92,8 +92,8 @@ app shell / routes | 0. 治理文档与强约束 | 已完成 | 总计划、依赖规则、注释规范、AGENTS 门禁、注释检查器 | 文档、门禁规则、Go/TypeScript 检查器和历史基线已落盘 | | 1. PR CI 与测试基础 | 已完成 | 独立 CI、测试 DB 模板、可执行 race | CI、独立模板、server smoke race 和完整 race 均有验证 | | 2. 敏感数据访问边界 | 已完成 | 摘要、凭证、登录秘密分离 | 生产完整详情白名单、所有权/凭证锁审计、SQLite/MySQL/Postgres 窄查询回归和全量门禁已完成 | -| 3. HTTP API 契约 | 进行中 | 统一错误、具名 DTO、版本化路径 | 统一错误 DTO、认证/公共 API 错误迁移及契约测试已完成;继续迁移业务 API | -| 4. Server 应用服务 | 未开始 | 订单、发布、登录、聊天纵向抽取 | handler 不再直接编排基础设施 | +| 3. HTTP API 契约 | 已完成 | 统一错误、具名 DTO、版本化路径 | 统一错误 DTO、具名成功 DTO、所有前端业务调用方版本化、旧路径兼容和最终审计均已完成 | +| 4. Server 应用服务 | 进行中 | 订单、发布、登录、聊天纵向抽取 | 订单应用服务切片开始,目标是让 handler 不再直接编排基础设施 | | 5. 应用生命周期装配 | 未开始 | 消除必需依赖 setter 回填 | 构造验证与幂等关闭测试 | | 6. Engine 与 Automation | 未开始 | facade + 独立状态组件 | race、生命周期与冻结规范测试 | | 7. React Feature 化 | 未开始 | 页面、Hook、API、类型按领域拆分 | 行为测试、懒加载和 bundle 记录 | @@ -103,7 +103,7 @@ app shell / routes ### 当前执行入口 -- 当前阶段:阶段 3“HTTP API 契约”(进行中); +- 当前阶段:阶段 4“Server 应用服务”(进行中);阶段 3 HTTP API 契约已完成最终审计; - 已完成:总计划、依赖规则、中文注释规范、`AGENTS.md` 强约束,以及 Go/TypeScript AST 注释检查器和历史基线; - 阶段 1 已完成:server 测试模板预置管理员和账号 cookie,普通测试约 21.3 秒,完整 server race 约 194.3 秒通过; - 已完成阶段 2 逻辑切片一“Repository 敏感数据边界”:建立 `CookieSummary`、`ListOwnedIDs`、`ExistsOwned`、`GetOwnerID`、`GetSummaryOwned` 和原子 `GetValueOwned`,覆盖跨用户、无效 user ID 及无效密文回归; @@ -152,7 +152,8 @@ app shell / routes - 已完成阶段 3 第二十三个 PR 切片“管理员、仪表盘与订单分析 API 版本化兼容入口迁移”:新增管理员用户/账号/统计、仪表盘统计、订单分析和有效订单 `/api/v1/admin...`、`/api/v1/analytics...` 薄适配入口,复用既有管理员权限与统计 handler;React 管理员统计、仪表盘和订单分析调用已迁移,旧路径保留;新增管理员/统计契约测试并保持独立可回滚提交; - 已完成阶段 3 第二十四个 PR 切片“二维码登录 API 版本化兼容入口迁移”:新增二维码生成、状态查询、状态持久化和验证完成 `/api/v1/qr-login...` 薄适配入口,复用既有认证、会话所有权和敏感字段过滤 handler;React 二维码生成、轮询和验证完成调用已迁移,旧路径保留;新增二维码新旧入口契约测试并保持独立可回滚提交; - 已完成阶段 3 第二十五个 PR 切片“密码登录及剩余公共调用方 API 版本化兼容入口迁移”:新增会话密码/凭证、账号删除、密码登录禁用、自动化规则/异常处理、订单删除和商品创建 `/api/v1/...` 薄适配入口,复用既有认证、权限和业务 handler;React 对应调用已迁移,旧路径保留;新增剩余公共调用方 Go/React 契约测试并保持独立可回滚提交; -- 阶段 3 下一 PR 切片为“版本化入口最终审计与旧调用方清零”:扫描前端、Vite 代理、服务端路由和测试中的业务旧路径,补齐必要的版本化兼容入口与调用方迁移证据,确认阶段 3 完成条件后再进入阶段 4,不拆分单个 handler 提交; +- 已完成阶段 3 第二十六个 PR 切片“版本化入口最终审计与旧调用方清零”:前端生产调用和批量结果下载已无业务旧路径;Vite 代理收敛为 `/api` 与健康检查;服务端剩余商品兼容入口已补齐;新增旧代理别名和商品遗漏入口审计证据,阶段 3 完成条件满足并保持独立可回滚提交; +- 阶段 4 下一 PR 切片为“订单应用服务边界提取”:围绕订单列表、详情、更新、删除、刷新、导入和手动发货提取不依赖 `net/http` 的应用服务,保留 DTO/权限契约和事务不变量,不拆分单个 handler 提交; - 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。 ## 6. 阶段 0:治理文档与强约束 @@ -554,3 +555,4 @@ npm --prefix frontend run build | 2026-08-14 | 完成阶段 3 第二十三个 PR 切片“管理员、仪表盘与订单分析 API 版本化兼容入口迁移” | 新增管理员用户/账号/统计、仪表盘统计、订单分析和有效订单 `/api/v1/admin...`、`/api/v1/analytics...` 薄适配入口,复用既有权限边界与 handler;React 管理员统计、仪表盘和订单分析调用已迁移;Go/React 契约测试确认新旧入口兼容;全量门禁通过并合并为一个可回滚提交 | 阶段 3:二维码登录 API 版本化兼容入口迁移 | | 2026-08-14 | 完成阶段 3 第二十四个 PR 切片“二维码登录 API 版本化兼容入口迁移” | 新增二维码生成、状态查询、状态持久化和验证完成 `/api/v1/qr-login...` 薄适配入口,复用既有认证、会话所有权和敏感字段过滤 handler;React 二维码生成、轮询和验证完成调用已迁移;Go/React 契约测试确认新旧入口兼容;全量门禁通过并合并为一个可回滚提交 | 阶段 3:密码登录及剩余公共调用方 API 版本化兼容入口迁移 | | 2026-08-14 | 完成阶段 3 第二十五个 PR 切片“密码登录及剩余公共调用方 API 版本化兼容入口迁移” | 新增会话密码/凭证、账号删除、密码登录禁用、自动化规则/异常处理、订单删除和商品创建 `/api/v1/...` 薄适配入口,复用既有认证、权限和业务 handler;React 对应调用已迁移;Go/React 契约测试确认新旧入口兼容;全量门禁通过并合并为一个可回滚提交 | 阶段 3:版本化入口最终审计与旧调用方清零 | +| 2026-08-14 | 完成阶段 3 第二十六个 PR 切片“版本化入口最终审计与旧调用方清零” | 前端生产调用和批量结果下载已无业务旧路径;Vite 代理收敛为 `/api` 与健康检查;服务端补齐商品按账号列表、多规格和多数量兼容入口;Go/React/Vite 审计测试、全量测试、race、vet、lint、注释和构建门禁通过并合并为一个可回滚提交 | 阶段 4:订单应用服务边界提取 | diff --git a/frontend/components/ItemList.tsx b/frontend/components/ItemList.tsx index 5b219d3..6fbf4ba 100644 --- a/frontend/components/ItemList.tsx +++ b/frontend/components/ItemList.tsx @@ -1320,7 +1320,7 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { 正在保存远端结果并安全取消… ) : ( - )} diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index d82b65e..8c7a9a5 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -14,107 +14,6 @@ export default defineConfig({ changeOrigin: true, ws: true, }, - // 代理其他后端请求 - '/cookies': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/account': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/qr-login': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/password-login': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/keywords': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/keywords-with-item-id': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/default-reply': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/items': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/cards': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/automation-rules': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/automation-issues': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/automation-runs': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/automation-pending-tasks': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/notification-channels': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/message-notifications': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/ai-reply-settings': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/ai-models': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/system-settings': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/user-settings': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/admin': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/analytics': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/login': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/verify': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/logout': { - target: 'http://localhost:59188', - changeOrigin: true, - }, - '/change-password': { - target: 'http://localhost:59188', - changeOrigin: true, - }, '/health': { target: 'http://localhost:59188', changeOrigin: true, @@ -132,7 +31,9 @@ export default defineConfig({ sourcemap: false, rollupOptions: { output: { + // manualChunks 按依赖领域拆分生产构建文件,控制首屏资源体积。 manualChunks(id) { + // modulePath 是统一分隔符后的模块绝对路径,用于稳定匹配依赖目录。 const modulePath = id.split(path.sep).join('/'); if (!modulePath.includes('/node_modules/')) { return undefined; diff --git a/frontend/viteConfig.test.ts b/frontend/viteConfig.test.ts index 1b89da2..6d0d193 100644 --- a/frontend/viteConfig.test.ts +++ b/frontend/viteConfig.test.ts @@ -2,11 +2,17 @@ import { expect, test } from 'vitest'; import type { UserConfig } from 'vite'; import config from './vite.config'; -test('development server proxies every automation API prefix', () => { +test('development server proxies versioned API and health checks', () => { const proxy = (config as UserConfig).server?.proxy; expect(proxy).toBeDefined(); - expect(proxy).toHaveProperty('/automation-rules'); - expect(proxy).toHaveProperty('/automation-issues'); - expect(proxy).toHaveProperty('/automation-runs'); - expect(proxy).toHaveProperty('/automation-pending-tasks'); + expect(proxy).toHaveProperty('/api'); + expect(proxy).toHaveProperty('/health'); + expect(proxy).not.toHaveProperty('/automation-rules'); + expect(proxy).not.toHaveProperty('/automation-issues'); + expect(proxy).not.toHaveProperty('/automation-runs'); + expect(proxy).not.toHaveProperty('/automation-pending-tasks'); + expect(proxy).not.toHaveProperty('/password-login'); + expect(proxy).not.toHaveProperty('/qr-login'); + expect(proxy).not.toHaveProperty('/items'); + expect(proxy).not.toHaveProperty('/cookies'); }); diff --git a/internal/server/versioned_item_routes.go b/internal/server/versioned_item_routes.go index f8ec4cf..a136441 100644 --- a/internal/server/versioned_item_routes.go +++ b/internal/server/versioned_item_routes.go @@ -12,10 +12,13 @@ func (s *Server) mountVersionedItems(r chi.Router) { r.Use(s.Auth.Middleware) r.Use(auth.RequireAuth) r.Get("/api/v1/items", s.listItems) + r.Get("/api/v1/items/cookie/{cookie_id}", s.listItemsByCookie) r.Get("/api/v1/items/{cookie_id}/{item_id}", s.getItem) r.Post("/api/v1/items/{cookie_id}", s.createItem) r.Post("/api/v1/items/publish", s.publishItem) r.Put("/api/v1/items/{cookie_id}/{item_id}", s.updateItem) r.Delete("/api/v1/items/{cookie_id}/{item_id}", s.deleteItem) + r.Put("/api/v1/items/{cookie_id}/{item_id}/multi-spec", s.setItemMultiSpec) + r.Put("/api/v1/items/{cookie_id}/{item_id}/multi-quantity-delivery", s.setItemMultiQuantity) }) } diff --git a/internal/server/versioned_remaining_routes_contract_test.go b/internal/server/versioned_remaining_routes_contract_test.go index f1778b1..49e9f54 100644 --- a/internal/server/versioned_remaining_routes_contract_test.go +++ b/internal/server/versioned_remaining_routes_contract_test.go @@ -59,6 +59,9 @@ func TestVersionedRemainingRoutesPreserveLegacyContracts(t *testing.T) { {name: "automation-task-resolve", method: http.MethodPost, versionedPath: "/api/v1/automation-pending-tasks/invalid/resolve", legacyPath: "/automation-pending-tasks/invalid/resolve", body: `{}`, wantStatus: http.StatusBadRequest}, {name: "delete-order", method: http.MethodDelete, versionedPath: "/api/v1/orders/missing-order", legacyPath: "/api/orders/missing-order", wantStatus: http.StatusNotFound}, {name: "create-item", method: http.MethodPost, versionedPath: "/api/v1/items/missing-account", legacyPath: "/items/missing-account", body: `{}`, wantStatus: http.StatusNotFound}, + {name: "list-items-by-cookie", method: http.MethodGet, versionedPath: "/api/v1/items/cookie/missing-account", legacyPath: "/items/cookie/missing-account", wantStatus: http.StatusNotFound}, + {name: "set-item-multi-spec", method: http.MethodPut, versionedPath: "/api/v1/items/missing-account/item/multi-spec", legacyPath: "/items/missing-account/item/multi-spec", body: `{}`, wantStatus: http.StatusNotFound}, + {name: "set-item-multi-quantity", method: http.MethodPut, versionedPath: "/api/v1/items/missing-account/item/multi-quantity-delivery", legacyPath: "/items/missing-account/item/multi-quantity-delivery", body: `{}`, wantStatus: http.StatusNotFound}, } for _, routeCase := range cases { // routeCase 是当前正在执行的剩余公共路由样例。 // versionedStatus 是版本化入口实际返回的状态码。 diff --git a/internal/webui/static/assets/index-BN4uXegq.js b/internal/webui/static/assets/index-BBbP32Ar.js similarity index 60% rename from internal/webui/static/assets/index-BN4uXegq.js rename to internal/webui/static/assets/index-BBbP32Ar.js index 1948ac8..6f24858 100644 --- a/internal/webui/static/assets/index-BN4uXegq.js +++ b/internal/webui/static/assets/index-BBbP32Ar.js @@ -16,4 +16,4 @@ CODE-789012 `).filter(x=>x.trim()).length})," 条"]})]}),j.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 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-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:j.api_method,onChange:x=>F({...j,api_method:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:j.api_timeout,onChange:x=>F({...j,api_timeout:parseInt(x.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),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:"请求头(JSON)"}),e.jsx("textarea",{value:j.api_headers,onChange:x=>F({...j,api_headers:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:j.api_params,onChange:x=>F({...j,api_params:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] 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",{value:j.description,onChange:x=>F({...j,description:x.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:j.delay_seconds,onChange:x=>F({...j,delay_seconds:parseInt(x.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>_(!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:p,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(et,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),G&&qe.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:()=>me(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(Me,{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:()=>v("create"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${oe==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(tl,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>v("append"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${oe==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Dt,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),oe==="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:he,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(sl,{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(Dt,{className:"w-4 h-4"}),q?q.name:"选择 .xlsx / .csv / .tsv",e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv",className:"hidden",onChange:x=>{var V;return ce(((V=x.target.files)==null?void 0:V[0])||null)}})]})]}),Q&&!Q.error&&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:["共 ",Q.total," 行 · 成功 ",Q.created," · 失败 ",Q.failed]}),Q.failed>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:Q.rows.filter(x=>!x.success).map(x=>e.jsxs("div",{className:"text-xs text-red-600",children:["第 ",x.row_no," 行「",x.name,"」:",x.error]},x.row_no))})]})]}):e.jsx("div",{className:"space-y-4",children:M.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:ue,onChange:x=>k(x.target.value),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",children:M.map(x=>e.jsxs("option",{value:String(x.id),children:[x.name,"(ID: ",x.id,")"]},x.id))})]}),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:Z,onChange:x=>se(x.target.value),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.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),K&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",K.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:()=>me(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),oe==="create"?e.jsxs("button",{onClick:ye,disabled:!q||B,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[B?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(Dt,{className:"w-4 h-4"}),B?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:Ee,disabled:!ue||!Z.trim()||B||M.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[B?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(et,{className:"w-4 h-4"}),B?"处理中...":"追加卡密"]})]})]})}),document.body)]})},mn=t=>t.find(a=>a.status==="running"||a.status==="canceling"),la="ydisks-amap-js-api",pn="c9b68d4ce9a2a97f22a4a439404488ca";let $t=null;const un=()=>pn,hn=()=>window.AMap?Promise.resolve(window.AMap):$t||($t=new Promise((t,a)=>{const l=document.getElementById(la),i=l||document.createElement("script"),m=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(N)},_=()=>{window.AMap?(m(),t(window.AMap)):(m(),a(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},N=window.setTimeout(()=>{m(),a(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=_,i.id=la,i.async=!0,i.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(un())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,i.onerror=()=>{m(),a(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},l||document.head.appendChild(i)}).catch(t=>{throw $t=null,t}),$t),Ht=t=>Number.isFinite(t)&&t!==0,gn=t=>{var m,_;const a=Number((m=t.location)==null?void 0:m.lng),l=Number((_=t.location)==null?void 0:_.lat),i={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:a,latitude:l,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!i.division_id||!i.province||!i.city||!i.poi_id||!i.poi_name||!Ht(a)||!Ht(l)||a<-180||a>180||l<-90||l>90?null:i},bn=async(t,a)=>{if(!Ht(t)||!Ht(a)||t<-180||t>180||a<-90||a>90)throw new Error("经纬度无效");const l=await hn();return new Promise((i,m)=>{new l.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,a],1e3,(N,R)=>{var C;if(N!=="complete"){if(N==="no_data"){i([]);return}m(new Error("高德地图附近地址查询失败,请稍后重试"));return}const g=(((C=R==null?void 0:R.poiList)==null?void 0:C.pois)||[]).map(gn).filter(j=>j!==null);i(g)})})},fn=t=>{const a=String(t||"").trim();return a?/^[¥¥]/.test(a)?a:`¥${a}`:"-"},yn=({onConfigureDelivery:t})=>{const[a,l]=r.useState([]),[i,m]=r.useState([]),[_,N]=r.useState([]),[R,g]=r.useState(""),[C,j]=r.useState(""),[F,G]=r.useState(!1),[me,oe]=r.useState(!1),[v,q]=r.useState(!1),[ce,Q]=r.useState(!1),[ee,B]=r.useState(!1),[ge,ue]=r.useState(!1),[k,Z]=r.useState(!1),[se,K]=r.useState("upload"),[ve,J]=r.useState(null),[I,E]=r.useState(null),[$,be]=r.useState(""),[Re,ae]=r.useState(!1),[T,p]=r.useState(!1),[b,U]=r.useState([]),[M,ne]=r.useState(null),[he,ye]=r.useState([]),[Ee,ke]=r.useState(null),[x,V]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[X,c]=r.useState(null),[d,D]=r.useState(null),[S,Y]=r.useState(null),O=r.useRef(!1),[de,Se]=r.useState(null),[fe,Oe]=r.useState({}),[re,h]=r.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[f,P]=r.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[z,Ie]=r.useState([]);r.useEffect(()=>{if(!ge||f.images.length===0){Ie([]);return}const n=f.images.map((w,H)=>({key:w.name+H,url:URL.createObjectURL(w)}));return Ie(n),()=>{n.forEach(w=>URL.revokeObjectURL(w.url))}},[ge,f.images]);const Ae=async()=>{const n=await vt();l(n)},we=async()=>{m(await gs())};r.useEffect(()=>{Promise.all([Ft(),vt(),gs(),Hs(20)]).then(([n,w,H,Te])=>{N(n),l(w),m(H);const s=Te.find(o=>["running","canceling"].includes(o.status))||Te.find(o=>o.status!=="preview");Y(s||null)}).catch(n=>console.error("加载商品配置失败:",n))},[]),r.useEffect(()=>{if(!k||!(d!=null&&d.id)||!["running","canceling"].includes(d.status))return;const n=window.setInterval(async()=>{if(!O.current){O.current=!0;try{const w=await bt(d.id);D(w),Y(w),["running","canceling"].includes(w.status)||(K("done"),await Ae(),await we())}catch(w){console.error("刷新批量铺货进度失败:",w)}finally{O.current=!1}}},3e3);return()=>{window.clearInterval(n)}},[k,d==null?void 0:d.id,d==null?void 0:d.status]);const De=async()=>{if(!R)return alert("请先选择账号");G(!0);try{const n=await hr(R);await Ae(),alert((n==null?void 0:n.message)||"商品同步完成")}catch(n){console.error("同步商品失败:",n),alert((n==null?void 0:n.message)||"同步失败,请重试")}finally{G(!1)}},te=n=>{Se(n),Oe({...n}),Q(!0)},je=async()=>{if(de)try{await kr(de.cookie_id,de.item_id,{item_title:fe.item_title||"",item_description:fe.item_description||"",item_category:fe.item_category||"",item_price:fe.item_price||"",item_detail:fe.item_detail||de.item_detail||""}),await Ae(),await we(),Q(!1),Se(null)}catch(n){console.error("更新商品失败:",n),alert("更新失败,请重试")}},u=async n=>{if(confirm(`确认删除商品"${n.item_title}"吗?`))try{await gr(n.cookie_id,n.item_id),l(w=>w.filter(H=>!(H.cookie_id===n.cookie_id&&H.item_id===n.item_id)))}catch(w){console.error("删除商品失败:",w),alert("删除失败,请重试")}},L=async()=>{try{if(!re.cookie_id||!re.item_id){alert("请选择账号并填写商品ID");return}await br(re.cookie_id,{item_id:re.item_id,item_title:re.item_title,item_price:re.item_price,item_detail:re.item_image?JSON.stringify({item_image:re.item_image}):""}),await Ae(),B(!1),h({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(n){console.error("添加商品失败:",n),alert("添加失败,请重试")}},le=async()=>{if(!f.cookie_id)return alert("请选择发布账号");if(!f.title.trim())return alert("请填写商品标题");if(!f.price.trim())return alert("请填写商品价格");if(!f.quantity||Number(f.quantity)<=0)return alert("库存数量必须大于 0");if(f.images.length===0)return alert("至少上传 1 张商品图片");if(f.postage_mode==="fixed"&&!f.postage.trim())return alert("请填写一口价邮费");oe(!0);try{const n=await fr({...f,location:M||void 0});if(await Ae(),ue(!1),P({cookie_id:R||"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),U([]),ne(null),n!=null&&n.item_id){const w={id:n.item_id,cookie_id:f.cookie_id,item_id:n.item_id,item_title:n.item_title||f.title,item_price:n.item_price||f.price,item_image:n.item_image};t(w),alert("商品发布成功,ID: "+n.item_id+",已为你打开发货规则配置")}else alert("商品发布成功")}catch(n){console.error("发布商品失败:",n);const w=n==null?void 0:n.payload;if((w==null?void 0:w.code)==="stock_permission_missing"){alert("发布失败:该账号没有库存发布权限,无法按库存数量发布商品。请换账号或先在闲鱼确认库存能力。");return}alert((n==null?void 0:n.message)||"发布失败,请重试")}finally{oe(!1)}},Ne=async()=>{K("upload"),c(null),D(null),J(null),E(null),be(""),V({catId:"",catName:"",channelCatId:"",tbCatId:""}),ye([]),ke(null),Z(!0),q(!0);try{const n=await Hs(20),w=mn(n);if(w!=null&&w.id){const H=await bt(w.id);Y(H),D(H),K(["running","canceling"].includes(H.status)?"running":"done")}}catch(n){console.error("恢复最近批量铺货任务失败:",n)}finally{q(!1)}},Ue=async()=>{const n=$.trim();if(!R)return alert("请先选择默认发布账号");if(!n)return alert("请输入类目关键词");ae(!0);try{const H=(await yr(R,n)).category;V({catId:H.cat_id,catName:H.cat_name,channelCatId:H.channel_cat_id,tbCatId:H.tb_cat_id||""})}catch(w){console.error("获取推荐类目失败:",w),alert((w==null?void 0:w.message)||"没有匹配到类目,请换一个更具体的关键词")}finally{ae(!1)}},Fe=async()=>{if(S!=null&&S.id){q(!0),Z(!0);try{const n=await bt(S.id);D(n),K(["running","canceling"].includes(n.status)?"running":"done")}catch(n){console.error("加载最近批量铺货结果失败:",n)}finally{q(!1)}}},tt=async()=>{if(!ve)return alert("请先上传商品表格");if(!R)return alert("请先选择默认发布账号");q(!0);try{const n=await jr({file:ve,imagesZip:I,defaultCookieId:R,fallbackCategory:x,location:Ee||void 0});c(n),D(null),K("preview")}catch(n){console.error("批量铺货预检失败:",n),alert((n==null?void 0:n.message)||"预检失败,请检查表格和图片 zip")}finally{q(!1)}},kt=async()=>{if(X!=null&&X.preview_id){if(X.valid<=0)return alert("没有可发布的商品行");q(!0);try{const n=await Nr(X.preview_id),w=await bt(n.batch_id||X.preview_id);D(w),Y(w),K(w.status==="running"?"running":"done")}catch(n){console.error("启动批量铺货失败:",n),alert((n==null?void 0:n.message)||"启动发布任务失败")}finally{q(!1)}}},Je=async()=>{if(d!=null&&d.id&&confirm("确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。")){q(!0);try{const n=await vr(d.id),w=await bt(d.id);D(w),K((n==null?void 0:n.status)==="canceling"||w.status==="canceling"?"running":"done")}catch(n){alert((n==null?void 0:n.message)||"取消失败")}finally{q(!1)}}},We=async()=>{const n=X==null?void 0:X.preview_id;if(n&&se==="preview")try{await _r(n)}catch(w){console.error("清理批量铺货预检失败:",w)}c(null),K("upload")},Ct=async()=>{await We(),Z(!1)},St=async()=>{if(d!=null&&d.id){q(!0);try{await wr(d.id),D(await bt(d.id)),K("running")}catch(n){alert((n==null?void 0:n.message)||"重试失败")}finally{q(!1)}}},mt=()=>{const H=[["账号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(y=>y.map(A=>`"${String(A).replace(/"/g,'""')}"`).join(",")).join(` -`),Te=new Blob(["\uFEFF"+H],{type:"text/csv;charset=utf-8"}),s=URL.createObjectURL(Te),o=document.createElement("a");o.href=s,o.download="批量铺货模板.csv",document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(s)},Lt=()=>{h(n=>({...n,cookie_id:R||n.cookie_id})),B(!0)},nt=()=>{P(n=>({...n,cookie_id:R||n.cookie_id})),ue(!0)},it=async n=>{if(!(n?R:f.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");p(!0),navigator.geolocation.getCurrentPosition(async H=>{try{const Te=await bn(H.coords.longitude,H.coords.latitude);if(!Te.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");n?(ye(Te),ke(Te[0])):(U(Te),ne(Te[0]))}catch(Te){alert((Te==null?void 0:Te.message)||"获取发货地失败")}finally{p(!1)}},H=>{p(!1),alert(H.code===H.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},Ot=n=>i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id).length>0?i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id):i.filter(w=>w.cookie_id===n.cookie_id&&!w.item_id),pt=n=>{switch(n){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 n||"-"}},ut=n=>{switch(n){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"}},st=r.useMemo(()=>new Map(_.map(n=>[n.id,n])),[_]),ht=r.useMemo(()=>C?a.filter(n=>n.cookie_id===C):a,[C,a]),Ge=n=>{const w=st.get(n),H=(w==null?void 0:w.remark)||(w==null?void 0:w.nickname);return H?`${H} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},ot=n=>{const w=st.get(n);return(w==null?void 0:w.remark)||(w==null?void 0:w.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(ll,{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:C,onChange:n=>j(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.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(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-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:R,onChange:n=>g(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:De,disabled:F||!R,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(ze,{className:`w-4 h-4 ${F?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Lt,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(et,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:nt,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(es,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Ne(),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(Bt,{className:"w-4 h-4"}),S&&["running","canceling"].includes(S.status)?"继续批量任务":"批量铺货"]}),S&&!["running","canceling"].includes(S.status)&&e.jsx("button",{onClick:()=>void Fe(),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:[ht.map(n=>{const w=Ot(n),H=w.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:()=>te(n),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(Nt,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>u(n),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(Qe,{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:[n.item_image?e.jsx("img",{src:n.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(ga,{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:fn(n.item_price)})]}),e.jsx("h3",{className:"font-bold text-gray-900 line-clamp-2 text-xs mb-1.5 h-8 leading-4",children:n.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:ot(n.cookie_id),children:[e.jsx(xt,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:ot(n.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: ",n.item_id]}),e.jsxs("span",{className:`inline-flex items-center gap-1 font-bold ${H?"text-emerald-600":"text-amber-600"}`,children:[H?e.jsx(ds,{className:"w-3 h-3"}):e.jsx(rl,{className:"w-3 h-3"}),H?`${w.length} 规则`:"未配置"]})]}),e.jsx("div",{className:"space-y-2 mt-auto",children:e.jsxs("button",{onClick:()=>t(n),className:`w-full flex items-center justify-between gap-1 px-2.5 py-2 rounded-lg text-[11px] font-extrabold transition-all ${H?"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(nl,{className:"w-3.5 h-3.5"}),H?"查看发货规则":"关联发货规则"]}),e.jsx(xs,{className:"w-3.5 h-3.5"})]})})]},`${n.cookie_id}-${n.item_id}`)}),ht.length===0&&e.jsxs("div",{className:"col-span-full py-20 text-center text-gray-400",children:[e.jsx(ba,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),C?"该账号暂无商品数据":"暂无商品数据,请选择账号进行同步"]})]}),ce&&de&&qe.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: ",de.item_id]})]}),e.jsx("button",{onClick:()=>Q(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(Me,{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:fe.item_title||"",onChange:n=>Oe({...fe,item_title:n.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"价格",value:fe.item_price||"",onChange:n=>Oe({...fe,item_price:n.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"分类",value:fe.item_category||"",onChange:n=>Oe({...fe,item_category:n.target.value})}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述",value:fe.item_description||"",onChange:n=>Oe({...fe,item_description:n.target.value})})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:je,className:"w-full 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),ee&&qe.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:()=>B(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(Me,{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:re.cookie_id,onChange:n=>h({...re,cookie_id:n.target.value}),children:[e.jsx("option",{value:"",children:"选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.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:re.item_id,onChange:n=>h({...re,item_id:n.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:re.item_price,onChange:n=>h({...re,item_price:n.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:re.item_title,onChange:n=>h({...re,item_title:n.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:re.item_image,onChange:n=>h({...re,item_image:n.target.value})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:L,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(et,{className:"w-4 h-4"}),"添加商品"]})})]})}),document.body),ge&&qe.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:()=>ue(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(Me,{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:f.cookie_id,onChange:n=>{P({...f,cookie_id:n.target.value}),U([]),ne(null)},children:[e.jsx("option",{value:"",children:"选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.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:f.title,onChange:n=>P({...f,title:n.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:f.quantity,onChange:n=>P({...f,quantity:n.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:f.description,onChange:n=>P({...f,description:n.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:f.price,onChange:n=>P({...f,price:n.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:f.original_price,onChange:n=>P({...f,original_price:n.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:f.postage_mode,onChange:n=>P({...f,postage_mode:n.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:"无需邮寄"})]})]})]}),f.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:f.postage,onChange:n=>P({...f,postage:n.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:T||!f.cookie_id,onClick:()=>void it(!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(Ms,{className:"h-4 w-4"}),T?"定位中...":"获取当前位置"]})]}),b.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,b.indexOf(M))),onChange:n=>ne(b[Number(n.target.value)]||null),children:b.map((n,w)=>e.jsx("option",{value:String(w),children:[n.province,n.city,n.area,n.poi_name].filter(Boolean).join(" ")},`${n.division_id}-${n.poi_id}-${w}`))})]}),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(Bt,{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:f.images.length?"已选择 "+f.images.length+" 张":"支持 JPG / PNG / GIF"}),e.jsx("input",{className:"hidden",type:"file",accept:"image/*",multiple:!0,onChange:n=>P({...f,images:Array.from(n.target.files||[]).slice(0,9)})})]}),z.length>0&&e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-3",children:z.map(n=>e.jsx("div",{className:"aspect-square rounded-xl bg-gray-100 overflow-hidden border border-gray-100",children:e.jsx("img",{src:n.url,alt:"",className:"w-full h-full object-cover"})},n.key))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{disabled:me,onClick:le,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(es,{className:"w-4 h-4"}),me?"正在发布...":"发布到闲鱼"]})})]})}),document.body),k&&qe.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 Ct(),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(Me,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx("div",{className:"grid grid-cols-4 gap-2",children:[["upload","1 上传"],["preview","2 预检"],["running","3 发布"],["done","4 结果"]].map(([n,w])=>e.jsx("div",{className:`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${se===n?"bg-blue-600 text-white border-blue-600":"bg-gray-50 text-gray-500 border-gray-100"}`,children:w},n))}),se==="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:mt,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:R,onChange:n=>{g(n.target.value),ye([]),ke(null)},children:[e.jsx("option",{value:"",children:"选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.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(_t,{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:$,onChange:n=>be(n.target.value),onKeyDown:n=>{n.key==="Enter"&&(n.preventDefault(),Ue())}})]}),e.jsxs("button",{type:"button",disabled:!R||!$.trim()||Re,onClick:()=>void Ue(),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(_t,{className:"h-4 w-4"}),Re?"匹配中...":"获取类目"]})]}),x.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(ds,{className:"h-4 w-4 shrink-0 text-emerald-600"}),e.jsx("span",{className:"truncate",children:x.catName})]}),e.jsxs("div",{className:"mt-1 font-mono text-xs text-gray-500",children:["类目 ",x.catId," · 频道 ",x.channelCatId]})]}),e.jsx("button",{type:"button",title:"清除默认类目",onClick:()=>V({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(Me,{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:T||!R,onClick:()=>void it(!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(Ms,{className:"h-4 w-4"}),T?"定位中...":"获取当前位置"]})]}),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(Ee))),onChange:n=>ke(he[Number(n.target.value)]||null),children:he.map((n,w)=>e.jsx("option",{value:String(w),children:[n.province,n.city,n.area,n.poi_name].filter(Boolean).join(" ")},`${n.division_id}-${n.poi_id}-${w}`))})]}),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(Bt,{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:ve?ve.name:"支持 .xlsx / .csv / .tsv"}),e.jsx("input",{className:"hidden",type:"file",accept:".xlsx,.csv,.tsv",onChange:n=>{var w;return J(((w=n.target.files)==null?void 0:w[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(Bt,{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:I?I.name:"表格图片字段使用 zip 内相对路径"}),e.jsx("input",{className:"hidden",type:"file",accept:".zip",onChange:n=>{var w;return E(((w=n.target.files)==null?void 0:w[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(([n,w,H])=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-bold text-gray-900 whitespace-nowrap",children:n}),e.jsx("td",{className:`px-3 py-2 min-w-[210px] font-bold ${w==="每个商品都要填"?"text-red-600":w==="可以留空"?"text-gray-500":"text-amber-700"}`,children:w}),e.jsx("td",{className:"px-3 py-2 min-w-[260px]",children:H})]},n))})]})})]})]}),se==="preview"&&X&&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:X.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:X.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:X.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:X.rows.map(n=>{var w,H,Te,s;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:n.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 ${n.valid?"bg-emerald-50 text-emerald-700 border-emerald-100":"bg-red-50 text-red-700 border-red-100"}`,children:n.valid?"可发布":"需修正"})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[240px] truncate",children:n.title||"-"}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:["¥",n.price||"-"," / ",n.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:((w=n.category)==null?void 0:w.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((H=n.category)==null?void 0:H.cat_id)||"失败后使用电子资料"})]}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:[((Te=n.images)==null?void 0:Te.length)||0," 张"]}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[280px]",children:((s=n.errors)==null?void 0:s.join(";"))||"-"})]},n.row_no)})})]})})]}),(se==="running"||se==="done")&&d&&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 ${ut(d.status)}`,children:[e.jsx("div",{className:"text-xs font-bold opacity-70",children:"任务状态"}),e.jsx("div",{className:"text-xl font-extrabold mt-1",children:pt(d.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:d.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:d.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:d.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:d.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:d.rows.map(n=>{var w,H;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:n.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 ${ut(n.status)}`,children:pt(n.status)})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[260px] truncate",children:n.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:((w=n.category)==null?void 0:w.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((H=n.category)==null?void 0:H.cat_id)||"失败后使用电子资料"})]}),e.jsx("td",{className:"px-4 py-3 text-xs font-mono",children:n.item_url?e.jsx("a",{href:n.item_url,target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline",children:n.item_id}):n.item_id||"-"}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[340px]",children:n.error_message||"-"})]},n.id)})})]})})]})]}),e.jsxs("div",{className:"modal-footer",children:[se==="upload"&&e.jsxs("button",{disabled:v||!ve||!R,onClick:tt,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(ze,{className:`w-4 h-4 ${v?"animate-spin":""}`}),v?"正在预检...":"开始预检"]}),se==="preview"&&X&&e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{disabled:v,onClick:()=>void We(),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:v||X.valid<=0,onClick:kt,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(es,{className:"w-4 h-4"}),v?"启动中...":`确认发布 ${X.valid} 个商品`]})]}),(se==="running"||se==="done")&&d&&e.jsxs("div",{className:"flex gap-3 w-full",children:[d.status==="running"?e.jsx("button",{disabled:v,onClick:Je,className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"取消任务"}):d.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(`/items/publish-batches/${d.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:"下载结果"}),d.retryable>0&&!["running","canceling"].includes(d.status)&&e.jsxs("button",{disabled:v,onClick:St,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(ze,{className:`w-4 h-4 ${v?"animate-spin":""}`}),"重试失败项"]}),!["running","canceling"].includes(d.status)&&e.jsx("button",{onClick:()=>{Z(!1),Ae(),we()},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)]})},ra="https://dashscope.aliyuncs.com/compatible-mode/v1",jn=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],Nn=new Set(["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"]),_n=()=>{const[t,a]=r.useState(null),[l,i]=r.useState(!1),[m,_]=r.useState(""),[N,R]=r.useState(!1),[g,C]=r.useState([]),[j,F]=r.useState(!1),[G,me]=r.useState(""),[oe,v]=r.useState(!1),q=r.useRef(null),[ce,Q]=r.useState(!1),[ee,B]=r.useState(!1),[ge,ue]=r.useState(!1),[k,Z]=r.useState(!1),[se,K]=r.useState(!1),[ve,J]=r.useState(null),[I,E]=r.useState({new_username:"",current_password:"",new_password:"",confirm_password:""});r.useEffect(()=>{be(),La().then(b=>{b.username&&E(U=>({...U,new_username:b.username||""}))}).catch(()=>{})},[]),r.useEffect(()=>{const b=U=>{var M;(M=q.current)!=null&&M.contains(U.target)||v(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]);const $=async(b,U=!1)=>{const M=b||t,ne=(M==null?void 0:M.ai_api_url)||(M==null?void 0:M.ai_base_url)||ra;F(!0),me("");try{const he=await qr(ne,(M==null?void 0:M.ai_api_key)||"");C(he),v(U&&he.length>0),!(M!=null&&M.ai_model)&&he.length>0&&a(ye=>ye&&{...ye,ai_model:he[0]})}catch(he){C([]),v(!1),me(he.message||"读取模型失败")}finally{F(!1)}},be=()=>{i(!0),_(""),$a().then(b=>{a(b),$(b)}).catch(b=>{a(null),_(b.message||"加载配置失败")}).finally(()=>i(!1))},Re=async()=>{if(t){R(!0);try{const b=Object.fromEntries(Object.entries(t).filter(([U,M])=>!Nn.has(U)&&M!==void 0&&M!==null));await Pa(b),alert("系统配置已保存")}catch(b){alert("保存失败:"+b.message)}finally{R(!1)}}},ae=async b=>{b.preventDefault(),J(null);const U=I.new_username.trim();if(U.length<3){J({type:"error",text:"用户名至少需要 3 个字符"});return}if(!I.current_password){J({type:"error",text:"请输入当前密码确认身份"});return}if(I.new_password&&I.new_password.length<8){J({type:"error",text:"新密码至少需要 8 个字符"});return}if(I.new_password!==I.confirm_password){J({type:"error",text:"两次输入的新密码不一致"});return}K(!0);try{const M=await Rl({current_password:I.current_password,new_username:U,new_password:I.new_password||void 0});if(!M.success){J({type:"error",text:M.message||"登录凭据更新失败"});return}J({type:"success",text:M.message||"登录凭据已更新"}),window.setTimeout(()=>window.location.reload(),1400)}catch(M){J({type:"error",text:M.message||"登录凭据更新失败"})}finally{K(!1)}};if(!t)return e.jsx("div",{className:"p-8 text-center text-gray-400",children:m||(l?"加载配置中...":"暂无配置")});const T=t.ai_model||"",p=g;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(js,{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:be,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(ze,{className:"w-4 h-4"}),"刷新"]})]}),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(il,{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:t.log_level||"info",onChange:b=>a({...t,log_level:b.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:jn.map(b=>e.jsx("option",{value:b.value,children:b.label},b.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:t.log_format||"text",onChange:b=>a({...t,log_format:b.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:t.renewal_log_retention_days??10,onChange:b=>a({...t,renewal_log_retention_days:parseInt(b.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(vs,{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:t.ai_api_url||ra,onChange:b=>a({...t,ai_api_url:b.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:ce?"text":"password",value:t.ai_api_key||"",onChange:b=>a({...t,ai_api_key:b.target.value}),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",placeholder:"sk-..."}),e.jsx("button",{type:"button",onClick:()=>Q(!ce),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:ce?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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:q,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:T,onFocus:()=>g.length>0&&v(!0),onChange:b=>{a({...t,ai_model:b.target.value}),g.length>0&&v(!0)},onKeyDown:b=>{b.key==="Escape"&&v(!1),b.key==="ArrowDown"&&g.length>0&&v(!0)},className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:()=>g.length>0&&v(b=>!b),disabled:g.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(ol,{className:`w-4 h-4 transition-transform ${oe?"rotate-180":""}`})}),oe&&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:p.length>0?p.map(b=>e.jsxs("button",{type:"button",onClick:()=>{a({...t,ai_model:b}),v(!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:b}),b===T&&e.jsx(Ke,{className:"w-4 h-4 shrink-0 text-brand"})]},b)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:()=>$(void 0,!0),disabled:j,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(ze,{className:`w-4 h-4 ${j?"animate-spin":""}`}),"读取模型"]})]}),G?e.jsx("p",{className:"text-xs text-red-500",children:G}):e.jsx("p",{className:"text-xs text-gray-500",children:g.length>0?`已从当前 API 地址读取到 ${g.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(Mt,{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:t["captcha.remote_service_url"]||"",onChange:b=>a({...t,"captcha.remote_service_url":b.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:ee?"text":"password",value:t["captcha.remote_secret_key"]||"",onChange:b=>a({...t,"captcha.remote_secret_key":b.target.value}),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",autoComplete:"off"}),e.jsx("button",{type:"button",onClick:()=>B(!ee),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:ee?"隐藏秘钥":"显示秘钥",children:ee?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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(t["captcha.remote_pass_cookies"]||"").toLowerCase()==="true",onChange:b=>a({...t,"captcha.remote_pass_cookies":b.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(qs,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:ae,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(Gt,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:I.new_username,onChange:b=>E({...I,new_username:b.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:ge?"text":"password",value:I.current_password,onChange:b=>E({...I,current_password:b.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:()=>ue(!ge),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:ge?"隐藏密码":"显示密码",children:ge?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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:k?"text":"password",value:I.new_password,onChange:b=>E({...I,new_password:b.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:()=>Z(!k),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:k?"隐藏密码":"显示密码",children:k?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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:k?"text":"password",value:I.confirm_password,onChange:b=>E({...I,confirm_password:b.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),ve&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${ve.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(Mt,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:ve.text})]}),e.jsxs("button",{type:"submit",disabled:se||!I.new_username||!I.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(qs,{className:"w-4 h-4"}),se?"正在更新...":"更新登录凭据"]})]})]})]})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:Re,disabled:N,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(He,{className:"w-6 h-6"}),N?"保存中...":"保存所有配置"]})})]})},ns=(t,a)=>t.allowed_resolutions.includes(a),vn=(t,a)=>({runs:t.runs.filter(l=>!a||l.cookie_id===a),pending_tasks:t.pending_tasks.filter(l=>!a||l.cookie_id===a)}),wn=t=>({external_result_unknown:"外部动作结果未知",invalid_snapshot:"历史数据无法恢复",rule_unavailable:"规则不可用",partial_failure:"部分动作失败",execution_failed:"动作执行失败"})[t]||"自动化异常",kn=(t,a,l,i,m,_)=>t!==a||l!==i?!1:(_(m),!0),at={order_paid:{label:"付款后自动发货",shortLabel:"自动发货",description:"闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。",flow:["付款系统卡片","匹配商品/规格","发送卡密","确认发货"],accent:"blue",icon:qt},buyer_reviewed:{label:"评价后发送赠品",shortLabel:"评价赠品",description:"闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。",flow:["评价系统卡片","匹配商品/规格","发送赠品"],accent:"emerald",icon:cl},review_missing_timeout:{label:"超时未评价求评价",shortLabel:"求评价",description:"计划任务扫描已发货未评价订单,到期后发送求评价文案。",flow:["计划任务扫描","已发货未评价","达到等待时间","发送提醒"],accent:"amber",icon:va}},Vt=["order_paid","buyer_reviewed","review_missing_timeout"],Cn="亲,商品使用满意的话,麻烦给个评价,谢谢~",Pt=()=>({spec_name:"",spec_value:"",card_id:0,delivery_count:1,enabled:!0,delay_override:!1,delay_seconds:0}),Da=t=>{if(!t)return{};try{const a=JSON.parse(t);return a&&typeof a=="object"&&!Array.isArray(a)?a:{}}catch{return{}}},ct=(t,a={})=>{const l=Da(t);return JSON.stringify({after_shipped_hours:Number(l.after_shipped_hours||72),repeat_interval_hours:Number(l.repeat_interval_hours||24),max_attempts:Number(l.max_attempts||1),...a})},Rt=(t,a)=>{var i;const l=((i=at[t])==null?void 0:i.label)||"自动化规则";return a?`${l} - ${a}`:l},na=t=>{const a=(t||"").trim();return a?Object.values(at).some(l=>a===l.label||a.startsWith(`${l.label} -`)):!0},Et=(t,a=0)=>{if(t==="review_missing_timeout")return[{action_type:"send_text",message_template:Cn,enabled:!0,sort_order:1}];const l={action_type:"send_card",card_id:a,delivery_count:1,enabled:!0,sort_order:1};return t==="order_paid"?[l,{action_type:"confirm_shipment",enabled:!0,sort_order:2}]:[l]},Sn=t=>{var l,i;if(t.trigger_type==="review_missing_timeout")return((i=(l=t.actions)==null?void 0:l.find(m=>m.action_type==="send_text"))==null?void 0:i.message_template)||"发送求评价文案";const a=(t.actions||[]).filter(m=>m.action_type==="send_card");return a.length?a.map(m=>m.card_name||`卡密 ${m.card_id}`).join(" / "):"未配置卡密库存"},ia=(t,a=!1)=>{const l={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 l[t]||l.blue},Ln=t=>t?"bg-emerald-100 text-emerald-700":"bg-gray-200 text-gray-500",Qt=t=>(t==null?void 0:t.nickname)||(t==null?void 0:t.remark)||(t==null?void 0:t.id)||"未知账号",On=t=>t===!0||t===1||t==="1",In=({initialDeliveryTarget:t,onDeliveryTargetHandled:a})=>{var w,H,Te;const[l,i]=r.useState("automation"),[m,_]=r.useState([]),[N,R]=r.useState({runs:[],pending_tasks:[]}),[g,C]=r.useState([]),[j,F]=r.useState({}),[G,me]=r.useState([]),[oe,v]=r.useState([]),[q,ce]=r.useState([]),[Q,ee]=r.useState(!1),[B,ge]=r.useState(""),[ue,k]=r.useState(""),[Z,se]=r.useState(""),[K,ve]=r.useState(""),[J,I]=r.useState("all"),[E,$]=r.useState(1),[be,Re]=r.useState(10),[ae,T]=r.useState(0),[p,b]=r.useState(0),[U,M]=r.useState({}),ne=r.useRef(0),he=r.useRef(0),ye=r.useRef("");ye.current=B;const[Ee,ke]=r.useState(!1),[x,V]=r.useState(!1),[X,c]=r.useState(!1),[d,D]=r.useState(null),[S,Y]=r.useState(null),[O,de]=r.useState({cookie_id:"",enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""});G.find(s=>s.id===B);const Se=r.useCallback(async()=>{const[s,o,y,A]=await Promise.all([Ft(),Xe(),vt(),Xs()]);me(s),v(o),ce(y),F(A),ge(W=>{var pe;return W||((pe=s[0])==null?void 0:pe.id)||""})},[]),fe=r.useCallback(async()=>{const s=++ne.current,o=Or().catch(W=>(console.warn("加载自动化异常列表失败,不阻断规则展示",W),null)),y=await Cr({cookieId:B||void 0,triggerType:K,enabled:J==="all"?void 0:J==="enabled",search:Z,page:E,pageSize:be});if(s!==ne.current)return;_(y.data),T(y.total),b(y.total_pages),M(y.trigger_counts||{}),y.page!==E&&$(y.page);const A=await o;s===ne.current&&A&&R(A)},[E,be,J,K,Z,B]),Oe=r.useCallback(async()=>{const s=B;if(s!==ye.current)return;const o=++he.current;if(C([]),!s)return;const y=await Rr(s);kn(o,he.current,s,ye.current,y,C)},[B]),re=r.useCallback(async()=>{F(await Xs())},[]),h=r.useCallback(async()=>{ee(!0);try{l==="automation"?await fe():l==="reply"?await Oe():await re()}finally{ee(!1)}},[l,fe,re,Oe]);r.useEffect(()=>{const s=window.setTimeout(()=>{$(1),se(ue.trim())},300);return()=>window.clearTimeout(s)},[ue]),r.useEffect(()=>{Se().catch(s=>console.error("加载规则参考数据失败",s))},[Se]),r.useEffect(()=>{h().catch(s=>console.error("刷新规则页面失败",s))},[h]);const f=r.useMemo(()=>m.filter(s=>!B||s.cookie_id===B),[m,B]),P=r.useMemo(()=>vn(N,B),[N,B]),z=r.useMemo(()=>G.filter(s=>!B||s.id===B),[G,B]),Ie=r.useMemo(()=>{if(p<=1)return[];const s=Math.max(1,Math.min(E-2,p-4)),o=Math.min(p,s+4);return Array.from({length:o-s+1},(y,A)=>s+A)},[E,p]),Ae=!!(ue.trim()||K||J!=="all"),we=()=>{k(""),se(""),ve(""),I("all"),$(1)},De=r.useMemo(()=>{const s=(d==null?void 0:d.cookie_id)||B;return q.filter(o=>o.cookie_id===s)},[d==null?void 0:d.cookie_id,q,B]),te=r.useMemo(()=>{if(!(!(d!=null&&d.cookie_id)||!(d!=null&&d.item_id)))return q.find(s=>s.cookie_id===d.cookie_id&&s.item_id===d.item_id)},[d==null?void 0:d.cookie_id,d==null?void 0:d.item_id,q]),je=On(te==null?void 0:te.is_multi_spec),u=(d==null?void 0:d.trigger_type)||"order_paid",L=at[u],le=Da(d==null?void 0:d.config_json),Ne=r.useCallback((s="order_paid",o=B,y="")=>{const A=q.find(pe=>pe.cookie_id===o&&pe.item_id===y),W=(A==null?void 0:A.item_title)||y;return{name:Rt(s,W),trigger_type:s,cookie_id:o,item_id:y,item_title:(A==null?void 0:A.item_title)||"",item_keyword:W,card_group_id:0,priority:100,enabled:!0,config_json:s==="review_missing_timeout"?ct():"{}",actions:Et(s),variants:s==="review_missing_timeout"?[]:[Pt()]}},[q,B]),Ue=r.useCallback(s=>{var y,A;const o=s.trigger_type||"order_paid";D({...s,trigger_type:o,config_json:o==="review_missing_timeout"?ct(s.config_json):s.config_json||"{}",actions:(y=s.actions)!=null&&y.length?s.actions.map(W=>({...W})):Et(o,s.card_group_id),variants:(A=s.variants)!=null&&A.length?s.variants.map(W=>({...W})):o==="review_missing_timeout"?[]:[Pt()]}),ke(!0)},[]);r.useEffect(()=>{if(!t)return;let s=!1;return(async()=>{i("automation"),ge(t.cookieId),ee(!0);try{const[y,A,W]=await Promise.all([gs(),vt(),Xe().catch(xe=>(console.warn("加载卡密库存失败,不阻断打开自动化规则",xe),[]))]);if(s)return;_(y),ce(A),v(W);const pe=y.find(xe=>xe.cookie_id===t.cookieId&&xe.item_id===t.itemId&&xe.trigger_type==="order_paid");if(pe)Ue(pe);else{const xe=A.find($e=>$e.cookie_id===t.cookieId&&$e.item_id===t.itemId);D({...Ne("order_paid",t.cookieId,t.itemId),item_title:(xe==null?void 0:xe.item_title)||"",item_keyword:(xe==null?void 0:xe.item_title)||t.itemId,name:Rt("order_paid",(xe==null?void 0:xe.item_title)||t.itemId)}),ke(!0)}}catch(y){console.error("打开商品自动化规则失败",y),alert("无法加载该商品的自动化规则")}finally{s||(ee(!1),a==null||a())}})(),()=>{s=!0}},[Ne,t,a,Ue]);const Fe=(s="order_paid")=>{if(!B){alert("请先选择账号");return}D(Ne(s)),ke(!0)},tt=s=>{var A,W,pe,xe,$e;if(!d)return;const o=((W=(A=d.variants)==null?void 0:A.find(ie=>ie.card_id))==null?void 0:W.card_id)||((xe=(pe=d.actions)==null?void 0:pe.find(ie=>ie.action_type==="send_card"))==null?void 0:xe.card_id)||d.card_group_id||0,y=(te==null?void 0:te.item_title)||d.item_title||d.item_id||"";D({...d,trigger_type:s,name:na(d.name)?Rt(s,y):d.name,card_group_id:o,config_json:s==="review_missing_timeout"?ct(d.config_json):"{}",actions:Et(s,o),variants:s==="review_missing_timeout"?[]:($e=d.variants)!=null&&$e.length?d.variants:[{...Pt(),card_id:o}]})},kt=s=>{if(!d)return;const o=q.find(A=>A.cookie_id===(d.cookie_id||B)&&A.item_id===s),y=(o==null?void 0:o.item_title)||s;D({...d,item_id:s,item_title:(o==null?void 0:o.item_title)||"",item_keyword:y,name:na(d.name)?Rt(u,y):d.name})},Je=(w=d==null?void 0:d.variants)!=null&&w.length?d.variants:[Pt()],We=(s,o)=>{var A;if(!d)return;const y=Je.map((W,pe)=>pe===s?{...W,...o}:W);D({...d,variants:y,card_group_id:((A=y[0])==null?void 0:A.card_id)||0})},Ct=()=>{if(!d)return;const s=Je[Je.length-1];D({...d,variants:[...Je,{...Pt(),spec_name:je&&(s==null?void 0:s.spec_name)||"",spec_value:je&&(s==null?void 0:s.spec_value)||""}]})},St=async()=>{var A,W,pe,xe,$e;if(!d)return;const s=d.trigger_type||"order_paid";if(!d.cookie_id){alert("请选择账号");return}const o=(A=d.variants)!=null&&A.length?d.variants:[];if(s!=="review_missing_timeout"){if(!o.length||o.some(ie=>!ie.card_id)){alert(s==="buyer_reviewed"?"请选择评价赠品卡密库存":"请选择发货卡密库存");return}if(je&&o.some(ie=>!ie.spec_name.trim()||!ie.spec_value.trim())){alert("多规格商品必须填写每一行的规格名称和规格值");return}}if(s==="review_missing_timeout"&&!(((pe=(W=d.actions)==null?void 0:W.find(Ye=>Ye.action_type==="send_text"))==null?void 0:pe.message_template)||"").trim()){alert("请填写求评价文案");return}const y=s==="review_missing_timeout"?[]:o.map(ie=>({...ie,spec_name:je?ie.spec_name.trim():"",spec_value:je?ie.spec_value.trim():"",delivery_count:Math.max(1,Number(ie.delivery_count)||1),enabled:ie.enabled!==!1}));try{await Zs({...d,trigger_type:s,name:(d.name||"").trim()||Rt(s,(te==null?void 0:te.item_title)||d.item_id||""),config_json:s==="review_missing_timeout"?ct(d.config_json):d.config_json||"{}",actions:(xe=d.actions)!=null&&xe.length?d.actions:Et(s,(($e=y[0])==null?void 0:$e.card_id)||d.card_group_id||0),variants:y}),ke(!1),await Promise.all([fe(),Se()]),alert("保存成功")}catch(ie){console.error("保存自动化规则失败:",ie),alert("保存失败:"+ie.message)}},mt=async s=>{if(confirm("确定删除该自动化规则吗?"))try{await Lr(s),await fe(),alert("删除成功")}catch(o){alert("删除失败:"+o.message)}},Lt=async s=>{try{await Zs({...s,enabled:!s.enabled}),await fe()}catch(o){alert("操作失败:"+o.message)}},nt=async(s,o)=>{if(confirm(o==="continue"?"确认外部动作已经执行成功,并跳到下一步吗?":o==="retry"?"确认外部动作没有执行,可以安全重试吗?错误判断可能造成重复发送。":"确认终止该自动化运行吗?"))try{await Ir(s,o),await fe()}catch(A){alert("处理失败:"+A.message)}},it=async(s,o)=>{if(confirm(o==="retry"?"确认重新执行该任务吗?":"确认忽略并删除该异常任务吗?"))try{await Ar(s,o),await fe()}catch(y){alert("处理失败:"+y.message)}},Ot=()=>{if(!B){alert("请先选择账号");return}Y({keyword:"",reply_content:"",image_url:"",item_id:"",type:"text",match_type:"fuzzy",enabled:!0}),V(!0)},pt=async()=>{var o,y,A;if(!S||!B)return;const s=S.type==="image"?!!((o=S.image_url)!=null&&o.trim()):!!((y=S.reply_content)!=null&&y.trim());if(!((A=S.keyword)!=null&&A.trim())||!s){alert("请填写关键词和回复内容");return}try{await Er({...S,match_type:"fuzzy",enabled:!0},B),V(!1),await Oe(),alert("保存成功")}catch(W){alert("保存失败:"+W.message)}},ut=async s=>{if(!(!B||!confirm("确定删除该回复规则吗?")))try{await Dr(s,B),await Oe(),alert("删除成功")}catch(o){alert("删除失败:"+o.message)}},st=async(s=B)=>{if(!s){alert("请先选择账号");return}try{const o=await Jr(s);de({cookie_id:s,enabled:o.enabled,reply_content:o.reply_content,reply_once:o.reply_once,reply_image_url:o.reply_image_url||""})}catch{de({cookie_id:s,enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""})}c(!0)},ht=async()=>{if(!O.cookie_id){alert("请先选择账号");return}if(O.enabled&&!O.reply_content.trim()&&!O.reply_image_url.trim()){alert("启用默认回复时,请填写回复内容或图片 URL");return}try{await Vr(O.cookie_id,{enabled:O.enabled,reply_content:O.reply_content,reply_once:O.reply_once,reply_image_url:O.reply_image_url}),c(!1),await re(),alert("保存成功")}catch(s){alert("保存失败:"+s.message)}},Ge=async s=>{if(confirm("确定删除该账号默认回复吗?"))try{await Qr(s),await re(),alert("删除成功")}catch(o){alert("删除失败:"+o.message)}},ot=async s=>{if(confirm("确定清空该账号的默认回复记录吗?清空后可重新对所有会话使用“只回复一次”。"))try{await Gr(s),alert("清空成功")}catch(o){alert("清空失败:"+o.message)}},n=l==="automation"?"新建自动化":l==="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:B,onChange:s=>{ge(s.target.value),$(1)},className:"ios-input w-full px-4 py-3 rounded-2xl text-sm sm:w-64",children:[e.jsx("option",{value:"",children:"全部账号"}),G.map(s=>e.jsx("option",{value:s.id,children:Qt(s)},s.id))]}),e.jsxs("button",{onClick:h,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(ze,{className:`w-4 h-4 ${Q?"animate-spin":""}`}),"刷新"]}),e.jsxs("button",{onClick:l==="automation"?()=>Fe("order_paid"):l==="reply"?Ot:()=>void st(),disabled:!B,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(et,{className:"w-4 h-4"}),n]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[{id:"automation",label:"交易自动化",icon:cs},{id:"reply",label:"关键词回复",icon:Tt},{id:"default",label:"账号默认回复",icon:yt}].map(s=>{const o=s.icon;return e.jsxs("button",{onClick:()=>i(s.id),className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${l===s.id?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:[e.jsx(o,{className:"w-4 h-4"}),s.label]},s.id)})}),l==="automation"&&(P.runs.length>0||P.pending_tasks.length>0)&&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(rt,{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:[P.runs.map(s=>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:["账号 ",s.cookie_id," · 订单 ",s.order_id||"-"," · 已记录发送 ",s.sent_count," 条"]}),e.jsx("div",{className:"text-xs font-bold text-red-800 mt-1",children:wn(s.issue_kind)}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:s.error_message})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 shrink-0",children:[ns(s,"continue")&&e.jsx("button",{onClick:()=>void nt(s.id,"continue"),className:"px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold",children:"已执行,继续下一步"}),ns(s,"retry")&&e.jsx("button",{onClick:()=>void nt(s.id,"retry"),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"未执行,安全重试"}),ns(s,"cancel")&&e.jsx("button",{onClick:()=>void nt(s.id,"cancel"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"终止"})]})]},`run-${s.id}`)),P.pending_tasks.map(s=>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:["账号 ",s.cookie_id," · 延迟任务重试已达 ",s.attempt_count," 次"]}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:s.error_message})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>void it(s.id,"retry"),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"重新入队"}),e.jsx("button",{onClick:()=>void it(s.id,"dismiss"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"忽略"})]})]},`task-${s.id}`))]})]}),l==="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:Vt.map(s=>{const o=at[s],y=o.icon;return e.jsx("button",{type:"button",onClick:()=>Fe(s),className:`w-full text-left rounded-2xl border p-4 transition-colors ${ia(o.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(y,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:o.label}),e.jsx("div",{className:"text-xs opacity-75 mt-1 leading-5",children:o.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:["共 ",ae," 条"]})]}),e.jsx("div",{className:"space-y-3",children:Vt.map(s=>{const o=at[s],y=o.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(y,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:o.shortLabel})]}),e.jsx("span",{className:"text-sm font-black text-gray-900",children:U[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(_t,{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:ue,onChange:s=>{k(s.target.value),$(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(_a,{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:K,onChange:s=>{ve(s.target.value),$(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:"全部自动化类型"}),Vt.map(s=>e.jsx("option",{value:s,children:at[s].shortLabel},s))]})]}),e.jsxs("select",{"aria-label":"按启用状态筛选",value:J,onChange:s=>{I(s.target.value),$(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:"已禁用"})]}),Ae&&e.jsx("button",{type:"button",onClick:we,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(Me,{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:["找到 ",ae," 条规则"]}),Q&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ze,{className:"h-3.5 w-3.5 animate-spin"}),"正在更新"]})]})]}),Q&&f.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(ze,{className:"mr-2 h-4 w-4 animate-spin"}),"正在加载规则"]}):f.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-dashed border-gray-200 p-16 text-center",children:[e.jsx(cs,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-black text-gray-900",children:Ae?"没有匹配的自动化规则":"还没有自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2",children:Ae?"调整或清除筛选条件后再试。":"从左侧选择一个模板开始配置。"})]}):f.map(s=>{const o=at[s.trigger_type],y=o.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 ${ia(o.accent,!0)}`,children:e.jsx(y,{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 ${Ln(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:o.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:Sn(s)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>Ue(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(Nt,{className:"w-4 h-4"}),"编辑"]}),e.jsx("button",{onClick:()=>Lt(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:()=>mt(s.id),className:"p-2.5 rounded-xl text-red-500 hover:bg-red-50",title:"删除",children:e.jsx(Qe,{className:"w-4 h-4"})})]})]})},s.id)}),ae>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:["第 ",E," / ",Math.max(p,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:be,onChange:s=>{Re(Number(s.target.value)),$(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:E<=1||Q,onClick:()=>$(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(_s,{className:"h-4 w-4"})}),Ie.map(s=>e.jsx("button",{type:"button",disabled:Q,onClick:()=>$(s),className:`h-9 min-w-9 rounded-lg px-2 text-sm font-bold transition-colors ${s===E?"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===E?"page":void 0,children:s},s)),e.jsx("button",{type:"button",disabled:E>=p||Q,onClick:()=>$(s=>Math.min(p,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(Ns,{className:"h-4 w-4"})})]})]})]})]}),l==="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(rt,{className:"w-4 h-4"}),"这里只处理买家用户消息;系统通知不会进入关键词或 AI 回复。"]}),e.jsxs("div",{className:"space-y-3",children:[g.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:()=>{Y({...s}),V(!0)},className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(Nt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ut(s.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Qe,{className:"w-5 h-5"})})]})]},s.id)),g.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无关键词回复规则"})]})]}),l==="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(rt,{className:"w-4 h-4"}),"默认回复只处理买家用户消息;关键词未命中且 AI 未接管时才会使用。"]}),e.jsxs("div",{className:"space-y-3",children:[z.map(s=>{const o=j[s.id],y=!!(o!=null&&o.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 ${y?"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 ${y?"bg-purple-600 text-white":"bg-gray-200 text-gray-400"}`,children:e.jsx(yt,{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:Qt(s)}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-xs font-bold ${y?"bg-green-100 text-green-700":"bg-gray-200 text-gray-500"}`,children:y?"已启用":"未启用"}),(o==null?void 0:o.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:y?o.reply_content||o.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 st(s.id),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(Nt,{className:"w-4 h-4"})}),y&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>void ot(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 Ge(s.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Qe,{className:"w-5 h-5"})})]})]})]},s.id)}),z.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无账号"})]})]}),Ee&&d&&qe.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:d.id?"编辑自动化规则":"新建自动化规则"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:L.description})]}),e.jsx("button",{onClick:()=>ke(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",title:"关闭",children:e.jsx(Me,{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:Vt.map(s=>{const o=at[s],y=o.icon,A=u===s;return e.jsx("button",{type:"button",onClick:()=>tt(s),className:`w-full rounded-2xl p-4 text-left border transition-all ${A?"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(y,{className:`w-5 h-5 mt-0.5 ${A?"text-brand":"text-white"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black",children:o.label}),e.jsx("div",{className:`text-xs mt-1 leading-5 ${A?"text-gray-500":"text-gray-400"}`,children:o.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:L.flow.map((s,o)=>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:o+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(ds,{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:d.name||"",onChange:s=>D({...d,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:d.cookie_id||"",onChange:s=>D({...d,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:"选择账号"}),G.map(s=>e.jsx("option",{value:s.id,children:Qt(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:d.item_id||"",onChange:s=>kt(s.target.value),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级规则(不限定商品)"}),De.map(s=>e.jsx("option",{value:s.item_id,children:s.item_title||s.item_id},`${s.cookie_id}-${s.item_id}`))]})]})]}),te&&u!=="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:te.item_title||te.item_id}),e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${je?"bg-blue-50 text-blue-700":"bg-gray-100 text-gray-500"}`,children:je?"多规格商品":"普通商品"}),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:"多规格状态来自闲鱼商品本身,发布后不能在这里修改;系统会在买家付款后读取订单详情,按实际购买规格和数量匹配下面的发货规则。"})]})]}),u!=="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(dl,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:u==="buyer_reviewed"?"赠品库存":"发货库存"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:je?"每条发货内容绑定一个订单规格;同一规格可添加多条内容并全部发送。":"可添加多条发货内容,买家付款后会按顺序全部发送。"})]}),e.jsxs("button",{type:"button",onClick:Ct,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(et,{className:"w-3.5 h-3.5"}),"添加发货内容"]})]}),e.jsx("div",{className:"space-y-3",children:Je.map((s,o)=>e.jsxs("div",{className:`grid grid-cols-1 gap-3 items-end rounded-2xl border border-gray-200 p-4 ${je?"md:grid-cols-[1fr_1fr_1.4fr_110px_40px]":"md:grid-cols-[1.4fr_110px_40px]"}`,children:[je&&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:y=>We(o,{spec_name:y.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:y=>We(o,{spec_value:y.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:y=>We(o,{card_id:Number(y.target.value)}),className:"w-full ios-input px-3 py-2.5 rounded-lg",children:[e.jsx("option",{value:"",children:"请选择卡密库存"}),oe.filter(y=>y.enabled&&y.type!=="api").map(y=>e.jsx("option",{value:y.id,children:y.name},y.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:y=>We(o,{delivery_count:Math.max(1,Number(y.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:y=>We(o,{delay_override:y.target.checked}),className:"accent-brand"}),"覆盖卡密默认延时"]}),s.delay_override&&e.jsx("input",{type:"number",min:"0",max:"3600",value:s.delay_seconds||0,onChange:y=>We(o,{delay_seconds:Math.max(0,Number(y.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:Je.length===1,onClick:()=>D({...d,variants:Je.filter((y,A)=>A!==o)}),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(Qe,{className:"w-4 h-4"})})]},s.id||o))})]}):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(va,{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(le.after_shipped_hours||72),onChange:s=>D({...d,config_json:ct(d.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(le.repeat_interval_hours||24),onChange:s=>D({...d,config_json:ct(d.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(le.max_attempts||1),onChange:s=>D({...d,config_json:ct(d.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:((Te=(H=d.actions)==null?void 0:H.find(s=>s.action_type==="send_text"))==null?void 0:Te.message_template)||"",onChange:s=>{var o;return D({...d,actions:((o=d.actions)!=null&&o.length?d.actions:Et("review_missing_timeout")).map(y=>y.action_type==="send_text"?{...y,message_template:s.target.value}:y)})},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:d.priority||100,onChange:s=>D({...d,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:d.enabled!==!1,onChange:s=>D({...d,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:()=>ke(!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:St,className:"flex-1 ios-btn-primary px-6 py-3 rounded-2xl font-bold flex items-center justify-center gap-2",children:[e.jsx(He,{className:"w-4 h-4"}),"保存自动化规则"]})]})]})}),document.body),x&&S&&qe.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:()=>V(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Me,{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=>Y({...S,item_id:s.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级回复"}),q.filter(s=>!B||s.cookie_id===B).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 o=s.target.value;Y({...S,type:o,reply_content:o==="text"?S.reply_content:"",image_url:o==="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=>Y({...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=>Y({...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=>Y({...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:()=>V(!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:pt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Zt,{className:"w-4 h-4"}),"保存规则"]})]})]})]})}),document.body),X&&qe.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:()=>c(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",title:"关闭",children:e.jsx(Me,{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:O.cookie_id,onChange:s=>de({...O,cookie_id:s.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),G.map(s=>e.jsx("option",{value:s.id,children:Qt(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:()=>de({...O,enabled:!O.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${O.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 ${O.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:O.reply_content,onChange:s=>de({...O,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:O.reply_image_url,onChange:s=>de({...O,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:O.reply_once,onChange:s=>de({...O,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:()=>c(!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:ht,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)]})},An=t=>{const a=String(t.smtp_from||"").trim(),l=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a);return{...t,smtp_from_name:t.smtp_from_name||(l?"":a),smtp_from_address:t.smtp_from_address||(l?a:t.smtp_user||""),smtp_use_tls:oa(t.smtp_use_tls,!0),smtp_use_ssl:oa(t.smtp_use_ssl,!1)}},oa=(t,a)=>{if(typeof t=="boolean")return t;if(typeof t=="string"){if(["true","1","yes","on"].includes(t.toLowerCase()))return!0;if(["false","0","no","off"].includes(t.toLowerCase()))return!1}return a},ks=["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from_name","smtp_from_address","smtp_use_tls","smtp_use_ssl"],fs=(t,a)=>{if(typeof t=="boolean")return t;if(typeof t=="string"){if(["true","1","yes","on"].includes(t.toLowerCase()))return!0;if(["false","0","no","off"].includes(t.toLowerCase()))return!1}return a},Ta=t=>{const a=Object.prototype.hasOwnProperty.call(t,"use_custom_smtp"),l=ks.some(i=>String(t[i]??"").trim()!=="");return{...t,use_custom_smtp:a?fs(t.use_custom_smtp,!1):l}},ca=(t,a)=>{const l={...t,use_custom_smtp:!0};for(const i of ks)String(l[i]??"").trim()===""&&a[i]!==void 0&&(l[i]=a[i]);return l.smtp_port||(l.smtp_port=587),l.smtp_from_address||(l.smtp_from_address=l.smtp_user||""),l.smtp_use_tls=fs(l.smtp_use_tls,!0),l.smtp_use_ssl=fs(l.smtp_use_ssl,!1),l},$n=t=>{const a=Ta(t),l={to_email:String(a.to_email??"").trim(),use_custom_smtp:a.use_custom_smtp===!0};if(l.use_custom_smtp)for(const i of ks)l[i]=a[i];return l},ft={bark:{label:"Bark",icon:jt,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:Tt,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:Tt,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:Tt,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:xl,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:Zt,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:wa,fields:[{key:"to_email",label:"收件邮箱",placeholder:"receiver@example.com",required:!0}],guide:{steps:["通常先保存页面中的系统 SMTP 配置","邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP","只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置"],note:"继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。"}}},Ma=[{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:"后台任务或系统级异常"}],Pn=t=>!t||t.length===0?"全部事件":t.map(l=>{var i;return((i=Ma.find(m=>m.value===l))==null?void 0:i.label)||l}).join("、"),Rn=({isAdmin:t=!1})=>{const[a,l]=r.useState([]),[i,m]=r.useState(!0),[_,N]=r.useState(!1),[R,g]=r.useState(null),[C,j]=r.useState(!1),[F,G]=r.useState(""),[me,oe]=r.useState(null),[v,q]=r.useState({}),[ce,Q]=r.useState(!1),[ee,B]=r.useState(!1),[ge,ue]=r.useState(!1),[k,Z]=r.useState({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),se=async()=>{m(!0);try{const p=await Ea();l(p.data||[])}catch(p){console.error("加载通知渠道失败",p)}finally{m(!1)}},K=async()=>{try{const p=await $a();q(An(p||{}))}catch(p){console.error("加载 SMTP 配置失败",p)}},ve=async()=>{Q(!0);try{await Pa({smtp_server:v.smtp_server||"",smtp_port:v.smtp_port||587,smtp_user:v.smtp_user||"",smtp_password:v.smtp_password||"",smtp_from_name:v.smtp_from_name||"",smtp_from_address:v.smtp_from_address||v.smtp_user||"",smtp_use_tls:v.smtp_use_tls!==!1,smtp_use_ssl:v.smtp_use_ssl===!0}),J("success","SMTP 配置已保存")}catch(p){J("error",(p==null?void 0:p.message)||"保存失败")}finally{Q(!1)}};r.useEffect(()=>{se(),t?K():q({})},[t]);const J=(p,b)=>{oe({type:p,text:b}),window.setTimeout(()=>oe(null),3e3)},I=()=>{g(null),Z({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),ue(!1),N(!0)},E=p=>{g(p);const b=p.type==="email"?Ta({...p.config||{}}):null,U=b?b.use_custom_smtp===!0?ca(b,v):b:{...p.config||{}};Z({name:p.name,type:p.type,enabled:p.enabled,config:U,event_types:p.event_types||[]}),ue(!1),N(!0)},$=async()=>{const p=ft[k.type];for(const U of p.fields)if(U.required&&!String(k.config[U.key]||"").trim()){J("error",`请填写 ${U.label}`);return}if(!k.name.trim()){J("error","请填写渠道名称");return}let b=k.config;if(k.type==="email"&&(b=$n(k.config),b.use_custom_smtp)){const M=[["smtp_server","独立 SMTP 服务器"],["smtp_port","独立 SMTP 端口"],["smtp_user","独立 SMTP 登录邮箱"],["smtp_password","独立 SMTP 密码 / 授权码"],["smtp_from_address","独立 SMTP 发件地址"]].find(([ne])=>!String(b[ne]||"").trim());if(M){J("error",`请填写 ${M[1]}`);return}}j(!0);try{const U={name:k.name.trim(),type:k.type,config:b,event_types:k.event_types,enabled:k.enabled};R?await Ys(R.id,U):await Br(U),N(!1),await se(),J("success",R?"已更新":"已创建")}catch(U){console.error("保存失败",U),J("error",(U==null?void 0:U.message)||"保存失败")}finally{j(!1)}},be=async p=>{if(confirm(`确认删除渠道「${p.name}」吗?已绑定该渠道的账号会自动解绑。`))try{await zr(p.id),await se(),J("success","已删除")}catch(b){J("error",(b==null?void 0:b.message)||"删除失败")}},Re=async p=>{try{await Ys(p.id,{enabled:!p.enabled}),l(b=>b.map(U=>U.id===p.id?{...U,enabled:!U.enabled}:U))}catch(b){J("error",(b==null?void 0:b.message)||"切换失败")}},ae=async p=>{G(p.id);try{await Wr(p.id),J("success","测试通知已发送,请检查对应渠道")}catch(b){J("error",(b==null?void 0:b.message)||"发送失败")}finally{G("")}},T=ft[k.type];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:se,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(ze,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:I,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(et,{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(jt,{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:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),i?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(Pe,{className:"w-8 h-8 text-brand animate-spin"})}):a.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(jt,{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:a.map(p=>{const b=ft[p.type]||ft.webhook,U=b.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(U,{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:p.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium",children:b.label}),!p.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:b.fields.map(M=>{var ne;return(ne=p.config)==null?void 0:ne[M.key]}).filter(Boolean).map((M,ne)=>e.jsx("span",{className:"mr-3",children:String(M).length>40?String(M).slice(0,40)+"…":String(M)},ne))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",Pn(p.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>Re(p),className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${p.enabled?"bg-green-50 text-green-700 hover:bg-green-100":"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:p.enabled?"启用中":"已停用"}),e.jsxs("button",{onClick:()=>ae(p),disabled:F===p.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:[F===p.id?e.jsx(Pe,{className:"w-3 h-3 animate-spin"}):e.jsx(Zt,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{onClick:()=>E(p),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(Na,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>be(p),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(Qe,{className:"w-4 h-4"})})]})]},p.id)})}),t&&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(wa,{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",{type:"text",value:v.smtp_server||"",onChange:p=>q({...v,smtp_server:p.target.value}),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:v.smtp_port||587,onChange:p=>q({...v,smtp_port:parseInt(p.target.value)||587}),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",{type:"email",value:v.smtp_user||"",onChange:p=>q({...v,smtp_user:p.target.value}),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:ee?"text":"password",value:v.smtp_password||"",onChange:p=>q({...v,smtp_password:p.target.value}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>B(!ee),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:ee?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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",{type:"text",value:v.smtp_from_name||"",onChange:p=>q({...v,smtp_from_name:p.target.value}),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",{type:"email",value:v.smtp_from_address||v.smtp_user||"",onChange:p=>q({...v,smtp_from_address:p.target.value}),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:v.smtp_use_tls!==!1,onChange:p=>q({...v,smtp_use_tls:p.target.checked,smtp_use_ssl:p.target.checked?!1:v.smtp_use_ssl})}),"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:v.smtp_use_ssl===!0,onChange:p=>q({...v,smtp_use_ssl:p.target.checked,smtp_use_tls:p.target.checked?!1:v.smtp_use_tls})}),"SSL/TLS 直连(常用于 465 端口)"]})]}),e.jsxs("button",{onClick:ve,disabled:ce,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[ce?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(He,{className:"w-4 h-4"}),ce?"保存中...":"保存 SMTP 配置"]})]}),_&&qe.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:R?"编辑通知渠道":"新建通知渠道"}),e.jsx("button",{onClick:()=>N(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(Me,{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:k.name,onChange:p=>Z({...k,name:p.target.value}),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(ft).map(p=>{const b=ft[p],U=b.icon,M=k.type===p;return e.jsxs("button",{type:"button",onClick:()=>Z({...k,type:p,config:{}}),className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${M?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(U,{className:`w-5 h-5 ${M?"text-brand":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${M?"text-brand":"text-gray-600"}`,children:b.label})]},p)})})]}),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(jt,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",T.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:T.guide.steps.map((p,b)=>e.jsx("li",{children:p},b))}),T.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:T.guide.urlFormat})]}),T.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",T.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:T.fields.map(p=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:[p.label,p.required&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),e.jsx("input",{type:p.type==="password"?"password":p.type==="number"?"number":"text",value:String(k.config[p.key]||""),onChange:b=>Z({...k,config:{...k.config,[p.key]:b.target.value}}),placeholder:p.placeholder,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),p.help&&e.jsx("p",{className:"text-xs text-gray-500",children:p.help})]},p.key))}),k.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:k.config.use_custom_smtp===!0?"当前渠道使用一套完整、独立的发件配置。":"当前渠道完整继承系统 SMTP,只单独设置收件邮箱。"})]}),e.jsx("button",{type:"button",onClick:()=>{const p=k.config.use_custom_smtp===!0;Z({...k,config:p?{...k.config,use_custom_smtp:!1}:ca(k.config,v)})},className:`relative h-7 w-12 shrink-0 rounded-full transition-colors ${k.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 ${k.config.use_custom_smtp===!0?"translate-x-5":""}`})})]}),k.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",{type:"text",value:String(k.config.smtp_server||""),onChange:p=>Z({...k,config:{...k.config,smtp_server:p.target.value}}),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",{type:"number",value:String(k.config.smtp_port||587),onChange:p=>Z({...k,config:{...k.config,smtp_port:p.target.value}}),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",{type:"email",value:String(k.config.smtp_user||""),onChange:p=>Z({...k,config:{...k.config,smtp_user:p.target.value}}),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",{type:ge?"text":"password",value:String(k.config.smtp_password||""),onChange:p=>Z({...k,config:{...k.config,smtp_password:p.target.value}}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>ue(p=>!p),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",children:ge?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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",{type:"text",value:String(k.config.smtp_from_name||""),onChange:p=>Z({...k,config:{...k.config,smtp_from_name:p.target.value}}),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",{type:"email",value:String(k.config.smtp_from_address||""),onChange:p=>Z({...k,config:{...k.config,smtp_from_address:p.target.value}}),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:k.config.smtp_use_tls!==!1,onChange:p=>Z({...k,config:{...k.config,smtp_use_tls:p.target.checked,smtp_use_ssl:p.target.checked?!1:k.config.smtp_use_ssl}})}),"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:k.config.smtp_use_ssl===!0,onChange:p=>Z({...k,config:{...k.config,smtp_use_ssl:p.target.checked,smtp_use_tls:p.target.checked?!1:k.config.smtp_use_tls}})}),"SSL/TLS 直连(常用于 465)"]})]})]})]}),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:Ma.map(p=>{const b=k.event_types.includes(p.value);return e.jsxs("button",{type:"button",onClick:()=>{const U=b?k.event_types.filter(M=>M!==p.value):[...k.event_types,p.value];Z({...k,event_types:U})},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(Ke,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${b?"text-brand":"text-gray-800"}`,children:p.label})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 pl-6 leading-5",children:p.description})]},p.value)})})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("button",{type:"button",onClick:()=>Z({...k,enabled:!k.enabled}),className:`relative w-11 h-6 rounded-full transition-colors ${k.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 ${k.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:()=>N(!1),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:$,disabled:C,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[C?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(Ke,{className:"w-4 h-4"}),C?"保存中...":"保存"]})]})]})}),document.body),me&&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 ${me.type==="success"?"bg-success-500":"bg-danger-500"}`,children:[me.type==="success"?e.jsx(Ke,{className:"w-4 h-4"}):e.jsx(Me,{className:"w-4 h-4"}),me.text]})]})},qa=[["尊嘟假嘟","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"]],En=t=>t,Dn=new Map(qa.map(([t,a])=>[t,a])),da=t=>t.split(/(\[[^\]]+\])/g).map((a,l)=>{const i=a.startsWith("[")?Dn.get(a.slice(1,-1)):void 0;return i?e.jsx("img",{src:i,alt:a,title:a,className:"mx-0.5 inline-block h-7 w-7 align-middle"},l):e.jsx(ys.Fragment,{children:a},l)}),xa="ydisks.chat.account.v1",Tn=t=>{if(!t)return"";const a=new Date(t<1e10?t*1e3:t),l=new Date;return a.toDateString()===l.toDateString()?a.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit",hour12:!1}):a.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"})},ma=t=>new Date(t<1e10?t*1e3:t).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}),Mn=()=>{const[t,a]=r.useState([]),[l,i]=r.useState(""),[m,_]=r.useState({}),[N,R]=r.useState(""),[g,C]=r.useState([]),[j,F]=r.useState(""),[G,me]=r.useState(!1),[oe,v]=r.useState(""),[q,ce]=r.useState(!0),[Q,ee]=r.useState(!1),[B,ge]=r.useState(!1),[ue,k]=r.useState(!1),[Z,se]=r.useState(),[K,ve]=r.useState({}),[J,I]=r.useState({}),[E,$]=r.useState(!1),[be,Re]=r.useState(!1),[ae,T]=r.useState(!1),[p,b]=r.useState(""),[U,M]=r.useState("connecting"),ne=r.useRef(""),he=r.useRef(""),ye=r.useRef(null),Ee=r.useRef({accountID:"",chatID:""}),ke=r.useRef(!0),x=r.useRef(!1),V=r.useRef(null),X=r.useRef(new Set);r.useEffect(()=>{ne.current=l},[l]),r.useEffect(()=>{he.current=N},[N]);const c=async h=>{const f=await as(h,void 0,void 0,!0);return _(P=>({...P,[h]:f.sessions})),ve(P=>({...P,[h]:f.next_cursor})),I(P=>({...P,[h]:f.has_more})),f.sessions};r.useEffect(()=>{let h=!1;return(async()=>{var P;ce(!0);try{const[z,Ie]=await Promise.all([Ft(),hs()]),we=z.map(u=>{var L,le;return{...u,runtime_state:((L=Ie[u.id])==null?void 0:L.state)||(u.enabled?"connecting":"disabled"),runtime_connected:((le=Ie[u.id])==null?void 0:le.connected)===!0}}).filter(u=>u.enabled),De=await Promise.all(we.map(async u=>[u.id,await as(u.id)]));if(h)return;a(we),_(Object.fromEntries(De.map(([u,L])=>[u,L.sessions]))),ve(Object.fromEntries(De.map(([u,L])=>[u,L.next_cursor]))),I(Object.fromEntries(De.map(([u,L])=>[u,L.has_more])));const te=window.localStorage.getItem(xa)||"",je=we.some(u=>u.id===te)?te:((P=we[0])==null?void 0:P.id)||"";i(je)}catch(z){h||b(z instanceof Error?z.message:"加载聊天数据失败")}finally{h||ce(!1)}})(),()=>{h=!0}},[]),r.useEffect(()=>{let h=!1,f=0,P=null;const z=async()=>{P=new AbortController;try{const Ie=await hs({signal:P.signal,timeoutMs:1e4});h||a(Ae=>Ae.map(we=>{var De,te;return{...we,runtime_state:((De=Ie[we.id])==null?void 0:De.state)||we.runtime_state,runtime_connected:((te=Ie[we.id])==null?void 0:te.connected)??we.runtime_connected}}))}catch{}finally{h||(f=window.setTimeout(z,3e3))}};return f=window.setTimeout(z,3e3),()=>{h=!0,window.clearTimeout(f),P==null||P.abort()}},[]),r.useEffect(()=>{if(!l)return;window.localStorage.setItem(xa,l);const h=m[l]||[];R(f=>{var P;return h.some(z=>z.chat_id===f)?f:((P=h[0])==null?void 0:P.chat_id)||""})},[l,m]),r.useEffect(()=>{!l||X.current.has(l)||(X.current.add(l),c(l).catch(h=>{b(h instanceof Error?h.message:"同步会话失败")}))},[l]),r.useEffect(()=>{if(!l||!N){C([]);return}const h=new AbortController;return ee(!0),Promise.all([us(l,N,void 0,void 0,{signal:h.signal}),Qs(l,N)]).then(([f])=>{C(f.messages),k(f.has_more),se(f.next_cursor),f.session&&_(P=>({...P,[l]:(P[l]||[]).map(z=>{var Ie;return z.chat_id===((Ie=f.session)==null?void 0:Ie.chat_id)?f.session:z})})),_(P=>({...P,[l]:(P[l]||[]).map(z=>z.chat_id===N?{...z,unread_count:0}:z)}))}).catch(f=>{h.signal.aborted||b(f instanceof Error?f.message:"加载消息失败")}).finally(()=>{h.signal.aborted||ee(!1)}),()=>h.abort()},[l,N]);const d=async()=>{var P;if(!l||!N||B||!ue)return;const h=ye.current,f=(h==null?void 0:h.scrollHeight)||0;x.current=!0,ge(!0),b("");try{const z=(P=g[0])==null?void 0:P.id,Ie=await us(l,N,Z,z);C(Ae=>{const we=new Set(Ae.map(De=>De.message_key));return[...Ie.messages.filter(De=>!we.has(De.message_key)),...Ae]}),k(Ie.has_more),se(Ie.next_cursor),requestAnimationFrame(()=>{h&&(h.scrollTop+=h.scrollHeight-f)})}catch(z){x.current=!1,b(z instanceof Error?z.message:"加载历史消息失败")}finally{ge(!1)}};r.useEffect(()=>{let h=!1,f=0,P=0,z=null;const Ie=()=>{if(h)return;M("connecting");const Ae=window.location.protocol==="https:"?"wss:":"ws:";z=new WebSocket(`${Ae}//${window.location.host}/api/v1/chat/ws`),z.onopen=()=>{P=0,M("online")},z.onmessage=we=>{try{const te=JSON.parse(we.data).message;if(!te)return;const je=te.account_id;_(u=>{const L=u[je]||[];return L.some(Ne=>Ne.chat_id===te.chat_id)?{...u,[je]:L.map(Ne=>Ne.chat_id===te.chat_id?{...Ne,last_message:te.content,last_message_at:te.sent_at,unread_count:te.direction==="incoming"&&(ne.current!==je||he.current!==te.chat_id)?Ne.unread_count+1:Ne.unread_count}:Ne).sort((Ne,Ue)=>Ue.last_message_at-Ne.last_message_at)}:(c(je),u)}),ne.current===je&&he.current===te.chat_id&&(C(u=>{const L=u.findIndex(le=>le.message_key===te.message_key);return L>=0?u.map((le,Ne)=>Ne===L?te:le):[...u,te]}),te.direction==="incoming"&&Qs(je,te.chat_id))}catch{}},z.onclose=()=>{if(h)return;M("offline");const we=Math.min(15e3,1e3*2**Math.min(P++,4));f=window.setTimeout(Ie,we)},z.onerror=()=>z==null?void 0:z.close()};return Ie(),()=>{h=!0,window.clearTimeout(f),z==null||z.close()}},[]);const D=()=>{const h=ye.current;if(!h)return;const f=h.scrollHeight-h.scrollTop-h.clientHeight;ke.current=f<=48};r.useLayoutEffect(()=>{const h=Ee.current.accountID!==l||Ee.current.chatID!==N;Ee.current={accountID:l,chatID:N},h&&(ke.current=!0);const f=ye.current;if(f){if(x.current){x.current=!1;return}(Q||ke.current)&&(f.scrollTop=f.scrollHeight)}},[l,N,g,Q]);const S=t.find(h=>h.id===l),Y=m[l]||[],O=Y.find(h=>h.chat_id===N),de=r.useMemo(()=>{const h=j.trim().toLowerCase();return Y.filter(f=>G&&f.unread_count<=0?!1:h?[f.buyer_name,f.buyer_id,f.item_title,f.last_message].some(P=>(P||"").toLowerCase().includes(h)):!0)},[Y,j,G]),Se=h=>(m[h]||[]).reduce((f,P)=>f+P.unread_count,0),fe=async()=>{if(!(!l||E||!J[l])){$(!0),b("");try{const h=await as(l,K[l],void 0,!0);_(f=>({...f,[l]:h.sessions})),ve(f=>({...f,[l]:h.next_cursor})),I(f=>({...f,[l]:h.has_more}))}catch(h){b(h instanceof Error?h.message:"加载历史联系人失败")}finally{$(!1)}}},Oe=async()=>{const h=oe.trim();if(!(!h||!O||!l||ae)){T(!0),b("");try{const f=await ql({account_id:l,chat_id:O.chat_id,buyer_id:O.buyer_id,buyer_name:O.buyer_name,item_id:O.item_id,item_title:O.item_title,text:h});v(""),C(P=>P.some(z=>z.message_key===f.message.message_key)?P.map(z=>z.message_key===f.message.message_key?f.message:z):[...P,f.message])}catch(f){b(f instanceof Error?f.message:"消息发送失败"),Ml(l,O.chat_id).then(C)}finally{T(!1)}}},re=async h=>{if(!(!h||!O||!l||ae)){T(!0),b("");try{const f=await Fl({account_id:l,chat_id:O.chat_id,buyer_id:O.buyer_id,buyer_name:O.buyer_name,buyer_avatar_url:O.buyer_avatar_url,item_id:O.item_id,item_title:O.item_title,image:h});C(P=>P.some(z=>z.message_key===f.message.message_key)?P.map(z=>z.message_key===f.message.message_key?f.message:z):[...P,f.message])}catch(f){b(f instanceof Error?f.message:"图片发送失败")}finally{T(!1),V.current&&(V.current.value="")}}};return q?e.jsx("div",{className:"flex h-[calc(100vh-4rem)] items-center justify-center",children:e.jsx(Pe,{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 ${U==="online"?"bg-emerald-50 text-emerald-700":U==="connecting"?"bg-amber-50 text-amber-700":"bg-red-50 text-red-700"}`,children:[U==="online"?e.jsx(ml,{className:"h-3.5 w-3.5"}):e.jsx(pl,{className:"h-3.5 w-3.5"}),U==="online"?"实时同步中":U==="connecting"?"正在连接":"连接已断开"]})]}),e.jsx("div",{className:"flex gap-1 overflow-x-auto pb-0",role:"tablist","aria-label":"聊天账号",children:t.map(h=>{const f=h.id===l,P=Se(h.id),z=h.runtime_state==="online";return e.jsxs("button",{type:"button",role:"tab","aria-selected":f,onClick:()=>i(h.id),className:`relative flex h-11 shrink-0 items-center gap-2 border-b-2 px-3 text-sm font-extrabold transition-colors ${f?"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 ${z?"bg-emerald-500":"bg-slate-300"}`}),e.jsx("span",{className:"max-w-36 truncate",children:h.nickname||h.remark||h.id}),P>0&&e.jsx("span",{className:"min-w-5 rounded-full bg-red-500 px-1.5 py-0.5 text-[10px] text-white",children:P>99?"99+":P})]},h.id)})})]}),t.length===0?e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(is,{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(_t,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx("input",{value:j,onChange:h=>F(h.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:()=>me(h=>!h),className:`rounded-lg px-2.5 py-1.5 text-xs font-bold ${G?"bg-sky-100 text-sky-700":"text-slate-500 hover:bg-slate-100"}`,children:G?"只看未读":"全部会话"}),e.jsx("button",{type:"button",title:"刷新会话",onClick:()=>void c(l),className:"rounded-lg p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700",children:e.jsx(ze,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[de.map(h=>e.jsxs("button",{type:"button",onClick:()=>R(h.chat_id),className:`flex w-full gap-3 border-b border-slate-100 p-4 text-left transition-colors ${h.chat_id===N?"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:h.buyer_avatar_url?e.jsx("img",{src:h.buyer_avatar_url,alt:"",className:"h-full w-full object-cover"}):e.jsx(Gt,{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:h.buyer_name||`用户 ${h.buyer_id}`}),e.jsx("span",{className:"ml-auto shrink-0 text-[10px] font-medium text-slate-400",children:Tn(h.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:h.last_message||"暂无消息"}),h.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:h.unread_count})]}),h.item_title&&e.jsxs("div",{className:"mt-1.5 truncate text-[10px] font-medium text-sky-700",children:["商品 · ",h.item_title]})]})]},h.chat_id)),de.length===0&&e.jsx("div",{className:"px-6 py-16 text-center text-sm text-slate-400",children:"当前账号暂无匹配会话"}),J[l]&&!j&&!G&&e.jsx("div",{className:"flex justify-center p-4",children:e.jsxs("button",{type:"button",onClick:()=>void fe(),disabled:E,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:[E&&e.jsx(Pe,{className:"h-3.5 w-3.5 animate-spin"}),E?"正在加载":"加载更多历史联系人"]})})]})]}),e.jsx("main",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-surface-subtle",children:O?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:O.buyer_name||O.buyer_id}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-slate-500",children:["用户 ID:",O.buyer_id]})]}),e.jsx("span",{className:`ml-auto rounded-full px-2.5 py-1 text-[10px] font-bold ${(S==null?void 0:S.runtime_state)==="online"?"bg-emerald-50 text-emerald-700":"bg-slate-100 text-slate-500"}`,children:(S==null?void 0:S.runtime_state)==="online"?"账号在线":"账号离线"})]}),e.jsx("div",{ref:ye,onScroll:D,className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:Q?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Pe,{className:"h-6 w-6 animate-spin text-sky-500"})}):e.jsxs(e.Fragment,{children:[ue&&e.jsx("div",{className:"flex justify-center pb-1",children:e.jsxs("button",{type:"button",onClick:()=>void d(),disabled:B,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:[B&&e.jsx(Pe,{className:"h-3.5 w-3.5 animate-spin"}),B?"正在加载":"加载更早消息"]})}),g.map(h=>{const f=h.direction==="outgoing";return h.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:[da(h.content),e.jsx("div",{className:"mt-1 text-[10px] text-slate-400",children:ma(h.sent_at)})]})},h.message_key):e.jsxs("div",{className:`flex items-end gap-2.5 ${f?"justify-end":"justify-start"}`,children:[!f&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-slate-200 ring-2 ring-white",children:O.buyer_avatar_url?e.jsx("img",{src:O.buyer_avatar_url,alt:O.buyer_name||"用户",className:"h-full w-full object-cover"}):e.jsx(Gt,{className:"m-2 h-5 w-5 text-slate-500"})}),e.jsxs("div",{className:`max-w-[72%] ${f?"items-end":"items-start"} flex flex-col`,children:[e.jsx("div",{className:"mb-1 px-1 text-[10px] font-semibold text-slate-400",children:f?(S==null?void 0:S.nickname)||(S==null?void 0:S.remark)||"我":O.buyer_name||h.sender_name||O.buyer_id}),h.message_type==="image"?e.jsx("a",{href:h.content,target:"_blank",rel:"noreferrer",className:`block overflow-hidden rounded-2xl border bg-white p-1 shadow-sm ${f?"rounded-br-md border-sky-200":"rounded-bl-md border-slate-200"}`,children:e.jsx("img",{src:h.content,alt:"聊天图片",className:"max-h-80 max-w-full rounded-xl object-contain"})}):h.message_type==="video"?e.jsx("video",{src:h.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 ${f?"rounded-br-md bg-sky-500 text-white":"rounded-bl-md border border-slate-200 bg-white text-slate-800"}`,children:da(h.content)}),e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] text-slate-400",children:[ma(h.sent_at),f&&(h.status==="failed"?e.jsx(rt,{className:"h-3 w-3 text-red-500"}):h.status==="sent"?e.jsx(ul,{className:"h-3 w-3 text-sky-500"}):e.jsx(Ke,{className:"h-3 w-3"}))]})]}),f&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-sky-100 ring-2 ring-white",children:S!=null&&S.avatar_url?e.jsx("img",{src:S.avatar_url,alt:"我",className:"h-full w-full object-cover"}):e.jsx(Gt,{className:"m-2 h-5 w-5 text-sky-600"})})]},h.message_key)})]})}),p&&e.jsx("div",{className:"border-t border-red-100 bg-red-50 px-5 py-2 text-xs font-medium text-red-700",children:p}),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:()=>Re(h=>!h),disabled:ae||(S==null?void 0:S.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(hl,{className:"h-5 w-5"})}),be&&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:qa.map(([h,f])=>e.jsx("button",{type:"button",title:`[${h}]`,onClick:()=>{v(P=>P+`[${h}]`),Re(!1)},className:"flex h-10 w-10 items-center justify-center rounded-lg hover:bg-slate-100",children:e.jsx("img",{src:En(f),alt:`[${h}]`,className:"h-8 w-8 object-contain"})},h))})]})]}),e.jsx("input",{ref:V,type:"file",accept:"image/*",className:"hidden",onChange:h=>{var f;return void re((f=h.target.files)==null?void 0:f[0])}}),e.jsx("button",{type:"button",onClick:()=>{var h;return(h=V.current)==null?void 0:h.click()},disabled:ae||(S==null?void 0:S.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(gl,{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:oe,onChange:h=>v(h.target.value),rows:2,maxLength:2e3,onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),Oe())},disabled:(S==null?void 0:S.runtime_state)!=="online",placeholder:(S==null?void 0:S.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 Oe(),disabled:!oe.trim()||ae||(S==null?void 0:S.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:ae?e.jsx(Pe,{className:"h-4 w-4 animate-spin"}):e.jsx(Zt,{className:"h-4 w-4"})})]})]})]}):e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(is,{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:"该账号的新消息会实时出现在左侧列表。"})]})})]})]})},Fa="ydisks.sidebar.v1",qn=()=>{try{return window.localStorage.getItem(Fa)==="collapsed"}catch{return!1}},Fn=t=>{try{window.localStorage.setItem(Fa,t?"collapsed":"expanded")}catch{}},Ba={"/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"},pa=Object.fromEntries(Object.entries(Ba).map(([t,a])=>[a,t])),ua=()=>Ba[window.location.pathname]||"dashboard",Bn=()=>{const[t,a]=r.useState(!1),[l,i]=r.useState(!1),[m,_]=r.useState(ua),[N,R]=r.useState(!0),[g,C]=r.useState(!1),[j,F]=r.useState(""),[G,me]=r.useState(""),[oe,v]=r.useState(!1),[q,ce]=r.useState(""),[Q,ee]=r.useState(""),[B,ge]=r.useState(""),[ue,k]=r.useState(!1),[Z,se]=r.useState(""),[K,ve]=r.useState(),[J,I]=r.useState(qn),E=T=>{const p=T==="settings"&&!l?"dashboard":T,b=pa[p];b&&b!==window.location.pathname&&window.history.pushState({},"",b),_(p)};r.useEffect(()=>{const T=()=>_(ua());return window.addEventListener("popstate",T),()=>window.removeEventListener("popstate",T)},[]),r.useEffect(()=>{La().then(p=>{if((p==null?void 0:p.initialized)===!1){C(!0),a(!1),i(!1);return}C(!1),p!=null&&p.authenticated?(a(!0),i(p.is_admin===!0)):i(!1)}).catch(()=>{a(!1),i(!1)}).finally(()=>R(!1));const T=()=>{a(!1),i(!1)};return window.addEventListener("auth:logout",T),()=>window.removeEventListener("auth:logout",T)},[]),r.useEffect(()=>{!N&&t&&!l&&m==="settings"&&(window.history.replaceState({},"",pa.dashboard),_("dashboard"))},[N,t,l,m]);const $=async T=>{T.preventDefault(),v(!0),ce("");try{const p=await Al({username:j,password:G});p.success?(a(!0),i(p.is_admin===!0)):ce(p.message||"登录失败")}catch(p){const b=p instanceof Error?p.message:String(p);ce(b||"登录失败")}finally{v(!1)}},be=async T=>{if(T.preventDefault(),se(""),Q.length<8){se("密码至少需要 8 个字符");return}if(Q!==B){se("两次输入的密码不一致");return}k(!0);try{const p=await $l(Q);if(!p.success){se(p.message||"初始化失败,请重试");return}C(!1),a(!0),i(p.is_admin===!0),ee(""),ge("")}catch(p){const b=p instanceof Error?p.message:String(p);se(b||"初始化失败,请重试")}finally{k(!1)}},Re=async()=>{try{await Pl()}catch(T){console.error("退出登录失败",T)}finally{a(!1),i(!1)}};if(N)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-surface",children:e.jsx(Pe,{className:"w-8 h-8 text-brand animate-spin"})});if(g)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-canvas p-4 relative overflow-hidden font-sans",children:[e.jsx("div",{className:"absolute top-[-10%] left-[-10%] w-[60%] h-[60%] bg-blue-200/40 rounded-full blur-[120px] animate-pulse"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[60%] h-[60%] bg-blue-200/30 rounded-full blur-[120px] animate-pulse",style:{animationDelay:"2s"}}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-3xl p-8 md:p-12 rounded-xl shadow-panel w-full max-w-xl border border-white relative z-10 animate-fade-in",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"mx-auto mb-6 flex justify-center",children:e.jsx(ms,{sizeClass:"w-24 h-24"})}),e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900 mb-2 tracking-tight",children:"首次设置管理员密码"}),e.jsx("p",{className:"text-gray-600 font-medium",children:"设置完成后会自动进入系统,管理员账号为 admin。"})]}),e.jsxs("form",{onSubmit:be,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(Fs,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"password",placeholder:"设置管理员密码(至少 8 个字符)",value:Q,onChange:T=>ee(T.target.value),autoFocus:!0,className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Mt,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"password",placeholder:"再次输入密码",value:B,onChange:T=>ge(T.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]})]}),Z&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-50 text-red-500 text-sm text-center font-bold flex items-center justify-center gap-2",children:[e.jsx(Mt,{className:"w-4 h-4"})," ",Z]}),e.jsx("button",{type:"submit",disabled:ue,className:"w-full ios-btn-primary h-14 rounded-2xl text-lg shadow-xl shadow-blue-200 mt-2 flex items-center justify-center gap-2 group disabled:opacity-70",children:ue?e.jsx(Pe,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:["设置密码并进入系统 ",e.jsx(xs,{className:"w-5 h-5 group-hover:translate-x-1 transition-transform"})]})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-gray-100 text-center",children:e.jsx("span",{className:"text-xs text-gray-400 font-medium tracking-widest uppercase",children:"Secure Bootstrap"})})]})]});if(!t)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-canvas p-4 relative overflow-hidden font-sans",children:[e.jsx("div",{className:"absolute top-[-10%] left-[-10%] w-[60%] h-[60%] bg-blue-200/40 rounded-full blur-[120px] animate-pulse"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[60%] h-[60%] bg-blue-200/30 rounded-full blur-[120px] animate-pulse",style:{animationDelay:"2s"}}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-3xl p-8 md:p-12 rounded-xl shadow-panel w-full max-w-lg border border-white relative z-10 animate-fade-in",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("div",{className:"group mx-auto mb-6 flex cursor-pointer justify-center",children:e.jsx(ms,{sizeClass:"w-24 h-24",logoClassName:"w-full h-full text-white group-hover:scale-110 transition-transform"})}),e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900 mb-2 tracking-tight",children:"欢迎回来"}),e.jsx("p",{className:"text-gray-500 font-medium",children:"Ydisks闲鱼助手 · 自动发货与管家系统"})]}),e.jsxs("form",{onSubmit:$,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(xt,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"text",placeholder:"管理员账号",value:j,onChange:T=>F(T.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Fs,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"password",placeholder:"密码",value:G,onChange:T=>me(T.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]})]}),q&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-50 text-red-500 text-sm text-center font-bold flex items-center justify-center gap-2",children:[e.jsx(Mt,{className:"w-4 h-4"})," ",q]}),e.jsx("button",{type:"submit",disabled:oe,className:"w-full ios-btn-primary h-14 rounded-2xl text-lg shadow-xl shadow-blue-200 mt-2 flex items-center justify-center gap-2 group disabled:opacity-70",children:oe?e.jsx(Pe,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:["立即登录 ",e.jsx(xs,{className:"w-5 h-5 group-hover:translate-x-1 transition-transform"})]})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-gray-100",children:e.jsx("div",{className:"mt-6 text-center",children:e.jsx("span",{className:"text-xs text-gray-400 font-medium tracking-widest uppercase",children:"Ydisks闲鱼助手 v1.0"})})})]})]});const ae=()=>{switch(m){case"dashboard":return e.jsx(rs,{});case"accounts":return e.jsx(rn,{});case"chat":return e.jsx(Mn,{});case"orders":return e.jsx(cn,{});case"cards":return e.jsx(xn,{});case"items":return e.jsx(yn,{onConfigureDelivery:T=>{ve({cookieId:T.cookie_id,itemId:T.item_id,requestId:Date.now()}),E("rules")}});case"rules":return e.jsx(In,{initialDeliveryTarget:K,onDeliveryTargetHandled:()=>ve(void 0)});case"notifications":return e.jsx(Rn,{isAdmin:l});case"settings":return l?e.jsx(_n,{}):e.jsx(rs,{});default:return e.jsx(rs,{})}};return e.jsxs("div",{className:"flex min-h-screen bg-canvas text-ink",children:[e.jsx(wl,{activeTab:m,isAdmin:l,collapsed:J,onToggleCollapsed:()=>I(T=>{const p=!T;return Fn(p),p}),onNavigate:E,onLogout:Re}),e.jsxs("main",{className:`h-screen min-w-0 flex-1 overflow-x-hidden overflow-y-auto scroll-smooth transition-[margin] duration-300 ${J?"ml-16":"ml-64"} ${m==="chat"?"p-4 md:p-6":"p-8 md:p-12"}`,children:[e.jsx("div",{className:"fixed top-0 right-0 w-[800px] h-[800px] bg-gradient-to-bl from-blue-50 to-transparent rounded-full blur-[120px] pointer-events-none -z-10 opacity-60"}),e.jsx("div",{className:`${m==="chat"?"mx-auto max-w-[1680px]":"mx-auto max-w-[1400px] pb-10"}`,children:ae()})]})]})},za=document.getElementById("root");if(!za)throw new Error("Could not find root element to mount to");const zn=Wa.createRoot(za);zn.render(e.jsx(ys.StrictMode,{children:e.jsx(Bn,{})})); +`),Te=new Blob(["\uFEFF"+H],{type:"text/csv;charset=utf-8"}),s=URL.createObjectURL(Te),o=document.createElement("a");o.href=s,o.download="批量铺货模板.csv",document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(s)},Lt=()=>{h(n=>({...n,cookie_id:R||n.cookie_id})),B(!0)},nt=()=>{P(n=>({...n,cookie_id:R||n.cookie_id})),ue(!0)},it=async n=>{if(!(n?R:f.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");p(!0),navigator.geolocation.getCurrentPosition(async H=>{try{const Te=await bn(H.coords.longitude,H.coords.latitude);if(!Te.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");n?(ye(Te),ke(Te[0])):(U(Te),ne(Te[0]))}catch(Te){alert((Te==null?void 0:Te.message)||"获取发货地失败")}finally{p(!1)}},H=>{p(!1),alert(H.code===H.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},Ot=n=>i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id).length>0?i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id):i.filter(w=>w.cookie_id===n.cookie_id&&!w.item_id),pt=n=>{switch(n){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 n||"-"}},ut=n=>{switch(n){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"}},st=r.useMemo(()=>new Map(_.map(n=>[n.id,n])),[_]),ht=r.useMemo(()=>C?a.filter(n=>n.cookie_id===C):a,[C,a]),Ge=n=>{const w=st.get(n),H=(w==null?void 0:w.remark)||(w==null?void 0:w.nickname);return H?`${H} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},ot=n=>{const w=st.get(n);return(w==null?void 0:w.remark)||(w==null?void 0:w.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(ll,{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:C,onChange:n=>j(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.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(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-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:R,onChange:n=>g(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:De,disabled:F||!R,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(ze,{className:`w-4 h-4 ${F?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Lt,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(et,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:nt,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(es,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Ne(),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(Bt,{className:"w-4 h-4"}),S&&["running","canceling"].includes(S.status)?"继续批量任务":"批量铺货"]}),S&&!["running","canceling"].includes(S.status)&&e.jsx("button",{onClick:()=>void Fe(),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:[ht.map(n=>{const w=Ot(n),H=w.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:()=>te(n),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(Nt,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>u(n),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(Qe,{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:[n.item_image?e.jsx("img",{src:n.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(ga,{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:fn(n.item_price)})]}),e.jsx("h3",{className:"font-bold text-gray-900 line-clamp-2 text-xs mb-1.5 h-8 leading-4",children:n.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:ot(n.cookie_id),children:[e.jsx(xt,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:ot(n.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: ",n.item_id]}),e.jsxs("span",{className:`inline-flex items-center gap-1 font-bold ${H?"text-emerald-600":"text-amber-600"}`,children:[H?e.jsx(ds,{className:"w-3 h-3"}):e.jsx(rl,{className:"w-3 h-3"}),H?`${w.length} 规则`:"未配置"]})]}),e.jsx("div",{className:"space-y-2 mt-auto",children:e.jsxs("button",{onClick:()=>t(n),className:`w-full flex items-center justify-between gap-1 px-2.5 py-2 rounded-lg text-[11px] font-extrabold transition-all ${H?"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(nl,{className:"w-3.5 h-3.5"}),H?"查看发货规则":"关联发货规则"]}),e.jsx(xs,{className:"w-3.5 h-3.5"})]})})]},`${n.cookie_id}-${n.item_id}`)}),ht.length===0&&e.jsxs("div",{className:"col-span-full py-20 text-center text-gray-400",children:[e.jsx(ba,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),C?"该账号暂无商品数据":"暂无商品数据,请选择账号进行同步"]})]}),ce&&de&&qe.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: ",de.item_id]})]}),e.jsx("button",{onClick:()=>Q(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(Me,{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:fe.item_title||"",onChange:n=>Oe({...fe,item_title:n.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"价格",value:fe.item_price||"",onChange:n=>Oe({...fe,item_price:n.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"分类",value:fe.item_category||"",onChange:n=>Oe({...fe,item_category:n.target.value})}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述",value:fe.item_description||"",onChange:n=>Oe({...fe,item_description:n.target.value})})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:je,className:"w-full 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),ee&&qe.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:()=>B(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(Me,{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:re.cookie_id,onChange:n=>h({...re,cookie_id:n.target.value}),children:[e.jsx("option",{value:"",children:"选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.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:re.item_id,onChange:n=>h({...re,item_id:n.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:re.item_price,onChange:n=>h({...re,item_price:n.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:re.item_title,onChange:n=>h({...re,item_title:n.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:re.item_image,onChange:n=>h({...re,item_image:n.target.value})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:L,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(et,{className:"w-4 h-4"}),"添加商品"]})})]})}),document.body),ge&&qe.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:()=>ue(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(Me,{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:f.cookie_id,onChange:n=>{P({...f,cookie_id:n.target.value}),U([]),ne(null)},children:[e.jsx("option",{value:"",children:"选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.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:f.title,onChange:n=>P({...f,title:n.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:f.quantity,onChange:n=>P({...f,quantity:n.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:f.description,onChange:n=>P({...f,description:n.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:f.price,onChange:n=>P({...f,price:n.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:f.original_price,onChange:n=>P({...f,original_price:n.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:f.postage_mode,onChange:n=>P({...f,postage_mode:n.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:"无需邮寄"})]})]})]}),f.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:f.postage,onChange:n=>P({...f,postage:n.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:T||!f.cookie_id,onClick:()=>void it(!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(Ms,{className:"h-4 w-4"}),T?"定位中...":"获取当前位置"]})]}),b.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,b.indexOf(M))),onChange:n=>ne(b[Number(n.target.value)]||null),children:b.map((n,w)=>e.jsx("option",{value:String(w),children:[n.province,n.city,n.area,n.poi_name].filter(Boolean).join(" ")},`${n.division_id}-${n.poi_id}-${w}`))})]}),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(Bt,{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:f.images.length?"已选择 "+f.images.length+" 张":"支持 JPG / PNG / GIF"}),e.jsx("input",{className:"hidden",type:"file",accept:"image/*",multiple:!0,onChange:n=>P({...f,images:Array.from(n.target.files||[]).slice(0,9)})})]}),z.length>0&&e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-3",children:z.map(n=>e.jsx("div",{className:"aspect-square rounded-xl bg-gray-100 overflow-hidden border border-gray-100",children:e.jsx("img",{src:n.url,alt:"",className:"w-full h-full object-cover"})},n.key))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{disabled:me,onClick:le,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(es,{className:"w-4 h-4"}),me?"正在发布...":"发布到闲鱼"]})})]})}),document.body),k&&qe.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 Ct(),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(Me,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx("div",{className:"grid grid-cols-4 gap-2",children:[["upload","1 上传"],["preview","2 预检"],["running","3 发布"],["done","4 结果"]].map(([n,w])=>e.jsx("div",{className:`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${se===n?"bg-blue-600 text-white border-blue-600":"bg-gray-50 text-gray-500 border-gray-100"}`,children:w},n))}),se==="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:mt,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:R,onChange:n=>{g(n.target.value),ye([]),ke(null)},children:[e.jsx("option",{value:"",children:"选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.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(_t,{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:$,onChange:n=>be(n.target.value),onKeyDown:n=>{n.key==="Enter"&&(n.preventDefault(),Ue())}})]}),e.jsxs("button",{type:"button",disabled:!R||!$.trim()||Re,onClick:()=>void Ue(),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(_t,{className:"h-4 w-4"}),Re?"匹配中...":"获取类目"]})]}),x.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(ds,{className:"h-4 w-4 shrink-0 text-emerald-600"}),e.jsx("span",{className:"truncate",children:x.catName})]}),e.jsxs("div",{className:"mt-1 font-mono text-xs text-gray-500",children:["类目 ",x.catId," · 频道 ",x.channelCatId]})]}),e.jsx("button",{type:"button",title:"清除默认类目",onClick:()=>V({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(Me,{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:T||!R,onClick:()=>void it(!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(Ms,{className:"h-4 w-4"}),T?"定位中...":"获取当前位置"]})]}),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(Ee))),onChange:n=>ke(he[Number(n.target.value)]||null),children:he.map((n,w)=>e.jsx("option",{value:String(w),children:[n.province,n.city,n.area,n.poi_name].filter(Boolean).join(" ")},`${n.division_id}-${n.poi_id}-${w}`))})]}),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(Bt,{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:ve?ve.name:"支持 .xlsx / .csv / .tsv"}),e.jsx("input",{className:"hidden",type:"file",accept:".xlsx,.csv,.tsv",onChange:n=>{var w;return J(((w=n.target.files)==null?void 0:w[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(Bt,{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:I?I.name:"表格图片字段使用 zip 内相对路径"}),e.jsx("input",{className:"hidden",type:"file",accept:".zip",onChange:n=>{var w;return E(((w=n.target.files)==null?void 0:w[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(([n,w,H])=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-bold text-gray-900 whitespace-nowrap",children:n}),e.jsx("td",{className:`px-3 py-2 min-w-[210px] font-bold ${w==="每个商品都要填"?"text-red-600":w==="可以留空"?"text-gray-500":"text-amber-700"}`,children:w}),e.jsx("td",{className:"px-3 py-2 min-w-[260px]",children:H})]},n))})]})})]})]}),se==="preview"&&X&&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:X.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:X.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:X.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:X.rows.map(n=>{var w,H,Te,s;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:n.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 ${n.valid?"bg-emerald-50 text-emerald-700 border-emerald-100":"bg-red-50 text-red-700 border-red-100"}`,children:n.valid?"可发布":"需修正"})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[240px] truncate",children:n.title||"-"}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:["¥",n.price||"-"," / ",n.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:((w=n.category)==null?void 0:w.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((H=n.category)==null?void 0:H.cat_id)||"失败后使用电子资料"})]}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:[((Te=n.images)==null?void 0:Te.length)||0," 张"]}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[280px]",children:((s=n.errors)==null?void 0:s.join(";"))||"-"})]},n.row_no)})})]})})]}),(se==="running"||se==="done")&&d&&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 ${ut(d.status)}`,children:[e.jsx("div",{className:"text-xs font-bold opacity-70",children:"任务状态"}),e.jsx("div",{className:"text-xl font-extrabold mt-1",children:pt(d.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:d.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:d.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:d.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:d.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:d.rows.map(n=>{var w,H;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:n.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 ${ut(n.status)}`,children:pt(n.status)})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[260px] truncate",children:n.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:((w=n.category)==null?void 0:w.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((H=n.category)==null?void 0:H.cat_id)||"失败后使用电子资料"})]}),e.jsx("td",{className:"px-4 py-3 text-xs font-mono",children:n.item_url?e.jsx("a",{href:n.item_url,target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline",children:n.item_id}):n.item_id||"-"}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[340px]",children:n.error_message||"-"})]},n.id)})})]})})]})]}),e.jsxs("div",{className:"modal-footer",children:[se==="upload"&&e.jsxs("button",{disabled:v||!ve||!R,onClick:tt,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(ze,{className:`w-4 h-4 ${v?"animate-spin":""}`}),v?"正在预检...":"开始预检"]}),se==="preview"&&X&&e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{disabled:v,onClick:()=>void We(),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:v||X.valid<=0,onClick:kt,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(es,{className:"w-4 h-4"}),v?"启动中...":`确认发布 ${X.valid} 个商品`]})]}),(se==="running"||se==="done")&&d&&e.jsxs("div",{className:"flex gap-3 w-full",children:[d.status==="running"?e.jsx("button",{disabled:v,onClick:Je,className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"取消任务"}):d.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/${d.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:"下载结果"}),d.retryable>0&&!["running","canceling"].includes(d.status)&&e.jsxs("button",{disabled:v,onClick:St,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(ze,{className:`w-4 h-4 ${v?"animate-spin":""}`}),"重试失败项"]}),!["running","canceling"].includes(d.status)&&e.jsx("button",{onClick:()=>{Z(!1),Ae(),we()},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)]})},ra="https://dashscope.aliyuncs.com/compatible-mode/v1",jn=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],Nn=new Set(["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"]),_n=()=>{const[t,a]=r.useState(null),[l,i]=r.useState(!1),[m,_]=r.useState(""),[N,R]=r.useState(!1),[g,C]=r.useState([]),[j,F]=r.useState(!1),[G,me]=r.useState(""),[oe,v]=r.useState(!1),q=r.useRef(null),[ce,Q]=r.useState(!1),[ee,B]=r.useState(!1),[ge,ue]=r.useState(!1),[k,Z]=r.useState(!1),[se,K]=r.useState(!1),[ve,J]=r.useState(null),[I,E]=r.useState({new_username:"",current_password:"",new_password:"",confirm_password:""});r.useEffect(()=>{be(),La().then(b=>{b.username&&E(U=>({...U,new_username:b.username||""}))}).catch(()=>{})},[]),r.useEffect(()=>{const b=U=>{var M;(M=q.current)!=null&&M.contains(U.target)||v(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]);const $=async(b,U=!1)=>{const M=b||t,ne=(M==null?void 0:M.ai_api_url)||(M==null?void 0:M.ai_base_url)||ra;F(!0),me("");try{const he=await qr(ne,(M==null?void 0:M.ai_api_key)||"");C(he),v(U&&he.length>0),!(M!=null&&M.ai_model)&&he.length>0&&a(ye=>ye&&{...ye,ai_model:he[0]})}catch(he){C([]),v(!1),me(he.message||"读取模型失败")}finally{F(!1)}},be=()=>{i(!0),_(""),$a().then(b=>{a(b),$(b)}).catch(b=>{a(null),_(b.message||"加载配置失败")}).finally(()=>i(!1))},Re=async()=>{if(t){R(!0);try{const b=Object.fromEntries(Object.entries(t).filter(([U,M])=>!Nn.has(U)&&M!==void 0&&M!==null));await Pa(b),alert("系统配置已保存")}catch(b){alert("保存失败:"+b.message)}finally{R(!1)}}},ae=async b=>{b.preventDefault(),J(null);const U=I.new_username.trim();if(U.length<3){J({type:"error",text:"用户名至少需要 3 个字符"});return}if(!I.current_password){J({type:"error",text:"请输入当前密码确认身份"});return}if(I.new_password&&I.new_password.length<8){J({type:"error",text:"新密码至少需要 8 个字符"});return}if(I.new_password!==I.confirm_password){J({type:"error",text:"两次输入的新密码不一致"});return}K(!0);try{const M=await Rl({current_password:I.current_password,new_username:U,new_password:I.new_password||void 0});if(!M.success){J({type:"error",text:M.message||"登录凭据更新失败"});return}J({type:"success",text:M.message||"登录凭据已更新"}),window.setTimeout(()=>window.location.reload(),1400)}catch(M){J({type:"error",text:M.message||"登录凭据更新失败"})}finally{K(!1)}};if(!t)return e.jsx("div",{className:"p-8 text-center text-gray-400",children:m||(l?"加载配置中...":"暂无配置")});const T=t.ai_model||"",p=g;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(js,{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:be,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(ze,{className:"w-4 h-4"}),"刷新"]})]}),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(il,{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:t.log_level||"info",onChange:b=>a({...t,log_level:b.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:jn.map(b=>e.jsx("option",{value:b.value,children:b.label},b.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:t.log_format||"text",onChange:b=>a({...t,log_format:b.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:t.renewal_log_retention_days??10,onChange:b=>a({...t,renewal_log_retention_days:parseInt(b.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(vs,{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:t.ai_api_url||ra,onChange:b=>a({...t,ai_api_url:b.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:ce?"text":"password",value:t.ai_api_key||"",onChange:b=>a({...t,ai_api_key:b.target.value}),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",placeholder:"sk-..."}),e.jsx("button",{type:"button",onClick:()=>Q(!ce),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:ce?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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:q,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:T,onFocus:()=>g.length>0&&v(!0),onChange:b=>{a({...t,ai_model:b.target.value}),g.length>0&&v(!0)},onKeyDown:b=>{b.key==="Escape"&&v(!1),b.key==="ArrowDown"&&g.length>0&&v(!0)},className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:()=>g.length>0&&v(b=>!b),disabled:g.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(ol,{className:`w-4 h-4 transition-transform ${oe?"rotate-180":""}`})}),oe&&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:p.length>0?p.map(b=>e.jsxs("button",{type:"button",onClick:()=>{a({...t,ai_model:b}),v(!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:b}),b===T&&e.jsx(Ke,{className:"w-4 h-4 shrink-0 text-brand"})]},b)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:()=>$(void 0,!0),disabled:j,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(ze,{className:`w-4 h-4 ${j?"animate-spin":""}`}),"读取模型"]})]}),G?e.jsx("p",{className:"text-xs text-red-500",children:G}):e.jsx("p",{className:"text-xs text-gray-500",children:g.length>0?`已从当前 API 地址读取到 ${g.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(Mt,{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:t["captcha.remote_service_url"]||"",onChange:b=>a({...t,"captcha.remote_service_url":b.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:ee?"text":"password",value:t["captcha.remote_secret_key"]||"",onChange:b=>a({...t,"captcha.remote_secret_key":b.target.value}),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",autoComplete:"off"}),e.jsx("button",{type:"button",onClick:()=>B(!ee),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:ee?"隐藏秘钥":"显示秘钥",children:ee?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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(t["captcha.remote_pass_cookies"]||"").toLowerCase()==="true",onChange:b=>a({...t,"captcha.remote_pass_cookies":b.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(qs,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:ae,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(Gt,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:I.new_username,onChange:b=>E({...I,new_username:b.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:ge?"text":"password",value:I.current_password,onChange:b=>E({...I,current_password:b.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:()=>ue(!ge),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:ge?"隐藏密码":"显示密码",children:ge?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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:k?"text":"password",value:I.new_password,onChange:b=>E({...I,new_password:b.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:()=>Z(!k),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:k?"隐藏密码":"显示密码",children:k?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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:k?"text":"password",value:I.confirm_password,onChange:b=>E({...I,confirm_password:b.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),ve&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${ve.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(Mt,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:ve.text})]}),e.jsxs("button",{type:"submit",disabled:se||!I.new_username||!I.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(qs,{className:"w-4 h-4"}),se?"正在更新...":"更新登录凭据"]})]})]})]})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:Re,disabled:N,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(He,{className:"w-6 h-6"}),N?"保存中...":"保存所有配置"]})})]})},ns=(t,a)=>t.allowed_resolutions.includes(a),vn=(t,a)=>({runs:t.runs.filter(l=>!a||l.cookie_id===a),pending_tasks:t.pending_tasks.filter(l=>!a||l.cookie_id===a)}),wn=t=>({external_result_unknown:"外部动作结果未知",invalid_snapshot:"历史数据无法恢复",rule_unavailable:"规则不可用",partial_failure:"部分动作失败",execution_failed:"动作执行失败"})[t]||"自动化异常",kn=(t,a,l,i,m,_)=>t!==a||l!==i?!1:(_(m),!0),at={order_paid:{label:"付款后自动发货",shortLabel:"自动发货",description:"闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。",flow:["付款系统卡片","匹配商品/规格","发送卡密","确认发货"],accent:"blue",icon:qt},buyer_reviewed:{label:"评价后发送赠品",shortLabel:"评价赠品",description:"闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。",flow:["评价系统卡片","匹配商品/规格","发送赠品"],accent:"emerald",icon:cl},review_missing_timeout:{label:"超时未评价求评价",shortLabel:"求评价",description:"计划任务扫描已发货未评价订单,到期后发送求评价文案。",flow:["计划任务扫描","已发货未评价","达到等待时间","发送提醒"],accent:"amber",icon:va}},Vt=["order_paid","buyer_reviewed","review_missing_timeout"],Cn="亲,商品使用满意的话,麻烦给个评价,谢谢~",Pt=()=>({spec_name:"",spec_value:"",card_id:0,delivery_count:1,enabled:!0,delay_override:!1,delay_seconds:0}),Da=t=>{if(!t)return{};try{const a=JSON.parse(t);return a&&typeof a=="object"&&!Array.isArray(a)?a:{}}catch{return{}}},ct=(t,a={})=>{const l=Da(t);return JSON.stringify({after_shipped_hours:Number(l.after_shipped_hours||72),repeat_interval_hours:Number(l.repeat_interval_hours||24),max_attempts:Number(l.max_attempts||1),...a})},Rt=(t,a)=>{var i;const l=((i=at[t])==null?void 0:i.label)||"自动化规则";return a?`${l} - ${a}`:l},na=t=>{const a=(t||"").trim();return a?Object.values(at).some(l=>a===l.label||a.startsWith(`${l.label} -`)):!0},Et=(t,a=0)=>{if(t==="review_missing_timeout")return[{action_type:"send_text",message_template:Cn,enabled:!0,sort_order:1}];const l={action_type:"send_card",card_id:a,delivery_count:1,enabled:!0,sort_order:1};return t==="order_paid"?[l,{action_type:"confirm_shipment",enabled:!0,sort_order:2}]:[l]},Sn=t=>{var l,i;if(t.trigger_type==="review_missing_timeout")return((i=(l=t.actions)==null?void 0:l.find(m=>m.action_type==="send_text"))==null?void 0:i.message_template)||"发送求评价文案";const a=(t.actions||[]).filter(m=>m.action_type==="send_card");return a.length?a.map(m=>m.card_name||`卡密 ${m.card_id}`).join(" / "):"未配置卡密库存"},ia=(t,a=!1)=>{const l={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 l[t]||l.blue},Ln=t=>t?"bg-emerald-100 text-emerald-700":"bg-gray-200 text-gray-500",Qt=t=>(t==null?void 0:t.nickname)||(t==null?void 0:t.remark)||(t==null?void 0:t.id)||"未知账号",On=t=>t===!0||t===1||t==="1",In=({initialDeliveryTarget:t,onDeliveryTargetHandled:a})=>{var w,H,Te;const[l,i]=r.useState("automation"),[m,_]=r.useState([]),[N,R]=r.useState({runs:[],pending_tasks:[]}),[g,C]=r.useState([]),[j,F]=r.useState({}),[G,me]=r.useState([]),[oe,v]=r.useState([]),[q,ce]=r.useState([]),[Q,ee]=r.useState(!1),[B,ge]=r.useState(""),[ue,k]=r.useState(""),[Z,se]=r.useState(""),[K,ve]=r.useState(""),[J,I]=r.useState("all"),[E,$]=r.useState(1),[be,Re]=r.useState(10),[ae,T]=r.useState(0),[p,b]=r.useState(0),[U,M]=r.useState({}),ne=r.useRef(0),he=r.useRef(0),ye=r.useRef("");ye.current=B;const[Ee,ke]=r.useState(!1),[x,V]=r.useState(!1),[X,c]=r.useState(!1),[d,D]=r.useState(null),[S,Y]=r.useState(null),[O,de]=r.useState({cookie_id:"",enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""});G.find(s=>s.id===B);const Se=r.useCallback(async()=>{const[s,o,y,A]=await Promise.all([Ft(),Xe(),vt(),Xs()]);me(s),v(o),ce(y),F(A),ge(W=>{var pe;return W||((pe=s[0])==null?void 0:pe.id)||""})},[]),fe=r.useCallback(async()=>{const s=++ne.current,o=Or().catch(W=>(console.warn("加载自动化异常列表失败,不阻断规则展示",W),null)),y=await Cr({cookieId:B||void 0,triggerType:K,enabled:J==="all"?void 0:J==="enabled",search:Z,page:E,pageSize:be});if(s!==ne.current)return;_(y.data),T(y.total),b(y.total_pages),M(y.trigger_counts||{}),y.page!==E&&$(y.page);const A=await o;s===ne.current&&A&&R(A)},[E,be,J,K,Z,B]),Oe=r.useCallback(async()=>{const s=B;if(s!==ye.current)return;const o=++he.current;if(C([]),!s)return;const y=await Rr(s);kn(o,he.current,s,ye.current,y,C)},[B]),re=r.useCallback(async()=>{F(await Xs())},[]),h=r.useCallback(async()=>{ee(!0);try{l==="automation"?await fe():l==="reply"?await Oe():await re()}finally{ee(!1)}},[l,fe,re,Oe]);r.useEffect(()=>{const s=window.setTimeout(()=>{$(1),se(ue.trim())},300);return()=>window.clearTimeout(s)},[ue]),r.useEffect(()=>{Se().catch(s=>console.error("加载规则参考数据失败",s))},[Se]),r.useEffect(()=>{h().catch(s=>console.error("刷新规则页面失败",s))},[h]);const f=r.useMemo(()=>m.filter(s=>!B||s.cookie_id===B),[m,B]),P=r.useMemo(()=>vn(N,B),[N,B]),z=r.useMemo(()=>G.filter(s=>!B||s.id===B),[G,B]),Ie=r.useMemo(()=>{if(p<=1)return[];const s=Math.max(1,Math.min(E-2,p-4)),o=Math.min(p,s+4);return Array.from({length:o-s+1},(y,A)=>s+A)},[E,p]),Ae=!!(ue.trim()||K||J!=="all"),we=()=>{k(""),se(""),ve(""),I("all"),$(1)},De=r.useMemo(()=>{const s=(d==null?void 0:d.cookie_id)||B;return q.filter(o=>o.cookie_id===s)},[d==null?void 0:d.cookie_id,q,B]),te=r.useMemo(()=>{if(!(!(d!=null&&d.cookie_id)||!(d!=null&&d.item_id)))return q.find(s=>s.cookie_id===d.cookie_id&&s.item_id===d.item_id)},[d==null?void 0:d.cookie_id,d==null?void 0:d.item_id,q]),je=On(te==null?void 0:te.is_multi_spec),u=(d==null?void 0:d.trigger_type)||"order_paid",L=at[u],le=Da(d==null?void 0:d.config_json),Ne=r.useCallback((s="order_paid",o=B,y="")=>{const A=q.find(pe=>pe.cookie_id===o&&pe.item_id===y),W=(A==null?void 0:A.item_title)||y;return{name:Rt(s,W),trigger_type:s,cookie_id:o,item_id:y,item_title:(A==null?void 0:A.item_title)||"",item_keyword:W,card_group_id:0,priority:100,enabled:!0,config_json:s==="review_missing_timeout"?ct():"{}",actions:Et(s),variants:s==="review_missing_timeout"?[]:[Pt()]}},[q,B]),Ue=r.useCallback(s=>{var y,A;const o=s.trigger_type||"order_paid";D({...s,trigger_type:o,config_json:o==="review_missing_timeout"?ct(s.config_json):s.config_json||"{}",actions:(y=s.actions)!=null&&y.length?s.actions.map(W=>({...W})):Et(o,s.card_group_id),variants:(A=s.variants)!=null&&A.length?s.variants.map(W=>({...W})):o==="review_missing_timeout"?[]:[Pt()]}),ke(!0)},[]);r.useEffect(()=>{if(!t)return;let s=!1;return(async()=>{i("automation"),ge(t.cookieId),ee(!0);try{const[y,A,W]=await Promise.all([gs(),vt(),Xe().catch(xe=>(console.warn("加载卡密库存失败,不阻断打开自动化规则",xe),[]))]);if(s)return;_(y),ce(A),v(W);const pe=y.find(xe=>xe.cookie_id===t.cookieId&&xe.item_id===t.itemId&&xe.trigger_type==="order_paid");if(pe)Ue(pe);else{const xe=A.find($e=>$e.cookie_id===t.cookieId&&$e.item_id===t.itemId);D({...Ne("order_paid",t.cookieId,t.itemId),item_title:(xe==null?void 0:xe.item_title)||"",item_keyword:(xe==null?void 0:xe.item_title)||t.itemId,name:Rt("order_paid",(xe==null?void 0:xe.item_title)||t.itemId)}),ke(!0)}}catch(y){console.error("打开商品自动化规则失败",y),alert("无法加载该商品的自动化规则")}finally{s||(ee(!1),a==null||a())}})(),()=>{s=!0}},[Ne,t,a,Ue]);const Fe=(s="order_paid")=>{if(!B){alert("请先选择账号");return}D(Ne(s)),ke(!0)},tt=s=>{var A,W,pe,xe,$e;if(!d)return;const o=((W=(A=d.variants)==null?void 0:A.find(ie=>ie.card_id))==null?void 0:W.card_id)||((xe=(pe=d.actions)==null?void 0:pe.find(ie=>ie.action_type==="send_card"))==null?void 0:xe.card_id)||d.card_group_id||0,y=(te==null?void 0:te.item_title)||d.item_title||d.item_id||"";D({...d,trigger_type:s,name:na(d.name)?Rt(s,y):d.name,card_group_id:o,config_json:s==="review_missing_timeout"?ct(d.config_json):"{}",actions:Et(s,o),variants:s==="review_missing_timeout"?[]:($e=d.variants)!=null&&$e.length?d.variants:[{...Pt(),card_id:o}]})},kt=s=>{if(!d)return;const o=q.find(A=>A.cookie_id===(d.cookie_id||B)&&A.item_id===s),y=(o==null?void 0:o.item_title)||s;D({...d,item_id:s,item_title:(o==null?void 0:o.item_title)||"",item_keyword:y,name:na(d.name)?Rt(u,y):d.name})},Je=(w=d==null?void 0:d.variants)!=null&&w.length?d.variants:[Pt()],We=(s,o)=>{var A;if(!d)return;const y=Je.map((W,pe)=>pe===s?{...W,...o}:W);D({...d,variants:y,card_group_id:((A=y[0])==null?void 0:A.card_id)||0})},Ct=()=>{if(!d)return;const s=Je[Je.length-1];D({...d,variants:[...Je,{...Pt(),spec_name:je&&(s==null?void 0:s.spec_name)||"",spec_value:je&&(s==null?void 0:s.spec_value)||""}]})},St=async()=>{var A,W,pe,xe,$e;if(!d)return;const s=d.trigger_type||"order_paid";if(!d.cookie_id){alert("请选择账号");return}const o=(A=d.variants)!=null&&A.length?d.variants:[];if(s!=="review_missing_timeout"){if(!o.length||o.some(ie=>!ie.card_id)){alert(s==="buyer_reviewed"?"请选择评价赠品卡密库存":"请选择发货卡密库存");return}if(je&&o.some(ie=>!ie.spec_name.trim()||!ie.spec_value.trim())){alert("多规格商品必须填写每一行的规格名称和规格值");return}}if(s==="review_missing_timeout"&&!(((pe=(W=d.actions)==null?void 0:W.find(Ye=>Ye.action_type==="send_text"))==null?void 0:pe.message_template)||"").trim()){alert("请填写求评价文案");return}const y=s==="review_missing_timeout"?[]:o.map(ie=>({...ie,spec_name:je?ie.spec_name.trim():"",spec_value:je?ie.spec_value.trim():"",delivery_count:Math.max(1,Number(ie.delivery_count)||1),enabled:ie.enabled!==!1}));try{await Zs({...d,trigger_type:s,name:(d.name||"").trim()||Rt(s,(te==null?void 0:te.item_title)||d.item_id||""),config_json:s==="review_missing_timeout"?ct(d.config_json):d.config_json||"{}",actions:(xe=d.actions)!=null&&xe.length?d.actions:Et(s,(($e=y[0])==null?void 0:$e.card_id)||d.card_group_id||0),variants:y}),ke(!1),await Promise.all([fe(),Se()]),alert("保存成功")}catch(ie){console.error("保存自动化规则失败:",ie),alert("保存失败:"+ie.message)}},mt=async s=>{if(confirm("确定删除该自动化规则吗?"))try{await Lr(s),await fe(),alert("删除成功")}catch(o){alert("删除失败:"+o.message)}},Lt=async s=>{try{await Zs({...s,enabled:!s.enabled}),await fe()}catch(o){alert("操作失败:"+o.message)}},nt=async(s,o)=>{if(confirm(o==="continue"?"确认外部动作已经执行成功,并跳到下一步吗?":o==="retry"?"确认外部动作没有执行,可以安全重试吗?错误判断可能造成重复发送。":"确认终止该自动化运行吗?"))try{await Ir(s,o),await fe()}catch(A){alert("处理失败:"+A.message)}},it=async(s,o)=>{if(confirm(o==="retry"?"确认重新执行该任务吗?":"确认忽略并删除该异常任务吗?"))try{await Ar(s,o),await fe()}catch(y){alert("处理失败:"+y.message)}},Ot=()=>{if(!B){alert("请先选择账号");return}Y({keyword:"",reply_content:"",image_url:"",item_id:"",type:"text",match_type:"fuzzy",enabled:!0}),V(!0)},pt=async()=>{var o,y,A;if(!S||!B)return;const s=S.type==="image"?!!((o=S.image_url)!=null&&o.trim()):!!((y=S.reply_content)!=null&&y.trim());if(!((A=S.keyword)!=null&&A.trim())||!s){alert("请填写关键词和回复内容");return}try{await Er({...S,match_type:"fuzzy",enabled:!0},B),V(!1),await Oe(),alert("保存成功")}catch(W){alert("保存失败:"+W.message)}},ut=async s=>{if(!(!B||!confirm("确定删除该回复规则吗?")))try{await Dr(s,B),await Oe(),alert("删除成功")}catch(o){alert("删除失败:"+o.message)}},st=async(s=B)=>{if(!s){alert("请先选择账号");return}try{const o=await Jr(s);de({cookie_id:s,enabled:o.enabled,reply_content:o.reply_content,reply_once:o.reply_once,reply_image_url:o.reply_image_url||""})}catch{de({cookie_id:s,enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""})}c(!0)},ht=async()=>{if(!O.cookie_id){alert("请先选择账号");return}if(O.enabled&&!O.reply_content.trim()&&!O.reply_image_url.trim()){alert("启用默认回复时,请填写回复内容或图片 URL");return}try{await Vr(O.cookie_id,{enabled:O.enabled,reply_content:O.reply_content,reply_once:O.reply_once,reply_image_url:O.reply_image_url}),c(!1),await re(),alert("保存成功")}catch(s){alert("保存失败:"+s.message)}},Ge=async s=>{if(confirm("确定删除该账号默认回复吗?"))try{await Qr(s),await re(),alert("删除成功")}catch(o){alert("删除失败:"+o.message)}},ot=async s=>{if(confirm("确定清空该账号的默认回复记录吗?清空后可重新对所有会话使用“只回复一次”。"))try{await Gr(s),alert("清空成功")}catch(o){alert("清空失败:"+o.message)}},n=l==="automation"?"新建自动化":l==="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:B,onChange:s=>{ge(s.target.value),$(1)},className:"ios-input w-full px-4 py-3 rounded-2xl text-sm sm:w-64",children:[e.jsx("option",{value:"",children:"全部账号"}),G.map(s=>e.jsx("option",{value:s.id,children:Qt(s)},s.id))]}),e.jsxs("button",{onClick:h,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(ze,{className:`w-4 h-4 ${Q?"animate-spin":""}`}),"刷新"]}),e.jsxs("button",{onClick:l==="automation"?()=>Fe("order_paid"):l==="reply"?Ot:()=>void st(),disabled:!B,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(et,{className:"w-4 h-4"}),n]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[{id:"automation",label:"交易自动化",icon:cs},{id:"reply",label:"关键词回复",icon:Tt},{id:"default",label:"账号默认回复",icon:yt}].map(s=>{const o=s.icon;return e.jsxs("button",{onClick:()=>i(s.id),className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${l===s.id?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:[e.jsx(o,{className:"w-4 h-4"}),s.label]},s.id)})}),l==="automation"&&(P.runs.length>0||P.pending_tasks.length>0)&&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(rt,{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:[P.runs.map(s=>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:["账号 ",s.cookie_id," · 订单 ",s.order_id||"-"," · 已记录发送 ",s.sent_count," 条"]}),e.jsx("div",{className:"text-xs font-bold text-red-800 mt-1",children:wn(s.issue_kind)}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:s.error_message})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 shrink-0",children:[ns(s,"continue")&&e.jsx("button",{onClick:()=>void nt(s.id,"continue"),className:"px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold",children:"已执行,继续下一步"}),ns(s,"retry")&&e.jsx("button",{onClick:()=>void nt(s.id,"retry"),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"未执行,安全重试"}),ns(s,"cancel")&&e.jsx("button",{onClick:()=>void nt(s.id,"cancel"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"终止"})]})]},`run-${s.id}`)),P.pending_tasks.map(s=>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:["账号 ",s.cookie_id," · 延迟任务重试已达 ",s.attempt_count," 次"]}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:s.error_message})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>void it(s.id,"retry"),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"重新入队"}),e.jsx("button",{onClick:()=>void it(s.id,"dismiss"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"忽略"})]})]},`task-${s.id}`))]})]}),l==="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:Vt.map(s=>{const o=at[s],y=o.icon;return e.jsx("button",{type:"button",onClick:()=>Fe(s),className:`w-full text-left rounded-2xl border p-4 transition-colors ${ia(o.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(y,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:o.label}),e.jsx("div",{className:"text-xs opacity-75 mt-1 leading-5",children:o.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:["共 ",ae," 条"]})]}),e.jsx("div",{className:"space-y-3",children:Vt.map(s=>{const o=at[s],y=o.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(y,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:o.shortLabel})]}),e.jsx("span",{className:"text-sm font-black text-gray-900",children:U[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(_t,{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:ue,onChange:s=>{k(s.target.value),$(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(_a,{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:K,onChange:s=>{ve(s.target.value),$(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:"全部自动化类型"}),Vt.map(s=>e.jsx("option",{value:s,children:at[s].shortLabel},s))]})]}),e.jsxs("select",{"aria-label":"按启用状态筛选",value:J,onChange:s=>{I(s.target.value),$(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:"已禁用"})]}),Ae&&e.jsx("button",{type:"button",onClick:we,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(Me,{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:["找到 ",ae," 条规则"]}),Q&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ze,{className:"h-3.5 w-3.5 animate-spin"}),"正在更新"]})]})]}),Q&&f.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(ze,{className:"mr-2 h-4 w-4 animate-spin"}),"正在加载规则"]}):f.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-dashed border-gray-200 p-16 text-center",children:[e.jsx(cs,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-black text-gray-900",children:Ae?"没有匹配的自动化规则":"还没有自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2",children:Ae?"调整或清除筛选条件后再试。":"从左侧选择一个模板开始配置。"})]}):f.map(s=>{const o=at[s.trigger_type],y=o.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 ${ia(o.accent,!0)}`,children:e.jsx(y,{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 ${Ln(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:o.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:Sn(s)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>Ue(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(Nt,{className:"w-4 h-4"}),"编辑"]}),e.jsx("button",{onClick:()=>Lt(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:()=>mt(s.id),className:"p-2.5 rounded-xl text-red-500 hover:bg-red-50",title:"删除",children:e.jsx(Qe,{className:"w-4 h-4"})})]})]})},s.id)}),ae>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:["第 ",E," / ",Math.max(p,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:be,onChange:s=>{Re(Number(s.target.value)),$(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:E<=1||Q,onClick:()=>$(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(_s,{className:"h-4 w-4"})}),Ie.map(s=>e.jsx("button",{type:"button",disabled:Q,onClick:()=>$(s),className:`h-9 min-w-9 rounded-lg px-2 text-sm font-bold transition-colors ${s===E?"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===E?"page":void 0,children:s},s)),e.jsx("button",{type:"button",disabled:E>=p||Q,onClick:()=>$(s=>Math.min(p,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(Ns,{className:"h-4 w-4"})})]})]})]})]}),l==="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(rt,{className:"w-4 h-4"}),"这里只处理买家用户消息;系统通知不会进入关键词或 AI 回复。"]}),e.jsxs("div",{className:"space-y-3",children:[g.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:()=>{Y({...s}),V(!0)},className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(Nt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ut(s.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Qe,{className:"w-5 h-5"})})]})]},s.id)),g.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无关键词回复规则"})]})]}),l==="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(rt,{className:"w-4 h-4"}),"默认回复只处理买家用户消息;关键词未命中且 AI 未接管时才会使用。"]}),e.jsxs("div",{className:"space-y-3",children:[z.map(s=>{const o=j[s.id],y=!!(o!=null&&o.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 ${y?"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 ${y?"bg-purple-600 text-white":"bg-gray-200 text-gray-400"}`,children:e.jsx(yt,{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:Qt(s)}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-xs font-bold ${y?"bg-green-100 text-green-700":"bg-gray-200 text-gray-500"}`,children:y?"已启用":"未启用"}),(o==null?void 0:o.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:y?o.reply_content||o.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 st(s.id),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(Nt,{className:"w-4 h-4"})}),y&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>void ot(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 Ge(s.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Qe,{className:"w-5 h-5"})})]})]})]},s.id)}),z.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无账号"})]})]}),Ee&&d&&qe.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:d.id?"编辑自动化规则":"新建自动化规则"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:L.description})]}),e.jsx("button",{onClick:()=>ke(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",title:"关闭",children:e.jsx(Me,{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:Vt.map(s=>{const o=at[s],y=o.icon,A=u===s;return e.jsx("button",{type:"button",onClick:()=>tt(s),className:`w-full rounded-2xl p-4 text-left border transition-all ${A?"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(y,{className:`w-5 h-5 mt-0.5 ${A?"text-brand":"text-white"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black",children:o.label}),e.jsx("div",{className:`text-xs mt-1 leading-5 ${A?"text-gray-500":"text-gray-400"}`,children:o.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:L.flow.map((s,o)=>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:o+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(ds,{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:d.name||"",onChange:s=>D({...d,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:d.cookie_id||"",onChange:s=>D({...d,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:"选择账号"}),G.map(s=>e.jsx("option",{value:s.id,children:Qt(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:d.item_id||"",onChange:s=>kt(s.target.value),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级规则(不限定商品)"}),De.map(s=>e.jsx("option",{value:s.item_id,children:s.item_title||s.item_id},`${s.cookie_id}-${s.item_id}`))]})]})]}),te&&u!=="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:te.item_title||te.item_id}),e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${je?"bg-blue-50 text-blue-700":"bg-gray-100 text-gray-500"}`,children:je?"多规格商品":"普通商品"}),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:"多规格状态来自闲鱼商品本身,发布后不能在这里修改;系统会在买家付款后读取订单详情,按实际购买规格和数量匹配下面的发货规则。"})]})]}),u!=="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(dl,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:u==="buyer_reviewed"?"赠品库存":"发货库存"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:je?"每条发货内容绑定一个订单规格;同一规格可添加多条内容并全部发送。":"可添加多条发货内容,买家付款后会按顺序全部发送。"})]}),e.jsxs("button",{type:"button",onClick:Ct,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(et,{className:"w-3.5 h-3.5"}),"添加发货内容"]})]}),e.jsx("div",{className:"space-y-3",children:Je.map((s,o)=>e.jsxs("div",{className:`grid grid-cols-1 gap-3 items-end rounded-2xl border border-gray-200 p-4 ${je?"md:grid-cols-[1fr_1fr_1.4fr_110px_40px]":"md:grid-cols-[1.4fr_110px_40px]"}`,children:[je&&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:y=>We(o,{spec_name:y.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:y=>We(o,{spec_value:y.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:y=>We(o,{card_id:Number(y.target.value)}),className:"w-full ios-input px-3 py-2.5 rounded-lg",children:[e.jsx("option",{value:"",children:"请选择卡密库存"}),oe.filter(y=>y.enabled&&y.type!=="api").map(y=>e.jsx("option",{value:y.id,children:y.name},y.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:y=>We(o,{delivery_count:Math.max(1,Number(y.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:y=>We(o,{delay_override:y.target.checked}),className:"accent-brand"}),"覆盖卡密默认延时"]}),s.delay_override&&e.jsx("input",{type:"number",min:"0",max:"3600",value:s.delay_seconds||0,onChange:y=>We(o,{delay_seconds:Math.max(0,Number(y.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:Je.length===1,onClick:()=>D({...d,variants:Je.filter((y,A)=>A!==o)}),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(Qe,{className:"w-4 h-4"})})]},s.id||o))})]}):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(va,{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(le.after_shipped_hours||72),onChange:s=>D({...d,config_json:ct(d.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(le.repeat_interval_hours||24),onChange:s=>D({...d,config_json:ct(d.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(le.max_attempts||1),onChange:s=>D({...d,config_json:ct(d.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:((Te=(H=d.actions)==null?void 0:H.find(s=>s.action_type==="send_text"))==null?void 0:Te.message_template)||"",onChange:s=>{var o;return D({...d,actions:((o=d.actions)!=null&&o.length?d.actions:Et("review_missing_timeout")).map(y=>y.action_type==="send_text"?{...y,message_template:s.target.value}:y)})},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:d.priority||100,onChange:s=>D({...d,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:d.enabled!==!1,onChange:s=>D({...d,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:()=>ke(!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:St,className:"flex-1 ios-btn-primary px-6 py-3 rounded-2xl font-bold flex items-center justify-center gap-2",children:[e.jsx(He,{className:"w-4 h-4"}),"保存自动化规则"]})]})]})}),document.body),x&&S&&qe.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:()=>V(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Me,{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=>Y({...S,item_id:s.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级回复"}),q.filter(s=>!B||s.cookie_id===B).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 o=s.target.value;Y({...S,type:o,reply_content:o==="text"?S.reply_content:"",image_url:o==="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=>Y({...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=>Y({...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=>Y({...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:()=>V(!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:pt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Zt,{className:"w-4 h-4"}),"保存规则"]})]})]})]})}),document.body),X&&qe.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:()=>c(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",title:"关闭",children:e.jsx(Me,{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:O.cookie_id,onChange:s=>de({...O,cookie_id:s.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),G.map(s=>e.jsx("option",{value:s.id,children:Qt(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:()=>de({...O,enabled:!O.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${O.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 ${O.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:O.reply_content,onChange:s=>de({...O,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:O.reply_image_url,onChange:s=>de({...O,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:O.reply_once,onChange:s=>de({...O,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:()=>c(!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:ht,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)]})},An=t=>{const a=String(t.smtp_from||"").trim(),l=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a);return{...t,smtp_from_name:t.smtp_from_name||(l?"":a),smtp_from_address:t.smtp_from_address||(l?a:t.smtp_user||""),smtp_use_tls:oa(t.smtp_use_tls,!0),smtp_use_ssl:oa(t.smtp_use_ssl,!1)}},oa=(t,a)=>{if(typeof t=="boolean")return t;if(typeof t=="string"){if(["true","1","yes","on"].includes(t.toLowerCase()))return!0;if(["false","0","no","off"].includes(t.toLowerCase()))return!1}return a},ks=["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from_name","smtp_from_address","smtp_use_tls","smtp_use_ssl"],fs=(t,a)=>{if(typeof t=="boolean")return t;if(typeof t=="string"){if(["true","1","yes","on"].includes(t.toLowerCase()))return!0;if(["false","0","no","off"].includes(t.toLowerCase()))return!1}return a},Ta=t=>{const a=Object.prototype.hasOwnProperty.call(t,"use_custom_smtp"),l=ks.some(i=>String(t[i]??"").trim()!=="");return{...t,use_custom_smtp:a?fs(t.use_custom_smtp,!1):l}},ca=(t,a)=>{const l={...t,use_custom_smtp:!0};for(const i of ks)String(l[i]??"").trim()===""&&a[i]!==void 0&&(l[i]=a[i]);return l.smtp_port||(l.smtp_port=587),l.smtp_from_address||(l.smtp_from_address=l.smtp_user||""),l.smtp_use_tls=fs(l.smtp_use_tls,!0),l.smtp_use_ssl=fs(l.smtp_use_ssl,!1),l},$n=t=>{const a=Ta(t),l={to_email:String(a.to_email??"").trim(),use_custom_smtp:a.use_custom_smtp===!0};if(l.use_custom_smtp)for(const i of ks)l[i]=a[i];return l},ft={bark:{label:"Bark",icon:jt,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:Tt,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:Tt,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:Tt,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:xl,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:Zt,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:wa,fields:[{key:"to_email",label:"收件邮箱",placeholder:"receiver@example.com",required:!0}],guide:{steps:["通常先保存页面中的系统 SMTP 配置","邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP","只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置"],note:"继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。"}}},Ma=[{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:"后台任务或系统级异常"}],Pn=t=>!t||t.length===0?"全部事件":t.map(l=>{var i;return((i=Ma.find(m=>m.value===l))==null?void 0:i.label)||l}).join("、"),Rn=({isAdmin:t=!1})=>{const[a,l]=r.useState([]),[i,m]=r.useState(!0),[_,N]=r.useState(!1),[R,g]=r.useState(null),[C,j]=r.useState(!1),[F,G]=r.useState(""),[me,oe]=r.useState(null),[v,q]=r.useState({}),[ce,Q]=r.useState(!1),[ee,B]=r.useState(!1),[ge,ue]=r.useState(!1),[k,Z]=r.useState({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),se=async()=>{m(!0);try{const p=await Ea();l(p.data||[])}catch(p){console.error("加载通知渠道失败",p)}finally{m(!1)}},K=async()=>{try{const p=await $a();q(An(p||{}))}catch(p){console.error("加载 SMTP 配置失败",p)}},ve=async()=>{Q(!0);try{await Pa({smtp_server:v.smtp_server||"",smtp_port:v.smtp_port||587,smtp_user:v.smtp_user||"",smtp_password:v.smtp_password||"",smtp_from_name:v.smtp_from_name||"",smtp_from_address:v.smtp_from_address||v.smtp_user||"",smtp_use_tls:v.smtp_use_tls!==!1,smtp_use_ssl:v.smtp_use_ssl===!0}),J("success","SMTP 配置已保存")}catch(p){J("error",(p==null?void 0:p.message)||"保存失败")}finally{Q(!1)}};r.useEffect(()=>{se(),t?K():q({})},[t]);const J=(p,b)=>{oe({type:p,text:b}),window.setTimeout(()=>oe(null),3e3)},I=()=>{g(null),Z({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),ue(!1),N(!0)},E=p=>{g(p);const b=p.type==="email"?Ta({...p.config||{}}):null,U=b?b.use_custom_smtp===!0?ca(b,v):b:{...p.config||{}};Z({name:p.name,type:p.type,enabled:p.enabled,config:U,event_types:p.event_types||[]}),ue(!1),N(!0)},$=async()=>{const p=ft[k.type];for(const U of p.fields)if(U.required&&!String(k.config[U.key]||"").trim()){J("error",`请填写 ${U.label}`);return}if(!k.name.trim()){J("error","请填写渠道名称");return}let b=k.config;if(k.type==="email"&&(b=$n(k.config),b.use_custom_smtp)){const M=[["smtp_server","独立 SMTP 服务器"],["smtp_port","独立 SMTP 端口"],["smtp_user","独立 SMTP 登录邮箱"],["smtp_password","独立 SMTP 密码 / 授权码"],["smtp_from_address","独立 SMTP 发件地址"]].find(([ne])=>!String(b[ne]||"").trim());if(M){J("error",`请填写 ${M[1]}`);return}}j(!0);try{const U={name:k.name.trim(),type:k.type,config:b,event_types:k.event_types,enabled:k.enabled};R?await Ys(R.id,U):await Br(U),N(!1),await se(),J("success",R?"已更新":"已创建")}catch(U){console.error("保存失败",U),J("error",(U==null?void 0:U.message)||"保存失败")}finally{j(!1)}},be=async p=>{if(confirm(`确认删除渠道「${p.name}」吗?已绑定该渠道的账号会自动解绑。`))try{await zr(p.id),await se(),J("success","已删除")}catch(b){J("error",(b==null?void 0:b.message)||"删除失败")}},Re=async p=>{try{await Ys(p.id,{enabled:!p.enabled}),l(b=>b.map(U=>U.id===p.id?{...U,enabled:!U.enabled}:U))}catch(b){J("error",(b==null?void 0:b.message)||"切换失败")}},ae=async p=>{G(p.id);try{await Wr(p.id),J("success","测试通知已发送,请检查对应渠道")}catch(b){J("error",(b==null?void 0:b.message)||"发送失败")}finally{G("")}},T=ft[k.type];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:se,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(ze,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:I,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(et,{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(jt,{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:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),i?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(Pe,{className:"w-8 h-8 text-brand animate-spin"})}):a.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(jt,{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:a.map(p=>{const b=ft[p.type]||ft.webhook,U=b.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(U,{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:p.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium",children:b.label}),!p.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:b.fields.map(M=>{var ne;return(ne=p.config)==null?void 0:ne[M.key]}).filter(Boolean).map((M,ne)=>e.jsx("span",{className:"mr-3",children:String(M).length>40?String(M).slice(0,40)+"…":String(M)},ne))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",Pn(p.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>Re(p),className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${p.enabled?"bg-green-50 text-green-700 hover:bg-green-100":"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:p.enabled?"启用中":"已停用"}),e.jsxs("button",{onClick:()=>ae(p),disabled:F===p.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:[F===p.id?e.jsx(Pe,{className:"w-3 h-3 animate-spin"}):e.jsx(Zt,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{onClick:()=>E(p),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(Na,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>be(p),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(Qe,{className:"w-4 h-4"})})]})]},p.id)})}),t&&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(wa,{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",{type:"text",value:v.smtp_server||"",onChange:p=>q({...v,smtp_server:p.target.value}),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:v.smtp_port||587,onChange:p=>q({...v,smtp_port:parseInt(p.target.value)||587}),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",{type:"email",value:v.smtp_user||"",onChange:p=>q({...v,smtp_user:p.target.value}),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:ee?"text":"password",value:v.smtp_password||"",onChange:p=>q({...v,smtp_password:p.target.value}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>B(!ee),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:ee?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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",{type:"text",value:v.smtp_from_name||"",onChange:p=>q({...v,smtp_from_name:p.target.value}),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",{type:"email",value:v.smtp_from_address||v.smtp_user||"",onChange:p=>q({...v,smtp_from_address:p.target.value}),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:v.smtp_use_tls!==!1,onChange:p=>q({...v,smtp_use_tls:p.target.checked,smtp_use_ssl:p.target.checked?!1:v.smtp_use_ssl})}),"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:v.smtp_use_ssl===!0,onChange:p=>q({...v,smtp_use_ssl:p.target.checked,smtp_use_tls:p.target.checked?!1:v.smtp_use_tls})}),"SSL/TLS 直连(常用于 465 端口)"]})]}),e.jsxs("button",{onClick:ve,disabled:ce,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[ce?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(He,{className:"w-4 h-4"}),ce?"保存中...":"保存 SMTP 配置"]})]}),_&&qe.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:R?"编辑通知渠道":"新建通知渠道"}),e.jsx("button",{onClick:()=>N(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(Me,{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:k.name,onChange:p=>Z({...k,name:p.target.value}),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(ft).map(p=>{const b=ft[p],U=b.icon,M=k.type===p;return e.jsxs("button",{type:"button",onClick:()=>Z({...k,type:p,config:{}}),className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${M?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(U,{className:`w-5 h-5 ${M?"text-brand":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${M?"text-brand":"text-gray-600"}`,children:b.label})]},p)})})]}),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(jt,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",T.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:T.guide.steps.map((p,b)=>e.jsx("li",{children:p},b))}),T.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:T.guide.urlFormat})]}),T.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",T.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:T.fields.map(p=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:[p.label,p.required&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),e.jsx("input",{type:p.type==="password"?"password":p.type==="number"?"number":"text",value:String(k.config[p.key]||""),onChange:b=>Z({...k,config:{...k.config,[p.key]:b.target.value}}),placeholder:p.placeholder,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),p.help&&e.jsx("p",{className:"text-xs text-gray-500",children:p.help})]},p.key))}),k.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:k.config.use_custom_smtp===!0?"当前渠道使用一套完整、独立的发件配置。":"当前渠道完整继承系统 SMTP,只单独设置收件邮箱。"})]}),e.jsx("button",{type:"button",onClick:()=>{const p=k.config.use_custom_smtp===!0;Z({...k,config:p?{...k.config,use_custom_smtp:!1}:ca(k.config,v)})},className:`relative h-7 w-12 shrink-0 rounded-full transition-colors ${k.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 ${k.config.use_custom_smtp===!0?"translate-x-5":""}`})})]}),k.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",{type:"text",value:String(k.config.smtp_server||""),onChange:p=>Z({...k,config:{...k.config,smtp_server:p.target.value}}),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",{type:"number",value:String(k.config.smtp_port||587),onChange:p=>Z({...k,config:{...k.config,smtp_port:p.target.value}}),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",{type:"email",value:String(k.config.smtp_user||""),onChange:p=>Z({...k,config:{...k.config,smtp_user:p.target.value}}),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",{type:ge?"text":"password",value:String(k.config.smtp_password||""),onChange:p=>Z({...k,config:{...k.config,smtp_password:p.target.value}}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>ue(p=>!p),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",children:ge?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(lt,{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",{type:"text",value:String(k.config.smtp_from_name||""),onChange:p=>Z({...k,config:{...k.config,smtp_from_name:p.target.value}}),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",{type:"email",value:String(k.config.smtp_from_address||""),onChange:p=>Z({...k,config:{...k.config,smtp_from_address:p.target.value}}),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:k.config.smtp_use_tls!==!1,onChange:p=>Z({...k,config:{...k.config,smtp_use_tls:p.target.checked,smtp_use_ssl:p.target.checked?!1:k.config.smtp_use_ssl}})}),"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:k.config.smtp_use_ssl===!0,onChange:p=>Z({...k,config:{...k.config,smtp_use_ssl:p.target.checked,smtp_use_tls:p.target.checked?!1:k.config.smtp_use_tls}})}),"SSL/TLS 直连(常用于 465)"]})]})]})]}),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:Ma.map(p=>{const b=k.event_types.includes(p.value);return e.jsxs("button",{type:"button",onClick:()=>{const U=b?k.event_types.filter(M=>M!==p.value):[...k.event_types,p.value];Z({...k,event_types:U})},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(Ke,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${b?"text-brand":"text-gray-800"}`,children:p.label})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 pl-6 leading-5",children:p.description})]},p.value)})})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("button",{type:"button",onClick:()=>Z({...k,enabled:!k.enabled}),className:`relative w-11 h-6 rounded-full transition-colors ${k.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 ${k.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:()=>N(!1),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:$,disabled:C,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[C?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(Ke,{className:"w-4 h-4"}),C?"保存中...":"保存"]})]})]})}),document.body),me&&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 ${me.type==="success"?"bg-success-500":"bg-danger-500"}`,children:[me.type==="success"?e.jsx(Ke,{className:"w-4 h-4"}):e.jsx(Me,{className:"w-4 h-4"}),me.text]})]})},qa=[["尊嘟假嘟","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"]],En=t=>t,Dn=new Map(qa.map(([t,a])=>[t,a])),da=t=>t.split(/(\[[^\]]+\])/g).map((a,l)=>{const i=a.startsWith("[")?Dn.get(a.slice(1,-1)):void 0;return i?e.jsx("img",{src:i,alt:a,title:a,className:"mx-0.5 inline-block h-7 w-7 align-middle"},l):e.jsx(ys.Fragment,{children:a},l)}),xa="ydisks.chat.account.v1",Tn=t=>{if(!t)return"";const a=new Date(t<1e10?t*1e3:t),l=new Date;return a.toDateString()===l.toDateString()?a.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit",hour12:!1}):a.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"})},ma=t=>new Date(t<1e10?t*1e3:t).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}),Mn=()=>{const[t,a]=r.useState([]),[l,i]=r.useState(""),[m,_]=r.useState({}),[N,R]=r.useState(""),[g,C]=r.useState([]),[j,F]=r.useState(""),[G,me]=r.useState(!1),[oe,v]=r.useState(""),[q,ce]=r.useState(!0),[Q,ee]=r.useState(!1),[B,ge]=r.useState(!1),[ue,k]=r.useState(!1),[Z,se]=r.useState(),[K,ve]=r.useState({}),[J,I]=r.useState({}),[E,$]=r.useState(!1),[be,Re]=r.useState(!1),[ae,T]=r.useState(!1),[p,b]=r.useState(""),[U,M]=r.useState("connecting"),ne=r.useRef(""),he=r.useRef(""),ye=r.useRef(null),Ee=r.useRef({accountID:"",chatID:""}),ke=r.useRef(!0),x=r.useRef(!1),V=r.useRef(null),X=r.useRef(new Set);r.useEffect(()=>{ne.current=l},[l]),r.useEffect(()=>{he.current=N},[N]);const c=async h=>{const f=await as(h,void 0,void 0,!0);return _(P=>({...P,[h]:f.sessions})),ve(P=>({...P,[h]:f.next_cursor})),I(P=>({...P,[h]:f.has_more})),f.sessions};r.useEffect(()=>{let h=!1;return(async()=>{var P;ce(!0);try{const[z,Ie]=await Promise.all([Ft(),hs()]),we=z.map(u=>{var L,le;return{...u,runtime_state:((L=Ie[u.id])==null?void 0:L.state)||(u.enabled?"connecting":"disabled"),runtime_connected:((le=Ie[u.id])==null?void 0:le.connected)===!0}}).filter(u=>u.enabled),De=await Promise.all(we.map(async u=>[u.id,await as(u.id)]));if(h)return;a(we),_(Object.fromEntries(De.map(([u,L])=>[u,L.sessions]))),ve(Object.fromEntries(De.map(([u,L])=>[u,L.next_cursor]))),I(Object.fromEntries(De.map(([u,L])=>[u,L.has_more])));const te=window.localStorage.getItem(xa)||"",je=we.some(u=>u.id===te)?te:((P=we[0])==null?void 0:P.id)||"";i(je)}catch(z){h||b(z instanceof Error?z.message:"加载聊天数据失败")}finally{h||ce(!1)}})(),()=>{h=!0}},[]),r.useEffect(()=>{let h=!1,f=0,P=null;const z=async()=>{P=new AbortController;try{const Ie=await hs({signal:P.signal,timeoutMs:1e4});h||a(Ae=>Ae.map(we=>{var De,te;return{...we,runtime_state:((De=Ie[we.id])==null?void 0:De.state)||we.runtime_state,runtime_connected:((te=Ie[we.id])==null?void 0:te.connected)??we.runtime_connected}}))}catch{}finally{h||(f=window.setTimeout(z,3e3))}};return f=window.setTimeout(z,3e3),()=>{h=!0,window.clearTimeout(f),P==null||P.abort()}},[]),r.useEffect(()=>{if(!l)return;window.localStorage.setItem(xa,l);const h=m[l]||[];R(f=>{var P;return h.some(z=>z.chat_id===f)?f:((P=h[0])==null?void 0:P.chat_id)||""})},[l,m]),r.useEffect(()=>{!l||X.current.has(l)||(X.current.add(l),c(l).catch(h=>{b(h instanceof Error?h.message:"同步会话失败")}))},[l]),r.useEffect(()=>{if(!l||!N){C([]);return}const h=new AbortController;return ee(!0),Promise.all([us(l,N,void 0,void 0,{signal:h.signal}),Qs(l,N)]).then(([f])=>{C(f.messages),k(f.has_more),se(f.next_cursor),f.session&&_(P=>({...P,[l]:(P[l]||[]).map(z=>{var Ie;return z.chat_id===((Ie=f.session)==null?void 0:Ie.chat_id)?f.session:z})})),_(P=>({...P,[l]:(P[l]||[]).map(z=>z.chat_id===N?{...z,unread_count:0}:z)}))}).catch(f=>{h.signal.aborted||b(f instanceof Error?f.message:"加载消息失败")}).finally(()=>{h.signal.aborted||ee(!1)}),()=>h.abort()},[l,N]);const d=async()=>{var P;if(!l||!N||B||!ue)return;const h=ye.current,f=(h==null?void 0:h.scrollHeight)||0;x.current=!0,ge(!0),b("");try{const z=(P=g[0])==null?void 0:P.id,Ie=await us(l,N,Z,z);C(Ae=>{const we=new Set(Ae.map(De=>De.message_key));return[...Ie.messages.filter(De=>!we.has(De.message_key)),...Ae]}),k(Ie.has_more),se(Ie.next_cursor),requestAnimationFrame(()=>{h&&(h.scrollTop+=h.scrollHeight-f)})}catch(z){x.current=!1,b(z instanceof Error?z.message:"加载历史消息失败")}finally{ge(!1)}};r.useEffect(()=>{let h=!1,f=0,P=0,z=null;const Ie=()=>{if(h)return;M("connecting");const Ae=window.location.protocol==="https:"?"wss:":"ws:";z=new WebSocket(`${Ae}//${window.location.host}/api/v1/chat/ws`),z.onopen=()=>{P=0,M("online")},z.onmessage=we=>{try{const te=JSON.parse(we.data).message;if(!te)return;const je=te.account_id;_(u=>{const L=u[je]||[];return L.some(Ne=>Ne.chat_id===te.chat_id)?{...u,[je]:L.map(Ne=>Ne.chat_id===te.chat_id?{...Ne,last_message:te.content,last_message_at:te.sent_at,unread_count:te.direction==="incoming"&&(ne.current!==je||he.current!==te.chat_id)?Ne.unread_count+1:Ne.unread_count}:Ne).sort((Ne,Ue)=>Ue.last_message_at-Ne.last_message_at)}:(c(je),u)}),ne.current===je&&he.current===te.chat_id&&(C(u=>{const L=u.findIndex(le=>le.message_key===te.message_key);return L>=0?u.map((le,Ne)=>Ne===L?te:le):[...u,te]}),te.direction==="incoming"&&Qs(je,te.chat_id))}catch{}},z.onclose=()=>{if(h)return;M("offline");const we=Math.min(15e3,1e3*2**Math.min(P++,4));f=window.setTimeout(Ie,we)},z.onerror=()=>z==null?void 0:z.close()};return Ie(),()=>{h=!0,window.clearTimeout(f),z==null||z.close()}},[]);const D=()=>{const h=ye.current;if(!h)return;const f=h.scrollHeight-h.scrollTop-h.clientHeight;ke.current=f<=48};r.useLayoutEffect(()=>{const h=Ee.current.accountID!==l||Ee.current.chatID!==N;Ee.current={accountID:l,chatID:N},h&&(ke.current=!0);const f=ye.current;if(f){if(x.current){x.current=!1;return}(Q||ke.current)&&(f.scrollTop=f.scrollHeight)}},[l,N,g,Q]);const S=t.find(h=>h.id===l),Y=m[l]||[],O=Y.find(h=>h.chat_id===N),de=r.useMemo(()=>{const h=j.trim().toLowerCase();return Y.filter(f=>G&&f.unread_count<=0?!1:h?[f.buyer_name,f.buyer_id,f.item_title,f.last_message].some(P=>(P||"").toLowerCase().includes(h)):!0)},[Y,j,G]),Se=h=>(m[h]||[]).reduce((f,P)=>f+P.unread_count,0),fe=async()=>{if(!(!l||E||!J[l])){$(!0),b("");try{const h=await as(l,K[l],void 0,!0);_(f=>({...f,[l]:h.sessions})),ve(f=>({...f,[l]:h.next_cursor})),I(f=>({...f,[l]:h.has_more}))}catch(h){b(h instanceof Error?h.message:"加载历史联系人失败")}finally{$(!1)}}},Oe=async()=>{const h=oe.trim();if(!(!h||!O||!l||ae)){T(!0),b("");try{const f=await ql({account_id:l,chat_id:O.chat_id,buyer_id:O.buyer_id,buyer_name:O.buyer_name,item_id:O.item_id,item_title:O.item_title,text:h});v(""),C(P=>P.some(z=>z.message_key===f.message.message_key)?P.map(z=>z.message_key===f.message.message_key?f.message:z):[...P,f.message])}catch(f){b(f instanceof Error?f.message:"消息发送失败"),Ml(l,O.chat_id).then(C)}finally{T(!1)}}},re=async h=>{if(!(!h||!O||!l||ae)){T(!0),b("");try{const f=await Fl({account_id:l,chat_id:O.chat_id,buyer_id:O.buyer_id,buyer_name:O.buyer_name,buyer_avatar_url:O.buyer_avatar_url,item_id:O.item_id,item_title:O.item_title,image:h});C(P=>P.some(z=>z.message_key===f.message.message_key)?P.map(z=>z.message_key===f.message.message_key?f.message:z):[...P,f.message])}catch(f){b(f instanceof Error?f.message:"图片发送失败")}finally{T(!1),V.current&&(V.current.value="")}}};return q?e.jsx("div",{className:"flex h-[calc(100vh-4rem)] items-center justify-center",children:e.jsx(Pe,{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 ${U==="online"?"bg-emerald-50 text-emerald-700":U==="connecting"?"bg-amber-50 text-amber-700":"bg-red-50 text-red-700"}`,children:[U==="online"?e.jsx(ml,{className:"h-3.5 w-3.5"}):e.jsx(pl,{className:"h-3.5 w-3.5"}),U==="online"?"实时同步中":U==="connecting"?"正在连接":"连接已断开"]})]}),e.jsx("div",{className:"flex gap-1 overflow-x-auto pb-0",role:"tablist","aria-label":"聊天账号",children:t.map(h=>{const f=h.id===l,P=Se(h.id),z=h.runtime_state==="online";return e.jsxs("button",{type:"button",role:"tab","aria-selected":f,onClick:()=>i(h.id),className:`relative flex h-11 shrink-0 items-center gap-2 border-b-2 px-3 text-sm font-extrabold transition-colors ${f?"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 ${z?"bg-emerald-500":"bg-slate-300"}`}),e.jsx("span",{className:"max-w-36 truncate",children:h.nickname||h.remark||h.id}),P>0&&e.jsx("span",{className:"min-w-5 rounded-full bg-red-500 px-1.5 py-0.5 text-[10px] text-white",children:P>99?"99+":P})]},h.id)})})]}),t.length===0?e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(is,{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(_t,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx("input",{value:j,onChange:h=>F(h.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:()=>me(h=>!h),className:`rounded-lg px-2.5 py-1.5 text-xs font-bold ${G?"bg-sky-100 text-sky-700":"text-slate-500 hover:bg-slate-100"}`,children:G?"只看未读":"全部会话"}),e.jsx("button",{type:"button",title:"刷新会话",onClick:()=>void c(l),className:"rounded-lg p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700",children:e.jsx(ze,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[de.map(h=>e.jsxs("button",{type:"button",onClick:()=>R(h.chat_id),className:`flex w-full gap-3 border-b border-slate-100 p-4 text-left transition-colors ${h.chat_id===N?"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:h.buyer_avatar_url?e.jsx("img",{src:h.buyer_avatar_url,alt:"",className:"h-full w-full object-cover"}):e.jsx(Gt,{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:h.buyer_name||`用户 ${h.buyer_id}`}),e.jsx("span",{className:"ml-auto shrink-0 text-[10px] font-medium text-slate-400",children:Tn(h.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:h.last_message||"暂无消息"}),h.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:h.unread_count})]}),h.item_title&&e.jsxs("div",{className:"mt-1.5 truncate text-[10px] font-medium text-sky-700",children:["商品 · ",h.item_title]})]})]},h.chat_id)),de.length===0&&e.jsx("div",{className:"px-6 py-16 text-center text-sm text-slate-400",children:"当前账号暂无匹配会话"}),J[l]&&!j&&!G&&e.jsx("div",{className:"flex justify-center p-4",children:e.jsxs("button",{type:"button",onClick:()=>void fe(),disabled:E,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:[E&&e.jsx(Pe,{className:"h-3.5 w-3.5 animate-spin"}),E?"正在加载":"加载更多历史联系人"]})})]})]}),e.jsx("main",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-surface-subtle",children:O?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:O.buyer_name||O.buyer_id}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-slate-500",children:["用户 ID:",O.buyer_id]})]}),e.jsx("span",{className:`ml-auto rounded-full px-2.5 py-1 text-[10px] font-bold ${(S==null?void 0:S.runtime_state)==="online"?"bg-emerald-50 text-emerald-700":"bg-slate-100 text-slate-500"}`,children:(S==null?void 0:S.runtime_state)==="online"?"账号在线":"账号离线"})]}),e.jsx("div",{ref:ye,onScroll:D,className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:Q?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Pe,{className:"h-6 w-6 animate-spin text-sky-500"})}):e.jsxs(e.Fragment,{children:[ue&&e.jsx("div",{className:"flex justify-center pb-1",children:e.jsxs("button",{type:"button",onClick:()=>void d(),disabled:B,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:[B&&e.jsx(Pe,{className:"h-3.5 w-3.5 animate-spin"}),B?"正在加载":"加载更早消息"]})}),g.map(h=>{const f=h.direction==="outgoing";return h.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:[da(h.content),e.jsx("div",{className:"mt-1 text-[10px] text-slate-400",children:ma(h.sent_at)})]})},h.message_key):e.jsxs("div",{className:`flex items-end gap-2.5 ${f?"justify-end":"justify-start"}`,children:[!f&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-slate-200 ring-2 ring-white",children:O.buyer_avatar_url?e.jsx("img",{src:O.buyer_avatar_url,alt:O.buyer_name||"用户",className:"h-full w-full object-cover"}):e.jsx(Gt,{className:"m-2 h-5 w-5 text-slate-500"})}),e.jsxs("div",{className:`max-w-[72%] ${f?"items-end":"items-start"} flex flex-col`,children:[e.jsx("div",{className:"mb-1 px-1 text-[10px] font-semibold text-slate-400",children:f?(S==null?void 0:S.nickname)||(S==null?void 0:S.remark)||"我":O.buyer_name||h.sender_name||O.buyer_id}),h.message_type==="image"?e.jsx("a",{href:h.content,target:"_blank",rel:"noreferrer",className:`block overflow-hidden rounded-2xl border bg-white p-1 shadow-sm ${f?"rounded-br-md border-sky-200":"rounded-bl-md border-slate-200"}`,children:e.jsx("img",{src:h.content,alt:"聊天图片",className:"max-h-80 max-w-full rounded-xl object-contain"})}):h.message_type==="video"?e.jsx("video",{src:h.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 ${f?"rounded-br-md bg-sky-500 text-white":"rounded-bl-md border border-slate-200 bg-white text-slate-800"}`,children:da(h.content)}),e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] text-slate-400",children:[ma(h.sent_at),f&&(h.status==="failed"?e.jsx(rt,{className:"h-3 w-3 text-red-500"}):h.status==="sent"?e.jsx(ul,{className:"h-3 w-3 text-sky-500"}):e.jsx(Ke,{className:"h-3 w-3"}))]})]}),f&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-sky-100 ring-2 ring-white",children:S!=null&&S.avatar_url?e.jsx("img",{src:S.avatar_url,alt:"我",className:"h-full w-full object-cover"}):e.jsx(Gt,{className:"m-2 h-5 w-5 text-sky-600"})})]},h.message_key)})]})}),p&&e.jsx("div",{className:"border-t border-red-100 bg-red-50 px-5 py-2 text-xs font-medium text-red-700",children:p}),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:()=>Re(h=>!h),disabled:ae||(S==null?void 0:S.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(hl,{className:"h-5 w-5"})}),be&&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:qa.map(([h,f])=>e.jsx("button",{type:"button",title:`[${h}]`,onClick:()=>{v(P=>P+`[${h}]`),Re(!1)},className:"flex h-10 w-10 items-center justify-center rounded-lg hover:bg-slate-100",children:e.jsx("img",{src:En(f),alt:`[${h}]`,className:"h-8 w-8 object-contain"})},h))})]})]}),e.jsx("input",{ref:V,type:"file",accept:"image/*",className:"hidden",onChange:h=>{var f;return void re((f=h.target.files)==null?void 0:f[0])}}),e.jsx("button",{type:"button",onClick:()=>{var h;return(h=V.current)==null?void 0:h.click()},disabled:ae||(S==null?void 0:S.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(gl,{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:oe,onChange:h=>v(h.target.value),rows:2,maxLength:2e3,onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),Oe())},disabled:(S==null?void 0:S.runtime_state)!=="online",placeholder:(S==null?void 0:S.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 Oe(),disabled:!oe.trim()||ae||(S==null?void 0:S.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:ae?e.jsx(Pe,{className:"h-4 w-4 animate-spin"}):e.jsx(Zt,{className:"h-4 w-4"})})]})]})]}):e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(is,{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:"该账号的新消息会实时出现在左侧列表。"})]})})]})]})},Fa="ydisks.sidebar.v1",qn=()=>{try{return window.localStorage.getItem(Fa)==="collapsed"}catch{return!1}},Fn=t=>{try{window.localStorage.setItem(Fa,t?"collapsed":"expanded")}catch{}},Ba={"/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"},pa=Object.fromEntries(Object.entries(Ba).map(([t,a])=>[a,t])),ua=()=>Ba[window.location.pathname]||"dashboard",Bn=()=>{const[t,a]=r.useState(!1),[l,i]=r.useState(!1),[m,_]=r.useState(ua),[N,R]=r.useState(!0),[g,C]=r.useState(!1),[j,F]=r.useState(""),[G,me]=r.useState(""),[oe,v]=r.useState(!1),[q,ce]=r.useState(""),[Q,ee]=r.useState(""),[B,ge]=r.useState(""),[ue,k]=r.useState(!1),[Z,se]=r.useState(""),[K,ve]=r.useState(),[J,I]=r.useState(qn),E=T=>{const p=T==="settings"&&!l?"dashboard":T,b=pa[p];b&&b!==window.location.pathname&&window.history.pushState({},"",b),_(p)};r.useEffect(()=>{const T=()=>_(ua());return window.addEventListener("popstate",T),()=>window.removeEventListener("popstate",T)},[]),r.useEffect(()=>{La().then(p=>{if((p==null?void 0:p.initialized)===!1){C(!0),a(!1),i(!1);return}C(!1),p!=null&&p.authenticated?(a(!0),i(p.is_admin===!0)):i(!1)}).catch(()=>{a(!1),i(!1)}).finally(()=>R(!1));const T=()=>{a(!1),i(!1)};return window.addEventListener("auth:logout",T),()=>window.removeEventListener("auth:logout",T)},[]),r.useEffect(()=>{!N&&t&&!l&&m==="settings"&&(window.history.replaceState({},"",pa.dashboard),_("dashboard"))},[N,t,l,m]);const $=async T=>{T.preventDefault(),v(!0),ce("");try{const p=await Al({username:j,password:G});p.success?(a(!0),i(p.is_admin===!0)):ce(p.message||"登录失败")}catch(p){const b=p instanceof Error?p.message:String(p);ce(b||"登录失败")}finally{v(!1)}},be=async T=>{if(T.preventDefault(),se(""),Q.length<8){se("密码至少需要 8 个字符");return}if(Q!==B){se("两次输入的密码不一致");return}k(!0);try{const p=await $l(Q);if(!p.success){se(p.message||"初始化失败,请重试");return}C(!1),a(!0),i(p.is_admin===!0),ee(""),ge("")}catch(p){const b=p instanceof Error?p.message:String(p);se(b||"初始化失败,请重试")}finally{k(!1)}},Re=async()=>{try{await Pl()}catch(T){console.error("退出登录失败",T)}finally{a(!1),i(!1)}};if(N)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-surface",children:e.jsx(Pe,{className:"w-8 h-8 text-brand animate-spin"})});if(g)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-canvas p-4 relative overflow-hidden font-sans",children:[e.jsx("div",{className:"absolute top-[-10%] left-[-10%] w-[60%] h-[60%] bg-blue-200/40 rounded-full blur-[120px] animate-pulse"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[60%] h-[60%] bg-blue-200/30 rounded-full blur-[120px] animate-pulse",style:{animationDelay:"2s"}}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-3xl p-8 md:p-12 rounded-xl shadow-panel w-full max-w-xl border border-white relative z-10 animate-fade-in",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"mx-auto mb-6 flex justify-center",children:e.jsx(ms,{sizeClass:"w-24 h-24"})}),e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900 mb-2 tracking-tight",children:"首次设置管理员密码"}),e.jsx("p",{className:"text-gray-600 font-medium",children:"设置完成后会自动进入系统,管理员账号为 admin。"})]}),e.jsxs("form",{onSubmit:be,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(Fs,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"password",placeholder:"设置管理员密码(至少 8 个字符)",value:Q,onChange:T=>ee(T.target.value),autoFocus:!0,className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Mt,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"password",placeholder:"再次输入密码",value:B,onChange:T=>ge(T.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]})]}),Z&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-50 text-red-500 text-sm text-center font-bold flex items-center justify-center gap-2",children:[e.jsx(Mt,{className:"w-4 h-4"})," ",Z]}),e.jsx("button",{type:"submit",disabled:ue,className:"w-full ios-btn-primary h-14 rounded-2xl text-lg shadow-xl shadow-blue-200 mt-2 flex items-center justify-center gap-2 group disabled:opacity-70",children:ue?e.jsx(Pe,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:["设置密码并进入系统 ",e.jsx(xs,{className:"w-5 h-5 group-hover:translate-x-1 transition-transform"})]})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-gray-100 text-center",children:e.jsx("span",{className:"text-xs text-gray-400 font-medium tracking-widest uppercase",children:"Secure Bootstrap"})})]})]});if(!t)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-canvas p-4 relative overflow-hidden font-sans",children:[e.jsx("div",{className:"absolute top-[-10%] left-[-10%] w-[60%] h-[60%] bg-blue-200/40 rounded-full blur-[120px] animate-pulse"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[60%] h-[60%] bg-blue-200/30 rounded-full blur-[120px] animate-pulse",style:{animationDelay:"2s"}}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-3xl p-8 md:p-12 rounded-xl shadow-panel w-full max-w-lg border border-white relative z-10 animate-fade-in",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("div",{className:"group mx-auto mb-6 flex cursor-pointer justify-center",children:e.jsx(ms,{sizeClass:"w-24 h-24",logoClassName:"w-full h-full text-white group-hover:scale-110 transition-transform"})}),e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900 mb-2 tracking-tight",children:"欢迎回来"}),e.jsx("p",{className:"text-gray-500 font-medium",children:"Ydisks闲鱼助手 · 自动发货与管家系统"})]}),e.jsxs("form",{onSubmit:$,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(xt,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"text",placeholder:"管理员账号",value:j,onChange:T=>F(T.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Fs,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"password",placeholder:"密码",value:G,onChange:T=>me(T.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]})]}),q&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-50 text-red-500 text-sm text-center font-bold flex items-center justify-center gap-2",children:[e.jsx(Mt,{className:"w-4 h-4"})," ",q]}),e.jsx("button",{type:"submit",disabled:oe,className:"w-full ios-btn-primary h-14 rounded-2xl text-lg shadow-xl shadow-blue-200 mt-2 flex items-center justify-center gap-2 group disabled:opacity-70",children:oe?e.jsx(Pe,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:["立即登录 ",e.jsx(xs,{className:"w-5 h-5 group-hover:translate-x-1 transition-transform"})]})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-gray-100",children:e.jsx("div",{className:"mt-6 text-center",children:e.jsx("span",{className:"text-xs text-gray-400 font-medium tracking-widest uppercase",children:"Ydisks闲鱼助手 v1.0"})})})]})]});const ae=()=>{switch(m){case"dashboard":return e.jsx(rs,{});case"accounts":return e.jsx(rn,{});case"chat":return e.jsx(Mn,{});case"orders":return e.jsx(cn,{});case"cards":return e.jsx(xn,{});case"items":return e.jsx(yn,{onConfigureDelivery:T=>{ve({cookieId:T.cookie_id,itemId:T.item_id,requestId:Date.now()}),E("rules")}});case"rules":return e.jsx(In,{initialDeliveryTarget:K,onDeliveryTargetHandled:()=>ve(void 0)});case"notifications":return e.jsx(Rn,{isAdmin:l});case"settings":return l?e.jsx(_n,{}):e.jsx(rs,{});default:return e.jsx(rs,{})}};return e.jsxs("div",{className:"flex min-h-screen bg-canvas text-ink",children:[e.jsx(wl,{activeTab:m,isAdmin:l,collapsed:J,onToggleCollapsed:()=>I(T=>{const p=!T;return Fn(p),p}),onNavigate:E,onLogout:Re}),e.jsxs("main",{className:`h-screen min-w-0 flex-1 overflow-x-hidden overflow-y-auto scroll-smooth transition-[margin] duration-300 ${J?"ml-16":"ml-64"} ${m==="chat"?"p-4 md:p-6":"p-8 md:p-12"}`,children:[e.jsx("div",{className:"fixed top-0 right-0 w-[800px] h-[800px] bg-gradient-to-bl from-blue-50 to-transparent rounded-full blur-[120px] pointer-events-none -z-10 opacity-60"}),e.jsx("div",{className:`${m==="chat"?"mx-auto max-w-[1680px]":"mx-auto max-w-[1400px] pb-10"}`,children:ae()})]})]})},za=document.getElementById("root");if(!za)throw new Error("Could not find root element to mount to");const zn=Wa.createRoot(za);zn.render(e.jsx(ys.StrictMode,{children:e.jsx(Bn,{})})); diff --git a/internal/webui/static/index.html b/internal/webui/static/index.html index 1a6a65e..eedf4a6 100644 --- a/internal/webui/static/index.html +++ b/internal/webui/static/index.html @@ -6,7 +6,7 @@ Ydisks闲鱼助手 - 自动发货与管家系统 - +