<?php

namespace Fab\Controller;

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

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

/**
 * Upgrade Notice.
 *
 * @package    Fab
 * @subpackage Fab/Controller
 */
class Upgrade_Notice extends Notice implements JIT_Interface {

    /**
     * Constructor.
     *
     * @return void
     */
    public function __construct() {
        $this->id                         = 'fab_upgrade_premium';
        $this->non_dismissible_by_screens = array(
            'fab_page_floating-awesome-button-setting',
            'fab_page_floating-awesome-button-templates',
            'fab_page_fab-dashboard',
        );
    }

    /**
     * Show admin upgrade notice.
     *
     * @return void
     */
    public function fab_show_admin_notice() {
        // Check if the user is on a premium plan.
        if ( \FAB()->Helper->isPremiumPlan() ) {
            return;
        }

        // Check if the notice should be shown.
        if ( ! $this->should_show_notice() ) {
            return;
        }

        // Prepare the data for the admin notice.
        $data = array_merge(
            $this->get_default_data(),
            array(
                'title'   => __( '🚀 Unlock Premium Features Today!', 'floating-awesome-button' ),
                'message' => __( 'Transform your website with our Pro version! Get advanced triggers, precise targeting rules, and powerful customization options that will help you boost engagement and conversions. Join thousands of satisfied users who have upgraded to unlock the full potential of Floating Awesome Button.', 'floating-awesome-button' ),
                'buttons' => array(
                    array(
                        'message' => __( 'Get PRO Features Now →', 'floating-awesome-button' ),
                        'url'     => \FAB()->Helper->getUpgradeURL(),
                        'classes' => 'text-white text-center text-xs px-2.5 py-1.5 bg-primary-600 hover:bg-primary-700 transition-all font-semibold shadow-md animate__animated animate__pulse animate__infinite animate__slow',
                    ),
                ),
            )
        );

        View::RenderStatic( 'Backend.admin-notice', $data );
    }

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

    /**
     * JIT method.
     *
     * @return void
     */
    public static function jit() {
        // Show admin usage tracking notice.
        add_action( 'admin_notices', array( __CLASS__, 'jit_fab_show_admin_notice' ) );
    }
}
