
#                                      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::SitejetBanner;

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/cp-sitejet-banner.min.js';

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

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

has 'image1_url' => (
    is      => 'rw',
    default => Cpanel::MagicRevision::calculate_magic_url('plugin_banners/sitejet/banner/assets/sj-editor.png'),
);

has 'image2_url' => (
    is      => 'rw',
    default => Cpanel::MagicRevision::calculate_magic_url('plugin_banners/sitejet/banner/assets/sj-templates.png'),
);

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

has '+template_file' => (
    default => 'plugin_banners/sitejet/banner/sitejet_banner.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->%*,
        image1_url  => $self->image1_url,
        image2_url  => $self->image2_url,
        campaign_id => $self->campaign_id,
    };
    return $self->$orig( $args, $opts );
};

1;
