"use client";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Button } from "@/components/ui/button";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { QrCode, X } from "lucide-react";
import { useReportDesigner } from "@/contexts/ReportDesignerContext";
import type { ComponentConfig } from "@/types/report";
interface Props {
component: ComponentConfig;
/** 우측 패널: "style" | 모달: "data" | 미전달: 전체 표시 (하위 호환) */
section?: "style" | "data";
}
export function BarcodeProperties({ component, section }: Props) {
const { updateComponent, queries, getQueryResult } = useReportDesigner();
const showStyle = !section || section === "style";
const showData = !section || section === "data";
return (
<>
{/* 바코드 스타일 — 우측 패널(section="style")에서 표시 */}
{showStyle && (
바코드 스타일
{/* 1D 바코드 전용: 텍스트 표시 */}
{component.barcodeType !== "QR" && (
updateComponent(component.id, { showBarcodeText: e.target.checked })}
className="h-4 w-4 rounded border-gray-300"
/>
)}
{/* 색상 설정 */}
{/* 여백 */}
updateComponent(component.id, { barcodeMargin: Number(e.target.value) })}
min={0}
max={50}
className="h-9"
/>
)}
{/* 바코드 데이터 — 모달(section="data")에서 표시 */}
{showData && (
바코드 데이터
{/* 바코드 타입 */}
{/* QR 오류 보정 수준 */}
{component.barcodeType === "QR" && (
높을수록 손상에 강하지만 크기 증가
)}
{/* 바코드 값 입력 (쿼리 연결 없을 때) */}
{!component.queryId && (
updateComponent(component.id, { barcodeValue: e.target.value })}
placeholder={
component.barcodeType === "EAN13"
? "13자리 숫자"
: component.barcodeType === "EAN8"
? "8자리 숫자"
: component.barcodeType === "UPC"
? "12자리 숫자"
: "바코드에 표시할 값"
}
className="h-9"
/>
{(component.barcodeType === "EAN13" ||
component.barcodeType === "EAN8" ||
component.barcodeType === "UPC") && (
{component.barcodeType === "EAN13" && "EAN-13: 12~13자리 숫자 필요"}
{component.barcodeType === "EAN8" && "EAN-8: 7~8자리 숫자 필요"}
{component.barcodeType === "UPC" && "UPC: 11~12자리 숫자 필요"}
)}
)}
{/* 쿼리 연결 안내 — 인라인 안내 텍스트 (수정하지 않음) */}
{!component.queryId && (
쿼리를 연결하면 데이터베이스 값으로 바코드를 생성할 수 있습니다.
)}
{/* 쿼리 연결 시 필드 선택 */}
{component.queryId && (
<>
{/* QR코드: 다중 필드 모드 토글 */}
{component.barcodeType === "QR" && (
updateComponent(component.id, {
qrUseMultiField: e.target.checked,
...(e.target.checked && { barcodeFieldName: "" }),
})
}
className="h-4 w-4 rounded border-gray-300"
/>
)}
{/* 단일 필드 모드 (1D 바코드 또는 QR 단일 모드) */}
{(component.barcodeType !== "QR" || !component.qrUseMultiField) && (
)}
{/* QR코드 다중 필드 모드 UI */}
{component.barcodeType === "QR" && component.qrUseMultiField && (
{/* 필드 목록 */}
{(component.qrDataFields || []).map((field, index) => (
))}
{(component.qrDataFields || []).length === 0 && (
필드를 추가하세요
)}
결과:{" "}
{component.qrIncludeAllRows
? `[{"${(component.qrDataFields || []).map((f) => f.label || "key").join('":"값","')}"}, ...]`
: `{"${(component.qrDataFields || []).map((f) => f.label || "key").join('":"값","')}":"값"}`}
)}
{/* QR코드 모든 행 포함 옵션 */}
{component.barcodeType === "QR" && component.queryId && (
updateComponent(component.id, { qrIncludeAllRows: e.target.checked })}
className="h-4 w-4 rounded border-gray-300"
/>
)}
>
)}
)}
>
);
}