<?php
namespace PlugozaEventTicketing;

use PlugozaEventTicketing\Admin\Admin;
use PlugozaEventTicketing\Database\Installer;
use PlugozaEventTicketing\Frontend\Shortcodes;
use PlugozaEventTicketing\Payment_Gateways;

defined( 'ABSPATH' ) || exit;

/** Plugin bootstrap. */
final class Plugin {
	private static $instance;
	public static function instance() { return self::$instance ?: self::$instance = new self(); }
	private function __construct() {}
	public function run() {
		add_filter( 'wp_page_menu_args', array( $this, 'exclude_system_pages_from_menu' ) );
		Installer::maybe_upgrade();
		new Payment_Gateways();
		new Ticket();
		new Admin();
		new Shortcodes();
	}
	/**
	 * Keep internal booking-flow pages out of WordPress's automatic page menu.
	 *
	 * @param array $args Page-menu arguments.
	 * @return array
	 */
	public function exclude_system_pages_from_menu( $args ) {
		$excluded = array_filter(
			array(
				absint( get_option( 'plugoza_ett_booking_page_id', 0 ) ),
				absint( get_page_by_path( 'booking-success' ) ? get_page_by_path( 'booking-success' )->ID : 0 ),
			)
		);

		if ( ! $excluded ) {
			return $args;
		}

		$current = empty( $args['exclude'] ) ? array() : array_map( 'absint', explode( ',', (string) $args['exclude'] ) );
		$args['exclude'] = implode( ',', array_unique( array_merge( $current, $excluded ) ) );

		return $args;
	}
	public static function deactivate() { wp_clear_scheduled_hook( 'plugoza_ett_cleanup_expired_transients' ); }
}
