<?php
include_once "../global.php";

$pageTitle = "WhatsApp Automation - ";
include_once '../header.php';
?>
<!--breadcrumb-->
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
    <div class="breadcrumb-title pe-3">WhatsApp Management</div>
    <div class="ps-3">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb mb-0 p-0">
                <li class="breadcrumb-item"><a href="javascript:;"></a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">WhatsApp Automation</li>
            </ol>
        </nav>
    </div>
    <div class="ms-auto">
        <a href="<?php echo WEB_URL; ?>/whatsapp/addnewrule">New Rule</a>
    </div>
</div>
<!--end breadcrumb-->
<h6 class="mb-0 text-uppercase">WhatsApp Automation</h6>
<hr>
<div class="card">
    <div class="card-body p-4">
        <div class="table-responsive">
            <?php $crm->waRuleList(); ?>
        </div>
    </div>
</div>

<script>
    function deleteRule(ths) {
        var deleteRuleId = $(ths).attr('data-id');
        $.ajax({
            url: '<?php echo WEB_URL; ?>/ajax_call?page=deleteWaRule',
            type: 'POST',
            data: {
                deleteRuleId: deleteRuleId
            },
            beforeSend: function() {
                $("#spinner-overlay").fadeIn('slow');
            },
            success: function(response) {
                if (response == '1') {
                    $(ths).closest('tr').hide(1000, function() {
                        $(this).remove();
                    });
                } else if (response == '0') {
                    showAlert("Delete fail please try again.");
                } else {
                    window.location.reload();
                }
            },
            error: function(xhr, status, errorThrown) {
                console.log(xhr.responseJSON);
            },
            complete: function() {
                $("#spinner-overlay").fadeOut('slow');
            }
        });
    }
</script>

<?php
include_once '../footer.php';
?>