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, 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 AuthMethod from '@/modules/feeds/Editor/components/FormElements/AuthMethod/AuthMethod';
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 JsRendering from '@/modules/feeds/Editor/components/FormElements/JsRendering/JsRendering';
import Language from '@/modules/feeds/Editor/components/FormElements/Language/Language';
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 Url from '@/modules/feeds/Editor/components/FormElements/Url/Url';
import UseForDownload from '@/modules/feeds/Editor/components/FormElements/UseForDownload/UseForDownload';
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);

  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="Access Level">
        <AccessLevel />
      </FormRow>
      {accessLevel === ACCESS_LEVEL_HUB && (
        <FormRow label="Select Hubs">
          <Hubs />
        </FormRow>
      )}
      {accessLevel === ACCESS_LEVEL_PRIVATE && (
        <FormRow label="Select Owners">
          <AccessVideoOwner />
        </FormRow>
      )}

      <FormGroupTitle>Auth</FormGroupTitle>
      <FormRow label="Url">
        <Url />
      </FormRow>
      <FormRow label="User">
        <User />
      </FormRow>
      <FormRow label="Password">
        <Password />
      </FormRow>
      <FormRow label="Auth. Method">
        <AuthMethod />
      </FormRow>
      <FormRow label="Use For Download">
        <UseForDownload />
      </FormRow>
      <FormRow label="Support JS Rendering">
        <JsRendering />
      </FormRow>

      <FormGroupTitle>Schedule Settings</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>
      )}
    </>
  );
}

export default GeneralTab;
