<?php

namespace Ecoyn\Setup\Steps;

use QUI;
use QUI\Locale;

use function dirname;
use function file_get_contents;

/**
 * Class Welcome
 */
class License extends QUI\InstallationWizard\AbstractInstallationWizardStep
{
    /**
     * @param array<string, mixed> $attributes
     */
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->setJavaScriptControl('package/ecoyn/core/bin/backend/controls/Setup/Steps/Licence');
    }

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

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

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

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

    public function create(): string
    {
        $Engine = QUI::getTemplateManager()->getEngine();

        $Engine->assign([
            'urlImageDir' => URL_OPT_DIR . 'ecoyn/core/bin/setup/',
            'licence' => file_get_contents(dirname(__FILE__, 5) . '/LICENSE')
        ]);

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