#                                      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::SocialBee::META;

use cPstrict;

=encoding utf-8

=head1 NAME

Cpanel::Config::ConfigObj::Driver::SocialBee::META

=head1 DESCRIPTION

Feature Showcase metadata for Social Media Management, internally known as SocialBee

=cut

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

our $VERSION = '1.0';

sub meta_version {
    return 1;
}

use Cpanel::Plugin::Install ();

use constant get_driver_name => 'socialbee';
use constant feature_file    => Cpanel::Plugin::Install::_addon_feature_directory() . '/' . get_driver_name();

=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/social-media-management-marketing',
        'name'   => {
            'short'  => 'Social Media Management now available in cPanel & WHM',
            'driver' => get_driver_name(),
        },
        'since'    => 'cPanel® 11.118',
        'abstract' => "cPanel & WHM now offers a robust Social Media Management feature, powered by SocialBee, to streamline managing your online presence. This feature lets you create, schedule, and reuse content across multiple social media platforms while ensuring consistent engagement. You also get detailed analytics to help you track performance and refine your social media strategy.",
        'version'  => $VERSION,
        'readonly' => 1,
    };

    if ($locale_handle) {
        $content->{'abstract'} = join(
            ' ',
            $locale_handle->maketext(
                "[asis,cPanel & WHM] now offers a robust [output,url,_1,Social Media Management] feature, powered by [asis,SocialBee], to streamline managing your online presence. This feature lets you create, schedule, and reuse content across multiple social media platforms while ensuring consistent engagement. You also get detailed analytics to help you track performance and refine your social media strategy.",
                "https://go.cpanel.net/social-media-management-docs"
            ),
        );
    }

    $content->{'name'}->{'long'} = "$content->{'name'}->{'short'}, provided by SocialBee";

    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 {
    require Common::JSONC;
    my $config_path = '/var/cpanel/plugins/socialbee/lifecycle.jsonc';

    return 0 unless -e $config_path;

    my $config = Common::JSONC::load_jsonc($config_path);

    require Cpanel::Plugins::Components::Rules;
    my $rules_obj = Cpanel::Plugins::Components::Rules->new( 'config' => $config->{install}->{condition} );

    return $rules_obj->is_allowed();
}

1;
