<?php

declare(strict_types=1);

namespace KupShop\ShoppingListBundle\EmailRegister;

use KupShop\KupShopBundle\Email\EmailInterface;
use KupShop\KupShopBundle\EmailRegister\EmailRegisterInterface;
use KupShop\ShoppingListBundle\Email\ShareShoppingListEmail;

class ShoppingListEmailRegister implements EmailRegisterInterface
{
    public function applyPlaceholders(EmailInterface $email): void
    {
        if ($email instanceof ShareShoppingListEmail) {
            $email->addPlaceholder('PRODUKTY_V_SEZNAMU', function () use ($email) {
                $smarty = createSmarty(false, true);
                $smarty->assign('products', $email->shoppingListUtil->fetchItems($email->listId)->getProducts());

                return $smarty->fetch('email/block.shopping-list-items.tpl');
            }, 'Produkty v nákupním seznamu');

            $email->addPlaceholder('OD', function () use ($email) {
                return $email->from;
            }, 'Nákupní seznam uživatele');
        }
    }
}
