"use client";

import { PopComponentRegistry } from "../../PopComponentRegistry";
import { PopWorkDetailComponent } from "./PopWorkDetailComponent";
import { PopWorkDetailConfigPanel } from "./PopWorkDetailConfig";
import { PopWorkDetailPreviewComponent } from "./PopWorkDetailPreview";
import type { PopWorkDetailConfig } from "../types";

const defaultConfig: PopWorkDetailConfig = {
  showTimer: true,
  showQuantityInput: false,
  displayMode: "list",
  phaseLabels: { PRE: "작업 전", IN: "작업 중", POST: "작업 후" },
  infoBar: {
    enabled: true,
    fields: [
      { label: "작업지시", column: "wo_no" },
      { label: "품목", column: "item_name" },
      { label: "공정", column: "__process_name" },
      { label: "지시수량", column: "qty" },
    ],
  },
  stepControl: {
    requireStartBeforeInput: false,
    autoAdvance: true,
  },
  navigation: {
    showPrevNext: true,
    showCompleteButton: true,
  },
  resultSections: [
    { id: "total-qty", type: "total-qty", enabled: true, showCondition: { type: "always" } },
    { id: "good-defect", type: "good-defect", enabled: true, showCondition: { type: "always" } },
    { id: "defect-types", type: "defect-types", enabled: true, showCondition: { type: "always" } },
    { id: "note", type: "note", enabled: true, showCondition: { type: "always" } },
  ],
};

PopComponentRegistry.registerComponent({
  id: "pop-work-detail",
  name: "작업 상세",
  description: "공정별 체크리스트/검사/실적 상세 작업 화면",
  category: "display",
  icon: "ClipboardCheck",
  component: PopWorkDetailComponent,
  configPanel: PopWorkDetailConfigPanel,
  preview: PopWorkDetailPreviewComponent,
  defaultProps: defaultConfig,
  connectionMeta: {
    sendable: [
      {
        key: "process_completed",
        label: "공정 완료",
        type: "event",
        category: "event",
        description: "공정 작업 전체 완료 이벤트",
      },
    ],
    receivable: [],
  },
  touchOptimized: true,
  supportedDevices: ["mobile", "tablet"],
});
