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 '../BandiBeneficiario/components/AllBandiAccordion';

const BandiPreferredBeneficiario = () => {
    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 osservati', '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">
                <AllBandiAccordion showOnlyPreferred={true}/>
            </div>
        </div>
    )
}

export default BandiPreferredBeneficiario;