<?php 

function paystack_settings_fields() {
	$live_mode = get_option('paystack_live_mode');
	label("Paystack Settings");
	input(['label' => 'Test Secret Key', 'id' => 'test_sk', 'type' => 'password', 'value' => get_option('paystack_test_sk', false)]);
	input(['label' => 'Test Public Key', 'id' => 'test_pk', 'value' => get_option('paystack_test_pk', false)]);
	input(['label' => 'Live Secret Key', 'id' => 'live_sk', 'type' => 'password', 'value' => get_option('paystack_live_sk', false)]);
	input(['label' => 'Live Public Key', 'id' => 'live_pk', 'value' => get_option('paystack_live_pk', false)]);
	if($live_mode) {
		input(['label' => 'Live Mode', 'id' => 'live_mode', 'value' => true, 'type' => 'checkbox', 'checked' => 'checked']);
	} else {
		input(['label' => 'Live Mode', 'id' => 'live_mode', 'value' => true, 'type' => 'checkbox']);
	}
}

function save_paystack_settings($args) {
	// $live_mode = ($args['live_mode'] == 1) ? 1 : 0;
	update_option('paystack_test_sk', $args['test_sk']);
	update_option('paystack_test_pk', $args['test_pk']);
	update_option('paystack_live_sk', $args['live_sk']);
	update_option('paystack_live_pk', $args['live_pk']);
	update_option('paystack_live_mode', $args['live_mode'] ?? '');
}

function paystack_payment_method($args) {
	$args['gateway_name'] = 'Debit/Credit Card';
	$args['gateway_description'] = 'Debit/Credit Card payment will be processed securely through paystack payment gateway. This gateway also enables you to pay with just your bank account number.';
	$args['gateway_icon'] = 'contents/plugins/paystack_gateway/img/card-72x72.png';
	$args['gateway_page'] = 'paystack';
	$args['gateway_id'] = 'paystack';
	payment_method_list_template($args);
}

function paystack_pm_list_payment_method($args) {
	$option = get_option("gtw_meta-paystack");
	if(!$option) return;
	?>
	<option value="<?php echo $option['gateway_id'] ?>" data-option="gtw_meta-paystack"><?php echo $option['gateway_name'] ?></option>
	<?php
}