/**
 * ResponsiveFormTemplate - 통합 등록 페이지 템플릿
 */

"use client";

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;
}

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={isEditMode ? `${title} 수정` : title}
        description={description}
        icon={icon}
        actions={headerActions}
      />

      {/* 메인 컨텐츠 */}
      <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>
  );
}