From 614bae4b2bb53cdf706d9cb4679c8989d2b124dd Mon Sep 17 00:00:00 2001 From: Christ Date: Sat, 25 Jul 2026 14:17:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=A1=A3:=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=91=BD=E5=90=8D=E3=80=81=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E4=B8=8E=E4=BD=BF=E7=94=A8=E6=8C=87=E5=8D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 4 +- AGENTS.md | 4 +- Dockerfile.browser-test | 2 +- LICENSE | 201 ++++++++++++++++++ Makefile | 2 +- NOTICE | 5 + README.md | 39 ++-- compose.yml | 2 +- docker-compose.debian13-postgres17.yml | 4 +- docker-compose.functional.yml | 22 +- docs/login-renewal-risk-control-plan.md | 2 +- docs/wiki/AI、通知与运维.md | 46 ++++ docs/wiki/Home.md | 34 +++ docs/wiki/_Sidebar.md | 8 + docs/wiki/批量铺货.md | 51 +++++ docs/wiki/自动化发货与回复.md | 47 ++++ docs/wiki/账号、库存与商品.md | 42 ++++ docs/wiki/部署与数据库.md | 82 +++++++ frontend/README.md | 6 +- frontend/components/Notifications.tsx | 2 +- frontend/package-lock.json | 4 +- frontend/package.json | 2 +- internal/server/notification_handlers.go | 2 +- .../{index-DWScSBc3.js => index-ZWBpSY5a.js} | 2 +- internal/webui/static/index.html | 2 +- 25 files changed, 572 insertions(+), 45 deletions(-) create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 docs/wiki/AI、通知与运维.md create mode 100644 docs/wiki/Home.md create mode 100644 docs/wiki/_Sidebar.md create mode 100644 docs/wiki/批量铺货.md create mode 100644 docs/wiki/自动化发货与回复.md create mode 100644 docs/wiki/账号、库存与商品.md create mode 100644 docs/wiki/部署与数据库.md rename internal/webui/static/assets/{index-DWScSBc3.js => index-ZWBpSY5a.js} (87%) diff --git a/.env.example b/.env.example index 420dd86..10d6705 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ # 复制为 .env 后再填写。不要提交包含真实密钥的 .env。 -COMPOSE_PROJECT_NAME=xianyu +COMPOSE_PROJECT_NAME=ydisks-xianyu-helper # PostgreSQL 17 POSTGRES_IMAGE=postgres:17-trixie @@ -10,7 +10,7 @@ POSTGRES_PASSWORD=请替换为高强度数据库密码 DATABASE_URL=postgres://xianyu:请替换为URL编码后的数据库密码@postgres:5432/xianyu?sslmode=disable # 应用:默认 compose.yml 仅拉取 GHCR 镜像,不会在服务器上构建源码。 -XIANYU_IMAGE=ghcr.io/christ9038/xinayu-go:latest +XIANYU_IMAGE=ghcr.io/christ9038/ydisks-xianyu-helper:latest XIANYU_DATA_KEY=请替换为稳定且足够长的随机密钥 XIANYU_BIND_ADDRESS=0.0.0.0 XIANYU_HTTP_PORT=8080 diff --git a/AGENTS.md b/AGENTS.md index 74c0215..5bda580 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -21,7 +21,7 @@ The active application contains: ## Common commands ```bash -cd /Users/christ/Workspace/git/xianyu/xianyu-go +cd /Users/christ/Workspace/git/xianyu/Ydisks-Xianyu-Helper make build # go build ./cmd/server make test # go test ./... @@ -74,7 +74,7 @@ go test ./internal/db -run TestMultiDB -v Build the frontend: ```bash -cd /Users/christ/Workspace/git/xianyu/xianyu-go/frontend +cd /Users/christ/Workspace/git/xianyu/Ydisks-Xianyu-Helper/frontend npm install npm run build ``` diff --git a/Dockerfile.browser-test b/Dockerfile.browser-test index b679863..e632c63 100644 --- a/Dockerfile.browser-test +++ b/Dockerfile.browser-test @@ -2,7 +2,7 @@ FROM golang:1.26-trixie AS go-toolchain # 复用生产运行镜像中已经安装并验证过的 Chromium、Node 和 Playwright driver, # 只补 Go 工具链来执行真实浏览器集成测试。 -FROM xianyu-go:functional +FROM ydisks-xianyu-helper:functional ENV PATH=/usr/local/go/bin:${PATH} ENV CGO_ENABLED=0 WORKDIR /src diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Makefile b/Makefile index f7a43d8..c396cc2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# xianyu-go 常用命令入口。详见各 target 注释。 +# Ydisks-Xianyu-Helper 常用命令入口。详见各 target 注释。 GO ?= go GOLANGCI_LINT ?= golangci-lint diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..e1aa7d5 --- /dev/null +++ b/NOTICE @@ -0,0 +1,5 @@ +Ydisks闲鱼助手 / Ydisks-Xianyu-Helper +Copyright 2026 Christ9038 + +This product includes software developed by Christ9038 and is licensed under +the Apache License, Version 2.0. diff --git a/README.md b/README.md index a2c5283..1285dda 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,17 @@ -# Xianyu Go +# Ydisks闲鱼助手 基于 Go 与 React 构建的闲鱼多账号管理、消息回复与自动发货系统 [![Go](https://img.shields.io/badge/Go-1.26-00ADD8?logo=go&logoColor=white)](go.mod) [![React](https://img.shields.io/badge/React-19-61DAFB?logo=react&logoColor=black)](frontend/package.json) [![PostgreSQL](https://img.shields.io/badge/PostgreSQL-17-4169E1?logo=postgresql&logoColor=white)](compose.yml) -[![Docker Image](https://github.com/Christ9038/xinayu-go/actions/workflows/docker-publish.yml/badge.svg?branch=dev)](https://github.com/Christ9038/xinayu-go/actions/workflows/docker-publish.yml) +[![Docker Image](https://github.com/Christ9038/Ydisks-Xianyu-Helper/actions/workflows/docker-publish.yml/badge.svg?branch=dev)](https://github.com/Christ9038/Ydisks-Xianyu-Helper/actions/workflows/docker-publish.yml) [功能特性](#功能特性) · [快速开始](#快速开始) · [配置说明](#配置说明) · -[Docker 部署](#docker-部署) · [开发指南](#开发指南) +[Docker 部署](#docker-部署) · [开发指南](#开发指南) · [开源协议](#开源协议) + +操作手册见仓库内的 [GitHub Wiki 文档](docs/wiki/Home.md):包含数据库选择、账号接入、 +批量铺货、自动化发货、AI、通知和运维流程。 > [!IMPORTANT] > 本项目是社区维护的非官方工具,与闲鱼、阿里巴巴集团及其关联公司无隶属、合作或 @@ -17,7 +20,7 @@ ## 项目简介 -Xianyu Go 是一个面向闲鱼卖家的自托管管理系统。它将账号运行、即时消息、订单、 +Ydisks闲鱼助手(英文项目名:Ydisks-Xianyu-Helper)是一个面向闲鱼卖家的自托管管理系统。它将账号运行、即时消息、订单、 商品、卡密库存、自动化规则、AI 回复和异常通知整合到同一个 Web 管理后台,适合需要 同时维护多个闲鱼账号或交付数字商品的个人与小型团队。 @@ -25,6 +28,14 @@ Xianyu Go 是一个面向闲鱼卖家的自托管管理系统。它将账号运 不是业务请求代理,仅用于读取真实浏览器指纹以及处理必须依赖浏览器环境的滑块风控。 扫码登录、人脸验证流程、消息连接、凭证更新和绝大部分业务逻辑均由 Go 客户端完成。 +## 开源协议 + +本项目采用 [Apache License 2.0](LICENSE) 开源,版权所有 © 2026 Christ9038。 + +你可以使用、复制、修改和分发本项目代码;分发原始或衍生代码时,必须附带许可证文本, +保留 [NOTICE](NOTICE) 中 Ydisks闲鱼助手(Ydisks-Xianyu-Helper)的版权与署名声明,并在 +修改过的文件中明确标注已修改。 + ### 适用场景 - 多个闲鱼账号的统一在线状态与消息管理 @@ -84,8 +95,8 @@ flowchart LR Docker Desktop,并使用 Docker Compose v2。 ```bash -git clone https://github.com/Christ9038/xinayu-go.git -cd xinayu-go +git clone https://github.com/Christ9038/Ydisks-Xianyu-Helper.git +cd Ydisks-Xianyu-Helper cp .env.example .env ``` @@ -133,8 +144,8 @@ docker compose up -d 构建前端: ```bash -git clone https://github.com/Christ9038/xinayu-go.git -cd xinayu-go +git clone https://github.com/Christ9038/Ydisks-Xianyu-Helper.git +cd Ydisks-Xianyu-Helper npm --prefix frontend ci npm --prefix frontend run build ``` @@ -207,12 +218,12 @@ Docker Compose 还支持: | 变量 | 默认值 | 说明 | | --- | --- | --- | -| `COMPOSE_PROJECT_NAME` | `xianyu` | Compose 项目名及命名卷前缀 | +| `COMPOSE_PROJECT_NAME` | `ydisks-xianyu-helper` | Compose 项目名及命名卷前缀 | | `POSTGRES_IMAGE` | `postgres:17-trixie` | PostgreSQL 镜像 | | `POSTGRES_DB` | 必填 | 数据库名 | | `POSTGRES_USER` | 必填 | 数据库用户 | | `POSTGRES_PASSWORD` | 必填 | 数据库密码 | -| `XIANYU_IMAGE` | `ghcr.io/christ9038/xinayu-go:latest` | 应用镜像与标签 | +| `XIANYU_IMAGE` | `ghcr.io/christ9038/ydisks-xianyu-helper:latest` | 应用镜像与标签 | | `XIANYU_BIND_ADDRESS` | `0.0.0.0` | 应用在宿主机上的绑定地址 | | `XIANYU_HTTP_PORT` | `8080` | 应用在宿主机上的端口 | @@ -282,7 +293,7 @@ LocalAI 或兼容网关。只有在明确了解数据流向时才应向外部 AI GitHub Actions 会将同一标签发布为多架构镜像: ```text -ghcr.io/christ9038/xinayu-go:dev +ghcr.io/christ9038/ydisks-xianyu-helper:dev ├── linux/amd64 └── linux/arm64 ``` @@ -315,7 +326,7 @@ docker compose up -d | 服务 | 用途 | | --- | --- | | `postgres` | PostgreSQL 17 数据库,仅在 Compose 内部网络开放 5432 | -| `app` | Xianyu Go 主服务、前端和 Chromium | +| `app` | Ydisks闲鱼助手主服务、前端和 Chromium | `app` 会在首次启动时自动创建 `admin`;如果管理员已存在,后续 `up`、重启或升级均不会 修改其密码。 @@ -334,8 +345,8 @@ docker compose up -d ### 完整部署步骤 ```bash -git clone https://github.com/Christ9038/xinayu-go.git -cd xinayu-go +git clone https://github.com/Christ9038/Ydisks-Xianyu-Helper.git +cd Ydisks-Xianyu-Helper cp .env.example .env ``` diff --git a/compose.yml b/compose.yml index dbfa963..c333e0f 100644 --- a/compose.yml +++ b/compose.yml @@ -38,7 +38,7 @@ services: start_period: 10s app: - image: ${XIANYU_IMAGE:-ghcr.io/christ9038/xinayu-go:latest} + image: ${XIANYU_IMAGE:-ghcr.io/christ9038/ydisks-xianyu-helper:latest} pull_policy: always restart: unless-stopped depends_on: diff --git a/docker-compose.debian13-postgres17.yml b/docker-compose.debian13-postgres17.yml index e64e292..a59ec90 100644 --- a/docker-compose.debian13-postgres17.yml +++ b/docker-compose.debian13-postgres17.yml @@ -36,7 +36,7 @@ services: start_period: 10s app: - image: ${XIANYU_IMAGE:-xianyu-go:debian13} + image: ${XIANYU_IMAGE:-ydisks-xianyu-helper:debian13} build: context: . dockerfile: Dockerfile.debian13 @@ -57,7 +57,7 @@ services: start_period: 30s init-admin: - image: ${XIANYU_IMAGE:-xianyu-go:debian13} + image: ${XIANYU_IMAGE:-ydisks-xianyu-helper:debian13} build: context: . dockerfile: Dockerfile.debian13 diff --git a/docker-compose.functional.yml b/docker-compose.functional.yml index de0ff8f..734438a 100644 --- a/docker-compose.functional.yml +++ b/docker-compose.functional.yml @@ -1,4 +1,4 @@ -name: xianyu-functional +name: ydisks-xianyu-helper-functional x-mysql-url: &mysql-url mysql://root:xianyu_root_password@tcp(mysql:3306)/xianyu?parseTime=true&loc=UTC x-postgres-url: &postgres-url postgres://xianyu:xianyu_postgres_password@postgres:5432/xianyu?sslmode=disable&timezone=UTC @@ -65,7 +65,7 @@ services: sqlite3 /seed/xianyu_data.db "PRAGMA quick_check" | grep -qx ok seed-mysql: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional build: context: . dockerfile: Dockerfile.debian13 @@ -82,7 +82,7 @@ services: command: ["/app/xianyu-dbseed", "-source", "/seed/xianyu_data.db", "-target", *mysql-url, "-limit", "20"] seed-sqlite: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional build: context: . dockerfile: Dockerfile.debian13 @@ -98,7 +98,7 @@ services: command: ["/app/xianyu-dbseed", "-source", "/seed/xianyu_data.db", "-target", "/app/data/xianyu-functional.db", "-limit", "20"] seed-postgres: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional restart: "no" depends_on: postgres: @@ -112,7 +112,7 @@ services: command: ["/app/xianyu-dbseed", "-source", "/seed/xianyu_data.db", "-target", *postgres-url, "-limit", "20"] app-mysql: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional restart: unless-stopped depends_on: seed-mysql: @@ -134,7 +134,7 @@ services: retries: 30 app-sqlite: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional restart: unless-stopped depends_on: seed-sqlite: @@ -156,7 +156,7 @@ services: retries: 30 app-postgres: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional restart: unless-stopped depends_on: seed-postgres: @@ -223,7 +223,7 @@ services: command: ["sh", "-c", "npm run typecheck && npm test && npm run build"] dbverify-mysql: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional depends_on: mysql: condition: service_healthy @@ -232,7 +232,7 @@ services: command: ["/app/xianyu-dbverify", *mysql-url] dbverify-sqlite: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional environment: XIANYU_DATA_KEY: *data-key volumes: @@ -240,7 +240,7 @@ services: command: ["/app/xianyu-dbverify", "/app/data/verify.db"] dbverify-postgres: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional depends_on: postgres: condition: service_healthy @@ -249,7 +249,7 @@ services: command: ["/app/xianyu-dbverify", *postgres-url] functional-test: - image: xianyu-go:functional + image: ydisks-xianyu-helper:functional restart: "no" depends_on: app-sqlite: diff --git a/docs/login-renewal-risk-control-plan.md b/docs/login-renewal-risk-control-plan.md index 6d20e50..f9c17ad 100644 --- a/docs/login-renewal-risk-control-plan.md +++ b/docs/login-renewal-risk-control-plan.md @@ -2,7 +2,7 @@ ## 目标 -参考 `zhinianboke/xianyu-auto-reply` 的实现,把当前项目缺少的登录态续期、MTOP 风控识别、扫码人脸验证能力补齐。改造重点是提升账号长期在线能力和风控状态的可恢复性,同时保持 `xianyu-go` 现有单进程架构清晰、可测试、可回滚。 +参考 `zhinianboke/xianyu-auto-reply` 的实现,把当前项目缺少的登录态续期、MTOP 风控识别、扫码人脸验证能力补齐。改造重点是提升账号长期在线能力和风控状态的可恢复性,同时保持 `Ydisks-Xianyu-Helper` 现有单进程架构清晰、可测试、可回滚。 ## 非目标 diff --git a/docs/wiki/AI、通知与运维.md b/docs/wiki/AI、通知与运维.md new file mode 100644 index 0000000..e5ed3e5 --- /dev/null +++ b/docs/wiki/AI、通知与运维.md @@ -0,0 +1,46 @@ +# AI、通知与运维 + +## 配置 AI 服务 + +系统级连接在“系统与 AI”设置,仅管理员可修改: + +1. 填写 OpenAI 兼容的 API 地址,填到版本根路径即可,例如 `https://api.openai.com/v1` 或通义兼容地址 `https://dashscope.aliyuncs.com/compatible-mode/v1`;不要填 `/chat/completions`。 +2. 填入 API Key,点击“读取模型”。若服务不支持模型列表,也可手动填模型名。 +3. 保存系统设置。API Key 会作为敏感字段保存;仍应限制数据库和管理员访问。 +4. 前往“账号管理”,在目标账号行打开“AI 设置”。 +5. 打开“启用 AI 自动回复”,配置最大折扣比例、最大降价金额、最大砍价轮次和自定义提示词,保存。 +6. 使用真实但无风险的砍价对话测试输出;确认金额边界和措辞均符合预期后再开启正式账号。 + +AI 用于处理买家的砍价消息。`0` 的最大折扣比例或金额表示不允许对应降价;砍价轮次应设置保守值。提示词应明确产品边界、禁止承诺事项、语气和转人工条件,不应放入 Cookie、密码、完整订单隐私或其他机密。 + +## 配置通知 + +1. 打开“通知设置”,先按需要配置系统 SMTP(仅邮件渠道需要)。 +2. 新建通知渠道,选择 Bark、钉钉、飞书、企业微信、Telegram、邮件或自定义 Webhook,并填写该渠道所需地址/令牌。 +3. 选择接收事件;不选择表示接收全部。可选事件包括掉线、恢复、禁用、安全验证、续期和交易结果。 +4. 保存后点击“测试通知”,在目标渠道确认收到。 +5. 回到“账号管理 → 编辑”,把通知渠道绑定到具体账号。仅创建渠道不会自动让账号使用它。 + +Webhook 和机器人令牌通常等同于密码。不要贴进截图、Issue 或聊天记录;更换令牌后立即更新渠道并重测。 + +## 日常巡检 + +每天或每次大促前检查: + +- Dashboard 的在线账号、订单、库存和异常趋势; +- 自动化异常/延迟任务是否有待处理项; +- 批量卡密库存是否低于安全线; +- 最近一次通知是否可达; +- 登录续期和安全验证是否需要人工操作。 + +## 故障排查顺序 + +1. **账号不在线**:检查账号是否被暂停、Cookie 是否失效、是否需要扫码或安全验证;完成后确认恢复通知。 +2. **未自动发货**:核对订单所属账号、商品/规格匹配、规则启用、卡密库存和自动化异常。先确认是否已经实际发送过内容。 +3. **AI 无回复**:确认系统 API 地址、Key 和模型可用;再确认该账号 AI 已启用,且消息属于砍价场景。 +4. **通知未达**:先点击测试通知,再核对事件筛选与账号绑定;邮件还需检查 SMTP 配置。 +5. **数据库无法连接**:检查 `DATABASE_URL`、网络/TLS、数据库账号权限和服务日志。不要通过删除数据库来“修复”。 + +## 备份与恢复 + +备份至少包含数据库、`.env`(特别是 `XIANYU_DATA_KEY`)和必要的上传资源。恢复到新机器时先恢复数据库与同一把密钥,再启动服务;若密钥不一致,已加密的 Cookie、AI 和通知配置不可读取。恢复后先禁用高风险自动化,用测试订单逐项确认。 diff --git a/docs/wiki/Home.md b/docs/wiki/Home.md new file mode 100644 index 0000000..709091c --- /dev/null +++ b/docs/wiki/Home.md @@ -0,0 +1,34 @@ +# Ydisks闲鱼助手 Wiki + +本 Wiki 面向管理后台操作人员。先完成“部署与数据库”和“账号接入”,再配置库存、商品、自动化与 AI。 + +## 推荐上线路径 + +1. 选择并启动数据库;生产环境推荐 PostgreSQL。 +2. 设置并备份 `XIANYU_DATA_KEY`,初始化管理员后登录后台。 +3. 在“账号管理”扫码接入账号,确认账号为启用且在线状态。 +4. 在“卡密库存”建立可交付内容。 +5. 同步已有商品,或通过“商品管理”发布商品。 +6. 在“自动化规则”建立付款发货、评价赠品或求评价规则。 +7. 可选:在“系统与 AI”配置模型,再为每个账号启用 AI。 +8. 建立通知渠道并绑定到账号;用测试通知验证。 +9. 用小额测试订单验证“卡密发送 → 确认发货”全过程后,再开放正式商品。 + +## 先读这些页面 + +- [部署与数据库](部署与数据库) +- [账号、库存与商品](账号、库存与商品) +- [批量铺货](批量铺货) +- [自动化发货与回复](自动化发货与回复) +- [AI、通知与运维](AI、通知与运维) + +## 关键安全规则 + +- 不要提交 `.env`、数据库备份、Cookie、API Key 或通知 Webhook 地址。 +- `XIANYU_DATA_KEY` 用于加密 Cookie、密码、AI/SMTP 和通知凭据;换密钥会导致旧数据无法解密。务必和数据库一同离线备份。 +- 自动化必须先用测试商品、测试卡密和小额订单验证。库存耗尽、账号掉线或风控时,不应假设发货已完成。 +- 本项目为非官方工具。请确保使用方式符合平台规则、当地法律及账号授权范围。 + +## GitHub Wiki 同步 + +这些 Markdown 文件位于仓库 `docs/wiki/`,可直接复制到 GitHub Wiki 对应页面;文件名即页面名。`_Sidebar.md` 是 Wiki 导航。仓库内保留副本便于在 Pull Request 中审阅和版本化维护。 diff --git a/docs/wiki/_Sidebar.md b/docs/wiki/_Sidebar.md new file mode 100644 index 0000000..4b99182 --- /dev/null +++ b/docs/wiki/_Sidebar.md @@ -0,0 +1,8 @@ +### Ydisks闲鱼助手 + +- [首页](Home) +- [部署与数据库](部署与数据库) +- [账号、库存与商品](账号、库存与商品) +- [批量铺货](批量铺货) +- [自动化发货与回复](自动化发货与回复) +- [AI、通知与运维](AI、通知与运维) diff --git a/docs/wiki/批量铺货.md b/docs/wiki/批量铺货.md new file mode 100644 index 0000000..e0c01ec --- /dev/null +++ b/docs/wiki/批量铺货.md @@ -0,0 +1,51 @@ +# 批量铺货 + +批量铺货会先预检,再启动后台发布任务。它最多一次处理 50 行商品;建议先用 1 行测试资料包验证后再跑正式批次。 + +## 1. 准备资料包 + +必需文件为 CSV、XLSX 或 TSV 表格;如引用本地图片,再提供 ZIP 图片包。下载“商品管理 → 批量铺货”中的模板可避免表头错误。 + +推荐中文表头: + +```text +账号ID,标题,描述,价格,原价,库存,邮费模式,邮费,图片,付款发货启用,付款发货内容,评价赠品启用,评价赠品内容,求评价启用,求评价等待小时,求评价文案,求评价最多次数 +``` + +也支持英文表头,但不能与中文混用。每行一个商品;`账号ID` 可留空并在上传页选择默认账号。 + +### 必填与格式 + +- 标题非空,价格大于 0;库存为正整数,留空默认 1。 +- 邮费模式为 `free`/`包邮` 或 `fixed`/`固定邮费`;固定邮费时必须填邮费。 +- 每件商品 1–9 张图片,多个用英文分号 `;` 分隔。可用公开 `https://` URL,或 ZIP 内相对路径。 +- 本地图片 ZIP 最大 200 MiB,单图最大 10 MiB;表格最大 20 MiB。 +- CSV 使用 UTF-8,建议带 BOM;不要在表头增加空格。 + +### 自动化列 + +“付款发货内容”和“评价赠品内容”格式相同: + +```text +卡密组ID:每件份数:延迟秒;卡密组ID:每件份数:延迟秒 +``` + +例如 `101:1;102:2:30`:先从组 101 发 1 份,再等待 30 秒从组 102 发 2 份。份数省略时为 1,延迟省略时为 0。卡密组 ID 从“卡密库存”复制。启用值可写“是”、`true`、`1` 或 `on`;不启用写“否”、`false`、`0` 或留空。 + +完整字段规范和示例见仓库 [批量铺货资料包准备规格](../批量铺货使用文档.md)。 + +## 2. 后台操作 + +1. 在“商品管理”点击“批量铺货”。 +2. 选择表格;表格引用本地图片时同时选择 ZIP。 +3. 未填账号 ID 时,在页面选择默认账号。 +4. 点击预检,逐行处理错误。常见错误是账号未授权、卡密组不存在、图片路径不匹配、固定邮费缺失或价格为 0。 +5. 所有需发布行确认无误后启动任务;不要关闭正在运行的任务页面。 +6. 在任务详情查看成功、失败与进行中行。需要时取消任务;正在提交的单件商品可能继续完成。 +7. 对可重试失败项使用“重试失败”,并下载结果 CSV 留档。 + +## 3. 常见问题 + +- **图片找不到**:ZIP 内路径必须与表格完全一致,使用 `/`,不能以 `/` 开头或包含 `..`。 +- **自动化不生效**:检查卡密组 ID、账号归属、启用列和库存;发布成功后仍应查看自动化规则是否已创建。 +- **任务中断**:先重新打开批次详情确认状态,避免重复新建整批任务;仅重试失败行。 diff --git a/docs/wiki/自动化发货与回复.md b/docs/wiki/自动化发货与回复.md new file mode 100644 index 0000000..d7444e4 --- /dev/null +++ b/docs/wiki/自动化发货与回复.md @@ -0,0 +1,47 @@ +# 自动化发货与回复 + +## 自动化的三种触发器 + +| 触发器 | 触发时机 | 标准流程 | +| --- | --- | --- | +| 付款后自动发货 | 收到付款系统卡片 | 匹配商品/规格 → 发送卡密 → 成功后确认发货。 | +| 评价后发送赠品 | 收到评价系统卡片 | 匹配商品/规格 → 发送赠品卡密。 | +| 超时未评价求评价 | 定时扫描已发货未评价订单 | 到达等待时间 → 发送提醒文案。 | + +系统通知卡片只进入自动化判断;买家普通消息走关键词、默认回复和 AI 规则。 + +## 配置付款自动发货 + +前提:账号在线、商品已同步、卡密组已建立且有库存。 + +1. 进入“自动化规则”,选择“付款后自动发货”,点击新增。 +2. 设置规则名称,选择目标账号和商品;商品有规格时为每个需要交付的规格建立对应配置。 +3. 添加“发送卡密”动作,选择卡密库存、每件发送数量与是否启用。 +4. 如需覆盖卡密组默认延迟,打开延迟覆盖并填写秒数;否则使用卡密组的默认延时。 +5. 保存并确认规则处于启用状态。 +6. 用测试订单确认:卡密内容已发送、卡密库存扣减正确、随后才确认发货。 + +按购买数量发货:动作中的“每件发送数量”会乘以订单购买数量。不要把每单总量误填为每件数量。 + +## 配置评价赠品与求评价 + +评价赠品的配置与付款发货相同,但触发器选择“评价后发送赠品”。赠品应使用独立卡密组,便于核对和补货。 + +配置求评价: + +1. 新建“超时未评价求评价”规则,选择账号和商品。 +2. 填写等待时间(发货后多少小时开始检查)、重复间隔及最多提醒次数。 +3. 填写发送给买家的求评价文案,保存并启用。 +4. 在测试订单上确认不会提前发送;达到最大次数后不再重复提醒。 + +## 异常处理与补发 + +“自动化规则”页面的异常区会列出可处理的自动化运行和延迟任务。先查看订单、库存、聊天记录和失败原因,再使用页面的“处理/解决”操作。不要在不确定已发货状态时直接重试,以免重复发卡。 + +需要人工补发时,在订单管理中定位订单,确认买家、商品和历史交付记录,再使用手动发货/补发能力。处理后记录原因并检查库存。 + +## 关键词与默认回复 + +在“自动化规则”的“关键词回复”页:选择账号 → 新增规则 → 填写关键词与文本或图片 URL → 保存。关键词规则用于买家普通消息。 + +“账号默认回复”只在关键词和 AI 都未处理该消息时使用。可设置文本、图片 URL 和“同一会话只回复一次”。上线前避免关键词、默认回复和 AI 提示词对同类问题给出互相矛盾的答案。 diff --git a/docs/wiki/账号、库存与商品.md b/docs/wiki/账号、库存与商品.md new file mode 100644 index 0000000..df07a8a --- /dev/null +++ b/docs/wiki/账号、库存与商品.md @@ -0,0 +1,42 @@ +# 账号、库存与商品 + +## 1. 接入账号 + +1. 进入“账号管理”,选择添加账号/扫码登录。 +2. 用目标闲鱼账号在官方客户端完成扫码;若出现人脸或安全验证,按页面提示在官方流程中完成。 +3. 等待后台保存登录信息,确认昵称、账号 ID 和运行状态正常。 +4. 为账号填写备注,按需开启或暂停账号,并进入编辑页绑定通知渠道。 +5. 首次接入后同步一次商品;开始自动化前确认账号处于启用状态。 + +不要手工向他人发送 Cookie。登录态、指纹和密码等敏感值由系统加密存储,依赖固定的 `XIANYU_DATA_KEY`。 + +## 2. 创建卡密库存 + +付款自动发货和评价赠品都先依赖卡密库存。进入“卡密库存”后点击“添加新卡密”: + +| 类型 | 适用内容 | 填写方式 | +| --- | --- | --- | +| 文本 | 固定说明、链接 | 填写文本内容。 | +| 批量卡密(`data`) | 一次性兑换码、序列号 | 每行一个卡密;发货会按库存消费。 | +| 图片 | 固定图片资源 | 填写公开可访问的图片 URL。 | +| API | 外部发码接口 | 填写 URL、GET/POST、超时、请求头和参数;先用无敏感测试数据验证。 | + +通用字段包括名称、描述、启用状态和默认延时秒数。保存后复制“卡密组 ID”;它是自动化规则和批量铺货表格引用库存的唯一标识。 + +批量卡密可用“批量导入”创建,也可选择已有 `data` 类型卡密组追加新卡密。上架前检查库存余量;库存不足时应先补货,不要依赖人工补救。 + +## 3. 同步或发布商品 + +进入“商品管理”: + +- 对已在闲鱼上存在的商品,选择同步全部或按页同步,确认商品归属到正确账号。 +- 对单个新商品,使用发布入口填写标题、描述、价格、库存、邮费和图片。图片必须可用;提交前复核目标账号。 +- 商品发布成功不等于已开启自动发货。仍需在“自动化规则”中按商品/规格绑定卡密组,或在批量铺货表格中一并声明自动化配置。 + +## 4. 上线前检查 + +1. 账号在线并已启用。 +2. 商品已同步或发布成功,价格、库存和图片正确。 +3. 所需卡密组启用且余量充足。 +4. 自动化规则准确匹配商品;有规格时逐个规格确认。 +5. 先用测试订单验证,检查订单列表、自动化异常列表和通知记录。 diff --git a/docs/wiki/部署与数据库.md b/docs/wiki/部署与数据库.md new file mode 100644 index 0000000..0ce42c2 --- /dev/null +++ b/docs/wiki/部署与数据库.md @@ -0,0 +1,82 @@ +# 部署与数据库 + +## 选择数据库 + +| 场景 | 建议 | 原因 | +| --- | --- | --- | +| 本机试用、单人低频使用 | SQLite | 无需额外服务,数据库是一个文件。 | +| Docker 生产部署 | PostgreSQL 17 | 默认 Compose 已提供服务、持久化卷和健康检查。 | +| 已有 MySQL 运维体系 | MySQL 8+ | 可复用现有备份、监控和权限管理。 | +| 多人或长期运行 | PostgreSQL / MySQL | 更适合并发、备份和独立运维。 | + +三种数据库均会在应用启动时自动执行内置迁移。连接优先级是:`DATABASE_URL` > `-db-url` > `-db`。升级生产库前先备份。 + +## Docker + PostgreSQL(推荐) + +1. 复制配置:`cp .env.example .env`。 +2. 编辑 `.env`,至少设置 `POSTGRES_DB`、`POSTGRES_USER`、`POSTGRES_PASSWORD`、`XIANYU_DATA_KEY`、`XIANYU_ADMIN_PASSWORD`。 +3. 为 `XIANYU_DATA_KEY` 生成一次长期固定的随机值,例如 `openssl rand -base64 48`;不要在后续升级时更换。 +4. 启动:`docker compose up -d`。 +5. 查看:`docker compose ps` 和 `docker compose logs -f app`。 +6. 打开 `http://服务器地址:8080`,用管理员账号登录。若未自动初始化,可按 README 的 `-init-admin` 命令执行。 + +默认连接已由 `compose.yml` 注入,不需要手写 PostgreSQL URL。若修改 `COMPOSE_PROJECT_NAME`,新卷名前缀也会变化;已有部署升级时保留原 `.env`,避免误用新空卷。 + +## SQLite + +适合开发或轻量单机。默认数据库路径为 `data/xianyu_data.db`: + +```bash +go run ./cmd/server -db data/xianyu_data.db -addr :8080 +``` + +也可显式指定: + +```bash +DATABASE_URL="sqlite://data/xianyu_data.db" ./xianyu-server +``` + +备份时先停服务,或使用 SQLite 在线备份工具;不要只复制正在写入的 WAL 数据库主文件。恢复时同时恢复数据库和原有 `XIANYU_DATA_KEY`。 + +## MySQL + +先创建 UTF-8 数据库和最小权限账号,再为应用提供 URL: + +```bash +DATABASE_URL="mysql://user:URL编码后的密码@tcp(db.example:3306)/xianyu" \ + ./xianyu-server -addr :8080 +``` + +应用会补齐所需 MySQL 连接参数。密码中出现 `@`、`:`、`/` 等字符时必须 URL 编码。使用 TLS 的环境请按数据库驱动/基础设施要求配置安全连接,不要把真实密码写进命令历史。 + +## PostgreSQL(外部服务) + +```bash +DATABASE_URL="postgres://user:URL编码后的密码@db.example:5432/xianyu?sslmode=require" \ + ./xianyu-server -addr :8080 +``` + +仅在受信任的本机网络可考虑 `sslmode=disable`;公网或跨网络部署应使用 TLS。数据库账号只应拥有该应用数据库的必要权限。 + +## 初始化、备份和升级 + +初始化管理员: + +```bash +go run ./cmd/server -init-admin -db data/xianyu_data.db -admin-password '强密码' +``` + +已有管理员时,仅确保其存在而不重置密码: + +```bash +go run ./cmd/server -ensure-admin -admin-password '强密码' +``` + +PostgreSQL 备份示例: + +```bash +docker compose exec -T postgres pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" \ + > ydisks-backup.sql +``` + +升级顺序:备份数据库和 `.env` → 拉取/构建新镜像 → `docker compose up -d` → 查看日志确认迁移成功 → 登录检查账号和自动化任务。若迁移失败,停止继续操作并从备份恢复。 diff --git a/frontend/README.md b/frontend/README.md index a6aace0..f2a19ad 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -1,6 +1,6 @@ -# 闲鱼管家前端 +# Ydisks闲鱼助手前端 -React + Vite + TypeScript 单页应用,作为闲鱼管家 Go 后端的管理面板。 +React + Vite + TypeScript 单页应用,作为 Ydisks闲鱼助手 Go 后端的管理面板。 ## 目录结构 @@ -19,7 +19,7 @@ frontend/ ## 开发 ```bash -cd /Users/christ/Workspace/git/xianyu/xianyu-go/frontend +cd /Users/christ/Workspace/git/xianyu/Ydisks-Xianyu-Helper/frontend npm install npm run dev # http://localhost:3000,API 代理到 localhost:8080 ``` diff --git a/frontend/components/Notifications.tsx b/frontend/components/Notifications.tsx index 1905fb4..608f992 100644 --- a/frontend/components/Notifications.tsx +++ b/frontend/components/Notifications.tsx @@ -31,7 +31,7 @@ const CHANNEL_TYPES: Record = { fields: [ { key: 'server_url', label: 'Bark 服务器', placeholder: 'https://api.day.app', required: true }, { key: 'device_key', label: 'Device Key', placeholder: '你的 Bark 设备 Key', required: true }, - { key: 'title', label: '标题(可选)', placeholder: '闲鱼助手' }, + { key: 'title', label: '标题(可选)', placeholder: 'Ydisks闲鱼助手' }, { key: 'sound', label: '铃声(可选)', placeholder: 'default' }, { key: 'group', label: '分组(可选)', placeholder: 'xianyu' }, ], diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 19edac1..6a496fe 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,11 +1,11 @@ { - "name": "闲鱼自动发货-pro", + "name": "ydisks-xianyu-helper", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "闲鱼自动发货-pro", + "name": "ydisks-xianyu-helper", "version": "0.0.0", "dependencies": { "axios": "^1.13.2", diff --git a/frontend/package.json b/frontend/package.json index 933baaf..c923fba 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,5 +1,5 @@ { - "name": "闲鱼自动发货-pro", + "name": "ydisks-xianyu-helper", "private": true, "version": "0.0.0", "type": "module", diff --git a/internal/server/notification_handlers.go b/internal/server/notification_handlers.go index 8129c95..6529efb 100644 --- a/internal/server/notification_handlers.go +++ b/internal/server/notification_handlers.go @@ -147,7 +147,7 @@ func (s *Server) testChannel(w http.ResponseWriter, r *http.Request) { if !s.requireChannelOwner(w, r, id) { return } - body := "🧪 通知渠道测试\n\n这是一条来自闲鱼助手的测试通知,收到说明渠道配置正常。\n时间: " + + body := "🧪 通知渠道测试\n\n这是一条来自Ydisks闲鱼助手的测试通知,收到说明渠道配置正常。\n时间: " + time.Now().Format("2006-01-02 15:04:05") if err := s.notifier.SendToChannel(id, body); err != nil { writeErr(w, http.StatusInternalServerError, "发送失败: "+err.Error()) diff --git a/internal/webui/static/assets/index-DWScSBc3.js b/internal/webui/static/assets/index-ZWBpSY5a.js similarity index 87% rename from internal/webui/static/assets/index-DWScSBc3.js rename to internal/webui/static/assets/index-ZWBpSY5a.js index e7ed37e..5efc545 100644 --- a/internal/webui/static/assets/index-DWScSBc3.js +++ b/internal/webui/static/assets/index-ZWBpSY5a.js @@ -16,4 +16,4 @@ CODE-789012 `).filter(i=>i.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:i=>G({...j,api_method:i.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:i=>G({...j,api_timeout:parseInt(i.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:i=>G({...j,api_headers:i.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:i=>G({...j,api_params:i.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:i=>G({...j,description:i.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:i=>G({...j,delay_seconds:parseInt(i.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:()=>f(!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:m,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Qe,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),Y&&Se.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:()=>X(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(we,{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:()=>C("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 ${de==="create"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(fa,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>C("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 ${de==="append"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(js,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),de==="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:se,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(ya,{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(js,{className:"w-4 h-4"}),M?M.name:"选择 .xlsx / .csv / .tsv",e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv",className:"hidden",onChange:i=>{var q;return oe(((q=i.target.files)==null?void 0:q[0])||null)}})]})]}),ee&&!ee.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:["共 ",ee.total," 行 · 成功 ",ee.created," · 失败 ",ee.failed]}),ee.failed>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:ee.rows.filter(i=>!i.success).map(i=>e.jsxs("div",{className:"text-xs text-red-600",children:["第 ",i.row_no," 行「",i.name,"」:",i.error]},i.row_no))})]})]}):e.jsx("div",{className:"space-y-4",children:S.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:D,onChange:i=>N(i.target.value),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",children:S.map(i=>e.jsxs("option",{value:String(i.id),children:[i.name,"(ID: ",i.id,")"]},i.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:$,onChange:i=>T(i.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:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),J&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",J.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:()=>X(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),de==="create"?e.jsxs("button",{onClick:z,disabled:!M||O,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[O?e.jsx(Te,{className:"w-4 h-4 animate-spin"}):e.jsx(js,{className:"w-4 h-4"}),O?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:re,disabled:!D||!$.trim()||O||S.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[O?e.jsx(Te,{className:"w-4 h-4 animate-spin"}):e.jsx(Qe,{className:"w-4 h-4"}),O?"处理中...":"追加卡密"]})]})]})}),document.body)]})},gr=s=>s.find(t=>t.status==="running"||t.status==="canceling"),br=s=>{const t=String(s||"").trim();return t?/^[¥¥]/.test(t)?t:`¥${t}`:"-"},fr=({onConfigureDelivery:s})=>{const[t,l]=n.useState([]),[c,h]=n.useState([]),[f,L]=n.useState([]),[F,g]=n.useState(""),[I,j]=n.useState(""),[G,Y]=n.useState(!1),[X,de]=n.useState(!1),[C,M]=n.useState(!1),[oe,ee]=n.useState(!1),[xe,O]=n.useState(!1),[le,D]=n.useState(!1),[N,$]=n.useState(!1),[T,J]=n.useState("upload"),[ue,Q]=n.useState(null),[A,b]=n.useState(null),[v,B]=n.useState(null),[R,K]=n.useState(null),[H,m]=n.useState(null),p=n.useRef(!1),[y,S]=n.useState(null),[U,se]=n.useState({}),[z,re]=n.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[E,i]=n.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[q,d]=n.useState([]);n.useEffect(()=>{if(!le||E.images.length===0){d([]);return}const r=E.images.map((a,u)=>({key:a.name+u,url:URL.createObjectURL(a)}));return d(r),()=>{r.forEach(a=>URL.revokeObjectURL(a.url))}},[le,E.images]);const _=async()=>{const r=await ps();l(r)},te=async()=>{h(await Is())};n.useEffect(()=>{Promise.all([Rs(),ps(),Is(),yt(20)]).then(([r,a,u,w])=>{L(r),l(a),h(u);const W=w.find(ae=>["running","canceling"].includes(ae.status))||w.find(ae=>ae.status!=="preview");m(W||null)}).catch(r=>console.error("加载商品配置失败:",r))},[]),n.useEffect(()=>{if(!N||!(R!=null&&R.id)||!["running","canceling"].includes(R.status))return;const r=window.setInterval(async()=>{if(!p.current){p.current=!0;try{const a=await os(R.id);K(a),m(a),["running","canceling"].includes(a.status)||(J("done"),await _(),await te())}catch(a){console.error("刷新批量铺货进度失败:",a)}finally{p.current=!1}}},3e3);return()=>{window.clearInterval(r)}},[N,R==null?void 0:R.id,R==null?void 0:R.status]);const Z=async()=>{if(!F)return alert("请先选择账号");Y(!0);try{const r=await _l(F);await _(),alert((r==null?void 0:r.message)||"商品同步完成")}catch(r){console.error("同步商品失败:",r),alert((r==null?void 0:r.message)||"同步失败,请重试")}finally{Y(!1)}},pe=r=>{S(r),se({...r}),ee(!0)},Ne=async()=>{if(y)try{await Rl(y.cookie_id,y.item_id,{item_title:U.item_title||"",item_description:U.item_description||"",item_category:U.item_category||"",item_price:U.item_price||"",item_detail:U.item_detail||y.item_detail||""}),await _(),await te(),ee(!1),S(null)}catch(r){console.error("更新商品失败:",r),alert("更新失败,请重试")}},ce=async r=>{if(confirm(`确认删除商品"${r.item_title}"吗?`))try{await wl(r.cookie_id,r.item_id),l(a=>a.filter(u=>!(u.cookie_id===r.cookie_id&&u.item_id===r.item_id)))}catch(a){console.error("删除商品失败:",a),alert("删除失败,请重试")}},_e=async()=>{try{if(!z.cookie_id||!z.item_id){alert("请选择账号并填写商品ID");return}await kl(z.cookie_id,{item_id:z.item_id,item_title:z.item_title,item_price:z.item_price,item_detail:z.item_image?JSON.stringify({item_image:z.item_image}):""}),await _(),O(!1),re({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(r){console.error("添加商品失败:",r),alert("添加失败,请重试")}},Re=async()=>{if(!E.cookie_id)return alert("请选择发布账号");if(!E.title.trim())return alert("请填写商品标题");if(!E.price.trim())return alert("请填写商品价格");if(!E.quantity||Number(E.quantity)<=0)return alert("库存数量必须大于 0");if(E.images.length===0)return alert("至少上传 1 张商品图片");if(E.postage_mode==="fixed"&&!E.postage.trim())return alert("请填写一口价邮费");de(!0);try{const r=await Cl(E);if(await _(),D(!1),i({cookie_id:F||"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),r!=null&&r.item_id){const a={id:r.item_id,cookie_id:E.cookie_id,item_id:r.item_id,item_title:r.item_title||E.title,item_price:r.item_price||E.price,item_image:r.item_image};s(a),alert("商品发布成功,ID: "+r.item_id+",已为你打开发货规则配置")}else alert("商品发布成功")}catch(r){console.error("发布商品失败:",r);const a=r==null?void 0:r.payload;if((a==null?void 0:a.code)==="stock_permission_missing"){alert("发布失败:该账号没有库存发布权限,无法按库存数量发布商品。请换账号或先在闲鱼确认库存能力。");return}alert((r==null?void 0:r.message)||"发布失败,请重试")}finally{de(!1)}},ye=async()=>{J("upload"),B(null),K(null),Q(null),b(null),$(!0),M(!0);try{const r=await yt(20),a=gr(r);if(a!=null&&a.id){const u=await os(a.id);m(u),K(u),J(["running","canceling"].includes(u.status)?"running":"done")}}catch(r){console.error("恢复最近批量铺货任务失败:",r)}finally{M(!1)}},Ae=async()=>{if(H!=null&&H.id){M(!0),$(!0);try{const r=await os(H.id);K(r),J(["running","canceling"].includes(r.status)?"running":"done")}catch(r){console.error("加载最近批量铺货结果失败:",r)}finally{M(!1)}}},Le=async()=>{if(!ue)return alert("请先上传商品表格");if(!F)return alert("请先选择默认发布账号");M(!0);try{const r=await Sl({file:ue,imagesZip:A,defaultCookieId:F});B(r),K(null),J("preview")}catch(r){console.error("批量铺货预检失败:",r),alert((r==null?void 0:r.message)||"预检失败,请检查表格和图片 zip")}finally{M(!1)}},Be=async()=>{if(v!=null&&v.preview_id){if(v.valid<=0)return alert("没有可发布的商品行");M(!0);try{const r=await Ll(v.preview_id),a=await os(r.batch_id||v.preview_id);K(a),m(a),J(a.status==="running"?"running":"done")}catch(r){console.error("启动批量铺货失败:",r),alert((r==null?void 0:r.message)||"启动发布任务失败")}finally{M(!1)}}},Ie=async()=>{if(R!=null&&R.id&&confirm("确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。")){M(!0);try{const r=await Il(R.id),a=await os(R.id);K(a),J((r==null?void 0:r.status)==="canceling"||a.status==="canceling"?"running":"done")}catch(r){alert((r==null?void 0:r.message)||"取消失败")}finally{M(!1)}}},Me=async()=>{const r=v==null?void 0:v.preview_id;if(r&&T==="preview")try{await Al(r)}catch(a){console.error("清理批量铺货预检失败:",a)}B(null),J("upload")},We=async()=>{await Me(),$(!1)},Ye=async()=>{if(R!=null&&R.id){M(!0);try{await $l(R.id),K(await os(R.id)),J("running")}catch(r){alert((r==null?void 0:r.message)||"重试失败")}finally{M(!1)}}},$e=()=>{const u=[["账号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(ve=>ve.map(he=>`"${String(he).replace(/"/g,'""')}"`).join(",")).join(` -`),w=new Blob(["\uFEFF"+u],{type:"text/csv;charset=utf-8"}),W=URL.createObjectURL(w),ae=document.createElement("a");ae.href=W,ae.download="批量铺货模板.csv",document.body.appendChild(ae),ae.click(),ae.remove(),URL.revokeObjectURL(W)},ss=()=>{re(r=>({...r,cookie_id:F||r.cookie_id})),O(!0)},Ze=()=>{i(r=>({...r,cookie_id:F||r.cookie_id})),D(!0)},Xe=r=>c.filter(a=>a.cookie_id===r.cookie_id&&a.item_id===r.item_id).length>0?c.filter(a=>a.cookie_id===r.cookie_id&&a.item_id===r.item_id):c.filter(a=>a.cookie_id===r.cookie_id&&!a.item_id),He=r=>{switch(r){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 r||"-"}},x=r=>{switch(r){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"}},P=n.useMemo(()=>new Map(f.map(r=>[r.id,r])),[f]),me=n.useMemo(()=>I?t.filter(r=>r.cookie_id===I):t,[I,t]),fe=r=>{const a=P.get(r),u=(a==null?void 0:a.remark)||(a==null?void 0:a.nickname);return u?`${u} · ${r.slice(0,6)}`:`账号 ${r.slice(0,8)}`},ze=r=>{const a=P.get(r);return(a==null?void 0:a.remark)||(a==null?void 0:a.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(Na,{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:I,onChange:r=>j(r.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.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(ns,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:F,onChange:r=>g(r.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.id))]})]})]}),e.jsxs("button",{onClick:Z,disabled:G||!F,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(qe,{className:`w-4 h-4 ${G?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:ss,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(Qe,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:Ze,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-600 text-white hover:bg-emerald-700 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Ts,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void ye(),className:"px-5 py-3 rounded-2xl font-bold bg-blue-600 text-white hover:bg-blue-700 transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(_s,{className:"w-4 h-4"}),H&&["running","canceling"].includes(H.status)?"继续批量任务":"批量铺货"]}),H&&!["running","canceling"].includes(H.status)&&e.jsx("button",{onClick:()=>void Ae(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[me.map(r=>{const a=Xe(r),u=a.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:()=>pe(r),className:"p-1.5 bg-white/90 backdrop-blur rounded-lg shadow-md text-gray-600 hover:bg-[#0094f7] hover:text-white transition-colors",title:"编辑",children:e.jsx(us,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>ce(r),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(Je,{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:[r.item_image?e.jsx("img",{src:r.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(Et,{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:br(r.item_price)})]}),e.jsx("h3",{className:"font-bold text-gray-900 line-clamp-2 text-xs mb-1.5 h-8 leading-4",children:r.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:ze(r.cookie_id),children:[e.jsx(ns,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:ze(r.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: ",r.item_id]}),e.jsxs("span",{className:`inline-flex items-center gap-1 font-bold ${u?"text-emerald-600":"text-amber-600"}`,children:[u?e.jsx(Bt,{className:"w-3 h-3"}):e.jsx(va,{className:"w-3 h-3"}),u?`${a.length} 规则`:"未配置"]})]}),e.jsx("div",{className:"space-y-2 mt-auto",children:e.jsxs("button",{onClick:()=>s(r),className:`w-full flex items-center justify-between gap-1 px-2.5 py-2 rounded-lg text-[11px] font-extrabold transition-all ${u?"bg-gray-900 text-white hover:bg-black":"bg-[#0094f7] text-white hover:bg-[#0071e3] shadow-md shadow-blue-100"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_a,{className:"w-3.5 h-3.5"}),u?"查看发货规则":"关联发货规则"]}),e.jsx(Ws,{className:"w-3.5 h-3.5"})]})})]},`${r.cookie_id}-${r.item_id}`)}),me.length===0&&e.jsxs("div",{className:"col-span-full py-20 text-center text-gray-400",children:[e.jsx(Tt,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),I?"该账号暂无商品数据":"暂无商品数据,请选择账号进行同步"]})]}),oe&&y&&Se.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: ",y.item_id]})]}),e.jsx("button",{onClick:()=>ee(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(we,{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:U.item_title||"",onChange:r=>se({...U,item_title:r.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"价格",value:U.item_price||"",onChange:r=>se({...U,item_price:r.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"分类",value:U.item_category||"",onChange:r=>se({...U,item_category:r.target.value})}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述",value:U.item_description||"",onChange:r=>se({...U,item_description:r.target.value})})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:Ne,className:"w-full ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4"}),"保存"]})})]})}),document.body),xe&&Se.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:()=>O(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(we,{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:z.cookie_id,onChange:r=>re({...z,cookie_id:r.target.value}),children:[e.jsx("option",{value:"",children:"选择账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.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:z.item_id,onChange:r=>re({...z,item_id:r.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:z.item_price,onChange:r=>re({...z,item_price:r.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:z.item_title,onChange:r=>re({...z,item_title:r.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:z.item_image,onChange:r=>re({...z,item_image:r.target.value})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:_e,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(Qe,{className:"w-4 h-4"}),"添加商品"]})})]})}),document.body),le&&Se.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:()=>D(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(we,{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:E.cookie_id,onChange:r=>i({...E,cookie_id:r.target.value}),children:[e.jsx("option",{value:"",children:"选择账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.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:E.title,onChange:r=>i({...E,title:r.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:E.quantity,onChange:r=>i({...E,quantity:r.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:E.description,onChange:r=>i({...E,description:r.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:E.price,onChange:r=>i({...E,price:r.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:E.original_price,onChange:r=>i({...E,original_price:r.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:E.postage_mode,onChange:r=>i({...E,postage_mode:r.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:"无需邮寄"})]})]})]}),E.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:E.postage,onChange:r=>i({...E,postage:r.target.value})})]}),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(_s,{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:E.images.length?"已选择 "+E.images.length+" 张":"支持 JPG / PNG / GIF"}),e.jsx("input",{className:"hidden",type:"file",accept:"image/*",multiple:!0,onChange:r=>i({...E,images:Array.from(r.target.files||[]).slice(0,9)})})]}),q.length>0&&e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-3",children:q.map(r=>e.jsx("div",{className:"aspect-square rounded-xl bg-gray-100 overflow-hidden border border-gray-100",children:e.jsx("img",{src:r.url,alt:"",className:"w-full h-full object-cover"})},r.key))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{disabled:X,onClick:Re,className:"w-full bg-emerald-600 hover:bg-emerald-700 disabled:opacity-60 text-white px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ts,{className:"w-4 h-4"}),X?"正在发布...":"发布到闲鱼"]})})]})}),document.body),N&&Se.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 We(),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(we,{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(([r,a])=>e.jsx("div",{className:`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${T===r?"bg-blue-600 text-white border-blue-600":"bg-gray-50 text-gray-500 border-gray-100"}`,children:a},r))}),T==="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:$e,className:"shrink-0 rounded-xl bg-blue-600 px-4 py-2 text-sm font-extrabold text-white hover:bg-blue-700",children:"下载CSV模板"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"默认发布账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:F,onChange:r=>g(r.target.value),children:[e.jsx("option",{value:"",children:"选择账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.id))]}),e.jsx("p",{className:"text-xs text-gray-500",children:"表格中“账号ID”为空时,会使用这里选择的账号。"})]}),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(_s,{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:ue?ue.name:"支持 .xlsx / .csv / .tsv"}),e.jsx("input",{className:"hidden",type:"file",accept:".xlsx,.csv,.tsv",onChange:r=>{var a;return Q(((a=r.target.files)==null?void 0:a[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(_s,{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:A?A.name:"表格图片字段使用 zip 内相对路径"}),e.jsx("input",{className:"hidden",type:"file",accept:".zip",onChange:r=>{var a;return b(((a=r.target.files)==null?void 0:a[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,按上方示例填写"],["评价赠品启用","需要评价赠品时填写","填“是”表示开启;不需要时填“否”或留空"],["评价赠品内容","“评价赠品启用”填“是”时填写","格式和付款发货内容相同,也可以同时发送多个卡密组"],["求评价启用","需要自动求评价时填写","填“是”表示开启;不需要时填“否”或留空"],["求评价等待小时","“求评价启用”填“是”时填写","填写等待小时数;留空按 72 小时处理"],["求评价文案","“求评价启用”填“是”时填写","填写要发送给买家的求评价消息"],["求评价最多次数","可以留空","留空只提醒 1 次"]].map(([r,a,u])=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-bold text-gray-900 whitespace-nowrap",children:r}),e.jsx("td",{className:`px-3 py-2 min-w-[210px] font-bold ${a==="每个商品都要填"?"text-red-600":a==="可以留空"?"text-gray-500":"text-amber-700"}`,children:a}),e.jsx("td",{className:"px-3 py-2 min-w-[260px]",children:u})]},r))})]})})]})]}),T==="preview"&&v&&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:v.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:v.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:v.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("tbody",{className:"divide-y divide-gray-50",children:v.rows.map(r=>{var a,u;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:r.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 ${r.valid?"bg-emerald-50 text-emerald-700 border-emerald-100":"bg-red-50 text-red-700 border-red-100"}`,children:r.valid?"可发布":"需修正"})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[240px] truncate",children:r.title||"-"}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:["¥",r.price||"-"," / ",r.quantity||1]}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:[((a=r.images)==null?void 0:a.length)||0," 张"]}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[280px]",children:((u=r.errors)==null?void 0:u.join(";"))||"-"})]},r.row_no)})})]})})]}),(T==="running"||T==="done")&&R&&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 ${x(R.status)}`,children:[e.jsx("div",{className:"text-xs font-bold opacity-70",children:"任务状态"}),e.jsx("div",{className:"text-xl font-extrabold mt-1",children:He(R.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:R.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:R.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:R.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:R.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:"商品ID"}),e.jsx("th",{className:"px-4 py-3",children:"错误原因"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:R.rows.map(r=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:r.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 ${x(r.status)}`,children:He(r.status)})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[260px] truncate",children:r.title}),e.jsx("td",{className:"px-4 py-3 text-xs font-mono",children:r.item_url?e.jsx("a",{href:r.item_url,target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline",children:r.item_id}):r.item_id||"-"}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[340px]",children:r.error_message||"-"})]},r.id))})]})})]})]}),e.jsxs("div",{className:"modal-footer",children:[T==="upload"&&e.jsxs("button",{disabled:C||!ue||!F,onClick:Le,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(qe,{className:`w-4 h-4 ${C?"animate-spin":""}`}),C?"正在预检...":"开始预检"]}),T==="preview"&&v&&e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{disabled:C,onClick:()=>void Me(),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:C||v.valid<=0,onClick:Be,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(Ts,{className:"w-4 h-4"}),C?"启动中...":`确认发布 ${v.valid} 个商品`]})]}),(T==="running"||T==="done")&&R&&e.jsxs("div",{className:"flex gap-3 w-full",children:[R.status==="running"?e.jsx("button",{disabled:C,onClick:Ie,className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"取消任务"}):R.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/${R.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:"下载结果"}),R.retryable>0&&!["running","canceling"].includes(R.status)&&e.jsxs("button",{disabled:C,onClick:Ye,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(qe,{className:`w-4 h-4 ${C?"animate-spin":""}`}),"重试失败项"]}),!["running","canceling"].includes(R.status)&&e.jsx("button",{onClick:()=>{$(!1),_(),te()},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)]})},Ct="https://dashscope.aliyuncs.com/compatible-mode/v1",yr=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],jr=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"]),Nr=()=>{const[s,t]=n.useState(null),[l,c]=n.useState(!1),[h,f]=n.useState(""),[L,F]=n.useState(!1),[g,I]=n.useState([]),[j,G]=n.useState(!1),[Y,X]=n.useState(""),[de,C]=n.useState(!1),M=n.useRef(null),[oe,ee]=n.useState(!1),[xe,O]=n.useState(!1),[le,D]=n.useState(!1),[N,$]=n.useState(!1),[T,J]=n.useState(!1),[ue,Q]=n.useState(null),[A,b]=n.useState({new_username:"",current_password:"",new_password:"",confirm_password:""});n.useEffect(()=>{B(),Gt().then(p=>{p.username&&b(y=>({...y,new_username:p.username||""}))}).catch(()=>{})},[]),n.useEffect(()=>{const p=y=>{var S;(S=M.current)!=null&&S.contains(y.target)||C(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[]);const v=async(p,y=!1)=>{const S=p||s,U=(S==null?void 0:S.ai_api_url)||(S==null?void 0:S.ai_base_url)||Ct;G(!0),X("");try{const se=await Vl(U,(S==null?void 0:S.ai_api_key)||"");I(se),C(y&&se.length>0),!(S!=null&&S.ai_model)&&se.length>0&&t(z=>z&&{...z,ai_model:se[0]})}catch(se){I([]),C(!1),X(se.message||"读取模型失败")}finally{G(!1)}},B=()=>{c(!0),f(""),Kt().then(p=>{t(p),v(p)}).catch(p=>{t(null),f(p.message||"加载配置失败")}).finally(()=>c(!1))},R=async()=>{if(s){F(!0);try{const p=Object.fromEntries(Object.entries(s).filter(([y,S])=>!jr.has(y)&&S!==void 0&&S!==null));await Yt(p),alert("系统配置已保存")}catch(p){alert("保存失败:"+p.message)}finally{F(!1)}}},K=async p=>{p.preventDefault(),Q(null);const y=A.new_username.trim();if(y.length<3){Q({type:"error",text:"用户名至少需要 3 个字符"});return}if(!A.current_password){Q({type:"error",text:"请输入当前密码确认身份"});return}if(A.new_password&&A.new_password.length<8){Q({type:"error",text:"新密码至少需要 8 个字符"});return}if(A.new_password!==A.confirm_password){Q({type:"error",text:"两次输入的新密码不一致"});return}J(!0);try{const S=await Ga({current_password:A.current_password,new_username:y,new_password:A.new_password||void 0});if(!S.success){Q({type:"error",text:S.message||"登录凭据更新失败"});return}Q({type:"success",text:S.message||"登录凭据已更新"}),window.setTimeout(()=>window.location.reload(),1400)}catch(S){Q({type:"error",text:S.message||"登录凭据更新失败"})}finally{J(!1)}};if(!s)return e.jsx("div",{className:"p-8 text-center text-gray-400",children:h||(l?"加载配置中...":"暂无配置")});const H=s.ai_model||"",m=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(Ys,{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:B,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(qe,{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(wa,{className:"w-4 h-4"})}),"基础设置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出等级"}),e.jsx("select",{value:s.log_level||"info",onChange:p=>t({...s,log_level:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:yr.map(p=>e.jsx("option",{value:p.value,children:p.label},p.value))}),e.jsx("p",{className:"text-xs text-gray-500",children:"等级越低输出越详细,Debug 适合排查问题"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出格式"}),e.jsxs("select",{value:s.log_format||"text",onChange:p=>t({...s,log_format:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"JSON 适合接入集中式日志系统,保存后需重启服务生效"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"续期日志保留天数"}),e.jsx("input",{type:"number",value:s.renewal_log_retention_days??10,onChange:p=>t({...s,renewal_log_retention_days:parseInt(p.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-[#0094f7] text-white",children:e.jsx(Ft,{className:"w-4 h-4"})}),"AI 智能回复配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API 地址"}),e.jsx("input",{type:"text",value:s.ai_api_url||Ct,onChange:p=>t({...s,ai_api_url:p.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:oe?"text":"password",value:s.ai_api_key||"",onChange:p=>t({...s,ai_api_key:p.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:()=>ee(!oe),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:oe?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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:M,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:H,onFocus:()=>g.length>0&&C(!0),onChange:p=>{t({...s,ai_model:p.target.value}),g.length>0&&C(!0)},onKeyDown:p=>{p.key==="Escape"&&C(!1),p.key==="ArrowDown"&&g.length>0&&C(!0)},className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:()=>g.length>0&&C(p=>!p),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(ka,{className:`w-4 h-4 transition-transform ${de?"rotate-180":""}`})}),de&&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:m.length>0?m.map(p=>e.jsxs("button",{type:"button",onClick:()=>{t({...s,ai_model:p}),C(!1)},className:"w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-[#0094f7] flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:p}),p===H&&e.jsx(Ge,{className:"w-4 h-4 shrink-0 text-[#0094f7]"})]},p)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:()=>v(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(qe,{className:`w-4 h-4 ${j?"animate-spin":""}`}),"读取模型"]})]}),Y?e.jsx("p",{className:"text-xs text-red-500",children:Y}):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(Vs,{className:"w-4 h-4"})}),"远程过滑块配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务地址"}),e.jsx("input",{type:"url",value:s["captcha.remote_service_url"]||"",onChange:p=>t({...s,"captcha.remote_service_url":p.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:xe?"text":"password",value:s["captcha.remote_secret_key"]||"",onChange:p=>t({...s,"captcha.remote_secret_key":p.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:()=>O(!xe),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:xe?"隐藏秘钥":"显示秘钥",children:xe?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{className:"w-4 h-4"})})]})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl bg-amber-50 p-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:String(s["captcha.remote_pass_cookies"]||"").toLowerCase()==="true",onChange:p=>t({...s,"captcha.remote_pass_cookies":p.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(xt,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:K,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(Ca,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:A.new_username,onChange:p=>b({...A,new_username:p.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:le?"text":"password",value:A.current_password,onChange:p=>b({...A,current_password:p.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:()=>D(!le),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:le?"隐藏密码":"显示密码",children:le?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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:N?"text":"password",value:A.new_password,onChange:p=>b({...A,new_password:p.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:()=>$(!N),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:N?"隐藏密码":"显示密码",children:N?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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:N?"text":"password",value:A.confirm_password,onChange:p=>b({...A,confirm_password:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),ue&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${ue.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(Vs,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:ue.text})]}),e.jsxs("button",{type:"submit",disabled:T||!A.new_username||!A.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(xt,{className:"w-4 h-4"}),T?"正在更新...":"更新登录凭据"]})]})]})]})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:R,disabled:L,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(Ke,{className:"w-6 h-6"}),L?"保存中...":"保存所有配置"]})})]})},qs=(s,t)=>s.allowed_resolutions.includes(t),vr=(s,t)=>({runs:s.runs.filter(l=>!t||l.cookie_id===t),pending_tasks:s.pending_tasks.filter(l=>!t||l.cookie_id===t)}),_r=s=>({external_result_unknown:"外部动作结果未知",invalid_snapshot:"历史数据无法恢复",rule_unavailable:"规则不可用",partial_failure:"部分动作失败",execution_failed:"动作执行失败"})[s]||"自动化异常",wr=async s=>{const t=s.loadIssues().then(s.onIssues).catch(s.onIssuesError),l=await s.loadRules();s.onRules(l),await t},kr=(s,t,l,c,h,f)=>s!==t||l!==c?!1:(f(h),!0),ls={order_paid:{label:"付款后自动发货",shortLabel:"自动发货",description:"闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。",flow:["付款系统卡片","匹配商品/规格","发送卡密","确认发货"],accent:"blue",icon:Ns},buyer_reviewed:{label:"评价后发送赠品",shortLabel:"评价赠品",description:"闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。",flow:["评价系统卡片","匹配商品/规格","发送赠品"],accent:"emerald",icon:Sa},review_missing_timeout:{label:"超时未评价求评价",shortLabel:"求评价",description:"计划任务扫描已发货未评价订单,到期后发送求评价文案。",flow:["计划任务扫描","已发货未评价","达到等待时间","发送提醒"],accent:"amber",icon:zt}},Bs=["order_paid","buyer_reviewed","review_missing_timeout"],Cr="亲,商品使用满意的话,麻烦给个评价,谢谢~",bs=()=>({spec_name:"",spec_value:"",card_id:0,delivery_count:1,enabled:!0,delay_override:!1,delay_seconds:0}),Ht=s=>{if(!s)return{};try{const t=JSON.parse(s);return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}catch{return{}}},as=(s,t={})=>{const l=Ht(s);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),...t})},fs=(s,t)=>{var c;const l=((c=ls[s])==null?void 0:c.label)||"自动化规则";return t?`${l} - ${t}`:l},St=s=>{const t=(s||"").trim();return t?Object.values(ls).some(l=>t===l.label||t.startsWith(`${l.label} -`)):!0},ys=(s,t=0)=>{if(s==="review_missing_timeout")return[{action_type:"send_text",message_template:Cr,enabled:!0,sort_order:1}];const l={action_type:"send_card",card_id:t,delivery_count:1,enabled:!0,sort_order:1};return s==="order_paid"?[l,{action_type:"confirm_shipment",enabled:!0,sort_order:2}]:[l]},Sr=s=>{var l,c;if(s.trigger_type==="review_missing_timeout")return((c=(l=s.actions)==null?void 0:l.find(h=>h.action_type==="send_text"))==null?void 0:c.message_template)||"发送求评价文案";const t=(s.actions||[]).filter(h=>h.action_type==="send_card");return t.length?t.map(h=>h.card_name||`卡密 ${h.card_id}`).join(" / "):"未配置卡密库存"},Lt=(s,t=!1)=>{const l={blue:t?"border-blue-500 bg-blue-50 text-blue-700":"border-blue-100 bg-blue-50/60 text-blue-700 hover:border-blue-300",emerald:t?"border-emerald-500 bg-emerald-50 text-emerald-700":"border-emerald-100 bg-emerald-50/60 text-emerald-700 hover:border-emerald-300",amber:t?"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[s]||l.blue},Lr=s=>s?"bg-emerald-100 text-emerald-700":"bg-gray-200 text-gray-500",Ss=s=>(s==null?void 0:s.nickname)||(s==null?void 0:s.remark)||(s==null?void 0:s.id)||"未知账号",Ar=s=>s===!0||s===1||s==="1",Ir=({initialDeliveryTarget:s,onDeliveryTargetHandled:t})=>{var fe,ze,r;const[l,c]=n.useState("automation"),[h,f]=n.useState([]),[L,F]=n.useState({runs:[],pending_tasks:[]}),[g,I]=n.useState([]),[j,G]=n.useState({}),[Y,X]=n.useState([]),[de,C]=n.useState([]),[M,oe]=n.useState([]),[ee,xe]=n.useState(!1),[O,le]=n.useState(""),D=n.useRef(0),N=n.useRef("");N.current=O;const[$,T]=n.useState(!1),[J,ue]=n.useState(!1),[Q,A]=n.useState(!1),[b,v]=n.useState(null),[B,R]=n.useState(null),[K,H]=n.useState({cookie_id:"",enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""});Y.find(a=>a.id===O);const m=n.useCallback(async()=>{const[a,u,w,W]=await Promise.all([Rs(),Ve(),ps(),vt()]);X(a),C(u),oe(w),G(W),le(ae=>{var ve;return ae||((ve=a[0])==null?void 0:ve.id)||""})},[]),p=n.useCallback(async()=>{await wr({loadRules:Is,loadIssues:El,onRules:f,onIssues:F,onIssuesError:a=>console.warn("加载自动化异常列表失败,不阻断规则展示",a)})},[]),y=n.useCallback(async()=>{const a=O;if(a!==N.current)return;const u=++D.current;if(I([]),!a)return;const w=await ql(a);kr(u,D.current,a,N.current,w,I)},[O]),S=n.useCallback(async()=>{G(await vt())},[]),U=n.useCallback(async()=>{xe(!0);try{l==="automation"?await p():l==="reply"?await y():await S()}finally{xe(!1)}},[l,p,S,y]);n.useEffect(()=>{m().catch(a=>console.error("加载规则参考数据失败",a))},[m]),n.useEffect(()=>{U().catch(a=>console.error("刷新规则页面失败",a))},[U]);const se=n.useMemo(()=>h.filter(a=>!O||a.cookie_id===O),[h,O]),z=n.useMemo(()=>vr(L,O),[L,O]),re=n.useMemo(()=>Y.filter(a=>!O||a.id===O),[Y,O]),E=n.useMemo(()=>{var u;const a={order_paid:[],buyer_reviewed:[],review_missing_timeout:[]};for(const w of se)(u=a[w.trigger_type])==null||u.push(w);return a},[se]),i=n.useMemo(()=>{const a=(b==null?void 0:b.cookie_id)||O;return M.filter(u=>u.cookie_id===a)},[b==null?void 0:b.cookie_id,M,O]),q=n.useMemo(()=>{if(!(!(b!=null&&b.cookie_id)||!(b!=null&&b.item_id)))return M.find(a=>a.cookie_id===b.cookie_id&&a.item_id===b.item_id)},[b==null?void 0:b.cookie_id,b==null?void 0:b.item_id,M]),d=Ar(q==null?void 0:q.is_multi_spec),_=(b==null?void 0:b.trigger_type)||"order_paid",te=ls[_],Z=Ht(b==null?void 0:b.config_json),pe=n.useCallback((a="order_paid",u=O,w="")=>{const W=M.find(ve=>ve.cookie_id===u&&ve.item_id===w),ae=(W==null?void 0:W.item_title)||w;return{name:fs(a,ae),trigger_type:a,cookie_id:u,item_id:w,item_title:(W==null?void 0:W.item_title)||"",item_keyword:ae,card_group_id:0,priority:100,enabled:!0,config_json:a==="review_missing_timeout"?as():"{}",actions:ys(a),variants:a==="review_missing_timeout"?[]:[bs()]}},[M,O]),Ne=n.useCallback(a=>{var w,W;const u=a.trigger_type||"order_paid";v({...a,trigger_type:u,config_json:u==="review_missing_timeout"?as(a.config_json):a.config_json||"{}",actions:(w=a.actions)!=null&&w.length?a.actions.map(ae=>({...ae})):ys(u,a.card_group_id),variants:(W=a.variants)!=null&&W.length?a.variants.map(ae=>({...ae})):u==="review_missing_timeout"?[]:[bs()]}),T(!0)},[]);n.useEffect(()=>{if(!s)return;let a=!1;return(async()=>{c("automation"),le(s.cookieId),xe(!0);try{const[w,W,ae]=await Promise.all([Is(),ps(),Ve().catch(he=>(console.warn("加载卡密库存失败,不阻断打开自动化规则",he),[]))]);if(a)return;f(w),oe(W),C(ae);const ve=w.find(he=>he.cookie_id===s.cookieId&&he.item_id===s.itemId&&he.trigger_type==="order_paid");if(ve)Ne(ve);else{const he=W.find(De=>De.cookie_id===s.cookieId&&De.item_id===s.itemId);v({...pe("order_paid",s.cookieId,s.itemId),item_title:(he==null?void 0:he.item_title)||"",item_keyword:(he==null?void 0:he.item_title)||s.itemId,name:fs("order_paid",(he==null?void 0:he.item_title)||s.itemId)}),T(!0)}}catch(w){console.error("打开商品自动化规则失败",w),alert("无法加载该商品的自动化规则")}finally{a||(xe(!1),t==null||t())}})(),()=>{a=!0}},[pe,s,t,Ne]);const ce=(a="order_paid")=>{if(!O){alert("请先选择账号");return}v(pe(a)),T(!0)},_e=a=>{var W,ae,ve,he,De;if(!b)return;const u=((ae=(W=b.variants)==null?void 0:W.find(je=>je.card_id))==null?void 0:ae.card_id)||((he=(ve=b.actions)==null?void 0:ve.find(je=>je.action_type==="send_card"))==null?void 0:he.card_id)||b.card_group_id||0,w=(q==null?void 0:q.item_title)||b.item_title||b.item_id||"";v({...b,trigger_type:a,name:St(b.name)?fs(a,w):b.name,card_group_id:u,config_json:a==="review_missing_timeout"?as(b.config_json):"{}",actions:ys(a,u),variants:a==="review_missing_timeout"?[]:(De=b.variants)!=null&&De.length?b.variants:[{...bs(),card_id:u}]})},Re=a=>{if(!b)return;const u=M.find(W=>W.cookie_id===(b.cookie_id||O)&&W.item_id===a),w=(u==null?void 0:u.item_title)||a;v({...b,item_id:a,item_title:(u==null?void 0:u.item_title)||"",item_keyword:w,name:St(b.name)?fs(_,w):b.name})},ye=(fe=b==null?void 0:b.variants)!=null&&fe.length?b.variants:[bs()],Ae=(a,u)=>{var W;if(!b)return;const w=ye.map((ae,ve)=>ve===a?{...ae,...u}:ae);v({...b,variants:w,card_group_id:((W=w[0])==null?void 0:W.card_id)||0})},Le=()=>{if(!b)return;const a=ye[ye.length-1];v({...b,variants:[...ye,{...bs(),spec_name:d&&(a==null?void 0:a.spec_name)||"",spec_value:d&&(a==null?void 0:a.spec_value)||""}]})},Be=async()=>{var W,ae,ve,he,De;if(!b)return;const a=b.trigger_type||"order_paid";if(!b.cookie_id){alert("请选择账号");return}const u=(W=b.variants)!=null&&W.length?b.variants:[];if(a!=="review_missing_timeout"){if(!u.length||u.some(je=>!je.card_id)){alert(a==="buyer_reviewed"?"请选择评价赠品卡密库存":"请选择发货卡密库存");return}if(d&&u.some(je=>!je.spec_name.trim()||!je.spec_value.trim())){alert("多规格商品必须填写每一行的规格名称和规格值");return}}if(a==="review_missing_timeout"&&!(((ve=(ae=b.actions)==null?void 0:ae.find(o=>o.action_type==="send_text"))==null?void 0:ve.message_template)||"").trim()){alert("请填写求评价文案");return}const w=a==="review_missing_timeout"?[]:u.map(je=>({...je,spec_name:d?je.spec_name.trim():"",spec_value:d?je.spec_value.trim():"",delivery_count:Math.max(1,Number(je.delivery_count)||1),enabled:je.enabled!==!1}));try{await jt({...b,trigger_type:a,name:(b.name||"").trim()||fs(a,(q==null?void 0:q.item_title)||b.item_id||""),config_json:a==="review_missing_timeout"?as(b.config_json):b.config_json||"{}",actions:(he=b.actions)!=null&&he.length?b.actions:ys(a,((De=w[0])==null?void 0:De.card_id)||b.card_group_id||0),variants:w}),T(!1),await Promise.all([p(),m()]),alert("保存成功")}catch(je){console.error("保存自动化规则失败:",je),alert("保存失败:"+je.message)}},Ie=async a=>{if(confirm("确定删除该自动化规则吗?"))try{await Tl(a),await p(),alert("删除成功")}catch(u){alert("删除失败:"+u.message)}},Me=async a=>{try{await jt({...a,enabled:!a.enabled}),await p()}catch(u){alert("操作失败:"+u.message)}},We=async(a,u)=>{if(confirm(u==="continue"?"确认外部动作已经执行成功,并跳到下一步吗?":u==="retry"?"确认外部动作没有执行,可以安全重试吗?错误判断可能造成重复发送。":"确认终止该自动化运行吗?"))try{await Fl(a,u),await p()}catch(W){alert("处理失败:"+W.message)}},Ye=async(a,u)=>{if(confirm(u==="retry"?"确认重新执行该任务吗?":"确认忽略并删除该异常任务吗?"))try{await Dl(a,u),await p()}catch(w){alert("处理失败:"+w.message)}},$e=()=>{if(!O){alert("请先选择账号");return}R({keyword:"",reply_content:"",image_url:"",item_id:"",type:"text",match_type:"fuzzy",enabled:!0}),ue(!0)},ss=async()=>{var u,w,W;if(!B||!O)return;const a=B.type==="image"?!!((u=B.image_url)!=null&&u.trim()):!!((w=B.reply_content)!=null&&w.trim());if(!((W=B.keyword)!=null&&W.trim())||!a){alert("请填写关键词和回复内容");return}try{await Bl({...B,match_type:"fuzzy",enabled:!0},O),ue(!1),await y(),alert("保存成功")}catch(ae){alert("保存失败:"+ae.message)}},Ze=async a=>{if(!(!O||!confirm("确定删除该回复规则吗?")))try{await zl(a,O),await y(),alert("删除成功")}catch(u){alert("删除失败:"+u.message)}},Xe=async(a=O)=>{if(!a){alert("请先选择账号");return}try{const u=await Zl(a);H({cookie_id:a,enabled:u.enabled,reply_content:u.reply_content,reply_once:u.reply_once,reply_image_url:u.reply_image_url||""})}catch{H({cookie_id:a,enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""})}A(!0)},He=async()=>{if(!K.cookie_id){alert("请先选择账号");return}if(K.enabled&&!K.reply_content.trim()&&!K.reply_image_url.trim()){alert("启用默认回复时,请填写回复内容或图片 URL");return}try{await Xl(K.cookie_id,{enabled:K.enabled,reply_content:K.reply_content,reply_once:K.reply_once,reply_image_url:K.reply_image_url}),A(!1),await S(),alert("保存成功")}catch(a){alert("保存失败:"+a.message)}},x=async a=>{if(confirm("确定删除该账号默认回复吗?"))try{await Hl(a),await S(),alert("删除成功")}catch(u){alert("删除失败:"+u.message)}},P=async a=>{if(confirm("确定清空该账号的默认回复记录吗?清空后可重新对所有会话使用“只回复一次”。"))try{await er(a),alert("清空成功")}catch(u){alert("清空失败:"+u.message)}},me=l==="automation"?"新建自动化":l==="reply"?"新增关键词":"编辑默认回复";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:"系统通知卡片只进入自动化判断;买家消息进入关键词、默认或 AI 回复。"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("select",{value:O,onChange:a=>le(a.target.value),className:"ios-input px-4 py-3 rounded-2xl text-sm min-w-64",children:[e.jsx("option",{value:"",children:"全部账号"}),Y.map(a=>e.jsx("option",{value:a.id,children:Ss(a)},a.id))]}),e.jsxs("button",{onClick:U,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 transition-colors",children:[e.jsx(qe,{className:`w-4 h-4 ${ee?"animate-spin":""}`}),"刷新"]}),e.jsxs("button",{onClick:l==="automation"?()=>ce("order_paid"):l==="reply"?$e:()=>void Xe(),disabled:!O,className:"ios-btn-primary px-5 py-3 rounded-2xl text-sm font-extrabold flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(Qe,{className:"w-4 h-4"}),me]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[{id:"automation",label:"交易自动化",icon:Us},{id:"reply",label:"关键词回复",icon:Ls},{id:"default",label:"账号默认回复",icon:ds}].map(a=>{const u=a.icon;return e.jsxs("button",{onClick:()=>c(a.id),className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${l===a.id?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:[e.jsx(u,{className:"w-4 h-4"}),a.label]},a.id)})}),l==="automation"&&(z.runs.length>0||z.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(ms,{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:[z.runs.map(a=>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:["账号 ",a.cookie_id," · 订单 ",a.order_id||"-"," · 已记录发送 ",a.sent_count," 条"]}),e.jsx("div",{className:"text-xs font-bold text-red-800 mt-1",children:_r(a.issue_kind)}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:a.error_message})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 shrink-0",children:[qs(a,"continue")&&e.jsx("button",{onClick:()=>void We(a.id,"continue"),className:"px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold",children:"已执行,继续下一步"}),qs(a,"retry")&&e.jsx("button",{onClick:()=>void We(a.id,"retry"),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"未执行,安全重试"}),qs(a,"cancel")&&e.jsx("button",{onClick:()=>void We(a.id,"cancel"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"终止"})]})]},`run-${a.id}`)),z.pending_tasks.map(a=>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:["账号 ",a.cookie_id," · 延迟任务重试已达 ",a.attempt_count," 次"]}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:a.error_message})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>void Ye(a.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 Ye(a.id,"dismiss"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"忽略"})]})]},`task-${a.id}`))]})]}),l==="automation"&&e.jsxs("div",{className:"grid grid-cols-1 2xl:grid-cols-[360px_1fr] gap-6",children:[e.jsxs("aside",{className:"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:Bs.map(a=>{const u=ls[a],w=u.icon;return e.jsx("button",{type:"button",onClick:()=>ce(a),className:`w-full text-left rounded-2xl border p-4 transition-colors ${Lt(u.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(w,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:u.label}),e.jsx("div",{className:"text-xs opacity-75 mt-1 leading-5",children:u.description})]})]})},a)})})]}),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-4",children:"规则概览"}),e.jsx("div",{className:"space-y-3",children:Bs.map(a=>{const u=ls[a],w=u.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(w,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:u.shortLabel})]}),e.jsx("span",{className:"text-sm font-black text-gray-900",children:E[a].length})]},a)})})]})]}),e.jsx("section",{className:"space-y-4",children:se.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-dashed border-gray-200 p-16 text-center",children:[e.jsx(Us,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-black text-gray-900",children:"还没有自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2",children:"从左侧选择一个模板开始配置。"})]}):se.map(a=>{const u=ls[a.trigger_type],w=u.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 ${Lt(u.accent,!0)}`,children:e.jsx(w,{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:a.name}),e.jsx("span",{className:`px-2.5 py-1 rounded-full text-xs font-bold ${Lr(a.enabled)}`,children:a.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:u.label}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:a.item_title||a.item_id||"账号级规则"}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-blue-50 text-blue-700",children:Sr(a)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>Ne(a),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(us,{className:"w-4 h-4"}),"编辑"]}),e.jsx("button",{onClick:()=>Me(a),className:`px-4 py-2 rounded-xl text-sm font-bold ${a.enabled?"bg-amber-50 text-amber-700 hover:bg-amber-100":"bg-emerald-50 text-emerald-700 hover:bg-emerald-100"}`,children:a.enabled?"禁用":"启用"}),e.jsx("button",{onClick:()=>Ie(a.id),className:"p-2.5 rounded-xl text-red-500 hover:bg-red-50",title:"删除",children:e.jsx(Je,{className:"w-4 h-4"})})]})]})},a.id)})})]}),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(ms,{className:"w-4 h-4"}),"这里只处理买家用户消息;系统通知不会进入关键词或 AI 回复。"]}),e.jsxs("div",{className:"space-y-3",children:[g.map(a=>e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border border-gray-100 bg-[#F7F8FA] 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:["“",a.keyword,"”"]})]}),e.jsx("div",{className:"bg-white p-3 rounded-xl border border-gray-100 text-sm text-gray-600 leading-relaxed",children:a.type==="image"&&a.image_url?a.image_url:a.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:()=>{R({...a}),ue(!0)},className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(us,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>Ze(a.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Je,{className:"w-5 h-5"})})]})]},a.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(ms,{className:"w-4 h-4"}),"默认回复只处理买家用户消息;关键词未命中且 AI 未接管时才会使用。"]}),e.jsxs("div",{className:"space-y-3",children:[re.map(a=>{const u=j[a.id],w=!!(u!=null&&u.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 ${w?"border-purple-100 bg-purple-50/50 hover:bg-white hover:shadow-lg":"border-gray-100 bg-[#F7F8FA] 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 ${w?"bg-purple-600 text-white":"bg-gray-200 text-gray-400"}`,children:e.jsx(ds,{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:Ss(a)}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-xs font-bold ${w?"bg-green-100 text-green-700":"bg-gray-200 text-gray-500"}`,children:w?"已启用":"未启用"}),(u==null?void 0:u.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:w?u.reply_content||u.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 Xe(a.id),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(us,{className:"w-4 h-4"})}),w&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>void P(a.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 x(a.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Je,{className:"w-5 h-5"})})]})]})]},a.id)}),re.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无账号"})]})]}),$&&b&&Se.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:b.id?"编辑自动化规则":"新建自动化规则"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:te.description})]}),e.jsx("button",{onClick:()=>T(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",title:"关闭",children:e.jsx(we,{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:Bs.map(a=>{const u=ls[a],w=u.icon,W=_===a;return e.jsx("button",{type:"button",onClick:()=>_e(a),className:`w-full rounded-2xl p-4 text-left border transition-all ${W?"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(w,{className:`w-5 h-5 mt-0.5 ${W?"text-[#0094f7]":"text-white"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black",children:u.label}),e.jsx("div",{className:`text-xs mt-1 leading-5 ${W?"text-gray-500":"text-gray-400"}`,children:u.description})]})]})},a)})}),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:te.flow.map((a,u)=>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:u+1}),e.jsx("span",{className:"text-sm font-bold text-gray-100",children:a})]},a))})]})]}),e.jsx("div",{className:"p-6 overflow-y-auto bg-[#F7F8FA]",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(Bt,{className:"w-5 h-5 text-[#0094f7]"}),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:b.name||"",onChange:a=>v({...b,name:a.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:b.cookie_id||"",onChange:a=>v({...b,cookie_id:a.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:"选择账号"}),Y.map(a=>e.jsx("option",{value:a.id,children:Ss(a)},a.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:b.item_id||"",onChange:a=>Re(a.target.value),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级规则(不限定商品)"}),i.map(a=>e.jsx("option",{value:a.item_id,children:a.item_title||a.item_id},`${a.cookie_id}-${a.item_id}`))]})]})]}),q&&_!=="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:q.item_title||q.item_id}),e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${d?"bg-blue-50 text-blue-700":"bg-gray-100 text-gray-500"}`,children:d?"多规格商品":"普通商品"}),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:"多规格状态来自闲鱼商品本身,发布后不能在这里修改;系统会在买家付款后读取订单详情,按实际购买规格和数量匹配下面的发货规则。"})]})]}),_!=="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(La,{className:"w-5 h-5 text-[#0094f7]"}),e.jsx("h4",{className:"font-black text-gray-900",children:_==="buyer_reviewed"?"赠品库存":"发货库存"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:d?"每条发货内容绑定一个订单规格;同一规格可添加多条内容并全部发送。":"可添加多条发货内容,买家付款后会按顺序全部发送。"})]}),e.jsxs("button",{type:"button",onClick:Le,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(Qe,{className:"w-3.5 h-3.5"}),"添加发货内容"]})]}),e.jsx("div",{className:"space-y-3",children:ye.map((a,u)=>e.jsxs("div",{className:`grid grid-cols-1 gap-3 items-end rounded-2xl border border-gray-200 p-4 ${d?"md:grid-cols-[1fr_1fr_1.4fr_110px_40px]":"md:grid-cols-[1.4fr_110px_40px]"}`,children:[d&&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:a.spec_name,onChange:w=>Ae(u,{spec_name:w.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:a.spec_value,onChange:w=>Ae(u,{spec_value:w.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:a.card_id||"",onChange:w=>Ae(u,{card_id:Number(w.target.value)}),className:"w-full ios-input px-3 py-2.5 rounded-lg",children:[e.jsx("option",{value:"",children:"请选择卡密库存"}),de.filter(w=>w.enabled&&w.type!=="api").map(w=>e.jsx("option",{value:w.id,children:w.name},w.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:a.delivery_count,onChange:w=>Ae(u,{delivery_count:Math.max(1,Number(w.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:a.delay_override===!0,onChange:w=>Ae(u,{delay_override:w.target.checked}),className:"accent-[#0094f7]"}),"覆盖卡密默认延时"]}),a.delay_override&&e.jsx("input",{type:"number",min:"0",max:"3600",value:a.delay_seconds||0,onChange:w=>Ae(u,{delay_seconds:Math.max(0,Number(w.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:a.delay_override?`本动作延时 ${a.delay_seconds||0} 秒`:"使用卡密默认延时"})]}),e.jsx("button",{type:"button",disabled:ye.length===1,onClick:()=>v({...b,variants:ye.filter((w,W)=>W!==u)}),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(Je,{className:"w-4 h-4"})})]},a.id||u))})]}):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(zt,{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(Z.after_shipped_hours||72),onChange:a=>v({...b,config_json:as(b.config_json,{after_shipped_hours:Math.max(1,Number(a.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(Z.repeat_interval_hours||24),onChange:a=>v({...b,config_json:as(b.config_json,{repeat_interval_hours:Math.max(1,Number(a.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(Z.max_attempts||1),onChange:a=>v({...b,config_json:as(b.config_json,{max_attempts:Math.max(1,Number(a.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:((r=(ze=b.actions)==null?void 0:ze.find(a=>a.action_type==="send_text"))==null?void 0:r.message_template)||"",onChange:a=>{var u;return v({...b,actions:((u=b.actions)!=null&&u.length?b.actions:ys("review_missing_timeout")).map(w=>w.action_type==="send_text"?{...w,message_template:a.target.value}:w)})},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:b.priority||100,onChange:a=>v({...b,priority:Number(a.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:b.enabled!==!1,onChange:a=>v({...b,enabled:a.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:()=>T(!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:Be,className:"flex-1 ios-btn-primary px-6 py-3 rounded-2xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4"}),"保存自动化规则"]})]})]})}),document.body),J&&B&&Se.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:B.id?"编辑回复规则":"新增回复规则"}),e.jsx("button",{onClick:()=>ue(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(we,{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:B.item_id||"",onChange:a=>R({...B,item_id:a.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级回复"}),M.filter(a=>!O||a.cookie_id===O).map(a=>e.jsx("option",{value:a.item_id,children:a.item_title||a.item_id},`${a.cookie_id}-${a.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:B.type||"text",onChange:a=>{const u=a.target.value;R({...B,type:u,reply_content:u==="text"?B.reply_content:"",image_url:u==="image"?B.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:B.keyword||"",onChange:a=>R({...B,keyword:a.target.value}),placeholder:"买家发送的关键词",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),B.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:B.image_url||"",onChange:a=>R({...B,image_url:a.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:B.reply_content||"",onChange:a=>R({...B,reply_content:a.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:()=>ue(!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:ss,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Zs,{className:"w-4 h-4"}),"保存规则"]})]})]})]})}),document.body),Q&&Se.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:()=>A(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",title:"关闭",children:e.jsx(we,{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:K.cookie_id,onChange:a=>H({...K,cookie_id:a.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),Y.map(a=>e.jsx("option",{value:a.id,children:Ss(a)},a.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:()=>H({...K,enabled:!K.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${K.enabled?"bg-[#0094f7]":"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 ${K.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:K.reply_content,onChange:a=>H({...K,reply_content:a.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:K.reply_image_url,onChange:a=>H({...K,reply_image_url:a.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:K.reply_once,onChange:a=>H({...K,reply_once:a.target.checked}),className:"w-4 h-4 rounded"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:()=>A(!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:He,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4"}),"保存默认回复"]})]})]})]})}),document.body)]})},$r=s=>{const t=String(s.smtp_from||"").trim(),l=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);return{...s,smtp_from_name:s.smtp_from_name||(l?"":t),smtp_from_address:s.smtp_from_address||(l?t:s.smtp_user||""),smtp_use_tls:At(s.smtp_use_tls,!0),smtp_use_ssl:At(s.smtp_use_ssl,!1)}},At=(s,t)=>{if(typeof s=="boolean")return s;if(typeof s=="string"){if(["true","1","yes","on"].includes(s.toLowerCase()))return!0;if(["false","0","no","off"].includes(s.toLowerCase()))return!1}return t},Hs=["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from_name","smtp_from_address","smtp_use_tls","smtp_use_ssl"],Ks=(s,t)=>{if(typeof s=="boolean")return s;if(typeof s=="string"){if(["true","1","yes","on"].includes(s.toLowerCase()))return!0;if(["false","0","no","off"].includes(s.toLowerCase()))return!1}return t},ea=s=>{const t=Object.prototype.hasOwnProperty.call(s,"use_custom_smtp"),l=Hs.some(c=>String(s[c]??"").trim()!=="");return{...s,use_custom_smtp:t?Ks(s.use_custom_smtp,!1):l}},It=(s,t)=>{const l={...s,use_custom_smtp:!0};for(const c of Hs)String(l[c]??"").trim()===""&&t[c]!==void 0&&(l[c]=t[c]);return l.smtp_port||(l.smtp_port=587),l.smtp_from_address||(l.smtp_from_address=l.smtp_user||""),l.smtp_use_tls=Ks(l.smtp_use_tls,!0),l.smtp_use_ssl=Ks(l.smtp_use_ssl,!1),l},Rr=s=>{const t=ea(s),l={to_email:String(t.to_email??"").trim(),use_custom_smtp:t.use_custom_smtp===!0};if(l.use_custom_smtp)for(const c of Hs)l[c]=t[c];return l},cs={bark:{label:"Bark",icon:xs,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:"闲鱼助手"},{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:Ls,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:Ls,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:Ls,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:Aa,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:Zs,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:Ut,fields:[{key:"to_email",label:"收件邮箱",placeholder:"receiver@example.com",required:!0}],guide:{steps:["通常先保存页面中的系统 SMTP 配置","邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP","只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置"],note:"继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。"}}},sa=[{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:"后台任务或系统级异常"}],Pr=s=>!s||s.length===0?"全部事件":s.map(l=>{var c;return((c=sa.find(h=>h.value===l))==null?void 0:c.label)||l}).join("、"),Tr=({isAdmin:s=!1})=>{const[t,l]=n.useState([]),[c,h]=n.useState(!0),[f,L]=n.useState(!1),[F,g]=n.useState(null),[I,j]=n.useState(!1),[G,Y]=n.useState(""),[X,de]=n.useState(null),[C,M]=n.useState({}),[oe,ee]=n.useState(!1),[xe,O]=n.useState(!1),[le,D]=n.useState(!1),[N,$]=n.useState({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),T=async()=>{h(!0);try{const m=await Xt();l(m.data||[])}catch(m){console.error("加载通知渠道失败",m)}finally{h(!1)}},J=async()=>{try{const m=await Kt();M($r(m||{}))}catch(m){console.error("加载 SMTP 配置失败",m)}},ue=async()=>{ee(!0);try{await Yt({smtp_server:C.smtp_server||"",smtp_port:C.smtp_port||587,smtp_user:C.smtp_user||"",smtp_password:C.smtp_password||"",smtp_from_name:C.smtp_from_name||"",smtp_from_address:C.smtp_from_address||C.smtp_user||"",smtp_use_tls:C.smtp_use_tls!==!1,smtp_use_ssl:C.smtp_use_ssl===!0}),Q("success","SMTP 配置已保存")}catch(m){Q("error",(m==null?void 0:m.message)||"保存失败")}finally{ee(!1)}};n.useEffect(()=>{T(),s?J():M({})},[s]);const Q=(m,p)=>{de({type:m,text:p}),window.setTimeout(()=>de(null),3e3)},A=()=>{g(null),$({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),D(!1),L(!0)},b=m=>{g(m);const p=m.type==="email"?ea({...m.config||{}}):null,y=p?p.use_custom_smtp===!0?It(p,C):p:{...m.config||{}};$({name:m.name,type:m.type,enabled:m.enabled,config:y,event_types:m.event_types||[]}),D(!1),L(!0)},v=async()=>{const m=cs[N.type];for(const y of m.fields)if(y.required&&!String(N.config[y.key]||"").trim()){Q("error",`请填写 ${y.label}`);return}if(!N.name.trim()){Q("error","请填写渠道名称");return}let p=N.config;if(N.type==="email"&&(p=Rr(N.config),p.use_custom_smtp)){const S=[["smtp_server","独立 SMTP 服务器"],["smtp_port","独立 SMTP 端口"],["smtp_user","独立 SMTP 登录邮箱"],["smtp_password","独立 SMTP 密码 / 授权码"],["smtp_from_address","独立 SMTP 发件地址"]].find(([U])=>!String(p[U]||"").trim());if(S){Q("error",`请填写 ${S[1]}`);return}}j(!0);try{const y={name:N.name.trim(),type:N.type,config:p,event_types:N.event_types,enabled:N.enabled};F?await Nt(F.id,y):await Jl(y),L(!1),await T(),Q("success",F?"已更新":"已创建")}catch(y){console.error("保存失败",y),Q("error",(y==null?void 0:y.message)||"保存失败")}finally{j(!1)}},B=async m=>{if(confirm(`确认删除渠道「${m.name}」吗?已绑定该渠道的账号会自动解绑。`))try{await Ql(m.id),await T(),Q("success","已删除")}catch(p){Q("error",(p==null?void 0:p.message)||"删除失败")}},R=async m=>{try{await Nt(m.id,{enabled:!m.enabled}),l(p=>p.map(y=>y.id===m.id?{...y,enabled:!y.enabled}:y))}catch(p){Q("error",(p==null?void 0:p.message)||"切换失败")}},K=async m=>{Y(m.id);try{await Yl(m.id),Q("success","测试通知已发送,请检查对应渠道")}catch(p){Q("error",(p==null?void 0:p.message)||"发送失败")}finally{Y("")}},H=cs[N.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:T,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(qe,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:A,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(Qe,{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(xs,{className:"w-5 h-5 text-[#0094f7] 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:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),c?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(Te,{className:"w-8 h-8 text-[#0094f7] animate-spin"})}):t.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(xs,{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:t.map(m=>{const p=cs[m.type]||cs.webhook,y=p.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(y,{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:m.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium",children:p.label}),!m.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:p.fields.map(S=>{var U;return(U=m.config)==null?void 0:U[S.key]}).filter(Boolean).map((S,U)=>e.jsx("span",{className:"mr-3",children:String(S).length>40?String(S).slice(0,40)+"…":String(S)},U))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",Pr(m.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>R(m),className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${m.enabled?"bg-green-50 text-green-700 hover:bg-green-100":"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:m.enabled?"启用中":"已停用"}),e.jsxs("button",{onClick:()=>K(m),disabled:G===m.id,className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-[#0094f7] hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50",children:[G===m.id?e.jsx(Te,{className:"w-3 h-3 animate-spin"}):e.jsx(Zs,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{onClick:()=>b(m),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(Ot,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>B(m),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(Je,{className:"w-4 h-4"})})]})]},m.id)})}),s&&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(Ut,{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:C.smtp_server||"",onChange:m=>M({...C,smtp_server:m.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:C.smtp_port||587,onChange:m=>M({...C,smtp_port:parseInt(m.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:C.smtp_user||"",onChange:m=>M({...C,smtp_user:m.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:xe?"text":"password",value:C.smtp_password||"",onChange:m=>M({...C,smtp_password:m.target.value}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>O(!xe),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:xe?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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:C.smtp_from_name||"",onChange:m=>M({...C,smtp_from_name:m.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:C.smtp_from_address||C.smtp_user||"",onChange:m=>M({...C,smtp_from_address:m.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:C.smtp_use_tls!==!1,onChange:m=>M({...C,smtp_use_tls:m.target.checked,smtp_use_ssl:m.target.checked?!1:C.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:C.smtp_use_ssl===!0,onChange:m=>M({...C,smtp_use_ssl:m.target.checked,smtp_use_tls:m.target.checked?!1:C.smtp_use_tls})}),"SSL/TLS 直连(常用于 465 端口)"]})]}),e.jsxs("button",{onClick:ue,disabled:oe,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[oe?e.jsx(Te,{className:"w-4 h-4 animate-spin"}):e.jsx(Ke,{className:"w-4 h-4"}),oe?"保存中...":"保存 SMTP 配置"]})]}),f&&Se.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:F?"编辑通知渠道":"新建通知渠道"}),e.jsx("button",{onClick:()=>L(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(we,{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:N.name,onChange:m=>$({...N,name:m.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(cs).map(m=>{const p=cs[m],y=p.icon,S=N.type===m;return e.jsxs("button",{type:"button",onClick:()=>$({...N,type:m,config:{}}),className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${S?"border-[#0094f7] bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(y,{className:`w-5 h-5 ${S?"text-[#0094f7]":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${S?"text-[#0094f7]":"text-gray-600"}`,children:p.label})]},m)})})]}),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(xs,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",H.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:H.guide.steps.map((m,p)=>e.jsx("li",{children:m},p))}),H.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:H.guide.urlFormat})]}),H.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",H.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:H.fields.map(m=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:[m.label,m.required&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),e.jsx("input",{type:m.type==="password"?"password":m.type==="number"?"number":"text",value:String(N.config[m.key]||""),onChange:p=>$({...N,config:{...N.config,[m.key]:p.target.value}}),placeholder:m.placeholder,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),m.help&&e.jsx("p",{className:"text-xs text-gray-500",children:m.help})]},m.key))}),N.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:N.config.use_custom_smtp===!0?"当前渠道使用一套完整、独立的发件配置。":"当前渠道完整继承系统 SMTP,只单独设置收件邮箱。"})]}),e.jsx("button",{type:"button",onClick:()=>{const m=N.config.use_custom_smtp===!0;$({...N,config:m?{...N.config,use_custom_smtp:!1}:It(N.config,C)})},className:`relative h-7 w-12 shrink-0 rounded-full transition-colors ${N.config.use_custom_smtp===!0?"bg-[#0094f7]":"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 ${N.config.use_custom_smtp===!0?"translate-x-5":""}`})})]}),N.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(N.config.smtp_server||""),onChange:m=>$({...N,config:{...N.config,smtp_server:m.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(N.config.smtp_port||587),onChange:m=>$({...N,config:{...N.config,smtp_port:m.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(N.config.smtp_user||""),onChange:m=>$({...N,config:{...N.config,smtp_user:m.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:le?"text":"password",value:String(N.config.smtp_password||""),onChange:m=>$({...N,config:{...N.config,smtp_password:m.target.value}}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>D(m=>!m),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",children:le?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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(N.config.smtp_from_name||""),onChange:m=>$({...N,config:{...N.config,smtp_from_name:m.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(N.config.smtp_from_address||""),onChange:m=>$({...N,config:{...N.config,smtp_from_address:m.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:N.config.smtp_use_tls!==!1,onChange:m=>$({...N,config:{...N.config,smtp_use_tls:m.target.checked,smtp_use_ssl:m.target.checked?!1:N.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:N.config.smtp_use_ssl===!0,onChange:m=>$({...N,config:{...N.config,smtp_use_ssl:m.target.checked,smtp_use_tls:m.target.checked?!1:N.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:sa.map(m=>{const p=N.event_types.includes(m.value);return e.jsxs("button",{type:"button",onClick:()=>{const y=p?N.event_types.filter(S=>S!==m.value):[...N.event_types,m.value];$({...N,event_types:y})},className:`text-left rounded-xl border px-3 py-2.5 transition-colors ${p?"border-[#0094f7] 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 ${p?"bg-[#0094f7] border-[#0094f7]":"border-gray-300"}`,children:p&&e.jsx(Ge,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${p?"text-[#0094f7]":"text-gray-800"}`,children:m.label})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 pl-6 leading-5",children:m.description})]},m.value)})})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("button",{type:"button",onClick:()=>$({...N,enabled:!N.enabled}),className:`relative w-11 h-6 rounded-full transition-colors ${N.enabled?"bg-[#0094f7]":"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 ${N.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:()=>L(!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:v,disabled:I,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[I?e.jsx(Te,{className:"w-4 h-4 animate-spin"}):e.jsx(Ge,{className:"w-4 h-4"}),I?"保存中...":"保存"]})]})]})}),document.body),X&&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",style:{background:X.type==="success"?"#10b981":"#ef4444",color:"white"},children:[X.type==="success"?e.jsx(Ge,{className:"w-4 h-4"}):e.jsx(we,{className:"w-4 h-4"}),X.text]})]})},ta={"/app/dashboard":"dashboard","/app/accounts":"accounts","/app/orders":"orders","/app/cards":"cards","/app/items":"items","/app/rules":"rules","/app/notifications":"notifications","/app/settings":"settings"},$t=Object.fromEntries(Object.entries(ta).map(([s,t])=>[t,s])),Rt=()=>ta[window.location.pathname]||"dashboard",Er=/Win/i.test(navigator.platform||navigator.userAgent),Fr=()=>{const[s,t]=n.useState(!1),[l,c]=n.useState(!1),[h,f]=n.useState(Rt),[L,F]=n.useState(!0),[g,I]=n.useState(!1),[j,G]=n.useState(""),[Y,X]=n.useState(""),[de,C]=n.useState(!1),[M,oe]=n.useState(""),[ee,xe]=n.useState(),O=$=>{const T=$==="settings"&&!l?"dashboard":$,J=$t[T];J&&J!==window.location.pathname&&window.history.pushState({},"",J),f(T)};n.useEffect(()=>{const $=()=>f(Rt());return window.addEventListener("popstate",$),()=>window.removeEventListener("popstate",$)},[]),n.useEffect(()=>{Gt().then(T=>{if((T==null?void 0:T.initialized)===!1){I(!0),t(!1),c(!1);return}I(!1),T!=null&&T.authenticated?(t(!0),c(T.is_admin===!0)):c(!1)}).catch(()=>{t(!1),c(!1)}).finally(()=>F(!1));const $=()=>{t(!1),c(!1)};return window.addEventListener("auth:logout",$),()=>window.removeEventListener("auth:logout",$)},[]),n.useEffect(()=>{!L&&s&&!l&&h==="settings"&&(window.history.replaceState({},"",$t.dashboard),f("dashboard"))},[L,s,l,h]);const le=async $=>{$.preventDefault(),C(!0),oe("");try{const T=await Wa({username:j,password:Y});T.success?(t(!0),c(T.is_admin===!0)):oe(T.message||"登录失败")}catch(T){const J=T instanceof Error?T.message:String(T);oe(J||"登录失败")}finally{C(!1)}},D=async()=>{try{await Va()}catch($){console.error("退出登录失败",$)}finally{t(!1),c(!1)}};if(L)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[#f5f5f7]",children:e.jsx(Te,{className:"w-8 h-8 text-[#0094f7] animate-spin"})});if(g)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-[#F4F5F7] 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-[0_20px_60px_-15px_rgba(0,0,0,0.05)] 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(Gs,{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:"为避免默认口令风险,管理员必须通过服务器本机 CLI 初始化。"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 rounded-2xl bg-gray-50 border border-gray-100",children:[e.jsx("div",{className:"text-sm font-bold text-gray-900 mb-2",children:"请在服务器上执行:"}),e.jsx("pre",{className:"text-xs bg-black text-white p-4 rounded-2xl overflow-x-auto",children:Er?'.\\xianyu-server.exe -init-admin -db data\\xianyu_data.db -admin-password "请设置密码"':"./xianyu-server -init-admin -db data/xianyu_data.db -admin-password '请设置密码'"}),e.jsx("div",{className:"text-xs text-gray-500 mt-2",children:"完成后刷新页面即可进入登录。"})]}),e.jsxs("button",{type:"button",onClick:()=>window.location.reload(),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",children:["我已初始化,刷新 ",e.jsx(Ws,{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(!s)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-[#F4F5F7] 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-[0_20px_60px_-15px_rgba(0,0,0,0.05)] 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(Gs,{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:le,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(ns,{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:$=>G($.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(Ia,{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:Y,onChange:$=>X($.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]})]}),M&&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(Vs,{className:"w-4 h-4"})," ",M]}),e.jsx("button",{type:"submit",disabled:de,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:de?e.jsx(Te,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:["立即登录 ",e.jsx(Ws,{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 N=()=>{switch(h){case"dashboard":return e.jsx(Os,{});case"accounts":return e.jsx(dr,{});case"orders":return e.jsx(ur,{});case"cards":return e.jsx(hr,{});case"items":return e.jsx(fr,{onConfigureDelivery:$=>{xe({cookieId:$.cookie_id,itemId:$.item_id,requestId:Date.now()}),O("rules")}});case"rules":return e.jsx(Ir,{initialDeliveryTarget:ee,onDeliveryTargetHandled:()=>xe(void 0)});case"notifications":return e.jsx(Tr,{isAdmin:l});case"settings":return l?e.jsx(Nr,{}):e.jsx(Os,{});default:return e.jsx(Os,{})}};return e.jsxs("div",{className:"flex min-h-screen bg-[#F4F5F7] text-[#111]",children:[e.jsx(Ma,{activeTab:h,isAdmin:l,onNavigate:O,onLogout:D}),e.jsxs("main",{className:"flex-1 ml-64 p-8 md:p-12 overflow-y-auto h-screen relative scroll-smooth",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:"max-w-[1400px] mx-auto pb-10",children:N()})]})]})},aa=document.getElementById("root");if(!aa)throw new Error("Could not find root element to mount to");const Dr=ra.createRoot(aa);Dr.render(e.jsx(na.StrictMode,{children:e.jsx(Fr,{})})); +`),w=new Blob(["\uFEFF"+u],{type:"text/csv;charset=utf-8"}),W=URL.createObjectURL(w),ae=document.createElement("a");ae.href=W,ae.download="批量铺货模板.csv",document.body.appendChild(ae),ae.click(),ae.remove(),URL.revokeObjectURL(W)},ss=()=>{re(r=>({...r,cookie_id:F||r.cookie_id})),O(!0)},Ze=()=>{i(r=>({...r,cookie_id:F||r.cookie_id})),D(!0)},Xe=r=>c.filter(a=>a.cookie_id===r.cookie_id&&a.item_id===r.item_id).length>0?c.filter(a=>a.cookie_id===r.cookie_id&&a.item_id===r.item_id):c.filter(a=>a.cookie_id===r.cookie_id&&!a.item_id),He=r=>{switch(r){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 r||"-"}},x=r=>{switch(r){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"}},P=n.useMemo(()=>new Map(f.map(r=>[r.id,r])),[f]),me=n.useMemo(()=>I?t.filter(r=>r.cookie_id===I):t,[I,t]),fe=r=>{const a=P.get(r),u=(a==null?void 0:a.remark)||(a==null?void 0:a.nickname);return u?`${u} · ${r.slice(0,6)}`:`账号 ${r.slice(0,8)}`},ze=r=>{const a=P.get(r);return(a==null?void 0:a.remark)||(a==null?void 0:a.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(Na,{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:I,onChange:r=>j(r.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.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(ns,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:F,onChange:r=>g(r.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.id))]})]})]}),e.jsxs("button",{onClick:Z,disabled:G||!F,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(qe,{className:`w-4 h-4 ${G?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:ss,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(Qe,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:Ze,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-600 text-white hover:bg-emerald-700 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Ts,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void ye(),className:"px-5 py-3 rounded-2xl font-bold bg-blue-600 text-white hover:bg-blue-700 transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(_s,{className:"w-4 h-4"}),H&&["running","canceling"].includes(H.status)?"继续批量任务":"批量铺货"]}),H&&!["running","canceling"].includes(H.status)&&e.jsx("button",{onClick:()=>void Ae(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[me.map(r=>{const a=Xe(r),u=a.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:()=>pe(r),className:"p-1.5 bg-white/90 backdrop-blur rounded-lg shadow-md text-gray-600 hover:bg-[#0094f7] hover:text-white transition-colors",title:"编辑",children:e.jsx(us,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>ce(r),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(Je,{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:[r.item_image?e.jsx("img",{src:r.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(Et,{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:br(r.item_price)})]}),e.jsx("h3",{className:"font-bold text-gray-900 line-clamp-2 text-xs mb-1.5 h-8 leading-4",children:r.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:ze(r.cookie_id),children:[e.jsx(ns,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:ze(r.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: ",r.item_id]}),e.jsxs("span",{className:`inline-flex items-center gap-1 font-bold ${u?"text-emerald-600":"text-amber-600"}`,children:[u?e.jsx(Bt,{className:"w-3 h-3"}):e.jsx(va,{className:"w-3 h-3"}),u?`${a.length} 规则`:"未配置"]})]}),e.jsx("div",{className:"space-y-2 mt-auto",children:e.jsxs("button",{onClick:()=>s(r),className:`w-full flex items-center justify-between gap-1 px-2.5 py-2 rounded-lg text-[11px] font-extrabold transition-all ${u?"bg-gray-900 text-white hover:bg-black":"bg-[#0094f7] text-white hover:bg-[#0071e3] shadow-md shadow-blue-100"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_a,{className:"w-3.5 h-3.5"}),u?"查看发货规则":"关联发货规则"]}),e.jsx(Ws,{className:"w-3.5 h-3.5"})]})})]},`${r.cookie_id}-${r.item_id}`)}),me.length===0&&e.jsxs("div",{className:"col-span-full py-20 text-center text-gray-400",children:[e.jsx(Tt,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),I?"该账号暂无商品数据":"暂无商品数据,请选择账号进行同步"]})]}),oe&&y&&Se.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: ",y.item_id]})]}),e.jsx("button",{onClick:()=>ee(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(we,{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:U.item_title||"",onChange:r=>se({...U,item_title:r.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"价格",value:U.item_price||"",onChange:r=>se({...U,item_price:r.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"分类",value:U.item_category||"",onChange:r=>se({...U,item_category:r.target.value})}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述",value:U.item_description||"",onChange:r=>se({...U,item_description:r.target.value})})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:Ne,className:"w-full ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4"}),"保存"]})})]})}),document.body),xe&&Se.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:()=>O(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(we,{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:z.cookie_id,onChange:r=>re({...z,cookie_id:r.target.value}),children:[e.jsx("option",{value:"",children:"选择账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.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:z.item_id,onChange:r=>re({...z,item_id:r.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:z.item_price,onChange:r=>re({...z,item_price:r.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:z.item_title,onChange:r=>re({...z,item_title:r.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:z.item_image,onChange:r=>re({...z,item_image:r.target.value})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:_e,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(Qe,{className:"w-4 h-4"}),"添加商品"]})})]})}),document.body),le&&Se.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:()=>D(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(we,{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:E.cookie_id,onChange:r=>i({...E,cookie_id:r.target.value}),children:[e.jsx("option",{value:"",children:"选择账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.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:E.title,onChange:r=>i({...E,title:r.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:E.quantity,onChange:r=>i({...E,quantity:r.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:E.description,onChange:r=>i({...E,description:r.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:E.price,onChange:r=>i({...E,price:r.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:E.original_price,onChange:r=>i({...E,original_price:r.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:E.postage_mode,onChange:r=>i({...E,postage_mode:r.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:"无需邮寄"})]})]})]}),E.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:E.postage,onChange:r=>i({...E,postage:r.target.value})})]}),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(_s,{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:E.images.length?"已选择 "+E.images.length+" 张":"支持 JPG / PNG / GIF"}),e.jsx("input",{className:"hidden",type:"file",accept:"image/*",multiple:!0,onChange:r=>i({...E,images:Array.from(r.target.files||[]).slice(0,9)})})]}),q.length>0&&e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-3",children:q.map(r=>e.jsx("div",{className:"aspect-square rounded-xl bg-gray-100 overflow-hidden border border-gray-100",children:e.jsx("img",{src:r.url,alt:"",className:"w-full h-full object-cover"})},r.key))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{disabled:X,onClick:Re,className:"w-full bg-emerald-600 hover:bg-emerald-700 disabled:opacity-60 text-white px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ts,{className:"w-4 h-4"}),X?"正在发布...":"发布到闲鱼"]})})]})}),document.body),N&&Se.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 We(),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(we,{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(([r,a])=>e.jsx("div",{className:`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${T===r?"bg-blue-600 text-white border-blue-600":"bg-gray-50 text-gray-500 border-gray-100"}`,children:a},r))}),T==="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:$e,className:"shrink-0 rounded-xl bg-blue-600 px-4 py-2 text-sm font-extrabold text-white hover:bg-blue-700",children:"下载CSV模板"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"默认发布账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:F,onChange:r=>g(r.target.value),children:[e.jsx("option",{value:"",children:"选择账号"}),f.map(r=>e.jsx("option",{value:r.id,children:fe(r.id)},r.id))]}),e.jsx("p",{className:"text-xs text-gray-500",children:"表格中“账号ID”为空时,会使用这里选择的账号。"})]}),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(_s,{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:ue?ue.name:"支持 .xlsx / .csv / .tsv"}),e.jsx("input",{className:"hidden",type:"file",accept:".xlsx,.csv,.tsv",onChange:r=>{var a;return Q(((a=r.target.files)==null?void 0:a[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(_s,{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:A?A.name:"表格图片字段使用 zip 内相对路径"}),e.jsx("input",{className:"hidden",type:"file",accept:".zip",onChange:r=>{var a;return b(((a=r.target.files)==null?void 0:a[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,按上方示例填写"],["评价赠品启用","需要评价赠品时填写","填“是”表示开启;不需要时填“否”或留空"],["评价赠品内容","“评价赠品启用”填“是”时填写","格式和付款发货内容相同,也可以同时发送多个卡密组"],["求评价启用","需要自动求评价时填写","填“是”表示开启;不需要时填“否”或留空"],["求评价等待小时","“求评价启用”填“是”时填写","填写等待小时数;留空按 72 小时处理"],["求评价文案","“求评价启用”填“是”时填写","填写要发送给买家的求评价消息"],["求评价最多次数","可以留空","留空只提醒 1 次"]].map(([r,a,u])=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-bold text-gray-900 whitespace-nowrap",children:r}),e.jsx("td",{className:`px-3 py-2 min-w-[210px] font-bold ${a==="每个商品都要填"?"text-red-600":a==="可以留空"?"text-gray-500":"text-amber-700"}`,children:a}),e.jsx("td",{className:"px-3 py-2 min-w-[260px]",children:u})]},r))})]})})]})]}),T==="preview"&&v&&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:v.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:v.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:v.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("tbody",{className:"divide-y divide-gray-50",children:v.rows.map(r=>{var a,u;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:r.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 ${r.valid?"bg-emerald-50 text-emerald-700 border-emerald-100":"bg-red-50 text-red-700 border-red-100"}`,children:r.valid?"可发布":"需修正"})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[240px] truncate",children:r.title||"-"}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:["¥",r.price||"-"," / ",r.quantity||1]}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:[((a=r.images)==null?void 0:a.length)||0," 张"]}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[280px]",children:((u=r.errors)==null?void 0:u.join(";"))||"-"})]},r.row_no)})})]})})]}),(T==="running"||T==="done")&&R&&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 ${x(R.status)}`,children:[e.jsx("div",{className:"text-xs font-bold opacity-70",children:"任务状态"}),e.jsx("div",{className:"text-xl font-extrabold mt-1",children:He(R.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:R.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:R.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:R.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:R.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:"商品ID"}),e.jsx("th",{className:"px-4 py-3",children:"错误原因"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:R.rows.map(r=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:r.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 ${x(r.status)}`,children:He(r.status)})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[260px] truncate",children:r.title}),e.jsx("td",{className:"px-4 py-3 text-xs font-mono",children:r.item_url?e.jsx("a",{href:r.item_url,target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline",children:r.item_id}):r.item_id||"-"}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[340px]",children:r.error_message||"-"})]},r.id))})]})})]})]}),e.jsxs("div",{className:"modal-footer",children:[T==="upload"&&e.jsxs("button",{disabled:C||!ue||!F,onClick:Le,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(qe,{className:`w-4 h-4 ${C?"animate-spin":""}`}),C?"正在预检...":"开始预检"]}),T==="preview"&&v&&e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{disabled:C,onClick:()=>void Me(),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:C||v.valid<=0,onClick:Be,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(Ts,{className:"w-4 h-4"}),C?"启动中...":`确认发布 ${v.valid} 个商品`]})]}),(T==="running"||T==="done")&&R&&e.jsxs("div",{className:"flex gap-3 w-full",children:[R.status==="running"?e.jsx("button",{disabled:C,onClick:Ie,className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"取消任务"}):R.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/${R.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:"下载结果"}),R.retryable>0&&!["running","canceling"].includes(R.status)&&e.jsxs("button",{disabled:C,onClick:Ye,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(qe,{className:`w-4 h-4 ${C?"animate-spin":""}`}),"重试失败项"]}),!["running","canceling"].includes(R.status)&&e.jsx("button",{onClick:()=>{$(!1),_(),te()},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)]})},Ct="https://dashscope.aliyuncs.com/compatible-mode/v1",yr=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],jr=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"]),Nr=()=>{const[s,t]=n.useState(null),[l,c]=n.useState(!1),[h,f]=n.useState(""),[L,F]=n.useState(!1),[g,I]=n.useState([]),[j,G]=n.useState(!1),[Y,X]=n.useState(""),[de,C]=n.useState(!1),M=n.useRef(null),[oe,ee]=n.useState(!1),[xe,O]=n.useState(!1),[le,D]=n.useState(!1),[N,$]=n.useState(!1),[T,J]=n.useState(!1),[ue,Q]=n.useState(null),[A,b]=n.useState({new_username:"",current_password:"",new_password:"",confirm_password:""});n.useEffect(()=>{B(),Gt().then(p=>{p.username&&b(y=>({...y,new_username:p.username||""}))}).catch(()=>{})},[]),n.useEffect(()=>{const p=y=>{var S;(S=M.current)!=null&&S.contains(y.target)||C(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[]);const v=async(p,y=!1)=>{const S=p||s,U=(S==null?void 0:S.ai_api_url)||(S==null?void 0:S.ai_base_url)||Ct;G(!0),X("");try{const se=await Vl(U,(S==null?void 0:S.ai_api_key)||"");I(se),C(y&&se.length>0),!(S!=null&&S.ai_model)&&se.length>0&&t(z=>z&&{...z,ai_model:se[0]})}catch(se){I([]),C(!1),X(se.message||"读取模型失败")}finally{G(!1)}},B=()=>{c(!0),f(""),Kt().then(p=>{t(p),v(p)}).catch(p=>{t(null),f(p.message||"加载配置失败")}).finally(()=>c(!1))},R=async()=>{if(s){F(!0);try{const p=Object.fromEntries(Object.entries(s).filter(([y,S])=>!jr.has(y)&&S!==void 0&&S!==null));await Yt(p),alert("系统配置已保存")}catch(p){alert("保存失败:"+p.message)}finally{F(!1)}}},K=async p=>{p.preventDefault(),Q(null);const y=A.new_username.trim();if(y.length<3){Q({type:"error",text:"用户名至少需要 3 个字符"});return}if(!A.current_password){Q({type:"error",text:"请输入当前密码确认身份"});return}if(A.new_password&&A.new_password.length<8){Q({type:"error",text:"新密码至少需要 8 个字符"});return}if(A.new_password!==A.confirm_password){Q({type:"error",text:"两次输入的新密码不一致"});return}J(!0);try{const S=await Ga({current_password:A.current_password,new_username:y,new_password:A.new_password||void 0});if(!S.success){Q({type:"error",text:S.message||"登录凭据更新失败"});return}Q({type:"success",text:S.message||"登录凭据已更新"}),window.setTimeout(()=>window.location.reload(),1400)}catch(S){Q({type:"error",text:S.message||"登录凭据更新失败"})}finally{J(!1)}};if(!s)return e.jsx("div",{className:"p-8 text-center text-gray-400",children:h||(l?"加载配置中...":"暂无配置")});const H=s.ai_model||"",m=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(Ys,{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:B,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(qe,{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(wa,{className:"w-4 h-4"})}),"基础设置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出等级"}),e.jsx("select",{value:s.log_level||"info",onChange:p=>t({...s,log_level:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:yr.map(p=>e.jsx("option",{value:p.value,children:p.label},p.value))}),e.jsx("p",{className:"text-xs text-gray-500",children:"等级越低输出越详细,Debug 适合排查问题"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出格式"}),e.jsxs("select",{value:s.log_format||"text",onChange:p=>t({...s,log_format:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"JSON 适合接入集中式日志系统,保存后需重启服务生效"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"续期日志保留天数"}),e.jsx("input",{type:"number",value:s.renewal_log_retention_days??10,onChange:p=>t({...s,renewal_log_retention_days:parseInt(p.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-[#0094f7] text-white",children:e.jsx(Ft,{className:"w-4 h-4"})}),"AI 智能回复配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API 地址"}),e.jsx("input",{type:"text",value:s.ai_api_url||Ct,onChange:p=>t({...s,ai_api_url:p.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:oe?"text":"password",value:s.ai_api_key||"",onChange:p=>t({...s,ai_api_key:p.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:()=>ee(!oe),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:oe?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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:M,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:H,onFocus:()=>g.length>0&&C(!0),onChange:p=>{t({...s,ai_model:p.target.value}),g.length>0&&C(!0)},onKeyDown:p=>{p.key==="Escape"&&C(!1),p.key==="ArrowDown"&&g.length>0&&C(!0)},className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:()=>g.length>0&&C(p=>!p),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(ka,{className:`w-4 h-4 transition-transform ${de?"rotate-180":""}`})}),de&&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:m.length>0?m.map(p=>e.jsxs("button",{type:"button",onClick:()=>{t({...s,ai_model:p}),C(!1)},className:"w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-[#0094f7] flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:p}),p===H&&e.jsx(Ge,{className:"w-4 h-4 shrink-0 text-[#0094f7]"})]},p)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:()=>v(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(qe,{className:`w-4 h-4 ${j?"animate-spin":""}`}),"读取模型"]})]}),Y?e.jsx("p",{className:"text-xs text-red-500",children:Y}):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(Vs,{className:"w-4 h-4"})}),"远程过滑块配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务地址"}),e.jsx("input",{type:"url",value:s["captcha.remote_service_url"]||"",onChange:p=>t({...s,"captcha.remote_service_url":p.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:xe?"text":"password",value:s["captcha.remote_secret_key"]||"",onChange:p=>t({...s,"captcha.remote_secret_key":p.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:()=>O(!xe),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:xe?"隐藏秘钥":"显示秘钥",children:xe?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{className:"w-4 h-4"})})]})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl bg-amber-50 p-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:String(s["captcha.remote_pass_cookies"]||"").toLowerCase()==="true",onChange:p=>t({...s,"captcha.remote_pass_cookies":p.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(xt,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:K,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(Ca,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:A.new_username,onChange:p=>b({...A,new_username:p.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:le?"text":"password",value:A.current_password,onChange:p=>b({...A,current_password:p.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:()=>D(!le),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:le?"隐藏密码":"显示密码",children:le?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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:N?"text":"password",value:A.new_password,onChange:p=>b({...A,new_password:p.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:()=>$(!N),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:N?"隐藏密码":"显示密码",children:N?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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:N?"text":"password",value:A.confirm_password,onChange:p=>b({...A,confirm_password:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),ue&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${ue.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(Vs,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:ue.text})]}),e.jsxs("button",{type:"submit",disabled:T||!A.new_username||!A.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(xt,{className:"w-4 h-4"}),T?"正在更新...":"更新登录凭据"]})]})]})]})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:R,disabled:L,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(Ke,{className:"w-6 h-6"}),L?"保存中...":"保存所有配置"]})})]})},qs=(s,t)=>s.allowed_resolutions.includes(t),vr=(s,t)=>({runs:s.runs.filter(l=>!t||l.cookie_id===t),pending_tasks:s.pending_tasks.filter(l=>!t||l.cookie_id===t)}),_r=s=>({external_result_unknown:"外部动作结果未知",invalid_snapshot:"历史数据无法恢复",rule_unavailable:"规则不可用",partial_failure:"部分动作失败",execution_failed:"动作执行失败"})[s]||"自动化异常",wr=async s=>{const t=s.loadIssues().then(s.onIssues).catch(s.onIssuesError),l=await s.loadRules();s.onRules(l),await t},kr=(s,t,l,c,h,f)=>s!==t||l!==c?!1:(f(h),!0),ls={order_paid:{label:"付款后自动发货",shortLabel:"自动发货",description:"闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。",flow:["付款系统卡片","匹配商品/规格","发送卡密","确认发货"],accent:"blue",icon:Ns},buyer_reviewed:{label:"评价后发送赠品",shortLabel:"评价赠品",description:"闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。",flow:["评价系统卡片","匹配商品/规格","发送赠品"],accent:"emerald",icon:Sa},review_missing_timeout:{label:"超时未评价求评价",shortLabel:"求评价",description:"计划任务扫描已发货未评价订单,到期后发送求评价文案。",flow:["计划任务扫描","已发货未评价","达到等待时间","发送提醒"],accent:"amber",icon:zt}},Bs=["order_paid","buyer_reviewed","review_missing_timeout"],Cr="亲,商品使用满意的话,麻烦给个评价,谢谢~",bs=()=>({spec_name:"",spec_value:"",card_id:0,delivery_count:1,enabled:!0,delay_override:!1,delay_seconds:0}),Ht=s=>{if(!s)return{};try{const t=JSON.parse(s);return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}catch{return{}}},as=(s,t={})=>{const l=Ht(s);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),...t})},fs=(s,t)=>{var c;const l=((c=ls[s])==null?void 0:c.label)||"自动化规则";return t?`${l} - ${t}`:l},St=s=>{const t=(s||"").trim();return t?Object.values(ls).some(l=>t===l.label||t.startsWith(`${l.label} -`)):!0},ys=(s,t=0)=>{if(s==="review_missing_timeout")return[{action_type:"send_text",message_template:Cr,enabled:!0,sort_order:1}];const l={action_type:"send_card",card_id:t,delivery_count:1,enabled:!0,sort_order:1};return s==="order_paid"?[l,{action_type:"confirm_shipment",enabled:!0,sort_order:2}]:[l]},Sr=s=>{var l,c;if(s.trigger_type==="review_missing_timeout")return((c=(l=s.actions)==null?void 0:l.find(h=>h.action_type==="send_text"))==null?void 0:c.message_template)||"发送求评价文案";const t=(s.actions||[]).filter(h=>h.action_type==="send_card");return t.length?t.map(h=>h.card_name||`卡密 ${h.card_id}`).join(" / "):"未配置卡密库存"},Lt=(s,t=!1)=>{const l={blue:t?"border-blue-500 bg-blue-50 text-blue-700":"border-blue-100 bg-blue-50/60 text-blue-700 hover:border-blue-300",emerald:t?"border-emerald-500 bg-emerald-50 text-emerald-700":"border-emerald-100 bg-emerald-50/60 text-emerald-700 hover:border-emerald-300",amber:t?"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[s]||l.blue},Lr=s=>s?"bg-emerald-100 text-emerald-700":"bg-gray-200 text-gray-500",Ss=s=>(s==null?void 0:s.nickname)||(s==null?void 0:s.remark)||(s==null?void 0:s.id)||"未知账号",Ar=s=>s===!0||s===1||s==="1",Ir=({initialDeliveryTarget:s,onDeliveryTargetHandled:t})=>{var fe,ze,r;const[l,c]=n.useState("automation"),[h,f]=n.useState([]),[L,F]=n.useState({runs:[],pending_tasks:[]}),[g,I]=n.useState([]),[j,G]=n.useState({}),[Y,X]=n.useState([]),[de,C]=n.useState([]),[M,oe]=n.useState([]),[ee,xe]=n.useState(!1),[O,le]=n.useState(""),D=n.useRef(0),N=n.useRef("");N.current=O;const[$,T]=n.useState(!1),[J,ue]=n.useState(!1),[Q,A]=n.useState(!1),[b,v]=n.useState(null),[B,R]=n.useState(null),[K,H]=n.useState({cookie_id:"",enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""});Y.find(a=>a.id===O);const m=n.useCallback(async()=>{const[a,u,w,W]=await Promise.all([Rs(),Ve(),ps(),vt()]);X(a),C(u),oe(w),G(W),le(ae=>{var ve;return ae||((ve=a[0])==null?void 0:ve.id)||""})},[]),p=n.useCallback(async()=>{await wr({loadRules:Is,loadIssues:El,onRules:f,onIssues:F,onIssuesError:a=>console.warn("加载自动化异常列表失败,不阻断规则展示",a)})},[]),y=n.useCallback(async()=>{const a=O;if(a!==N.current)return;const u=++D.current;if(I([]),!a)return;const w=await ql(a);kr(u,D.current,a,N.current,w,I)},[O]),S=n.useCallback(async()=>{G(await vt())},[]),U=n.useCallback(async()=>{xe(!0);try{l==="automation"?await p():l==="reply"?await y():await S()}finally{xe(!1)}},[l,p,S,y]);n.useEffect(()=>{m().catch(a=>console.error("加载规则参考数据失败",a))},[m]),n.useEffect(()=>{U().catch(a=>console.error("刷新规则页面失败",a))},[U]);const se=n.useMemo(()=>h.filter(a=>!O||a.cookie_id===O),[h,O]),z=n.useMemo(()=>vr(L,O),[L,O]),re=n.useMemo(()=>Y.filter(a=>!O||a.id===O),[Y,O]),E=n.useMemo(()=>{var u;const a={order_paid:[],buyer_reviewed:[],review_missing_timeout:[]};for(const w of se)(u=a[w.trigger_type])==null||u.push(w);return a},[se]),i=n.useMemo(()=>{const a=(b==null?void 0:b.cookie_id)||O;return M.filter(u=>u.cookie_id===a)},[b==null?void 0:b.cookie_id,M,O]),q=n.useMemo(()=>{if(!(!(b!=null&&b.cookie_id)||!(b!=null&&b.item_id)))return M.find(a=>a.cookie_id===b.cookie_id&&a.item_id===b.item_id)},[b==null?void 0:b.cookie_id,b==null?void 0:b.item_id,M]),d=Ar(q==null?void 0:q.is_multi_spec),_=(b==null?void 0:b.trigger_type)||"order_paid",te=ls[_],Z=Ht(b==null?void 0:b.config_json),pe=n.useCallback((a="order_paid",u=O,w="")=>{const W=M.find(ve=>ve.cookie_id===u&&ve.item_id===w),ae=(W==null?void 0:W.item_title)||w;return{name:fs(a,ae),trigger_type:a,cookie_id:u,item_id:w,item_title:(W==null?void 0:W.item_title)||"",item_keyword:ae,card_group_id:0,priority:100,enabled:!0,config_json:a==="review_missing_timeout"?as():"{}",actions:ys(a),variants:a==="review_missing_timeout"?[]:[bs()]}},[M,O]),Ne=n.useCallback(a=>{var w,W;const u=a.trigger_type||"order_paid";v({...a,trigger_type:u,config_json:u==="review_missing_timeout"?as(a.config_json):a.config_json||"{}",actions:(w=a.actions)!=null&&w.length?a.actions.map(ae=>({...ae})):ys(u,a.card_group_id),variants:(W=a.variants)!=null&&W.length?a.variants.map(ae=>({...ae})):u==="review_missing_timeout"?[]:[bs()]}),T(!0)},[]);n.useEffect(()=>{if(!s)return;let a=!1;return(async()=>{c("automation"),le(s.cookieId),xe(!0);try{const[w,W,ae]=await Promise.all([Is(),ps(),Ve().catch(he=>(console.warn("加载卡密库存失败,不阻断打开自动化规则",he),[]))]);if(a)return;f(w),oe(W),C(ae);const ve=w.find(he=>he.cookie_id===s.cookieId&&he.item_id===s.itemId&&he.trigger_type==="order_paid");if(ve)Ne(ve);else{const he=W.find(De=>De.cookie_id===s.cookieId&&De.item_id===s.itemId);v({...pe("order_paid",s.cookieId,s.itemId),item_title:(he==null?void 0:he.item_title)||"",item_keyword:(he==null?void 0:he.item_title)||s.itemId,name:fs("order_paid",(he==null?void 0:he.item_title)||s.itemId)}),T(!0)}}catch(w){console.error("打开商品自动化规则失败",w),alert("无法加载该商品的自动化规则")}finally{a||(xe(!1),t==null||t())}})(),()=>{a=!0}},[pe,s,t,Ne]);const ce=(a="order_paid")=>{if(!O){alert("请先选择账号");return}v(pe(a)),T(!0)},_e=a=>{var W,ae,ve,he,De;if(!b)return;const u=((ae=(W=b.variants)==null?void 0:W.find(je=>je.card_id))==null?void 0:ae.card_id)||((he=(ve=b.actions)==null?void 0:ve.find(je=>je.action_type==="send_card"))==null?void 0:he.card_id)||b.card_group_id||0,w=(q==null?void 0:q.item_title)||b.item_title||b.item_id||"";v({...b,trigger_type:a,name:St(b.name)?fs(a,w):b.name,card_group_id:u,config_json:a==="review_missing_timeout"?as(b.config_json):"{}",actions:ys(a,u),variants:a==="review_missing_timeout"?[]:(De=b.variants)!=null&&De.length?b.variants:[{...bs(),card_id:u}]})},Re=a=>{if(!b)return;const u=M.find(W=>W.cookie_id===(b.cookie_id||O)&&W.item_id===a),w=(u==null?void 0:u.item_title)||a;v({...b,item_id:a,item_title:(u==null?void 0:u.item_title)||"",item_keyword:w,name:St(b.name)?fs(_,w):b.name})},ye=(fe=b==null?void 0:b.variants)!=null&&fe.length?b.variants:[bs()],Ae=(a,u)=>{var W;if(!b)return;const w=ye.map((ae,ve)=>ve===a?{...ae,...u}:ae);v({...b,variants:w,card_group_id:((W=w[0])==null?void 0:W.card_id)||0})},Le=()=>{if(!b)return;const a=ye[ye.length-1];v({...b,variants:[...ye,{...bs(),spec_name:d&&(a==null?void 0:a.spec_name)||"",spec_value:d&&(a==null?void 0:a.spec_value)||""}]})},Be=async()=>{var W,ae,ve,he,De;if(!b)return;const a=b.trigger_type||"order_paid";if(!b.cookie_id){alert("请选择账号");return}const u=(W=b.variants)!=null&&W.length?b.variants:[];if(a!=="review_missing_timeout"){if(!u.length||u.some(je=>!je.card_id)){alert(a==="buyer_reviewed"?"请选择评价赠品卡密库存":"请选择发货卡密库存");return}if(d&&u.some(je=>!je.spec_name.trim()||!je.spec_value.trim())){alert("多规格商品必须填写每一行的规格名称和规格值");return}}if(a==="review_missing_timeout"&&!(((ve=(ae=b.actions)==null?void 0:ae.find(o=>o.action_type==="send_text"))==null?void 0:ve.message_template)||"").trim()){alert("请填写求评价文案");return}const w=a==="review_missing_timeout"?[]:u.map(je=>({...je,spec_name:d?je.spec_name.trim():"",spec_value:d?je.spec_value.trim():"",delivery_count:Math.max(1,Number(je.delivery_count)||1),enabled:je.enabled!==!1}));try{await jt({...b,trigger_type:a,name:(b.name||"").trim()||fs(a,(q==null?void 0:q.item_title)||b.item_id||""),config_json:a==="review_missing_timeout"?as(b.config_json):b.config_json||"{}",actions:(he=b.actions)!=null&&he.length?b.actions:ys(a,((De=w[0])==null?void 0:De.card_id)||b.card_group_id||0),variants:w}),T(!1),await Promise.all([p(),m()]),alert("保存成功")}catch(je){console.error("保存自动化规则失败:",je),alert("保存失败:"+je.message)}},Ie=async a=>{if(confirm("确定删除该自动化规则吗?"))try{await Tl(a),await p(),alert("删除成功")}catch(u){alert("删除失败:"+u.message)}},Me=async a=>{try{await jt({...a,enabled:!a.enabled}),await p()}catch(u){alert("操作失败:"+u.message)}},We=async(a,u)=>{if(confirm(u==="continue"?"确认外部动作已经执行成功,并跳到下一步吗?":u==="retry"?"确认外部动作没有执行,可以安全重试吗?错误判断可能造成重复发送。":"确认终止该自动化运行吗?"))try{await Fl(a,u),await p()}catch(W){alert("处理失败:"+W.message)}},Ye=async(a,u)=>{if(confirm(u==="retry"?"确认重新执行该任务吗?":"确认忽略并删除该异常任务吗?"))try{await Dl(a,u),await p()}catch(w){alert("处理失败:"+w.message)}},$e=()=>{if(!O){alert("请先选择账号");return}R({keyword:"",reply_content:"",image_url:"",item_id:"",type:"text",match_type:"fuzzy",enabled:!0}),ue(!0)},ss=async()=>{var u,w,W;if(!B||!O)return;const a=B.type==="image"?!!((u=B.image_url)!=null&&u.trim()):!!((w=B.reply_content)!=null&&w.trim());if(!((W=B.keyword)!=null&&W.trim())||!a){alert("请填写关键词和回复内容");return}try{await Bl({...B,match_type:"fuzzy",enabled:!0},O),ue(!1),await y(),alert("保存成功")}catch(ae){alert("保存失败:"+ae.message)}},Ze=async a=>{if(!(!O||!confirm("确定删除该回复规则吗?")))try{await zl(a,O),await y(),alert("删除成功")}catch(u){alert("删除失败:"+u.message)}},Xe=async(a=O)=>{if(!a){alert("请先选择账号");return}try{const u=await Zl(a);H({cookie_id:a,enabled:u.enabled,reply_content:u.reply_content,reply_once:u.reply_once,reply_image_url:u.reply_image_url||""})}catch{H({cookie_id:a,enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""})}A(!0)},He=async()=>{if(!K.cookie_id){alert("请先选择账号");return}if(K.enabled&&!K.reply_content.trim()&&!K.reply_image_url.trim()){alert("启用默认回复时,请填写回复内容或图片 URL");return}try{await Xl(K.cookie_id,{enabled:K.enabled,reply_content:K.reply_content,reply_once:K.reply_once,reply_image_url:K.reply_image_url}),A(!1),await S(),alert("保存成功")}catch(a){alert("保存失败:"+a.message)}},x=async a=>{if(confirm("确定删除该账号默认回复吗?"))try{await Hl(a),await S(),alert("删除成功")}catch(u){alert("删除失败:"+u.message)}},P=async a=>{if(confirm("确定清空该账号的默认回复记录吗?清空后可重新对所有会话使用“只回复一次”。"))try{await er(a),alert("清空成功")}catch(u){alert("清空失败:"+u.message)}},me=l==="automation"?"新建自动化":l==="reply"?"新增关键词":"编辑默认回复";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:"系统通知卡片只进入自动化判断;买家消息进入关键词、默认或 AI 回复。"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("select",{value:O,onChange:a=>le(a.target.value),className:"ios-input px-4 py-3 rounded-2xl text-sm min-w-64",children:[e.jsx("option",{value:"",children:"全部账号"}),Y.map(a=>e.jsx("option",{value:a.id,children:Ss(a)},a.id))]}),e.jsxs("button",{onClick:U,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 transition-colors",children:[e.jsx(qe,{className:`w-4 h-4 ${ee?"animate-spin":""}`}),"刷新"]}),e.jsxs("button",{onClick:l==="automation"?()=>ce("order_paid"):l==="reply"?$e:()=>void Xe(),disabled:!O,className:"ios-btn-primary px-5 py-3 rounded-2xl text-sm font-extrabold flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(Qe,{className:"w-4 h-4"}),me]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[{id:"automation",label:"交易自动化",icon:Us},{id:"reply",label:"关键词回复",icon:Ls},{id:"default",label:"账号默认回复",icon:ds}].map(a=>{const u=a.icon;return e.jsxs("button",{onClick:()=>c(a.id),className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${l===a.id?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:[e.jsx(u,{className:"w-4 h-4"}),a.label]},a.id)})}),l==="automation"&&(z.runs.length>0||z.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(ms,{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:[z.runs.map(a=>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:["账号 ",a.cookie_id," · 订单 ",a.order_id||"-"," · 已记录发送 ",a.sent_count," 条"]}),e.jsx("div",{className:"text-xs font-bold text-red-800 mt-1",children:_r(a.issue_kind)}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:a.error_message})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 shrink-0",children:[qs(a,"continue")&&e.jsx("button",{onClick:()=>void We(a.id,"continue"),className:"px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold",children:"已执行,继续下一步"}),qs(a,"retry")&&e.jsx("button",{onClick:()=>void We(a.id,"retry"),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"未执行,安全重试"}),qs(a,"cancel")&&e.jsx("button",{onClick:()=>void We(a.id,"cancel"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"终止"})]})]},`run-${a.id}`)),z.pending_tasks.map(a=>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:["账号 ",a.cookie_id," · 延迟任务重试已达 ",a.attempt_count," 次"]}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:a.error_message})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>void Ye(a.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 Ye(a.id,"dismiss"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"忽略"})]})]},`task-${a.id}`))]})]}),l==="automation"&&e.jsxs("div",{className:"grid grid-cols-1 2xl:grid-cols-[360px_1fr] gap-6",children:[e.jsxs("aside",{className:"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:Bs.map(a=>{const u=ls[a],w=u.icon;return e.jsx("button",{type:"button",onClick:()=>ce(a),className:`w-full text-left rounded-2xl border p-4 transition-colors ${Lt(u.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(w,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:u.label}),e.jsx("div",{className:"text-xs opacity-75 mt-1 leading-5",children:u.description})]})]})},a)})})]}),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-4",children:"规则概览"}),e.jsx("div",{className:"space-y-3",children:Bs.map(a=>{const u=ls[a],w=u.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(w,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:u.shortLabel})]}),e.jsx("span",{className:"text-sm font-black text-gray-900",children:E[a].length})]},a)})})]})]}),e.jsx("section",{className:"space-y-4",children:se.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-dashed border-gray-200 p-16 text-center",children:[e.jsx(Us,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-black text-gray-900",children:"还没有自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2",children:"从左侧选择一个模板开始配置。"})]}):se.map(a=>{const u=ls[a.trigger_type],w=u.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 ${Lt(u.accent,!0)}`,children:e.jsx(w,{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:a.name}),e.jsx("span",{className:`px-2.5 py-1 rounded-full text-xs font-bold ${Lr(a.enabled)}`,children:a.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:u.label}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:a.item_title||a.item_id||"账号级规则"}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-blue-50 text-blue-700",children:Sr(a)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>Ne(a),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(us,{className:"w-4 h-4"}),"编辑"]}),e.jsx("button",{onClick:()=>Me(a),className:`px-4 py-2 rounded-xl text-sm font-bold ${a.enabled?"bg-amber-50 text-amber-700 hover:bg-amber-100":"bg-emerald-50 text-emerald-700 hover:bg-emerald-100"}`,children:a.enabled?"禁用":"启用"}),e.jsx("button",{onClick:()=>Ie(a.id),className:"p-2.5 rounded-xl text-red-500 hover:bg-red-50",title:"删除",children:e.jsx(Je,{className:"w-4 h-4"})})]})]})},a.id)})})]}),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(ms,{className:"w-4 h-4"}),"这里只处理买家用户消息;系统通知不会进入关键词或 AI 回复。"]}),e.jsxs("div",{className:"space-y-3",children:[g.map(a=>e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border border-gray-100 bg-[#F7F8FA] 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:["“",a.keyword,"”"]})]}),e.jsx("div",{className:"bg-white p-3 rounded-xl border border-gray-100 text-sm text-gray-600 leading-relaxed",children:a.type==="image"&&a.image_url?a.image_url:a.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:()=>{R({...a}),ue(!0)},className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(us,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>Ze(a.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Je,{className:"w-5 h-5"})})]})]},a.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(ms,{className:"w-4 h-4"}),"默认回复只处理买家用户消息;关键词未命中且 AI 未接管时才会使用。"]}),e.jsxs("div",{className:"space-y-3",children:[re.map(a=>{const u=j[a.id],w=!!(u!=null&&u.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 ${w?"border-purple-100 bg-purple-50/50 hover:bg-white hover:shadow-lg":"border-gray-100 bg-[#F7F8FA] 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 ${w?"bg-purple-600 text-white":"bg-gray-200 text-gray-400"}`,children:e.jsx(ds,{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:Ss(a)}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-xs font-bold ${w?"bg-green-100 text-green-700":"bg-gray-200 text-gray-500"}`,children:w?"已启用":"未启用"}),(u==null?void 0:u.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:w?u.reply_content||u.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 Xe(a.id),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(us,{className:"w-4 h-4"})}),w&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>void P(a.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 x(a.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Je,{className:"w-5 h-5"})})]})]})]},a.id)}),re.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无账号"})]})]}),$&&b&&Se.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:b.id?"编辑自动化规则":"新建自动化规则"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:te.description})]}),e.jsx("button",{onClick:()=>T(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",title:"关闭",children:e.jsx(we,{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:Bs.map(a=>{const u=ls[a],w=u.icon,W=_===a;return e.jsx("button",{type:"button",onClick:()=>_e(a),className:`w-full rounded-2xl p-4 text-left border transition-all ${W?"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(w,{className:`w-5 h-5 mt-0.5 ${W?"text-[#0094f7]":"text-white"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black",children:u.label}),e.jsx("div",{className:`text-xs mt-1 leading-5 ${W?"text-gray-500":"text-gray-400"}`,children:u.description})]})]})},a)})}),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:te.flow.map((a,u)=>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:u+1}),e.jsx("span",{className:"text-sm font-bold text-gray-100",children:a})]},a))})]})]}),e.jsx("div",{className:"p-6 overflow-y-auto bg-[#F7F8FA]",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(Bt,{className:"w-5 h-5 text-[#0094f7]"}),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:b.name||"",onChange:a=>v({...b,name:a.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:b.cookie_id||"",onChange:a=>v({...b,cookie_id:a.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:"选择账号"}),Y.map(a=>e.jsx("option",{value:a.id,children:Ss(a)},a.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:b.item_id||"",onChange:a=>Re(a.target.value),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级规则(不限定商品)"}),i.map(a=>e.jsx("option",{value:a.item_id,children:a.item_title||a.item_id},`${a.cookie_id}-${a.item_id}`))]})]})]}),q&&_!=="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:q.item_title||q.item_id}),e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${d?"bg-blue-50 text-blue-700":"bg-gray-100 text-gray-500"}`,children:d?"多规格商品":"普通商品"}),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:"多规格状态来自闲鱼商品本身,发布后不能在这里修改;系统会在买家付款后读取订单详情,按实际购买规格和数量匹配下面的发货规则。"})]})]}),_!=="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(La,{className:"w-5 h-5 text-[#0094f7]"}),e.jsx("h4",{className:"font-black text-gray-900",children:_==="buyer_reviewed"?"赠品库存":"发货库存"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:d?"每条发货内容绑定一个订单规格;同一规格可添加多条内容并全部发送。":"可添加多条发货内容,买家付款后会按顺序全部发送。"})]}),e.jsxs("button",{type:"button",onClick:Le,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(Qe,{className:"w-3.5 h-3.5"}),"添加发货内容"]})]}),e.jsx("div",{className:"space-y-3",children:ye.map((a,u)=>e.jsxs("div",{className:`grid grid-cols-1 gap-3 items-end rounded-2xl border border-gray-200 p-4 ${d?"md:grid-cols-[1fr_1fr_1.4fr_110px_40px]":"md:grid-cols-[1.4fr_110px_40px]"}`,children:[d&&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:a.spec_name,onChange:w=>Ae(u,{spec_name:w.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:a.spec_value,onChange:w=>Ae(u,{spec_value:w.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:a.card_id||"",onChange:w=>Ae(u,{card_id:Number(w.target.value)}),className:"w-full ios-input px-3 py-2.5 rounded-lg",children:[e.jsx("option",{value:"",children:"请选择卡密库存"}),de.filter(w=>w.enabled&&w.type!=="api").map(w=>e.jsx("option",{value:w.id,children:w.name},w.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:a.delivery_count,onChange:w=>Ae(u,{delivery_count:Math.max(1,Number(w.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:a.delay_override===!0,onChange:w=>Ae(u,{delay_override:w.target.checked}),className:"accent-[#0094f7]"}),"覆盖卡密默认延时"]}),a.delay_override&&e.jsx("input",{type:"number",min:"0",max:"3600",value:a.delay_seconds||0,onChange:w=>Ae(u,{delay_seconds:Math.max(0,Number(w.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:a.delay_override?`本动作延时 ${a.delay_seconds||0} 秒`:"使用卡密默认延时"})]}),e.jsx("button",{type:"button",disabled:ye.length===1,onClick:()=>v({...b,variants:ye.filter((w,W)=>W!==u)}),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(Je,{className:"w-4 h-4"})})]},a.id||u))})]}):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(zt,{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(Z.after_shipped_hours||72),onChange:a=>v({...b,config_json:as(b.config_json,{after_shipped_hours:Math.max(1,Number(a.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(Z.repeat_interval_hours||24),onChange:a=>v({...b,config_json:as(b.config_json,{repeat_interval_hours:Math.max(1,Number(a.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(Z.max_attempts||1),onChange:a=>v({...b,config_json:as(b.config_json,{max_attempts:Math.max(1,Number(a.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:((r=(ze=b.actions)==null?void 0:ze.find(a=>a.action_type==="send_text"))==null?void 0:r.message_template)||"",onChange:a=>{var u;return v({...b,actions:((u=b.actions)!=null&&u.length?b.actions:ys("review_missing_timeout")).map(w=>w.action_type==="send_text"?{...w,message_template:a.target.value}:w)})},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:b.priority||100,onChange:a=>v({...b,priority:Number(a.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:b.enabled!==!1,onChange:a=>v({...b,enabled:a.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:()=>T(!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:Be,className:"flex-1 ios-btn-primary px-6 py-3 rounded-2xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4"}),"保存自动化规则"]})]})]})}),document.body),J&&B&&Se.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:B.id?"编辑回复规则":"新增回复规则"}),e.jsx("button",{onClick:()=>ue(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(we,{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:B.item_id||"",onChange:a=>R({...B,item_id:a.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级回复"}),M.filter(a=>!O||a.cookie_id===O).map(a=>e.jsx("option",{value:a.item_id,children:a.item_title||a.item_id},`${a.cookie_id}-${a.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:B.type||"text",onChange:a=>{const u=a.target.value;R({...B,type:u,reply_content:u==="text"?B.reply_content:"",image_url:u==="image"?B.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:B.keyword||"",onChange:a=>R({...B,keyword:a.target.value}),placeholder:"买家发送的关键词",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),B.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:B.image_url||"",onChange:a=>R({...B,image_url:a.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:B.reply_content||"",onChange:a=>R({...B,reply_content:a.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:()=>ue(!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:ss,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Zs,{className:"w-4 h-4"}),"保存规则"]})]})]})]})}),document.body),Q&&Se.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:()=>A(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",title:"关闭",children:e.jsx(we,{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:K.cookie_id,onChange:a=>H({...K,cookie_id:a.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),Y.map(a=>e.jsx("option",{value:a.id,children:Ss(a)},a.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:()=>H({...K,enabled:!K.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${K.enabled?"bg-[#0094f7]":"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 ${K.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:K.reply_content,onChange:a=>H({...K,reply_content:a.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:K.reply_image_url,onChange:a=>H({...K,reply_image_url:a.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:K.reply_once,onChange:a=>H({...K,reply_once:a.target.checked}),className:"w-4 h-4 rounded"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:()=>A(!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:He,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4"}),"保存默认回复"]})]})]})]})}),document.body)]})},$r=s=>{const t=String(s.smtp_from||"").trim(),l=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);return{...s,smtp_from_name:s.smtp_from_name||(l?"":t),smtp_from_address:s.smtp_from_address||(l?t:s.smtp_user||""),smtp_use_tls:At(s.smtp_use_tls,!0),smtp_use_ssl:At(s.smtp_use_ssl,!1)}},At=(s,t)=>{if(typeof s=="boolean")return s;if(typeof s=="string"){if(["true","1","yes","on"].includes(s.toLowerCase()))return!0;if(["false","0","no","off"].includes(s.toLowerCase()))return!1}return t},Hs=["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from_name","smtp_from_address","smtp_use_tls","smtp_use_ssl"],Ks=(s,t)=>{if(typeof s=="boolean")return s;if(typeof s=="string"){if(["true","1","yes","on"].includes(s.toLowerCase()))return!0;if(["false","0","no","off"].includes(s.toLowerCase()))return!1}return t},ea=s=>{const t=Object.prototype.hasOwnProperty.call(s,"use_custom_smtp"),l=Hs.some(c=>String(s[c]??"").trim()!=="");return{...s,use_custom_smtp:t?Ks(s.use_custom_smtp,!1):l}},It=(s,t)=>{const l={...s,use_custom_smtp:!0};for(const c of Hs)String(l[c]??"").trim()===""&&t[c]!==void 0&&(l[c]=t[c]);return l.smtp_port||(l.smtp_port=587),l.smtp_from_address||(l.smtp_from_address=l.smtp_user||""),l.smtp_use_tls=Ks(l.smtp_use_tls,!0),l.smtp_use_ssl=Ks(l.smtp_use_ssl,!1),l},Rr=s=>{const t=ea(s),l={to_email:String(t.to_email??"").trim(),use_custom_smtp:t.use_custom_smtp===!0};if(l.use_custom_smtp)for(const c of Hs)l[c]=t[c];return l},cs={bark:{label:"Bark",icon:xs,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:Ls,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:Ls,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:Ls,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:Aa,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:Zs,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:Ut,fields:[{key:"to_email",label:"收件邮箱",placeholder:"receiver@example.com",required:!0}],guide:{steps:["通常先保存页面中的系统 SMTP 配置","邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP","只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置"],note:"继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。"}}},sa=[{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:"后台任务或系统级异常"}],Pr=s=>!s||s.length===0?"全部事件":s.map(l=>{var c;return((c=sa.find(h=>h.value===l))==null?void 0:c.label)||l}).join("、"),Tr=({isAdmin:s=!1})=>{const[t,l]=n.useState([]),[c,h]=n.useState(!0),[f,L]=n.useState(!1),[F,g]=n.useState(null),[I,j]=n.useState(!1),[G,Y]=n.useState(""),[X,de]=n.useState(null),[C,M]=n.useState({}),[oe,ee]=n.useState(!1),[xe,O]=n.useState(!1),[le,D]=n.useState(!1),[N,$]=n.useState({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),T=async()=>{h(!0);try{const m=await Xt();l(m.data||[])}catch(m){console.error("加载通知渠道失败",m)}finally{h(!1)}},J=async()=>{try{const m=await Kt();M($r(m||{}))}catch(m){console.error("加载 SMTP 配置失败",m)}},ue=async()=>{ee(!0);try{await Yt({smtp_server:C.smtp_server||"",smtp_port:C.smtp_port||587,smtp_user:C.smtp_user||"",smtp_password:C.smtp_password||"",smtp_from_name:C.smtp_from_name||"",smtp_from_address:C.smtp_from_address||C.smtp_user||"",smtp_use_tls:C.smtp_use_tls!==!1,smtp_use_ssl:C.smtp_use_ssl===!0}),Q("success","SMTP 配置已保存")}catch(m){Q("error",(m==null?void 0:m.message)||"保存失败")}finally{ee(!1)}};n.useEffect(()=>{T(),s?J():M({})},[s]);const Q=(m,p)=>{de({type:m,text:p}),window.setTimeout(()=>de(null),3e3)},A=()=>{g(null),$({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),D(!1),L(!0)},b=m=>{g(m);const p=m.type==="email"?ea({...m.config||{}}):null,y=p?p.use_custom_smtp===!0?It(p,C):p:{...m.config||{}};$({name:m.name,type:m.type,enabled:m.enabled,config:y,event_types:m.event_types||[]}),D(!1),L(!0)},v=async()=>{const m=cs[N.type];for(const y of m.fields)if(y.required&&!String(N.config[y.key]||"").trim()){Q("error",`请填写 ${y.label}`);return}if(!N.name.trim()){Q("error","请填写渠道名称");return}let p=N.config;if(N.type==="email"&&(p=Rr(N.config),p.use_custom_smtp)){const S=[["smtp_server","独立 SMTP 服务器"],["smtp_port","独立 SMTP 端口"],["smtp_user","独立 SMTP 登录邮箱"],["smtp_password","独立 SMTP 密码 / 授权码"],["smtp_from_address","独立 SMTP 发件地址"]].find(([U])=>!String(p[U]||"").trim());if(S){Q("error",`请填写 ${S[1]}`);return}}j(!0);try{const y={name:N.name.trim(),type:N.type,config:p,event_types:N.event_types,enabled:N.enabled};F?await Nt(F.id,y):await Jl(y),L(!1),await T(),Q("success",F?"已更新":"已创建")}catch(y){console.error("保存失败",y),Q("error",(y==null?void 0:y.message)||"保存失败")}finally{j(!1)}},B=async m=>{if(confirm(`确认删除渠道「${m.name}」吗?已绑定该渠道的账号会自动解绑。`))try{await Ql(m.id),await T(),Q("success","已删除")}catch(p){Q("error",(p==null?void 0:p.message)||"删除失败")}},R=async m=>{try{await Nt(m.id,{enabled:!m.enabled}),l(p=>p.map(y=>y.id===m.id?{...y,enabled:!y.enabled}:y))}catch(p){Q("error",(p==null?void 0:p.message)||"切换失败")}},K=async m=>{Y(m.id);try{await Yl(m.id),Q("success","测试通知已发送,请检查对应渠道")}catch(p){Q("error",(p==null?void 0:p.message)||"发送失败")}finally{Y("")}},H=cs[N.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:T,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(qe,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:A,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(Qe,{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(xs,{className:"w-5 h-5 text-[#0094f7] 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:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),c?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(Te,{className:"w-8 h-8 text-[#0094f7] animate-spin"})}):t.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(xs,{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:t.map(m=>{const p=cs[m.type]||cs.webhook,y=p.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(y,{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:m.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium",children:p.label}),!m.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:p.fields.map(S=>{var U;return(U=m.config)==null?void 0:U[S.key]}).filter(Boolean).map((S,U)=>e.jsx("span",{className:"mr-3",children:String(S).length>40?String(S).slice(0,40)+"…":String(S)},U))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",Pr(m.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>R(m),className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${m.enabled?"bg-green-50 text-green-700 hover:bg-green-100":"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:m.enabled?"启用中":"已停用"}),e.jsxs("button",{onClick:()=>K(m),disabled:G===m.id,className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-[#0094f7] hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50",children:[G===m.id?e.jsx(Te,{className:"w-3 h-3 animate-spin"}):e.jsx(Zs,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{onClick:()=>b(m),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(Ot,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>B(m),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(Je,{className:"w-4 h-4"})})]})]},m.id)})}),s&&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(Ut,{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:C.smtp_server||"",onChange:m=>M({...C,smtp_server:m.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:C.smtp_port||587,onChange:m=>M({...C,smtp_port:parseInt(m.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:C.smtp_user||"",onChange:m=>M({...C,smtp_user:m.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:xe?"text":"password",value:C.smtp_password||"",onChange:m=>M({...C,smtp_password:m.target.value}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>O(!xe),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:xe?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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:C.smtp_from_name||"",onChange:m=>M({...C,smtp_from_name:m.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:C.smtp_from_address||C.smtp_user||"",onChange:m=>M({...C,smtp_from_address:m.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:C.smtp_use_tls!==!1,onChange:m=>M({...C,smtp_use_tls:m.target.checked,smtp_use_ssl:m.target.checked?!1:C.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:C.smtp_use_ssl===!0,onChange:m=>M({...C,smtp_use_ssl:m.target.checked,smtp_use_tls:m.target.checked?!1:C.smtp_use_tls})}),"SSL/TLS 直连(常用于 465 端口)"]})]}),e.jsxs("button",{onClick:ue,disabled:oe,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[oe?e.jsx(Te,{className:"w-4 h-4 animate-spin"}):e.jsx(Ke,{className:"w-4 h-4"}),oe?"保存中...":"保存 SMTP 配置"]})]}),f&&Se.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:F?"编辑通知渠道":"新建通知渠道"}),e.jsx("button",{onClick:()=>L(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(we,{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:N.name,onChange:m=>$({...N,name:m.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(cs).map(m=>{const p=cs[m],y=p.icon,S=N.type===m;return e.jsxs("button",{type:"button",onClick:()=>$({...N,type:m,config:{}}),className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${S?"border-[#0094f7] bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(y,{className:`w-5 h-5 ${S?"text-[#0094f7]":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${S?"text-[#0094f7]":"text-gray-600"}`,children:p.label})]},m)})})]}),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(xs,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",H.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:H.guide.steps.map((m,p)=>e.jsx("li",{children:m},p))}),H.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:H.guide.urlFormat})]}),H.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",H.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:H.fields.map(m=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:[m.label,m.required&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),e.jsx("input",{type:m.type==="password"?"password":m.type==="number"?"number":"text",value:String(N.config[m.key]||""),onChange:p=>$({...N,config:{...N.config,[m.key]:p.target.value}}),placeholder:m.placeholder,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),m.help&&e.jsx("p",{className:"text-xs text-gray-500",children:m.help})]},m.key))}),N.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:N.config.use_custom_smtp===!0?"当前渠道使用一套完整、独立的发件配置。":"当前渠道完整继承系统 SMTP,只单独设置收件邮箱。"})]}),e.jsx("button",{type:"button",onClick:()=>{const m=N.config.use_custom_smtp===!0;$({...N,config:m?{...N.config,use_custom_smtp:!1}:It(N.config,C)})},className:`relative h-7 w-12 shrink-0 rounded-full transition-colors ${N.config.use_custom_smtp===!0?"bg-[#0094f7]":"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 ${N.config.use_custom_smtp===!0?"translate-x-5":""}`})})]}),N.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(N.config.smtp_server||""),onChange:m=>$({...N,config:{...N.config,smtp_server:m.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(N.config.smtp_port||587),onChange:m=>$({...N,config:{...N.config,smtp_port:m.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(N.config.smtp_user||""),onChange:m=>$({...N,config:{...N.config,smtp_user:m.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:le?"text":"password",value:String(N.config.smtp_password||""),onChange:m=>$({...N,config:{...N.config,smtp_password:m.target.value}}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>D(m=>!m),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",children:le?e.jsx(rs,{className:"w-4 h-4"}):e.jsx(es,{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(N.config.smtp_from_name||""),onChange:m=>$({...N,config:{...N.config,smtp_from_name:m.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(N.config.smtp_from_address||""),onChange:m=>$({...N,config:{...N.config,smtp_from_address:m.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:N.config.smtp_use_tls!==!1,onChange:m=>$({...N,config:{...N.config,smtp_use_tls:m.target.checked,smtp_use_ssl:m.target.checked?!1:N.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:N.config.smtp_use_ssl===!0,onChange:m=>$({...N,config:{...N.config,smtp_use_ssl:m.target.checked,smtp_use_tls:m.target.checked?!1:N.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:sa.map(m=>{const p=N.event_types.includes(m.value);return e.jsxs("button",{type:"button",onClick:()=>{const y=p?N.event_types.filter(S=>S!==m.value):[...N.event_types,m.value];$({...N,event_types:y})},className:`text-left rounded-xl border px-3 py-2.5 transition-colors ${p?"border-[#0094f7] 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 ${p?"bg-[#0094f7] border-[#0094f7]":"border-gray-300"}`,children:p&&e.jsx(Ge,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${p?"text-[#0094f7]":"text-gray-800"}`,children:m.label})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 pl-6 leading-5",children:m.description})]},m.value)})})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("button",{type:"button",onClick:()=>$({...N,enabled:!N.enabled}),className:`relative w-11 h-6 rounded-full transition-colors ${N.enabled?"bg-[#0094f7]":"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 ${N.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:()=>L(!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:v,disabled:I,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[I?e.jsx(Te,{className:"w-4 h-4 animate-spin"}):e.jsx(Ge,{className:"w-4 h-4"}),I?"保存中...":"保存"]})]})]})}),document.body),X&&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",style:{background:X.type==="success"?"#10b981":"#ef4444",color:"white"},children:[X.type==="success"?e.jsx(Ge,{className:"w-4 h-4"}):e.jsx(we,{className:"w-4 h-4"}),X.text]})]})},ta={"/app/dashboard":"dashboard","/app/accounts":"accounts","/app/orders":"orders","/app/cards":"cards","/app/items":"items","/app/rules":"rules","/app/notifications":"notifications","/app/settings":"settings"},$t=Object.fromEntries(Object.entries(ta).map(([s,t])=>[t,s])),Rt=()=>ta[window.location.pathname]||"dashboard",Er=/Win/i.test(navigator.platform||navigator.userAgent),Fr=()=>{const[s,t]=n.useState(!1),[l,c]=n.useState(!1),[h,f]=n.useState(Rt),[L,F]=n.useState(!0),[g,I]=n.useState(!1),[j,G]=n.useState(""),[Y,X]=n.useState(""),[de,C]=n.useState(!1),[M,oe]=n.useState(""),[ee,xe]=n.useState(),O=$=>{const T=$==="settings"&&!l?"dashboard":$,J=$t[T];J&&J!==window.location.pathname&&window.history.pushState({},"",J),f(T)};n.useEffect(()=>{const $=()=>f(Rt());return window.addEventListener("popstate",$),()=>window.removeEventListener("popstate",$)},[]),n.useEffect(()=>{Gt().then(T=>{if((T==null?void 0:T.initialized)===!1){I(!0),t(!1),c(!1);return}I(!1),T!=null&&T.authenticated?(t(!0),c(T.is_admin===!0)):c(!1)}).catch(()=>{t(!1),c(!1)}).finally(()=>F(!1));const $=()=>{t(!1),c(!1)};return window.addEventListener("auth:logout",$),()=>window.removeEventListener("auth:logout",$)},[]),n.useEffect(()=>{!L&&s&&!l&&h==="settings"&&(window.history.replaceState({},"",$t.dashboard),f("dashboard"))},[L,s,l,h]);const le=async $=>{$.preventDefault(),C(!0),oe("");try{const T=await Wa({username:j,password:Y});T.success?(t(!0),c(T.is_admin===!0)):oe(T.message||"登录失败")}catch(T){const J=T instanceof Error?T.message:String(T);oe(J||"登录失败")}finally{C(!1)}},D=async()=>{try{await Va()}catch($){console.error("退出登录失败",$)}finally{t(!1),c(!1)}};if(L)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[#f5f5f7]",children:e.jsx(Te,{className:"w-8 h-8 text-[#0094f7] animate-spin"})});if(g)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-[#F4F5F7] 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-[0_20px_60px_-15px_rgba(0,0,0,0.05)] 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(Gs,{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:"为避免默认口令风险,管理员必须通过服务器本机 CLI 初始化。"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 rounded-2xl bg-gray-50 border border-gray-100",children:[e.jsx("div",{className:"text-sm font-bold text-gray-900 mb-2",children:"请在服务器上执行:"}),e.jsx("pre",{className:"text-xs bg-black text-white p-4 rounded-2xl overflow-x-auto",children:Er?'.\\xianyu-server.exe -init-admin -db data\\xianyu_data.db -admin-password "请设置密码"':"./xianyu-server -init-admin -db data/xianyu_data.db -admin-password '请设置密码'"}),e.jsx("div",{className:"text-xs text-gray-500 mt-2",children:"完成后刷新页面即可进入登录。"})]}),e.jsxs("button",{type:"button",onClick:()=>window.location.reload(),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",children:["我已初始化,刷新 ",e.jsx(Ws,{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(!s)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-[#F4F5F7] 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-[0_20px_60px_-15px_rgba(0,0,0,0.05)] 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(Gs,{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:le,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(ns,{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:$=>G($.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(Ia,{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:Y,onChange:$=>X($.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]})]}),M&&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(Vs,{className:"w-4 h-4"})," ",M]}),e.jsx("button",{type:"submit",disabled:de,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:de?e.jsx(Te,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:["立即登录 ",e.jsx(Ws,{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 N=()=>{switch(h){case"dashboard":return e.jsx(Os,{});case"accounts":return e.jsx(dr,{});case"orders":return e.jsx(ur,{});case"cards":return e.jsx(hr,{});case"items":return e.jsx(fr,{onConfigureDelivery:$=>{xe({cookieId:$.cookie_id,itemId:$.item_id,requestId:Date.now()}),O("rules")}});case"rules":return e.jsx(Ir,{initialDeliveryTarget:ee,onDeliveryTargetHandled:()=>xe(void 0)});case"notifications":return e.jsx(Tr,{isAdmin:l});case"settings":return l?e.jsx(Nr,{}):e.jsx(Os,{});default:return e.jsx(Os,{})}};return e.jsxs("div",{className:"flex min-h-screen bg-[#F4F5F7] text-[#111]",children:[e.jsx(Ma,{activeTab:h,isAdmin:l,onNavigate:O,onLogout:D}),e.jsxs("main",{className:"flex-1 ml-64 p-8 md:p-12 overflow-y-auto h-screen relative scroll-smooth",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:"max-w-[1400px] mx-auto pb-10",children:N()})]})]})},aa=document.getElementById("root");if(!aa)throw new Error("Could not find root element to mount to");const Dr=ra.createRoot(aa);Dr.render(e.jsx(na.StrictMode,{children:e.jsx(Fr,{})})); diff --git a/internal/webui/static/index.html b/internal/webui/static/index.html index 924f906..a14461e 100644 --- a/internal/webui/static/index.html +++ b/internal/webui/static/index.html @@ -6,7 +6,7 @@ Ydisks闲鱼助手 - 自动发货与管家系统 - +