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

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

import { accessLevelSelector, accountSelector, 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 DisplayName from '@/modules/feeds/Editor/components/FormElements/DisplayName/DisplayName';
import Hubs from '@/modules/feeds/Editor/components/FormElements/Hubs/Hubs';
import IabCategories from '@/modules/feeds/Editor/components/FormElements/IabCategories/IabCategories';
import Language from '@/modules/feeds/Editor/components/FormElements/Language/Language';
import LoadFromLastDays from '@/modules/feeds/Editor/components/FormElements/LoadFromLastDays/LoadFromLastDays';
import Name from '@/modules/feeds/Editor/components/FormElements/Name/Name';
import Password from '@/modules/feeds/Editor/components/FormElements/Password/Password';
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 User from '@/modules/feeds/Editor/components/FormElements/User/User';

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);

  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="User ID">
        <User placeholder="Enter Vimeo User ID" label="Required" />
      </FormRow>
      <FormRow label="Access token">
        <Password placeholder="Enter Vimeo Access Token" label="Required" />
      </FormRow>
      <FormRow label="Load from Last Days">
        <LoadFromLastDays />
      </FormRow>
    </>
  );
}

export default GeneralTab;
