@extends('layouts.app')

@section('content')
@include('closer.closerheader')

    <div class='container'>
            <div class='row d-flex justify-content-center'>
                <div class='col-md-10 pb-3 pt-5 mt-5 text-end'>
                @if (Session::has('success'))
                <div class='text-center alert-dismissible fade show' role='alert'>
                  <b class='text-success'>{{ Session::get('success') }}</b>
                </div>
                @endif
                @if ($errors->any())
                <div class="alert w-50 m-auto">
                <ul class='m-0 text-center ' style='list-style-type:none;'>
                @foreach ($errors->all() as $error)
                <li class='text-danger'>{{ $error }}</li>
                @endforeach
                </ul>
                </div>
                @endif
                    <a  data-bs-toggle="modal" data-bs-target="#addcouponmodal" class='btn btn-primary text-white'><i class="fa fa-plus-circle" aria-hidden="true"></i>
                        Add New Coupon</a>    
                </div>
            </div>

        <div class='row d-flex justify-content-center'>
            <div class='col-md-10'>
            <table id="example" class="table table-striped data-table" style="width:100%">
        <thead>
            <tr class='dt-row'>
                <th>ID</th>
                <th>Coupon Code</th>
                <th>Discount Price</th> 
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
            </div>
        </div>
    </div>

    <!-- Modal -->
<div class="modal fade" id="addcouponmodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add New Coupon</h5>
      </div>
      <div class="modal-body">
      <form method='post' action="{{ route('insertcoupon')}}">
        @csrf

        <div class="form-group my-3">
             <input type="text" class="form-control py-2" name="code" placeholder="Enter Coupon Name">
        </div>   
        <div class="form-group my-3">
            <input type="text" class="form-control py-2" name="discount_price" placeholder="Enter Discount Price">
        </div>  
            <div class="form-group">   
            @foreach($closer as $clsr)
        <input  type="text" hidden class="form-control" id="clsrid" name='closer_id' value='{{$clsr->id}}'>
            @endforeach     
            </div>
    
    
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
        <button type='submit' class='btn btn-primary'>Save Changes</button>
        
    </form>
      </div>
    </div>
  </div>
</div>

    <script type="text/javascript">
  $(function () {
      
    var table = $('.data-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: "{{ route('closer-dashboard') }}",
        columns: [
            {data: 'id'},
            {data: 'code'},
            {
                data: 'discount_price',
                render: function (data, type, row) {
                    return '$' + data;
                }
            },
        ]
    });
      
  });
</script>

@endsection

  