import type { ReactNode } from 'react';
import { IconSpark } from './icons';
import './badge.css';

// ── StatusBadge (design.md §1-4) ──
export type FlowStatus =
  | 'draft'
  | 'submitted'
  | 'ai-review'
  | 'approved'
  | 'rejected'
  | 'building'
  | 'inspected';

const STATUS_LABEL: Record<FlowStatus, string> = {
  draft: '작성중',
  submitted: '제출됨',
  'ai-review': 'AI검토',
  approved: '승인',
  rejected: '반려',
  building: '시공중',
  inspected: '검수완료',
};

/** 신청 흐름 상태 배지 — 모든 목록·카드 공통. */
export function StatusBadge({ status }: { status: FlowStatus }) {
  return (
    <span className={`kx-badge kx-badge--status-${status}`}>{STATUS_LABEL[status]}</span>
  );
}

/** 역할 배지 (SCR-01 워크스페이스 카드). */
export function RoleBadge({ role }: { role: string }) {
  const label =
    role === 'ORGANIZER'
      ? '주최자'
      : role === 'EXHIBITOR'
        ? '참가업체'
        : role === 'CONTRACTOR'
          ? '장치업체'
          : role === 'HALL_MANAGER'
            ? '홀매니저'
            : role;
  return <span className="kx-badge kx-badge--role">{label}</span>;
}

/** D-데이 칩 — D-3 이내 warning, 초과 error. */
export function DdayChip({ dday }: { dday: number }) {
  const tone = dday < 0 ? 'over' : dday <= 3 ? 'warn' : 'normal';
  const text = dday < 0 ? `D+${Math.abs(dday)}` : `D-${dday}`;
  return <span className={`kx-badge kx-badge--dday-${tone} tnum`}>{text}</span>;
}

/** AI 라벨 — 보라 외곽선 칩. */
export function AiLabel({ children = 'AI 초안' }: { children?: ReactNode }) {
  return (
    <span className="kx-badge kx-badge--ai">
      <span className="kx-badge__spark" aria-hidden="true"><IconSpark size={12} /></span>
      {children}
    </span>
  );
}
