File size: 44,761 Bytes
ea775bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { createColumnHelper } from "@tanstack/react-table";
import { AlertTriangle, Eye, Filter, Info, Pencil, Plus, RefreshCw, Search, Sparkles, Trash2, X } from "lucide-react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useForm } from "react-hook-form";
import { Link } from "react-router-dom";
import { z } from "zod";
import { Badge } from "../../components/ui/Badge";
import { Button } from "../../components/ui/Button";
import { Card } from "../../components/ui/Card";
import { DataTable } from "../../components/ui/DataTable";
import { Input } from "../../components/ui/Input";
import { OffsetPagination } from "../../components/ui/OffsetPagination";
import { Select } from "../../components/ui/Select";
import { Switch } from "../../components/ui/Switch";
import { Textarea } from "../../components/ui/Textarea";
import { ToastContainer } from "../../components/ui/Toast";
import { useToast } from "../../hooks/useToast";
import { useI18n } from "../../i18n";
import { formatApiErrorMessage } from "../../lib/error-message";
import { formatDateTime, formatGoDuration, formatRelativeTime } from "../../lib/time";
import {
  cleanupSubscriptionCircuitOpenNodes,
  createSubscription,
  deleteSubscription,
  listSubscriptions,
  refreshSubscription,
  updateSubscription,
} from "./api";
import type { Subscription } from "./types";

type EnabledFilter = "all" | "enabled" | "disabled";
type SubscriptionSourceType = "remote" | "local";

const SUBSCRIPTION_SOURCE_TABS: Array<{ key: SubscriptionSourceType; label: string; hint: string }> = [
  { key: "remote", label: "远程", hint: "从 HTTP/HTTPS 订阅链接拉取内容" },
  { key: "local", label: "本地", hint: "直接填写订阅文本,不经过网络拉取" },
];

const subscriptionCreateSchema = z.object({
  name: z.string().trim().min(1, "订阅名称不能为空"),
  source_type: z.enum(["remote", "local"]),
  url: z.string(),
  content: z.string(),
  update_interval: z.string().trim().min(1, "更新间隔不能为空"),
  ephemeral_node_evict_delay: z.string().trim().min(1, "临时节点驱逐延迟不能为空"),
  enabled: z.boolean(),
  ephemeral: z.boolean(),
  incremental_alive_nodes: z.boolean(),
}).superRefine((value, ctx) => {
  const url = value.url.trim();
  const content = value.content.trim();
  if (value.source_type === "remote") {
    if (!url) {
      ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["url"], message: "URL 不能为空" });
      return;
    }
    if (!(url.startsWith("http://") || url.startsWith("https://"))) {
      ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["url"], message: "URL 必须是 http/https 地址" });
    }
    return;
  }
  if (!content) {
    ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["content"], message: "订阅内容不能为空" });
  }
});

const subscriptionEditSchema = subscriptionCreateSchema;

type SubscriptionCreateForm = z.infer<typeof subscriptionCreateSchema>;
type SubscriptionEditForm = z.infer<typeof subscriptionEditSchema>;
const EMPTY_SUBSCRIPTIONS: Subscription[] = [];
const PAGE_SIZE_OPTIONS = [10, 20, 50, 100] as const;
const LOCAL_SOURCE_UPDATE_INTERVAL = "12h";
const SUBSCRIPTION_DISABLE_HINT = "禁用订阅后,相关节点不会参与平台路由、健康统计或自动探测。";
const SUBSCRIPTION_EPHEMERAL_HINT = "临时订阅的非健康节点会在一段时间后被自动删除。订阅本身不会被删除。";
const SUBSCRIPTION_INCREMENTAL_HINT = "开启后刷新时保留当前仍存活的旧节点,仅清理失效旧节点,并合并新订阅内容;关闭后仅保留刷新后的订阅内容。";

function extractHostname(url: string): string {
  try {
    return new URL(url).hostname;
  } catch {
    return url;
  }
}

function subscriptionToEditForm(subscription: Subscription): SubscriptionEditForm {
  return {
    name: subscription.name,
    source_type: subscription.source_type,
    url: subscription.url,
    content: subscription.content ?? "",
    update_interval: subscription.update_interval,
    ephemeral_node_evict_delay: subscription.ephemeral_node_evict_delay,
    enabled: subscription.enabled,
    ephemeral: subscription.ephemeral,
    incremental_alive_nodes: subscription.incremental_alive_nodes,
  };
}

function sourceTypeLabel(sourceType: SubscriptionSourceType): string {
  return sourceType === "local" ? "本地" : "远程";
}

function parseEnabledFilter(value: EnabledFilter): boolean | undefined {
  if (value === "enabled") {
    return true;
  }
  if (value === "disabled") {
    return false;
  }
  return undefined;
}

function normalizeSubmitUpdateInterval(sourceType: SubscriptionSourceType, raw: string): string {
  if (sourceType === "local") {
    return LOCAL_SOURCE_UPDATE_INTERVAL;
  }
  return raw.trim();
}

