"use client";

import { useCompanyManagement } from "@/hooks/useCompanyManagement";
import { CompanyToolbar } from "@/components/admin/CompanyToolbar";
import { CompanyTable } from "@/components/admin/CompanyTable";
import { CompanyFormModal } from "@/components/admin/CompanyFormModal";
import { CompanyDeleteDialog } from "@/components/admin/CompanyDeleteDialog";
import { DiskUsageSummary } from "@/components/admin/DiskUsageSummary";
import { ScrollToTop } from "@/components/common/ScrollToTop";

/**
 * 회사 관리 페이지
 * 모든 회사 관리 기능을 통합하여 제공
 */
export default function CompanyPage() {
  const {
    // 데이터
    companies,
    searchFilter,
    isLoading,
    error,

    // 디스크 사용량 관련
    diskUsageInfo,
    isDiskUsageLoading,
    loadDiskUsage,

    // 모달 상태
    modalState,
    deleteState,

    // 검색 기능
    updateSearchFilter,
    clearSearchFilter,

    // 모달 제어
    openCreateModal,
    openEditModal,
    closeModal,
    updateFormData,

    // 삭제 다이얼로그 제어
    openDeleteDialog,
    closeDeleteDialog,

    // CRUD 작업
    saveCompany,
    deleteCompany,

    // 에러 처리
    clearError,
  } = useCompanyManagement();

  return (
    <div className="flex min-h-screen flex-col bg-background">
      <div className="space-y-6 p-6">
        {/* 페이지 헤더 */}
        <div className="space-y-2 border-b pb-4">
          <h1 className="text-3xl font-bold tracking-tight">회사 관리</h1>
          <p className="text-sm text-muted-foreground">시스템에서 사용하는 회사 정보를 관리합니다</p>
        </div>

        {/* 디스크 사용량 요약 */}
        <DiskUsageSummary diskUsageInfo={diskUsageInfo} isLoading={isDiskUsageLoading} onRefresh={loadDiskUsage} />

        {/* 툴바 - 검색, 필터, 등록 버튼 */}
        <CompanyToolbar
          searchFilter={searchFilter}
          totalCount={companies.length}
          filteredCount={companies.length}
          onSearchChange={updateSearchFilter}
          onSearchClear={clearSearchFilter}
          onCreateClick={openCreateModal}
        />

        {/* 회사 목록 테이블 */}
        <CompanyTable companies={companies} isLoading={isLoading} onEdit={openEditModal} onDelete={openDeleteDialog} />

        {/* 회사 등록/수정 모달 */}
        <CompanyFormModal
          modalState={modalState}
          isLoading={isLoading}
          error={error}
          onClose={closeModal}
          onSave={saveCompany}
          onFormChange={updateFormData}
          onClearError={clearError}
        />

        {/* 회사 삭제 확인 다이얼로그 */}
        <CompanyDeleteDialog
          deleteState={deleteState}
          isLoading={isLoading}
          error={error}
          onClose={closeDeleteDialog}
          onConfirm={deleteCompany}
          onClearError={clearError}
        />
      </div>

      {/* Scroll to Top 버튼 */}
      <ScrollToTop />
    </div>
  );
}
