<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class AIEO_Carts {

	
	private static $instance = null;

	
	public static function instance() {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	private function __construct() {
		$dir = AIEO_DIR . 'includes/carts/';

		require_once $dir . 'sql/carts-schema.php';
		require_once $dir . 'class-aieo-carts-store.php';
		require_once $dir . 'class-aieo-carts-capture.php';
		if ( file_exists( $dir . 'class-aieo-carts-frontend.php' ) ) {
			require_once $dir . 'class-aieo-carts-frontend.php';
		}

		
		
		add_action( 'admin_init', array( __CLASS__, 'maybe_install' ) );

		if ( class_exists( 'AIEO_Carts_Capture' ) ) {
			AIEO_Carts_Capture::instance()->register_hooks();
		}
		if ( class_exists( 'AIEO_Carts_Frontend' ) ) {
			AIEO_Carts_Frontend::instance()->register_hooks();
		}
	}

	
	public static function maybe_install() {
		if ( ! class_exists( 'AIEO_Carts_Store' ) || ! function_exists( 'aieo_carts_create_tables' ) ) {
			return;
		}
		if ( ! AIEO_Carts_Store::table_exists( AIEO_Carts_Store::carts_table() ) ) {
			aieo_carts_create_tables();
		}
	}
}
