<?php

namespace UltraguardPro\modules\login_protect;

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

use UltraguardPro\Plugin;

class LoginProtectDashboardContributor {

    private Plugin $plugin;

    public function __construct( Plugin $plugin ) {
        $this->plugin = $plugin;
    }

    public function register(): void {
        add_action( 'admin_init', [ $this, 'contribute' ], 20 );
    }

    public function contribute(): void {
        if ( ! \UltraguardPro\core\Admin::is_ultraguard_dashboard() ) { return; }

        $stats = ( new LoginUrlEngine( $this->plugin ) )->get_stats();

        do_action( 'ultraguard_dashboard_register_stat', [
            'id'       => 'stat-login-protect-blocked-today',
            'title'    => __( 'Login URL Blocks', 'ultraguard-security-suite' ),
            'value'    => $stats['today'],
            'format'   => 'number',
            'icon'     => 'dashicons-lock',
            'class'    => $stats['today'] > 0 ? 'warning' : 'success',
            'animated' => true,
            'priority' => 32,
            'hide_when_empty' => true,
            'span'     => 3,
        ] );

        do_action( 'ultraguard_dashboard_register_status', [
            'id'      => 'status-login-protect',
            'icon'    => 'dashicons-lock',
            'text'    => __( 'Login URL Protection', 'ultraguard-security-suite' ),
            'badge'   => [ 'text' => __( 'Active', 'ultraguard-security-suite' ), 'badge_type' => 'success' ],
            'actions' => [ [ 'type' => 'button', 'text' => __( 'Manage', 'ultraguard-security-suite' ), 'button_style' => 'secondary','size'  => 'small', 'url' => admin_url( 'admin.php?page=ultraguard-security-suite-dashboard&ug_page=login-protect' ) ] ],
        ] );
    }
}
