<?php
namespace ShopyPress\Views\Admin\Settings;
if ( ! defined( 'ABSPATH' ) ) exit;

use ShopyPress\Views\Admin\Settings\BaseView;
use ShopyPress\Views\Admin\Settings\IView;
use ShopyPress\Utils\OptionUtils;

class Collections extends BaseView implements IView {

    public function render(): void {
        $shop_domain = OptionUtils::getInstance()->getOption('shop_domain', '');
        ?>
        <div class="row">
            <div class="col-md-12">
                <h5 class="mb-3"><?php esc_html_e('Shopify Collections', 'synckube-products-sync-for-shopify'); ?></h5>

                <?php if (empty($shop_domain)): ?>
                    <div class="alert alert-warning" role="alert">
                        <strong><?php esc_html_e('Warning:', 'synckube-products-sync-for-shopify'); ?></strong>
                        <?php esc_html_e('Please configure your Shop Domain in the Settings tab first.', 'synckube-products-sync-for-shopify'); ?>
                    </div>
                <?php else: ?>
                    <div class="mb-3">
                        <button type="button" id="btn-fetch-collections" class="btn btn-primary">
                            <?php esc_html_e('Fetch Collections', 'synckube-products-sync-for-shopify'); ?>
                        </button>
                    </div>

                    <div id="collections-status-container"></div>

                    <div id="collections-list-container" class="mt-4" style="display: none;">
                        <h6><?php esc_html_e('Collections:', 'synckube-products-sync-for-shopify'); ?></h6>
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th width="50"><?php esc_html_e('Order', 'synckube-products-sync-for-shopify'); ?></th>
                                        <th width="100"><?php esc_html_e('Import', 'synckube-products-sync-for-shopify'); ?></th>
                                        <th><?php esc_html_e('Image', 'synckube-products-sync-for-shopify'); ?></th>
                                        <th><?php esc_html_e('Title', 'synckube-products-sync-for-shopify'); ?></th>
                                        <th><?php esc_html_e('Handle', 'synckube-products-sync-for-shopify'); ?></th>
                                        <th><?php esc_html_e('Products', 'synckube-products-sync-for-shopify'); ?></th>
                                        <th><?php esc_html_e('Description', 'synckube-products-sync-for-shopify'); ?></th>
                                    </tr>
                                </thead>
                                <tbody id="collections-table-body" class="collections-sortable">
                                </tbody>
                            </table>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
        </div>
        <?php
    }
}
