<?php
/**
 * _             _       _
 * | |____      _| | __ _| |__
 * | '_ \ \ /\ / / |/ _` | '_ \
 * | |_) \ V  V /| | (_| | |_) |
 * |_.__/ \_/\_/ |_|\__,_|_.__/.
 *
 * @author    Bwlab di Luigi Massa <info@bwlab.it>
 * @copyright since 2014 Bwlab
 * @license   proprietary
 */

declare(strict_types=1);

namespace Bwlab\Withdrawal\Hook;

if (!defined('_PS_VERSION_')) {
    exit;
}

class CheckoutHookHandler
{
    public function handle(array $params): string
    {
        if (!(bool) \Configuration::get('BWWITHDRAWAL_ENABLED')) {
            return '';
        }

        $context = \Context::getContext();
        $isoCode = $context->language->iso_code ?? 'it';
        $noticeKey = strtolower($isoCode) === 'it'
            ? 'BWWITHDRAWAL_NOTICE_IT'
            : 'BWWITHDRAWAL_NOTICE_EN';

        $notice = \Configuration::get($noticeKey);
        if (empty($notice)) {
            return '';
        }

        $context->smarty->assign(['withdrawal_notice' => $notice]);

        return $context->smarty->fetch(
            'module:bwwithdrawal/views/templates/hook/checkout-notice.tpl'
        );
    }
}
