"use client"; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { isAdminLoggedIn } from '../../lib/auth'; import LoginPage from '../login/page'; import Close from '../../public/svg/close'; import Logout from '../../public/svg/logout'; const imgLogo = "http://localhost:3845/assets/89fda8e949171025b1232bae70fc9d442e4e70c8.png"; const imgArrowDisabled = "http://localhost:3845/assets/6edcb2defc36a2bf4a05a3abe53b8da3d42b2cb4.svg"; const imgArrowDefault = "http://localhost:3845/assets/ad0cb4418492f1b020bb38a2ff038a331294ce87.svg"; const imgArrowNext = "http://localhost:3845/assets/6328cf96ee1169c1425c2ce55e7a2dcca0374508.svg"; const imgLogout = "http://localhost:3845/assets/2277a58aa2f582fd42132439745c5bb051f322c2.svg"; const imgClose = "http://localhost:3845/assets/51206896b81ebe68b2d80b5b603e576227587007.svg"; const imgCloseX = "http://localhost:3845/assets/91a45a4f2e47cd854574f32ee6ac1b84e12807cf.svg"; const imgMingcuteDownLine = "http://localhost:3845/assets/a50ea05576e2bcccf052b5be6750edaf476ad4d4.svg"; interface Course { id: number; courseName: string; instructorName: string; isIncluded: string; createdAt: string; registrar: string; } type PaginationMove = "Previous" | "Next"; type PaginationStatus = "Default" | "Disabled"; function PaginationBtnMove({ status = "Default", move = "Previous" }: { status?: PaginationStatus; move?: PaginationMove }) { const isDisabled = status === "Disabled"; const isNext = move === "Next"; if (isDisabled && isNext) { // Disabled Next 버튼 return (
); } if (isDisabled && !isNext) { // Disabled Previous 버튼 return (
); } if (isNext) { // Default Next 버튼 return (
); } // Default Previous 버튼 return (
); } export default function AdminLecture1Page() { const router = useRouter(); const [isLoading, setIsLoading] = useState(true); const [isAuthenticated, setIsAuthenticated] = useState(false); const [currentPage, setCurrentPage] = useState(1); const [isModalOpen, setIsModalOpen] = useState(false); const [courseName, setCourseName] = useState(''); const [instructorName, setInstructorName] = useState(''); const [showInstructorDropdown, setShowInstructorDropdown] = useState(false); const [nextId, setNextId] = useState(14); // 샘플 강좌 데이터 const [courses, setCourses] = useState([ { id: 39, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 38, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 37, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 36, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 35, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 34, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 33, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 32, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 31, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 30, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 29, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 28, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 27, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 26, courseName: '방사선 원리', instructorName: '김강사', isIncluded: '포함', createdAt: '2025-12-11', registrar: '김등록' }, { id: 25, courseName: '방사선 원리', instructorName: '김강사', isIncluded: '포함', createdAt: '2025-12-11', registrar: '김등록' }, { id: 24, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 23, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 22, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 21, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 20, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 19, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 18, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 17, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 16, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 15, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 14, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 13, courseName: '방사선 원리', instructorName: '김강사', isIncluded: '포함', createdAt: '2025-12-11', registrar: '김등록' }, { id: 12, courseName: '방사선 원리', instructorName: '김강사', isIncluded: '포함', createdAt: '2025-12-11', registrar: '김등록' }, { id: 11, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 10, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 9, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 8, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 7, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 6, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 5, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 4, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 3, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 2, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, { id: 1, courseName: '방사선 적용', instructorName: '김강사', isIncluded: '포함', createdAt: '2026-01-15', registrar: '이철수' }, ]); const instructors = ['김강사', '이강사', '박강사', '최강사']; // 관리자 인증 확인 useEffect(() => { const checkAuth = () => { if (typeof window !== 'undefined') { const isAdmin = isAdminLoggedIn(); setIsAuthenticated(isAdmin); setIsLoading(false); if (!isAdmin) { // 인증되지 않은 경우 로그인 페이지로 리다이렉트 router.push('/login'); } } }; checkAuth(); }, [router]); const handleOpenModal = () => { setIsModalOpen(true); setCourseName(''); setInstructorName(''); }; const handleCloseModal = () => { setIsModalOpen(false); setCourseName(''); setInstructorName(''); setShowInstructorDropdown(false); }; const handleSave = () => { if (!courseName.trim() || !instructorName.trim()) { alert('교육 과정명과 강사를 입력해 주세요.'); return; } const today = new Date(); const formattedDate = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`; const newCourse: Course = { id: nextId, courseName: courseName.trim(), instructorName: instructorName.trim(), isIncluded: '미포함', createdAt: formattedDate, registrar: '관리자', }; const updatedCourses = [...courses, newCourse]; setCourses(updatedCourses); setNextId(nextId + 1); // 13개를 넘어가면 해당 페이지로 이동 const newTotalPages = Math.ceil(updatedCourses.length / 13); if (newTotalPages > 1 && updatedCourses.length > 13) { setCurrentPage(newTotalPages); } handleCloseModal(); }; const handleSelectInstructor = (instructor: string) => { setInstructorName(instructor); setShowInstructorDropdown(false); }; const itemsPerPage = 13; const totalPages = Math.ceil(courses.length / itemsPerPage); const pageNumbers = Array.from({ length: totalPages }, (_, i) => i + 1); const startIndex = (currentPage - 1) * itemsPerPage; const endIndex = startIndex + itemsPerPage; const currentCourses = courses.slice(startIndex, endIndex); if (isLoading) { return null; // 로딩 중 } if (!isAuthenticated) { return ; } return (
{/* 사이드바 */}
{/* 로고 */} {/* 메뉴 */}
{/* 로그아웃 */}
{/* 메인 콘텐츠 */}
{/* 헤더 */}

교육 과정 관리

{/* 교육 과정 등록 버튼 */} {/* 테이블 */}
{/* 테이블 헤더 */}

교육 과정명

강사명

강좌 포함 여부

생성일

등록 담당자

{/* 테이블 바디 */}
{currentCourses.map((course) => (

{course.courseName}

{course.instructorName}

{course.isIncluded}

{course.createdAt}

{course.registrar}

))}
{/* 페이지네이션 */}
{pageNumbers.map((pageNum) => ( ))}
{/* 모달 팝업 */} {isModalOpen && (
{/* 배경 오버레이 */}
{/* 모달 컨텐츠 */}
e.stopPropagation()} > {/* 닫기 버튼 */} {/* 저장 버튼 */} {/* 취소 버튼 */} {/* 폼 컨텐츠 */}
{/* 제목 */}

교육 과정 등록

{/* 교육 과정명 */}

교육 과정명 *

setCourseName(e.target.value)} placeholder="교육 과정명을 입력해 주세요." className="basis-0 border border-[#b9b9b9] border-solid box-border content-stretch flex gap-[10px] grow items-center justify-center min-h-px min-w-px p-[10px] relative rounded-[8px] shrink-0 bg-white text-[16px] text-[#515151] focus:outline-none focus:border-[#2b82e8]" />
{/* 강사 */}

강사 *

{showInstructorDropdown && (
{instructors.map((instructor) => ( ))}
)}
{/* 교육 과정 이미지 */}

교육 과정 이미지

30MB 미만의 교육 과정 이미지를 첨부해 주세요.

첨부하지 않을 경우 기본 이미지가 노출돼요.

)}
); }