@extends('layouts.user')
@section('title', __('suppliers.add_adjust'))

@section('content')
<div class="max-w-3xl mx-auto border border-slate-200 bg-white p-4 shadow-sm text-[13px]">
  <div class="flex items-center justify-between gap-3 border-b border-slate-200 pb-3">
    <div>
      <div class="text-base font-bold text-slate-800">{{ __('suppliers.add_adjust') }}</div>
      <div class="mt-0.5 text-[11px] text-slate-500">
        {{ $supplier->name }} ({{ __('suppliers.manual_correction') }})
      </div>
    </div>

    <a href="{{ route('user.suppliers.ledger.index', $supplier->id) }}"
       class="border border-slate-300 px-3 py-1.5 text-[12px] text-slate-700 hover:bg-slate-50">
      {{ __('suppliers.back') }}
    </a>
  </div>

  @if(session('err'))
    <div class="mt-4 border border-rose-200 bg-rose-50 p-3 text-[12px] text-rose-700">
      {{ session('err') }}
    </div>
  @endif

  @if($errors->any())
    <div class="mt-4 border border-rose-200 bg-rose-50 p-3 text-[12px] text-rose-700">
      <ul class="ml-4 list-disc space-y-0.5">
        @foreach($errors->all() as $e)
          <li>{{ $e }}</li>
        @endforeach
      </ul>
    </div>
  @endif

  <form class="mt-4 grid gap-4"
        method="POST"
        action="{{ route('user.suppliers.ledger.adjust.store', $supplier->id) }}">
    @csrf

    <div>
      <label class="text-[11px] font-semibold text-slate-600">{{ __('suppliers.type') }}</label>
      <input type="text"
             value="{{ __('suppliers.adjust') }}"
             disabled
             class="mt-1 w-full border border-slate-300 bg-slate-50 px-3 py-2 text-[12px] text-slate-600">
      <div class="mt-1 text-[11px] text-slate-500">
        {{ __('suppliers.adjust_hint_supplier') }}
      </div>
    </div>

    <div class="grid gap-3 md:grid-cols-2">
      <div>
        <label class="text-[11px] font-semibold text-slate-600">{{ __('suppliers.debit_optional') }}</label>
        <input type="number"
               name="debit"
               step="any"
               min="0"
               value="{{ old('debit') }}"
               placeholder="Example 100"
               class="mt-1 w-full border border-slate-300 px-3 py-2 text-[12px]">
      </div>

      <div>
        <label class="text-[11px] font-semibold text-slate-600">{{ __('suppliers.credit_optional') }}</label>
        <input type="number"
               name="credit"
               step="any"
               min="0"
               value="{{ old('credit') }}"
               placeholder="Example 100"
               class="mt-1 w-full border border-slate-300 px-3 py-2 text-[12px]">
      </div>
    </div>

    <div>
      <label class="text-[11px] font-semibold text-slate-600">{{ __('suppliers.posted_at_optional') }}</label>
      <input type="datetime-local"
             name="posted_at"
             value="{{ old('posted_at') }}"
             class="mt-1 w-full border border-slate-300 px-3 py-2 text-[12px]">
      <div class="mt-1 text-[11px] text-slate-500">
        {{ __('suppliers.current_time_save_hint') }}
      </div>
    </div>

    <div>
      <label class="text-[11px] font-semibold text-slate-600">{{ __('suppliers.note') }} *</label>
      <textarea name="note"
                rows="3"
                required
                class="mt-1 w-full border border-slate-300 px-3 py-2 text-[12px]">{{ old('note') }}</textarea>
    </div>

    <div class="border-t border-slate-200 pt-3">
      <button type="submit"
              class="bg-slate-900 px-4 py-2 text-[12px] font-medium text-white hover:bg-slate-800">
        {{ __('suppliers.save_adjust') }}
      </button>
    </div>
  </form>
</div>
@endsection