<?php

if ( !defined( 'ABSPATH' ) ) {
    exit;
}
/**
 *
 * @link       https://wpgeenie.org
 * @since      1.0.0
 *
 * @package    Spending_Limits_For_Woocommerce
 * @subpackage Spending_Limits_For_Woocommerce/admin/partials
 */
$lock_until = get_user_meta( $user->ID, 'spending_limit_lock_until', true );
$spend_limit_amount = get_user_meta( $user->ID, 'spend_limit_amount', true ) ?? 0;
$spend_limit_period = get_user_meta( $user->ID, 'spend_limit_period', true ) ?? false;
$spend_limit_period_custom = get_user_meta( $user->ID, 'spend_limit_period_custom', true ) ?? false;
$spend_limit_period_custom_time = get_user_meta( $user->ID, 'spend_limit_period_custom_time', true ) ?? false;
$dateformat = get_option( 'date_format' );
$timeformat = get_option( 'time_format' );
?>


<h3><?php 
esc_html_e( 'User Spending Limit and Lock Settings', 'spending-limits-for-woocommerce' );
?></h3>

<table class="form-table spending-limit-for-woocommerce">
	<?php 
if ( $lock_until ) {
    ?>
	<tr><h4 class='spending-limit-for-woocommerce-lock'>
		<?php 
    if ( 'permanent' === $lock_until ) {
        esc_html_e( 'Account is locked permanently.', 'spending-limits-for-woocommerce' );
    } else {
        printf( 
            // translators: date.
            esc_html__( 'Account is locked until %s.', 'spending-limits-for-woocommerce' ),
            esc_html( date_i18n( $dateformat, strtotime( $lock_until ) ) . ' ' . date_i18n( $timeformat, strtotime( $lock_until ) ) )
         );
    }
    ?>
		</h4></tr>
	<?php 
}
?>
	<tr>
		<th><label for="locklength"><?php 
esc_html_e( 'Lock Length', 'spending-limits-for-woocommerce' );
?></label></th>
		<td>
			<input type="radio" id="locklength1" name="locklength" value="1w" >
			<label for="locklength1"><?php 
esc_html_e( '1 Week', 'spending-limits-for-woocommerce' );
?></label><br>
			<input type="radio" id="locklength2" name="locklength" value="4w" >
			<label for="locklength2"><?php 
esc_html_e( '4 Weeks', 'spending-limits-for-woocommerce' );
?></label><br>
			<input type="radio" id="locklength3" name="locklength" value="12w" >
			<label for="locklength3"><?php 
esc_html_e( '12 weeks', 'spending-limits-for-woocommerce' );
?></label><br>
			<input type="radio" id="locklength4" name="locklength" value="1y">
			<label for="locklength4"><?php 
esc_html_e( '1 year', 'spending-limits-for-woocommerce' );
?></label><br>
			<input type="radio" id="locklength4" name="locklength" value="permanent" <?php 
checked( 'permanent' === $lock_until );
?> >
			<label for="locklength4"><?php 
esc_html_e( 'Exclude permanently', 'spending-limits-for-woocommerce' );
?></label><br>
			<input type="radio" id="locklength4" name="locklength" value="clear" >
			<label for="locklength4"><?php 
esc_html_e( 'Clear lock', 'spending-limits-for-woocommerce' );
?></label>
		</td>
	</tr>


<tr>

<th><label for="spend_limit_amount"><?php 
esc_html_e( 'Spending Limit', 'spending-limits-for-woocommerce' );
?></label></th>

<td>
	<label for="spend_limit_amount"><?php 
esc_html_e( 'Spending Limit Amount', 'spending-limits-for-woocommerce' );
?></label><br><br>

	<?php 
echo get_woocommerce_currency_symbol();
// phpcs:ignore
?>
	<input type="number" name="spend_limit_amount" id="spend_limit_amount" value="<?php 
echo intval( $spend_limit_amount ) ?? '';
?>" >
	<label for="spend_limit_length"><?php 
esc_html_e( 'Limit Length', 'spending-limits-for-woocommerce' );
?></label><br><br>

	<input type="radio" id="spend_limit_period1" name="spend_limit_period" value="day" <?php 
checked( 'day' === $spend_limit_period );
?>>
	<label for="spend_limit_period1"><?php 
esc_html_e( 'Per Day', 'spending-limits-for-woocommerce' );
?></label><br>
	<input type="radio" id="spend_limit_period2" name="spend_limit_period" value="week" <?php 
checked( 'week' === $spend_limit_period );
?>>
	<label for="spend_limit_period2"><?php 
esc_html_e( 'Per Week', 'spending-limits-for-woocommerce' );
?></label><br>
	<input type="radio" id="spend_limit_period3" name="spend_limit_period" value="month" <?php 
checked( 'month' === $spend_limit_period );
?>>
	<label for="spend_limit_period3"><?php 
esc_html_e( 'Per Month', 'spending-limits-for-woocommerce' );
?></label><br>
	<input type="radio" id="spend_limit_period4" name="spend_limit_period" value="year" <?php 
checked( 'year' === $spend_limit_period );
?>>
	<label for="spend_limit_period4"><?php 
esc_html_e( 'Per Year', 'spending-limits-for-woocommerce' );
?></label><br>
	<?php 
?>
	<input type="radio" id="spend_limit_period5" name="spend_limit_period" value="clear" >

	<label for="spend_limit_period5"><?php 
esc_html_e( 'Clear limit', 'spending-limits-for-woocommerce' );
?></label><br>
	<br /><span class="description"><?php 
esc_html_e( 'Set the spending limit for the user.', 'spending-limits-for-woocommerce' );
?></span>
</td>
</tr>

</table>
