<?php

namespace KupShop\ComponentsBundle\Twig\Components\Utils\Forms\ProductQuestion;

use KupShop\ComponentsBundle\Twig\Components\Utils\Forms\BaseComponentEmail;
use KupShop\KupShopBundle\Util\HtmlBuilder\HTML;

class ProductQuestionEmail extends BaseComponentEmail
{
    protected static $name = 'Dotaz na produkt';
    protected static $type = 'PRODUCT_EMAIL_TEMPLATE';
    protected $subject = 'Dotaz na produkt';

    public function renderEmail($message, $data = [], $base_template = '@Components/emails/product_question.html.twig'): array
    {
        return parent::renderEmail($message, $data, $base_template);
    }

    public static function getPlaceholders()
    {
        $placeholders = parent::getPlaceholders();
        $placeholders[self::$type] = array_merge($placeholders[self::$type] ?? [], [
            'DATA_PAGE_URL' => ['text' => 'Odkaz na product'],
            'DATA_NAME' => ['text' => 'Jméno uživatele'],
            'DATA_EMAIL' => ['text' => 'Email uživatele'],
            'DATA_SUBJECT' => ['text' => 'Dotaz na produkt'],
            'DATA_COMMENT' => ['text' => 'Comment'],
        ]);

        return $placeholders;
    }

    public function replacePlaceholdersItem($placeholder)
    {
        $replace = parent::replacePlaceholdersItem($placeholder);

        if (is_null($replace)) {
            switch ($placeholder) {
                case 'DATA_PAGE_URL':
                    $element = HTML::create('a');
                    $element
                        ->attr('href', $this->data['DATA_PAGE_URL'] ?? '')
                        ->attr('target', '_blank')
                        ->text($this->data['DATA_SUBJECT'] ?? '')
                        ->end();

                    return $element->html();
                default:
                    return $this->data[$placeholder] ?? '';
            }
        }

        return $replace;
    }
}
