<?php
declare(strict_types=1);
/**
 * Limesharp_Stockists extension
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the MIT License
 * that is bundled with this package in the file LICENSE
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/mit-license.php
 *
 * @category  Limesharp
 * @package   Limesharp_Stockists
 * @copyright 2016 Claudiu Creanga
 * @license   http://opensource.org/licenses/mit-license.php MIT License
 * @author    Claudiu Creanga
 */
?>
<?php /** @var \Limesharp\Stockists\Block\Stockists $block */ ?>
<?php $data = $block->getStoresForFrontend(); ?>
<?php $countryList = $block->getCountries(); ?>
<?php $modulePath = "limesharp_stockists/stockist/image/"; ?>
<?php $templateSetting = $block->getTemplateSettings(); ?>
<?php $storeDetails = $this->getDetails(); ?>
<?php
if($block->getMapPin()){
    $mapPin = $block->getMediaUrl()."limesharp_stockists/".$block->getMapPin();
} else {
    $mapPin = $block->getViewFileUrl('Limesharp_Stockists::images/map_pin.png');
}
?>
<div class="individual-stockists">

    <div class="image">
        <img src="<?php echo $block->getBaseImageUrl().$modulePath.$block->escapeHtml($storeDetails["details_image"]) ?>"
             alt="<?php echo $block->escapeHtml(__($storeDetails["address"])) ?>" />
    </div>

    <div class="details">
        <div class="title">
            <p><?php echo $block->escapeHtml(__("Store Details")) ?></p>
        </div>
        <div class="border"></div>
        <div class="address">
            <div class="exact-address">
                <p class="address-title"><?php echo $block->escapeHtml(__("Address")) ?></p>
                <p><?php echo $block->escapeHtml($storeDetails["address"]) ?></p>
                <p><?php echo $block->escapeHtml($storeDetails["city"]) ?></p>
                <p><?php echo $block->escapeHtml($storeDetails["postcode"]) ?></p>
            </div>
            <?php if($storeDetails["station"]): ?>
                <div class="station">
                    <div class="nearest-station">
                        <p>
                            <span class="nearest"><?php echo $block->escapeHtml(__("Nearest Station")); ?>
                            </span><?php echo $block->escapeHtml($storeDetails["station"]) ?></span>
                        </p>
                    </div>
                    <div class="distance">
                        <p><?php echo $storeDetails["distance"] ?></p>
                    </div>
                </div>
            <?php endif; ?>
        </div>
        <div class="clearfix"></div>
        <div class="get-directions">
            <a href="http://maps.google.com/maps?saddr=&daddr=<?php echo $block->escapeHtml($storeDetails["latitude"]).",".$block->escapeHtml($storeDetails["longitude"]); ?>" target="_blank">
                <?php echo $block->escapeHtml(__("Get Directions")) ?>
            </a>
        </div>
        <div id="map-canvas-individual"></div>
        <?php if($storeDetails["intro"]): ?>
        <div class="intro">
            <p class="intro">
                <?php echo $block->escapeHtml(__($storeDetails["intro"])); ?>
            </p>
        </div>
        <?php endif; ?>

        <?php if($storeDetails["description"]): ?>
        <div class="intro">
            <p class="intro">
                <?php echo $block->escapeHtml(__($storeDetails["description"])); ?>
            </p>
        </div>
        <?php endif; ?>

        <?php if($storeDetails["wo_general_indication"] || $storeDetails["wo_monday"] || $storeDetails["wo_tuesday"] || $storeDetails["wo_wednesday"] || $storeDetails["wo_thursday"] || $storeDetails["wo_friday"] || $storeDetails["wo_saturday"] || $storeDetails["wo_sunday"]): ?>
            <div class="intro working-hours">
                <h6><?php echo __('Working Hours'); ?></h6>
                <?php if($storeDetails["wo_general_indication"]): ?>
                    <p class="intro"><?php echo $block->escapeHtml(__($storeDetails["wo_general_indication"])); ?></p>
                <?php endif; ?>
                <?php if($storeDetails["wo_monday"]): ?>
                    <p class="intro">
                        <strong><?= __('Monday'); ?>:</strong> <?php echo $block->escapeHtml(__($storeDetails["wo_monday"])); ?>
                    </p>
                <?php endif; ?>
                <?php if($storeDetails["wo_tuesday"]): ?>
                    <p class="intro">
                        <strong><?= __('Tuesday'); ?>:</strong> <?php echo $block->escapeHtml(__($storeDetails["wo_tuesday"])); ?>
                    </p>
                <?php endif; ?>
                <?php if($storeDetails["wo_wednesday"]): ?>
                    <p class="intro">
                        <strong><?= __('Wednesday'); ?>:</strong> <?php echo $block->escapeHtml(__($storeDetails["wo_wednesday"])); ?>
                    </p>
                <?php endif; ?>
                <?php if($storeDetails["wo_thursday"]): ?>
                    <p class="intro">
                        <strong><?= __('Thursday'); ?>:</strong> <?php echo $block->escapeHtml(__($storeDetails["wo_thursday"])); ?>
                    </p>
                <?php endif; ?>
                <?php if($storeDetails["wo_friday"]): ?>
                    <p class="intro">
                        <strong><?= __('Friday'); ?>:</strong> <?php echo $block->escapeHtml(__($storeDetails["wo_friday"])); ?>
                    </p>
                <?php endif; ?>
                <?php if($storeDetails["wo_saturday"]): ?>
                    <p class="intro">
                        <strong><?= __('Saturday'); ?>:</strong> <?php echo $block->escapeHtml(__($storeDetails["wo_saturday"])); ?>
                    </p>
                <?php endif; ?>
                <?php if($storeDetails["wo_sunday"]): ?>
                    <p class="intro">
                        <strong><?= __('Sunday'); ?>:</strong> <?php echo $block->escapeHtml(__($storeDetails["wo_sunday"])); ?>
                    </p>
                <?php endif; ?>
            </div>
        <?php endif; ?>

        <?php if ($storeDetails["schedule"]): ?>
            <div class="schedule">
                <?php
                $schedule = $block->escapeHtml($storeDetails["schedule"]);
                $schedule = explode("\n",$schedule);
                foreach($schedule as $day): ?>
                    <p class="day"><?php echo str_replace('\n', "", $day); ?></p>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>

    </div>

    <div class="clearfix"></div>

