"use client";

import { FaCoins } from "react-icons/fa6";

import styles from "./sidebar-wallet-card.module.css";

export interface SidebarWalletCardProps {
  creditBalance: number;
  onActivateVip?: () => void;
  onTopUp: () => void;
  onRulesClick: () => void;
}

const formatCoins = (value: number): string =>
  new Intl.NumberFormat("en-US").format(Math.max(0, Math.trunc(value)));

export function SidebarWalletCard({
  creditBalance,
  onActivateVip,
  onTopUp,
  onRulesClick,
}: SidebarWalletCardProps) {
  return (
    <section className={styles.card} aria-label="My wallet">
      <div className={styles.leftColumn}>
        <div className={styles.titleRow}>
          <span className={styles.iconWrap} aria-hidden="true">
            <FaCoins size={18} />
          </span>
          <h2 className={styles.title}>My Wallet</h2>
        </div>

        <p className={styles.balance}>
          <span className={styles.balanceValue}>{formatCoins(creditBalance)}</span>
          <span className={styles.balanceUnit}> coins</span>
        </p>

        <button
          type="button"
          className={styles.rulesButton}
          onClick={onRulesClick}
        >
          Coin Usage Rules
        </button>
      </div>

      <div className={styles.actionColumn}>
        {onActivateVip ? (
          <button
            type="button"
            className={styles.activateButton}
            onClick={onActivateVip}
          >
            Activate VIP
          </button>
        ) : null}
        <button type="button" className={styles.topUpButton} onClick={onTopUp}>
          Top Up
        </button>
      </div>
    </section>
  );
}
