<?php $__env->startSection('title', 'Dashboard'); ?>

<?php $__env->startSection('content-page'); ?>

    <div class="">
        <div class="page-title">
            <div class="title_left">
                <h3>
                    <?php echo $__env->yieldContent('title'); ?>
                </h3>
            </div>
        </div>

        <div class="clearfix"></div>

        <?php if(session('success')): ?>
            <div class="alert alert-success text-uppercase">
                <strong>Berhasil</strong>, <?php echo session('success'); ?>

            </div>
        <?php elseif(session('error')): ?>
            <div class="alert alert-danger text-uppercase">
                <strong>Gagal</strong>, <?php echo session('error'); ?>

            </div>
        <?php endif; ?>

        <div class="row">
            <?php if(session('data')['account_category'] == 'PARTNER'): ?>
                <div class="col-md-6">
                    <div class="row">
                        <div class="animated flipInY col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <div class="tile-stats">
                                <div class="icon">
                                    <i class="fa fa-users"></i>
                                </div>
                                <div class="count">
                                    <?php echo e($totalResponderPartner); ?>

                                </div>
                                <h3>Responder</h3>
                                <a href="<?php echo e(route('pages.account.responder.index-admin', ['member_account_code' => session('data')['member_account_code']])); ?>"
                                    class="btn btn-secondary btn-sm btn-block" style="margin-top: 10px;">
                                    <i class="fa fa-sign-in"></i> Pergi Ke Halaman
                                </a>
                            </div>
                        </div>
                        <div class="animated flipInY col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <div class="tile-stats">
                                <div class="icon">
                                    <i class="fa fa-users"></i>
                                </div>
                                <div class="count">
                                    <?php echo e($totalTransaksiPartnerUmum); ?>

                                </div>
                                <h3>Transaksi</h3>
                                <a href="<?php echo e(route('pages.accounts.user.index-admin', ['member_account_code' => session('data')['institution_id']])); ?>"
                                    class="btn btn-secondary btn-sm btn-block" style="margin-top: 10px;">
                                    <i class="fa fa-sign-in"></i> Pergi Ke Halaman
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            <?php endif; ?>

            <?php if(session('data')['account_category'] != 'PARTNER'): ?>
                <div class="col-md-6">
                    <div class="row">
                        <div class="animated flipInY col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <div class="tile-stats">
                                <div class="icon">
                                    <i class="fa fa-users"></i>
                                </div>
                                <div class="count">
                                    <?php echo e($totalResponder); ?>

                                </div>
                                <h3>Responder</h3>
                                <a href="<?php echo e(route('pages.account.responder.index-admin', ['member_account_code' => session('data')['member_account_code']])); ?>"
                                    class="btn btn-secondary btn-sm btn-block" style="margin-top: 10px;">
                                    <i class="fa fa-sign-in"></i> Pergi Ke Halaman
                                </a>
                            </div>
                        </div>
                        <div class="animated flipInY col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <div class="tile-stats">
                                <div class="icon">
                                    <i class="fa fa-users"></i>
                                </div>
                                <div class="count">
                                    <?php echo e($totalUser); ?>

                                </div>
                                <h3>User</h3>
                                <a href="<?php echo e(route('pages.accounts.user.index-admin', ['member_account_code' => session('data')['member_account_code']])); ?>"
                                    class="btn btn-secondary btn-sm btn-block" style="margin-top: 10px;">
                                    <i class="fa fa-sign-in"></i> Pergi Ke Halaman
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>
                                Detail Paket
                            </h2>
                            <?php if(session('data')['account_category'] == 'INTERNAL'): ?>
                                <?php if($showDetail['detailMembership']['remainingDate'] >= 7): ?>
                                    <button type="button" class="btn btn-primary btn-sm pull-right" data-toggle="modal"
                                        data-target=".bs-example-modal-lg">
                                        <i class="fa fa-plus" style="margin-right: 5px"></i> Tambah Limit User
                                    </button>
                                    <a href="<?php echo e(route('pages.master.paket.index')); ?>"
                                        class="btn btn-primary btn-sm pull-right">
                                        Beli Paket Baru
                                    </a>
                                <?php else: ?>
                                <?php endif; ?>
                            <?php endif; ?>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
                            <div class="row">
                                <div class="col-md-4">
                                    Nama Paket
                                </div>
                                <div class="col-md-5">
                                    <?php echo e($showDetail['detailMembership']['nama_paket'] == "Custom" ? "Voice Call" : $showDetail['detailMembership']['nama_paket']); ?>

                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4">
                                    Status Subscribe
                                </div>
                                <div class="col-md-5">
                                    <?php echo e($showDetail['detailMembership']['status_subscribe']); ?>

                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4">
                                    Sisa Masa Aktif
                                </div>
                                <div class="col-md-5">
                                    <?php echo e($showDetail['detailMembership']['remainingDate']); ?> Hari
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4">
                                    Limit User
                                </div>
                                <div class="col-md-5">
                                    <?php echo e($showDetail['detailMembership']['limit_user']); ?>

                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4">
                                    Limit Responder
                                </div>
                                <div class="col-md-5">
                                    <?php echo e($showDetail['detailMembership']['limit_contact']); ?>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </div>

    <?php if(session('data')['account_category'] != 'PARTNER'): ?>
        <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">

                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">
                            <span aria-hidden="true">×</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">
                            <i class="fa fa-plus"></i> Tambah Data
                        </h4>
                    </div>
                    <div class="modal-body">
                        <input type="hidden" name="code" value="<?php echo e($showDetail['detailMembership']['code']); ?>">
                        <?php if($showDetail['detailMembership']['code']): ?>
                            <input type="hidden" name="id_master_paket_organization"
                                value="<?php echo e($showDetail['detailMembership']['id_master_paket_organization']); ?>">
                        <?php endif; ?>
                        <input type="hidden" name="limit_user"
                            value="<?php echo e($showDetail['detailMembership']['limit_user']); ?>">
                        <input type="hidden" name="member_account_code"
                            value="<?php echo e($showDetail['detailMembership']['member_account_code']); ?>">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="jumlah-user" class="form-label"> Jumlah User </label>
                                    <input type="number" min="1" class="form-control" name="jumlah-user"
                                        id="jumlah-user" placeholder="0">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="harga" class="form-label"> Harga </label>
                            <div id="harga">
                                Rp. 0
                            </div>
                            <input type="hidden" name="limit_user_new" id="limit_user_new">
                        </div>
                        <small class="text-danger fw-bold">
                            Catatan : Masa aktif user menyesuaikan sisa waktu paket (
                                <?php echo e($showDetail['detailMembership']['remainingDate']); ?> Hari
                            )

                        </small>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-success btn-sm btn-block" id="btn-pembayaran">
                            <i class="fa fa-edit"></i> Lanjutkan Pembayaran
                        </button>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('component-js'); ?>
    <script type="text/javascript">
        function formatRupiah(amount) {
            let number_string = amount.toString(),
                split = number_string.split(','),
                sisa = split[0].length % 3,
                rupiah = split[0].substr(0, sisa),
                ribuan = split[0].substr(sisa).match(/\d{3}/gi);

            if (ribuan) {
                let separator = sisa ? '.' : '';
                rupiah += separator + ribuan.join('.');
            }

            return 'Rp ' + rupiah;
        }

        function checkPrice() {
            let jumlahUser = $("#jumlah-user").val();
            let code = $("input[name='code']").val();
            let limitUser = $("input[name='limit_user']").val();
            let member_account_code = $("input[name='member_account_code']").val();

            let id_master_paket_organization;
            let idPaket;
            if (code == "001") {
                id_master_paket_organization = $("input[name='id_master_paket_organization']").val();
                idPaket = $("input[name='id_master_paket_organization']").val();
            } else {
                id_master_paket_organization = code;
                idPaket = $("input[name='id_master_paket_organization']").val();
            }

            if (jumlahUser && jumlahUser > 0) {
                $.ajax({
                    url: "<?php echo e(url('/check-komersil')); ?>",
                    method: "POST",
                    data: {
                        code: id_master_paket_organization,
                        id_master_paket_organization: idPaket,
                        add_on_user: jumlahUser,
                        limit_user: limitUser,
                        member_account_code: member_account_code,
                        _token: "<?php echo e(csrf_token()); ?>"
                    },
                    success: function(response) {
                        console.log('====================================');
                        console.log(response);
                        console.log('====================================');
                        if (response.status == true) {
                            let formattedAmount = formatRupiah(response.data.amount);
                            $("#limit_user_new").val(response.data.total_all_user);
                            $("#harga").text(formattedAmount);
                        } else if (response.status == false) {
                            console.log(response.message);
                        }
                    },
                    error: function(error) {
                        console.log('====================================');
                        console.log('error');
                        console.log('====================================');
                        console.log(error.message);
                    }
                });
            }
        }

        $(document).ready(function() {
            $("#btn-check").click(function() {
                checkPrice();
            });

            $("#jumlah-user").on('input', function() {
                checkPrice();
            });

            $("#btn-pembayaran").click(function() {
                let harga = $("#harga").text();
                let hargaAmount = harga.replace('Rp ', '').replace(/\./g, '');
                let limit_user_new = $("input[name='limit_user_new']").val();
                let member_account_code = $("input[name='member_account_code']").val();

                $.ajax({
                    url: "<?php echo e(url('/pages/pembayaran-internal')); ?>",
                    type: "POST",
                    data: {
                        limit_user: limit_user_new,
                        amount: hargaAmount,
                        member_account_code: member_account_code,
                        _token: "<?php echo e(csrf_token()); ?>"
                    },
                    success: function(response) {
                        if (response.status == true) {
                            window.location.href = "/pages/payment/checkout";
                        } else if (response.status == false) {
                            console.log(response.message);
                        }
                    },
                    error: function(error) {
                        console.log(error);
                    }
                });
            });
        });
    </script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('pages.layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\XNS\Deployment\Dashboard-New-Ecommerce\resources\views/pages/dashboard.blade.php ENDPATH**/ ?>