<?php

/**
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;
global $post;
global $current_user;

// Check user is loggedin or not, if not redirect to login page
conikal_redirect_login();

// get option payout financial
$withdrawal_paypal 		= isset($campoal_options['conikal_withdrawal_paypal_field']) && $campoal_options['conikal_withdrawal_paypal_field'] != '' ? $campoal_options['conikal_withdrawal_paypal_field'] : 1;
$withdrawal_payoneer 	= isset($campoal_options['conikal_withdrawal_payoneer_field']) && $campoal_options['conikal_withdrawal_payoneer_field'] != '' ? $campoal_options['conikal_withdrawal_payoneer_field'] : 1;
$withdrawal_bank 		= isset($campoal_options['conikal_withdrawal_bank_field']) && $campoal_options['conikal_withdrawal_bank_field'] != '' ? $campoal_options['conikal_withdrawal_bank_field'] : 1;
$withdraw_bitcoin 		= isset($campoal_options['conikal_withdrawal_bitcoin_field']) && $campoal_options['conikal_withdrawal_bitcoin_field'] != '' ? $campoal_options['conikal_withdrawal_bitcoin_field'] : 1;
$bitcoin_networks 		= isset($campoal_options['conikal_bitcoin_networks_field']) && $campoal_options['conikal_bitcoin_networks_field'] != '' ? $campoal_options['conikal_bitcoin_networks_field'] : 0;

// get financial infomation
$paypal 		= get_user_meta($current_user->ID, 'financial_paypal', true);
$payoneer 		= get_user_meta($current_user->ID, 'financial_payoneer', true);
$bank 			= get_user_meta($current_user->ID, 'financial_bank', true);
$bitcoin 		= get_user_meta($current_user->ID, 'financial_bitcoin', true);

// convert financial infomation to object
$paypal_details 	= $paypal ? (object) $paypal : '';
$payoneer_details 	= $payoneer ? (object) $payoneer : '';
$bank_details 		= $bank ? (object) $bank : '';
$bitcion_details 	= $bitcoin ? (object) $bitcoin : '';
?>

<div class="ui hidden divider"></div>
<div class="ui middle aligned grid">
	<div class="ten wide column"></div>
	<div class="six wide right aligned column">
		<button class="ui icon basic button" id="dashboard-sidebar-btn"><i class="sidebar icon"></i></button>
	</div>
</div>
<div class="ui hidden divider"></div>

<?php if ($withdrawal_paypal || $withdrawal_payoneer || $withdrawal_bank || $withdraw_bitcoin) : ?>
<div class="ui centered grid">
	<div class="sixteen wide mobile twelve wide computer left aligned column">
		<?php if ($withdrawal_paypal == 1) : ?>
		<div class="ui relaxed grid secondary">
			<div class="sixteen wide mobile six wide computer center aligned middle aligned column">
				<h3 class="ui dividing icon header"><i class="paypal icon"></i><?php esc_html_e('PayPal', 'campoal') ?></h3>
				<p class="font tiny text grey">
					<?php esc_html_e('You will pay the fee yourself when receiving money via PayPal, which is deducted directly from the money you receive.', 'campoal') ?>
				</p>
			</div>
			<div class="sixteen wide mobile ten wide computer column">
				<div id="financial-response" class="respon-message"></div>
				<div class="ui form">
					<h4 class="ui dividing header"><?php esc_html_e('PayPal infomation', 'campoal') ?></h4>
					<div class="field required">
						<label><?php esc_html_e('Paypal Email', 'campoal'); ?></label>
						<input type="email" name="fn_paypal_email" id="fn_paypal_email" value="<?php echo esc_attr($paypal ? $paypal_details->email : '') ?>" placeholder="<?php esc_attr_e('eg. payment@mail.com', 'campoal') ?>">
					</div>
				</div>
			</div>
		</div>
		<?php endif; ?>
		<?php if ($withdrawal_payoneer == 1) : ?>
		<div class="ui section divider"></div>
		<div class="ui relaxed grid secondary">
			<div class="sixteen wide mobile six wide computer center aligned middle aligned column">
				<h3 class="ui dividing icon header"><i class="credit card alternative icon"></i><?php esc_html_e('Payoneer', 'campoal') ?></h3>
				<p class="font tiny text grey">
					<?php esc_html_e('Your funds will be sent directly from our Payoneer account to your Payoneer account or credit card issued by Payoneer.', 'campoal') ?>
				</p>
			</div>
			<div class="sixteen wide mobile ten wide computer column">
				<div class="ui form">
					<h4 class="ui dividing header"><?php esc_html_e('Payoneer infomation', 'campoal') ?></h4>
					<div class="field required">
						<label><?php esc_html_e('Payoneer Email', 'campoal'); ?></label>
						<input type="email" name="fn_payoneer_email" id="fn_payoneer_email" value="<?php echo esc_attr($payoneer ? $payoneer_details->email : '') ?>" placeholder="<?php esc_attr_e('eg. payment@mail.com', 'campoal') ?>">
					</div>
					<div class="field">
						<label><?php esc_html_e("Payoneer Card Number", 'campoal'); ?></label>
						<input type="number" name="fn_payoneer_card" id="fn_payoneer_card" value="<?php echo esc_attr($payoneer ? $payoneer_details->card : '') ?>" placeholder="<?php esc_attr_e('eg. 1234 3212 1351 1321', 'campoal') ?>">
					</div>
				</div>
			</div>
		</div>
		<?php endif; ?>
		<?php if ($withdraw_bitcoin == 1) : ?>
		<div class="ui section divider"></div>
		<div class="ui relaxed grid secondary">
			<div class="sixteen wide mobile six wide computer center aligned middle aligned column">
				<h3 class="ui dividing icon header"><i class="bitcoin icon"></i><?php esc_html_e('Bitcoin', 'campoal') ?></h3>
				<p class="font tiny text grey">
					<?php esc_html_e('Please enter the correct Bitcoin wallet address and choose the correct network, mistake will cause your money to be lost.', 'campoal') ?>
				</p>
			</div>
			<div class="sixteen wide mobile ten wide computer column">
				<div class="ui form">
					<h4 class="ui dividing header"><?php esc_html_e('Bitcoin infomation', 'campoal') ?></h4>
					<?php if ($bitcoin_networks) { ?>
					<div class="field required">
						<label><?php esc_html_e('Bitcoin Network', 'campoal'); ?></label>
						<select class="ui dropdown large fluid input" name="fn_bitcoin_network" id="fn_bitcoin_network">
							<?php foreach ($bitcoin_networks as $label) { ?>
								<option value="<?php echo esc_attr($label) ?>"<?php echo esc_attr($label == $bitcion_details->network ? ' selected' : '') ?>><?php echo esc_html($label) ?></option>
							<?php } ?>
						</select>
					</div>
					<?php } ?>
					<div class="field required">
						<label><?php esc_html_e("Bitcoin Address", 'campoal'); ?></label>
						<input type="text" name="fn_bitcoin_address" id="fn_bitcoin_address" value="<?php echo esc_attr($bitcoin ? $bitcion_details->address : '') ?>" placeholder="<?php esc_attr_e('eg. 3FZbgi29cpjq2GjdwV8eyHuJJnkLtktZc5', 'campoal') ?>">
					</div>
				</div>
			</div>
		</div>
		<?php endif; ?>
		<?php if ($withdrawal_bank == 1) : ?>
		<div class="ui section divider"></div>
		<div class="ui relaxed grid secondary">
			<div class="sixteen wide mobile six wide computer center aligned middle aligned column">
				<h3 class="ui dividing icon header"><i class="university icon"></i><?php esc_html_e('Bank Transfer', 'campoal') ?></h3>
				<p class="font tiny text grey"><?php esc_html_e('We cannot be held responsible for delays, extra costs or financial loss that arises from being provided incorrect account information, so please ensure that you double check the details with your financial institution prior to submitting a request for a Bank Wire Transfer.', 'campoal') ?></p>
			</div>
			<div class="sixteen wide mobile ten wide computer column">
				<div class="ui form">
					<h4 class="ui dividing header"><?php esc_html_e('Account holder', 'campoal') ?></h4>
					<div class="field required">
						<label><?php esc_html_e('Name of the account holder', 'campoal') ?></label>
						<input type="text" name="fn_bank_fullname" id="fn_bank_fullname" value="<?php echo esc_attr($bank ? $bank_details->fullname : '') ?>" placeholder="<?php esc_attr_e('eg. Michael Joseph Jackson', 'campoal') ?>">
					</div>
					<div class="field required">
						<label><?php esc_html_e('Your Address', 'campoal') ?></label>
						<input type="text" name="fn_bank_user_address" id="fn_bank_user_address" value="<?php echo esc_attr($bank ? $bank_details->user_address : '') ?>" placeholder="<?php esc_attr_e('eg. 5225 Figueroa Mountain Road, Los Olivos, California 93441', 'campoal') ?>">
					</div>
					<h4 class="ui dividing header"><?php esc_html_e('Bank infomation', 'campoal') ?></h4>
					<div class="field required">
						<label><?php esc_html_e("Bank Name", 'campoal') ?></label>
						<input type="text" name="fn_bank_name" id="fn_bank_name" value="<?php echo esc_attr($bank ? $bank_details->name : '') ?>" placeholder="<?php esc_attr_e('eg. Bank of America', 'campoal') ?>">
					</div>
					<div class="field required">
						<label><?php esc_html_e("Bank's Address", 'campoal') ?></label>
						<input type="text" name="fn_bank_address" id="fn_bank_address" value="<?php echo esc_attr($bank ? $bank_details->address : '') ?>" placeholder="<?php esc_attr_e('eg. Center 100 North Tryon Street Charlotte, North Carolina, U.S', 'campoal') ?>">
					</div>
					<div class="field required">
						<label><?php esc_html_e('SWIFT code', 'campoal') ?></label>
						<input type="text" name="fn_bank_swift_code" id="fn_bank_swift_code" value="<?php echo esc_attr($bank ? $bank_details->swift_code : '') ?>" placeholder="<?php esc_attr_e('eg. BOFAUS3N', 'campoal') ?>">
					</div>
					<div class="field required">
						<label><?php esc_html_e('Account number', 'campoal') ?></label>
						<input type="text" name="fn_bank_account_number" id="fn_bank_account_number" value="<?php echo esc_attr($bank ? $bank_details->account_number : '') ?>" placeholder="<?php esc_attr_e('eg. 123456789', 'campoal') ?>">
					</div>
				</div>
			</div>
		</div>
		<?php endif; ?>
		<div class="ui section divider"></div>
		<div class="ui relaxed grid secondary">
			<div class="sixteen wide mobile six wide computer center aligned middle aligned column">
				</div>
			<div class="sixteen wide mobile ten wide computer column">
				<div class="ui form">
					<div class="ui message">
						<div class="field required">
		                    <label><?php esc_html_e('Confirm Password', 'campoal') ?></label>
		                    <input type="password" name="fn_confirm_password" id="fn_confirm_password" placeholder="<?php esc_attr_e('Enter your password', 'campoal') ?>">
		                </div>
		                <p>
			            <?php esc_html_e('* To protect your financial information when the change is not from you. We require a confirmation with your password. Please enter your password in the field above.', 'campoal') ?>
			            </p>
		            </div>
					<div class="ui right floated header field">
						<button class="ui primary button" id="saveFinancialBtn"><?php esc_html_e('Save', 'campoal') ?></button>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<?php else :
    // display not found post notice
    conikal_not_found_post(__('No payout methods.', 'campoal'), __("We're sorry, but no payout methods available.", 'campoal'));
endif; ?>
<?php wp_nonce_field('financial_ajax_nonce', 'securityFinancial', true); ?>