<?php
/**
 * Copyright © 2018 EaDesign by Eco Active S.R.L. All rights reserved.
 * See LICENSE for license details.
 */

namespace Eadesigndev\Awb\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\UrlInterface;
/**
 * Handles the config and other settings
 *
 * Class Data
 * @package Eadesigndev\Awb\Helper
 */
#[\AllowDynamicProperties]
class Preview extends AbstractHelper
{
    protected $_urlInterface;
    public function __construct(
        Context $context,
        UrlInterface $urlInterface
    )
    {
        $this->_urlInterface = $urlInterface;
        parent::__construct($context);
    }

    public function getPreviewUrl($carrierName, $identifier, $label = "", $useJs = false, $pickupId = 0)
    {
        if (empty($label)) {
            $label = $identifier;
        }

        $urlToGo = $this->_urlInterface->getUrl(
            'shipping_awb/index/preview',
            [
                'carrier' => $carrierName,
                'identifier' => $identifier,
                'pickup_id' => $pickupId,
                '_secure' => true
            ]
        );

        return '<a '
        . ($useJs ? 'attr="target: $col.getTarget($action()), href: $action().href" ' : '')
        .'target="_blank" 
        href="' . $urlToGo . '">' . $label . "</a>";
    }
}