<?php
$this->load->view($left);
$this->load->view($header);
?>
<style type="text/css">
    .ibox-content {
        border-style : none;
    }

    .hr-line-dashed {
        margin: 5px 0;
    }

    .disabledbutton {
        pointer-events: none;
        opacity: 0.4;
    }

    .imageupload {
        background: white;
        border-radius: 5px;
        border: 2px dashed rgb(0, 135, 247);
        border-image: none;
        max-width: 500px;
        min-height:200px;
        margin-left: auto;
        margin-right: auto;
    }

    .brbt{
        border-bottom:1px solid lightgray; 
        padding-bottom: 10px;
    }

    .rdolft{
        float: left;
        padding: 0 5px 0 0;
    }
    .chklft{
        text-align: left;
    }
</style>
<link rel="stylesheet" 
              href=
"https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" />
<form method="post" class="form-horizontal" id="attributes_data">
    <input type="hidden" value="<?php echo $product->id; ?>" name="id"> 
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-6">
        <h2>Edit Attributes - <b><?php echo $product->photo_id; ?></b></h2>
    </div>
    <div class="col-sm-6">
        <div class="title-action">
        <button class="btn btn-primary save_attributes" type="button" data-status="1"><i class="fa fa-save"></i><i class="fa fa-spinner fa-spin" style="display:none;"></i><span class="m-l-xs">Save</span></button>

        <a href="<?php echo site_url("all_products/optionsEdit/$next_id"); ?>" class="btn btn-info">
            <i class="fa fa-arrow-right"></i>
            <span class="m-l-xs">Next</span>
        </a>
        </div>
    </div>
</div>

