'use client'; /* IMPORT */ import { Badge } from '@/components/ui/badge'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; import { Sheet, SheetContent, SheetHeader, SheetTitle } from '@/components/ui/sheet'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { useEffect, useState } from 'react'; import { Loader2 } from 'lucide-react'; import { REG_EVAL_CRITERIA_CATEGORY, REG_EVAL_CRITERIA_CATEGORY2, REG_EVAL_CRITERIA_ITEM, type RegEvalCriteriaDetails, type RegEvalCriteria, } from '@/db/schema'; import { getRegEvalCriteriaDetails } from '../service'; // 서버 액션 import // ---------------------------------------------------------------------------------------------------- /* TYPES */ interface RegEvalCriteriaDetailsSheetProps { criteriaViewData: RegEvalCriteria; open: boolean; onOpenChange: (open: boolean) => void; } // ---------------------------------------------------------------------------------------------------- /* CRITERIA DETAILS SHEET COMPONENT */ export function RegEvalCriteriaDetailsSheet({ criteriaViewData, open, onOpenChange }: RegEvalCriteriaDetailsSheetProps) { const [details, setDetails] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); // 상세 항목들 가져오기 useEffect(() => { if (criteriaViewData?.id && open) { setLoading(true); setError(null); getRegEvalCriteriaDetails(criteriaViewData.id) .then((fetchedDetails) => { setDetails(fetchedDetails || []); }) .catch((err) => { console.error('Failed to fetch criteria details:', err); setError('상세 정보를 불러오는데 실패했습니다.'); setDetails([]); }) .finally(() => { setLoading(false); }); } }, [criteriaViewData?.id, open]); // 라벨 변환 함수들 const getCategoryLabel = (value: string) => REG_EVAL_CRITERIA_CATEGORY.find(item => item.value === value)?.label ?? value; const getCategory2Label = (value: string) => REG_EVAL_CRITERIA_CATEGORY2.find(item => item.value === value)?.label ?? value; const getItemLabel = (value: string) => REG_EVAL_CRITERIA_ITEM.find(item => item.value === value)?.label ?? value; // 점수 표시 함수 const formatScore = (score: string | null | undefined) => { if (!score) return '-'; const numericScore = typeof score === 'string' ? parseFloat(score) : score; return isNaN(numericScore) ? '-' : parseFloat(numericScore.toFixed(2)).toString(); }; return ( 평가 기준 상세보기
{/* 기본 정보 카드 */} 기본 정보

평가부문

{getCategoryLabel(criteriaViewData.category)}

점수구분

{getCategory2Label(criteriaViewData.category2)}

항목

{getItemLabel(criteriaViewData.item)}

구분

{criteriaViewData.classification}

평가명

{criteriaViewData.range || '-'}

{criteriaViewData.remarks && (

비고

{criteriaViewData.remarks}

)}
{/* 점수 정보 카드 - 점수 유형에 따라 다른 UI 표시 */} {criteriaViewData.scoreType === 'variable' ? ( /* 변동점수 정보 카드 */ 변동점수 설정

이 평가 기준은 변동점수 유형으로 설정되어 있습니다.

최소점수

{criteriaViewData.variableScoreMin || '-'}

최대점수

{criteriaViewData.variableScoreMax || '-'}

점수단위

{criteriaViewData.variableScoreUnit || '-'}

변동점수 유형에서는 평가 시 설정된 점수 범위 내에서 점수를 부여합니다.

) : ( /* 고정점수 - 평가 옵션 및 점수 카드 */ 평가 옵션 및 점수

각 평가 옵션에 따른 점수를 확인할 수 있습니다.

{loading ? (
로딩 중...
) : error ? (
{error}
) : details.length === 0 ? (
등록된 평가 옵션이 없습니다.
) : (
# 평가 옵션 기자재-조선 기자재-해양 벌크-조선 벌크-해양 {details.map((detail, index) => ( {(detail.orderIndex ?? index) + 1} {detail.detail} {formatScore(detail.scoreEquipShip)} {formatScore(detail.scoreEquipMarine)} {formatScore(detail.scoreBulkShip)} {formatScore(detail.scoreBulkMarine)} ))}
)}
)}
); } // ---------------------------------------------------------------------------------------------------- /* EXPORT */ export default RegEvalCriteriaDetailsSheet;