<?php 
$colors = $this->config->item("package_selected_colors");
$orders_popup = "";
    foreach ($i["for_orders"] as $o) {
        $orders_popup .= "<p class='order-popover'><a href='".$o["data"]["adminUrl"]."'>".$o["order_code"]."</a> <span>".floor($o["current_item"]["amount"])." ks</span></p>"; 
    }
 
?>
<div class="col-md-3" style="text-align: center; padding-top: 10px;">
    
    <img style="max-width: 300px; max-height: 300px;" src="<?php if($i["shoptet_product"]["product_data"]["images"][0]["name"]) echo $image_prefix.$i["shoptet_product"]["product_data"]["images"][0]["name"];?>">

</div>
<div class="col-md-5" style="padding-top: 30px; font-size: 17px;">
    <table class="table">
        <tr>
            <th>Kód:</th>
            <td><a href="<?=$i["shoptet_product"]["product_data"]["url"]?>" target="_blank"><?=$i["shoptet_product"]["product_data"]["variants"][0]["code"]?></a></td>
        </tr>
        <tr>
            <th>EAN:</th>
            <td><?=$i["shoptet_product"]["product_data"]["variants"][0]["ean"]?></td>
        </tr>
        <tr>
            <th>Název:</th>
            <td><?=$i["shoptet_product"]["product_data"]["name"]?></td>
        </tr>
        <tr>
            <th>Varianta:</th>
            <td><?=$i["shoptet_product"]["product_data"]["variant_name"]?></td>
        </tr>
        
        <tr>
            <th>Pozice skladu:</th>
            <td><?=$i["stock_location"]?></td>
        </tr>
        <tr>
            <th>Skladovost:</th>
            <td><?=$i["shoptet_product"]["product_data"]["variants"][0]["stock"]?> ks</td>
        </tr>
        <tr>
            <th>Objednávky:</th>
            <td>
                <button data-html="true" data-placement="top" data-trigger="manual" data-toggle="popover"
                data-content="<?=$orders_popup?>"
                class="btn btn-xs btn-default col-md-12 col-xs-6 col-xs-offset-3 col-md-offset-0">Objednávky <?=count($i["for_orders"])?></button>
            </td>
        </tr>
        <tr>
            <th>Počet kusů:</th>
            <td style="font-size: 27px;"><?=$i["total_amount"]?> ks</td>
        </tr>

    </table>
    


</div>

<div class="col-md-4">
    <div class="product_numbers_item row form-inline">
    <?php ksort($i["package_selected_numbers"]);
    foreach ($i["package_selected_numbers"] as $key => $value): ?>
        <?php 
            if(!isset($colors[$key-1])) $colors[$key-1] = "lightgrey";
            if(hexdec(substr($colors[$key-1],1,2))+hexdec(substr($colors[$key-1],3,2))+hexdec(substr($colors[$key-1],5,2)) > 381) $text_color = "black"; else $text_color = "white"; 
            if(!isset($package_selected_number[$i["shoptet_product"]["product_data"]["variants"][0]["code"]][$key])) $package_selected_number[$i["shoptet_product"]["product_data"]["variants"][0]["code"]][$key] = 0;
            $total_amounts[$i["shoptet_product"]["product_data"]["variants"][0]["code"]] = $value;
            if(!isset($picked_items[$i["shoptet_product"]["product_data"]["variants"][0]["code"]])) $picked_items[$i["shoptet_product"]["product_data"]["variants"][0]["code"]] = [];
            $picked_items[$i["shoptet_product"]["product_data"]["variants"][0]["code"]][$key] = $package_selected_number[$i["shoptet_product"]["product_data"]["variants"][0]["code"]][$key];
            ?> 
            <div class="form-inline" style="display: flex; font-size: 22px; margin-top: 10px;">
                <h4 style="width: 180px;"><span class="label label-default" style="background-color: <?=$colors[$key-1]?>; color: <?=$text_color?>; margin-right: 10px;  font-size: 22px;"><?=$key?></span>  <span style=" font-size: 22px; margin-left: 15px; margin-right: 15px;" id="<?="inum-".$c."-".$key?>-active"><?=$this->package_model->get_package_selected_number_amount_text($package_selected_number[$i["shoptet_product"]["product_data"]["variants"][0]["code"]][$key], $value)?></span></h4>
                           
                <button <?php if($package_selected_number[$i["shoptet_product"]["product_data"]["variants"][0]["code"]][$key] == $value)  echo "disabled"; ?> style="margin-left: 10px; width: 30px; height: 30px; font-size: 19px;" data-text-id="<?="inum-".$c."-".$key?>" data-total_amount="<?=$value?>" data-code="<?=$i["shoptet_product"]["product_data"]["variants"][0]["code"]?>" data-selected_number="<?=$key?>" onclick="add_selected_number(this);" class="btn-item-plus"><i class="fa fa-plus" aria-hidden="true"></i></button>
                
                <button   data-total_amount="<?=$value?>" data-text-id="<?="inum-".$c."-".$key?>" data-code="<?=$i["shoptet_product"]["product_data"]["variants"][0]["code"]?>" data-selected_number="<?=$key?>" onclick="add_selected_number(this,true);" class="btn-item-minus" style="margin-left: 10px; width: 30px; height: 30px; font-size: 19px;"><i class="fa fa-minus" aria-hidden="true"></i></button>

                <button data-current_value='<?=$package_selected_number[$i["shoptet_product"]["product_data"]["variants"][0]["code"]][$key]?>' style="margin-left: 10px; width: 70px; height: 30px; font-size: 19px; line-height:13px;" data-total_amount="<?=$value?>" data-text-id="<?="inum-".$c."-".$key?>" data-code="<?=$i["shoptet_product"]["product_data"]["variants"][0]["code"]?>" data-selected_number="<?=$key?>" onclick="add_all_selected_number(this);" class="btn btn-default btn-item-all">Vše</button>
            </div>
    <?php endforeach; ?>

    </div>
</div>




