<?php

namespace Ecoyn\Setup\Steps;

use Ecoyn\Setup\PackageConfig;
use QUI;
use QUI\Exception;
use QUI\Locale;

/**
 * Class DistributionType
 * - Business Type
 */
class DistributionType extends QUI\InstallationWizard\AbstractInstallationWizardStep
{
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->addCSSFile(dirname(__FILE__) . '/DistributionType.css');
        $this->setJavaScriptControl('package/ecoyn/core/bin/backend/controls/Setup/Steps/DistributionType');
    }

    public function getTitle(?Locale $Locale = null): string
    {
        if ($Locale === null) {
            $Locale = QUI::getLocale();
        }

        return $Locale->get('ecoyn/core', 'setup.data.distributionType.title');
    }

    public function getDescription(?Locale $Locale = null): string
    {
        if ($Locale === null) {
            $Locale = QUI::getLocale();
        }

        return $Locale->get('ecoyn/core', 'setup.data.distributionType.description');
    }

    /**
     * @return string
     * @throws Exception
     */
    public function create(): string
    {
        $Engine = QUI::getTemplateManager()->getEngine();
        $Config = PackageConfig::get('quiqqer/erp');

        $Engine->assign([
            'urlImageDir' => URL_OPT_DIR . 'ecoyn/core/bin/setup/',
            'general_businessType' => $Config->get('general', 'businessType')
        ]);

        return $Engine->fetch(dirname(__FILE__) . '/DistributionType.html');
    }
}
