<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" media="screen">
<script src="//cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.js"></script>
<style>
.page-title{
    display: none;
}
.thumbnail {
    height: auto;
}
.photo-name {
    text-align: center;
    font-size: 15px;
}
.photo-detail {
    text-align: center;
    font-size: 15px;
}
.photo-detail table th {
    text-align: right;
    width: 25%;
    vertical-align: middle !important;
}
.photo-detail table td {
    text-align: center;
    width: 25%;
    vertical-align: middle !important;
}
.photo-detail table tr{
    vertical-align: middle;
}
.empty-gallery {
    text-align: center;
    margin-top: 150px;
    margin-bottom: 120px;
}
.empty-gallery h2 {
    font-size: 25px;
    font-weight: lighter;
}
.zoom {
    cursor: pointer;
}
.zoom:hover {
    transform: scale(5);
    transform-origin: bottom right;
    transition-delay:0.3s;
}
</style>
<?php $PHOTO_TYPES = ["BRANI-PHOTO" => "Tlačítko", "BRANI-PACKED" => "Zabaleno", "ITEM-SCAN" => "Načtení produktu"]; ?>



<div class="row">
     <div class="col-md-12 tile-stats" style="padding: 10px; padding-top: 15px; text-align: center;">
        <?php 
            $next_page = $this->package_model->is_all_selected_packed($this->uri["eshop_id"]);
            if($next_page === False){
               echo anchor("package/packaging/eshop_id/".$this->uri["eshop_id"]."/order/".$this->uri["order"],'Zpět na balení' , 'class="btn btn-primary" style="position: absolute; left: 20px; margin-top:10px;"');
            }else{
                 echo anchor("package/packaging/eshop_id/".$this->uri["eshop_id"]."/r/".$next_page,'Zpět na balení' , 'class="btn btn-primary" style="position: absolute; left: 20px; margin-top:10px;"');
            }

         ?>
         <h1><?=$title?></h1>
         <?=anchor("package/packaging_photos/eshop_id/".$this->uri["eshop_id"]."/order/".$this->uri["order"]."/download_zip/1",'Stáhnout vše jako ZIP' , 'class="btn btn-default" style="position: absolute; right: 20px; top: 15px; margin-top:10px;"')?>
     </div>
</div>

<div class="row"> 
    <div class="col-md-offset-1 col-md-10">
            <div class="container">
                <div class="row">
                    <div class='list-group gallery'>

                        <?php if(count($photos) == 0):?>
                                <div class="empty-gallery">
                                        <h2>Pro tuto objednávku zde nejsou zatím žádné fotografie.</h2>
                                </div>


                        <?php else: ?>
                        <?php foreach ($photos as $photo): 
                            $product = False;
                            if(isset($PHOTO_TYPES[$photo["package_photo_type"]])) $type = $PHOTO_TYPES[$photo["package_photo_type"]]; else $type = $photo["package_photo_type"];
                            if($photo["package_photo_custom_id"] && $photo["package_photo_type"] == "ITEM-SCAN"){
                                $product = $this->package_model->get_packed_items(["package_packed_items_id" => $photo["package_photo_custom_id"]], true);
                                if(count($product) == 0) {
                                    $product = False;
                                }else {
                                    $product = $product[0];
                                    $product_data = json_decode($product["data"], true);
                                    
                                } 

                            }
                            ?>
                                <div class='col-sm-4 col-xs-6 col-md-3 col-lg-3'>
                                    <a class="thumbnail fancybox" rel="gallery" href="<?=get_balic_photo($photo["package_photo_url"])?>" data-fancybox-title='
                                        <div class="photo-detail">
                                                <table class="table table-striped">
                                                        <tr> 
                                                            <th> Datum: </th>
                                                            <td><?=$photo["package_photo_datetime"]?></td>
                                                            <th> Typ: </th>
                                                            <td><?= $type?></td>
                                                        </tr>
                                                        <tr>
                                                            <th> Uživatel: </th>
                                                            <td><?=$photo["client_name"]?></td>
                                                            <th> Stáhnout fotografii: </th>
                                                            <td>
                                                                <?=anchor(base_url('package/download_image?l='.urlencode(get_balic_photo($photo['package_photo_url']))), 'Stáhnout', 'download="'.$this->uri["order"].'_'.normalizeString($photo['package_photo_datetime'].'_'.$photo["package_photo_type"]).'.jpg" " class="btn btn-sm btn-default"')?></td>
                                                        </tr>
                                                        <?php if($photo["package_photo_custom_id"] && $photo["package_photo_type"] == "ITEM-SCAN"): ?>
                                                            <?php if($product === False): ?>
                                                                <tr>
                                                                    <td colspan="4">Načtení tohoto produktu bylo odstraněno.</td>
                                                                </tr>

                                                            <?php elseif($product): ?>
                                                            <tr style="background-color: whitesmoke;">
                                                                <th> Product:</th>
                                                                <td> <?=$product_data["name"]?> </td>
                                                                <td>  <?=$product["package_item_code"]?> <?php if($product_data["variants"][0]["ean"]) echo "(".$product_data["variants"][0]["ean"].")"; ?></td>
                                                                <td> <img class="zoom" height="65" src="<?php if($product_data["images"][0]["name"]) echo $image_prefix.$product_data["images"][0]["name"];?>"> </td>
                                                                
                                                            </tr>
                                                            <?php endif;?>
                                                        <?php endif;?>
                                                </table>
                                        </div>
                                        '>
                                        <img class="img-responsive" alt="" src="<?=get_balic_photo($photo["package_photo_url"])?>" width="314" height="177"/>
                                        <div class='photo-name'>
                                            <span class='text-muted'><strong><?=$photo["package_photo_datetime"]?></strong> <br> <?= $type?> <?php if($product) echo "(".$product["package_item_code"].")"; ?></span>
                                        </div> 
                                    </a>
                                </div> <!-- col-6 / end -->
                        <?php endforeach; ?>
                    <?php endif; ?>
                    </div> <!-- list-group / end -->
                </div> <!-- row / end -->
            </div> <!-- container / end -->
        </div>
</div>


<script>
    $(document).ready(function(){
    $(".fancybox").fancybox({
        openEffect: "none",
        closeEffect: "none",
        helpers     : {
            title   : { type : 'inside' },
            buttons : {}
        }
    });
});
</script>