import Seo from '@/core/components/Seo';
import dynamic from 'next/dynamic';
import SimpleFooter from '@/core/components/elements/Footer/SimpleFooter';
import BasicLayout from '@/core/components/layouts/BasicLayout';
import DesktopView from '@/core/components/views/DesktopView';
import MobileView from '@/core/components/views/MobileView';
import { getAuth } from '~/libs/auth';
import { useRouter } from 'next/router';
import { useEffect } from 'react';

const PagePengajuanTempo = dynamic(() =>
  import('@/lib/pengajuan-tempo/component/PengajuanTempo')
);

export default function TrackingOrder() {
  const auth = getAuth();
  const router = useRouter();

  useEffect(() => {
    if (!auth) {
      const nextUrl = encodeURIComponent(router.asPath);
      router.push(`/login?next=${nextUrl}`);
    } else if (!auth?.parentId) {
      router.push('/pengajuan-tempo/switch-account');
    }
  }, [auth, router]);

  if (!auth?.parentId) {
    return null;
  }

  return (
    <>
      <Seo title='Pengajuan Tempo - Indoteknik.com' />

      <DesktopView>
        <BasicLayout>
          <PagePengajuanTempo />
        </BasicLayout>
      </DesktopView>

      <MobileView>
        <BasicLayout>
          <PagePengajuanTempo />
        </BasicLayout>
      </MobileView>
    </>
  );
}
