<?php
if ( ! defined( 'ABSPATH' ) ) exit;
?>
<div class="wrap bingocr-admin-wrap">
	<h1><?php esc_html_e( 'Fleet Management', 'bingocar' ); ?></h1>

	<div id="bingocr-cars-app">

		<div class="bingocr-toolbar">
			<button class="button button-primary" id="bingocr-add-car">
				<?php esc_html_e( '+ Add Car', 'bingocar' ); ?>
			</button>
		</div>

		<div id="bingocr-cars-list">
			<p><?php esc_html_e( 'Loading…', 'bingocar' ); ?></p>
		</div>

		<!-- Car form (hidden until add/edit) -->
		<div id="bingocr-car-form-wrap" class="bingocr-modal-wrap" style="display:none;">
			<div class="bingocr-modal">
				<h2 id="bingocr-car-form-title"><?php esc_html_e( 'Add Car', 'bingocar' ); ?></h2>
				<form id="bingocr-car-form" novalidate>
					<input type="hidden" id="car-id" value="">

					<div class="bingocr-form-row bingocr-two-col">
						<label><?php esc_html_e( 'Brand *', 'bingocar' ); ?><br>
							<input type="text" name="brand" required class="regular-text">
						</label>
						<label><?php esc_html_e( 'Model *', 'bingocar' ); ?><br>
							<input type="text" name="model" required class="regular-text">
						</label>
					</div>

					<div class="bingocr-form-row bingocr-two-col">
						<label><?php esc_html_e( 'Year', 'bingocar' ); ?><br>
							<input type="number" name="year" min="1990" max="2030" class="small-text">
						</label>
						<label><?php esc_html_e( 'Category', 'bingocar' ); ?><br>
							<input type="text" name="category" placeholder="economy, suv, luxury…" class="regular-text">
						</label>
					</div>

					<div class="bingocr-form-row bingocr-three-col">
						<label><?php esc_html_e( 'Transmission', 'bingocar' ); ?><br>
							<select name="transmission">
								<option value="manual"><?php esc_html_e( 'Manual', 'bingocar' ); ?></option>
								<option value="automatic"><?php esc_html_e( 'Automatic', 'bingocar' ); ?></option>
							</select>
						</label>
						<label><?php esc_html_e( 'Fuel Type', 'bingocar' ); ?><br>
							<select name="fuel_type">
								<option value="petrol"><?php esc_html_e( 'Petrol', 'bingocar' ); ?></option>
								<option value="diesel"><?php esc_html_e( 'Diesel', 'bingocar' ); ?></option>
								<option value="electric"><?php esc_html_e( 'Electric', 'bingocar' ); ?></option>
								<option value="hybrid"><?php esc_html_e( 'Hybrid', 'bingocar' ); ?></option>
							</select>
						</label>
						<label><?php esc_html_e( 'Seats', 'bingocar' ); ?><br>
							<input type="number" name="seats" min="1" max="20" value="5" class="small-text">
						</label>
					</div>

					<div class="bingocr-form-row bingocr-three-col">
						<label><?php esc_html_e( 'Price / Day *', 'bingocar' ); ?><br>
							<input type="number" name="price_per_day" min="0" step="0.01" required class="small-text">
						</label>
						<label><?php esc_html_e( 'Quantity', 'bingocar' ); ?><br>
							<input type="number" name="quantity" min="1" value="1" class="small-text">
						</label>
						<label><?php esc_html_e( 'Status', 'bingocar' ); ?><br>
							<select name="status">
								<option value="available"><?php esc_html_e( 'Available', 'bingocar' ); ?></option>
								<option value="unavailable"><?php esc_html_e( 'Unavailable', 'bingocar' ); ?></option>
								<option value="maintenance"><?php esc_html_e( 'Maintenance', 'bingocar' ); ?></option>
							</select>
						</label>
					</div>

					<div class="bingocr-form-row bingocr-two-col">
						<div>
							<label><?php esc_html_e( 'Deposit Type', 'bingocar' ); ?><br>
								<select name="deposit_type" id="car-deposit-type" style="width:100%">
									<option value="default"><?php esc_html_e( 'Default (global setting)', 'bingocar' ); ?></option>
									<option value="percentage"><?php esc_html_e( 'Percentage of total', 'bingocar' ); ?></option>
									<option value="flat"><?php esc_html_e( 'Flat amount', 'bingocar' ); ?></option>
								</select>
							</label>
							<p class="description" id="car-deposit-default-hint"></p>
						</div>
						<div id="car-deposit-value-wrap" style="display:none;">
							<label><?php esc_html_e( 'Deposit Value', 'bingocar' ); ?><br>
								<input type="number" name="deposit_value" min="0" step="0.01" value="0" class="small-text">
							</label>
							<p class="description" id="car-deposit-value-hint"></p>
						</div>
					</div>

					<div class="bingocr-form-row">
						<label><?php esc_html_e( 'Photo', 'bingocar' ); ?><br>
							<button type="button" class="button" id="bingocr-select-image"><?php esc_html_e( 'Select Image', 'bingocar' ); ?></button>
							<input type="hidden" name="image_id" id="car-image-id">
							<input type="hidden" name="image_url" id="car-image-url">
							<img id="car-image-preview" src="" alt="" style="max-height:80px;margin-left:8px;vertical-align:middle;display:none;">
						</label>
					</div>

					<div class="bingocr-form-row">
						<label><?php esc_html_e( 'Description', 'bingocar' ); ?><br>
							<textarea name="description" rows="3" class="large-text"></textarea>
						</label>
					</div>

					<div class="bingocr-form-row">
						<label><?php esc_html_e( 'Features (comma separated)', 'bingocar' ); ?><br>
							<input type="text" name="features_raw" placeholder="AC, GPS, Bluetooth…" class="large-text">
						</label>
					</div>

					<!-- Duration Pricing Tiers – only shown when editing existing car -->
					<div id="bingocr-car-tiers-section" style="display:none;">
						<hr style="margin:20px 0 16px;border:none;border-top:1px solid #eee;">
						<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">
							<strong><?php esc_html_e( 'Duration Pricing Tiers', 'bingocar' ); ?></strong>
							<button type="button" class="button" id="bingocr-add-tier">
								<?php esc_html_e( '+ Add Tier', 'bingocar' ); ?>
							</button>
						</div>
						<p class="description" style="margin-bottom:12px;">
							<?php esc_html_e( 'Day-range rates specific to this car — e.g. days 1–5 = base price, days 6–14 = lower rate. When matched, overrides the base price per day.', 'bingocar' ); ?>
						</p>
						<div id="bingocr-car-tiers-header" class="bcr-tier-row bcr-tier-header" style="display:none;">
							<span><?php esc_html_e( 'From day', 'bingocar' ); ?></span>
							<span><?php esc_html_e( 'To day', 'bingocar' ); ?></span>
							<span><?php esc_html_e( 'Rate / day', 'bingocar' ); ?></span>
							<span></span>
						</div>
						<div id="bingocr-car-tiers-body"></div>
					</div>

					<div class="bingocr-form-actions">
						<button type="submit" class="button button-primary"><?php esc_html_e( 'Save Car', 'bingocar' ); ?></button>
						<button type="button" class="button" id="bingocr-cancel-car"><?php esc_html_e( 'Cancel', 'bingocar' ); ?></button>
						<span class="bingocr-form-message"></span>
					</div>
				</form>
			</div>
		</div>

	</div>
</div>
