#                                      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::Config::ConfigObj::Driver::Xovi::META;

use cPstrict;

=encoding utf-8

=head1 NAME

Cpanel::Config::ConfigObj::Driver::Xovi::META

=head1 DESCRIPTION

Feature Showcase metadata for Search Engine Optimizer, internally known as XOVI

=cut

use parent qw(Cpanel::Config::ConfigObj::Interface::Config::Version::v1);

use Common::JSONC                      ();
use Cpanel::Plugins::Components::Rules ();

use constant get_driver_name => 'xovi';
use constant feature_file    => '/usr/local/cpanel/whostmgr/addonfeatures/' . get_driver_name();
use constant config_path     => '/var/cpanel/plugins/xovi/lifecycle.jsonc';

our $VERSION = '1.0';

sub meta_version {
    return 1;
}

=head1 FUNCTIONS

=head2 content

Defines the content used in the Feature Showcase entry

=cut

sub content {
    my ($locale_handle) = @_;

    my $content = {
        'vendor' => 'WebPros International, LLC',
        'url'    => 'https://go.cpanel.net/search-engine-optimization',
        'name'   => {
            'short'  => "Search Engine Optimization for cPanel",
            'driver' => get_driver_name(),
        },
        'since'    => 'cPanel® 11.118',
        'abstract' => "cPanel's new Search Engine Optimization feature enables users to increase their websites' visibility, track keyword performance, and identify problems that could decrease traffic. This intuitive feature requires no prior SEO experience, providing easy solutions with step-by-step explanations.",
        'version'  => $VERSION,
        'readonly' => 1,
    };

    if ($locale_handle) {
        $content->{'abstract'} = join(
            ' ',
            $locale_handle->maketext("cPanel‘s new Search Engine Optimization feature enables users to increase their websites‘ visibility, track keyword performance, and identify problems that could decrease traffic. This intuitive feature requires no prior SEO experience, providing easy solutions with step-by-step explanations."),
        );
    }

    $content->{'name'}->{'long'} = $content->{'name'}->{'short'};

    return $content;
}

=head2 showcase()

Determine how and if an item should appear in the showcase

=cut

sub showcase {
    return 0 unless _validate_rules();

    # do not display if the plugin is not installed
    return 0 unless -e feature_file();
    return { 'is_recommended' => 0, 'is_spotlight_feature' => 1 };
}

sub _validate_rules {
    return 0 unless -e config_path();

    my $config = Common::JSONC::load_jsonc( config_path() );
    my $show_banner;
    if ( my $condition = $config->{install}{condition} ) {
        my $rules_obj = Cpanel::Plugins::Components::Rules->new( 'config' => $condition );
        $show_banner = $rules_obj->is_allowed();
    }
    return $show_banner;
}

1;
