@extends('backend.layouts.master')

@section('styles')
	<!-- CHOICES CSS -->
	<link rel="stylesheet" href="{{ asset('assets/libs/choices.js/public/assets/styles/choices.min.css') }}">
@endsection

@section('content')
	<div class="content">
		@if ($insurer)
			<!-- Edit mode -->
			<div id="insurer-dashboard" class="main-content">
				<div class="block justify-between page-header sm:flex">
					<div>
						<h3 class="text-gray-700 hover:text-gray-900 dark:text-white dark:hover:text-white text-2xl font-medium">
							{{ $insurer->short_name }}</h3>
					</div>
					<div>
						@if (session('status'))
							<script>
								document.addEventListener("DOMContentLoaded", function() {
									notifier.success("{{ session('status') }}");
								});
							</script>
						@endif
					</div>
				</div>

				<div class="grid grid-cols-12 gap-x-6">
					<div class="col-span-12 lg:col-span-3">
						<div class="box">
							<div class="box-body pt-6">
								@include('backend.insurance.insurers.components.sidebar')
							</div>
						</div>
					</div>
					<div class="col-span-12 lg:col-span-9">
						<div class="grid grid-cols-12 gap-x-5">
							<div class="col-span-12 lg:col-span-8">
								@include('backend.insurance.insurers.forms.insurer-form-edit', [
									'insurer' => $insurer,
									'readonly' => $readonly,
								])
							</div>
							<div class="col-span-12 lg:col-span-4">
								@if ($insurer->lastActiveResidence)
									@include('backend.insurance.insurers.forms.address-residence-form-edit', ['insurer' => $insurer])
								@else
									@include('backend.insurance.insurers.forms.address-residence-form', [
										'insurer' => $insurer,
									])
								@endif
							</div>
						</div>
					</div>
				</div>
			</div>
		@else
			<!-- Create mode -->
			<div id="insurer-dashboard" class="main-content">
				<div class="block justify-between page-header sm:flex">
					<div>
						<h3 class="text-gray-700 hover:text-gray-900 dark:text-white dark:hover:text-white text-2xl font-medium">
							Novo osiguranje </h3>
					</div>
					<div>
						@if (session('status'))
							<script>
								document.addEventListener("DOMContentLoaded", function() {
									notifier.success("{{ session('status') }}");
								});
							</script>
						@endif
					</div>
				</div>

				<div class="grid grid-cols-12 gap-x-6">
					<div class="col-span-12 lg:col-span-2">
						<div class="box">
							<div class="box-body pt-6">
								@include('backend.insurance.insurers.components.sidebar')
							</div>
						</div>
					</div>
					<div class="col-span-12 lg:col-span-10">
						<div class="grid grid-cols-12 gap-x-5">
							<div class="col-span-12 lg:col-span-8">
								@include('backend.insurance.insurers.forms.insurer-form', [
									'readonly' => $readonly,
								])
							</div>
							<div class="col-span-12 lg:col-span-4">
								@include('backend.insurance.insurers.placeholders.address-form')
							</div>
						</div>
					</div>
				</div>
			</div>
		@endif
	</div>

@endsection

@section('scripts')
	<!-- CHOICES JS -->
	<script src="{{ asset('assets/libs/choices.js/public/assets/scripts/choices.min.js') }}"></script>

	@if ($insurer)
		<script>
			window.__IS_READONLY__ = @json($readonly);

			// For residence
			window.__OLD_residence_city_id = "{{ old('residence.city_id') }}";
			window.__EXISTING_residence_city_id = "{{ optional($insurer->lastActiveResidence)->city_id }}";
		</script>

		@vite(['resources/js/choices-setup.js'])
	@endif
@endsection
