<?php
/**
 * Frontend template: Inline donation form.
 * Compact horizontal layout — suited for sidebars and widget areas.
 *
 * Same variable contract as form-stacked.php.
 *
 * @package Donatico
 */

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

// Variables are set by FormRenderer::render() before this template is included.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>

<div class="donatico-form donatico-form--inline"
	 id="<?php echo esc_attr( $form_id ); ?>"
	 data-form-id="<?php echo esc_attr( $form_id ); ?>"
	 data-currency="<?php echo esc_attr( $currency ); ?>"
	 data-currency-symbol="<?php echo esc_attr( $currency_symbol ); ?>">

	<?php if ( $title ) : ?>
		<h2 class="donatico-form-title"><?php echo esc_html( $title ); ?></h2>
	<?php endif; ?>

	<?php if ( $description ) : ?>
		<p class="donatico-form-description"><?php echo esc_html( $description ); ?></p>
	<?php endif; ?>

	<?php if ( $goal > 0 ) : ?>
	<div class="donatico-goal-progress">
		<div class="donatico-progress-track"
			 role="progressbar"
			 aria-valuenow="<?php echo esc_attr( (string) $progress ); ?>"
			 aria-valuemin="0"
			 aria-valuemax="100">
			<div class="donatico-progress-fill" style="transform:scaleX(<?php echo esc_attr( number_format( $progress / 100, 4 ) ); ?>)"></div>
		</div>
		<p class="donatico-goal-meta">
			<strong><?php echo esc_html( $currency_symbol . number_format( $total_raised / 100, 2 ) ); ?></strong>
			<?php esc_html_e( 'raised', 'donatico' ); ?>
			· <?php echo esc_html( $progress . '%' ); ?>
		</p>
	</div>
	<?php endif; ?>

	<form class="donatico-form-element"
		  id="<?php echo esc_attr( $form_id . '-form' ); ?>"
		  novalidate
		  aria-label="<?php esc_attr_e( 'Donation form', 'donatico' ); ?>">

		<?php /* ---- Amount row ---- */ ?>
		<div class="donatico-amount-row"
			 role="group"
			 aria-label="<?php esc_attr_e( 'Select an amount', 'donatico' ); ?>">
			<?php foreach ( $amounts as $preset ) : ?>
			<button type="button"
					class="donatico-amount-btn"
					data-amount="<?php echo esc_attr( (string) $preset ); ?>"
					aria-pressed="false">
				<?php echo esc_html( $currency_symbol . $preset ); ?>
			</button>
			<?php endforeach; ?>
			<button type="button"
					class="donatico-amount-btn donatico-amount-btn--custom"
					aria-pressed="false">
				<?php esc_html_e( 'Other', 'donatico' ); ?>
			</button>
		</div>

		<div class="donatico-custom-amount-wrap" hidden>
			<div class="donatico-currency-input-wrap">
				<span class="donatico-currency-symbol" aria-hidden="true"><?php echo esc_html( $currency_symbol ); ?></span>
				<input type="number"
					   id="<?php echo esc_attr( $form_id . '-custom' ); ?>"
					   class="donatico-input donatico-custom-input"
					   min="1"
					   step="0.01"
					   placeholder="0.00"
					   aria-label="<?php esc_attr_e( 'Custom donation amount', 'donatico' ); ?>">
			</div>
		</div>

		<?php
		/**
		 * Fires inside the donation form, after the amount picker
		 * and before donor info. Use to inject custom fields
		 * (frequency toggle, tier selector, campaign hidden inputs).
		 *
		 * @since 1.0.1
		 * @param array $context Form rendering context.
		 */
		do_action(
			'donatico_form_fields',
			array(
				'form_id'         => $form_id,
				'layout'          => 'inline',
				'currency'        => $currency,
				'currency_symbol' => $currency_symbol,
				'amounts'         => $amounts,
				'goal'            => $goal,
			)
		);
		?>

		<?php /* ---- Compact donor row ---- */ ?>
		<div class="donatico-inline-donor-row">
			<div class="donatico-field">
				<label for="<?php echo esc_attr( $form_id . '-name' ); ?>" class="donatico-sr-only">
					<?php esc_html_e( 'Full Name', 'donatico' ); ?>
				</label>
				<input type="text"
					   id="<?php echo esc_attr( $form_id . '-name' ); ?>"
					   class="donatico-input donatico-input-name"
					   required
					   aria-required="true"
					   autocomplete="name"
					   placeholder="<?php esc_attr_e( 'Full name', 'donatico' ); ?>">
			</div>
			<div class="donatico-field">
				<label for="<?php echo esc_attr( $form_id . '-email' ); ?>" class="donatico-sr-only">
					<?php esc_html_e( 'Email Address', 'donatico' ); ?>
				</label>
				<input type="email"
					   id="<?php echo esc_attr( $form_id . '-email' ); ?>"
					   class="donatico-input donatico-input-email"
					   required
					   aria-required="true"
					   autocomplete="email"
					   placeholder="<?php esc_attr_e( 'Email address', 'donatico' ); ?>">
			</div>
			<button type="submit" class="donatico-submit-btn" disabled aria-live="polite">
				<?php echo esc_html( $button_text ); ?>
			</button>
		</div>

		<?php if ( $show_message ) : ?>
		<div class="donatico-field">
			<label for="<?php echo esc_attr( $form_id . '-message' ); ?>" class="donatico-field-label">
				<?php esc_html_e( 'Message', 'donatico' ); ?>
				<span class="donatico-optional"><?php esc_html_e( '(optional)', 'donatico' ); ?></span>
			</label>
			<textarea id="<?php echo esc_attr( $form_id . '-message' ); ?>"
					  class="donatico-textarea donatico-input-message"
					  rows="2"
					  placeholder="<?php esc_attr_e( 'Leave a message…', 'donatico' ); ?>"></textarea>
		</div>
		<?php endif; ?>

		<?php if ( $allow_anonymous ) : ?>
		<div class="donatico-field donatico-field--checkbox">
			<label class="donatico-checkbox-label">
				<input type="checkbox" class="donatico-input-anonymous" value="1">
				<?php esc_html_e( 'Donate anonymously', 'donatico' ); ?>
			</label>
		</div>
		<?php endif; ?>

		<input type="hidden" class="donatico-nonce" value="<?php echo esc_attr( $nonce ); ?>">
		<input type="hidden" class="donatico-currency-field" value="<?php echo esc_attr( $currency ); ?>">

		<p class="donatico-secure-badge">
			<svg class="donatico-lock-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" width="12" height="12">
				<path fill-rule="evenodd" d="M5 9V7a5 5 0 0110 0v2a2 2 0 012 2v5a2 2 0 01-2 2H5a2 2 0 01-2-2v-5a2 2 0 012-2zm8-2v2H7V7a3 3 0 016 0z" clip-rule="evenodd"/>
			</svg>
			<?php esc_html_e( 'Secure payment via Stripe', 'donatico' ); ?>
		</p>

		<div class="donatico-form-error" hidden aria-live="assertive" role="alert"></div>

	</form>
</div>
