<?php
/*
 * @package    ECLCDEK shipping plugin СДЭК to RadicalMart
 * @subpackage    ECLCDEK
 * @version    1.0.1
 * @author Econsult Lab.
 * @copyright  Copyright (c) 2025 Econsult Lab. All rights reserved.
 * @license    GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
 * @link       https://econsultlab.ru
 */

use Joomla\CMS\Language\Text;

extract($displayData);

/**
 * Layout variables
 * -----------------
 *
 * @var  Array   $address     	Данные адреса.
 * @var  string  $deliveryType     Тип доставки.
 *
 */
$result = "";
if ($address)
{
	if ($deliveryType === "office")
	{
		$result = Text::sprintf("PLG_RADICALMART_SHIPPING_ECLCDEK_LAYOUT_RESULT_OFFICE_TITLE", $pvs, $address['code']) . "<br>";
		$result .= Text::sprintf("PLG_RADICALMART_SHIPPING_ECLCDEK_LAYOUT_RESULT_ADDRESS", $address['region'], $address['city'], $address['address']) . "<br>";
		$result .= Text::sprintf("PLG_RADICALMART_SHIPPING_ECLCDEK_LAYOUT_RESULT_WORK_TIME", $address['work_time']);
	}
	else
	{
		$result   = [];
		$result[] = $address["formatted"];
		if (isset($address["entrance"]) && $address["entrance"])
		{
			$result[] = mb_strtolower(Text::_("PLG_RADICALMART_SHIPPING_ECLCDEK_CDEK_FIELD_ENTRANCE")) . " " . $address["entrance"];
		}

		if (isset($address["floor"]) && $address["floor"])
		{
			$result[] = mb_strtolower(Text::_("PLG_RADICALMART_SHIPPING_ECLCDEK_CDEK_FIELD_FLOOR")) . " " . $address["floor"];
		}

		if (isset($address["apartment"]) && $address["apartment"])
		{
			$result[] = mb_strtolower(Text::_("PLG_RADICALMART_SHIPPING_ECLCDEK_CDEK_FIELD_APARTMENT")) . " " . $address["apartment"];
		}
		
		$result = implode(", ", $result);

		$result = Text::sprintf("PLG_RADICALMART_SHIPPING_ECLCDEK_LAYOUT_RESULT_DOOR_TITLE",$result);
	}
}
echo $result;

