import React, { ReactElement, useEffect } from 'react';
import Head from 'next/head';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';
import dayjs from 'dayjs';
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
import { useRouter } from 'next/router';
import { fetch } from '../../stores/company_profiles/company_profilesSlice';
import { saveFile } from '../../helpers/fileSaver';
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from '../../components/ImageField';
import LayoutAuthenticated from '../../layouts/Authenticated';
import { getPageTitle } from '../../config';
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
import SectionMain from '../../components/SectionMain';
import CardBox from '../../components/CardBox';
import BaseButton from '../../components/BaseButton';
import BaseDivider from '../../components/BaseDivider';
import { mdiChartTimelineVariant } from '@mdi/js';
import { SwitchField } from '../../components/SwitchField';
import FormField from '../../components/FormField';

import { hasPermission } from '../../helpers/userPermissions';

const Company_profilesView = () => {
  const router = useRouter();
  const dispatch = useAppDispatch();
  const { company_profiles } = useAppSelector(
    (state) => state.company_profiles,
  );

  const { currentUser } = useAppSelector((state) => state.auth);

  const { id } = router.query;

  function removeLastCharacter(str) {
    console.log(str, `str`);
    return str.slice(0, -1);
  }

  useEffect(() => {
    dispatch(fetch({ id }));
  }, [dispatch, id]);

  return (
    <>
      <Head>
        <title>{getPageTitle('View company_profiles')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton
          icon={mdiChartTimelineVariant}
          title={removeLastCharacter('View company_profiles')}
          main
        >
          <BaseButton
            color='info'
            label='Edit'
            href={`/company_profiles/company_profiles-edit/?id=${id}`}
          />
        </SectionTitleLineWithButton>
        <CardBox>
          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Tenant</p>

            <p>{company_profiles?.tenant?.name ?? 'No data'}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>LegalName</p>
            <p>{company_profiles?.legal_name}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Address</p>
            <p>{company_profiles?.address}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Phone</p>
            <p>{company_profiles?.phone}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Email</p>
            <p>{company_profiles?.email}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Website</p>
            <p>{company_profiles?.website}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>RC</p>
            <p>{company_profiles?.rc}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>ICE</p>
            <p>{company_profiles?.ice}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Patente</p>
            <p>{company_profiles?.patente}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>LogoURL</p>
            <p>{company_profiles?.logo_url}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>PDFFooter</p>
            <p>{company_profiles?.pdf_footer}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>agences</p>

            <p>{company_profiles?.agences?.name ?? 'No data'}</p>
          </div>

          <BaseDivider />

          <BaseButton
            color='info'
            label='Back'
            onClick={() =>
              router.push('/company_profiles/company_profiles-list')
            }
          />
        </CardBox>
      </SectionMain>
    </>
  );
};

Company_profilesView.getLayout = function getLayout(page: ReactElement) {
  return (
    <LayoutAuthenticated permission={'READ_COMPANY_PROFILES'}>
      {page}
    </LayoutAuthenticated>
  );
};

export default Company_profilesView;
