<?php
/**
 * Subscription create/edit form.
 *
 * @package Lucrativeit_Subscription_Recurring_Billing
 *
 * @var LUCRSURE_Settings $settings Settings.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Included template; variables are local to the including scope.

if ( ! current_user_can( lucrsure_admin_capability() ) ) {
	wp_die( esc_html__( 'You are not allowed to access this page.', 'lucrativeit-subscription-recurring-billing' ) );
}

$repo          = new LUCRSURE_Subscription_Repository();
$customer_repo = new LUCRSURE_Customer_Repository();
$plan_repo     = new LUCRSURE_Plan_Repository();
$branch_repo   = new LUCRSURE_Branch_Repository();

$id       = 0;
$pre_plan = 0;

if ( isset( $_GET['_wpnonce'] )
	&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'lucrsure_admin_form' )
) {
	$id       = isset( $_GET['id'] ) ? absint( wp_unslash( $_GET['id'] ) ) : 0;
	$pre_plan = isset( $_GET['plan'] ) ? absint( wp_unslash( $_GET['plan'] ) ) : 0;
}

$sub = $id ? $repo->find( $id ) : array();
if ( $id && empty( $sub ) ) {
	$id  = 0;
	$sub = array();
}

$customers = $customer_repo->query( array( 'limit' => 500 ) );
$plans     = $plan_repo->active();
$branches  = $branch_repo->active();
$gateways  = LUCRSURE_Gateway_Manager::instance()->all();
$intervals = lucrsure_billing_intervals();

$customer_id = isset( $sub['customer_id'] ) ? (int) $sub['customer_id'] : 0;
$plan_id     = isset( $sub['plan_id'] ) ? (int) $sub['plan_id'] : $pre_plan;
$status      = isset( $sub['status'] ) ? $sub['status'] : 'active';
$quantity    = isset( $sub['quantity'] ) ? (int) $sub['quantity'] : 1;
$start_date  = isset( $sub['start_date'] ) && $sub['start_date'] ? gmdate( 'Y-m-d', strtotime( $sub['start_date'] ) ) : gmdate( 'Y-m-d' );
$trial_ends  = isset( $sub['trial_ends'] ) && $sub['trial_ends'] ? gmdate( 'Y-m-d', strtotime( $sub['trial_ends'] ) ) : '';
$gateway     = isset( $sub['gateway'] ) ? $sub['gateway'] : $settings->get( 'default_gateway', 'manual' );
$auto_renew  = $id ? ! empty( $sub['auto_renew'] ) : true;
?>

<div class="lucrsure-page-head">
	<div>
		<h1><?php echo $id ? esc_html__( 'Manage Subscription', 'lucrativeit-subscription-recurring-billing' ) : esc_html__( 'New Subscription', 'lucrativeit-subscription-recurring-billing' ); ?></h1>
		<p class="lucrsure-sub"><?php esc_html_e( 'Assign a plan to a customer and choose how they are billed.', 'lucrativeit-subscription-recurring-billing' ); ?></p>
	</div>
</div>

<?php if ( $id ) : ?>

<div class="lucrsure-card lucrsure-form-card">
	<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
		<?php wp_nonce_field( 'lucrsure_save_subscription' ); ?>
		<input type="hidden" name="action" value="lucrsure_save_subscription" />
		<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />

		<div class="lucrsure-form-row">
			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Customer', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<select name="customer_id" required>
					<option value=""><?php esc_html_e( 'Select customer', 'lucrativeit-subscription-recurring-billing' ); ?></option>
					<?php foreach ( $customers as $customer ) : ?>
						<option value="<?php echo esc_attr( $customer['id'] ); ?>" <?php selected( $customer_id, $customer['id'] ); ?>><?php echo esc_html( $customer['name'] . ' (' . $customer['email'] . ')' ); ?></option>
					<?php endforeach; ?>
				</select>
			</div>
			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Plan', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<select name="plan_id" required>
					<option value=""><?php esc_html_e( 'Select plan', 'lucrativeit-subscription-recurring-billing' ); ?></option>
					<?php foreach ( $plans as $plan ) : ?>
						<option value="<?php echo esc_attr( $plan['id'] ); ?>" <?php selected( $plan_id, $plan['id'] ); ?>><?php echo esc_html( $plan['name'] . ' — ' . lucrsure_plan_format_price_display( $plan )['effective'] ); ?></option>
					<?php endforeach; ?>
				</select>
			</div>
		</div>

		<div class="lucrsure-form-row">
			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Status', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<select name="status">
					<?php foreach ( lucrsure_subscription_statuses() as $key => $label ) : ?>
						<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $status, $key ); ?>><?php echo esc_html( $label ); ?></option>
					<?php endforeach; ?>
				</select>
			</div>
			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Quantity', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<input type="number" min="1" name="quantity" value="<?php echo esc_attr( $quantity ); ?>" />
			</div>
		</div>

		<div class="lucrsure-form-row">
			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Start Date', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<input type="date" name="start_date" value="<?php echo esc_attr( $start_date ); ?>" />
			</div>
			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Trial Ends', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<input type="date" name="trial_ends" value="<?php echo esc_attr( $trial_ends ); ?>" />
			</div>
		</div>

		<div class="lucrsure-field">
			<label><?php esc_html_e( 'Payment Gateway', 'lucrativeit-subscription-recurring-billing' ); ?></label>
			<select name="gateway" id="lucrsure-gateway-select">
				<?php
				foreach ( $gateways as $gw ) :
					$auto = $gw->supports_automatic_recurring();
					?>
					<option value="<?php echo esc_attr( $gw->get_id() ); ?>" data-auto="<?php echo $auto ? '1' : '0'; ?>" <?php selected( $gateway, $gw->get_id() ); ?>>
						<?php echo esc_html( $gw->get_title() . ( $auto ? ' (' . __( 'Automatic Recurring', 'lucrativeit-subscription-recurring-billing' ) . ')' : ' (' . __( 'Invoice-based', 'lucrativeit-subscription-recurring-billing' ) . ')' ) ); ?>
					</option>
				<?php endforeach; ?>
			</select>
		</div>

		<div class="lucrsure-gateway-note lucrsure-gateway-note-auto">
			<strong>&#8635; <?php esc_html_e( 'AUTOMATIC PAYMENT', 'lucrativeit-subscription-recurring-billing' ); ?></strong>
			<span><?php esc_html_e( "Payment is charged automatically on each billing cycle. The customer's card is saved and renewed without sending an invoice.", 'lucrativeit-subscription-recurring-billing' ); ?></span>
		</div>
		<div class="lucrsure-gateway-note lucrsure-gateway-note-invoice">
			<strong>&#129534; <?php esc_html_e( 'INVOICE-BASED PAYMENT', 'lucrativeit-subscription-recurring-billing' ); ?></strong>
			<span><?php esc_html_e( 'An invoice with a payment link is emailed each cycle. The customer pays manually.', 'lucrativeit-subscription-recurring-billing' ); ?></span>
		</div>

		<div class="lucrsure-form-inline">
			<label class="lucrsure-check"><input type="checkbox" name="auto_renew" value="1" <?php checked( $auto_renew ); ?> /> <?php esc_html_e( 'Auto-renew subscription', 'lucrativeit-subscription-recurring-billing' ); ?></label>
		</div>

		<div class="lucrsure-form-actions">
			<a class="lucrsure-btn lucrsure-btn-light" href="<?php echo esc_url( lucrsure_admin_url( 'subscriptions' ) ); ?>"><?php esc_html_e( 'Cancel', 'lucrativeit-subscription-recurring-billing' ); ?></a>
			<button type="submit" class="lucrsure-btn lucrsure-btn-primary"><?php esc_html_e( 'Update Subscription', 'lucrativeit-subscription-recurring-billing' ); ?></button>
		</div>
	</form>
</div>

<?php else : ?>

<div class="lucrsure-wizard" id="lucrsure-subscription-wizard">
	<ol class="lucrsure-wizard-steps" aria-label="<?php esc_attr_e( 'Subscription setup steps', 'lucrativeit-subscription-recurring-billing' ); ?>">
		<li class="lucrsure-wizard-step is-active" data-step="1">
			<span class="lucrsure-wizard-step-num">1</span>
			<span class="lucrsure-wizard-step-label"><?php esc_html_e( 'Choose Plan', 'lucrativeit-subscription-recurring-billing' ); ?></span>
		</li>
		<li class="lucrsure-wizard-step" data-step="2">
			<span class="lucrsure-wizard-step-num">2</span>
			<span class="lucrsure-wizard-step-label"><?php esc_html_e( 'Select Customer', 'lucrativeit-subscription-recurring-billing' ); ?></span>
		</li>
		<li class="lucrsure-wizard-step" data-step="3">
			<span class="lucrsure-wizard-step-num">3</span>
			<span class="lucrsure-wizard-step-label"><?php esc_html_e( 'Billing Details', 'lucrativeit-subscription-recurring-billing' ); ?></span>
		</li>
	</ol>

	<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" class="lucrsure-card lucrsure-wizard-card">
		<?php wp_nonce_field( 'lucrsure_save_subscription' ); ?>
		<input type="hidden" name="action" value="lucrsure_save_subscription" />
		<input type="hidden" name="id" value="0" />
		<input type="hidden" name="plan_id" id="lucrsure-wizard-plan" value="<?php echo esc_attr( $plan_id ); ?>" />
		<input type="hidden" name="customer_id" id="lucrsure-wizard-customer" value="" />

		<!-- Step 1: Plan -->
		<div class="lucrsure-wizard-panel is-active" data-step="1">
			<div class="lucrsure-wizard-panel-head">
				<h2><?php esc_html_e( 'Select a Plan', 'lucrativeit-subscription-recurring-billing' ); ?></h2>
				<p class="lucrsure-muted"><?php esc_html_e( 'Pick the pricing tier for this subscription.', 'lucrativeit-subscription-recurring-billing' ); ?></p>
			</div>

			<?php if ( empty( $plans ) ) : ?>
				<div class="lucrsure-empty-state lucrsure-wizard-empty" id="lucrsure-plan-empty">
					<p><?php esc_html_e( 'No active plans yet. Create one to get started.', 'lucrativeit-subscription-recurring-billing' ); ?></p>
				</div>
			<?php endif; ?>

			<div class="lucrsure-cards-grid lucrsure-select-grid" id="lucrsure-plan-grid">
				<?php
				foreach ( $plans as $plan ) :
					$interval      = isset( $intervals[ $plan['billing_interval'] ] ) ? strtolower( $plan['billing_interval'] ) : $plan['billing_interval'];
					$selected      = (int) $plan_id === (int) $plan['id'];
					$price_display = lucrsure_plan_format_price_display( $plan );
					?>
					<button
						type="button"
						class="lucrsure-select-card lucrsure-plan-card<?php echo $selected ? ' is-selected' : ''; ?>"
						data-type="plan"
						data-id="<?php echo esc_attr( $plan['id'] ); ?>"
						data-name="<?php echo esc_attr( $plan['name'] ); ?>"
						data-price="<?php echo esc_attr( $price_display['effective'] ); ?>"
					>
						<div class="lucrsure-plan-top">
							<strong><?php echo esc_html( $plan['name'] ); ?></strong>
							<span class="lucrsure-select-check" aria-hidden="true">&#10003;</span>
						</div>
						<div class="lucrsure-plan-price">
							<?php if ( $price_display['has_special'] ) : ?>
								<span class="lucrsure-price-regular"><?php echo esc_html( $price_display['regular'] ); ?></span>
							<?php endif; ?>
							<?php echo esc_html( $price_display['effective'] ); ?>
							<span>/<?php echo esc_html( $interval ); ?></span>
						</div>
						<?php if ( $plan['description'] ) : ?>
							<p class="lucrsure-muted"><?php echo esc_html( $plan['description'] ); ?></p>
						<?php endif; ?>
						<?php if ( (int) $plan['trial_days'] > 0 ) : ?>
							<p class="lucrsure-plan-trial"><?php echo esc_html( sprintf( /* translators: %d days */ __( '%d-day free trial', 'lucrativeit-subscription-recurring-billing' ), (int) $plan['trial_days'] ) ); ?></p>
						<?php endif; ?>
					</button>
				<?php endforeach; ?>

				<button type="button" class="lucrsure-select-card lucrsure-add-card" data-open-modal="plan">
					<span class="lucrsure-add-icon">+</span>
					<strong><?php esc_html_e( 'Add New Plan', 'lucrativeit-subscription-recurring-billing' ); ?></strong>
					<span class="lucrsure-muted"><?php esc_html_e( 'Create a new pricing tier', 'lucrativeit-subscription-recurring-billing' ); ?></span>
				</button>
			</div>

			<div class="lucrsure-wizard-nav">
				<a class="lucrsure-btn lucrsure-btn-light" href="<?php echo esc_url( lucrsure_admin_url( 'subscriptions' ) ); ?>"><?php esc_html_e( 'Cancel', 'lucrativeit-subscription-recurring-billing' ); ?></a>
				<button type="button" class="lucrsure-btn lucrsure-btn-primary lucrsure-wizard-next" data-next="2" <?php echo ( empty( $plans ) || ! $plan_id ) ? 'disabled' : ''; ?>><?php esc_html_e( 'Next: Customer', 'lucrativeit-subscription-recurring-billing' ); ?> &rarr;</button>
			</div>
		</div>

		<!-- Step 2: Customer -->
		<div class="lucrsure-wizard-panel" data-step="2" hidden>
			<div class="lucrsure-wizard-panel-head">
				<h2><?php esc_html_e( 'Select a Customer', 'lucrativeit-subscription-recurring-billing' ); ?></h2>
				<p class="lucrsure-muted"><?php esc_html_e( 'Search and pick who this subscription belongs to.', 'lucrativeit-subscription-recurring-billing' ); ?></p>
			</div>

			<div class="lucrsure-search lucrsure-search-wide lucrsure-wizard-search" id="lucrsure-customer-search-wrap" <?php echo empty( $customers ) ? 'hidden' : ''; ?>>
				<span class="lucrsure-search-icon" aria-hidden="true">&#128269;</span>
				<input type="search" id="lucrsure-customer-search" placeholder="<?php esc_attr_e( 'Search by name, email, or company...', 'lucrativeit-subscription-recurring-billing' ); ?>" autocomplete="off" />
			</div>

			<?php if ( empty( $customers ) ) : ?>
				<div class="lucrsure-empty-state lucrsure-wizard-empty" id="lucrsure-customer-empty">
					<p><?php esc_html_e( 'No customers yet. Add one to continue.', 'lucrativeit-subscription-recurring-billing' ); ?></p>
				</div>
			<?php endif; ?>

			<div class="lucrsure-cards-grid lucrsure-select-grid lucrsure-customer-grid" id="lucrsure-customer-grid">
				<?php
				foreach ( $customers as $customer ) :
					$search_blob = strtolower( $customer['name'] . ' ' . $customer['email'] . ' ' . $customer['company'] );
					?>
					<button
						type="button"
						class="lucrsure-select-card lucrsure-customer-card"
						data-type="customer"
						data-id="<?php echo esc_attr( $customer['id'] ); ?>"
						data-name="<?php echo esc_attr( $customer['name'] ); ?>"
						data-email="<?php echo esc_attr( $customer['email'] ); ?>"
						data-search="<?php echo esc_attr( $search_blob ); ?>"
					>
						<div class="lucrsure-customer-card-top">
							<span class="lucrsure-avatar lucrsure-avatar-lg"><?php echo esc_html( strtoupper( substr( $customer['name'], 0, 2 ) ) ); ?></span>
							<span class="lucrsure-select-check" aria-hidden="true">&#10003;</span>
						</div>
						<strong><?php echo esc_html( $customer['name'] ); ?></strong>
						<span class="lucrsure-muted"><?php echo esc_html( $customer['email'] ); ?></span>
						<?php if ( $customer['company'] ) : ?>
							<span class="lucrsure-customer-company"><?php echo esc_html( $customer['company'] ); ?></span>
						<?php endif; ?>
						<span class="lucrsure-pill lucrsure-status-<?php echo esc_attr( $customer['status'] ); ?>"><?php echo esc_html( $customer['status'] ); ?></span>
					</button>
				<?php endforeach; ?>

				<button type="button" class="lucrsure-select-card lucrsure-add-card" data-open-modal="customer">
					<span class="lucrsure-add-icon">+</span>
					<strong><?php esc_html_e( 'Add New Customer', 'lucrativeit-subscription-recurring-billing' ); ?></strong>
					<span class="lucrsure-muted"><?php esc_html_e( 'Create a new subscriber', 'lucrativeit-subscription-recurring-billing' ); ?></span>
				</button>
			</div>
			<p class="lucrsure-wizard-no-results lucrsure-muted" id="lucrsure-customer-no-results" hidden><?php esc_html_e( 'No customers match your search.', 'lucrativeit-subscription-recurring-billing' ); ?></p>

			<div class="lucrsure-wizard-nav">
				<button type="button" class="lucrsure-btn lucrsure-btn-light lucrsure-wizard-back" data-back="1">&larr; <?php esc_html_e( 'Back', 'lucrativeit-subscription-recurring-billing' ); ?></button>
				<button type="button" class="lucrsure-btn lucrsure-btn-primary lucrsure-wizard-next" data-next="3" disabled><?php esc_html_e( 'Next: Billing', 'lucrativeit-subscription-recurring-billing' ); ?> &rarr;</button>
			</div>
		</div>

		<!-- Step 3: Billing options -->
		<div class="lucrsure-wizard-panel" data-step="3" hidden>
			<div class="lucrsure-wizard-panel-head">
				<h2><?php esc_html_e( 'Billing & Subscription Options', 'lucrativeit-subscription-recurring-billing' ); ?></h2>
				<p class="lucrsure-muted"><?php esc_html_e( 'Configure status, dates, and payment method.', 'lucrativeit-subscription-recurring-billing' ); ?></p>
			</div>

			<div class="lucrsure-wizard-summary" id="lucrsure-wizard-summary">
				<div class="lucrsure-wizard-summary-item">
					<span class="lucrsure-wizard-summary-label"><?php esc_html_e( 'Plan', 'lucrativeit-subscription-recurring-billing' ); ?></span>
					<strong id="lucrsure-summary-plan">—</strong>
				</div>
				<div class="lucrsure-wizard-summary-item">
					<span class="lucrsure-wizard-summary-label"><?php esc_html_e( 'Customer', 'lucrativeit-subscription-recurring-billing' ); ?></span>
					<strong id="lucrsure-summary-customer">—</strong>
				</div>
			</div>

			<div class="lucrsure-form-row">
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Status', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<select name="status">
						<?php foreach ( lucrsure_subscription_statuses() as $key => $label ) : ?>
							<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $status, $key ); ?>><?php echo esc_html( $label ); ?></option>
						<?php endforeach; ?>
					</select>
				</div>
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Quantity', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="number" min="1" name="quantity" value="<?php echo esc_attr( $quantity ); ?>" />
				</div>
			</div>

			<div class="lucrsure-form-row">
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Start Date', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="date" name="start_date" value="<?php echo esc_attr( $start_date ); ?>" />
				</div>
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Trial Ends', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="date" name="trial_ends" value="<?php echo esc_attr( $trial_ends ); ?>" />
				</div>
			</div>

			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Payment Gateway', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<select name="gateway" id="lucrsure-gateway-select">
					<?php
					foreach ( $gateways as $gw ) :
						$auto = $gw->supports_automatic_recurring();
						?>
						<option value="<?php echo esc_attr( $gw->get_id() ); ?>" data-auto="<?php echo $auto ? '1' : '0'; ?>" <?php selected( $gateway, $gw->get_id() ); ?>>
							<?php echo esc_html( $gw->get_title() . ( $auto ? ' (' . __( 'Automatic Recurring', 'lucrativeit-subscription-recurring-billing' ) . ')' : ' (' . __( 'Invoice-based', 'lucrativeit-subscription-recurring-billing' ) . ')' ) ); ?>
						</option>
					<?php endforeach; ?>
				</select>
			</div>

			<div class="lucrsure-gateway-note lucrsure-gateway-note-auto">
				<strong>&#8635; <?php esc_html_e( 'AUTOMATIC PAYMENT', 'lucrativeit-subscription-recurring-billing' ); ?></strong>
				<span><?php esc_html_e( "Payment is charged automatically on each billing cycle. The customer's card is saved and renewed without sending an invoice.", 'lucrativeit-subscription-recurring-billing' ); ?></span>
			</div>
			<div class="lucrsure-gateway-note lucrsure-gateway-note-invoice">
				<strong>&#129534; <?php esc_html_e( 'INVOICE-BASED PAYMENT', 'lucrativeit-subscription-recurring-billing' ); ?></strong>
				<span><?php esc_html_e( 'An invoice with a payment link is emailed each cycle. The customer pays manually.', 'lucrativeit-subscription-recurring-billing' ); ?></span>
			</div>

			<div class="lucrsure-form-inline">
				<label class="lucrsure-check"><input type="checkbox" name="auto_renew" value="1" <?php checked( $auto_renew ); ?> /> <?php esc_html_e( 'Auto-renew subscription', 'lucrativeit-subscription-recurring-billing' ); ?></label>
			</div>

			<div class="lucrsure-wizard-nav">
				<button type="button" class="lucrsure-btn lucrsure-btn-light lucrsure-wizard-back" data-back="2">&larr; <?php esc_html_e( 'Back', 'lucrativeit-subscription-recurring-billing' ); ?></button>
				<button type="submit" class="lucrsure-btn lucrsure-btn-primary"><?php esc_html_e( 'Create Subscription', 'lucrativeit-subscription-recurring-billing' ); ?></button>
			</div>
		</div>
	</form>
