<?php

namespace UltraguardPro\modules\ip_intelligence;

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

use UltraguardPro\Plugin;

class IpIntelligenceDashboardContributor {

    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 FeedSyncEngine( $this->plugin ) )->get_stats();

        do_action( 'ultraguard_dashboard_register_stat', [
            'id'       => 'stat-ip-intel-feed-total',
            'title'    => __( 'Threat Feed IPs', 'ultraguard-security-suite' ),
            'value'    => $stats['feed_total'],
            'format'   => 'number',
            'icon'     => 'dashicons-shield-alt',
            'class'    => 'info',
            'animated' => true,
            'priority' => 12,
            'span'     => 3,
            'hide_when_empty' => true,
        ] );

        do_action( 'ultraguard_dashboard_register_status', [
            'id'      => 'status-ip-intelligence',
            'icon'    => 'dashicons-shield-alt',
            'text'    => __( 'IP Intelligence', 'ultraguard-security-suite' ),
            'badge'   => [ 'text' => __( 'Pro', 'ultraguard-security-suite' ), 'badge_type' => 'info' ],
            'actions' => [ [ 'type' => 'button', 'text' => __( 'Manage', 'ultraguard-security-suite' ),'size'  => 'small', 'button_style' => 'secondary','url' => admin_url( 'admin.php?page=ultraguard-security-suite-dashboard&ug_page=ip-intelligence' ) ] ],
        ] );
    }
}
