import React from 'react';
import { __ } from '@wordpress/i18n';
import { Link } from 'react-router-dom';
import { head, isEmpty } from 'ramda';

// store
import { useStoreValue } from '../../store';

// components
import AllBandiAccordion from './components/AllBandiAccordion';
import ErrorBoundary from '../../components/ErrorBoundary';

const REACT_APP_HUB_ID = process.env.REACT_APP_HUB_ID;

const BandiBeneficiario = () => {
    const chosenCompanyId = useStoreValue('chosenCompanyId');
    const companies = useStoreValue('companies');
    const company = head(companies.filter(o => o.id === chosenCompanyId));

    return (
        <div className="appPage">
            <div className="appPage__pageHeader">
                <h1>{__('Bandi disponibili', 'gepafin')}</h1>
                {company ? <span className="companyName">{company.companyName}</span> : null}
            </div>

            <div className="appPage__spacer"></div>

            {isEmpty(chosenCompanyId) || chosenCompanyId === 0
                ? <>
                    <div className="appPageSection__message warning">
                        <i className="pi pi-exclamation-triangle"></i>
                        <span className="summary">{__('Attenzione', 'gepafin')}</span>
                        <span>
                            {__('Per applicare ai bandi devi Registare un Azienda clicca', 'gepafin')}
                            <Link to={`/agguingi-azienda`} style={{ marginLeft: '0.5ch' }}>{__('qua', 'gepafin')}</Link>
                        </span>
                    </div>
                    <div className="appPage__spacer"></div>
                </> : null}

            <div className="appPageSection">
                <ErrorBoundary><AllBandiAccordion/></ErrorBoundary>
            </div>

            {REACT_APP_HUB_ID !== 't7jh5wfg9QXylNaTZkPoE'
                ? <>
                    <div className="appPage__spacer"></div>
                    <div className="appPageSection">
                        <h2>{__('Questionario Antiriciclaggio', 'gepafin')}</h2>
                        <ErrorBoundary><AllBandiAccordion isAntiMoneylaundry={true}/></ErrorBoundary>
                    </div>
                </>
                : null}
        </div>
    )
}

export default BandiBeneficiario;