<?php
/**
 * Loads view for accounts tab.
 *
 * @package miniorange-sms-order-notification-otp-verification/controllers/
 */

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

if ( ! current_user_can( 'manage_options' ) ) {
	wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'miniorange-sms-order-notification-otp-verification' ) );
}

use WCSMSOTP\Handler\MoRegistrationHandler;
use WCSMSOTP\Helper\MoConstants;
use WCSMSOTP\Helper\MoUtility;

$mowc_url = MoConstants::HOSTNAME . '/moas/login?redirectUrl=' . MoConstants::HOSTNAME . '/moas/viewlicensekeys';

$mowc_handler = MoRegistrationHandler::instance();


if ( get_mo_wc_option( 'verify_customer' ) ) {
	$mowc_admin_email = get_mo_wc_option( 'admin_email' ) ? get_mo_wc_option( 'admin_email' ) : '';
	$mowc_nonce       = $mowc_handler->get_nonce_value();
	$mowc_login_file  = MOV_WC_DIR . 'views/account/login.php';
	if ( ! MoUtility::mo_require_file( $mowc_login_file, MOV_WC_DIR ) ) {
		return;
	}
	require_once $mowc_login_file;
} elseif ( ! MoUtility::micr() ) {
	$mowc_mo_current_user = wp_get_current_user();
	$mowc_admin_phone     = get_mo_wc_option( 'admin_phone' ) ? get_mo_wc_option( 'admin_phone' ) : '';
	$mowc_nonce           = $mowc_handler->get_nonce_value();
	delete_site_option( 'password_mismatch' );
	update_mo_wc_option( 'new_registration', 'true' );
	$mowc_register_file = MOV_WC_DIR . 'views/account/register.php';
	if ( ! MoUtility::mo_require_file( $mowc_register_file, MOV_WC_DIR ) ) {
		return;
	}
	require_once $mowc_register_file;
} else {
	$mowc_customer_id  = get_mo_wc_option( 'admin_customer_key' );
	$mowc_api_key      = get_mo_wc_option( 'admin_api_key' );
	$mowc_token        = get_mo_wc_option( 'customer_token' );
	$mowc_vl           = MoUtility::mclv() && ! MoUtility::is_mg();
	$mowc_nonce        = $mowc_admin_handler->get_nonce_value();
	$mowc_regnonce     = $mowc_handler->get_nonce_value();
	$mowc_profile_file = MOV_WC_DIR . 'views/account/profile.php';
	if ( ! MoUtility::mo_require_file( $mowc_profile_file, MOV_WC_DIR ) ) {
		return;
	}
	require_once $mowc_profile_file;
}
