'use client';

import type { SourceType, DocumentCategory } from '@/types/firestore';

interface UnverifiedBannerProps {
  severity?: 'info' | 'caution';
  category?: DocumentCategory;
  sourceType?: SourceType;
  className?: string;
}

function resolveSeverity(
  severity?: 'info' | 'caution',
  category?: DocumentCategory,
  sourceType?: SourceType,
): 'info' | 'caution' {
  if (severity !== undefined) return severity;
  if (category === 'practice' && sourceType === 'user_submitted') return 'caution';
  return 'info';
}

const InfoIcon = () => (
  <svg className="w-5 h-5 text-blue-500" viewBox="0 0 20 20" fill="currentColor">
    <path
      fillRule="evenodd"
      d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z"
      clipRule="evenodd"
    />
  </svg>
);

const WarningIcon = () => (
  <svg className="w-5 h-5 text-amber-500" viewBox="0 0 20 20" fill="currentColor">
    <path
      fillRule="evenodd"
      d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
      clipRule="evenodd"
    />
  </svg>
);

const SEVERITY_CONFIG = {
  info: {
    styles: 'bg-blue-50 border-blue-300',
    icon: <InfoIcon />,
    title: '참고 정보',
    message: '이 문서는 아직 전문가 검증을 거치지 않았습니다.',
  },
  caution: {
    styles: 'bg-amber-50 border-amber-300',
    icon: <WarningIcon />,
    title: '미검증 실무 정보',
    message: '이 문서는 사용자 제출 실무 정보로, 전문가 검증이 필요합니다. 실무 적용 전 반드시 확인하세요.',
  },
} as const;

export default function UnverifiedBanner({
  severity,
  category,
  sourceType,
  className,
}: UnverifiedBannerProps) {
  const resolvedSeverity = resolveSeverity(severity, category, sourceType);
  const { styles, icon, title, message } = SEVERITY_CONFIG[resolvedSeverity];

  return (
    <div
      role="alert"
      className={`border-l-4 rounded-r-lg p-4 ${styles} ${className || ''}`}
    >
      <div className="flex items-start gap-3">
        <span aria-hidden="true">{icon}</span>
        <div>
          <p className="text-sm font-medium">{title}</p>
          <p className="text-xs mt-1">{message}</p>
        </div>
      </div>
    </div>
  );
}