</div>

<div class="lucrsure-modal" id="lucrsure-modal-plan" hidden>
	<div class="lucrsure-modal-backdrop" data-close-modal></div>
	<div class="lucrsure-modal-dialog" role="dialog" aria-modal="true" aria-labelledby="lucrsure-modal-plan-title">
		<div class="lucrsure-modal-header">
			<h3 id="lucrsure-modal-plan-title"><?php esc_html_e( 'Add New Plan', 'lucrativeit-subscription-recurring-billing' ); ?></h3>
			<button type="button" class="lucrsure-modal-close" data-close-modal aria-label="<?php esc_attr_e( 'Close', 'lucrativeit-subscription-recurring-billing' ); ?>">&times;</button>
		</div>
		<form id="lucrsure-quick-plan-form" class="lucrsure-modal-body">
			<div class="lucrsure-form-row">
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Plan Name', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="text" name="name" required />
				</div>
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Price', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="number" step="0.01" min="0" name="price" value="0" required />
				</div>
			</div>
			<div class="lucrsure-form-row">
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Currency', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="text" name="currency" value="<?php echo esc_attr( $settings->get( 'default_currency', 'USD' ) ); ?>" />
				</div>
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Billing Interval', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<select name="billing_interval">
						<?php foreach ( lucrsure_billing_intervals() as $key => $label ) : ?>
							<option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $label ); ?></option>
						<?php endforeach; ?>
					</select>
				</div>
			</div>
			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Trial Days', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<input type="number" min="0" name="trial_days" value="0" />
			</div>
			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Description', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<textarea name="description" rows="2"></textarea>
			</div>
			<p class="lucrsure-modal-error" id="lucrsure-plan-modal-error" hidden></p>
			<div class="lucrsure-modal-footer">
				<button type="button" class="lucrsure-btn lucrsure-btn-light" data-close-modal><?php esc_html_e( 'Cancel', 'lucrativeit-subscription-recurring-billing' ); ?></button>
				<button type="submit" class="lucrsure-btn lucrsure-btn-primary"><?php esc_html_e( 'Create Plan', 'lucrativeit-subscription-recurring-billing' ); ?></button>
			</div>
		</form>
	</div>
