<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
    <div class="tw-flex tw-items-center tw-justify-between tw-mb-3">
        <div class="tw-flex tw-items-center">
            <h4 class="tw-mt-0 tw-font-semibold tw-text-lg tw-text-neutral-700 section-heading section-heading-invoices">
                <?php echo $title; ?>
                <span class="tw-text-sm">
        <a href="<?php echo site_url(PROPERTYBASE_MODULE_NAME . '/propertybase_client/properties') ?>"
           class="view-account-statement"><?php echo _l('propertybase_go_back_to_properties'); ?></a>
    </span>
            </h4>
        </div>
        <a href="<?php echo site_url(PROPERTYBASE_MODULE_NAME . '/propertybase_client/request_maintenance/' . $property_id) ?>"
           class="btn btn-secondary">
            <i class="fa-regular fa-plus tw-mr-1"></i>
            <?php echo _l('propertybase_request_maintenance'); ?>
        </a>
    </div>
<?php echo hooks()->do_action('propertybase_client_manage_maintenance_requests_properties_page_before'); ?>
    <div class="panel_s">
        <div class="panel-body">
            <table class="table dt-table table-properties" data-order-col="2" data-order-type="desc">
                <thead>
                <tr>
                    <th><?php echo _l('propertybase_maintenance_id'); ?></th>
                    <th><?php echo _l('propertybase_request_images'); ?></th>
                    <th><?php echo _l('propertybase_maintenance_title'); ?></th>
                    <th><?php echo _l('propertybase_maintenance_description'); ?></th>
                    <th><?php echo _l('propertybase_maintenance_status'); ?></th>
                    <th><?php echo _l('propertybase_requested_by'); ?></th>
                    <th><?php echo _l('propertybase_created_at'); ?></th>

                    <?php echo hooks()->do_action('propertybase_client_manage_maintenance_requests_properties_table_head'); ?>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($maintenance_requests as $request) { ?>
                    <?php
                    $CI = &get_instance();

                    $renderImages = '';

                    if (isset($request['attachments']) && count($request['attachments']) > 0) {

                        foreach ($request['attachments'] as $attachment) {
                            $renderedImage = substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/property_images/maintenance_requests/' . $request['id'] . '/' . $attachment['filename']), 0, -1);
                            $style = "max-height: 90px;max-width: 90px;";
                            $renderImages .= '<a target="_blank" href="' . $renderedImage . '"><img style="'.$style.'" class="mtop5 img img-responsive text-center" src="' . $renderedImage . '"></a>';
                        }
                    }

                    $requestedBy = '';
                    if (!empty($request['requested_by'])) {
                        $requestedBy = '<a href="#"><img class="client-profile-image-small mright5" src="' . contact_profile_image_url($request['requested_by']) . '"></a>';
                        $requestedBy .= ' ' . get_contact_full_name($request['requested_by']);
                    }

                    $status = propertybase_get_request_status_data($request['status'])['badge'] ?? 'undefined';
                    ?>
                    <tr>
                        <td><?php echo $request['id']; ?></td>
                        <td><?php echo $renderImages; ?></td>
                        <td><?php echo $request['maintenance_title']; ?></td>
                        <td><?php echo $request['maintenance_description']; ?></td>
                        <td><?php echo $status; ?></td>
                        <td><?php echo $requestedBy; ?></td>
                        <td><?php echo $request['created_at']; ?></td>

                        <?php echo hooks()->do_action('propertybase_client_manage_maintenance_requests_properties_table_footer', $request); ?>
                    </tr>
                <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
<?php echo hooks()->do_action('propertybase_client_manage_maintenance_requests_properties_page_after'); ?>