
<div class="content-wrapper">
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">User Account</h1>
                </div><!-- /.col -->
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="<?=base_url()?>home">Home</a></li>
                    <li class="breadcrumb-item active">User Account</li>
                    </ol>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <hr/>
    <section class="content">
        <div class="container-fluid">
            <form id="f1" action="#" method="post" enctype="multipart/form-data">
                <div class="row">
                    <div class="col-lg-6">
                        <div class="card card-outline card-success">
                            <div class="card-header">
                                <div class="card-title">
                                    Data User
                                </div>
                            </div>
                            <div class="card-body">
                                <div class="form-group">
                                    <label for="username">Username / Sold ID</label>
                                    <span class="form-control form-control-border" id="username">
                                        <?=$user_data->data['sold_id']?>
                                    </span>
                                    <span id="eusername" class="error invalid-feedback"></span>
                                </div>
                                <div class="form-group">
                                    <label for="password">Password</label>
                                    <input type="password" class="form-control form-control-border" id="password" placeholder="Password Login" name="password">
                                    <span id="epassword" class="error invalid-feedback"></span>
                                </div>
                                <div class="form-group">
                                    <input type="submit" class="btn bg-gradient-primary" value="Update Password">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </section>
    <script>
        $(document).ready(function () {
            $("#f1").submit(function (e) {
                e.preventDefault();
                Swal.fire({
                    text: 'Menyimpan data.. Silahkan tunggu..',
                    allowOutsideClick: false
                });
                Swal.showLoading();
                var data_kirim = $("#f1").serialize();
                
                $.post("<?=base_url()?>agen_pengguna_update",data_kirim).done(function (data) {
                    if (data.message == 'success')
                    {
                        Swal.fire({
                            text:'Data User berhasil disimpan.',
                            icon : 'success'
                        }).then(function () {
                            window.location.href = '<?=base_url()?>agen_pengguna';
                        });
                    }
                }).fail(function (data) {
                    if(data.statusText == 'input'){
                        Object.keys(data.responseJSON.messages).forEach(function(key){
                            $("#e"+key).html(data.responseJSON.messages[key]);
                            $("#e"+key).show();
                        });
                        Swal.close();
                    }else{
                        Swal.fire({
                            text:'Terjadi kesalahan pada saat penyimpanan!',
                            icon : 'error'
                        });
                    }
                });
            });
        });
    </script>
</div>