<?php

namespace TableBuilderPro\Routes;

defined('ABSPATH') || exit;
class Init
{
	use \TableBuilderPro\Traits\Singleton;

	public function __construct()
	{
		new SettingsList();
		new DataTableRoute();
		new PostDataRoute();
		
		// Initialize WooCommerce cart handler after WordPress init
		add_action('init', [$this, 'init_woocommerce_cart_handler'], 20);
	}
	
	/**
	 * Initialize WooCommerce cart handler
	 */
	public function init_woocommerce_cart_handler(): void
	{
		if (class_exists('WooCommerce')) {
			// Ensure CartHandler file is loaded
			$cart_handler_file = TABLE_BUILDER_BLOCK_PRO_INC_DIR . 'WooCommerce/CartHandler.php';
			if (file_exists($cart_handler_file)) {
				require_once $cart_handler_file;
				
				if (class_exists('\TableBuilderPro\WooCommerce\CartHandler')) {
					\TableBuilderPro\WooCommerce\CartHandler::instance();
				}
			}
		}
	}
}
