<!-- FLATPICKR CSS -->
<link rel="stylesheet" href="<?php echo e(asset('assets/libs/flatpickr/flatpickr.min.css')); ?>">

<div class="box" id="InsurancePolicy-form-edit">

	<div class="box-body pb-2">
		<form action="<?php echo e(route('osiguranje.insurance-policies.update', [$entity, $insurancePolicy])); ?>" method="POST">
			<?php echo csrf_field(); ?>
			<?php echo method_field('PUT'); ?>
			<input type="hidden" name="entity_id" value="<?php echo e($entity->id); ?>">
			<input type="hidden" name="policy_number" value="<?php echo e($insurancePolicy->id); ?>">
			<input type="hidden" name="status" value="active">
			<input type="hidden" name="insurer_id" value="<?php echo e($insurancePolicy->insurer_id); ?>">
			<input type="hidden" name="commission_default_id" value="<?php echo e($insurancePolicy->commission_default_id); ?>">

			<div class="sm:grid grid-cols-12 gap-x-6 gap-y-4 mb-6">
				<!-- Naziv polise -->
				<div class="col-span-12 lg:col-span-10 flex flex-col space-y-2 w-full rtl:space-y-reverse">
					<label for="custom_name" class="block text-sm font-medium mb-1">
						Naziv polise
					</label>
					<input id="custom_name" name="custom_name" type="text"
						class="ti-form-input w-full <?php $__errorArgs = ['custom_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" placeholder="Naziv polise"
						value="<?php echo e(old('custom_name') ?? $insurancePolicy->custom_name); ?>">
				</div>

				<!-- Procenat -->
				<div class="col-span-12 lg:col-span-2 flex flex-col space-y-2 w-full rtl:space-y-reverse">
					<label for="commission_pct" class="block text-sm font-medium mb-1">
						Procenat
					</label>
					<input id="commission_pct" name="commission_pct" type="text"
						class="ti-form-input w-full <?php $__errorArgs = ['commission_pct'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" placeholder="Broj polise"
						value="<?php echo e(old('commission_pct') ?? $insurancePolicy->commission_pct); ?>">
				</div>
			</div>

			<div class="grid grid-cols-8 gap-x-6 space-y-0 lg:space-y-0 pt-4">
				<div class="space-y-2">
					<label for="policy_number" class="block text-sm font-medium mb-1">
						Broj polise <?php $__errorArgs = ['policy_number'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
							<?php echo e($message); ?>

						<?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
					</label>
					<input type="text" class="my-auto ti-form-input <?php $__errorArgs = ['policy_number'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
						placeholder="Broj polise" name="policy_number"
						value="<?php echo e(old('policy_number') ?? $insurancePolicy->policy_number); ?>">
				</div>
				
				<div class="space-y-2">
					<label class="block text-sm font-medium mb-1">
						Početak osiguranja
					</label>
					<div class="flex rounded-sm shadow-sm">
						<div
							class="px-2 inline-flex items-center border ltr:border-r-0 rtl:border-l-0
                           border-gray-200 bg-gray-50 dark:bg-black/20 dark:border-white/10
                           <?php $__errorArgs = ['start_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
							<i class="ti ti-player-play text-xl text-gray-500 dark:text-white/70"></i>
						</div>
						<input type="text" id="start_date" name="start_date" readonly placeholder="Početak osiguranja"
							value="<?php echo e(old('start_date', $insurancePolicy->start_date)); ?>"
							class="ti-form-input rounded-l-none focus:z-10 flatpickr-input
                           <?php $__errorArgs = ['start_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 focus:border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
					</div>
					<?php $__errorArgs = ['start_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
						<div class="text-red-600 text-xs mt-1"><?php echo e($message); ?></div>
					<?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
				</div>

				
				<div class="space-y-2">
					<label class="block text-sm font-medium mb-1">
						Kraj osiguranja
					</label>
					<div class="flex rounded-sm shadow-sm">
						<div
							class="px-2 inline-flex items-center border ltr:border-r-0 rtl:border-l-0
                           border-gray-200 bg-gray-50 dark:bg-black/20 dark:border-white/10
                           <?php $__errorArgs = ['end_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
							<i class="ti ti-player-stop text-xl text-gray-500 dark:text-white/70"></i>
						</div>
						<input type="text" id="end_date" name="end_date" readonly placeholder="Kraj osiguranja"
							value="<?php echo e(old('end_date', $insurancePolicy->end_date)); ?>"
							class="ti-form-input rounded-l-none focus:z-10 flatpickr-input
                           <?php $__errorArgs = ['end_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 focus:border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
					</div>
					<?php $__errorArgs = ['end_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
						<div class="text-red-600 text-xs mt-1"><?php echo e($message); ?></div>
					<?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
				</div>




				
				<div class="space-y-2">
					<label class="block text-sm font-medium mb-1">
						Kurs (na dan)
					</label>
					<div class="flex rounded-sm shadow-sm">
						<div
							class="px-2 inline-flex items-center border ltr:border-r-0 rtl:border-l-0
                           border-gray-200 bg-gray-50 dark:bg-black/20 dark:border-white/10
                           <?php $__errorArgs = ['rate_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
							<i class="ti ti-player-stop text-xl text-gray-500 dark:text-white/70"></i>
						</div>
						<input type="text" id="rate_date" name="rate_date" readonly placeholder="datum kursa"
							value="<?php echo e(old('rate_date', $insurancePolicy->rate_date)); ?>"
							class="ti-form-input rounded-l-none focus:z-10 flatpickr-input
                           <?php $__errorArgs = ['rate_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 focus:border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
					</div>
					<?php $__errorArgs = ['rate_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
						<div class="text-red-600 text-xs mt-1"><?php echo e($message); ?></div>
					<?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
				</div>				

				<div class="space-y-2">
					<label for="exchange_rate" class="block text-sm font-medium mb-1">
						Kurs <?php $__errorArgs = ['exchange_rate'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
							<?php echo e($message); ?>

						<?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
					</label>
					<input type="number" step="0.000001" class="my-auto ti-form-input <?php $__errorArgs = ['exchange_rate'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
						placeholder="npr. 117.500000" name="exchange_rate" value="<?php echo e(old('exchange_rate') ?? $insurancePolicy->exchange_rate); ?>">
				</div>

				<div class="space-y-2">
					<label for="currency" class="block text-sm font-medium mb-1">
						Valuta <?php $__errorArgs = ['currency'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
							<?php echo e($message); ?>

						<?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
					</label>
					<select name="currency" class="my-0 py-2 ti-form-select font-semibold">
						<?php $__currentLoopData = ['RSD','EUR','USD']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cur): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
							<option value="<?php echo e($cur); ?>" <?php if(old('currency', $insurancePolicy->currency ?? 'RSD') === $cur): echo 'selected'; endif; ?>><?php echo e($cur); ?></option>
						<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
					</select>
				</div>

				<div class="space-y-2">
					<label for="premium" class="block text-sm font-medium mb-1">
						Premija osiguranja <?php $__errorArgs = ['premium'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
							<?php echo e($message); ?>

						<?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
					</label>
					<input type="text" class="my-auto ti-form-input <?php $__errorArgs = ['premium'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
						placeholder="Premija osiguranja" name="premium" value="<?php echo e(old('premium') ?? $insurancePolicy->premium); ?>">
				</div>
				<div class="space-y-2">
					<label for="expected_commission" class="block text-sm font-medium mb-1">
						Očekivana provizija <?php $__errorArgs = ['expected_commission'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
							<?php echo e($message); ?>

						<?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
					</label>
					<input type="text" class="my-auto ti-form-input <?php $__errorArgs = ['expected_commission'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
						placeholder="Očekivana provizija" name="expected_commission"
						value="<?php echo e(old('expected_commission') ?? $insurancePolicy->expected_commission); ?>">
				</div>

			</div>

			<?php if(!$readonly): ?>
				<!-- Submit Button -->
				<div class="flex justify-between">
					<div>

					</div>

					<button type="submit" class="ti-btn ti-btn-outline-success py-1 px-3 mr-0">
						<span>
							<?php echo e(__('forms.Update')); ?>

						</span>
					</button>
				</div>
			<?php endif; ?>
		</form>
	</div>
	<div class="box-footer">
		<div class="grid grid-cols-12 gap-x-2">
			<div class="box shadow-none mb-2 px-2 py-1 col-span-12 md:col-span-6 lg:col-span-9">
				<div class="flex relative border-1">
					<div class="flex-1">
						<div class="flex justify-between items-center mb-1 text-sm">
							<span
								class="text-md font-semibold text-gray-200 dark:text-white"><?php echo e($insurancePolicy->commissionDefault->insuranceType->description); ?></span>
						</div>
						<div class="flex justify-between items-center text-xs">
							<span class="text-gray-300 dark:text-white/70">Vrsta osiguranja</span>
						</div>
					</div>
				</div>
			</div>

			<div class="box shadow-none mb-2 px-2 py-1 col-span-12 md:col-span-6 lg:col-span-3">
				<div class="flex relative border-1">
					<div class="flex-1">
						<div class="flex justify-between items-center mb-1 text-sm">
							<span
								class="text-md font-semibold text-gray-200 dark:text-white"><?php echo e($insurancePolicy->commission_pct_default); ?></span>
						</div>
						<div class="flex justify-between items-center text-xs">
							<span class="text-gray-300 dark:text-white/70">Podrazumevani procenat</span>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<?php $__env->startSection('scripts'); ?>
	<script src="<?php echo e(asset('assets/libs/flatpickr/flatpickr.min.js')); ?>"></script>

	<script>
		document.addEventListener('DOMContentLoaded', function() {
			// basic single-date pickers
			flatpickr('#start_date', {
				dateFormat: 'Y-m-d',
				// you can set minDate, maxDate, locale, etc here
			});

			flatpickr('#end_date', {
				dateFormat: 'Y-m-d',
				// e.g. disallow selecting before the start date
				onOpen: function(selectedDates, dateStr, instance) {
					const start = document.querySelector('#start_date')._flatpickr.selectedDates[0];
					if (start) {
						instance.set('minDate', start);
					}
				}
			});

			flatpickr('#rate_date', {
				dateFormat: 'Y-m-d',
				// you can set minDate, maxDate, locale, etc here
			});
		});
	</script>

	<!-- Alpine -->
	<script src="//unpkg.com/alpinejs" defer></script>

	<!-- 3) Alpine component + TomSelect integration -->
	<script>
		document.addEventListener('DOMContentLoaded', function() {
			flatpickr('#start_date', {
				dateFormat: 'Y-m-d',
				defaultDate: '<?php echo e(old('start_date', $insurancePolicy->start_date)); ?>',
			});

			flatpickr('#end_date', {
				dateFormat: 'Y-m-d',
				defaultDate: '<?php echo e(old('end_date', $insurancePolicy->end_date)); ?>',
				onOpen: function(selectedDates, dateStr, instance) {
					const start = document.querySelector('#start_date')._flatpickr.selectedDates[0];
					if (start) instance.set('minDate', start);
				}
			});

			flatpickr('#rate_date', {
				dateFormat: 'Y-m-d',
				defaultDate: '<?php echo e(old('rate_date', $insurancePolicy->rate_date)); ?>',
			});

		});
	</script>
<?php $__env->stopSection(); ?>
<?php /**PATH C:\laragon\www\policypilot\resources\views/backend/insurance/insurance-policies/forms/insurance-policies-form-edit.blade.php ENDPATH**/ ?>