<?php
/*------------------------------------------------------------------------
# com_zhgooglemap - Zh GoogleMap
# ------------------------------------------------------------------------
# author:    Dmitry Zhuk
# copyright: Copyright (C) 2011 zhuk.cc. All Rights Reserved.
# license:   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
# website:   http://zhuk.cc
# Technical Support Forum: http://forum.zhuk.cc/
-------------------------------------------------------------------------*/
// No direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;  


	$document    = Factory::getDocument();	
	
	$wa  = $document->getWebAssetManager();
	
    $load_bs = (int)$this->state->get('placemark.load_bootstrap');
		
    if ($load_bs == 0
     || $load_bs == 1)
    {
        $wa->registerAndUseStyle('zhgooglemaps.bootstrap_css', URI::root().'components/com_zhgooglemap/assets/bootstrap/css/bootstrap.min.css');
		// in new version there is no this style
        //$wa->registerAndUseStyle('zhgooglemaps.bootstrap_css_responsive', URI::root().'components/com_zhgooglemap/assets/bootstrap/css/bootstrap-responsive.min.css');
    }
    $wa->registerAndUseStyle('zhgooglemaps.common', URI::root() .'components/com_zhgooglemap/assets/css/placemark-common.css');
    
    if ($load_bs == 0)
    {
        $wa->registerAndUseScript('zhgooglemaps.bootstrap', URI::root().'components/com_zhgooglemap/assets/bootstrap/js/bootstrap.min.js');
    }
    
    $current_image_idx = 0; 
    $current_indicator_idx = 0; 
    
    function get_Slide($pi_idx, $pi_image, $pi_title, $pi_descr) {
        $cur_image_idx = $pi_idx;
        if ( $pi_image != "") 
        {
            $cur_image_idx += 1;

            echo "\n"."<div class=\"carousel-item zhgm-placemarkCarouselImg";
            
            if ($cur_image_idx == 1) 
            echo " active";
            echo "\">"."\n";
            
            echo "<img alt=\"\" src=\"";
            echo $pi_image; 
            echo "\">"."\n";
            if ($pi_title != "" || $pi_descr != "")
            {
                echo "<div class=\"carousel-caption d-none d-md-block\">";
                if ($pi_title != "")
                {
                    echo "<h4>";
                    echo $pi_title; 
                echo "</h4>"."\n";
                }
                if ($pi_descr != "")
                {
                    echo $pi_descr;
                }
                echo "</div>"."\n";
            }
            echo "</div>"."\n";
        }        
        return $cur_image_idx;
    }


    function get_SlideIndex($pi_idx, $pi_image, $pi_title, $pi_descr) {
        $cur_image_idx = $pi_idx;
        if ( $pi_image != "") 
        {
            $cur_image_idx += 1;

            echo "\n"."<button type=\"button\" class=\"";
            
            if ($cur_image_idx == 1)
            {            
                echo "active\"";
            }
            else
            {
                echo "\"";
            }
            echo " data-bs-slide-to=\"".($cur_image_idx-1)."\" data-bs-target=\"#zhgmCarousel\"";

            echo ">";
            echo "</button>"."\n";
        }        
        return $cur_image_idx;
    }    
    
    function get_SlideNeed($pi_image, $pi_title, $pi_descr) {
        if ( $pi_image != "") 
        {
            $ret_val = 1;
        }    
        else
        {
            $ret_val = 0;
        }
        return $ret_val;
    }    
    
