import { SOCIAL_TYPE_OPTIONS } from "@/config/form";
import { maskRecipient } from "@/config/mail";

export type PlanCycleType = "daily" | "weekly" | "monthly";
export type PlanStatus = "inProgress" | "completed" | "paused";

export interface PlanCycleOption {
  type: PlanCycleType;
  name: string;
  desc: string;
}

export interface PlanSubmitPayload {
  cycleType: PlanCycleType;
  cycleName: string;
  socialType: number;
  socialTypeName: string;
  socialAccount: string;
  content: string;
}

export interface PlanItem {
  id: string;
  cycleType: PlanCycleType;
  cycleName: string;
  socialTypeName: string;
  socialAccount: string;
  content: string;
  nextRunTime: string;
  createdAt: string;
  status: PlanStatus;
}

export const PLAN_CYCLE_OPTIONS: PlanCycleOption[] = [
  {
    type: "daily",
    name: "每天",
    desc: "每天定时传达一次",
  },
  {
    type: "weekly",
    name: "每周",
    desc: "每周固定传达一次",
  },
  {
    type: "monthly",
    name: "每月",
    desc: "每月固定传达一次",
  },
];

export const PLAN_STATUS_TABS = [
  { name: "全部", value: "all" },
  { name: "进行中", value: "inProgress" },
  { name: "已完成", value: "completed" },
] as const;

export const PLAN_STATUS_META: Record<PlanStatus, { text: string; className: string }> = {
  inProgress: {
    text: "进行中",
    className: "status-running",
  },
  completed: {
    text: "已完成",
    className: "status-done",
  },
  paused: {
    text: "已暂停",
    className: "status-paused",
  },
};

export const PLAN_SOCIAL_OPTIONS = SOCIAL_TYPE_OPTIONS.filter((item) => item.value !== 6);

export const MOCK_PLAN_LIST: PlanItem[] = [
  {
    id: "PL250503001",
    cycleType: "daily",
    cycleName: "每天",
    socialTypeName: "手机短信",
    socialAccount: "19878384602",
    content: "每天都想轻轻问候你一下，希望你今天也能顺利一点。",
    nextRunTime: "2026-05-04 20:00:00",
    createdAt: "2026-05-03 18:30:00",
    status: "inProgress",
  },
  {
    id: "PL250502002",
    cycleType: "weekly",
    cycleName: "每周",
    socialTypeName: "微信",
    socialAccount: "moonlight_520",
    content: "每周给你留一句温柔的话，不催促，只表达我的在意。",
    nextRunTime: "2026-05-09 21:00:00",
    createdAt: "2026-05-02 21:12:00",
    status: "inProgress",
  },
  {
    id: "PL250501003",
    cycleType: "monthly",
    cycleName: "每月",
    socialTypeName: "QQ",
    socialAccount: "1289045216",
    content: "这个月也想认真祝你平安顺利，愿你越来越轻松。",
    nextRunTime: "2026-06-01 09:30:00",
    createdAt: "2026-05-01 09:18:00",
    status: "inProgress",
  },
  {
    id: "PL250430004",
    cycleType: "daily",
    cycleName: "每天",
    socialTypeName: "手机短信",
    socialAccount: "13677268104",
    content: "晚安，愿你今晚能睡得安心一点。",
    nextRunTime: "2026-04-30 23:00:00",
    createdAt: "2026-04-28 22:10:00",
    status: "completed",
  },
  {
    id: "PL250428005",
    cycleType: "weekly",
    cycleName: "每周",
    socialTypeName: "企业微信",
    socialAccount: "yanxi_2026",
    content: "想把没说好的话慢慢说清楚，也尊重你的节奏。",
    nextRunTime: "2026-05-05 19:30:00",
    createdAt: "2026-04-28 16:02:00",
    status: "paused",
  },
];

export const maskSocialAccount = (account: string): string => {
  if (/^1\d{10}$/.test(account)) {
    return maskRecipient(account);
  }

  if (account.length <= 6) {
    return account;
  }

  return `${account.slice(0, 3)}***${account.slice(-3)}`;
};
