@include('admin.layouts.alert-modal') 
<form method="post" action="{{ request()->url() }}" id="input_form">
	@csrf
	<div class="form-group">
		<label>Nama Lengkap <text class="text-danger">*</text></label>
		<input type="text" class="form-control" name="full_name" id="full_name" value="{{ old('full_name') ?? $target->full_name }}">
        <small id="full_name"></small>
	</div>
	<div class="form-group">
		<label>Nomor Telepon <text class="text-danger">*</text></label>
		<input class="form-control" type="number" name="phone_number" id="phone_number" value="{{ old('phone_number') ?? $target->phone_number }}">
        <small id="phone_number"></small>
	</div>
	<div class="form-group">
		<label>Email <text class="text-danger">*</text></label>
		<input class="form-control" type="email" name="email" id="email" value="{{ old('email') ?? $target->email }}">
        <small id="email"></small>
	</div>
	<div class="form-group">
		<label>Username <text class="text-danger">*</text></label>
		<input type="text" class="form-control" name="username" id="username" value="{{ old('username') ?? $target->username }}">
        <small id="username"></small>
	</div>
	<div class="form-group">
		<label>Password {!! request()->segment(4) == null ? '<text class="text-danger">*</text>' : '' !!}</label>
		<input type="password" class="form-control" name="password" id="password" placeholder="{{ request()->segment(4) == true ? 'Kosongkan jika tidak dibutuhkan' : '' }}" value="{{ old('password') }}">
        <small id="password"></small>
	</div>
	<div class="form-group">
		<label>Saldo <text class="text-danger">*</text></label>
		<input type="text" class="form-control autonumeric-currency" name="balance" id="balance" value="{{ old('balance') ?? $target->balance }}">
        <small id="balance"></small>
	</div>
	@if (request()->segment(4) == true)
	<div class="form-group">
		<label>Kunci API <text class="text-danger">*</text></label>
		<div class="input-group">
			<input type="text" class="form-control" name="api_key" id="api_key" value="{{ old('api_key') ?? $target->api_key }}" id="api_key">
			<div class="input-group-append">
				<button class="btn btn-dark" type="button" onclick="create_api_key()"><i class="fa fa-random fa-fw"></i></button>
			</div>
			<small id="api_key"></small>
		</div>
	</div>
	@endif
	<div class="form-group">
		<label>Level <text class="text-danger">*</text></label>
		<select class="custom-select" name="level" id="level">
			<option value="" selected>Pilih...</option>
			@foreach($levels as $item)
				<option value="{{ $item }}" {{ old('level') ? (old('level') == $item ? 'selected' : '') : ($target->level == $item ? 'selected' : '')  }}>{{ $item }}</option>
			@endforeach
		</select>
		<small id="level"></small>
	</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>
<script src="{{ asset('assets/js/modal-form.js') }}"></script>
<script src="{{ asset('assets/js/app.js') }}"></script>
<script>
	function create_api_key() {
		$.ajax({
			type: "GET",
			url: "{{ url('ajax/create_api_key') }}",
			success: function(data) {
				$('#api_key').val(data);
			}
		});
	}
</script>