<?php

/**
 * Sibs My Payment Information.
 *
 * The file is for displaying the Sibs My Payment Information
 * Copyright (c) SIBS
 *
 * @located at  /template/ckecmyaccountkout/
 */
if (! defined('ABSPATH')) {
    exit; // Prevent direct access
}
?>
<h2 class="header-title"><?php echo esc_attr(__('FRONTEND_MC_INFO', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></h2>

<?php if (WC()->session->__isset('sibs_myaccount_error')): ?>
	<ul class="response-box error-message">
		<li><?php echo esc_attr(WC()->session->get('sibs_myaccount_error')); ?></li>
	</ul>
<?php
    WC()->session->__unset('sibs_myaccount_error');
endif;
?>

<?php if (WC()->session->__isset('sibs_myaccount_success')): ?>
	<ul class="response-box success-message">
		<li><?php echo esc_attr(WC()->session->get('sibs_myaccount_success')); ?></li>
	</ul>
<?php
    WC()->session->__unset('sibs_myaccount_success');
endif;
?>

<?php if ($recurring): ?>
	<?php if ($is_active_cc): ?>
		<div class="group"><?php echo esc_attr(__('FRONTEND_MC_CC', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></div>
		<?php if ($registered_payments['CC']) : ?>
			<?php foreach ($registered_payments['CC'] as $payment): ?>
				<div class="group-list">
					<div class="group-img">
						<img src="<?php echo esc_attr($plugin_url); ?>assets/images/<?php echo esc_attr(strtolower($payment['brand'])); ?>.png" class="card_logo" alt="<?php echo esc_attr($payment['brand']); ?>">
					</div>
					<div class="card_info">
						<?php
                        echo esc_attr(__('FRONTEND_MC_ENDING', Sibs2\sibsConstants::SIBS_TRANSLATE)) . ' ' . esc_attr($payment['last4digits']) . '; ' .
                            esc_attr(__('FRONTEND_MC_VALIDITY', Sibs2\sibsConstants::SIBS_TRANSLATE)) . ' ' . esc_attr($payment['expiry_month']) . '/' . esc_attr(substr($payment['expiry_year'], -2))
			    ?>
					</div>
					<div class="group-button">
						<?php if ($payment['payment_default']) : ?>
							<button class="btnCustom btnDefault button-primary"><?php echo esc_attr(__('FRONTEND_MC_BT_DEFAULT', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
						<?php else : ?>
							<form action="<?php echo esc_attr($current_url); ?>page=wc-default" method="post">
								<input type="hidden" name="id" value="<?php echo esc_attr($payment['id']); ?>" />
								<input type="hidden" name="section" value="sibs_stg_ccsaved" />
								<button class="btnCustom btnDefault button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_SETDEFAULT', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
							</form>
						<?php endif; ?>
						<form action="<?php echo esc_attr($current_url); ?>page=wc-reregister" method="post">
							<input type="hidden" name="id" value="<?php echo esc_attr($payment['id']); ?>" />
							<input type="hidden" name="section" value="sibs_stg_ccsaved" />
							<button class="btnCustom button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_CHANGE', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
						</form>
						<form action="<?php echo esc_attr($current_url); ?>page=wc-deregister" method="post">
							<input type="hidden" name="id" value="<?php echo esc_attr($payment['id']); ?>" />
							<input type="hidden" name="section" value="sibs_stg_ccsaved" />
							<button class="btnCustom button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_DELETE', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
						</form>
						<div class="clear"></div>
					</div>
					<div class="clear"></div>
				</div>
			<?php endforeach; ?>
		<?php endif; ?>
		<div class="group-add">
			<form action="<?php echo esc_attr($current_url); ?>page=wc-register" method="post">
				<input type="hidden" name="section" value="sibs_stg_ccsaved" />
				<button class="btnCustom button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_ADD', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
			</form>
		</div>
		<div class="clear"></div>
	<?php endif; ?>

	<?php if ($is_active_dd) : ?>
		<div class="group"><?php echo esc_attr(__('FRONTEND_MC_DD', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></div>
		<?php if ($registered_payments['DD']) : ?>
			<?php foreach ($registered_payments['DD'] as $payment) : ?>
				<div class="group-list">
					<div class="group-img">
						<img src="<?php echo esc_attr($plugin_url); ?>assets/images/sepa.png" class="card_logo" alt="sepa">
					</div>
					<div class="card_info">
						<?php echo esc_attr(__('FRONTEND_MC_ACCOUNT', Sibs2\sibsConstants::SIBS_TRANSLATE)) . ' ' . esc_attr($payment['last4digits']); ?>
					</div>
					<div class="group-button">
						<?php if ($payment['payment_default']) : ?>
							<button class="btnCustom btnDefault button-primary"><?php echo esc_attr(__('FRONTEND_MC_BT_DEFAULT', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
						<?php else : ?>
							<form action="<?php echo esc_attr($current_url); ?>page=wc-default" method="post">
								<input type="hidden" name="id" value="<?php echo esc_attr($payment['id']); ?>" />
								<input type="hidden" name="section" value="sibs_stg_ddsaved" />
								<button class="btnCustom btnDefault button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_SETDEFAULT', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
							</form>
						<?php endif; ?>
						<form action="<?php echo esc_attr($current_url); ?>page=wc-reregister" method="post">
							<input type="hidden" name="id" value="<?php echo esc_attr($payment['id']); ?>" />
							<input type="hidden" name="section" value="sibs_stg_ddsaved" />
							<button class="btnCustom button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_CHANGE', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
						</form>
						<form action="<?php echo esc_attr($current_url); ?>page=wc-deregister" method="post">
							<input type="hidden" name="id" value="<?php echo esc_attr($payment['id']); ?>" />
							<input type="hidden" name="section" value="sibs_stg_ddsaved" />
							<button class="btnCustom button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_DELETE', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
						</form>
						<div class="clear"></div>
					</div>
					<div class="clear"></div>
				</div>
			<?php endforeach; ?>
		<?php endif; ?>
		<div class="group-add">
			<form action="<?php echo esc_attr($current_url); ?>page=wc-register" method="post">
				<input type="hidden" name="section" value="sibs_stg_ddsaved" />
				<button class="btnCustom button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_ADD', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
			</form>
		</div>
		<div class="clear"></div>
	<?php endif; ?>

	<?php if ($is_active_paypal): ?>
		<div class="group"><?php echo esc_attr(__('FRONTEND_MC_PAYPAL', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></div>
		<?php if ($registered_payments['PAYPAL']) : ?>
			<?php foreach ($registered_payments['PAYPAL'] as $payment) : ?>
				<div class="group-list">
					<div class="group-img">
						<img src="<?php echo esc_attr($plugin_url); ?>assets/images/paypal.png" class="card_logo" alt="paypal">
					</div>
					<div class="card_info">
						<?php echo esc_attr(__('FRONTEND_MC_EMAIL', Sibs2\sibsConstants::SIBS_TRANSLATE)) . ' ' . esc_attr($payment['email']); ?>
					</div>
					<div class="group-button">
						<?php if ($payment['payment_default']) : ?>
							<button class="btnCustom btnDefault button-primary"><?php echo esc_attr(__('FRONTEND_MC_BT_DEFAULT', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
						<?php else : ?>
							<form action="<?php echo esc_attr($current_url); ?>page=wc-default" method="post">
								<input type="hidden" name="id" value="<?php echo esc_attr($payment['id']); ?>" />
								<input type="hidden" name="section" value="sibs_stg_paypalsaved" />
								<button class="btnCustom btnDefault button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_SETDEFAULT', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
							</form>
						<?php endif; ?>
						<form action="<?php echo esc_attr($current_url); ?>page=wc-reregister" method="post">
							<input type="hidden" name="id" value="<?php echo esc_attr($payment['id']); ?>" />
							<input type="hidden" name="section" value="sibs_stg_paypalsaved" />
							<button class="btnCustom button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_CHANGE', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
						</form>
						<form action="<?php echo esc_attr($current_url); ?>page=wc-deregister" method="post">
							<input type="hidden" name="id" value="<?php echo esc_attr($payment['id']); ?>" />
							<input type="hidden" name="section" value="sibs_stg_paypalsaved" />
							<button class="btnCustom button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_DELETE', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
						</form>
						<div class="clear"></div>
					</div>
					<div class="clear"></div>
				</div>
			<?php endforeach; ?>
		<?php endif; ?>
		<div class="group-add">
			<form action="<?php echo esc_attr($current_url); ?>page=wc-register" method="post">
				<input type="hidden" name="section" value="sibs_stg_paypalsaved" />
				<button class="btnCustom button-primary" type="submit" value="submit"><?php echo esc_attr(__('FRONTEND_MC_BT_ADD', Sibs2\sibsConstants::SIBS_TRANSLATE)); ?></button>
			</form>
		</div>
		<div class="clear"></div>
	<?php endif; ?>
<?php endif; ?>