"use client";
/**
 * 订阅套餐卡片
 *
 * 视觉规格（与设计稿对齐）：
 *   - 卡片顶部：套餐名（12px / secondary）
 *   - 中部：大字价格（28px / 300）+ 划线原价（12px / line-through / 999）
 *   - 底部 28px 高色条：白字 12px/600 每日折算价
 *   - 选中：2px 粉色边框 + 浅粉阴影
 *   - 三个卡片底部色条不同：粉 → 亮粉 → 紫
 */

import styles from "./subscription-plan-card.module.css";

const PER_DAY_COLORS = [
  "#f657a0",
  "#fa77e3",
  "#bb72f9",
] as const;

export interface SubscriptionPlanView {
  id: string;
  name: string;
  price: string;
  originalPrice: string | null;
  perDay: string;
  currencySymbol: string;
}

export interface SubscriptionPlanCardProps {
  plan: SubscriptionPlanView;
  selected: boolean;
  onClick: () => void;
  gradientIndex?: number;
  className?: string;
}

export function SubscriptionPlanCard({
  plan,
  selected,
  onClick,
  gradientIndex = 0,
  className,
}: SubscriptionPlanCardProps) {
  const classes = [
    styles.card,
    selected ? styles.selected : "",
    selected && gradientIndex === 0 ? styles.firstSelected : "",
    className,
  ]
    .filter(Boolean)
    .join(" ");

  const perDayStyle = {
    backgroundColor: PER_DAY_COLORS[gradientIndex % PER_DAY_COLORS.length],
  };

  return (
    <button
      type="button"
      onClick={onClick}
      aria-pressed={selected}
      aria-label={`${plan.name} plan, ${plan.currencySymbol}${plan.price}`}
      className={classes}
    >
      <p className={styles.name}>{plan.name}</p>
      <div className={styles.priceBlock}>
        <span className={styles.currency}>{plan.currencySymbol}</span>
        <span className={styles.price}>{plan.price}</span>
      </div>
      <p className={styles.originalPrice}>
        {plan.originalPrice ?? "\u00a0"}
      </p>
      <div className={styles.perDayBar} style={perDayStyle}>
        {plan.perDay}
      </div>
    </button>
  );
}
