#!/usr/local/cpanel/3rdparty/bin/perl -w

#                                      Copyright 2025 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package t::medium::Cpanel::Plugins::Components::cpanel::tools::SitejetBanner;

use cPstrict;

use Test2::V0;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test2::Tools::Subtest;
use Test2::Tools::Exception;

use Test::MockModule qw/strict/;

use Cpanel::Plugins::Components ();

use constant {
    MOCKS => do {
        my @mocks;

        push @mocks, do {
            my $mock_MR = Test::MockModule->new('Cpanel::MagicRevision');
            $mock_MR->redefine(
                'calculate_magic_url_or_nothing' => sub ($url) {
                    return $url;
                },
            );
            $mock_MR->redefine(
                'calculate_magic_url' => sub ($url) {
                    return $url;
                },
            );
        };

        push @mocks, do {
            Test::MockModule->new('Cpanel::License::CompanyID')->redefine(
                '_read_company_id' => sub () {
                    return 7;
                },
            );
        };

        \@mocks;
    }
};

use Cpanel::Plugins::Components::cpanel::tools::SitejetBannerAI;

subtest 'Test Sitejet Banner' => sub {

    my $mock_rules = Test::MockModule->new('Cpanel::Plugins::Components::Rules');
    $mock_rules->redefine(
        'new' => sub ( $class, @other ) {
            bless {
                'config' => [
                    'date-range',
                    [
                        'start_date',
                        '09-26-2024',
                        'end_date',
                        ''
                    ],
                    'company-id',
                    [
                        7,
                        265
                    ]
                ]
            }, $class;
        },
    );

    my $banner = Cpanel::Plugins::Components::cpanel::tools::SitejetBannerAI->new();
    ok( $banner->is_enabled(), 'is_enabled returns 1' );
    is( $banner->cta_background_image(), 'plugin_banners/sitejet/banner-ai/assets/tools-banner-bg.png',     'cta_background_image matches img path' );
    is( $banner->js_url(),     'plugin_banners/sitejet/banner-ai/cp-sitejet-banner-ai.min.js', 'js_url matches bundle file path' );
    is( $banner->css,          'cp-feature-showcase { display: none; }',                 'new banner hides old banner on cpanel version where its not yet removed' );

    subtest 'Test Sitejet Banner disabled' => sub {
        $mock_rules->redefine(
            'new' => sub ( $class, @other ) {
                bless {
                    'config' => [
                        'date-range',
                        [
                            'start_date',
                            '09-26-2224',
                            'end_date',
                            ''
                        ],
                        'company-id',
                        [
                            7,
                            265
                        ]
                    ]
                }, $class;
            },
        );

        my $banner_disabled = Cpanel::Plugins::Components::cpanel::tools::SitejetBannerAI->new();
        is( $banner_disabled->is_enabled(), '', 'is_enabled returns 0 when the start date is in the future' );
    };
};

done_testing;
