<?php

namespace Ecoyn\Setup\Steps\BasicData;

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

/**
 * Class Welcome
 */
class CompanyData extends QUI\InstallationWizard\AbstractInstallationWizardStep
{
    public function __construct($attributes = [])
    {
        parent::__construct($attributes);
        $this->addCSSFile(dirname(__FILE__) . '/CompanyData.css');
    }

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

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

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

        return $Locale->get('ecoyn/core', 'setup.data.company.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/',
            'company_name' => $Config->get('company', 'name'),
            'company_owner' => $Config->get('company', 'owner'),
            'company_street' => $Config->get('company', 'street'),
            'company_zipCode' => $Config->get('company', 'zipCode'),
            'company_city' => $Config->get('company', 'city'),
            'company_country' => $Config->get('company', 'country'),
            'company_phone' => $Config->get('company', 'phone'),
            'company_fax' => $Config->get('company', 'fax'),
            'company_email' => $Config->get('company', 'email'),
            'company_web' => $Config->get('company', 'web'),
            'company_taxId' => $Config->get('company', 'taxId'),
            'company_taxNumber' => $Config->get('company', 'taxNumber'),
            'company_register' => $Config->get('company', 'register'),
            'company_court' => $Config->get('company', 'court'),
        ]);

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