@extends('admin.layouts.app')

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header :title="__('admin/sla.plan_create')" icon="fas fa-stopwatch"
        :buttons="[['label' => __('admin/common.back'), 'route' => route('admin.sla-plans.index'),
                     'icon' => 'fas fa-arrow-left', 'color' => 'outline-secondary']]" />

    <x-admin.alert />

    <form method="POST" action="{{ route('admin.sla-plans.store') }}">
        @csrf
        <div class="row">
            <div class="col-lg-8">
                <x-admin.card>
                    <div class="mb-3">
                        <label class="form-label">{{ __('admin/sla.form_name') }} <span class="text-danger">*</span></label>
                        <input type="text" class="form-control @error('name') is-invalid @enderror"
                               name="name" value="{{ old('name') }}" required>
                        @error('name') <div class="invalid-feedback">{{ $message }}</div> @enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label">{{ __('admin/sla.form_description') }}</label>
                        <textarea class="form-control @error('description') is-invalid @enderror"
                                  name="description" rows="2">{{ old('description') }}</textarea>
                        @error('description') <div class="invalid-feedback">{{ $message }}</div> @enderror
                    </div>

                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label class="form-label">{{ __('admin/sla.form_first_response_time') }} <span class="text-danger">*</span></label>
                            <input type="number" class="form-control @error('first_response_time') is-invalid @enderror"
                                   name="first_response_time" value="{{ old('first_response_time', 60) }}" min="1" required>
                            @error('first_response_time') <div class="invalid-feedback">{{ $message }}</div> @enderror
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="form-label">{{ __('admin/sla.form_resolution_time') }} <span class="text-danger">*</span></label>
                            <input type="number" class="form-control @error('resolution_time') is-invalid @enderror"
                                   name="resolution_time" value="{{ old('resolution_time', 1440) }}" min="1" required>
                            @error('resolution_time') <div class="invalid-feedback">{{ $message }}</div> @enderror
                        </div>
                    </div>

                    <h6 class="mt-3 mb-3">{{ __('admin/sla.form_priority_multipliers') }}</h6>
                    <div class="form-text small mb-3">{{ __('admin/sla.form_priority_multipliers_help') }}</div>
                    <div class="row">
                        <div class="col-md-3 mb-3">
                            <label class="form-label">{{ __('admin/sla.form_priority_low') }}</label>
                            <input type="number" step="0.1" class="form-control" name="priority_low" value="{{ old('priority_low', '2') }}">
                        </div>
                        <div class="col-md-3 mb-3">
                            <label class="form-label">{{ __('admin/sla.form_priority_medium') }}</label>
                            <input type="number" step="0.1" class="form-control" name="priority_medium" value="{{ old('priority_medium', '1') }}">
                        </div>
                        <div class="col-md-3 mb-3">
                            <label class="form-label">{{ __('admin/sla.form_priority_high') }}</label>
                            <input type="number" step="0.1" class="form-control" name="priority_high" value="{{ old('priority_high', '0.5') }}">
                        </div>
                        <div class="col-md-3 mb-3">
                            <label class="form-label">{{ __('admin/sla.form_priority_urgent') }}</label>
                            <input type="number" step="0.1" class="form-control" name="priority_urgent" value="{{ old('priority_urgent', '0.25') }}">
                        </div>
                    </div>
                </x-admin.card>
            </div>

            <div class="col-lg-4">
                <x-admin.card>
                    <div class="mb-3">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" name="business_hours_only" value="1"
                                   id="business_hours_only" {{ old('business_hours_only') ? 'checked' : '' }}>
                            <label class="form-check-label" for="business_hours_only">{{ __('admin/sla.form_business_hours_only') }}</label>
                        </div>
                    </div>

                    <div class="mb-3">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" name="is_active" value="1"
                                   id="is_active" {{ old('is_active', true) ? 'checked' : '' }}>
                            <label class="form-check-label" for="is_active">{{ __('admin/sla.form_is_active') }}</label>
                        </div>
                    </div>

                    {{-- PRC-351 — global default plan (used when a ticket's department has no own SLA plan). --}}
                    <div class="mb-3">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" name="is_global" value="1"
                                   id="is_global" {{ old('is_global') ? 'checked' : '' }}>
                            <label class="form-check-label" for="is_global">{{ __('admin/sla.form_is_global') }}</label>
                            <div class="form-text small">{{ __('admin/sla.form_is_global_help') }}</div>
                        </div>
                    </div>

                    <x-slot:footer>
                        <x-admin.form-actions :cancel-url="route('admin.sla-plans.index')" />
                    </x-slot:footer>
                </x-admin.card>
            </div>
        </div>
    </form>
</div>
@endsection
