<?php  $this->load->view('master/common/header.php',$data);
$base_name = $data['base_name'];
$shop = $data['shop'];
$mlm = $data['mlm'];
if($shop == 1){
    if($mlm == 1){
        $col = 'col-sm-3';
        $pvcol = 'col-sm-3';
        $dpcol = 'col-sm-3';
    }
    else
    {
        $col = 'col-sm-3';
        $pvcol = 'col-sm-3 d-none';
        $dpcol = 'col-sm-6';
    }
}
else{
    if($mlm == 1){
        $col = 'col-sm-3';
        $pvcol = 'col-sm-6';
        $dpcol = 'col-sm-3 d-none';
    }
    else
    {
        $col = 'col-sm-4';
        $pvcol = 'col-sm-4 d-none';
        $dpcol = 'col-sm-4 d-none';
    }
}
?>

    <div class="content">
        
        <!-- Start Content-->
        <div class="container-fluid">
            
            <!-- start page title -->
            <div class="row">
                <div class="col-12">
                    <div class="page-title-box">
                        <div class="page-title-right">
                            <ol class="breadcrumb m-0">
                                <li class="breadcrumb-item"><a href="javascript: void(0);"><?= $base_name;?></a></li>
                                <li class="breadcrumb-item active text-capitalize"><?= $page;?></li>
                            </ol>
                        </div>
                        <h4 class="page-title text-uppercase"><?= $page;?></h4>
                    </div>
                </div>
            </div>     
            <!-- end page title --> 

            <div class="row">
                <div class="col-md-12 col-xl-12">
                    <div class="card-box">
                        <div class="row">
                            <div class="col-sm-12">
                                <form class="form-horizontal" action="<?= base_url('master/product/add');?>" method="post" enctype="multipart/form-data">
                                    <input type="hidden" name="table" value="tbl_product" />
                                    <input type="hidden" name="page" value="product/create" />
                                    
                                    <h4 class="header-title mb-4">Product</h4>
                                    
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="tcat_id">Top Category<span class="text-danger">*</span></label>
                                                <select name="tcat_id" id="tcat_id" required="" class="form-control" >
                                                    <option value=""> Select Top Category</option>
                                                    
                                                    <?php if (!empty($top_category)) {?>
                                                        <?php foreach ($top_category as $row) {?>
                                                            <option value="<?=$row['tcat_id'];?>"><?=$row['tcat_name'];?></option>
                                                        <?php } ?>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="mcat_id">Mid Category <span class="text-danger">*</span></label>
                                                <select name="mcat_id"  id="mcat_id" required="" class="form-control" >
                                                    <option value=""> Select Mid Category</option>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="ecat_id">End Category <span class="text-danger">*</span></label>
                                                <select name="ecat_id"  id="ecat_id" required="" class="form-control" >
                                                    <option value=""> Select End Category</option>
                                                </select>
                                            </div>
                                        </div>
                                    
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="p_name">Product Name <span class="text-danger">*</span></label>
                                                <input type="text" name="p_name" id="p_name" required="" class="form-control" />
                                            </div>
                                        </div>  
                                        
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label for="tags">Product Tags <span class="text-danger">*</span></label>
                                                <div class="tags-default">
                                                    <input type="text" name="tags" id="tags" data-role="tagsinput" placeholder="Add tags Like - tag1,tag2"  class="form-control" required />
                                                </div>
                                            </div>
                                        </div> 
                                        <div class="col-sm-12 mb-2">
                                            <label for="userName" class="w-100 d-block">Product Size, Old Price, Current Price, Stock, Min. Stock <span class="text-danger">*</span><b class="btn btn-xs cursor-pointer float-right btn-info" id="btnAddSize">Add More +</b></label>
                                            <div class="parent" id="valueadd">
                                                <div class="row mb-2">
                                                    <div class="form-group <?=$col;?>" id="size1"> 
                                                        <label for="size">Product Size<span class="text-danger">*</span></label>
                                                        <select name="size[]" id="size" class="form-control" required>
                                                            <option value=""> Select Product Size</option>
                                                            <?php
                                                                if(!empty($size)){
                                                                    foreach($size as $row2){
                                                                        echo '<option value="'.$row2['size_id'].'">'.$row2['size_name'].'</option>';
                                                                    }
                                                                }
                                                            ?>
                                                        </select>
                                                    </div>
                                                    
                                                    <div class="form-group <?=$col;?>" id="color1"> 
                                                        <label for="size">Product Color<!--<span class="text-danger">*</span>--></label>
                                                        <!--<select name="color[0][]" class="form-control" multiple="multiple" id="multi_color_new" data-placeholder="Select Product Color">-->
                                                        <select name="color[]" class="form-control" data-placeholder="Select Product Color">
                                                            <option value=""> Select Color</option>
                                                            <?php
                                                                if(!empty($color)){
                                                                    foreach($color as $row3){
                                                                        echo '<option value="'.$row3['color_id'].'">'.$row3['color_name'].'</option>';
                                                                    }
                                                                }
                                                            ?>
                                                        </select>
                                                    </div>
                                                    
                                                    <div class="form-group <?=$col;?>" id="price1"> 
                                                        <label for="size">Product Old Price<span class="text-danger">*</span></label>
                                                        <input type="number" step="any" class="form-control" name="p_old_price[]" placeholder="Enter MRP " required />
                                                    </div>
                                                    <div class="form-group <?=$col;?>" id="price2"> 
                                                        <label for="size">Product Current Price<span class="text-danger">*</span></label>
                                                        <input type="number" step="any" class="form-control" name="p_current_price[]" placeholder="Enter Selling Price" required />
                                                    </div>
                                                    <div class="form-group <?=$dpcol;?>" id="price3"> 
                                                        <label for="size">Product DP Price<span class="text-danger">*</span></label>
                                                        <input type="number" step="any" class="form-control" name="p_dp_price[]" placeholder="Enter DP Price" value="<?=($shop==1) ? '' : '0' ;?>" />
                                                    </div>
                                                    <div class="form-group <?=$pvcol;?>" id="price4"> 
                                                        <label for="size">Product GST%<span class="text-danger">*</span></label>
                                                        <input type="text" class="form-control" name="p_pv[]" placeholder="Enter GST %" value="<?=($mlm==1) ? '' : '0' ;?>" />
                                                    </div>
                                                    <div class="form-group <?=$col;?>"  id="stock1"> 
                                                        <label for="size">Product Stock QTY<span class="text-danger">*</span></label>
                                                        <input type="number" class="form-control" name="p_qty[]" placeholder="Enter Stock" required />
                                                    </div>
                                                    <div class="form-group <?=$col;?>"  id="stock2">
                                                        <label for="size">Product Min. Stock QTY<span class="text-danger">*</span></label>
                                                        <input type="number" class="form-control" name="p_qty2[]" placeholder="Enter Min. Stock" required />
                                                    </div>
                                                    
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <div class="col-sm-12">
                                            <div class="form-group">
                                                <label for="photo">Product Photo (600px X 600px)<span class="text-danger">*</span></label>
                                                <input type="file" name="photo" id="photo" class="dropify" />
                                            </div>
                                        </div>
                                        
                                    
                                        <div class="col-sm-12">
                                            <label for="userName">Other Product  Photo (600 X 600px)</label>
                                           	<div class="input-group control-group after-add-more">
                                              <input type="file" name="p_photo[]" class="form-control">
                                              <div class="input-group-btn"> 
                                                <button class="btn btn-success add-more" type="button"><i class="fa fa-plus"></i> Add</button>
                                              </div>
                                            </div>
                                        </div>
                                            
                                        <div class="col-sm-12">
                                            <!-- Copy Fields -->
                                            <div class="copy hide">
                                                <div class="control-group input-group my-2">
                                                    <input type="file"  name="p_photo[]" class="form-control">
                                                    <div class="input-group-btn"> 
                                                        <button class="btn btn-danger remove" type="button"><i class="glyphicon glyphicon-remove"></i> Remove</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="form-group">
                                                <label for="userName">Product Details </label>
                                                <textarea type="text" name="p_description" id="summernote"  class="form-control" rows="4"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="form-group">
                                                <label for="userName">Product Features </label>
                                                <textarea type="text" name="p_feature" id="summernote"  class="form-control" rows="4"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="form-group">
                                                <label for="userName">Product Condition </label>
                                                <textarea type="text" name="p_condition" id="summernote"  class="form-control" rows="4"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="form-group">
                                                <label for="userName">Product Return Policy </label>
                                                <textarea type="text" name="p_return_policy" id="summernote"  class="form-control" rows="4"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group mb-1 w-100 d-block">
                                        <label for="" class="w-100 d-block control-label">Is Active?</label>
                                        <div class="custom-control custom-radio float-left">
        									<input class="custom-control-input" value="1" required type="radio" id="statusActive" checked name="p_is_active" />
        									<label for="statusActive" class="custom-control-label">Yes</label>
        								</div>
        								<div class="custom-control custom-radio float-left ml-3">
        									<input class="custom-control-input" value="0" required type="radio" id="statusBlock" name="p_is_active" />
        									<label for="statusBlock" class="custom-control-label">No</label>
        								</div>
                                    </div>
                                    
                                    <br> <br>
                                    <div class="form-group mb-1 w-100 d-block">
                                        <label for="" class="w-100 d-block control-label">Is Todays Best Deal?</label>
                                        <div class="custom-control custom-radio float-left">
        									<input class="custom-control-input" value="1" required type="radio" id="statusTodaysActive" name="todays_best_deal" />
        									<label for="statusTodaysActive" class="custom-control-label">Yes</label>
        								</div>
        								<div class="custom-control custom-radio float-left ml-3">
        									<input class="custom-control-input" value="0" required type="radio" id="statusTodaysBlock" checked name="todays_best_deal" />
        									<label for="statusTodaysBlock" class="custom-control-label">No</label>
        								</div>
                                    </div>
                                    <br> <br>
                                    
                                    <div class="form-group mb-1 w-100 d-block">
                                        <label for="" class="w-100 d-block control-label">Is Featured?</label>
                                        <div class="custom-control custom-radio float-left">
        									<input class="custom-control-input" value="1" required type="radio" id="statusFeaturedActive" name="p_is_featured" />
        									<label for="statusFeaturedActive" class="custom-control-label">Yes</label>
        								</div>
        								<div class="custom-control custom-radio float-left ml-3">
        									<input class="custom-control-input" value="0" required type="radio" id="statusFeaturedBlock" checked name="p_is_featured" />
        									<label for="statusFeaturedBlock" class="custom-control-label">No</label>
        								</div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <button type="submit" class="btn btn-success float-right my-2">Submit</button>
                                    </div>
                                
                                </form>
					        </div>
					    </div>
					</div>
				</div>
				<!-- /.col-md-6 -->
			</div>
			<!-- /.row -->
		</div>
		<!-- /.container-fluid -->
	</div>
	<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php $this->load->view('master/common/footer.php'); ?>

<script>
    $('#tcat_id').change(function(){
        var tcat_id = $(this).val();
        $.post("<?php echo base_url().'master/product/get_mid_category';?>",
          {
              tcat_id: tcat_id
          },
          function(data){
            $('#mcat_id').html(data);
          });
    });
    
    $('#mcat_id').change(function(){
        var mcat_id = $(this).val();
        $.post("<?php echo base_url().'master/product/get_end_category';?>",
          {
              mcat_id: mcat_id
          },
          function(data){
            $('#ecat_id').html(data);
          });
    });
</script>

<script>
    $("#btnAddSize").click(function () {
        var col = $("#size1").html();
        // var col2 = $("#color1").html();
        var count = $('.parent').find('.row').length;
        // var col2 = '<label for="size">Product Color</label><select name="color['+count+'][]" class="form-control" multiple="multiple" id="color_more_'+count+'" data-placeholder="Select Product Color"><?php if(!empty($color)){ foreach($color as $row3){ echo '<option value="'.$row3['color_id'].'">'.$row3['color_name'].'</option>';}}?></select>';
        var col2 = '<label for="size">Product Color</label><select name="color[]" class="form-control" id="color_more_'+count+'" data-placeholder="Select Product Color"><option value=""> Select Color</option><?php if(!empty($color)){ foreach($color as $row3){ echo '<option value="'.$row3['color_id'].'">'.$row3['color_name'].'</option>';}}?></select>';
        
        var col3 = $("#price1").html();
        var col4 = $("#price2").html();
        var col4x = $("#price3").html();
        var col4y = $("#price4").html();
        var col5 = $("#stock1").html();
        var col6 = $("#stock2").html();
        
        var a  = '<div class="row bg-light py-2 border-bottom mb-2" id="ss'+count+'">';
        var a1 = '<div class="col-sm-12">';
        var a2 = '<a href="javascript:void()" onclick="rem('+count+')" class="Delete2 btn btn-danger btn-xs float-right">X</a>';
        var a3 = '</div>';
        var a4 = '<div class="<?=$col;?>">'+col+'</div>';
        var a5 = '<div class="<?=$col;?>">'+col2+'</div>';
        var a6 = '<div class="<?=$col;?>">'+col3+'</div>';
        var a7 = '<div class="<?=$col;?>">'+col4+'</div>';
        var a7x = '<div class="<?=$dpcol;?>">'+col4x+'</div>';
        var a7y = '<div class="<?=$pvcol;?>">'+col4y+'</div>';
        var a8 = '<div class="<?=$col;?>">'+col5+'</div>';
        var a9 = '<div class="col-sm-3">'+col6+'</div>';
        var a10 = '</div>';
        
        var row = a+a1+a2+a3+a4+a5+a6+a7+a7x+a7y+a8+a9+a10;
        
        $("#valueadd").append(row);
        // multicolor(count);
        
    });
    
   /* $('#valueadd').delegate('a.Delete2', 'click', function () {
        $('.Delete2').closest('.parent').find('.row').not(':first').last().fadeOut("slow").remove();
    return false;
    });
    */
    
function rem(id)
{
  $("#ss"+id).fadeOut("slow").remove();  
}
</script>

<script>
$("#statusTodaysActive").click(function(){
    if ($("#statusTodaysActive").is(":checked")) {
        $("#statusFeaturedBlock").prop('checked','true');
    }
});
$("#statusFeaturedActive").click(function(){
    if ($("#statusFeaturedActive").is(":checked")) {
        $("#statusTodaysBlock").prop('checked','true');
    }
});
</script>
<script type="text/javascript">
    $(document).ready(function() {
      $(".add-more").click(function(){ 
          var html = $(".copy").html();
          $(".after-add-more").after(html);
      });


      $("body").on("click",".remove",function(){ 
          $(this).parents(".control-group").remove();
      });
    });
</script>

<script>
    function multicolor(id){
            var width = $("#color1").width();
        $("#color_more_"+id).multiselect({
                buttonWidth: width+'px'
            });
            $("#color_more_"+id).addClass('multi_color');
    }
</script>

<script>
        $(function() {
            var width = $("#color1").width();
            $("#multi_color_new").multiselect({
                buttonWidth: width+'px'
            });
            $("#multi_color_new").addClass('multi_color');
        });
</script>