<table class="wp-list-table widefat fixed striped" aria-describedby="List of rules">
    <thead>
        <tr>
            <th><?php _e('ID', 'wc-koin-official'); ?></th>
            <th><?php _e('Rule Title', 'wc-koin-official'); ?></th>
            <th><?php _e('Account Number', 'wc-koin-official'); ?></th>
            <th><?php _e('Start Date', 'wc-koin-official'); ?></th>
            <th><?php _e('End Date', 'wc-koin-official'); ?></th>
            <th><?php _e('Status', 'wc-koin-official'); ?></th>
            <th><?php _e('Actions', 'wc-koin-official'); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php if (!empty($rules)) : ?>
            <?php foreach ($rules as $rule) : ?>
                <tr>
                    <td><?php echo esc_html($rule->id); ?></td>
                    <td>
                        <a href="admin.php?page=wc-koin-official-installments&action=edit_rule&rule_id=<?php echo esc_attr($rule->id); ?><?php echo isset($product_id) ? '&product_id=' . esc_attr($product_id) : ''; ?>">
                            <?php echo esc_html($rule->ruleTitle); ?>
                        </a>
                    </td>
                    <td><?php echo esc_html($rule->accountNumber); ?></td>
                    <td><?php echo esc_html($rule->startDate ? $rule->startDate->format('d/m/Y H:i:s') : ''); ?></td>
                    <td><?php echo esc_html($rule->endDate ? $rule->endDate->format('d/m/Y H:i:s') : ''); ?></td>
                    <td>
                        <?php
                        if ($rule->enableRule) {
                            $currentDate = new \DateTime();
                            $startDate = $rule->startDate;
                            $endDate = $rule->endDate;

                            if ($startDate && $currentDate < $startDate) {
                                echo esc_html(__('Scheduled', 'wc-koin-official'));
                            } elseif ($endDate && $currentDate > $endDate) {
                                echo esc_html(__('Expired', 'wc-koin-official'));
                            } else {
                                echo esc_html(__('Active', 'wc-koin-official'));
                            }
                        } else {
                            echo esc_html(__('Inactive', 'wc-koin-official'));
                        }
                        ?>
                    </td>
                    <td>
                        <a href="admin.php?page=wc-koin-official-installments&action=edit_rule&rule_id=<?php echo esc_attr($rule->id); ?><?php echo isset($product_id) ? '&product_id=' . esc_attr($product_id) : ''; ?>" class="button button-secondary">
                            <?php _e('Edit', 'wc-koin-official'); ?>
                        </a>
                        <button class="button button-danger" onclick="if(confirm('<?php echo esc_js(__('Are you sure you want to delete this rule?', 'wc-koin-official')); ?>')) { location.href='admin.php?page=wc-koin-official-installments&action=delete_rule&rule_id=<?php echo esc_attr($rule->id); ?>&koin_settings_nonce=<?php echo wp_create_nonce('save_koin_settings'); ?><?php echo isset($product_id) ? '&product_id=' . esc_attr($product_id) : ''; ?>'; }">
                            <?php _e('Delete', 'wc-koin-official'); ?>
                        </button>
                    </td>
                </tr>
            <?php endforeach; ?>
        <?php else : ?>
            <tr>
                <td colspan="7"><?php _e('No rules found.', 'wc-koin-official'); ?></td>
            </tr>
        <?php endif; ?>
    </tbody>
</table>
