<?php

namespace ModulesGarden\Servers\OpenXchange\App\Http\Client;

use ModulesGarden\Servers\OpenXchange\App\UI\Client\EmailCatchAll\Pages\EmailCatchAllDescription;
use ModulesGarden\Servers\OpenXchange\Core\Helper;
use ModulesGarden\Servers\OpenXchange\Core\Http\AbstractClientController;
use ModulesGarden\Servers\OpenXchange\Core\UI\Traits\WhmcsParams;
use ModulesGarden\Servers\OpenXchange\App\Models\ProductConfiguration;

class EmailCatchAll extends AbstractClientController
{
    use WhmcsParams;

    public function index()
    {
        $hostingId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
        $hosting   = \WHMCS\Service\Service::find($hostingId);
        $config    = ProductConfiguration::config($hosting->packageid);

        if ($this->getWhmcsParamByKey('status') === 'Active' && isset($config['show_catch_all_button']) && $config['show_catch_all_button'] == 'on')
        {
            return Helper\view()
                ->addElement(EmailCatchAllDescription::class)
                ->addElement(\ModulesGarden\Servers\OpenXchange\App\UI\Client\EmailCatchAll\Pages\EmailCatchAll::class);
        }
    }
}