export function SubscriptionPage() {
  const { t } = useI18n();
  const [enabledFilter, setEnabledFilter] = useState<EnabledFilter>("all");
  const [search, setSearch] = useState("");
  const [page, setPage] = useState(0);
  const [pageSize, setPageSize] = useState<number>(20);
  const [selectedSubscriptionId, setSelectedSubscriptionId] = useState("");
  const [drawerOpen, setDrawerOpen] = useState(false);
  const [createModalOpen, setCreateModalOpen] = useState(false);
  const [pendingRefreshIds, setPendingRefreshIds] = useState<Set<string>>(() => new Set());
  const { toasts, showToast, dismissToast } = useToast();
  const pendingRefreshIdsRef = useRef<Set<string>>(new Set());

  const queryClient = useQueryClient();
  const enabledValue = parseEnabledFilter(enabledFilter);
  const subscriptionContentPlaceholder = [
    t("支持格式:"),
    t("sing-box / Clash|Mihomo / URI(vmess:// vless:// trojan:// ss:// ...)或他们的 base64 格式"),
    "",
    t("HTTP/HTTPS/SOCKS 示例:"),
    t("1.2.3.4:8080:user:pass (HTTP 认证代理)"),
    t("http://user:pass@1.2.3.4:8080(HTTP 认证代理)"),
    t("https://user:pass@example.com:8443?sni=example.com(HTTPS + SNI)"),
    t("socks5://user:pass@1.2.3.4:1080"),
    t("socks5h://user:pass@example.com:1080"),
  ].join("\n");

  const subscriptionsQuery = useQuery({
    queryKey: ["subscriptions", enabledFilter, page, pageSize, search],
    queryFn: () =>
      listSubscriptions({
        enabled: enabledValue,
        limit: pageSize,
        offset: page * pageSize,
        keyword: search,
      }),
    refetchInterval: 30_000,
    placeholderData: (prev) => prev,
  });

  const subscriptions = subscriptionsQuery.data?.items ?? EMPTY_SUBSCRIPTIONS;
  const totalSubscriptions = subscriptionsQuery.data?.total ?? 0;

  const totalPages = Math.max(1, Math.ceil(totalSubscriptions / pageSize));
  const currentPage = Math.min(page, totalPages - 1);

  const selectedSubscription = useMemo(() => {
    if (!selectedSubscriptionId) {
      return null;
    }
    return subscriptions.find((item) => item.id === selectedSubscriptionId) ?? null;
  }, [selectedSubscriptionId, subscriptions]);

  const drawerVisible = drawerOpen && Boolean(selectedSubscription);

  const createForm = useForm<SubscriptionCreateForm>({
    resolver: zodResolver(subscriptionCreateSchema),
    defaultValues: {
      name: "",
      source_type: "remote",
      url: "",
      content: "",
      update_interval: "12h",
      ephemeral_node_evict_delay: "72h",
      enabled: true,
      ephemeral: false,
      incremental_alive_nodes: false,
    },
  });

  const createEphemeral = createForm.watch("ephemeral");
  const createSourceType = createForm.watch("source_type");

  const editForm = useForm<SubscriptionEditForm>({
    resolver: zodResolver(subscriptionEditSchema),
    defaultValues: {
      name: "",
      source_type: "remote",
      url: "",
      content: "",
      update_interval: "12h",
      ephemeral_node_evict_delay: "72h",
      enabled: true,
      ephemeral: false,
      incremental_alive_nodes: false,
    },
  });

  const editEphemeral = editForm.watch("ephemeral");
  const editSourceType = editForm.watch("source_type");

  useEffect(() => {
    if (!selectedSubscription) {
      return;
    }
    editForm.reset(subscriptionToEditForm(selectedSubscription));
  }, [selectedSubscription, editForm]);

  useEffect(() => {
    if (!drawerVisible) {
      return;
    }

    const onKeyDown = (event: KeyboardEvent) => {
      if (event.key !== "Escape") {
        return;
      }
      setDrawerOpen(false);
    };

    window.addEventListener("keydown", onKeyDown);
    return () => window.removeEventListener("keydown", onKeyDown);
  }, [drawerVisible]);

  const invalidateSubscriptions = async () => {
    await queryClient.invalidateQueries({ queryKey: ["subscriptions"] });
  };

  const invalidateSubscriptionsAndNodes = async () => {
    await Promise.all([
      queryClient.invalidateQueries({ queryKey: ["subscriptions"] }),
      queryClient.invalidateQueries({ queryKey: ["nodes"] }),
    ]);
  };

  const createMutation = useMutation({
    mutationFn: createSubscription,
    onSuccess: async (created) => {
      await invalidateSubscriptions();
      setCreateModalOpen(false);
      createForm.reset({
        name: "",
        source_type: "remote",
        url: "",
        content: "",
        update_interval: LOCAL_SOURCE_UPDATE_INTERVAL,
        ephemeral_node_evict_delay: "72h",
        enabled: true,
        ephemeral: false,
        incremental_alive_nodes: false,
      });
      showToast("success", t("订阅 {{name}} 创建成功", { name: created.name }));
    },
    onError: (error) => {
      showToast("error", formatApiErrorMessage(error, t));
    },
  });

  const updateMutation = useMutation({
    mutationFn: async (formData: SubscriptionEditForm) => {
      if (!selectedSubscription) {
        throw new Error("请选择要编辑的订阅");
      }

      const payload = {
        name: formData.name.trim(),
        update_interval: normalizeSubmitUpdateInterval(formData.source_type, formData.update_interval),
        ephemeral_node_evict_delay: formData.ephemeral_node_evict_delay.trim(),
        enabled: formData.enabled,
        ephemeral: formData.ephemeral,
        incremental_alive_nodes: formData.incremental_alive_nodes,
        ...(formData.source_type === "remote"
          ? { url: formData.url.trim() }
          : { content: formData.content }),
      };
      return updateSubscription(selectedSubscription.id, payload);
    },
    onSuccess: async (updated) => {
      await invalidateSubscriptions();
      setSelectedSubscriptionId(updated.id);
      showToast("success", t("订阅 {{name}} 已更新", { name: updated.name }));
    },
    onError: (error) => {
      showToast("error", formatApiErrorMessage(error, t));
    },
  });

  const deleteMutation = useMutation({
    mutationFn: async (subscription: Subscription) => {
      await deleteSubscription(subscription.id);
      return subscription;
    },
    onSuccess: async (deleted) => {
      await invalidateSubscriptions();
      if (selectedSubscriptionId === deleted.id) {
        setSelectedSubscriptionId("");
        setDrawerOpen(false);
      }
      showToast("success", t("订阅 {{name}} 已删除", { name: deleted.name }));
    },
    onError: (error) => {
      showToast("error", formatApiErrorMessage(error, t));
    },
  });
  const deleteSubscriptionMutateAsync = deleteMutation.mutateAsync;
  const isDeletePending = deleteMutation.isPending;

  const refreshMutation = useMutation({
    mutationFn: async (subscription: Subscription) => {
      await refreshSubscription(subscription.id);
      return subscription;
    },
    onSuccess: async (subscription) => {
      await invalidateSubscriptions();
      showToast("success", t("订阅 {{name}} 已手动刷新", { name: subscription.name }));
    },
    onError: (error) => {
      showToast("error", formatApiErrorMessage(error, t));
    },
  });
  const refreshSubscriptionMutateAsync = refreshMutation.mutateAsync;

  const markRefreshPending = useCallback((subscriptionId: string): boolean => {
    if (pendingRefreshIdsRef.current.has(subscriptionId)) {
      return false;
    }
    const next = new Set(pendingRefreshIdsRef.current);
    next.add(subscriptionId);
    pendingRefreshIdsRef.current = next;
    setPendingRefreshIds(next);
    return true;
  }, []);

  const clearRefreshPending = useCallback((subscriptionId: string) => {
    if (!pendingRefreshIdsRef.current.has(subscriptionId)) {
      return;
    }
    const next = new Set(pendingRefreshIdsRef.current);
    next.delete(subscriptionId);
    pendingRefreshIdsRef.current = next;
    setPendingRefreshIds(next);
  }, []);

  const isRefreshPending = useCallback((subscriptionId: string): boolean => pendingRefreshIds.has(subscriptionId), [pendingRefreshIds]);

  const cleanupCircuitOpenNodesMutation = useMutation({
    mutationFn: async (subscription: Subscription) => {
      const cleanedCount = await cleanupSubscriptionCircuitOpenNodes(subscription.id);
      return { subscription, cleanedCount };
    },
    onSuccess: async ({ subscription, cleanedCount }) => {
      await invalidateSubscriptionsAndNodes();
      if (cleanedCount > 0) {
        showToast("success", t("订阅 {{name}} 已清理 {{count}} 个节点", { name: subscription.name, count: cleanedCount }));
        return;
      }
      showToast("success", t("订阅 {{name}} 没有可清理的熔断或异常节点", { name: subscription.name }));
    },
    onError: (error) => {
      showToast("error", formatApiErrorMessage(error, t));
    },
  });

  const onCreateSubmit = createForm.handleSubmit(async (values) => {
    const payload = {
      name: values.name.trim(),
      source_type: values.source_type,
      update_interval: normalizeSubmitUpdateInterval(values.source_type, values.update_interval),
      ephemeral_node_evict_delay: values.ephemeral_node_evict_delay.trim(),
      enabled: values.enabled,
      ephemeral: values.ephemeral,
      incremental_alive_nodes: values.incremental_alive_nodes,
      ...(values.source_type === "remote"
        ? { url: values.url.trim() }
        : { content: values.content }),
    };
    await createMutation.mutateAsync(payload);
  });

  const onEditSubmit = editForm.handleSubmit(async (values) => {
    await updateMutation.mutateAsync(values);
  });

  const handleDelete = useCallback(async (subscription: Subscription) => {
    const confirmed = window.confirm(t("确认删除订阅 {{name}}?关联节点会被清理。", { name: subscription.name }));
    if (!confirmed) {
      return;
    }
    await deleteSubscriptionMutateAsync(subscription);
  }, [deleteSubscriptionMutateAsync, t]);

  const handleCleanupCircuitOpenNodes = async (subscription: Subscription) => {
    const confirmed = window.confirm(t("确认立即清理订阅 {{name}} 中的熔断或异常节点?", { name: subscription.name }));
    if (!confirmed) {
      return;
    }
    await cleanupCircuitOpenNodesMutation.mutateAsync(subscription);
  };

  const openDrawer = useCallback((subscription: Subscription) => {
    setSelectedSubscriptionId(subscription.id);
    setDrawerOpen(true);
  }, []);

  const handleRefresh = useCallback(async (subscription: Subscription) => {
    if (!markRefreshPending(subscription.id)) {
      return;
    }
    try {
      await refreshSubscriptionMutateAsync(subscription);
    } catch {
      // Mutation callbacks already surface the failure to the user.
    } finally {
      clearRefreshPending(subscription.id);
    }
  }, [clearRefreshPending, markRefreshPending, refreshSubscriptionMutateAsync]);

  const changePageSize = (next: number) => {
    setPageSize(next);
    setPage(0);
  };

  const col = useMemo(() => createColumnHelper<Subscription>(), []);

  const subColumns = useMemo(
    () => [
      col.accessor("name", {
        header: t("名称"),
        cell: (info) => <p className="subscriptions-name-cell">{info.getValue()}</p>,
      }),
      col.accessor("url", {
        header: t("订阅源"),
        cell: (info) => {
          const s = info.row.original;
          if (s.source_type === "local") {
            return (
              <p className="subscriptions-url-cell" title={t("本地订阅")}>
                {t("本地订阅")}
              </p>
            );
          }
          return (
            <p className="subscriptions-url-cell" title={info.getValue()}>
              {extractHostname(info.getValue())}
            </p>
          );
        },
      }),
      col.accessor("update_interval", {
        header: t("更新间隔"),
        cell: (info) => formatGoDuration(info.getValue()),
      }),
      col.display({
        id: "node_count",
        header: t("节点数"),
        cell: (info) => {
          const s = info.row.original;
          return `${s.healthy_node_count} / ${s.node_count}`;
        },
      }),
      col.display({
        id: "status",
        header: t("状态"),
        cell: (info) => {
          const s = info.row.original;
          return (
            <div className="subscriptions-status-cell">
              {!s.enabled ? (
                <Badge variant="warning">{t("已禁用")}</Badge>
              ) : s.last_error ? (
                <Badge variant="danger">{t("错误")}</Badge>
              ) : (
                <Badge variant="success">{t("正常")}</Badge>
              )}
            </div>
          );
        },
      }),
      col.accessor("last_checked", {
        header: t("上次检查"),
        cell: (info) => formatRelativeTime(info.getValue() || ""),
      }),
      col.accessor("last_updated", {
        header: t("上次更新"),
        cell: (info) => formatRelativeTime(info.getValue() || ""),
      }),
      col.display({
        id: "actions",
        header: t("操作"),
        cell: (info) => {
          const s = info.row.original;
          return (
            <div className="subscriptions-row-actions" onClick={(event) => event.stopPropagation()}>
              <Link
                className="btn btn-ghost btn-sm"
                to={`/nodes?subscription_id=${encodeURIComponent(s.id)}`}
                title={t("预览节点池")}
                aria-label={t("预览订阅 {{name}} 的节点池", { name: s.name })}
              >
                <Eye size={14} />
              </Link>
              <Button size="sm" variant="ghost" onClick={() => openDrawer(s)} title={t("编辑")}>
                <Pencil size={14} />
              </Button>
              <Button
                size="sm"
                variant="ghost"
                onClick={() => void handleRefresh(s)}
                disabled={isRefreshPending(s.id)}
                title={t("刷新")}
              >
                <RefreshCw size={14} />
              </Button>
              <Button
                size="sm"
                variant="ghost"
                onClick={() => void handleDelete(s)}
                disabled={isDeletePending}
                title={t("删除")}
                style={{ color: "var(--delete-btn-color, #c27070)" }}
              >
                <Trash2 size={14} />
              </Button>
            </div>
          );
        },
      }),
    ],
    [col, handleDelete, handleRefresh, isDeletePending, isRefreshPending, openDrawer, t]
  );

  return (
    <section className="platform-page">
      <header className="module-header">
        <div>
          <h2>{t("订阅管理")}</h2>
          <p className="module-description">{t("保障订阅按计划更新,异常时可一键刷新。")}</p>
        </div>
      </header>

      <ToastContainer toasts={toasts} onDismiss={dismissToast} />

      <Card className="platform-list-card platform-directory-card">
        <div className="list-card-header">
          <div>
            <h3>{t("订阅列表")}</h3>
            <p>{t("共 {{count}} 个订阅", { count: totalSubscriptions })}</p>
          </div>
          <div style={{ display: "flex", gap: "0.5rem", alignItems: "center" }}>
            <label className="subscription-inline-filter" htmlFor="sub-status-filter" style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
              <Filter size={16} />
              <Select
                id="sub-status-filter"
                value={enabledFilter}
                onChange={(event) => {
                  setEnabledFilter(event.target.value as EnabledFilter);
                  setPage(0);
                }}
              >
                <option value="all">{t("全部")}</option>
                <option value="enabled">{t("仅启用")}</option>
                <option value="disabled">{t("仅禁用")}</option>
              </Select>
            </label>
            <label className="search-box" htmlFor="subscription-search" style={{ maxWidth: 200, margin: 0, gap: 6 }}>
              <Search size={16} />
              <Input
                id="subscription-search"
                placeholder={t("搜索订阅")}
                value={search}
                onChange={(event) => {
                  setSearch(event.target.value);
                  setPage(0);
                }}
                style={{ padding: "6px 10px", borderRadius: 8 }}
              />
            </label>
            <Button
              variant="secondary"
              size="sm"
              onClick={() => setCreateModalOpen(true)}
            >
              <Plus size={16} />
              {t("新建")}
            </Button>
            <Button
              variant="secondary"
              size="sm"
              onClick={() => subscriptionsQuery.refetch()}
              disabled={subscriptionsQuery.isFetching}
            >
              <RefreshCw size={16} className={subscriptionsQuery.isFetching ? "spin" : undefined} />
              {t("刷新")}
            </Button>
          </div>
        </div>
      </Card>

      <Card className="platform-cards-container subscriptions-table-card">
        {subscriptionsQuery.isLoading ? <p className="muted">{t("正在加载订阅数据...")}</p> : null}

        {subscriptionsQuery.isError ? (
          <div className="callout callout-error">
            <AlertTriangle size={14} />
            <span>{formatApiErrorMessage(subscriptionsQuery.error, t)}</span>
          </div>
        ) : null}

        {!subscriptionsQuery.isLoading && !subscriptions.length ? (
          <div className="empty-box">
            <Sparkles size={16} />
            <p>{t("没有匹配的订阅")}</p>
          </div>
        ) : null}

        {subscriptions.length ? (
          <DataTable
            data={subscriptions}
            columns={subColumns}
            onRowClick={openDrawer}
            getRowId={(s) => s.id}
            className="data-table-subs"
          />
        ) : null}

        <OffsetPagination
          page={currentPage}
          totalPages={totalPages}
          totalItems={totalSubscriptions}
          pageSize={pageSize}
          pageSizeOptions={PAGE_SIZE_OPTIONS}
          onPageChange={setPage}
          onPageSizeChange={changePageSize}
        />
      </Card>

      {drawerVisible && selectedSubscription ? (
        <div
          className="drawer-overlay"
          role="dialog"
          aria-modal="true"
          aria-label={t("编辑订阅 {{name}}", { name: selectedSubscription.name })}
          onClick={() => setDrawerOpen(false)}
        >
          <Card className="drawer-panel" onClick={(event) => event.stopPropagation()}>
            <div className="drawer-header">
              <div>
                <h3>{selectedSubscription.name}</h3>
                <p>{selectedSubscription.id}</p>
              </div>
              <div className="drawer-header-actions">
                <Badge variant={selectedSubscription.enabled ? "success" : "warning"}>
                  {selectedSubscription.enabled ? t("运行中") : t("已停用")}
                </Badge>
                <Button
                  variant="ghost"
                  size="sm"
                  aria-label={t("关闭编辑面板")}
                  onClick={() => setDrawerOpen(false)}
                >
                  <X size={16} />
                </Button>
              </div>
            </div>
            <div className="platform-drawer-layout">
              <section className="platform-drawer-section">
                <div className="platform-drawer-section-head">
                  <h4>{t("订阅配置")}</h4>
                  <p>
                    {editSourceType === "local"
                      ? t("更新本地订阅配置、刷新周期与状态开关后点击保存。")
                      : t("更新 URL、刷新周期与状态开关后点击保存。")}
                  </p>
                </div>

                <div className="stats-grid">
                  <div>
                    <span>{t("创建时间")}</span>
                    <p>{formatDateTime(selectedSubscription.created_at)}</p>
                  </div>
                  <div>
                    <span>{t("上次检查")}</span>
                    <p>{formatDateTime(selectedSubscription.last_checked || "")}</p>
                  </div>
                  <div>
                    <span>{t("上次更新")}</span>
                    <p>{formatDateTime(selectedSubscription.last_updated || "")}</p>
                  </div>
                </div>

                {selectedSubscription.last_error ? (
                  <div className="callout callout-error">{t("最近错误:{{message}}", { message: selectedSubscription.last_error })}</div>
                ) : (
                  <div className="callout callout-success">{t("最近一次刷新无错误")}</div>
                )}

                <form className="form-grid" onSubmit={onEditSubmit}>
                  <input type="hidden" {...editForm.register("source_type")} />

                  <div className="field-group">
                    <label className="field-label" htmlFor="edit-sub-name">
                      {t("订阅名称")}
                    </label>
                    <Input
                      id="edit-sub-name"
                      invalid={Boolean(editForm.formState.errors.name)}
                      {...editForm.register("name")}
                    />
                    {editForm.formState.errors.name?.message ? (
                      <p className="field-error">{t(editForm.formState.errors.name.message)}</p>
                    ) : null}
                  </div>

                  <div className="field-group">
                    <label className="field-label" htmlFor="edit-sub-source-type">
                      {t("订阅类型")}
                    </label>
                    <Input
                      id="edit-sub-source-type"
                      value={t(sourceTypeLabel(editSourceType))}
                      readOnly
                      disabled
                    />
                  </div>

                  {editSourceType === "remote" ? (
                    <>
                      <div className="field-group field-span-2">
                        <label className="field-label" htmlFor="edit-sub-interval">
                          {t("更新间隔")}
                        </label>
                        <Input
                          id="edit-sub-interval"
                          placeholder={t("例如 12h")}
                          invalid={Boolean(editForm.formState.errors.update_interval)}
                          {...editForm.register("update_interval")}
                        />
                        {editForm.formState.errors.update_interval?.message ? (
                          <p className="field-error">{t(editForm.formState.errors.update_interval.message)}</p>
                        ) : null}
                      </div>

                      <div className="field-group field-span-2">
                        <label className="field-label" htmlFor="edit-sub-url">
                          {t("订阅链接")}
                        </label>
                        <Input id="edit-sub-url" invalid={Boolean(editForm.formState.errors.url)} {...editForm.register("url")} />
                        {editForm.formState.errors.url?.message ? (
                          <p className="field-error">{t(editForm.formState.errors.url.message)}</p>
                        ) : null}
                      </div>
                    </>
                  ) : (
                    <div className="field-group field-span-2">
                      <label className="field-label" htmlFor="edit-sub-content">
                        {t("订阅内容")}
                      </label>
                      <Textarea
                        id="edit-sub-content"
                        rows={8}
                        placeholder={subscriptionContentPlaceholder}
                        invalid={Boolean(editForm.formState.errors.content)}
                        {...editForm.register("content")}
                      />
                      {editForm.formState.errors.content?.message ? (
                        <p className="field-error">{t(editForm.formState.errors.content.message)}</p>
                      ) : null}
                    </div>
                  )}

                  <div className="field-group">
                    <label className="field-label" htmlFor="edit-sub-ephemeral" style={{ visibility: "hidden" }}>
                      {t("临时订阅")}
                    </label>
                    <div className="subscription-switch-item">
                      <label className="subscription-switch-label" htmlFor="edit-sub-ephemeral">
                        <span>{t("临时订阅")}</span>
                        <span
                          className="subscription-info-icon"
                          title={t(SUBSCRIPTION_EPHEMERAL_HINT)}
                          aria-label={t(SUBSCRIPTION_EPHEMERAL_HINT)}
                          tabIndex={0}
                        >
                          <Info size={13} />
                        </span>
                      </label>
                      <Switch id="edit-sub-ephemeral" {...editForm.register("ephemeral")} />
                    </div>
                  </div>

                  <div className="field-group">
                    <label className="field-label" htmlFor="edit-sub-incremental-alive-nodes" style={{ visibility: "hidden" }}>
                      {t("存活节点增量模式")}
                    </label>
                    <div className="subscription-switch-item">
                      <label className="subscription-switch-label" htmlFor="edit-sub-incremental-alive-nodes">
                        <span>{t("存活节点增量模式")}</span>
                        <span
                          className="subscription-info-icon"
                          title={t(SUBSCRIPTION_INCREMENTAL_HINT)}
                          aria-label={t(SUBSCRIPTION_INCREMENTAL_HINT)}
                          tabIndex={0}
                        >
                          <Info size={13} />
                        </span>
                      </label>
                      <Switch id="edit-sub-incremental-alive-nodes" {...editForm.register("incremental_alive_nodes")} />
                    </div>
                  </div>

                  <div className="field-group">
                    <label className="field-label" htmlFor="edit-sub-ephemeral-evict-delay">
                      {t("临时节点驱逐延迟")}
                    </label>
                    <Input
                      id="edit-sub-ephemeral-evict-delay"
                      placeholder={t("例如 72h")}
                      invalid={Boolean(editForm.formState.errors.ephemeral_node_evict_delay)}
                      disabled={!editEphemeral}
                      {...editForm.register("ephemeral_node_evict_delay")}
                    />
                    {editForm.formState.errors.ephemeral_node_evict_delay?.message ? (
                      <p className="field-error">{t(editForm.formState.errors.ephemeral_node_evict_delay.message)}</p>
                    ) : null}
                  </div>

                  <div className="field-group">
                    <label className="field-label" htmlFor="edit-sub-enabled" style={{ visibility: "hidden" }}>
                      {t("启用")}
                    </label>
                    <div className="subscription-switch-item">
                      <label className="subscription-switch-label" htmlFor="edit-sub-enabled">
                        <span>{t("启用")}</span>
                        <span
                          className="subscription-info-icon"
                          title={t(SUBSCRIPTION_DISABLE_HINT)}
                          aria-label={t(SUBSCRIPTION_DISABLE_HINT)}
                          tabIndex={0}
                        >
                          <Info size={13} />
                        </span>
                      </label>
                      <Switch id="edit-sub-enabled" {...editForm.register("enabled")} />
                    </div>
                  </div>

                  <div className="platform-config-actions">
                    <Button type="submit" disabled={updateMutation.isPending}>
                      {updateMutation.isPending ? t("保存中...") : t("保存配置")}
                    </Button>
                  </div>
                </form>
              </section>

              <section className="platform-drawer-section platform-ops-section">
                <div className="platform-drawer-section-head">
                  <h4>{t("运维操作")}</h4>
                </div>

                <div className="platform-ops-list">
                  <div className="platform-op-item">
                    <div className="platform-op-copy">
                      <h5>{t("手动刷新")}</h5>
                      <p className="platform-op-hint">{t("立即刷新订阅并同步节点。")}</p>
                    </div>
                    <Button
                      variant="secondary"
                      onClick={() => void handleRefresh(selectedSubscription)}
                      disabled={isRefreshPending(selectedSubscription.id)}
                    >
                      {isRefreshPending(selectedSubscription.id) ? t("刷新中...") : t("立即刷新")}
                    </Button>
                  </div>

                  <div className="platform-op-item">
                    <div className="platform-op-copy">
                      <h5>{t("清理失效节点")}</h5>
                      <p className="platform-op-hint">{t("立即清理当前熔断,或出错的节点。")}</p>
                    </div>
                    <Button
                      variant="secondary"
                      onClick={() => void handleCleanupCircuitOpenNodes(selectedSubscription)}
                      disabled={cleanupCircuitOpenNodesMutation.isPending}
                    >
                      {cleanupCircuitOpenNodesMutation.isPending ? t("清理中...") : t("立即清理")}
                    </Button>
                  </div>

                  <div className="platform-op-item">
                    <div className="platform-op-copy">
                      <h5>{t("删除订阅")}</h5>
                      <p className="platform-op-hint">{t("删除订阅并清理关联节点,操作不可撤销。")}</p>
                    </div>
                    <Button
                      variant="danger"
                      onClick={() => void handleDelete(selectedSubscription)}
                      disabled={deleteMutation.isPending}
                    >
                      {deleteMutation.isPending ? t("删除中...") : t("删除订阅")}
                    </Button>
                  </div>
                </div>
              </section>
            </div>
          </Card>
        </div>
      ) : null}

      {createModalOpen ? (
        <div className="modal-overlay" role="dialog" aria-modal="true">
          <Card className="modal-card">
            <div className="modal-header">
              <h3>{t("新建订阅")}</h3>
              <Button variant="ghost" size="sm" onClick={() => setCreateModalOpen(false)}>
                <X size={16} />
              </Button>
            </div>

            <form className="form-grid" onSubmit={onCreateSubmit}>
              <input type="hidden" {...createForm.register("source_type")} />

              <div className="field-group field-span-2">
                <label className="field-label" htmlFor="create-sub-name">
                  {t("订阅名称")}
                </label>
                <Input
                  id="create-sub-name"
                  invalid={Boolean(createForm.formState.errors.name)}
                  {...createForm.register("name")}
                />
                {createForm.formState.errors.name?.message ? (
                  <p className="field-error">{t(createForm.formState.errors.name.message)}</p>
                ) : null}
              </div>

              <div className="field-group field-span-2">
                <label className="field-label">{t("订阅来源")}</label>
                <div className="platform-detail-tabs" role="tablist" aria-label={t("订阅来源类型")}>
                  {SUBSCRIPTION_SOURCE_TABS.map((tab) => {
                    const selected = createSourceType === tab.key;
                    return (
                      <button
                        key={tab.key}
                        type="button"
                        role="tab"
                        aria-selected={selected}
                        className={`platform-detail-tab ${selected ? "platform-detail-tab-active" : ""}`}
                        title={t(tab.hint)}
                        onClick={() => createForm.setValue("source_type", tab.key, { shouldDirty: true, shouldValidate: true })}
                      >
                        <span>{t(tab.label)}</span>
                      </button>
                    );
                  })}
                </div>
              </div>

              {createSourceType === "remote" ? (
                <>
                  <div className="field-group field-span-2">
                    <label className="field-label" htmlFor="create-sub-interval">
                      {t("更新间隔")}
                    </label>
                    <Input
                      id="create-sub-interval"
                      placeholder={t("例如 12h")}
                      invalid={Boolean(createForm.formState.errors.update_interval)}
                      {...createForm.register("update_interval")}
                    />
                    {createForm.formState.errors.update_interval?.message ? (
                      <p className="field-error">{t(createForm.formState.errors.update_interval.message)}</p>
                    ) : null}
                  </div>

                  <div className="field-group field-span-2">
                    <label className="field-label" htmlFor="create-sub-url">
                      {t("订阅链接")}
                    </label>
                    <Input
                      id="create-sub-url"
                      invalid={Boolean(createForm.formState.errors.url)}
                      {...createForm.register("url")}
                    />
                    {createForm.formState.errors.url?.message ? (
                      <p className="field-error">{t(createForm.formState.errors.url.message)}</p>
                    ) : null}
                  </div>
                </>
              ) : (
                <div className="field-group field-span-2">
                  <label className="field-label" htmlFor="create-sub-content">
                    {t("订阅内容")}
                  </label>
                  <Textarea
                    id="create-sub-content"
                    rows={8}
                    placeholder={subscriptionContentPlaceholder}
                    invalid={Boolean(createForm.formState.errors.content)}
                    {...createForm.register("content")}
                  />
                  {createForm.formState.errors.content?.message ? (
                    <p className="field-error">{t(createForm.formState.errors.content.message)}</p>
                  ) : null}
                </div>
              )}

              <div className="field-group">
                <label className="field-label" htmlFor="create-sub-ephemeral" style={{ visibility: "hidden" }}>
                  {t("临时订阅")}
                </label>
                <div className="subscription-switch-item">
                  <label className="subscription-switch-label" htmlFor="create-sub-ephemeral">
                    <span>{t("临时订阅")}</span>
                    <span
                      className="subscription-info-icon"
                      title={t(SUBSCRIPTION_EPHEMERAL_HINT)}
                      aria-label={t(SUBSCRIPTION_EPHEMERAL_HINT)}
                      tabIndex={0}
                    >
                      <Info size={13} />
                    </span>
                  </label>
                  <Switch id="create-sub-ephemeral" {...createForm.register("ephemeral")} />
                </div>
              </div>

              <div className="field-group">
                <label className="field-label" htmlFor="create-sub-incremental-alive-nodes" style={{ visibility: "hidden" }}>
                  {t("存活节点增量模式")}
                </label>
                <div className="subscription-switch-item">
                  <label className="subscription-switch-label" htmlFor="create-sub-incremental-alive-nodes">
                    <span>{t("存活节点增量模式")}</span>
                    <span
                      className="subscription-info-icon"
                      title={t(SUBSCRIPTION_INCREMENTAL_HINT)}
                      aria-label={t(SUBSCRIPTION_INCREMENTAL_HINT)}
                      tabIndex={0}
                    >
                      <Info size={13} />
                    </span>
                  </label>
                  <Switch id="create-sub-incremental-alive-nodes" {...createForm.register("incremental_alive_nodes")} />
                </div>
              </div>

              <div className="field-group">
                <label className="field-label" htmlFor="create-sub-ephemeral-evict-delay">
                  {t("临时节点驱逐延迟")}
                </label>
                <Input
                  id="create-sub-ephemeral-evict-delay"
                  placeholder={t("例如 72h")}
                  invalid={Boolean(createForm.formState.errors.ephemeral_node_evict_delay)}
                  disabled={!createEphemeral}
                  {...createForm.register("ephemeral_node_evict_delay")}
                />
                {createForm.formState.errors.ephemeral_node_evict_delay?.message ? (
                  <p className="field-error">{t(createForm.formState.errors.ephemeral_node_evict_delay.message)}</p>
                ) : null}
              </div>

              <div className="field-group">
                <label className="field-label" htmlFor="create-sub-enabled" style={{ visibility: "hidden" }}>
                  {t("启用")}
                </label>
                <div className="subscription-switch-item">
                  <label className="subscription-switch-label" htmlFor="create-sub-enabled">
                    <span>{t("启用")}</span>
                    <span
                      className="subscription-info-icon"
                      title={t(SUBSCRIPTION_DISABLE_HINT)}
                      aria-label={t(SUBSCRIPTION_DISABLE_HINT)}
                      tabIndex={0}
                    >
                      <Info size={13} />
                    </span>
                  </label>
                  <Switch id="create-sub-enabled" {...createForm.register("enabled")} />
                </div>
              </div>

              <div className="detail-actions" style={{ justifyContent: "flex-end" }}>
                <Button type="submit" disabled={createMutation.isPending}>
                  {createMutation.isPending ? t("创建中...") : t("确认创建")}
                </Button>
                <Button variant="secondary" onClick={() => setCreateModalOpen(false)}>
                  {t("取消")}
                </Button>
              </div>
            </form>
          </Card>
        </div>
      ) : null}
    </section>
  );
}