<div class="wrapper wrapper-content">
    <div class="row text-center animated fadeInRightBig">
        <div class="col-lg-4">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    
                    <div class="form-group">
                        <label class="col-sm-12"><h4><U>Designer</U></h4></label>
                        <div class="col-sm-12 brbt">
                            <select class="form-control" name="designer" id="designer" required>
                                <option value="<?php echo $product->_designer.'_'.$product->designer; ?>"><?php echo $product->designer; ?></option>
                                <option value="">Select Designer</option>
                                
                            </select>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label class="col-sm-12" ><h4><U>Quality</U></h4></label>

                        <div class="col-sm-12 brbt">

                            <div class="form-check rdolft">
                                <input type="radio" class="" id="quality" name="quality" value="<?php echo $product->quality; ?>" checked>
                                <label class="" for="radio2"><?php echo $product->quality; ?></label>
                            </div>

                                <?php
                                if (count($quality) > 0) {
                                    foreach ($quality as $key => $value) {
                                        if(!empty($value->name) && strtolower($product->quality) != strtolower($value->name)){
                                        ?>
                                        <div class="form-check rdolft">
                                            <input type="radio" class="" name="quality" value="<?php echo $value->name; ?>">
                                            <label class="" for="radio2"><?php echo $value->name; ?></label>
                                        </div>
                                        <?php
                                        }
                                    }
                                }
                                ?>
                           
                        </div>
                    </div>

                     <div class="form-group">
                        <label class="col-sm-12"><h4><U>BY COLOR</U></h4></label>
                        <div class="col-sm-12 brbt">
                            <select class="form-control select2" multiple name="colors[]" id="colors">
                                <option value="">Select Color</option>
                                <?php
                                $arr_colors = array();
                                if (!empty($color_drop)) {
                                    if($product->colors != null && $product->colors != ''){
                                        $arr_colors = json_decode($product->colors);
                                    }
                                    
                                    //print_r($arr_colors);exit;
                                    if(count($arr_colors > 0)){
                                       foreach ($arr_colors as $value) {

                                        ?>
                                        <option value="<?php echo $value; ?>" selected ><?php echo $value; ?></option>
                                        <?php
                                        } 
                                    }
                                    
                                    foreach ($color_drop->result() as $value) {
                                        if(!in_array($value->color, $arr_colors)){
                                        ?>
                                            <option value="<?php echo $value->color; ?>"><?php echo $value->color; ?></option>
                                        <?php
                                        }
                                    }
                                }
                                ?>
                            </select>
                        </div>
                            
                    </div>

                    <div class="form-group">
                        <label class="col-sm-12"><h4><U>Design</U></h4></label>
                        <div class="col-sm-12 brbt">
                           
                                <?php
                                if(count($selected_design) > 0){
                                   foreach ($selected_design as $key => $value) {
                                ?>       
                                    <div class="checkbox chklft">
                                      <label>
                                        <input type="checkbox" name="design[]" value="<?php echo $value ?>" checked>
                                        
                                        <?php echo $value ?>
                                      </label>
                                    </div>    
                                <?php        
                                    } 
                                }

                                if (count($design) > 0) {
                                    foreach ($design as $key => $value) {
                                        if(!in_array(strtolower($value->design), array_map('strtolower', $selected_design))){
                                        ?>
                                        
                                        <div class="checkbox chklft">
                                          <label>
                                            <input type="checkbox" name="design[]" value="<?php echo $value->design; ?>">
                                            
                                            <?php echo $value->design; ?>
                                          </label>
                                        </div>
                                        <?php
                                        }
                                    }
                                }
                                ?>
                            
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-12"><h4><U>Type</U></h4></label>
                        <div class="col-sm-12 brbt"> 
                            <?php                           
                            if(count($selected_type) > 0){
                               foreach ($selected_type as $key => $value) {
                            ?>
                                    <div class="checkbox chklft">
                                      <label>
                                        <input type="checkbox" name="type[]" value="<?php echo $value ?>" checked>
                                        
                                        <?php echo $value ?>
                                      </label>
                                    </div>
                            <?php
                                } 
                            }

                            if (count($type) > 0) {
                                foreach ($type as $key => $value) {
                                    if(!in_array(strtolower($value->name), array_map('strtolower', $selected_type))){
                                    ?>                                    
                                    <div class="checkbox chklft">
                                          <label>
                                            <input type="checkbox" name="type[]" value="<?php echo $value->name; ?>">
                                            
                                            <?php echo $value->name; ?>
                                          </label>
                                        </div>
                                    <?php
                                    }
                                }
                            }
                            ?>
                            
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-12"><h4><U>Material</U></h4></label>
                        <div class="col-sm-12 brbt">                            
                            <?php
                            if(count($selected_material) > 0){
                               foreach ($selected_material as $key => $value) {
                                    ?>
                                    
                                    <div class="checkbox chklft">
                                      <label>
                                        <input type="checkbox" name="material[]" value="<?php echo $value ?>" checked>
                                        
                                        <?php echo $value ?>
                                      </label>
                                    </div>
                            <?php
                                } 
                            }

                            if (count($material) > 0) {
                                foreach ($material as $key => $value) {
                                    if(!in_array(strtolower($value->name), array_map('strtolower', $selected_material))){
                                    ?>
                                    <div class="checkbox chklft">
                                      <label>
                                        <input type="checkbox" name="material[]" value="<?php echo $value->name; ?>">
                                        
                                        <?php echo $value->name; ?>
                                      </label>
                                    </div>
                                    <?php
                                    }
                                }
                            }
                            ?>
                            
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-12"><h4><U>Collections</U></h4></label>
                        <div class="col-sm-12 brbt">   
                                <div class="form-check rdolft">
                                    <input type="radio" class="" name="collection" value="<?php echo $product->_collection.'_'.$product->collection; ?>" checked>
                                    <label class="" for="radio2"><?php echo $product->collection; ?></label>
                                </div>

                                <?php
                                if (count($collections) > 0) {
                                    foreach ($collections as $key => $value) {
                                        if(!empty($value->name) && strtolower($product->collection) != strtolower($value->name)){
                                        ?>
                                        <div class="form-check rdolft">
                                            <input type="radio" class="" name="collection" value="<?php echo $value->id.'_'.$value->name; ?>">
                                            <label class="" for="radio2"><?php echo $value->name; ?></label>
                                        </div>
                                        <?php
                                        }
                                    }
                                }
                                ?>                           
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-8">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="form-group">
                        <label class="col-sm-12"><h4><U>Image</U></h4></label>
                        <div class="col-sm-12">
                            <img src="https://www.modernrugs.com/<?php echo $product->large_pic; ?>" width="100%">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</form>
            
<script>
    
   $(document).ready(function () {
        //Select2
        $(".customer").select2({
           
        });

        $(".select2").select2({
           
        });
        
        $("select").on("select2:select", function (evt) {
          var element = evt.params.data.element;
          var $element = $(element);
          
          $element.detach();
          $(this).append($element);
          $(this).trigger("change");
        });

        $("#designer").select2({
        minimumInputLength: 3,
        tags: [],
        ajax: {
            url: "/admin/Design/getDesignerByText",
            dataType: 'json',
            type: "GET",
            quietMillis: 50,
            data: function (keyword) {
                //console.log(keyword);
                return {
                    keyword
                };
            },
            processResults: function (data) {
                //console.log(data)
                return {
                    results: data
                  };
            }
        }
        });
       

       $('.save_attributes').on('click',function(){
            $(".fa-spin").css("display", "inline-block");
            $(".fa-save").css("display", "none");

            $.ajax({
                url: '<?php echo site_url('All_products/save_attributes');?>',
                type: "POST",
                data:$('#attributes_data').serialize(),
                success: function(data){
                    $(".fa-spin").css("display", "none");
                    $(".fa-save").css("display", "inline-block");
                    window.location.href = '<?php echo site_url("all_products/optionsEdit/".$product->id);?>';
                }
            });
        });
    });

    
</script>    

<script src=
"https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js">
       </script>        