import React from 'react';
import { useRouter } from 'next/router';

import {
  ACCESS_LEVEL_HUB,
  ACCESS_LEVEL_PRIVATE,
  CONTENT_TYPE_SHORTS,
  SCHEDULE_TYPE_CUSTOM,
} from '@/modules/feeds/Editor/constants';

import {
  accessLevelSelector,
  accountSelector,
  contentTypeSelector,
  scheduleTypeSelector,
} from '@/modules/feeds/Editor/redux/selectors';

import { FormGroupTitle, FormRow } from '@/modules/@common/Form';
import { useAppSelector } from '@/modules/@common/store/hooks';
import AccessLevel from '@/modules/feeds/Editor/components/FormElements/AccessLevel/AccessLevel';
import AccessVideoOwner from '@/modules/feeds/Editor/components/FormElements/AccessVideoOwner/AccessVideoOwner';
import Account from '@/modules/feeds/Editor/components/FormElements/Account/Account';
import AutoImport from '@/modules/feeds/Editor/components/FormElements/AutoImport/AutoImport';
import ContentType from '@/modules/feeds/Editor/components/FormElements/ContentType/ContentType';
import DisplayName from '@/modules/feeds/Editor/components/FormElements/DisplayName/DisplayName';
import FillLandingPage from '@/modules/feeds/Editor/components/FormElements/FillLandingPage/FillLandingPage';
import Hubs from '@/modules/feeds/Editor/components/FormElements/Hubs/Hubs';
import IabCategories from '@/modules/feeds/Editor/components/FormElements/IabCategories/IabCategories';
import ImportShortsThumbnail from '@/modules/feeds/Editor/components/FormElements/ImportShortsThumbnail/ImportShortsThumbnail';
import Language from '@/modules/feeds/Editor/components/FormElements/Language/Language';
import Name from '@/modules/feeds/Editor/components/FormElements/Name/Name';
import ScheduleFrequency from '@/modules/feeds/Editor/components/FormElements/ScheduleFrequency/ScheduleFrequency';
import SchedulePeriod from '@/modules/feeds/Editor/components/FormElements/SchedulePeriod/SchedulePeriod';
import ScheduleStartTime from '@/modules/feeds/Editor/components/FormElements/ScheduleStartTime/ScheduleStartTime';
import YouTubeChannelId from '@/modules/feeds/Editor/components/FormElements/YouTubeChannelId/YouTubeChannelId';
import YoutubeContentType from '@/modules/feeds/Editor/components/FormElements/YoutubeContentType/YoutubeContentType';
import YouTubeLoadFromDate from '@/modules/feeds/Editor/components/FormElements/YouTubeLoadFromDate/YouTubeLoadFromDate';

function GeneralTab() {
  const router = useRouter();
  const id = parseInt(router.query.id as string, 10);

  const accessLevel = useAppSelector(accessLevelSelector);
  const scheduleType = useAppSelector(scheduleTypeSelector);
  const account = useAppSelector(accountSelector);
  const contentType = useAppSelector(contentTypeSelector);

  return (
    <>
      <FormGroupTitle>Settings</FormGroupTitle>
      <FormRow label="Account">
        <Account disabled={!!id} />
      </FormRow>
      <FormRow label="Source Name">
        <Name disabled={!!id} />
      </FormRow>
      <FormRow label="Display Name">
        <DisplayName />
      </FormRow>
      <FormRow label="Language">
        <Language />
      </FormRow>
      <FormRow label="IAB Categories">
        <IabCategories />
      </FormRow>
      <FormRow label="Access Level">
        <AccessLevel />
      </FormRow>
      {accessLevel === ACCESS_LEVEL_HUB && (
        <FormRow label="Hubs">
          <Hubs disabled={!account} />
        </FormRow>
      )}
      {accessLevel === ACCESS_LEVEL_PRIVATE && (
        <FormRow label="Video Owner">
          <AccessVideoOwner disabled={!account} />
        </FormRow>
      )}

      <FormGroupTitle>Schedule</FormGroupTitle>
      <FormRow label="Auto Import">
        <AutoImport />
      </FormRow>
      <FormRow label="Schedule Period">
        <SchedulePeriod />
      </FormRow>
      <FormRow label="Start time">
        <ScheduleStartTime />
      </FormRow>
      {scheduleType === SCHEDULE_TYPE_CUSTOM && (
        <FormRow label="Frequency (min)">
          <ScheduleFrequency />
        </FormRow>
      )}

      <FormGroupTitle>Authentication</FormGroupTitle>
      <FormRow label="Channel / Playlist">
        <YoutubeContentType />
      </FormRow>
      <FormRow label="Channel ID / Playlist ID">
        <YouTubeChannelId />
      </FormRow>
      <FormRow label="Load from Date">
        <YouTubeLoadFromDate />
      </FormRow>
      <FormRow label="Content Type">
        <ContentType />
      </FormRow>
      {contentType === CONTENT_TYPE_SHORTS && (
        <FormRow label="Import YouTube Thumbnails for Shorts">
          <ImportShortsThumbnail />
        </FormRow>
      )}
      <FormRow label="Auto-Fill Landing Page URL">
        <FillLandingPage />
      </FormRow>
    </>
  );
}

export default GeneralTab;
