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

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

// components
import { Card } from 'primereact/card';

const navItems = [
    {
        permission: ['ROOT_MANAGE_NDG'],
        route: '/admin/set-ndg',
        label: __('Gestione NDG', 'gepafin'),
        subtitle: __('Imposta il codice NDG per le domande', 'gepafin'),
        icon: 'pi pi-id-card'
    },
    {
        permission: ['ROOT_MANAGE_APPL_STATUS'],
        route: '/admin/set-status',
        label: __('Gestione Stato Domanda', 'gepafin'),
        subtitle: __('Modifica lo stato delle domande', 'gepafin'),
        icon: 'pi pi-list'
    },
    {
        permission: ['ROOT_MANAGE_AMENDMENT_REOPEN'],
        route: '/admin/amendment-reopen',
        label: __('Riapri Soccorso', 'gepafin'),
        subtitle: __('Riapri un soccorso chiuso', 'gepafin'),
        icon: 'pi pi-refresh'
    },
    {
        permission: ['ROOT_MANAGE_AMENDMENT_EXTEND'],
        route: '/admin/amendment-extend',
        label: __('Estendi Soccorso', 'gepafin'),
        subtitle: __('Estendi la scadenza di un soccorso', 'gepafin'),
        icon: 'pi pi-calendar-plus'
    },
    {
        permission: ['ROOT_MANAGE_APPL_VIEW_DELETED', 'ROOT_MANAGE_APPL_DELETE_CONFIRM', 'ROOT_MANAGE_APPL_DELETE'],
        route: '/admin/elimina-domande',
        label: __('Elimina Domande', 'gepafin'),
        subtitle: __('Gestione eliminazione domande', 'gepafin'),
        icon: 'pi pi-trash'
    },
    {
        permission: ['ROOT_MANAGE_VIEW_LOG'],
        route: '/admin/log',
        label: __('Log Operazioni', 'gepafin'),
        subtitle: __('Storico delle operazioni amministrative', 'gepafin'),
        icon: 'pi pi-history'
    },
    {
        permission: ['ROOT_MANAGE_PEC_SEND'],
        route: '/admin/send-pec',
        label: __('Invio PEC Massivo', 'gepafin'),
        subtitle: __('Invia PEC a più destinatari tramite file CSV', 'gepafin'),
        icon: 'pi pi-envelope'
    },
    /*{
        permission: ['ROOT_MANAGE_EMAIL_TEMPLATES'],
        route: '/admin/email-templates',
        label: __('Template Email', 'gepafin'),
        subtitle: __('Gestione dei template per le email', 'gepafin'),
        icon: 'pi pi-file-edit'
    }*/
];

const Admin = () => {
    const permissions = useStoreValue('getPermissions');
    const navigate = useNavigate();

    const visibleItems = navItems.filter(
        (item) => intersection(permissions, item.permission).length > 0
    );

    return <div className="appPage">
        <div className="appPage__pageHeader"><h1>{__('Admin', 'gepafin')}</h1></div>
        <div className="appPage__spacer"></div>
        <div style={{ display: 'flex', flexWrap: 'wrap', gap: '1rem' }}>
            {visibleItems.map((item) => (
                <Card
                    key={item.route}
                    title={<span><i className={item.icon} style={{ marginRight: '0.5rem' }}/>{item.label}</span>}
                    subTitle={item.subtitle}
                    style={{ width: '280px', cursor: 'pointer', padding: '0.5rem' }}
                    onClick={() => navigate(item.route)}
                />
            ))}
        </div>
    </div>
}

export default Admin;
