<?php

namespace Fab\Controller;

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

use Fab\Interfaces\JIT_Interface;
use Fab\View;

/**
 * Custom Header
 *
 * @package    Fab
 * @subpackage Fab/Controller
 */
class Custom_Header extends Base implements JIT_Interface {

    /**
     * Add custom header div in FAB Post Type.
     *
     * @return void
     */
    public function add_custom_header() {
        $screen = get_current_screen();

        // Check if the current screen is the FAB post type.
        if ( ! $screen || 'edit-fab' !== $screen->id ) {
            return;
        }

        // Enqueue the component.
        \FAB()->Helper->wp_enqueue_script_component( 'fab-admin-header-component', 'assets/components/admin-header-fab/main.js', array(), FAB_VERSION, false );
        wp_localize_script(
            'fab-admin-header-component',
            'FAB_INSIGHTS',
            array(
                'loading_gif' => FAB_PLUGIN_URL . 'assets/img/loading.gif',
                'rest_api'    => array(
                    'insights' => get_rest_url( null, 'fab/v1/insights' ),
                ),
                'nonce'       => wp_create_nonce( 'wp_rest' ),
                'colors'      => array(
                    'primary' => '#4f46e5',
                    'status'  => array(
                        'publish'   => '#4f46e5',
                        'draft'     => '#95a5a6',
                        'trash'     => '#e74c3c',
                        'pending'   => '#f1c40f',
                        'private'   => '#34495e',
                        'scheduled' => '#1abc9c',
                    ),
                ),
                'urls'        => array(
                    'fab'       => admin_url( 'edit.php?post_type=fab' ),
                    'dashboard' => admin_url( 'edit.php?post_type=fab&page=fab-dashboard' ),
                ),
                'labels'      => array(
                    'loading'           => __( 'Loading...', 'floating-awesome-button' ),
                    'number_of_buttons' => __( 'Number of Buttons', 'floating-awesome-button' ),
                    'total_clicks'      => __( 'Total Clicks', 'floating-awesome-button' ),
                    'average_clicks'    => __( 'Average Clicks', 'floating-awesome-button' ),
                    'go_to_dashboard'   => __( 'Go to Dashboard', 'floating-awesome-button' ),
                ),
            )
        );

        // Load vendors.
        \FAB()->Helper->wp_enqueue_style( 'fontawesome', apply_filters( 'fab_fontawesome_css', 'vendor/fontawesome/css/all.min.css' ) );

        View::RenderStatic( 'Backend.Header.fab' );
    }

    /*
    |--------------------------------------------------------------------------
    | Fulfill implemented interface contracts
    |--------------------------------------------------------------------------
     */

    /**
     * JIT method.
     *
     * @return void
     */
    public static function jit() {
        // Add custom header div in FAB Post Type.
        add_action( 'admin_notices', array( __CLASS__, 'jit_add_custom_header' ) );
    }
}
