'use client';

import { useRouter } from 'next/navigation';
import PaperClipSvg from '../svgs/paperclipsvg';

type ResourceRow = {
  id: number;
  title: string;
  date: string;
  views: number;
  writer: string;
  hasAttachment?: boolean;
};

const rows: ResourceRow[] = [
  {
    id: 6,
    title: '방사선과 물질의 상호작용 관련 학습 자료',
    date: '2025-06-28',
    views: 1230,
    writer: '강민재',
    hasAttachment: true,
  },
  {
    id: 5,
    title: '감마선과 베타선의 특성 및 차이 분석 자료',
    date: '2025-06-28',
    views: 594,
    writer: '강민재',
  },
  {
    id: 4,
    title: '방사선량 단위(Sv, Gy) 비교 및 계산 예제',
    date: '2025-06-28',
    views: 1230,
    writer: '강민재',
  },
  {
    id: 3,
    title: '의료 영상 촬영 시 방사선 안전 수칙 가이드',
    date: '2025-06-28',
    views: 1230,
    writer: '강민재',
  },
  {
    id: 2,
    title: 'X선 발생 원리 및 특성에 대한 이해 자료',
    date: '2025-06-28',
    views: 1230,
    writer: '강민재',
  },
  {
    id: 1,
    title: '방사선의 기초 개념과 물질과의 상호작용 정리 자료',
    date: '2025-06-28',
    views: 1230,
    writer: '강민재',
  },
];

export default function ResourcesPage() {
  const router = useRouter();

  return (
    <div className="w-full bg-white">
      <div className="flex justify-center">
        <div className="w-full max-w-[1440px]">
          {/* 헤더 영역 */}
          <div className="h-[100px] flex items-center px-8">
            <h1 className="m-0 text-[24px] font-bold leading-[1.5] text-[#1B2027]">
              학습 자료실
            </h1>
          </div>

          {/* 본문 영역 */}
          <section className="px-8 pb-8">
            {/* 총 건수 */}
            <div className="h-10 flex items-center">
              <p className="m-0 text-[15px] font-medium leading-[1.5] text-[#333C47]">
                총 <span className="text-[#384FBF]">{rows.length}</span>건
              </p>
            </div>

            {/* 표 */}
            <div className="rounded-[8px] border border-[#DEE1E6] overflow-hidden bg-white">
              {/* 헤더 */}
              <div className="grid grid-cols-[57px_1fr_140px_140px_140px] bg-[#F9FAFB] h-[48px] text-[14px] font-semibold text-[#4C5561] border-b border-[#DEE1E6]">
                <div className="flex items-center justify-center px-4 border-r border-[#DEE1E6] whitespace-nowrap">
                  번호
                </div>
                <div className="flex items-center px-4 border-r border-[#DEE1E6] whitespace-nowrap">
                  제목
                </div>
                <div className="flex items-center px-4 border-r border-[#DEE1E6] whitespace-nowrap">
                  게시일
                </div>
                <div className="flex items-center px-4 border-r border-[#DEE1E6] whitespace-nowrap">
                  조회수
                </div>
                <div className="flex items-center px-4 whitespace-nowrap">등록자</div>
              </div>

              {/* 바디 */}
              <div>
                {rows.map((r) => (
                  <div
                    key={r.id}
                    role="button"
                    tabIndex={0}
                    onClick={() => router.push(`/resources/${r.id}`)}
                    onKeyDown={(e) => {
                      if (e.key === 'Enter' || e.key === ' ') {
                        e.preventDefault();
                        router.push(`/resources/${r.id}`);
                      }
                    }}
                    className={[
                      'grid grid-cols-[57px_1fr_140px_140px_140px] h-[48px] text-[15px] font-medium text-[#1B2027] border-t border-[#DEE1E6] hover:bg-[rgba(236,240,255,0.5)] cursor-pointer',
                    ].join(' ')}
                  >
                    <div className="flex items-center justify-center px-2 whitespace-nowrap border-r border-[#DEE1E6]">
                      {r.id}
                    </div>
                    <div
                      className="flex items-center gap-1.5 px-4 border-r border-[#DEE1E6] whitespace-nowrap overflow-hidden text-ellipsis"
                      title={r.title}
                    >
                      {r.title}
                      {r.hasAttachment && (
                        <PaperClipSvg width={16} height={16} className="shrink-0 text-[#8C95A1]" />
                      )}
                    </div>
                    <div className="flex items-center px-4 border-r border-[#DEE1E6]">
                      {r.date}
                    </div>
                    <div className="flex items-center px-4 border-r border-[#DEE1E6]">
                      {r.views.toLocaleString()}
                    </div>
                    <div className="flex items-center px-4">{r.writer}</div>
                  </div>
                ))}
              </div>
            </div>
          </section>
        </div>
      </div>
    </div>
  );
}


