"use client";

import { createComponentDefinition } from "../../utils/createComponentDefinition";
import { ComponentCategory } from "@/types/component";
import { SearchWrapper } from "./SearchComponent";
import { InvSearchConfigPanel } from "./InvSearchConfigPanel";
import type { SearchConfig } from "./types";

/**
 * Search — 통합 검색 필터 컴포넌트 정의 (2026-04-11, Phase A-4)
 *
 * 흡수 대상:
 *   - v2-table-search-widget (base, 기존 기능은 Phase F 에서 복구)
 *   - table-search-widget (legacy)
 *   - autocomplete-search-input (legacy; 자동완성은 input 그룹)
 *
 * 변형:
 *   - layout: inline | stacked
 *   - dateRangeEnabled, showResetButton, autoSearch, searchButtonText
 *
 * 관련 문서:
 *   notes/gbpark/2026-04-11-component-unification-plan.md §3.3
 */

const DEFAULT_CONFIG: Partial<SearchConfig> = {
  placeholder: "검색어를 입력하세요",
  layout: "inline",
  showResetButton: true,
  autoSearch: false,
  searchButtonText: "검색",
};

export const SearchDefinition = createComponentDefinition({
  id: "search",
  name: "검색",
  name_eng: "Search",
  description: "조건 입력 후 데이터 조회",
  category: ComponentCategory.UTILITY,
  web_type: "text",
  component: SearchWrapper,
  default_config: DEFAULT_CONFIG as Record<string, any>,
  default_size: { width: 480, height: 48 },
  config_panel: InvSearchConfigPanel,
  icon: "Search",
  tags: ["검색", "search", "filter", "widget"],
  version: "2.0.0",
  author: "INVYONE",
  documentation:
    "notes/gbpark/2026-04-11-component-unification-plan.md#33-search",
  // ─── INVYONE DataPort 선언 ───
  dataPorts: {
    outputs: [{ name: "searchParams", type: "params" }],
  },
});

export type { SearchConfig } from "./types";
export { SearchComponent, SearchWrapper } from "./SearchComponent";
export { InvSearchConfigPanel } from "./InvSearchConfigPanel";
