<script lang="ts">
import { m } from '$lib/paraglide/messages.js';

type Props = {
	currentPage: number;
	totalPages: number;
	isLoaded: boolean;
	showAnnotations: boolean;
	annotationCount: number;
	onPrev: () => void;
	onNext: () => void;
	onZoomIn: () => void;
	onZoomOut: () => void;
	onToggleAnnotations: () => void;
};

let {
	currentPage,
	totalPages,
	isLoaded,
	showAnnotations,
	annotationCount,
	onPrev,
	onNext,
	onZoomIn,
	onZoomOut,
	onToggleAnnotations
}: Props = $props();
</script>

<div class="flex shrink-0 items-center justify-between gap-2 border-b border-pdf-ctrl px-4 py-2">
	<!-- Page navigation: prev button, page counter, next button -->
	<div class="flex items-center gap-2">
		<button
			onclick={onPrev}
			disabled={currentPage <= 1}
			aria-label="Zurück"
			class="min-h-[44px] min-w-[44px] rounded p-2 text-ink-3 transition hover:bg-surface/10 focus-visible:ring-2 focus-visible:ring-brand-navy focus-visible:ring-offset-1 disabled:opacity-40"
		>
			<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
				<path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" />
			</svg>
		</button>

		{#if totalPages > 0}
			<span class="font-sans text-xs text-ink-2 tabular-nums">
				{currentPage} / {totalPages}
			</span>
		{/if}

		<button
			onclick={onNext}
			disabled={!isLoaded || currentPage >= totalPages}
			aria-label="Weiter"
			class="min-h-[44px] min-w-[44px] rounded p-2 text-ink-3 transition hover:bg-surface/10 focus-visible:ring-2 focus-visible:ring-brand-navy focus-visible:ring-offset-1 disabled:opacity-40"
		>
			<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
				<path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" />
			</svg>
		</button>
	</div>

	<!-- Zoom controls -->
	<div class="flex items-center gap-1">
		<button
			onclick={onZoomOut}
			aria-label="Verkleinern"
			class="min-h-[44px] min-w-[44px] rounded p-2 text-ink-3 transition hover:bg-surface/10 focus-visible:ring-2 focus-visible:ring-brand-navy focus-visible:ring-offset-1"
		>
			<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
				<circle cx="11" cy="11" r="8" />
				<path stroke-linecap="round" d="M21 21l-4.35-4.35M8 11h6" />
			</svg>
		</button>
		<button
			onclick={onZoomIn}
			aria-label="Vergrößern"
			class="min-h-[44px] min-w-[44px] rounded p-2 text-ink-3 transition hover:bg-surface/10 focus-visible:ring-2 focus-visible:ring-brand-navy focus-visible:ring-offset-1"
		>
			<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
				<circle cx="11" cy="11" r="8" />
				<path stroke-linecap="round" d="M21 21l-4.35-4.35M11 8v6M8 11h6" />
			</svg>
		</button>
	</div>

	<!-- Annotation visibility toggle (only when annotations exist) -->
	{#if annotationCount > 0}
		<button
			onclick={onToggleAnnotations}
			aria-label={showAnnotations ? m.pdf_annotations_hide() : m.pdf_annotations_show()}
			aria-pressed={showAnnotations}
			class="flex min-h-[44px] min-w-[44px] items-center gap-1.5 rounded px-3 py-2 font-sans text-xs transition focus-visible:ring-2 focus-visible:ring-brand-navy focus-visible:ring-offset-1 {showAnnotations
				? 'text-ink-2 hover:bg-surface/10'
				: 'bg-surface/10 text-primary'}"
		>
			<svg
				class="h-3.5 w-3.5 shrink-0"
				viewBox="0 0 24 24"
				fill="none"
				stroke="currentColor"
				stroke-width="2"
			>
				{#if showAnnotations}
					<path
						stroke-linecap="round"
						stroke-linejoin="round"
						d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
					/>
					<path
						stroke-linecap="round"
						stroke-linejoin="round"
						d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
					/>
				{:else}
					<path
						stroke-linecap="round"
						stroke-linejoin="round"
						d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"
					/>
				{/if}
			</svg>
			{showAnnotations ? m.pdf_annotations_hide() : m.pdf_annotations_show()}
		</button>
	{/if}
</div>
