"use client"; import React, { useState } from "react"; import { useMonitoringSettingsAll } from "@/hooks/useMonitoringSettings"; import type { MonitoringTheme, ProductionLayout, RefreshInterval, AllMonitoringSettings, } from "@/types/monitoringSettings"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { Switch } from "@/components/ui/switch"; import { Checkbox } from "@/components/ui/checkbox"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { cn } from "@/lib/utils"; import { Settings2, Save, RotateCcw, Factory, Wrench, ClipboardCheck } from "lucide-react"; // ─── 탭 타입 ───────────────────────────────────────────────── type MonitorTab = "production" | "equipment" | "quality"; const TABS: { key: MonitorTab; label: string; icon: React.ReactNode; desc: string }[] = [ { key: "production", label: "생산모니터링", icon: , desc: "작업지시 진행현황" }, { key: "equipment", label: "설비운영모니터링", icon: , desc: "설비 가동 현황" }, { key: "quality", label: "품질점검현황", icon: , desc: "검사 현황 모니터링" }, ]; // ─── 필드 라벨 매핑 ────────────────────────────────────────── const PRODUCTION_FIELD_LABELS: Record = { workInstructionNo: "작업지시번호", itemName: "품목명", spec: "규격", customerName: "거래처", worker: "작업자/작업조", dueDate: "납기일", equipment: "사용설비", processProgress: "공정 진행현황", progressBar: "진행률 바", priority: "우선순위 표시", salesOrderNo: "수주번호", quantityInfo: "지시수량/완료수량", }; const EQUIPMENT_FIELD_LABELS: Record = { equipmentName: "설비명", equipmentType: "설비유형", equipmentLocation: "설비위치", operationStatus: "가동상태", utilizationBar: "가동률 바", dailyOperationTime: "금일 가동시간", dailyProductionQty: "금일 생산수량", worker: "작업자", currentWorkInstruction: "현재 작업지시", sensorData: "센서 데이터 (온도/압력/RPM)", cumulativeOperationTime: "누적 가동시간", nextInspectionDate: "다음 점검 예정일", }; const QUALITY_COLUMN_LABELS: Record = { inspectionNo: "검사번호", inspectionType: "검사유형", itemName: "품목명", spec: "규격", inspectionQty: "검사수량", passFailQty: "합격/불합격 수량", defectRate: "불량률", resultBar: "검사결과 바", judgment: "판정", inspector: "검사자", inspectedAt: "검사일시", inspectionCriteria: "검사기준", }; const QUALITY_INSPECTION_LABELS: Record = { incoming: "입고검사", process: "공정검사", shipping: "출하검사", }; // ─── 메인 컴포넌트 ─────────────────────────────────────────── export default function MonitoringSettingsPage() { const { settings, setSettings, saveAll, resetAll, isLoaded } = useMonitoringSettingsAll(); const [activeTab, setActiveTab] = useState("production"); const [saved, setSaved] = useState(false); const handleSave = () => { saveAll(); setSaved(true); setTimeout(() => setSaved(false), 2000); }; const handleReset = () => { if (!window.confirm("설정을 초기화하시겠습니까?")) return; resetAll(); }; if (!isLoaded) { return
설정을 불러오는 중...
; } return (
{/* 헤더 */}

모니터링 설정

각 모니터링 화면의 디자인, 레이아웃, 표시 항목을 설정할 수 있습니다.

{/* 모니터링 선택 탭 */}
{TABS.map((tab) => ( ))}
{/* 설정 내용 */} {activeTab === "production" && } {activeTab === "equipment" && } {activeTab === "quality" && } {/* 하단 저장 바 */}
); } // ─── 테마 선택기 ───────────────────────────────────────────── function ThemeSelector({ value, onChange }: { value: MonitoringTheme; onChange: (theme: MonitoringTheme) => void }) { const themes: { key: MonitoringTheme; label: string; preview: string; bg: string }[] = [ { key: "dark", label: "다크 모드", preview: "bg-gray-900", bg: "bg-gray-900" }, { key: "blue", label: "딥 블루", preview: "bg-slate-800", bg: "bg-slate-800" }, { key: "light", label: "라이트 모드", preview: "bg-gray-100 border border-gray-200", bg: "bg-gray-100" }, ]; return (
{themes.map((t) => ( ))}
); } // ─── 레이아웃 선택기 (생산만) ──────────────────────────────── function LayoutSelector({ value, onChange, }: { value: ProductionLayout; onChange: (layout: ProductionLayout) => void; }) { const layouts: { key: ProductionLayout; label: string }[] = [ { key: "grid", label: "그리드형" }, { key: "list", label: "리스트형" }, { key: "split", label: "분할형" }, ]; return (
{layouts.map((l) => ( ))}
); } // ─── 갱신 설정 섹션 ────────────────────────────────────────── function RefreshSettings({ refreshInterval, autoRefresh, soundOrAlarm, soundOrAlarmLabel, onIntervalChange, onAutoRefreshChange, onSoundOrAlarmChange, }: { refreshInterval: RefreshInterval; autoRefresh: boolean; soundOrAlarm: boolean; soundOrAlarmLabel: string; onIntervalChange: (v: RefreshInterval) => void; onAutoRefreshChange: (v: boolean) => void; onSoundOrAlarmChange: (v: boolean) => void; }) { return (
{autoRefresh ? "사용" : "사용안함"}
{soundOrAlarm ? "사용" : "사용안함"}
); } // ─── 체크박스 그리드 ───────────────────────────────────────── function FieldCheckboxGrid({ fields, labels, onChange, }: { fields: Record; labels: Record; onChange: (key: string, checked: boolean) => void; }) { const allChecked = Object.values(fields).every(Boolean); const noneChecked = Object.values(fields).every((v) => !v); return (
{Object.entries(fields).map(([key, checked]) => ( ))}
); } // ─── 생산모니터링 설정 ─────────────────────────────────────── function ProductionSettings({ settings, setSettings, }: { settings: AllMonitoringSettings; setSettings: React.Dispatch>; }) { const prod = settings.production; const update = (partial: Partial) => { setSettings((prev) => ({ ...prev, production: { ...prev.production, ...partial }, })); }; return (
테마 설정 모니터링 화면의 배경 테마를 선택합니다 update({ theme })} /> 레이아웃 카드 배치 방식을 선택합니다 update({ layout })} /> 갱신 설정 update({ refreshInterval })} onAutoRefreshChange={(autoRefresh) => update({ autoRefresh })} onSoundOrAlarmChange={(soundEnabled) => update({ soundEnabled })} /> 표시 항목 작업 카드에 표시할 정보를 선택합니다 update({ displayFields: { ...prod.displayFields, [key]: checked }, }) } />
); } // ─── 설비모니터링 설정 ─────────────────────────────────────── function EquipmentSettings({ settings, setSettings, }: { settings: AllMonitoringSettings; setSettings: React.Dispatch>; }) { const equip = settings.equipment; const update = (partial: Partial) => { setSettings((prev) => ({ ...prev, equipment: { ...prev.equipment, ...partial }, })); }; return (
테마 설정 모니터링 화면의 배경 테마를 선택합니다 update({ theme })} /> 갱신 설정 update({ refreshInterval })} onAutoRefreshChange={(autoRefresh) => update({ autoRefresh })} onSoundOrAlarmChange={(alarmEnabled) => update({ alarmEnabled })} /> 표시 항목 설비 카드에 표시할 정보를 선택합니다 update({ displayFields: { ...equip.displayFields, [key]: checked }, }) } />
); } // ─── 품질모니터링 설정 ─────────────────────────────────────── function QualitySettings({ settings, setSettings, }: { settings: AllMonitoringSettings; setSettings: React.Dispatch>; }) { const qual = settings.quality; const update = (partial: Partial) => { setSettings((prev) => ({ ...prev, quality: { ...prev.quality, ...partial }, })); }; return (
테마 설정 모니터링 화면의 배경 테마를 선택합니다 update({ theme })} /> 갱신 설정 update({ refreshInterval })} onAutoRefreshChange={(autoRefresh) => update({ autoRefresh })} onSoundOrAlarmChange={(alarmEnabled) => update({ alarmEnabled })} /> 검사유형 표시 모니터링에 표시할 검사유형을 선택합니다
{Object.entries(qual.inspectionTypes).map(([key, checked]) => ( ))}
테이블 컬럼 검사 테이블에 표시할 컬럼을 선택합니다 update({ tableColumns: { ...qual.tableColumns, [key]: checked }, }) } />
); }