/**
 * 站内信动作类型常量（与后端 AdminNoticeActionTypeEnum 对齐）
 */
export const NOTICE_ACTION = {
  OPEN_WITHDRAW_AUDIT: 'open_withdraw_audit',
  OPEN_WAREHOUSE_PRODUCT_AUDIT: 'open_warehouse_product_audit',
  OPEN_STORE_INPUT_AUDIT: 'open_store_input_audit',
  OPEN_DOCTOR_INPUT_AUDIT: 'open_doctor_input_audit',
  OPEN_INVOICE_TODO: 'open_invoice_todo',
  OPEN_PERIOD_REPORT: 'open_period_report',
  OPEN_VIP_CARD: 'open_vip_card',
  OPEN_ROUTE: 'open_route',
  OPEN_QUEUE_JOB_DETAIL: 'open_queue_job_detail',
} as const;

export type NoticeActionType =
  (typeof NOTICE_ACTION)[keyof typeof NOTICE_ACTION];

export interface NoticeItemLike {
  id: number;
  title?: string;
  detail?: string;
  content?: string;
  type?: number;
  type_code?: string;
  type_name?: string;
  type_icon?: string;
  type_color?: string;
  action_type?: string;
  action_payload?: Record<string, any> | null;
  cover_url?: string;
  priority?: number;
  status?: number;
  edit_type?: number;
  created_at?: string;
  [key: string]: any;
}

/** 主题色 → Tailwind 类名（亮/暗自适应） */
export const NOTICE_COLOR_MAP: Record<
  string,
  { text: string; bg: string; border: string; bar: string }
> = {
  sky: {
    text: 'text-sky-500',
    bg: 'bg-sky-500/10',
    border: 'border-sky-500/30',
    bar: 'bg-sky-500',
  },
  amber: {
    text: 'text-amber-500',
    bg: 'bg-amber-500/10',
    border: 'border-amber-500/30',
    bar: 'bg-amber-500',
  },
  emerald: {
    text: 'text-emerald-500',
    bg: 'bg-emerald-500/10',
    border: 'border-emerald-500/30',
    bar: 'bg-emerald-500',
  },
  teal: {
    text: 'text-teal-500',
    bg: 'bg-teal-500/10',
    border: 'border-teal-500/30',
    bar: 'bg-teal-500',
  },
  cyan: {
    text: 'text-cyan-500',
    bg: 'bg-cyan-500/10',
    border: 'border-cyan-500/30',
    bar: 'bg-cyan-500',
  },
  orange: {
    text: 'text-orange-500',
    bg: 'bg-orange-500/10',
    border: 'border-orange-500/30',
    bar: 'bg-orange-500',
  },
  violet: {
    text: 'text-violet-500',
    bg: 'bg-violet-500/10',
    border: 'border-violet-500/30',
    bar: 'bg-violet-500',
  },
  indigo: {
    text: 'text-indigo-500',
    bg: 'bg-indigo-500/10',
    border: 'border-indigo-500/30',
    bar: 'bg-indigo-500',
  },
  blue: {
    text: 'text-blue-500',
    bg: 'bg-blue-500/10',
    border: 'border-blue-500/30',
    bar: 'bg-blue-500',
  },
  green: {
    text: 'text-green-500',
    bg: 'bg-green-500/10',
    border: 'border-green-500/30',
    bar: 'bg-green-500',
  },
  red: {
    text: 'text-red-500',
    bg: 'bg-red-500/10',
    border: 'border-red-500/30',
    bar: 'bg-red-500',
  },
  lime: {
    text: 'text-lime-500',
    bg: 'bg-lime-500/10',
    border: 'border-lime-500/30',
    bar: 'bg-lime-500',
  },
};

/**
 * 未读重要卡片微光色相（与 type_color token 对齐，供 CSS hsl(var(--notice-glow) / a)）
 */
export const NOTICE_GLOW_HSL: Record<string, string> = {
  sky: '199 89% 48%',
  amber: '38 92% 50%',
  emerald: '160 84% 39%',
  teal: '173 80% 40%',
  cyan: '189 94% 43%',
  orange: '25 95% 53%',
  violet: '262 83% 58%',
  indigo: '239 84% 67%',
  blue: '217 91% 60%',
  green: '142 71% 45%',
  red: '0 84% 60%',
  lime: '84 81% 44%',
};

export function resolveNoticeColor(color?: string) {
  return NOTICE_COLOR_MAP[color || 'sky'] || NOTICE_COLOR_MAP.sky;
}

/** 解析类型微光 HSL 通道 */
export function resolveNoticeGlow(color?: string) {
  return NOTICE_GLOW_HSL[color || 'sky'] || NOTICE_GLOW_HSL.sky;
}
