@include('admin.layouts.alert-modal') 
<div class="row">
    <div class="col-lg-3 mb-2 mb-sm-0">
        <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
            <a class="nav-link active show" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home"
                aria-selected="true">
                <i class="mdi mdi-home-variant"></i>
                <span class="">Utama</span>
            </a>
            <a class="nav-link" id="v-pills-settings-tab" data-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings"
                aria-selected="false">
                <i class="mdi mdi-cog"></i>
                <span class="">Pengaturan</span>
            </a>
        </div>
    </div> 
    <div class="col-lg-9">
        <form method="post" action="{{ request()->url() }}" id="input_form">
        @csrf
        <div class="tab-content" id="v-pills-tabContent">
            <div class="tab-pane fade active show" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
                <div class="row">
                    <div class="form-group col-lg-12">
                        <label>Kategori <text class="text-danger">*</text></label>
                        <select class="form-control" name="category_id" data-toggle="select2">
                            <option value="" selected>Pilih...</option>
                            @foreach($categories as $item)
                                <option value="{{ $item->id }}" {{ old('category_id') ? (old('category_id') == $item->id ? 'selected' : '') : ($target->category_id == $item->id ? 'selected' : '')  }}>{{ $item->name }}</option>
                            @endforeach
                        </select>
                        <small class="text-danger category_id_error"></small>
                    </div>
                    <div class="form-group col-lg-4">
                        <label>Penyedia <text class="text-danger">*</text></label>
                        <select class="form-control" name="provider_id" data-toggle="select2">
                            <option value="" selected>Pilih...</option>
                            @foreach($providers as $item)
                                <option value="{{ $item->id }}" {{ old('provider_id') ? (old('provider_id') == $item->id ? 'selected' : '') : ($target->provider_id == $item->id ? 'selected' : '')  }}>{{ $item->name }}</option>
                            @endforeach
                        </select>
                        <small class="text-danger provider_id_error"></small>
                    </div>
                    <div class="form-group col-lg-4">
                        <label>ID Layanan Penyedia <text class="text-danger">*</text></label>
                        <input type="text" class="form-control" name="provider_service_id" value="{{ old('provider_service_id') ?? $target->provider_service_id }}">
                        <small class="text-danger provider_service_id_error"></small>
                    </div>
                    <div class="form-group col-lg-4">
                        <label>Tipe <text class="text-danger">*</text></label>
                        <select class="form-control" name="type" data-toggle="select2">
                            <option value="" selected>Pilih...</option>
                            <option value="Default" {{ old('type') ? (old('type') == 'Default' ? 'selected' : '') : ($target->type == 'Default' ? 'selected' : '')  }}>Default</option>
                            <option value="Custom Comments" {{ old('type') ? (old('type') == 'Custom Comments' ? 'selected' : '') : ($target->type == 'Custom Comments' ? 'selected' : '')  }}>Custom Comments</option>
                            <option value="Comment Likes" {{ old('type') ? (old('type') == 'Comment Likes' ? 'selected' : '') : ($target->type == 'Comment Likes' ? 'selected' : '')  }}>Comment Likes</option>
                        </select>
                        <small class="text-danger type_error"></small>
                    </div>
                </div>
                <hr />
                <div class="form-group">
                    <label>Nama <text class="text-danger">*</text></label>
                    <input type="text" class="form-control" name="name" value="{{ old('name') ?? $target->name }}">
                    <small class="text-danger name_error"></small>
                </div>
                <div class="row">
                    <div class="form-group col-lg-6">
                        <label>Min. <text class="text-danger">*</text></label>
                        <input type="text" class="form-control autonumeric-quantity" name="min" value="{{ old('min') ?? $target->min }}">
                        <small class="text-danger min_error"></small>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>Maks. <text class="text-danger">*</text></label>
                        <input type="text" class="form-control autonumeric-quantity" name="max" value="{{ old('max') ?? $target->max }}">
                        <small class="text-danger max_error"></small>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group col-lg-6">
                        <label>Harga/K <text class="text-danger">*</text></label>
                        <input type="text" class="form-control autonumeric-currency" name="price" value="{{ old('price') ?? $target->price }}">
                        <small class="text-danger price_error"></small>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>Keuntungan/K <text class="text-danger">*</text></label>
                        <input type="text" class="form-control autonumeric-currency" name="profit" value="{{ old('profit') ?? $target->profit }}">
                        <small class="text-danger profit_error"></small>
                    </div>
                </div>
                <div class="form-group">
                    <label>Deskripsi <text class="text-danger">*</text></label>
                    <textarea class="form-control" name="description" rows="5">{{ old('description') ?? $target->description }}</textarea>
                    <small class="text-danger description_error"></small>
                </div>
                <div class="form-group">
                    <div class="custom-control custom-checkbox">
                        <input type="checkbox" class="custom-control-input" id="is_refill_support" name="is_refill_support" value="1" {{ (old('is_refill_support') ? 'checked' : ($target->is_refill_support == '1' ? 'checked' : ''))  }}> 
                        <label class="custom-control-label font-weight-normal" for="is_refill_support">
                            Support Refill
                        </label>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">
                <div class="form-group">
                    <div class="custom-control custom-checkbox">
                        <input type="checkbox" class="custom-control-input" id="update_service" name="update_service" value="1" {{ isset($target->id) ? (json_decode($target->settings, true)['update_service'] == '1' ? 'checked' : '') : '' }}> 
                        <label class="custom-control-label font-weight-normal" for="update_service">
                            Perbarui Otomatis Layanan
                        </label>
                    </div>
                </div>
                <div class="form-group {{ ($target->id == true AND json_decode($target->settings, true)['update_service'] == '1') ? '' : 'hidden' }}" id="service_settings">
                    <hr />
                    <div class="form-group">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input" id="update_automate[name]" name="update_automate[name]" value="1" {{ isset($target->id) ? (json_decode($target->settings, true)['name'] == '1' ? 'checked' : '') : '' }}> 
                            <label class="custom-control-label font-weight-normal" for="update_automate[name]">
                                Nama Layanan
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input" id="update_automate[min_max]" name="update_automate[min_max]" value="1" {{ isset($target->id) ? (json_decode($target->settings, true)['min_max'] == '1' ? 'checked' : '') : '' }}> 
                            <label class="custom-control-label font-weight-normal" for="update_automate[min_max]">
                                Min. & Maks. Layanan
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input" id="update_automate[price_profit]" name="update_automate[price_profit]" value="1" {{ isset($target->id) ? (json_decode($target->settings, true)['price_profit'] == '1' ? 'checked' : '') : '' }}> 
                            <label class="custom-control-label font-weight-normal" for="update_automate[price_profit]">
                                Harga & Keuntungan Layanan
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input" id="update_automate[description]" name="update_automate[description]" value="1" {{ isset($target->id) ? (json_decode($target->settings, true)['description'] == '1' ? 'checked' : '') : '' }}> 
                            <label class="custom-control-label font-weight-normal" for="update_automate[description]">
                                Deskripsi Layanan
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input" id="update_automate[status]" name="update_automate[status]" value="1" {{ isset($target->id) ? (json_decode($target->settings, true)['status'] == '1' ? 'checked' : '') : '' }}> 
                            <label class="custom-control-label font-weight-normal" for="update_automate[status]">
                                Status Layanan
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input" id="update_automate[custom_comments]" name="update_automate[custom_comments]" value="1" {{ isset($target->id) ? (json_decode($target->settings, true)['custom_comments'] == '1' ? 'checked' : '') : '' }}> 
                            <label class="custom-control-label font-weight-normal" for="update_automate[custom_comments]">
                                Komentar Khusus
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input" id="update_automate[refill_support]" name="update_automate[refill_support]" value="1" {{ isset($target->id) ? (json_decode($target->settings, true)['refill_support'] == '1' ? 'checked' : '') : '' }}> 
                            <label class="custom-control-label font-weight-normal" for="update_automate[refill_support]">
                                Refill Support
                            </label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <hr />
        <div class="button-items d-grid gap-2 hidden" id="process-button">
            <button type="button" class="btn btn-primary btn-block waves-effect waves-light mt-0" disabled>Mohon Tunggu...</button>
        </div>
        <div class="row" id="main-button">
            <div class="col-6">
                <div class="button-items d-grid gap-2">
                    <button type="reset" class="btn btn-secondary btn-block waves-effect waves-light mt-0"><i class="mdi mdi-refresh"></i> Reset</button>
                </div>
            </div>
            <div class="col-6">
                <div class="button-items d-grid gap-2">
                    <button type="submit" class="btn btn-custom btn-block waves-effect waves-light mt-0"><i class="mdi mdi-send-outline"></i> Submit</button>
                </div>
            </div>
        </div>
        </form>
    </div>
</div>
<script src="{{ asset('assets/js/modal-form.js') }}"></script>
<script src="{{ asset('assets/js/app.js') }}"></script>
<script>
    $('input[name="update_service"]').on('change', (event) => {
        if($(event.currentTarget).is(':checked')) {
            $('#service_settings').removeClass('hidden');
        } else {
            $('#service_settings').addClass('hidden');
        }
    });
</script>