<!-- Form -->

<div class="content-animation animated">
    <div class="row clearfix fBTitrBold ">
        <!-- Advanced Form Example With Validation -->
        <div class="row clearfix">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="card">
                    <div class="header text-center">
                        <h2 class="content-title">ثبت پروفایل جدید</h2>
                    </div>
                    <div class="body">
                        <div class="row rtl" dir="rtl">
                            <div class="col-md-12">
                                <div class="col-md-3">
                                    <input required id="fName" class="effect-7 fBTitrBold" maxlength="50" type="text"
                                           placeholder="نام">
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-3">
                                    <input required id="lName" class="effect-7 fBTitrBold" maxlength="50" type="text"
                                           placeholder="نام خانوادگی">
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-3">
                                    <input required id="pNumber" class="effect-7 fBTitrBold" maxlength="11"
                                           minlength="11"
                                           type="text" placeholder="شماره مبایل">
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-3">
                                    <input required id="pNC" class="effect-7 fBTitrBold" type="text" minlength="10"
                                           maxlength="10"
                                           placeholder="کد ملی">
                                    <span class="focus-border"><i></i></span>
                                </div>
                            </div>
                            <div class="col-md-12 text-center">
                                <button class="btn btn-default btn-new-profile waves-effect">ثبت پروفایل جدید
                                </button>
                            </div>
                        </div>
                        <div class="row" dir="rtl">
                            <div class="col-md-12">
                                <table class="table-responsive table text-center table-profile
table-bordered table-striped table-hover dataTable js-exportable full_width"
                                       style="overflow-y: hidden">
                                    <thead>
                                    <tr class="text-center">
                                        <th class="text-center border-color-black">نام و نام خانوادگی</th>
                                        <th class="text-center border-color-black">شماره ملی</th>
                                        <th class="text-center border-color-black">شماره مبایل</th>
                                        <th class="text-center border-color-black">تنظیمات</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    $select = $DLA->Select("SELECT `ID`, concat(fName , ' ', lName) as `fullName` , pNC as nc , pNumber as mobile FROM app_acceptor_profile");
                                    if ($select) {
                                        foreach ($select as $row) {
                                            echo "<tr>" .
                                                "<td>" . $row['fullName'] . "</td>" .
                                                "<td>" . $row['nc'] . "</td>" .
                                                "<td>" . $row['mobile'] . "</td>" .
                                                "<td><div class='btn-group-vertical'> " .
                                                "<button disabled class='disabled btn-danger btn-group btn waves-effect btn-delete-profile' data-id='" . $row['ID'] . "'>حذف</button>" .
                                                "</td>" .
                                                "</tr>";
                                        }
                                    } else {
                                        echo "<tr><td colspan=4'>موردی یافت نشد</td></tr>";
                                    }

                                    ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    (function ($) {

        /*Profile Section*/
        $(document).ready(function (e) {
            let table = $('table.table-profile'), eventListener = function () {
                table.find('button.btn-delete-profile').unbind().bind('click, tap', function (e) {
                    if (confirm("ایا این پروفایل حذف شود؟")) {
                        let object = {
                            id: $(this).attr('data-id')
                        };
                        LoadData({
                            request: 'proxy',
                            object: object,
                            action: 'acceptorController',
                            "header-type": 'remove-profile'
                        }, null, false, function (data) {
                            if (data === '1') {
                                let tr = table.find("button[data-id='" + object.id + "']").parents('tr');
                                tr.fadeOut(function (e) {
                                    tr.remove();
                                });
                                swal("انجام شد", "", "success");
                            } else {
                                swal("انجام نشد", "", "error");
                            }
                        });
                    } else {
                        swal("انجام نشد", "", "error");
                    }
                });
            }, addRow = function (ID, fullName, mobile, nc) {
                table.find("tbody").append(
                    "<tr>" +
                    "<td>" + fullName + "</td>" +
                    "<td>" + nc + "</td>" +
                    "<td>" + mobile + "</td>" +
                    "<td>" + "<button class='btn-danger btn waves-effect btn-delete-profile' data-id='" + ID + "'>حذف</button>" + " </td>" +
                    "</tr>"
                );
                eventListener();
            };
            $('.btn-new-profile').unbind().bind('click, tap', function (e) {
                object = {
                    fName: $('#fName').val(),
                    lName: $('#lName').val(),
                    pNumber: $('#pNumber').val(),
                    pNC: $('#pNC').val(),
                };
                LoadData({
                    request: 'proxy',
                    object: object,
                    action: 'acceptorController',
                    "header-type": 'add-profile'
                }, null, false, function (data) {
                    if (data > 0) {
                        addRow(data, object.fName + " " + object.lName, object.pNumber, object.pNC);
                        swal("انجام شد", "", "success");
                    } else {
                        swal("انجام نشد", "", "error");
                    }
                });
            });

            $('.table-profile').DataTable({
                "fnInfoCallback": function (oSettings, iStart, iEnd, iMax, iTotal, sPre) {
                    eventListener();
                },
                responsive: false,
                "language": {
                    "lengthMenu": "Display _MENU_ records per page",
                    "zeroRecords": " چیزی یافت نشد",
                    "info": "نمایش از _START_ تا _END_ در _TOTAL_ رکورد",
                    "infoEmpty": "<center>رکوردی پیدا نشد</center>",
                    "infoFiltered": "(filtered from _MAX_ total records)",
                    "paginate": {
                        "next": "بعدی",
                        "previous": "قبلی"
                    }
                }
            });


        });
    }(jQuery));


</script>