@extends('backend.layout.main') @section('content')

@if($errors->has('name'))
<div class="alert alert-danger alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>{{ $errors->first('name') }}</div>
@endif
@if($errors->has('image'))
<div class="alert alert-danger alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>{{ $errors->first('image') }}</div>
@endif
@if(session()->has('message'))
  <div class="alert alert-success alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>{{ session()->get('message') }}</div>
@endif
@if(session()->has('not_permitted'))
  <div class="alert alert-danger alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>{{ session()->get('not_permitted') }}</div>
@endif

<section>
    <div class="container">
        <!-- Trigger the modal with a button -->
        <button type="button" class="btn btn-info" data-toggle="modal" data-target="#tailoringcategory-modal"><i class="dripicons-plus"></i> {{trans("file.Add Category")}}</button>&nbsp;

    <!-- Category Modal -->
      <div id="tailoringcategory-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
          <div role="document" class="modal-dialog">
            <div class="modal-content">
              {!! Form::open(['route' => 'tailoringcategory.store', 'method' => 'post', 'files' => true]) !!}
              <div class="modal-header">
                <h5 id="exampleModalLabel" class="modal-title">{{trans('file.Add Category')}}</h5>
                <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true"><i class="dripicons-cross"></i></span></button>
              </div>
              <div class="modal-body">
                <p class="italic"><small>{{trans('file.The field labels marked with * are required input fields')}}.</small></p>
                  <div class="row">
                      <div class="col-md-6 form-group">
                          <label>{{trans('file.name')}} *</label>
                          {{Form::text('name',null,array('required' => 'required', 'class' => 'form-control', 'placeholder' => 'Type category name...'))}}
                      </div>
                  </div>

                  <div class="form-group">
                    <input type="submit" value="{{trans('file.submit')}}" class="btn btn-primary">
                  </div>
              </div>
              {{ Form::close() }}
            </div>
          </div>
      </div>
      <!-- Category Modal -->
    </div>
    <div class="table-responsive container">
        <table id="category-table" class="table" style="width: 100%">
            <thead>
                <tr>
                    <th class="not-exported">#</th>
                    <th>{{trans('file.category')}}</th>
                    {{-- <th>{{trans('file.Number of Product')}}</th> --}}
                    {{-- <th></th>
                    <th>{{trans('file.Stock Worth (Price/Cost)')}}</th> --}}
                    <th class="not-exported">{{trans('file.action')}}</th>
                </tr>
            </thead>
            <tbody>
                @foreach ($categories as $category)
                <tr>
                <td>{{ $category->id }}</td>
                <td>{{ $category->name }}</td>
                <td><div class="btn-group">
                    <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action
                        <span class="caret"></span>
                              <span class="sr-only">Toggle Dropdown</span>
                            </button>
                            <ul class="dropdown-menu edit-options dropdown-menu-right dropdown-default" user="menu">
                                <li>
                                    <button type="button" data-id="36" class="open-EditCategoryDialog btn btn-link" data-toggle="modal" data-target="#editModal-{{ $category->id }}"><i class="dripicons-document-edit"></i> Edit</button>
                                </li>
                                <li class="divider"></li>
                                <form method="POST" action="{{ route('tailoringcategory.destroy',$category->id) }}" accept-charset="UTF-8">
                                    @csrf
                                    @method('DELETE')
                                <li>
                                  <button type="submit" class="btn btn-link" id="{{ $category->id }}" onclick="return tailoringConfirmDelete()"><i class="dripicons-trash"></i> Delete</button>
                                </li></form>
                            </ul>
                        </div>
                </td>
                </tr>

                        <!-- Edit Modal -->
                        <div id="editModal-{{ $category->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
                        <div role="document" class="modal-dialog">
                            <div class="modal-content">
                                {{ Form::open(['route' => ['tailoringcategory.update', $category->id], 'method' => 'PUT', 'files' => true] ) }}
                            <div class="modal-header">
                                <h5 id="exampleModalLabel" class="modal-title">{{trans('file.Update Category')}}</h5>
                                <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true"><i class="dripicons-cross"></i></span></button>
                            </div>
                            <div class="modal-body">
                                <p class="italic"><small>{{trans('file.The field labels marked with * are required input fields')}}.</small></p>
                                <div class="row">
                                    <div class="col-md-6 form-group">
                                        <label>{{trans('file.name')}} *</label>
                                        <input type="text" name="name" required class="form-control" value="{{ $category->name }}">
                                    </div>
                                    <input type="hidden" name="category_id">
                                </div>

                                <div class="form-group">
                                    <input type="submit" value="{{trans('file.submit')}}" class="btn btn-primary">
                                </div>
                                </div>
                            {{ Form::close() }}
                            </div>
                        </div>
                        </div>
                @endforeach
            </tbody>
        </table>
    </div>
</section>



@endsection
@push('scripts')
<script type="text/javascript">
    $("ul#tailoring").siblings('a').attr('aria-expanded','true');
    $("ul#tailoring").addClass("show");
    $("ul#tailoring #tailoringcategory-menu").addClass("active");

    function tailoringConfirmDelete() {
      if (confirm("If you delete category all products under this category will also be deleted. Are you sure want to delete?")) {
          return true;

      }
      return false;
    }

</script>
@endpush
