import { CampusAttendanceEntryForm } from '@/components/campus-attendance/CampusAttendanceEntryForm';
import { CampusAttendanceHeader } from '@/components/campus-attendance/CampusAttendanceHeader';
import { CampusAttendanceLinkConfig } from '@/components/campus-attendance/CampusAttendanceLinkConfig';
import {
  CampusAttendanceLoadingState,
  CampusAttendanceStatus,
} from '@/components/campus-attendance/CampusAttendanceStatus';
import { IndividualCampusAttendanceView } from '@/components/campus-attendance/IndividualCampusAttendanceView';
import { SuperintendentAttendanceView } from '@/components/campus-attendance/SuperintendentAttendanceView';
import { useCampusAttendancePage } from '@/business/campus-attendance/hooks';
import type { UserRole } from '@/shared/types/app';

interface CampusAttendanceProps {
  userRole: UserRole;
  userCampus: string;
  userName: string;
}

const CampusAttendance = ({ userRole, userCampus, userName }: CampusAttendanceProps) => {
  const attendancePage = useCampusAttendancePage({ userRole, userCampus, userName });
  const { state, actions } = attendancePage;

  if (state.loading) {
    return <CampusAttendanceLoadingState />;
  }

  return (
    <div className="space-y-6">
      <CampusAttendanceHeader state={state} actions={actions} />
      <CampusAttendanceStatus successMessage={state.successMessage} errorMessage={state.errorMessage} />

      {state.roleAccess.isOfficeManager && state.showEntryForm && (
        <CampusAttendanceEntryForm state={state} actions={actions} />
      )}

      {state.roleAccess.isOfficeManager && (
        <CampusAttendanceLinkConfig state={state} actions={actions} />
      )}

      {state.roleAccess.isSuperintendent ? (
        <SuperintendentAttendanceView state={state} actions={actions} />
      ) : (
        <IndividualCampusAttendanceView state={state} actions={actions} />
      )}
    </div>
  );
};

export default CampusAttendance;
