<?php
/**
 * Frontend leave request form.
 *
 * @package MerchantKits\AttendanceManager
 *
 * @var array $employee Employee row.
 * @var array $policies Active leave policies.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<div class="mkam-widget mkam-leave-form">
	<h3 class="mkam-widget__title"><?php esc_html_e( 'Request Leave', 'merchantkits-attendance-manager' ); ?></h3>

	<form id="mkam-leave-form">
		<p>
			<label for="mkam-leave-type"><?php esc_html_e( 'Leave Type', 'merchantkits-attendance-manager' ); ?> *</label>
			<select id="mkam-leave-type" name="leave_type" required>
				<option value=""><?php esc_html_e( '— Select —', 'merchantkits-attendance-manager' ); ?></option>
				<?php foreach ( $policies as $policy ) : ?>
					<option value="<?php echo esc_attr( $policy['leave_type'] ); ?>"><?php echo esc_html( $policy['label'] ); ?></option>
				<?php endforeach; ?>
			</select>
		</p>

		<p class="mkam-leave-balance" id="mkam-leave-balance" aria-live="polite"></p>

		<p>
			<label for="mkam-start-date"><?php esc_html_e( 'Start Date', 'merchantkits-attendance-manager' ); ?> *</label>
			<input type="date" id="mkam-start-date" name="start_date" required />
		</p>

		<p>
			<label for="mkam-end-date"><?php esc_html_e( 'End Date', 'merchantkits-attendance-manager' ); ?> *</label>
			<input type="date" id="mkam-end-date" name="end_date" required />
		</p>

		<p>
			<label><input type="checkbox" id="mkam-half-day" name="is_half_day" value="1" /> <?php esc_html_e( 'Half Day', 'merchantkits-attendance-manager' ); ?></label>
		</p>

		<p id="mkam-half-day-period-wrap" style="display:none;">
			<label for="mkam-half-day-period"><?php esc_html_e( 'Half Day Period', 'merchantkits-attendance-manager' ); ?></label>
			<select id="mkam-half-day-period" name="half_day_period">
				<option value="first_half"><?php esc_html_e( 'First Half', 'merchantkits-attendance-manager' ); ?></option>
				<option value="second_half"><?php esc_html_e( 'Second Half', 'merchantkits-attendance-manager' ); ?></option>
			</select>
		</p>

		<p>
			<label for="mkam-reason"><?php esc_html_e( 'Reason', 'merchantkits-attendance-manager' ); ?> *</label>
			<textarea id="mkam-reason" name="reason" rows="3" required></textarea>
		</p>

		<button type="submit" class="mkam-btn mkam-btn--primary"><?php esc_html_e( 'Submit Request', 'merchantkits-attendance-manager' ); ?></button>

		<div class="mkam-leave-form__message" id="mkam-leave-message" role="status" aria-live="polite"></div>
	</form>
</div>
