@extends('layouts.layoutMaster')

@section('title', __('Inventory Adjustments'))

@section('vendor-style')
  @vite([
    'resources/assets/vendor/libs/datatables-bs5/datatables.bootstrap5.scss',
    'resources/assets/vendor/libs/datatables-responsive-bs5/responsive.bootstrap5.scss',
    'resources/assets/vendor/libs/datatables-buttons-bs5/buttons.bootstrap5.scss',
    'resources/assets/vendor/libs/sweetalert2/sweetalert2.scss'
  ])
@endsection

@section('vendor-script')
  @vite([
    'resources/assets/vendor/libs/datatables-bs5/datatables-bootstrap5.js',
    'resources/assets/vendor/libs/sweetalert2/sweetalert2.js'
  ])
@endsection

@section('page-script')
  <script>
    const pageData = {
      urls: {
        adjustmentsData: @json(route('wmsinventorycore.adjustments.data')),
        adjustmentsCreate: @json(route('wmsinventorycore.adjustments.create')),
        adjustmentsShow: @json(route('wmsinventorycore.adjustments.show', ['adjustment' => '__ADJUSTMENT_ID__'])),
        adjustmentsEdit: @json(route('wmsinventorycore.adjustments.edit', ['adjustment' => '__ADJUSTMENT_ID__'])),
        adjustmentsDelete: @json(route('wmsinventorycore.adjustments.destroy', ['adjustment' => '__ADJUSTMENT_ID__'])),
        adjustmentsApprove: @json(route('wmsinventorycore.adjustments.approve', ['adjustment' => '__ADJUSTMENT_ID__']))
      },
      filters: {
        warehouses: @json($warehouses),
        adjustmentTypes: @json($adjustmentTypes)
      },
      labels: {
        confirmApprove: @json(__('Are you sure?')),
        confirmApproveText: @json(__('This will approve the adjustment and update inventory levels!')),
        confirmApproveButton: @json(__('Yes, approve it!')),
        approved: @json(__('Approved!')),
        approvedText: @json(__('Adjustment has been approved.')),
        confirmDelete: @json(__('Are you sure?')),
        confirmDeleteText: @json(__("You won't be able to revert this!")),
        confirmDeleteButton: @json(__('Yes, delete it!')),
        deleted: @json(__('Deleted!')),
        deletedText: @json(__('Adjustment has been deleted.')),
        couldNotDeleteAdjustment: @json(__('Could not delete adjustment.')),
        error: @json(__('Error!')),
        export: @json(__('Export')),
        print: @json(__('Print')),
        csv: @json(__('CSV')),
        excel: @json(__('Excel')),
        pdf: @json(__('PDF')),
        // DataTable language labels
        processing: @json(__('Processing...')),
        search: @json(__('Search:')),
        lengthMenu: @json(__('Show _MENU_ entries')),
        info: @json(__('Showing _START_ to _END_ of _TOTAL_ entries')),
        infoEmpty: @json(__('Showing 0 to 0 of 0 entries')),
        infoFiltered: @json(__('(filtered from _MAX_ total entries)')),
        loadingRecords: @json(__('Loading...')),
        zeroRecords: @json(__('No matching records found')),
        emptyTable: @json(__('No data available in table')),
        first: @json(__('First')),
        last: @json(__('Last')),
        next: @json(__('Next')),
        previous: @json(__('Previous'))
      }
    };
  </script>
  @vite(['Modules/WMSInventoryCore/resources/assets/js/wms-inventory-adjustments.js'])
@endsection

@section('content')
@php
  $breadcrumbs = [
    ['name' => __('WMS & Inventory'), 'url' => route('wmsinventorycore.dashboard.index')]
  ];
@endphp

<x-breadcrumb
  :title="__('Inventory Adjustments')"
  :breadcrumbs="$breadcrumbs"
  :homeUrl="route('tenant.dashboard')"
/>

<div class="card">
  <div class="card-header">
    <div class="d-flex justify-content-between align-items-center">
      <h5 class="card-title mb-0">{{ __('All Adjustments') }}</h5>
      @can('wmsinventory.create-adjustment')
        <a href="{{ route('wmsinventorycore.adjustments.create') }}" class="btn btn-primary">
          <i class="bx bx-plus"></i> {{ __('Create Adjustment') }}
        </a>
      @endcan
    </div>
  </div>
  <div class="card-body">
    <div class="row mb-4">
      <div class="col-md-2 mb-2">
        <label class="form-label">{{ __('Filter by Warehouse') }}</label>
        <select id="warehouse-filter" class="form-select">
          <option value="">{{ __('All Warehouses') }}</option>
          @foreach($warehouses as $warehouse)
          <option value="{{ $warehouse->id }}">{{ $warehouse->name }}</option>
          @endforeach
        </select>
      </div>
      <div class="col-md-2 mb-2">
        <label class="form-label">{{ __('Filter by Type') }}</label>
        <select id="type-filter" class="form-select">
          <option value="">{{ __('All Types') }}</option>
          @foreach($adjustmentTypes as $type)
          <option value="{{ $type->id }}">{{ $type->name }}</option>
          @endforeach
        </select>
      </div>
      <div class="col-md-2 mb-2">
        <label class="form-label">{{ __('Filter by Status') }}</label>
        <select id="status-filter" class="form-select">
          <option value="">{{ __('All Statuses') }}</option>
          <option value="pending">{{ __('Pending') }}</option>
          <option value="approved">{{ __('Approved') }}</option>
          <option value="cancelled">{{ __('Cancelled') }}</option>
        </select>
      </div>
      <div class="col-md-2 mb-2">
        <label class="form-label">{{ __('Date From') }}</label>
        <input type="date" id="date-from" class="form-control">
      </div>
      <div class="col-md-2 mb-2">
        <label class="form-label">{{ __('Date To') }}</label>
        <input type="date" id="date-to" class="form-control">
      </div>
    </div>

    <div class="card-datatable table-responsive">
      <table class="table table-bordered datatables-adjustments" id="adjustments-table">
      <thead>
        <tr>
          <th>{{ __('ID') }}</th>
          <th>{{ __('Date') }}</th>
          <th>{{ __('Code') }}</th>
          <th>{{ __('Warehouse') }}</th>
          <th>{{ __('Type') }}</th>
          <th>{{ __('Total') }}</th>
          <th>{{ __('Status') }}</th>
          <th>{{ __('Actions') }}</th>
        </tr>
      </thead>
    </table>
    </div>
  </div>
</div>
@endsection
