<script lang="ts">
	import { page } from '$app/stores';
	import { resolve } from '$app/paths';
	import { onMount } from 'svelte';

	let format = $state('html');

	let pdfNotice = $state(true);

	onMount(() => {
		format = $page.url.searchParams.get('format') || 'html';
		if (format === 'pdf') {
			// Strip ?format=pdf from the URL so a refresh doesn't re-trigger the print dialog.
			const clean = window.location.pathname + window.location.hash;
			history.replaceState(null, '', clean);

			// Open the print dialog once the page is rendered.
			// The notice element is removed before print so it won't appear in the PDF.
			setTimeout(() => {
				pdfNotice = false;
				// Small delay so Svelte can remove the element before the print engine snapshots.
				setTimeout(() => window.print(), 50);
			}, 100);
		}
	});
</script>

<svelte:head>
	<title>Booking, Deposit & Cancellation Policy</title>
	<style>
		@media print {
			:global(nav),
			:global(.no-print) {
				display: none !important;
			}
			:global(body) {
				padding-top: 0 !important;
			}
		}
	</style>
</svelte:head>

<div class="mx-auto max-w-2xl px-4 py-8 text-gray-900">
	<h1 class="mb-2 border-b border-gray-200 pb-4 text-2xl font-bold">
		Booking, Deposit & Cancellation Policy
	</h1>
	<p class="mb-8 font-mono text-xs text-gray-500">Last updated: 18 June 2026</p>

	{#if format === 'pdf' && pdfNotice}
		<p class="mb-6 rounded border border-gray-200 bg-gray-50 p-3 text-xs text-gray-600 italic">
			Generating PDF… If the print dialog does not appear, use Ctrl+P / Cmd+P.
		</p>
	{/if}

	<div class="space-y-8 text-sm leading-relaxed text-gray-700">
		<!-- Section 1 -->
		<section>
			<h2 class="mb-3 text-base font-semibold text-gray-900">
				1. Deposit Requirements & Booking Rules
			</h2>
			<p class="mb-3">
				Where a deposit is required to secure your appointment, you must pay at least
				<strong>20%</strong> of the total service cost before the 24-hour deadline prior to the
				appointment. The 20% can be paid in a single payment or accumulated across multiple payments
				— what matters is the total when the deadline passes. When deposit restrictions are active
				on your account, appointments must be scheduled at least
				<strong>36 hours in advance</strong>.
			</p>
			<p class="mb-3">
				To maintain fairness and prevent scheduling abuse, accounts with outstanding deposit
				requirements are limited to <strong>one (1) active booking</strong> at any given time. No additional
				appointments can be scheduled until your current appointment is either completed, cancelled, or
				officially lapsed.
			</p>
		</section>

		<!-- Section 2 -->
		<section>
			<h2 class="mb-3 text-base font-semibold text-gray-900">
				2. Unpaid Deposits & The "Pending Release" Window
			</h2>
			<p class="mb-3">
				If a required deposit is not paid at least 24 hours before the appointment begins, the
				booking is shifted into a <strong>"Pending Release"</strong> status. The slot becomes vulnerable
				— if another customer books an overlapping time and pays, your original booking is automatically
				evicted.
			</p>
			<p class="mb-3">
				While in this status, your appointment is <strong>not guaranteed</strong>. The system will
				make this time slot visible to other clients. If another user attempts to book an
				overlapping time and completes their deposit payment first, your unpaid booking will be
				immediately and automatically evicted.
			</p>
			<p class="mb-3">
				If the slot has not yet been claimed by another client, paying your outstanding deposit will
				instantly restore your booking to a fully confirmed status.
			</p>
		</section>

		<!-- Section 3 -->
		<section>
			<h2 class="mb-3 text-base font-semibold text-gray-900">3. Cancellation & Refund Tiers</h2>
			<p class="mb-3">
				We understand that plans can change. Eligibility for a refund depends strictly on the amount
				of notice provided prior to your scheduled appointment time. These thresholds represent a
				genuine pre-estimate of the operational costs and loss of business incurred by late
				cancellations:
			</p>

			<div class="mt-4 divide-y divide-gray-200 rounded-md border border-gray-200">
				<div class="bg-gray-50/50 p-4">
					<p class="font-semibold text-gray-900">Notice of more than 72 hours</p>
					<p class="mt-1 text-xs text-gray-600">
						You are entitled to a full 100% refund of all deposits and advance payments made for the
						booking.
					</p>
				</div>

				<div class="p-4">
					<p class="font-semibold text-gray-900">Notice between 24 and 72 hours</p>
					<p class="mt-1 text-xs text-gray-600">
						Any advance payments made up to 50% of the total booking value are treated as a
						Protected Deposit. This Protected Deposit is retained to cover the short-notice vacancy,
						while any balance paid above 50% will be fully refunded.
					</p>
				</div>

				<div class="bg-gray-50/50 p-4">
					<p class="font-semibold text-gray-900">Notice of less than 24 hours</p>
					<p class="mt-1 text-xs text-gray-600">
						All processed payments and deposits are entirely non-refundable and will be retained.
						The cancellation will be logged as a missed appointment history strike.
					</p>
				</div>
			</div>

			<h3 class="mt-6 mb-2 text-sm font-semibold text-gray-800">Refund Payment Method</h3>
			<p class="mb-3 text-sm leading-relaxed text-gray-700">
				Refunds are returned to the original payment method where possible:
			</p>
			<ul class="mb-4 list-disc space-y-2 pl-5 text-sm leading-relaxed text-gray-700">
				<li>
					<strong>Card payments</strong> (debit/credit card processed online or in-person): Refunded directly
					back to the original card via Square. Processing times vary by card issuer (typically 3–10 working
					days).
				</li>
				<li>
					<strong>Gift card payments</strong>: Refunded back to the original gift card. The gift
					card's remaining balance is incremented and is immediately available for use. Expired gift
					cards are non-refundable.
				</li>
				<li>
					<strong>Cash payments</strong>: Credited to your account balance, available for immediate
					use against future bookings or services.
				</li>
			</ul>
			<p class="mb-4 text-xs leading-relaxed text-gray-500 italic">
				If a card refund cannot be processed (e.g. the card is expired or the Square payment
				reference is unavailable), the refund amount will be credited to your account balance as a
				fallback, so you are never left out of pocket.
			</p>

			<h3 class="mt-6 mb-2 text-sm font-semibold text-gray-800">Guest / Walk-In Bookings</h3>
			<p class="mb-3 text-sm leading-relaxed text-gray-700">
				Walk-in customers who book without creating an account are issued a <strong
					>guest account</strong
				> to hold their booking and payment records. The same cancellation and refund tiers above apply
				to guest bookings. Refunds are returned as follows:
			</p>
			<ul class="mb-4 list-disc space-y-2 pl-5 text-sm leading-relaxed text-gray-700">
				<li>
					<strong>Card payments</strong>: Refunded back to the original card via Square (same as
					registered users).
				</li>
				<li>
					<strong>Gift card payments</strong>: Refunded back to the original gift card. The gift
					card's remaining balance is incremented. Expired gift cards are non-refundable.
				</li>
				<li>
					<strong>Cash payments</strong>: Refunded in person at the salon. Please bring your receipt
					and an admin will process your cash refund at the till.
				</li>
			</ul>
			<p class="mb-3 text-xs leading-relaxed text-gray-500 italic">
				Guest accounts do not hold rolling balances. All refunds for walk-in bookings are returned
				via the original payment method or processed manually by salon staff.
			</p>
		</section>

		<!-- Section 4 -->
		<section>
			<h2 class="mb-3 text-base font-semibold text-gray-900">4. Missed Appointments (No-Shows)</h2>
			<p class="mb-3">
				Failing to attend a confirmed appointment without notifying us in advance constitutes a
				"No-Show". Cancelling a pending or deposit-lapsed booking within 24 hours does
				<strong>not</strong> count as a no-show — only confirmed bookings (where the slot was secured
				with a payment) can incur no-show strikes.
			</p>
			<p class="mb-3">
				If your account accumulates <strong
					>two (2) No-Show strikes within a rolling 6-month period</strong
				>, our system will automatically restrict your account privileges, making upfront deposits
				mandatory for future booking attempts (3 deposits required before deposits are automatically
				cleared). No-show strikes older than 6 months are automatically excluded from the count.
			</p>
			<p class="mb-3">
				Each completed booking with a payment reduces the required deposit count by one. Once the
				count reaches zero, all prior no-show records within the 6-month window are forgiven and
				your account returns to normal — no upfront deposits required — until a new no-show occurs.
				The salon can also forgive individual no-shows at management's discretion, which immediately
				removes them from the count.
			</p>
		</section>

		<!-- Section 5 -->
		<section>
			<h2 class="mb-3 text-base font-semibold text-gray-900">
				5. Statutory Rights & Exceptional Circumstances
			</h2>
			<p class="mb-3">
				This policy is strictly aligned with the <strong>Consumer Rights Act 2015</strong>. Nothing
				in these terms limits your statutory right to receive services carried out with reasonable
				care and skill, or your right to a full refund if we are forced to cancel your appointment
				due to our own scheduling conflicts.
			</p>
			<p class="mb-3">
				Please note that in accordance with UK statutory exclusions for distance contracts, the
				standard 14-day statutory cancellation "cooling-off" period under the Consumer Contracts
				Regulations 2013 does not apply to online bookings scheduled for a specific date or time.
			</p>
			<p class="mb-3">
				We recognize that genuine emergencies, sudden severe illness, or bereavement can occur. Our
				management team retains complete administrative system access to waive cancellation fees,
				refund deposits, or clear no-show history strikes on a case-by-case basis under exceptional
				circumstances.
			</p>
		</section>

		<!-- Section 6 -->
		<section>
			<h2 class="mb-3 text-base font-semibold text-gray-900">6. Policy Amendments and Updates</h2>
			<p class="mb-3">
				We reserve the right to amend, update, or modify this Booking, Deposit & Cancellation Policy
				at any time to reflect changes in our business operations, system features, or legal
				obligations under UK and Scottish law.
			</p>
			<p class="mb-3">
				Any updates will be published directly to this page, and the "Last updated" date at the top
				will change accordingly. For active bookings scheduled prior to an amendment, the terms in
				place at the exact time your booking was created will apply. Continued use of our booking
				system after a policy revision implies formal agreement to the updated terms.
			</p>
		</section>

		<!-- Section 7 -->
		<section class="border-t border-gray-200 pt-6">
			<h2 class="mb-2 text-base font-semibold text-gray-900">7. Governing Law</h2>
			<p class="mb-4">
				These terms and conditions are governed by and construed in accordance with the laws of
				Scotland. Any disputes or legal claims arising from these provisions shall be subject to the
				exclusive jurisdiction of the Scottish courts.
			</p>
			<p class="text-xs text-gray-500">
				If you need to request an adjustment due to exceptional circumstances or have questions
				regarding your upcoming appointments, please use our official <a
					href={resolve('/contact')}
					class="font-medium text-blue-600 underline hover:text-blue-800">Contact Channels</a
				> to get in touch.
			</p>
		</section>
	</div>
</div>