?>    

                        
    <div class="row">
        <div class="col-md-12">
            <h2>
            <?php echo htmlspecialchars(str_replace('\\', '/', ($this->item->title)), ENT_QUOTES, 'UTF-8'); ?>
            </h2>
        </div>
    </div>
    <div class="row">
        <?php if ($this->item->hrefimagethumbnail == ""
              || (int)$this->state->get('placemark.thumbnail') == 0)
        {
        ?>
        <div class="col-md-12">
            <h3>
            <?php echo htmlspecialchars(str_replace('\\', '/', ($this->item->description)), ENT_QUOTES, 'UTF-8'); ?>
            </h3>
        </div>
        <?php
        }
        else
        {
        ?>
        <div class="col-md-8">
            <h3>
            <?php echo htmlspecialchars(str_replace('\\', '/',($this->item->description)), ENT_QUOTES, 'UTF-8'); ?>
            </h3>
        </div>
        <div class="col-md-4">
            <?php
            if ($this->item->hrefimagethumbnail!="")
            {
                $tmp_image_path = strtolower($this->item->hrefimagethumbnail);
                
                if (substr($tmp_image_path,0,5) == "http:"
                || substr($tmp_image_path,0,6) == "https:"
                || substr($tmp_image_path,0,1) == "/"
                || substr($tmp_image_path,0,1) == ".")
                {
                    $tmp_image_path_add = "";
                }
                else
                {
                    $tmp_image_path_add = "/";
                }
                echo '<img src="'.$tmp_image_path_add . $this->item->hrefimagethumbnail.'" alt="" class="zhgm-placemarkDetailImg" />'."\n";
            }
            ?>
        </div>
        <?php
        }
        ?>        
    </div>    
    <?php /*
    <div class="row">
        <div class="col-md-12">
            <span>
            Images .... 
            </span>
        </div>
    </div> */
    ?>    
    <div class="row">
    <?php
        if (((int)$this->state->get('placemark.imagegalery') == 1 )
         &&
          ( get_SlideNeed($this->item->tab1image, $this->item->tab1title, $this->item->tab1)
            || get_SlideNeed($this->item->tab2image, $this->item->tab2title, $this->item->tab2)
            || get_SlideNeed($this->item->tab3image, $this->item->tab3title, $this->item->tab3)
            || get_SlideNeed($this->item->tab4image, $this->item->tab4title, $this->item->tab4)
            || get_SlideNeed($this->item->tab5image, $this->item->tab5title, $this->item->tab5)
            || get_SlideNeed($this->item->tab6image, $this->item->tab6title, $this->item->tab6)
            || get_SlideNeed($this->item->tab7image, $this->item->tab7title, $this->item->tab7)
            || get_SlideNeed($this->item->tab8image, $this->item->tab8title, $this->item->tab8)
            || get_SlideNeed($this->item->tab9image, $this->item->tab9title, $this->item->tab9)
            || get_SlideNeed($this->item->tab10image, $this->item->tab10title, $this->item->tab10)
            || get_SlideNeed($this->item->tab11image, $this->item->tab11title, $this->item->tab11)
            || get_SlideNeed($this->item->tab12image, $this->item->tab12title, $this->item->tab12)
            || get_SlideNeed($this->item->tab13image, $this->item->tab13title, $this->item->tab13)
            || get_SlideNeed($this->item->tab14image, $this->item->tab14title, $this->item->tab14)
            || get_SlideNeed($this->item->tab15image, $this->item->tab15title, $this->item->tab15)
            || get_SlideNeed($this->item->tab16image, $this->item->tab16title, $this->item->tab16)
            || get_SlideNeed($this->item->tab17image, $this->item->tab17title, $this->item->tab17)
            || get_SlideNeed($this->item->tab18image, $this->item->tab18title, $this->item->tab18)
            || get_SlideNeed($this->item->tab19image, $this->item->tab19title, $this->item->tab19)))
        {
        ?>    
        <div class="col-md-8">
                <div id="zhgmCarousel" class="carousel slide" data-bs-ride="carousel">
                    <div  class="carousel-indicators">
                    <?php 
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab1image, $this->item->tab1title, $this->item->tab1);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab2image, $this->item->tab2title, $this->item->tab2);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab3image, $this->item->tab3title, $this->item->tab3);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab4image, $this->item->tab4title, $this->item->tab4);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab5image, $this->item->tab5title, $this->item->tab5);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab6image, $this->item->tab6title, $this->item->tab6);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab7image, $this->item->tab7title, $this->item->tab7);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab8image, $this->item->tab8title, $this->item->tab8);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab9image, $this->item->tab9title, $this->item->tab9);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab10image, $this->item->tab10title, $this->item->tab10);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab11image, $this->item->tab11title, $this->item->tab11);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab12image, $this->item->tab12title, $this->item->tab12);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab13image, $this->item->tab13title, $this->item->tab13);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab14image, $this->item->tab14title, $this->item->tab14);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab15image, $this->item->tab15title, $this->item->tab15);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab16image, $this->item->tab16title, $this->item->tab16);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab17image, $this->item->tab17title, $this->item->tab17);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab18image, $this->item->tab18title, $this->item->tab18);
                        $current_indicator_idx = get_SlideIndex($current_indicator_idx, $this->item->tab19image, $this->item->tab19title, $this->item->tab19);
                        ?>
                    </div >
                    <div class="carousel-inner">
                        
                        <?php 
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab1image, $this->item->tab1title, $this->item->tab1);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab2image, $this->item->tab2title, $this->item->tab2);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab3image, $this->item->tab3title, $this->item->tab3);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab4image, $this->item->tab4title, $this->item->tab4);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab5image, $this->item->tab5title, $this->item->tab5);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab6image, $this->item->tab6title, $this->item->tab6);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab7image, $this->item->tab7title, $this->item->tab7);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab8image, $this->item->tab8title, $this->item->tab8);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab9image, $this->item->tab9title, $this->item->tab9);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab10image, $this->item->tab10title, $this->item->tab10);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab11image, $this->item->tab11title, $this->item->tab11);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab12image, $this->item->tab12title, $this->item->tab12);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab13image, $this->item->tab13title, $this->item->tab13);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab14image, $this->item->tab14title, $this->item->tab14);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab15image, $this->item->tab15title, $this->item->tab15);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab16image, $this->item->tab16title, $this->item->tab16);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab17image, $this->item->tab17title, $this->item->tab17);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab18image, $this->item->tab18title, $this->item->tab18);
                            $current_image_idx = get_Slide($current_image_idx, $this->item->tab19image, $this->item->tab19title, $this->item->tab19);
                        ?>        
                    </div>
					 <button class="carousel-control-prev" type="button" data-bs-target="#zhgmCarousel" data-bs-slide="prev">
						<span class="carousel-control-prev-icon" aria-hidden="true"></span>
					</button>
					<button class="carousel-control-next" type="button" data-bs-target="#zhgmCarousel" data-bs-slide="next">
						<span class="carousel-control-next-icon" aria-hidden="true"></span>
					</button>
                </div>
        </div>
        <div class="col-md-4">
        <?php
        }
        else
        {
        ?>    
        <div class="col-md-12">
        <?php
        }
        ?>    
            <div id="GMapsID" class="zhgm-placemarkDetailMap">
            </div>
            <div id="GMapsCredit" class="zhgm-credit">
            </div>

            <?php echo $this->mapscriptheader; ?>

            <script type="text/javascript" >/*<![CDATA[*/

                <?php echo $this->mapscript; ?>
            
            /*]]>*/</script>

        </div>
    </div>    
    
    <?php
        if ((int)$this->state->get('placemark.hidedescriptionhtml') == 0 ) {
    ?>
        <div class="row">
        <div class="col-md-12">
			<?php
            $pluginPrepContentText = $this->item->descriptionhtml;
				if (isset($this->item->preparecontent) && (int)$this->item->preparecontent != 0)
				{
					$pluginPrepContentText = HTMLHelper::_('content.prepare', $pluginPrepContentText);                               
				}

				echo $pluginPrepContentText; 
			?> 
        </div>
        </div>    
    <?php
        }
    ?>
        
    <?php
        if ((int)$this->state->get('placemark.showdescriptionfullhtml') == 1 ) {
    ?>
        <div class="row">
        <div class="col-md-12">
			<?php
            $pluginPrepContentText = $this->item->descriptionfullhtml;
			if (isset($this->item->preparecontent) && (int)$this->item->preparecontent != 0)
			{
				$pluginPrepContentText = HTMLHelper::_('content.prepare', $pluginPrepContentText);                               
			}

			echo $pluginPrepContentText;
			?> 
        </div>
        </div>    
    <?php
        }
    ?>
    