<?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 _l('propertybase_your_properties'); ?>
                <span class="tw-text-sm">
        <a target="_blank" href="<?php echo site_url(PROPERTYBASE_MODULE_NAME . '/Landingpage') ?>"
           class="view-account-statement"><?php echo _l('propertybase_check_other_properties'); ?></a>
    </span>
            </h4>
        </div>
    </div>
<?php echo hooks()->do_action('propertybase_client_manage_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_property_id'); ?></th>
                    <th><?php echo _l('propertybase_property_image'); ?></th>
                    <th><?php echo _l('propertybase_property_name'); ?></th>
                    <th><?php echo _l('propertybase_property_agent'); ?></th>
                    <th><?php echo _l('propertybase_property_status'); ?></th>
                    <th><?php echo _l('propertybase_property_location_information'); ?></th>
                    <th><?php echo _l('propertybase_property_pricing_information'); ?></th>

                    <?php echo hooks()->do_action('propertybase_client_manage_properties_table_head'); ?>

                    <th><?php echo _l('options'); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($properties_list as $property) { ?>
                    <?php
                    $CI = &get_instance();
                    $CI->load->model('propertybase_model');

                    $assetMainImages = $CI->propertybase_model->get_property_main_image_attachment($property['id']);

                    $imageStyle = "max-height: 90px;max-width: 90px;";
                    $assetImage = '<img style="'.$imageStyle.'" class="mtop5 img img-responsive text-center" src="' . substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/default_image.jpg'), 0, -1) . '">';
                    if (!empty($assetMainImages)) {
                        $renderedImage = substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/property_images/main_image/' . $property['id'] . '/' . $assetMainImages[0]['file_name']), 0, -1);

                        $assetImage = '<img style="'.$imageStyle.'" class="mtop5 img img-responsive text-center" src="' . $renderedImage . '">';
                    }

                    $assetManager = '';
                    if (!empty($property['selected_agent'])) {
                        $assetManager = '<a href="#">' . staff_profile_image($property['selected_agent'], [
                                'staff-profile-image-small',
                            ]) . '</a>';
                        $assetManager .= ' ' . get_staff_full_name($property['selected_agent']);
                    }

                    $status = propertybase_get_status_data($property['property_status'])['badge'] ?? 'undefined';
                    if ($property['property_status'] == 2 && !empty($propertyAssigned)) {
                        $status .= propertybase_get_property_assigned_data($propertyAssigned);
                    }

                    $propertyPriceColor = "color: green;font-weight: bold";
                    ?>
                    <tr>
                        <td><?php echo $property['id']; ?></td>
                        <td><?php echo $assetImage; ?></td>
                        <td><?php echo $property['name']; ?></td>
                        <td><?php echo $assetManager; ?></td>
                        <td><?php echo $status; ?></td>
                        <td><?php echo propertybase_formatted_property_location($property['id']); ?></td>
                        <td><?php echo '<span style="'.$propertyPriceColor.'">' . propertybase_get_property_price($property['id'], true, true) . '</span>'; ?></td>

                        <?php echo hooks()->do_action('propertybase_client_manage_properties_table_footer', $property); ?>

                        <td>
                            <div class="tw-flex tw-items-center tw-space-x-3">
                                <a href="<?php echo site_url(PROPERTYBASE_MODULE_NAME . '/propertybase_client/manage_maintenance_requests/' . $property['id']) ?>"
                                   class="btn btn-primary new-task">
                                    <i class="fa fa-eye tw-mr-1"></i>
                                </a>
                                <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>
                        </td>
                    </tr>
                <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
<?php echo hooks()->do_action('propertybase_client_manage_properties_page_after'); ?>