<?php
$session = new \Zend\Session\Container('userlogin');
$user_id = isset($session->userData['user_id']) ? $session->userData['user_id'] : '';
$data = [
    'user_id' => $user_id
];
$recentItems = $this->mainMenu()->getRecentlyViewedItems($data);

if (!empty($recentItems) && $user_id != "") {
    $config = new \Zend\Config\Config(include BASE_PATH . '/config/autoload/global.php');
    $masterPackageArr = $config->masterPackageId;
    $masterPackageArr = $masterPackageArr->toArray();
    ?>

    <!-- New Design -->

    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="span12">
                    <h2>Recently Search</h2>

                    <ul class="hot-tours" id="flexiselDemorecentitems">
                        <?php
                        foreach ($recentItems as $val) {
                            $booking_data = json_decode($val['booking_data']);
                            //echo '<pre>';print_r($booking_data);die;
                            $masterPackageName = $masterPackageArr[$booking_data->master_package_type];
                            if (isset($booking_data->city_id) && $booking_data->city_id != "") {
                                $cityName = $this->mainMenu()->getCityName($booking_data->city_id);
                                $cityId = $booking_data->city_id;
                            } else {
                                $cityName = $this->mainMenu()->getCityName($booking_data->pickcity_id);
                                $cityId = $booking_data->pickcity_id;
                            }

                            $url = strtolower(str_replace(' ', '-', $masterPackageName));
                            $action = "index";
                            if ($masterPackageName == 'Outstation' || $masterPackageName == 'One Way') {
                                $action = "one-way";
                                $url = "outstation";
                            }
                            if ($masterPackageName == 'Transfer') {
                                $url = "airport-transfer";
                            }
                            if ($masterPackageName == 'Activity') {
                                $url = "sight-seeing";
                            }
                            
                            $url = $this->url($url, ['controller' => 'index', 'action' => $action], ['query' => ['city' => $cityName['name'], 'city_id' => $cityId]]);
                            ?>

                            <li class="nbs-flexisel-item1">
                                <div class="col-md-12 col-md-3regency col-sm-6 pkg_col">
                                    <div class="package_con">

                                        <div class="item tr big">

                                            <div class="package_img ">
                                                <img src="/images/demestic_holidays/1.jpg" alt="">
                                            </div>
                                            <span class="package_icon">
                                                <div class="morecat_list">
                                                    <span title="More Associated Categories" class="more_cat">+more</span>
                                                    <div class="mc_list">
                                                        <div class="mcl_con">
                                                            <ul>
                                                                <li ><i class="filter_icon" title="Escorted Group Holiday">
                                                                        <div class="group_icon"></div></i> <span>Group Holiday</span></li>
                                                                <li ><i class="filter_icon" title="Family">
                                                                        <div class="family_icon"></div></i> <span>Family</span></li>
                                                                <li ><i class="filter_icon" title="Popular">
                                                                        <div class="populer_icon"></div></i> <span>Popular</span></li>
                                                            </ul>
                                                            <span style="float:right;">
                                                                <a style="float:left;margin-top: 2px; background:none !important;" href="javascript:void(0)" onclick="return deleteRecentlyViewed(<?php echo $val['id']; ?>)">
                                                                    <i class="fa fa-trash" style="font-size:24px;color:#000;"></i>
                                                                </a>
                                                            </span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </span>
                                            <a class="package_details" href="<?php echo $url; ?>">

                                                <div class="package_text">
                                                    <h4><?php echo $cityName['name']; ?> <?php echo $masterPackageName; ?></h4>
                                                    <p>
                                                        3 Nights / 2 Days
                                                    </p>
                                                </div>

                                                <span class="bk_nw_price">
                                                    <?php if (isset($booking_data->total_price) && $booking_data->total_price != "") { ?>INR<b><?php echo $booking_data->total_price; ?></b> <?php } ?>
                                                </span> 


                                                <span class="book_now_wrap">
                                                    <span>Book Now<i class="sprite icon_book_arrow"></i></span> 
                                                </span>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </li>


                        <?php } ?>

                    </ul>

                </div>
            </div>

        </div>
    </div>



    <?php
}
?>