<div class="row mb-3">
	<div class="col-6">
		<div class="row mb-3">
			<div class="col-12">
				{{ Form::label('article_id', 'Article') }}
				@include('components.form.select', ['name' => 'article_id', 'id_name' => 'article_id', 'list' => $articles ?? null, 'value' => $offer['article_id'] ?? null, 'with_empty' => '', 'class' => 'select2 select_article'])
			</div>
		</div>

		<div class="row mb-3">
			<div class="col-12">
				{{ Form::label('variation_id', 'Déclinaison') }}
				@include('components.form.select', ['name' => 'variation_id', 'id_name' => 'variation_id', 'list' => $variations ?? null, 'value' => $offer['variation_id'] ?? null, 'with_empty' => '', 'class' => 'select2 select_variation'])
			</div>
		</div>

		<div class="row mb-3">
			<div class="col-12">
				{{ Form::label('tariff_id', 'Tarif') }}
				@include('components.form.select', ['name' => 'tariff_id', 'id_name' => 'tariff_id', 'list' => $tariffs ?? null, 'value' => $offer['tariff_id'] ?? null, 'with_empty' => '', 'class' => 'select2 select_tariffs'])
			</div>
		</div>

		@component('components.card', ['title' => 'Disponibilité'])
			<div class="row mb-3">
				<div class="col-12 col-xl-6">
					{{ Form::label('stock_current', 'Appro immédiate') }}
					@include('components.form.inputs.money', ['name' => 'stock_current', 'value' => $offer['stock_current'] ?? 0])
				</div>
			</div>
			<div class="row mb-3">
				<div class="col-6">
					{{ Form::label('stock_delayed', 'Appro sur delai') }}
					@include('components.form.inputs.money', ['name' => 'stock_delayed', 'value' => $offer['stock_delayed'] ?? 0])
				</div>
				<div class="col-6">
					{{ Form::label('delay_type', 'Délai type') }}
					@include('components.form.input', ['name' => 'delay_type', 'value' => $offer['delay_type'] ?? null])
				</div>
			</div>
			<div class="row mb-3">
				<div class="col-6">
					{{ Form::label('stock_ondemand', 'Appro sur demande') }}
					@include('components.form.toggle', ['name' => 'stock_ondemand', 'value' => $offer['stock_ondemand'] ?? 0])
				</div>
				<div class="col-6">
					{{ Form::label('minimum_ondemand', 'Minimum de quantité') }}
					@include('components.form.inputs.money', ['name' => 'minimum_ondemand', 'value' => $offer['minimum_ondemand'] ?? 0])
				</div>
			</div>
		@endcomponent
	</div>
	<div class="col-6">
		@component('components.card', ['title' => 'Previsualisation'])
			<div id="preview-article"></div>
			<div id="preview-variation"></div>
			<div id="preview-tariff"></div>
		@endcomponent
	</div>

</div>

@include('components.save')

@include('load.layout.chevron')
@include('load.form.save')
@include('load.form.select2')

@push('js')
	<script>
		function handleArticle() {
			$('.select_article').change(function() {
				previewArticle($(this).val());
			})
		}

		function previewArticle(id) {
			var url = '{{ route('Admin.Shop.Offers.previewArticle') }}/' + id;
			$('#preview-article').load(url, function() {
				initChevron();
			});
		}

		function handleVariation() {
			$('.select_variation').change(function() {
				previewVariation($(this).val());
			})
		}

		function previewVariation(id) {
			var url = '{{ route('Admin.Shop.Offers.previewVariation') }}/' + id;
			$('#preview-variation').load(url, function() {
				initChevron();
			});
		}

		function handleTariff() {
			$('.select_tariffs').change(function() {
				previewTariff($(this).val());
			})
		}

		function previewTariff(id) {
			var url = '{{ route('Admin.Shop.Offers.previewTariff') }}/' + id;
			$('#preview-tariff').load(url, function() {
				initChevron();
			});
		}

		function initPreview() {
			previewArticle("{{ $offer['article_id'] ?? null }}");
			previewVariation("{{ $offer['variation_id'] ?? null }}");
			previewTariff("{{ $offer['tariff_id'] ?? null }}");
		}

		handleArticle();
		handleVariation();
		handleTariff();
		initChevron();
		initSaveForm('#offer-form');
		initSelect2();
		@if ($offer['id'] ?? false)
			initPreview();
		@endif
	</script>
@endpush