<?php echo $__env->make('dashboard.include.header', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>;

  
  <div class="content-wrapper">
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0">Add Product Attribute</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/home">Home</a></li>
              <li class="breadcrumb-item active">Add Product Attribute</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">
      <div class="card">
        <div class="card-body">
          <div class="row">
            <div class="col-md-12">
            <form class="form-horizontal" method="POST" action="/addattributes">
                <?php echo e(csrf_field()); ?>

            <div class="row">
                <div class="col-md-3"> 
                    <div class="form-group">
                    <input type="hidden" id="id" value="<?php echo e($pro_id); ?>" name="productid">
                        <label for="">Attribute Name <b style="color:red;">*color</b></label><input type="text" class="form-control" name="name" placeholder="Attribute Name*color" required>
                    </div>
                </div>
                <div class="col-md-7">
                    <div class="form-group">
                        <label for="">Attributes <b style="color:red;">*red,black,white</b> </label><input type="text" class="form-control" name="att" placeholder="Attributes *red,black,white" required>
                    </div>
                </div>
                <div class="col-md-2" style="padding-top:32px;"><button type="submit" class="btn btn-block btn-primary">Add Atteribute</button> </div>
           
            </div> 
            </form>
            
            </div>
          </div>
          </div>
        </div>

      <div class="card">
        <div class="card-body">
            <table id="example" class="table table-striped table-bordered" style="width:100%">
            <thead>
                <tr>
                    <th>Product Name</th>
                    <th>Attribute Name</th>
                    <th>Attributes</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php $__currentLoopData = $item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($data->Attributeids->name); ?></td>
                    <td><?php echo e($data->attname); ?></td>
                    <td><?php echo e($data->attributes); ?></td>
                    <td class="text-center">                            
                    <button type="button" data-id="<?php echo e($data->id); ?>" data-name="<?php echo e($data->attname); ?>" data-proid="<?php echo e($data->proid); ?>" data-attname="<?php echo e($data->attributes); ?>" class="btn btn-info btn-xs" data-toggle="modal" data-target="#editordermodel">Edit</button>
                        <a class="btn btn-danger btn-xs" data-id="<?php echo e($data->id); ?>"  href=""><i class="far fa-trash-alt"></i></a>
                    </td>
                    
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
            </tbody>
            <tfoot>
                <tr>
                    <th>Product Name</th>
                    <th>Attribute Name</th>
                    <th>Attributes</th>
                    <th>Action</th>
                </tr>
            </tfoot>
        </table>
        </div>
    </div>

      </div>
    </section>
  </div>
 

<div class="modal fade" id="editordermodel" role="dialog">
        <div class="modal-dialog">
        
          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
                    <h4 class="modal-title">Update Attributes</h4>
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              
            </div>
            
            <form  action="/updateaddattributes"  method="post" enctype="multipart/form-data">
            <?php echo e(csrf_field()); ?>

                <div class="modal-body">
                <input type="hidden" id="id" name="id">
                <input type="hidden" id="pro_id" value="<?php echo e($pro_id); ?>" name="productid">
                <div class="form-group">
                        <label>Attribute Name</label><a style="color:red;">*color</a> 
                        <input type="text" name="name" id="name" class="form-control" />
                    </div>
                    <div class="form-group">
                        <label>Attributes</label> <a style="color:red;">*red,black,white</a> 
                        <input type="text" name="att" id="att" class="form-control" />
                    </div>
                    
                </div>
                  
            <div class="modal-footer">
            <input type="submit" name="btnform1" id="action" class="btn btn-primary right" value="Update Attributes"/>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            </form>
          </div>
          
        </div>

</div>





  <?php echo $__env->make('dashboard.include.footer', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>;
  <script>
    $('#editordermodel').on('show.bs.modal', function (event) {

    var button = $(event.relatedTarget) // Button that triggered the modal

    var id = button.data('id') 
    var name = button.data('name') 
    var attname = button.data('attname') 


    var modal = $(this)
    //   modal.find('.modal-title').text('New message to ' + recipient)
    modal.find('.modal-body #id').val(id)
    modal.find('.modal-body #name').val(name)
    modal.find('.modal-body #att').val(attname)



    })
</script>

<script>
$(document).on('click', '.btn-danger', function (e) {
    e.preventDefault();
    var id = $(this).data('id');
    let ele = this;
    console.log(id);

                swal({
                title: "Are you sure?",
                text: "Are you Sure to Remove Attribute",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "<?php echo e(url('/deletattribute')); ?>/"+id ,
                            method: "POST",
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'JSON',
                            data:{
                                "id":id
                            },
                            success: function (result, code, ex) {
                                swal("Done!", "It was successfully deleted!", "success");
                                $(ele).closest('tr').hide();
                                // $("#here").load(location.href + " #here");
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Treatment Removed", "error");
                }
            })
});
</script>