@component('components.widget', ['title' => $editing ? 'Edit promotion' : 'Create promotion'])
{!! Form::open([
'route' => $editing ? ['advanced-promotions.update', $editing->id] : 'advanced-promotions.store',
'method' => $editing ? 'put' : 'post',
'id' => 'advanced_promotion_form'
]) !!}
{!! Form::label('name', 'Name:*') !!}
{!! Form::text('name', old('name', optional($editing)->name), ['class' => 'form-control', 'required']) !!}
{!! Form::label('priority', 'Priority:*') !!}
{!! Form::number('priority', old('priority', optional($editing)->priority ?? 0), ['class' => 'form-control', 'required']) !!}
{!! Form::label('rule_type', 'Rule type:*') !!}
{!! Form::select('rule_type', [
'percentage' => 'Percentage off',
'fixed_cart' => 'Fixed amount off cart',
'buy_x_get_y' => 'Buy X, get Y free',
], old('rule_type', optional($editing)->rule_type), ['class' => 'form-control', 'required', 'id' => 'promotion_rule_type']) !!}
{!! Form::label('discount_value', 'Discount value:') !!}
{!! Form::number('discount_value', old('discount_value', optional($editing)->discount_value ?? 0), ['class' => 'form-control', 'step' => '0.01', 'min' => 0]) !!}
{!! Form::label('buy_quantity', 'Buy quantity:') !!}
{!! Form::number('buy_quantity', old('buy_quantity', optional($editing)->buy_quantity ?? 1), ['class' => 'form-control', 'min' => 1]) !!}
{!! Form::label('get_quantity', 'Free quantity:') !!}
{!! Form::number('get_quantity', old('get_quantity', optional($editing)->get_quantity ?? 1), ['class' => 'form-control', 'min' => 1]) !!}
{!! Form::label('minimum_spend', 'Minimum eligible spend:') !!}
{!! Form::number('minimum_spend', old('minimum_spend', optional($editing)->minimum_spend ?? 0), ['class' => 'form-control', 'step' => '0.01', 'min' => 0]) !!}
{!! Form::label('minimum_quantity', 'Minimum eligible quantity:') !!}
{!! Form::number('minimum_quantity', old('minimum_quantity', optional($editing)->minimum_quantity ?? 0), ['class' => 'form-control', 'step' => '0.01', 'min' => 0]) !!}
{!! Form::label('maximum_discount', 'Maximum discount:') !!}
{!! Form::number('maximum_discount', old('maximum_discount', optional($editing)->maximum_discount), ['class' => 'form-control', 'step' => '0.01', 'min' => 0, 'placeholder' => 'No limit']) !!}
{!! Form::label('coupon_code', 'Coupon code:') !!}
{!! Form::text('coupon_code', old('coupon_code', optional($editing)->coupon_code), ['class' => 'form-control', 'placeholder' => 'Blank = automatic']) !!}
{!! Form::label('usage_limit', 'Overall use limit:') !!}
{!! Form::number('usage_limit', old('usage_limit', optional($editing)->usage_limit), ['class' => 'form-control', 'min' => 1, 'placeholder' => 'Unlimited']) !!}
{!! Form::label('per_customer_limit', 'Per-customer limit:') !!}
{!! Form::number('per_customer_limit', old('per_customer_limit', optional($editing)->per_customer_limit), ['class' => 'form-control', 'min' => 1, 'placeholder' => 'Unlimited']) !!}
{!! Form::label('starts_at', 'Starts at:') !!}
{!! Form::label('ends_at', 'Ends at:') !!}
{!! Form::label('location_ids', 'Branches:') !!}
{!! Form::select('location_ids[]', $locations, old('location_ids', (array) optional($editing)->location_ids), ['class' => 'form-control select2', 'multiple', 'data-placeholder' => 'All branches']) !!}
{!! Form::label('customer_group_ids', 'Customer groups:') !!}
{!! Form::select('customer_group_ids[]', $customerGroups, old('customer_group_ids', (array) optional($editing)->customer_group_ids), ['class' => 'form-control select2', 'multiple', 'data-placeholder' => 'All customer groups']) !!}
{!! Form::label('scope_type', 'Applies to:*') !!}
{!! Form::select('scope_type', [
'all' => 'All products',
'products' => 'Selected products',
'variations' => 'Selected product variations',
'categories' => 'Selected categories',
'brands' => 'Selected brands',
], old('scope_type', optional($editing)->scope_type ?? 'all'), ['class' => 'form-control', 'id' => 'promotion_scope_type']) !!}
@php($scopeIds = (array) optional($editing)->scope_ids)
{!! Form::select('scope_product_ids[]', $products, old('scope_product_ids', optional($editing)->scope_type === 'products' ? $scopeIds : []), ['class' => 'form-control select2', 'multiple', 'data-placeholder' => 'Select products']) !!}
{!! Form::select('scope_variation_ids[]', $variations, old('scope_variation_ids', optional($editing)->scope_type === 'variations' ? $scopeIds : []), ['class' => 'form-control select2', 'multiple', 'data-placeholder' => 'Select variations']) !!}
{!! Form::select('scope_category_ids[]', $categories, old('scope_category_ids', optional($editing)->scope_type === 'categories' ? $scopeIds : []), ['class' => 'form-control select2', 'multiple', 'data-placeholder' => 'Select categories']) !!}
{!! Form::select('scope_brand_ids[]', $brands, old('scope_brand_ids', optional($editing)->scope_type === 'brands' ? $scopeIds : []), ['class' => 'form-control select2', 'multiple', 'data-placeholder' => 'Select brands']) !!}