<?php
declare(strict_types=1);

namespace Itdatex\Ausgangsrechnung\Admin\Pages;

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

use Itdatex\Ausgangsrechnung\Admin\Menu;
use Itdatex\Ausgangsrechnung\Plugin;
use Itdatex\EInvoiceCore\InvoiceRepository;

/**
 * Liste der ausgegangenen Rechnungen.
 */
final class IssuedList
{
    public static function render(): void
    {
        if ( ! current_user_can( Plugin::CAPABILITY ) ) {
            wp_die( esc_html__( 'Keine Berechtigung.', 'itdatex-e-invoice-output' ), '', [ 'response' => 403 ] );
        }

        $repo  = new InvoiceRepository( 'outgoing' );
        $rows  = $repo->listByDirection( 'outgoing', 200 );
        $total = $repo->countByDirection( 'outgoing' );

        // phpcs:disable WordPress.Security.NonceVerification.Recommended
        // Rationale: read-only status/notice params after the PRG-redirect from
        // CreatePage. Only used for display; no state change happens here.
        $status    = isset( $_GET['ausrg_status'] ) ? sanitize_key( (string) $_GET['ausrg_status'] ) : '';
        $invoiceId = isset( $_GET['invoice_id'] ) ? (int) $_GET['invoice_id'] : 0;
        $msg       = isset( $_GET['msg'] ) ? sanitize_text_field( wp_unslash( (string) $_GET['msg'] ) ) : '';
        // phpcs:enable WordPress.Security.NonceVerification.Recommended

        include AUSRG_DIR . 'admin/views/page-list.php';
    }
}