</div>

<div class="lucrsure-modal" id="lucrsure-modal-customer" hidden>
	<div class="lucrsure-modal-backdrop" data-close-modal></div>
	<div class="lucrsure-modal-dialog" role="dialog" aria-modal="true" aria-labelledby="lucrsure-modal-customer-title">
		<div class="lucrsure-modal-header">
			<h3 id="lucrsure-modal-customer-title"><?php esc_html_e( 'Add New Customer', 'lucrativeit-subscription-recurring-billing' ); ?></h3>
			<button type="button" class="lucrsure-modal-close" data-close-modal aria-label="<?php esc_attr_e( 'Close', 'lucrativeit-subscription-recurring-billing' ); ?>">&times;</button>
		</div>
		<form id="lucrsure-quick-customer-form" class="lucrsure-modal-body">
			<div class="lucrsure-form-row">
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Full Name', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="text" name="name" required />
				</div>
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Email', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="email" name="email" required />
				</div>
			</div>
			<div class="lucrsure-form-row">
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Phone', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="text" name="phone" />
				</div>
				<div class="lucrsure-field">
					<label><?php esc_html_e( 'Company', 'lucrativeit-subscription-recurring-billing' ); ?></label>
					<input type="text" name="company" />
				</div>
			</div>
			<div class="lucrsure-field">
				<label><?php esc_html_e( 'Branch', 'lucrativeit-subscription-recurring-billing' ); ?></label>
				<select name="branch_id">
					<option value="0"><?php esc_html_e( 'Unassigned', 'lucrativeit-subscription-recurring-billing' ); ?></option>
					<?php foreach ( $branches as $branch ) : ?>
						<option value="<?php echo esc_attr( $branch['id'] ); ?>"><?php echo esc_html( $branch['name'] ); ?></option>
					<?php endforeach; ?>
				</select>
			</div>
			<p class="lucrsure-modal-error" id="lucrsure-customer-modal-error" hidden></p>
			<div class="lucrsure-modal-footer">
				<button type="button" class="lucrsure-btn lucrsure-btn-light" data-close-modal><?php esc_html_e( 'Cancel', 'lucrativeit-subscription-recurring-billing' ); ?></button>
				<button type="submit" class="lucrsure-btn lucrsure-btn-primary"><?php esc_html_e( 'Create Customer', 'lucrativeit-subscription-recurring-billing' ); ?></button>
			</div>
		</form>
	</div>
</div>

<?php endif; ?>
