<?php
/**
 * @author Aitoc Team
 * @copyright Copyright (c) 2020 Aitoc (https://www.aitoc.com)
 * @package Aitoc_PreOrders
 */

/**
 * Copyright © 2018 Aitoc. All rights reserved.
 * Developed by Alex Yakimovich
 */

namespace Aitoc\PreOrders\Plugin\Wishlist\Block\Customer\Wishlist\Item\Column;

use Aitoc\PreOrders\Helper\PreOrder as PreOrderHelper;
use Aitoc\PreOrders\Helper\Settings as SettingsHelper;
use Aitoc\PreOrders\Api\Data\Source\PreOrderNoteScope as PreOrderNoteScopeSourceInterface;
use Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Info as ColumnInfo;

/**
 * Class Actions
 */
class Info
{
    /**
     * @var PreOrderHelper
     */
    private $preOrderHelper;

    /**
     * @var SettingsHelper
     */
    private $settingsHelper;

    /**
     * @param PreOrderHelper $preOrderHelper
     * @param SettingsHelper $settingsHelper
     */
    public function __construct(
        PreOrderHelper $preOrderHelper,
        SettingsHelper $settingsHelper
    ) {
        $this->preOrderHelper = $preOrderHelper;
        $this->settingsHelper = $settingsHelper;
    }

    /**
     * @param ColumnInfo $subject
     * @param string $result
     * @return mixed
     */
    public function afterToHtml(
        ColumnInfo $subject,
        $result
    ) {
        $productId = $subject->getItem()->getProductId();
        $isPreOrder = $this->preOrderHelper->isProductPreOrder($productId);
        $preOrderNoteScope = $this->settingsHelper->getPreOrderNoteScopeSettings();
        if ($isPreOrder) {
            if (in_array(PreOrderNoteScopeSourceInterface::WISH_LIST_SCOPE, $preOrderNoteScope)) {
                $preOrderNote = $this->preOrderHelper->getPreOrderStatusLabelByProductId($productId);
                $preOrderMessage = '<span style="font-size: 0.85em;font-weight: bold;" class="preorder_note">' . $preOrderNote . '</span>';
                $result = $result . $preOrderMessage;
            }
        }
        return $result;
    }
}
