import AttorneyDashboard from 'components/sections/dashboard/Home/Dashboard/AttorneyDashboard';
import DashboardErrorPage from 'components/sections/dashboard/Home/Dashboard/DashboardErrorPage';
import DashboardLoading from 'components/sections/dashboard/Home/Dashboard/DashboardLoading';
import PropertyOwnerDashboard from 'components/sections/dashboard/Home/Dashboard/PropertyOwnerDashboard';
import RealEstateAgentDashboard from 'components/sections/dashboard/Home/Dashboard/RealEstateAgentDashboard';
import VendorDashboard from 'components/sections/dashboard/Home/Dashboard/VendorDashboard';
import { AccountContext } from 'contexts/AccountContext';
import { ReactElement, useContext } from 'react';
import { UserAPI } from 'types';

export type DashboardProps = {
  account: UserAPI;
};

const Dashboard = (): ReactElement => {
  const { account, accountLoading } = useContext(AccountContext);

  if (accountLoading) {
    return <DashboardLoading />;
  }

  if (!account) {
    return <DashboardErrorPage />;
  }

  //change what to show based on the account type
  if (account.user_type === 'property_owner') {
    return <PropertyOwnerDashboard account={account} />;
  } else if (account.user_type === 'vendor') {
    return <VendorDashboard account={account} />;
  } else if (account.user_type === 'attorney') {
    return <AttorneyDashboard account={account} />;
  } else if (account.user_type === 'real_estate_agent') {
    return <RealEstateAgentDashboard account={account} />;
  } else {
    return <p>404 error</p>;
  }
};

export default Dashboard;
