<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>
<div id="wrapper">
    <div class="content">
        <div class="row">
            <br>
            <div class="col-md-12">
                <div class="panel_s">
                    <div class="panel-body panel-table-full">
                        <div class="display-block">
                            <hr>
                            <div class="col-md-6 col-xs-6 border-right">
                                <?php echo render_select('properties', $properties, ['id', 'name'], 'propertybase_properties', '', array('multiple' => true, 'data-actions-box' => true), array(), '', '', false); ?>
                            </div>
                            <div class="col-md-6 col-xs-6">
                                <?php echo render_select('status', $request_statuses, ['id', 'name'], 'propertybase_maintenance_status', '', array('multiple' => true, 'data-actions-box' => true), array(), '', '', false); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-12">
                <div class="panel_s">
                    <div class="panel-body panel-table-full">
                        <?php
                        propertybase_load_view(module_views_path(PROPERTYBASE_MODULE_NAME, '/admin/maintenance_requests/maintenance_requests_table_html.php'));
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php init_tail(); ?>
<script>
    (function ($) {
        "use strict";

        var fnServerParams = {
            "properties": '[name="properties"]',
            "status": '[name="status"]',
        };

        $(function () {
            generate_table();

            $(document).on('change', 'select[name="properties"], select[name="status"]', generate_table);
        });

        function generate_table() {
            const tableClass = $('.table-property-maintenance-requests');

            if ($.fn.DataTable.isDataTable(tableClass)) {
                tableClass.DataTable().destroy();
            }
            initDataTable(tableClass, window.location.href, [], [], fnServerParams, [0, 'desc']);
        }

    })(jQuery);
</script>
