import React, { useEffect } from 'react';
import { __ } from '@wordpress/i18n';
import { intersection } from 'ramda';
import { useNavigate } from 'react-router-dom';

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

// components
import { Button } from 'primereact/button';
import ManageSendPecSection from '../Admin/components/ManageSendPecSection';

const AdminSendPec = () => {
    const permissions = useStoreValue('getPermissions');
    const navigate = useNavigate();
    const hasPermission = intersection(permissions, ['ROOT_MANAGE_PEC_SEND']).length > 0;

    useEffect(() => {
        if (!hasPermission) navigate('/admin');
    }, [hasPermission]);

    return <div className="appPage">
        <div className="appPage__pageHeader">
            <h1>{__('Invio PEC Massivo', 'gepafin')}</h1>
        </div>
        <div className="appPage__spacer"></div>
        <div className="appPageSection__actions">
            <Button type="button" outlined label={__('Indietro', 'gepafin')} icon="pi pi-arrow-left" onClick={() => navigate('/admin')}/>
        </div>
        <div className="appPage__spacer"></div>
        {hasPermission && <ManageSendPecSection/>}
    </div>
}

export default AdminSendPec;
