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/ir_companies/ir_companiesSlice'
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";


const Ir_companiesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { ir_companies } = useAppSelector((state) => state.ir_companies)
    

    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 ir_companies')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View ir_companies')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/ir_companies/ir_companies-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Name</p>
                    <p>{ir_companies?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>MarketSymbol</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{ir_companies?.market_symbol?.symbol ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Description</p>
                  {ir_companies.description
                    ? <p dangerouslySetInnerHTML={{__html: ir_companies.description}}/>
                    : <p>No data</p>
                  }
                </div>
              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>HQLocation</p>
                    <p>{ir_companies?.hq_location}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='LastUpdatedAt'>
                    {ir_companies.last_updated_at ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={ir_companies.last_updated_at ?
                        new Date(
                          dayjs(ir_companies.last_updated_at).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No LastUpdatedAt</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ir_management_members IRCompany</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>FullName</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>DisplayOrder</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ir_companies.ir_management_members_ir_company && Array.isArray(ir_companies.ir_management_members_ir_company) &&
                              ir_companies.ir_management_members_ir_company.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ir_management_members/ir_management_members-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="full_name">
                                        { item.full_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="display_order">
                                        { item.display_order }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ir_companies?.ir_management_members_ir_company?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ir_filings IRCompany</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>FilingType</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>FiledAt</th>
                                
                                
                                
                                <th>SECURL</th>
                                
                                
                                
                                
                                
                                <th>Summary</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ir_companies.ir_filings_ir_company && Array.isArray(ir_companies.ir_filings_ir_company) &&
                              ir_companies.ir_filings_ir_company.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ir_filings/ir_filings-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="filing_type">
                                        { item.filing_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="filed_at">
                                        { dataFormatter.dateTimeFormatter(item.filed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sec_url">
                                        { item.sec_url }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="summary">
                                        { item.summary }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ir_companies?.ir_filings_ir_company?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ir_dividends IRCompany</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>DeclarationDate</th>
                                
                                
                                
                                <th>Ex-DividendDate</th>
                                
                                
                                
                                <th>RecordDate</th>
                                
                                
                                
                                <th>PayableDate</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>Frequency</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ir_companies.ir_dividends_ir_company && Array.isArray(ir_companies.ir_dividends_ir_company) &&
                              ir_companies.ir_dividends_ir_company.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ir_dividends/ir_dividends-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="declaration_at">
                                        { dataFormatter.dateTimeFormatter(item.declaration_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ex_dividend_at">
                                        { dataFormatter.dateTimeFormatter(item.ex_dividend_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="record_at">
                                        { dataFormatter.dateTimeFormatter(item.record_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="payable_at">
                                        { dataFormatter.dateTimeFormatter(item.payable_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="frequency">
                                        { item.frequency }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ir_companies?.ir_dividends_ir_company?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ir_announcements IRCompany</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>AnnouncedAt</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>SourceURL</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ir_companies.ir_announcements_ir_company && Array.isArray(ir_companies.ir_announcements_ir_company) &&
                              ir_companies.ir_announcements_ir_company.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ir_announcements/ir_announcements-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="announced_at">
                                        { dataFormatter.dateTimeFormatter(item.announced_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="source_url">
                                        { item.source_url }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ir_companies?.ir_announcements_ir_company?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ir_financial_statement_summaries IRCompany</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>StatementType</th>
                                
                                
                                
                                <th>PeriodType</th>
                                
                                
                                
                                <th>PeriodEndAt</th>
                                
                                
                                
                                <th>TotalRevenue</th>
                                
                                
                                
                                <th>NetIncome</th>
                                
                                
                                
                                <th>TotalAssets</th>
                                
                                
                                
                                <th>TotalLiabilities</th>
                                
                                
                                
                                <th>FreeCashFlow</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {ir_companies.ir_financial_statement_summaries_ir_company && Array.isArray(ir_companies.ir_financial_statement_summaries_ir_company) &&
                              ir_companies.ir_financial_statement_summaries_ir_company.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ir_financial_statement_summaries/ir_financial_statement_summaries-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="statement_type">
                                        { item.statement_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_type">
                                        { item.period_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_end_at">
                                        { dataFormatter.dateTimeFormatter(item.period_end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_revenue">
                                        { item.total_revenue }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="net_income">
                                        { item.net_income }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_assets">
                                        { item.total_assets }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_liabilities">
                                        { item.total_liabilities }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="free_cash_flow">
                                        { item.free_cash_flow }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!ir_companies?.ir_financial_statement_summaries_ir_company?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                

                <BaseDivider />

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

Ir_companiesView.getLayout = function getLayout(page: ReactElement) {
    return (
      <LayoutAuthenticated
        
        permission={'READ_IR_COMPANIES'}
        
      >
          {page}
      </LayoutAuthenticated>
    )
}

export default Ir_companiesView;