
#                                      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 Cpanel::Plugins::Components::cpanel::tools::SitejetBannerAI;

use Moo;
use cPstrict;
use Cpanel::MagicRevision ();

extends 'Cpanel::Plugins::Components::Base';
with 'Cpanel::Plugins::Components::Role::Cpanel::Template';
my $uri = 'plugin_banners/sitejet/banner-ai/cp-sitejet-banner-ai.min.js';

has 'config_file' => (
    is       => 'ro',
    required => 1,
    default  => '/var/cpanel/plugins/sitejet_banner-ai/sitejet_banner_ai.json',
);

has '+js_url' => (
    is      => 'ro',
    default => $uri,
);

has 'cta_background_image' => (
    is      => 'rw',
    default => Cpanel::MagicRevision::calculate_magic_url('plugin_banners/sitejet/banner-ai/assets/tools-banner-bg.png'),
);

has 'campaign_id' => (
    is      => 'ro',
    default => 'campaign.sitejet-banner-ai.05.21.25',
);

has '+template_file' => (
    default => 'plugin_banners/sitejet/banner-ai/sitejet_banner_ai.tt',
);

has '+css' => (

    # hide the old feature sitejet banner
    default => sub {
        'cp-feature-showcase { display: none; }';
    }
);

has "+slot" => ( default => 'before-menu' );

has "+priority" => ( default => 0 );

has "+is_enabled" => (
    default => sub ($self) {
        require Cpanel::Plugins::Components::Rules;
        my $rules_obj = Cpanel::Plugins::Components::Rules->new( config_file => $self->config_file );
        return $rules_obj->is_allowed;
    }
);

around render => sub ( $orig, $self, $args, $opts ) {
    $args = {
        $args->%*,
        cta_background_image  => $self->cta_background_image,
        campaign_id => $self->campaign_id,
    };
    return $self->$orig( $args, $opts );
};

1;
