<?php

// Exit if accessed directly
if( !defined('ABSPATH') ) exit;

class ESLP_Easy_Social_Login_Extra {
		
	/**
	 * Constructor method.
	 *
	 * Initializes the class by registering rewrite rules and query variables
	 * for the 2FA functionality.
	 */
	public function __construct() {	}

	/**
	 * Check WooCommerce Status.
	 *
	 * Determines the activation and configuration status of WooCommerce.
	 *
	 * @return array Returns an array with the status and a corresponding message.
	 *               - 'active': WooCommerce is activated and configured correctly.
	 *               - 'partially': WooCommerce is activated but the store page is not configured.
	 *               - 'disable': WooCommerce is not activated.
	 */
	public function eslp_check_woocommerce_status() {
		if ( class_exists( 'WooCommerce' ) ) {
			$shop_page_id = wc_get_page_id( 'shop' );
			if ( $shop_page_id && get_post_status( $shop_page_id ) === 'publish' ) {
				return array( 'active', 'WooCommerce is activated and configured correctly.' );
			} else {
				return array( 'partially', 'WooCommerce is activated but the store page is not configured.' );
			}
		} else {
			return array( 'disable', 'WooCommerce is not activated.' );
		}
	}

	/**
	 * Display Warning Message.
	 *
	 * Outputs a sanitized warning message and optionally terminates execution.
	 *
	 * @param string $message   The warning message to display.
	 * @param string $echo  Optional. If set to 'die', the script execution will stop after displaying the message.
	 */
	public function eslp_esc_message( $message, $echo = null ) {
		if ( isset( $message ) ) {
			$output = sanitize_text_field( wp_unslash( $message ) );
			if ( isset( $echo ) && $echo === 'die' ) {
				switch ( $echo ){
					case 'die': 
						if ( WP_DEBUG === true && WP_DEBUG_LOG === true ) {
							error_log( esc_html( $output ) );
						}
						break;
					default:
						return $output;
				}
			}
		}
	}
}