// @design-system: domain/DraftsBanner

import { cn } from '@/lib/cn';
import { Icon } from '@/components/ui/icons/Icon';
import { useT } from '@/lib/i18n/react';
import { useDraftsBannerStore } from './draftsBannerStore';

// ── Component ────────────────────────────────────────────────────────────────

/** Props for DraftsBanner */
export interface DraftsBannerProps {
  /** Number of deal drafts for this vendor. Renders null when 0. */
  count: number;
  /** Additional class names. */
  className?: string;
}

/**
 * DraftsBanner — amber-tinted banner shown on vendor dashboard when the vendor
 * has deal drafts. Links to /vendor/deals/drafts. Dismissable for the session.
 *
 * @example
 * ```tsx
 * <DraftsBanner count={3} />
 * ```
 */
export function DraftsBanner({ count, className }: DraftsBannerProps) {
  const t = useT('vendorDrafts');
  const { dismissed, dismiss } = useDraftsBannerStore();

  if (count === 0 || dismissed) return null;

  const text = count === 1 ? t('bannerOne') : t('bannerMany').replace('{n}', String(count));

  return (
    <aside
      role="note"
      className={cn(
        'border-warning-400 bg-warning-50 flex items-center gap-3 rounded-xl border px-4 py-3',
        className,
      )}
    >
      <span className="text-warning-600 shrink-0" aria-hidden="true">
        <Icon name="FileText" size="sm" />
      </span>

      <a
        href="/vendor/deals/drafts"
        className="text-warning-800 min-w-0 flex-1 text-sm font-medium underline-offset-2 hover:underline focus-visible:underline focus-visible:outline-none"
      >
        {text}
      </a>

      <button
        type="button"
        onClick={dismiss}
        aria-label={t('dismiss')}
        className="text-warning-600 hover:text-warning-800 focus-visible:ring-warning-500 shrink-0 rounded focus-visible:ring-2 focus-visible:outline-none"
      >
        <Icon name="X" size="sm" aria-hidden={true} />
      </button>
    </aside>
  );
}
