@extends('admin.master')
@section('title') Business Type | SHOP @endsection
@section('business-type') active @endsection
@section('business-type.index') active @endsection
@section('styles')
@endsection

<!-- BEGIN: Content-->
@section('main_content_section')
<div class="row py-3 ps-2">
  <div class="heading d-flex justify-content-start heading-margin-bottom-minus">
    <h3 class="mb-0"><span>Business Type List</span></h3>
  </div>
</div>


<div class="table_wrapper py-1 card">
  <div class="row my-2 aggregate-section-div">
    <div class="px-3 ">
      <div class=" d-flex justify-content-between align-items-center aggregate-section border">
        <div class="d-flex align-items-center py-1">
          <p class="mb-0"><a href="{{route('business-type.index')}}" class="text-primary  py-2 px-3 active">All
              ({{ $allBusinessTypeCount }})</a>
          </p>
        </div>
        <div class="d-none d-sm-block">
          @if (Auth::user()->can('business-type-create'))
          <a href="javascript:void(0)" class="btn btn-success rounded-0 d-flex align-items-center px-2 border-0"
            data-bs-toggle="modal" data-bs-target="#addBusinessType"><span class="">New Type</span></a>
          @endif
        </div>
      </div>

      @if (Auth::user()->can('business-type-create'))
      <div class="mt-2 btn btn-success d-block rounded-0 d-sm-none" data-bs-toggle="modal" data-bs-target="#addBusinessType">
        New Type</div>
      @endif
    </div>
  </div>



  <div class="row px-3">
    <div class="table-container table-responsive">
      <table id="" class="table table-bordered">
        <thead class="text-uppercase">
          <tr class="me-3">

            <th class="text-center" scope="col"><span>Name</span></th>
            <th class="text-center" scope="col"><span>Status</span></th>
            <th class="text-center w-25" scope="col"><span>Created</span></th>

          </tr>
        </thead>
        <tbody class="text-center">

          @foreach ($businessTypeData as $item)
          @if(isset($item) && $item != null)
          <tr class="">
            <td>
              {{ $item->type_name }}
              <div class="row-actions">
                  @if (Auth::user()->can('business-type-edit'))
                  <span><a href="javascript:void(0)" class="edit_user_modal border-0 bg-transparent fw-bolder"
                      onclick="updateBusinessType({{$item->id}})"> <span class="text-primary">Edit</span></a></span>
                  

                  @if($item->status == true)
                  <span> | <a class="text-warning fw-bolder"
                      href="{{route('business-type-inactive', $item->id)}}">Inactive</a></span>
                  @else
                  <span> | <a class="text-success fw-bolder" href="{{route('business-type-active', $item->id)}}">Active</a></span>
                  @endif

                  @endif

                  @if (Auth::user()->can('business-type-delete'))
                  <span> | <a class="text-danger fw-bolder delete" href="{{route('business-type-delete', $item->id)}}">Delete</a></span>
                  @endif
              </div>
            </td>

            <td>
              @if($item->status == true)
              <span class="badge bg-success">Active</span>
              @else
              <span class="badge bg-warning">Inactive</span>
              @endif
            </td>

            <td class="text-start w-25">
              <b>Date: </b>{{Carbon\Carbon::parse($item->created_at->toDateString())->format('d-m-Y')}} <br>
              <b>Time: </b>{{Carbon\Carbon::create($item->created_at->toTimeString())->format('h:i')}}
            </td>

          </tr>

          {{-- edit modal  --}}
          <div class="modal fade" id="updateBusinessType{{$item->id}}" tabindex="-1" aria-labelledby="oneInputModalLabel"
            aria-hidden="true" data-bs-backdrop="static">
            <div class="modal-dialog modal-dialog-centered max-width-1000px">
              <div class="modal-content">
                <div class="modal-header">
                  <h1 class="modal-title fs-5" id="oneInputModalLabel">Update Business Type</h1>
                  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body p-0">
                  <form action="{{ route('business-type.update', $item->id) }}" method="post" enctype="multipart/form-data"
                    onsubmit="return checkValidateForUpdate({{$item->id}})">
                    @csrf
                    @method('put')
                    <div class="row px-4">
                      <div class=" col-md-12 my-1">
                        <label for="type_name" class="form-label mb-2">Type Name <span
                            class="text-danger">(required)</span></label>
                        <input type="text" class="form-control  form-control-solid" name="type_name" id="type_name"
                          placeholder="Type Name" value="{{$item->type_name}}" required>

                        @error('type_name')
                        <span class=text-danger>{{$message}}</span>
                        @enderror
                      </div>
                      
                    </div>
                    <div class="modal-footer">
                      <div class="">
                        <button type="submit" class="btn btn-success">Update</button>
                        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button>
                      </div>
                    </div>
                  </form>
                </div>
              </div>
            </div>
          </div>
          @endif
          @endforeach


        </tbody>
      </table>
    </div>

    @if(isset($allBusinessTypeCount) && $allBusinessTypeCount > 10)
    <div class="clearfix d-flex pb-2">
      <div class="float-left">
        <p class="text-muted">
          {{ __('Showing') }}
          <span class="font-weight-bold">{{ $businessTypeData->firstItem() }}</span>
          {{ __('to') }}
          <span class="font-weight-bold">{{ $businessTypeData->lastItem() }}</span>
          {{ __('of') }}
          <span class="font-weight-bold">{{ $businessTypeData->total() }}</span>
          {{ __('results') }}
        </p>
      </div>

      <div class="float-right custom-table-pagination">
        {!! $businessTypeData->links('pagination::bootstrap-4') !!}
      </div>
    </div>
    @endif

  </div>

  {{-- create modal  --}}
  <div class="modal fade" id="addBusinessType" tabindex="-1" aria-labelledby="oneInputModalLabel" aria-hidden="true"
    data-bs-backdrop="static">
    <div class="modal-dialog modal-dialog-centered max-width-900px">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5" id="oneInputModalLabel">New Business Type</h1>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body p-0">
          <form action="{{ route('business-type.store') }}" method="POST" onsubmit="return checkValidate()">
            @csrf
            <div class="row px-4">
              <div class=" col-md-12 my-1">
                <label for="type_name" class="form-label mb-2">Type Name <span class="text-danger">(required)</span></label>
                <input type="text" class="form-control  form-control-solid" name="type_name" id="type_name" placeholder="Type Name"
                  required>

                @error('type_name')
                <span class=text-danger>{{$message}}</span>
                @enderror
              </div>
            </div>
            <div class="modal-footer">
              <div class="">
                <button type="submit" class="btn btn-success">Save</button>
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>

</div>
@endsection


@section('scripts')
<script>
    function checkValidate() {
        return true;
    }
    
    //For update...
    function checkValidateForUpdate(id) {
        return true;
    }
    
    //To show update modal...
    function updateBusinessType(id) {
      $("#updateBusinessType"+id).modal('show');
    }
</script>
@endsection