import { useAuthModalWorkflow } from '@/business/auth/hooks';
import { AuthStatusMessage } from '@/components/sign-in-modal/AuthStatusMessage';
import { SignInForm } from '@/components/sign-in-modal/SignInForm';
import { SignInModalFrame } from '@/components/sign-in-modal/SignInModalFrame';
import { SignInModalHeader } from '@/components/sign-in-modal/SignInModalHeader';
import { useAuth } from '@/contexts/useAuth';

interface SignInModalProps {
  readonly isOpen: boolean;
  readonly onClose: () => void;
}

const SignInModal = ({ isOpen, onClose }: SignInModalProps) => {
  const { signIn, signUp } = useAuth();
  const modal = useAuthModalWorkflow({ signIn, signUp, onClose });
  const { state, actions } = modal;

  if (!isOpen) {
    return null;
  }

  return (
    <SignInModalFrame onClose={actions.handleClose}>
      <SignInModalHeader state={state} />
      <AuthStatusMessage error={state.error} success={state.success} />
      <SignInForm state={state} actions={actions} />
    </SignInModalFrame>
  );
};

export default SignInModal;
