<?php

namespace MovieEngine\Admin;

if (! defined("ABSPATH")) {
    exit; // Exit if accessed directly
}

class Dashboard {

    public function __construct() {
        add_action('wp_dashboard_setup', [$this, 'add_dashboard_widgets']);
    }

    public function add_dashboard_widgets() {
        wp_add_dashboard_widget(
            'movie_engine_dashboard_widget',
            esc_html__('Movie Engine Overview', 'cine-movie-engine'),
            [$this, 'render_dashboard_widget']
        );
    }

    public function render_dashboard_widget() {
        $movie_count = wp_count_posts('movie_engine_movie')->publish;
        $series_count = wp_count_posts('movie_engine_series')->publish;
?>
        <div class="movie-engine-dashboard">
            <p><strong><?php esc_html_e('Total Movies:', 'cine-movie-engine'); ?></strong> <?php echo intval($movie_count); ?></p>
            <p><strong><?php esc_html_e('Total Series:', 'cine-movie-engine'); ?></strong> <?php echo intval($series_count); ?></p>
            <hr>
            <a href="<?php echo esc_url(admin_url('admin.php?page=movie-engine-settings')); ?>" class="button button-primary"><?php esc_html_e('Go to Settings', 'cine-movie-engine'); ?></a>
        </div>
<?php
    }
}
