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

@section('style')
    <style>
        .signature-sec {
            display: flex;
            flex-direction: column;
            align-items: start;
            padding-inline: 10px;
            gap: 10px;
            width: 200px;
        }
    </style>
@endsection

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

    @include('travel::travel-plans.nav', ['plan_id' => $data['travelPlan']->id, 'is_approved' => $data['travelPlan']->status_id == 5 ? true : false])

    <div class="card ot-card">
        <div class="card-body">
            <div class="row">
                <div class="col-lg-6">
                    <table class="table table-striped table-borderless w-100">
                        <tr>
                            <th>{{ _trans('common.Employee') }}</th>
                            <td>: {{ $data['travelPlan']->employee->name }}</td>
                        </tr>
                        <tr>
                            <th>{{ _trans('common.Designation') }}</th>
                            <td>: {{ @$data['travelPlan']->employee->designation->title }}</td>
                        </tr>
                        <tr>
                            <th>{{ _trans('common.From Date') }}</th>
                            <td>: {{ $data['travelPlan']->from_date }}</td>
                        </tr>
                        <tr>
                            <th>{{ _trans('common.To Date') }}</th>
                            <td>: {{ $data['travelPlan']->to_date }}</td>
                        </tr>
                    </table>
                </div>
                <div class="col-lg-6">
                    <table class="table table-striped table-borderless w-100">
                        <tr>
                            <th>{{ _trans('common.From Location') }}</th>
                            <td>: {{ $data['travelPlan']->from_location }}</td>
                        </tr>
                        <tr>
                            <th>{{ _trans('common.To Location') }}</th>
                            <td>: {{ $data['travelPlan']->to_location }}</td>
                        </tr>
                        <tr>
                            <th>{{ _trans('common.Amount') }}</th>
                            <td>: {{ $data['travelPlan']->amount }}</td>
                        </tr>
                        <tr>
                            <th>{{ _trans('common.Status') }}</th>
                            <td>: 
                                <span class="badge badge-{{ $data['travelPlan']->status->class }}">
                                    {{ $data['travelPlan']->status->name }}
                                </span>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>

            <small class="text-muted mb-3">{{ _trans('common.Meeting') }}: </small>
            <p class="mb-5">{!! nl2br($data['travelPlan']->purpose) !!}</p>
            
            
            <div class="mb-5 signature-sec">
                <img src="{{ $data['travelPlan']->signature }}" alt="signature" width="120">
                <span>{{ $data['travelPlan']->signature_date }}</span>
            </div>

            @if ($data['travelPlan']->status_id == 2 && (hasPermission('travel_plan_approve') || hasPermission('travel_plan_reject')))
                <form action="{{ route('travel.plans.approve-or-reject', $data['travelPlan']->id) }}" method="POST" class="mt-5 bg-light px-3 py-2" onsubmit="return confirm(`{{ trans('common.Are you sure?') }}`)">
                    @csrf
                    
                    <div class="mb-5">
                        <textarea name="remark" class="form-control ot-input" placeholder="{{ _trans('common.Remark') }}">{{ old('approve_remark') }}</textarea>
                        @if ($errors->has('remark'))
                            <span class="error text-danger">
                                {{ $errors->first('remark') }}
                            </span>
                        @endif
                    </div>

                    <div class="d-flex justify-content-end gap-2 pb-3">
                        <a href="{{ route('travel.plans.index') }}" type="submit" 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>

                        @if (hasPermission('travel_plan_approve') && (!request('type') || request('type') == 'approve'))
                            <button class="btn btn-gradian d-flex align-items-center gap-2" name="is_approved" value="1"><i class="las la-check fs-4"></i> {{ _trans('common.Approve') }}</button>
                        @endif

                        @if (hasPermission('travel_plan_reject') && (!request('type') || request('type') == 'reject'))
                            <button class="btn btn-danger d-flex align-items-center gap-2" name="is_rejected" value="1"><i class="las la-ban fs-4"></i> {{ _trans('common.Reject') }}</button>
                        @endif
                    </div>
                </form>
            @endif

            <div class="mt-5 bg-light px-3 py-2">
                @if ($data['travelPlan']->status_id == 5 && $data['travelPlan']->approved_remark)
                    <small class="text-muted">{{ _trans('common.Remark') }}: </small>
                    <p>{!! nl2br($data['travelPlan']->approved_remark) !!}</p>
                @elseif ($data['travelPlan']->status_id == 6 && $data['travelPlan']->rejected_remark)
                    <small class="text-muted">{{ _trans('common.Remark') }}: </small>
                    <p>{!! nl2br($data['travelPlan']->rejected_remark) !!}</p>
                @endif
            </div>
        </div>
    </div>
@endsection
