/**
 * ResponsiveFormTemplate - 통합 등록 페이지 템플릿
 * 
 * 모든 등록 페이지에서 사용할 수 있는 통합 템플릿입니다.
 * 견적 등록, 수주 등록, 품목 등록 등에 동일한 디자인을 적용합니다.
 * 
 * 특징:
 * - PageLayout + PageHeader
 * - 반응형 섹션 레이아웃
 * - 통일된 필드 스타일
 * - 에러 처리
 * - 하단 액션 버튼
 */

import { ReactNode } from "react";
import { LucideIcon } from "lucide-react";
import { PageLayout } from "../organisms/PageLayout";
import { PageHeader } from "../organisms/PageHeader";
import { FormActions } from "../organisms/FormActions";

// Re-export form components for convenience
export { FormSection } from "../organisms/FormSection";
export type { FormSectionProps } from "../organisms/FormSection";
export { FormField } from "../molecules/FormField";
export type { FormFieldProps, FormFieldType, SelectOption } from "../molecules/FormField";
export { FormFieldGrid } from "../organisms/FormFieldGrid";
export type { FormFieldGridProps } from "../organisms/FormFieldGrid";
export { FormActions } from "../organisms/FormActions";
export type { FormActionsProps } from "../organisms/FormActions";

export interface ResponsiveFormTemplateProps {
  // 헤더 관련
  title: string;
  description?: string;
  icon?: LucideIcon;
  headerActions?: ReactNode; // 헤더 우측 버튼들 (데스크톱)
  isEditMode?: boolean; // 수정 모드 여부
  
  // 메인 컨텐츠
  children: ReactNode;
  
  // 하단 액션
  onSave?: () => void;
  onCancel?: () => void;
  saveLabel?: string;
  cancelLabel?: string;
  saveDisabled?: boolean;
  saveLoading?: boolean;
  showActions?: boolean; // 하단 액션 버튼 표시 여부
  customActions?: ReactNode; // 커스텀 액션 버튼
  
  // 스타일
  className?: string;
  maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full';
  
  // 버전 정보 (히스토리가 있는 경우)
  versionInfo?: ReactNode;
}

/**
 * ResponsiveFormTemplate 컴포넌트
 */
export function ResponsiveFormTemplate({
  title,
  description,
  icon,
  headerActions,
  isEditMode,
  children,
  onSave,
  onCancel,
  saveLabel = "저장",
  cancelLabel = "취소",
  saveDisabled = false,
  saveLoading = false,
  showActions = true,
  customActions,
  className = "",
  maxWidth = 'full',
  versionInfo,
}: ResponsiveFormTemplateProps) {
  
  return (
    <PageLayout maxWidth={maxWidth} versionInfo={versionInfo}>
      {/* 헤더 */}
      <PageHeader
        title={title}
        description={description}
        icon={icon}
        rightActions={headerActions}
        isEditMode={isEditMode}
      />

      {/* 메인 컨텐츠 */}
      <div className={`space-y-6 ${className}`}>
        {children}
      </div>

      {/* 하단 액션 버튼 (모바일에서도 표시) */}
      {showActions && (
        <div className="sticky bottom-0 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 border-t pt-4 pb-4 -mx-3 md:-mx-6 px-3 md:px-6 mt-6">
          {customActions || (
            <FormActions
              onSave={onSave}
              onCancel={onCancel}
              saveLabel={saveLabel}
              cancelLabel={cancelLabel}
              saveDisabled={saveDisabled}
              saveLoading={saveLoading}
            />
          )}
        </div>
      )}
    </PageLayout>
  );
}