<?php
declare(strict_types=1);

namespace Itdatex\Rechnungseingang\Admin\Pages;

if ( ! defined( 'ABSPATH' ) ) { exit; }

use Itdatex\Rechnungseingang\InvoiceRepository;
use Itdatex\Rechnungseingang\Plugin;

final class Inbox
{
    public function register(): void { /* keine Hooks */ }

    public static function render(): void
    {
        if ( ! current_user_can( Plugin::CAPABILITY ) ) {
            wp_die( esc_html__( 'Keine Berechtigung.', 'itdatex-e-invoice-intake' ), '', [ 'response' => 403 ] );
        }

        $repo     = new InvoiceRepository();
        $invoices = $repo->listInvoices( 200, 0 );
        $total    = $repo->countInvoices();

        // Notice aus Upload-Redirect
        $status     = isset( $_GET['reing_status'] ) ? sanitize_key( (string) $_GET['reing_status'] ) : '';
        $invoiceId  = isset( $_GET['invoice_id'] ) ? (int) $_GET['invoice_id'] : 0;
        $msg        = isset( $_GET['msg'] ) ? sanitize_text_field( wp_unslash( (string) $_GET['msg'] ) ) : '';

        include REING_DIR . 'admin/views/page-inbox.php';
    }
}
