#!/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 Cpanel::Plugins::Components::example::cpanel_app_plugin::Complex;

use cPstrict;
use Moo;

extends 'Cpanel::Plugins::Components::Base';

has '+markup' => (
    default => 'complex',
);

package main;

use cPstrict;

use Test2::V0;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test2::Tools::Subtest;
use Test2::Tools::Exception;
use Test2::Tools::Compare qw/prop object call/;

use Test::MockModule qw/strict/;
use File::Temp;
use File::Slurper;

use Test::Cpanel::Policy testing => 'Cpanel::Plugins::Components';

use Cpanel::Plugins::Components ();

my $temp_dir = File::Temp->newdir();
mkdir $temp_dir . "/usr";
mkdir $temp_dir . "/usr/local";
mkdir $temp_dir . "/usr/local/cpanel";
mkdir $temp_dir . "/usr/local/cpanel/Cpanel";
mkdir $temp_dir . "/usr/local/cpanel/Cpanel/Plugins";
mkdir $temp_dir . "/usr/local/cpanel/Cpanel/Plugins/Components";
mkdir $temp_dir . "/usr/local/cpanel/Cpanel/Plugins/Components/example";
mkdir $temp_dir . "/usr/local/cpanel/Cpanel/Plugins/Components/example/cpanel_app_plugin";

$Cpanel::Plugins::Components::LOAD_BASE       = "$temp_dir/usr/local/cpanel";
$Cpanel::Plugins::Components::COMPONENTS_PATH = "$temp_dir/usr/local/cpanel/Cpanel/Plugins/Components";

my $lib_dir = $temp_dir . "/usr/local/cpanel";

# Satisfy the module exist check
`touch $Cpanel::Plugins::Components::COMPONENTS_PATH/example/cpanel_app_plugin/Complex.pm`;

subtest 'Test loading complex app_key: cpanel-app-plugin' => sub {

    # Load modules from our temp folder first.
    local @INC = ($lib_dir);

    my $components = Cpanel::Plugins::Components::get_components( 'example', 'cpanel-app-plugin' );
    is $components, {
        default => [
            object { call markup => 'complex'; },
        ]
      },
      "We got the expected components in the default slot";
};

done_testing;
