@extends('backend.layouts.app')
@section('title', @$data['title'])

@section('content')
    {!! breadcrumb([
        'title' => @$data['title'],
        route('admin.dashboard') => _trans('common.Dashboard'),
        '#' => @$data['title'],
    ]) !!}

    <div class="card ot-card">
        <div class="card-body">
            <form 
                method="POST" 
                action="{{ route('travel.plans.update', $data['travelPlan']->id) }}" 
                enctype="multipart/form-data" 
                autocomplete="off"
                id="form"
            >
                @csrf
                @method('PUT')
                <div class="col-md-12">
                    <div class="row form-group mb-3 text-start">
                        <label for="from_date" class="col-md-4 col-lg-3 col-xl-2 form-label pt-3 text-end">{{ _trans('common.From Date') }} <span class="text-danger">*</span></label>
                        <div class="col-md-8 col-lg-9 col-xl-10">
                            <input type="date" name="from_date" class="form-control ot-form-control ot-input" value="{{ old('from_date', $data['travelPlan']->from_date) }}" required>
                            @if ($errors->has('from_date'))
                                <span class="error text-danger">
                                    {{ $errors->first('from_date') }}
                                </span>
                            @endif
                        </div>
                    </div>
                    <div class="row form-group mb-3 text-start">
                        <label for="to_date" class="col-md-4 col-lg-3 col-xl-2 form-label pt-3 text-end">{{ _trans('common.To Date') }} <span class="text-danger">*</span></label>
                        <div class="col-md-8 col-lg-9 col-xl-10">
                            <input type="date" name="to_date" class="form-control ot-form-control ot-input" value="{{ old('to_date', $data['travelPlan']->to_date) }}" required>
                            @if ($errors->has('to_date'))
                                <span class="error text-danger">
                                    {{ $errors->first('to_date') }}
                                </span>
                            @endif
                        </div>
                    </div>
                    <div class="row form-group mb-3 text-start">
                        <label for="from_location" class="col-md-4 col-lg-3 col-xl-2 form-label pt-3 text-end">{{ _trans('common.From Location') }} <span class="text-danger">*</span></label>
                        <div class="col-md-8 col-lg-9 col-xl-10">
                            <input type="text" name="from_location" class="form-control ot-form-control ot-input" placeholder="{{ _trans('common.From Location') }}" value="{{ old('from_location', $data['travelPlan']->from_location) }}" required>
                            @if ($errors->has('from_location'))
                                <span class="error text-danger">
                                    {{ $errors->first('from_location') }}
                                </span>
                            @endif
                        </div>
                    </div>
                    <div class="row form-group mb-3 text-start">
                        <label for="to_location" class="col-md-4 col-lg-3 col-xl-2 form-label pt-3 text-end">{{ _trans('common.To Location') }} <span class="text-danger">*</span></label>
                        <div class="col-md-8 col-lg-9 col-xl-10">
                            <input type="text" name="to_location" class="form-control ot-form-control ot-input" placeholder="{{ _trans('common.To Location') }}" value="{{ old('to_location', $data['travelPlan']->to_location) }}" required>
                            @if ($errors->has('to_location'))
                                <span class="error text-danger">
                                    {{ $errors->first('to_location') }}
                                </span>
                            @endif
                        </div>
                    </div>
                    <div class="row form-group mb-3 text-start">
                        <label for="to_location" class="col-md-4 col-lg-3 col-xl-2 form-label pt-3 text-end">{{ _trans('common.Travel Purpose') }} <span class="text-danger">*</span></label>
                        <div class="col-md-8 col-lg-9 col-xl-10">
                            <textarea name="purpose" class="form-control ot-input" placeholder="{{ _trans('common.Travel Purpose') }}" required>{{ old('purpose', $data['travelPlan']->purpose) }}</textarea>
                            <p>{{ _trans('common.Seminar, conference, meeting, training, licensing, inspection, audit, etc') }}</p>
                            @if ($errors->has('purpose'))
                                <span class="error text-danger">
                                    {{ $errors->first('purpose') }}
                                </span>
                            @endif
                        </div>
                    </div>
                    <div class="row form-group mb-3 text-start">
                        <label for="amount" class="col-md-4 col-lg-3 col-xl-2 form-label pt-3 text-end">
                            {{-- This condition applies only for a client instance; the else block is correct for other cases --}}
                            @if (config('app.style') === 'demo' || env('APP_STYLE') === "demo")
                                {{ _trans('common.Amount Required') }} <span class="text-danger">*</span>
                            @else
                                {{ _trans('common.Amount') }} <span class="text-danger">*</span>
                            @endif
                        </label>
                        <div class="col-md-8 col-lg-9 col-xl-10">
                            <input type="number" name="amount" class="form-control ot-form-control ot-input" value="{{ old('amount', $data['travelPlan']->amount) }}" step="0.01" min="0" required>
                            @if ($errors->has('amount'))
                                <span class="error text-danger">
                                    {{ $errors->first('amount') }}
                                </span>
                            @endif
                        </div>
                    </div>
                    <div class="row form-group text-start mb-5 mt-5">
                        <label class="col-md-4 col-lg-3 col-xl-2 form-label pt-3 text-end">{{ _trans('common.Signature') }} <span class="text-danger">*</span></label>
                        <div class="col-md-8 col-lg-9 col-xl-10">
                            <input type="hidden" name="signature" id="signature" value="{{ old('signature', $data['travelPlan']->signature) }}">
                            <div class="mb-3">
                                <canvas id="signature-pad" class="signature-pad bg-light" height=200></canvas>
                            </div>
                            <div>
                                <button type="button" class="btn btn-sm btn-secondary" id="undo">
                                    {{ _trans('common.Undo') }}
                                </button>
                                <button type="button" class="btn btn-sm btn-warning" id="clear">
                                    {{ _trans('common.Clear') }}
                                </button>
                            </div>
                            @if ($errors->has('signature'))
                                <span class="error text-danger">
                                    {{ $errors->first('signature') }}
                                </span>
                            @endif
                        </div>
                    </div>
                    <div class="row form-group mb-3 text-start">
                        <label for="signature" class="col-md-4 col-lg-3 col-xl-2 form-label pt-3 text-end">{{ _trans('common.Signature Date') }} <span class="text-danger">*</span></label>
                        <div class="col-md-8 col-lg-9 col-xl-10">
                            <input type="date" name="signature_date" class="form-control ot-form-control ot-input" value="{{ old('signature_date', date('Y-m-d')) }}" required>
                            @if ($errors->has('signature_date'))
                                <span class="error text-danger">
                                    {{ $errors->first('signature_date') }}
                                </span>
                            @endif
                        </div>
                    </div>
                    <div class="d-flex justify-content-end gap-2 mt-5">
                        <a href="{{ route('travel.plans.index') }}" class="btn btn-secondary d-flex align-items-center gap-2">
                            <i class="las la-arrow-left fs-4"></i> 
                            {{ _trans('common.Back to list') }}
                        </a>
                        <button type="button" class="btn btn-gradian d-flex align-items-center gap-2" id="btnSubmit"><i class="las la-check fs-4"></i> {{ _trans('common.Update') }}</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
@endsection

@section('script')
    @include('travel::travel-plans.script')
@endsection