<?php

use iwbvel\classes\helpers\Sanitizer;

if (!defined('ABSPATH')) exit; // Exit if accessed directly 
?>

<table id="iwbvel-items-list" class="widefat">
    <thead>
        <tr>
            <?php if (isset($show_id_column) && $show_id_column === true) : ?>
                <?php
                if ('id' == $settings['default_sort_by']) {
                    if ($settings['default_sort'] == 'ASC') {
                        $iwbvel_sortable_icon = "<i class='dashicons dashicons-arrow-up'></i>";
                    } else {
                        $iwbvel_sortable_icon = "<i class='dashicons dashicons-arrow-down'></i>";
                    }
                } else {
                    $iwbvel_sortable_icon = "<img src='" . esc_url(IWBVEL_IMAGES_URL . "sortable.png") . "' alt=''>";
                }
                ?>
                <th class="iwbvel-td70 <?php echo ($settings['sticky_first_columns'] == 'yes') ? 'iwbvel-td-sticky iwbvel-td-sticky-id' : ''; ?>">
                    <div class="iwbvel-table-item-selector-container">
                        <input type="checkbox" class="iwbvel-table-item-selector-checkbox" value="visible">
                        <div class="iwbvel-table-item-selector" title="<?php esc_attr_e('Select All', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?>">
                            <ul>
                                <li>
                                    <label>
                                        <input type="checkbox" value="all" class="iwbvel-check-item-main">
                                        <?php esc_html_e('Select All', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?>
                                    </label>
                                </li>
                                <li>
                                    <label>
                                        <input type="checkbox" value="visible" class="iwbvel-check-item-main">
                                        <span><?php esc_html_e('Select Visible', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></span>
                                    </label>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <label data-column-name="id" class="iwbvel-sortable-column"><?php esc_html_e('ID', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?><span class="iwbvel-sortable-column-icon"><?php echo wp_kses($iwbvel_sortable_icon, Sanitizer::allowed_html()); ?></span></label>
                </th>
            <?php endif; ?>
            <?php if (!empty($next_static_columns)) : ?>
                <?php foreach ($next_static_columns as $iwbvel_static_column) : ?>
                    <?php
                    if ($iwbvel_static_column['name'] == $settings['default_sort_by']) {
                        if ($settings['default_sort'] == 'ASC') {
                            $iwbvel_sortable_icon = "<i class='dashicons dashicons-arrow-up'></i>";
                        } else {
                            $iwbvel_sortable_icon = "<i class='dashicons dashicons-arrow-down'></i>";
                        }
                    } else {
                        $iwbvel_sortable_icon = "<img src='" . esc_url(IWBVEL_IMAGES_URL . "/sortable.png") . "' alt=''>";
                    }
                    ?>
                    <th data-column-name="<?php echo esc_attr($iwbvel_static_column['name']) ?>" class="iwbvel-sortable-column iwbvel-td120 <?php echo ($settings['sticky_first_columns'] == 'yes') ? 'iwbvel-td-sticky iwbvel-td-sticky-title' : ''; ?>"><?php echo esc_html($iwbvel_static_column['label']); ?><span class="iwbvel-sortable-column-icon"><?php echo wp_kses($iwbvel_sortable_icon, Sanitizer::allowed_html()); ?></span></th>
                <?php endforeach; ?>
            <?php endif; ?>
            <?php if (!empty($columns) && is_array($columns)) :
                foreach ($columns as $iwbvel_column_name => $iwbvel_column) :
                    $iwbvel_title = (!empty($columns_title) && isset($columns_title[$iwbvel_column_name])) ? $columns_title[$iwbvel_column_name] : '';
                    $iwbvel_sortable_icon = '';
                    if (isset($iwbvel_column['sortable']) && $iwbvel_column['sortable'] === true) {
                        if ($iwbvel_column_name == $settings['default_sort_by']) {
                            if ($settings['default_sort'] == 'ASC') {
                                $iwbvel_sortable_icon = "<i class='dashicons dashicons-arrow-up'></i>";
                            } else {
                                $iwbvel_sortable_icon = "<i class='dashicons dashicons-arrow-down'></i>";
                            }
                        } else {
                            $iwbvel_sortable_icon = "<img src='" . esc_url(IWBVEL_IMAGES_URL . "/sortable.png") . "' alt=''>";
                        }
                    }

                    if (isset($settings['display_full_columns_title']) && $settings['display_full_columns_title'] == 'yes') {
                        $iwbvel_column_title = $iwbvel_column['title'];
                    } else {
                        $iwbvel_column_title = (strlen($iwbvel_column['title']) > 12) ? mb_substr($iwbvel_column['title'], 0, 12) . '.' : $iwbvel_column['title'];
                    }
            ?>
                    <th data-column-name="<?php echo esc_attr($iwbvel_column_name); ?>" <?php echo (!empty($iwbvel_column['sortable'])) ? 'class="iwbvel-sortable-column"' : ''; ?>><?php echo (!empty($iwbvel_title)) ? "<span class='iwbvel-column-title dashicons dashicons-info' title='" . esc_attr($iwbvel_title) . "'></span>" : "" ?> <?php echo esc_html($iwbvel_column_title); ?> <span class="iwbvel-sortable-column-icon"><?php echo wp_kses($iwbvel_sortable_icon, Sanitizer::allowed_html()); ?></span></th>
                <?php endforeach; ?>
            <?php endif; ?>
            <?php if (!empty($after_dynamic_columns)) : ?>
                <?php foreach ($after_dynamic_columns as $iwbvel_last_column_item) : ?>
                    <th data-column-name="<?php echo esc_attr($iwbvel_last_column_item['field']) ?>" class="iwbvel-td120"><?php echo esc_attr($iwbvel_last_column_item['title']); ?></th>
                <?php endforeach; ?>
            <?php endif; ?>
        </tr>
    </thead>
    <tbody>
        <tr data-type="loading">
            <td colspan="100%" style="text-align: center;"><img style="vertical-align: middle; padding: 5px 0;" width="22" height="22" src="<?php echo esc_url(IWBVEL_IMAGES_URL . 'loading-2.gif'); ?>"></td>
        </tr>
    </tbody>
</table>