</div>

<div class="clearfix"></div>

<?php if($block->getOtherStoresSettings()): ?>
    <div class="all-stores">
        <div class="all-stores-title">
            <p><?php echo $block->escapeHtml(__("View Our Other Stores")) ?></p>
        </div>
        <div class="all-stores-slider-wrapper">
            <?php foreach($data as $store): ?>
                <?php if ($storeDetails["stockist_id"] != $store["stockist_id"]): ?>
                    <div class="item">
                        <div class="image">
                        <img src="<?php echo $block->getBaseImageUrl().$modulePath.$block->escapeHtml($store["image"]) ?>"
                             alt="<?php echo $block->escapeHtml($store["address"]) ?>" />
                        </div>
                        <a href="<?php echo $block->escapeHtml(__($store["link"])) ?>" class="individual-store-link">
                            <div class="details">
                                <p><?php echo $block->escapeHtml(__($store["name"])) ?></p>
                            </div>
                        </a>
                    </div>
                <?php endif; ?>
            <?php endforeach; ?>
        </div>
    </div>
<?php endif; ?>

<script type="text/x-magento-init">
    {
        "*": {

            "stockists_individual_stores": {
                "map_styles" : "<?php echo $block->getMapStyles() ?>",
                "map_pin" : "<?php echo $mapPin; ?>",
                "slider_arrow" : "<?php echo $block->getViewFileUrl('Limesharp_Stockists::images/slider-arrow.svg'); ?>",
                "geolocation" : <?php echo json_encode($block->getLocationSettings()) ?>,
                "otherStores" : <?php echo json_encode($block->getOtherStoresSettings()) ?>,
                "otherStoresSlider" : <?php echo json_encode($block->getSliderSettings()) ?>,
                "modulePath" : "<?php echo $block->getBaseImageUrl().$modulePath; ?>",
                "zoom_individual" : <?php echo json_encode($block->getZoomIndividualSettings()) ?>,
                "storeDetails" : <?php echo json_encode($storeDetails) ?>,
                "radius" : <?php echo json_encode($block->getRadiusSettings()) ?>,
                "apiKey" : "<?php echo $block->getApiKeySettings(); ?>",
                "unit" : "<?php echo $block->getUnitOfLengthSettings() ?>",
                "fillColor" : "<?php echo $block->getFillColorSettings() ?>",
                "fillOpacity" : <?php echo json_encode($block->getFillOpacitySettings()) ?>,
                "strokeColor" : "<?php echo $block->getStrokeColorSettings() ?>",
                "strokeOpacity" : <?php echo json_encode($block->getStrokeOpacitySettings()) ?>,
                "strokeWeight" : <?php echo json_encode($block->getStrokeWeightSettings()) ?>
            }

        }
    }
</script>
