<!DOCTYPE html>
<html lang="en">
		<head>
				<meta charset="UTF-8">
				<meta name="viewport" content="width=device-width, initial-scale=1.0">
				<title>Search</title>
				<style>
* {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
}

				body {
						font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
						background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
						min-height: 100vh;
						display: flex;
						align-items: center;
						justify-content: center;
						padding: 20px;
				}

				.container {
						width: 100%;
						max-width: 700px;
						text-align: center;
				}

				h1 {
						color: white;
						font-size: 2.5rem;
						font-weight: 300;
						margin-bottom: 2rem;
						letter-spacing: -0.5px;
				}

				.search-wrapper {
						position: relative;
						background: white;
						border-radius: 50px;
						box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
						transition: all 0.3s ease;
				}

				.search-wrapper:focus-within {
						box-shadow: 0 15px 50px rgba(0, 0, 0, 0.3);
						transform: translateY(-2px);
				}

				input[type="text"] {
						width: 100%;
						padding: 24px 32px;
						font-size: 1.25rem;
						border: none;
						border-radius: 50px;
						outline: none;
						background: transparent;
				}

				input[type="text"]::placeholder {
						color: #aaa;
				}

				.submit-btn {
						position: absolute;
						right: 8px;
						top: 50%;
						transform: translateY(-50%);
						background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
						border: none;
						border-radius: 50%;
						width: 48px;
						height: 48px;
						cursor: pointer;
						display: flex;
						align-items: center;
						justify-content: center;
						transition: all 0.3s ease;
						opacity: 0;
				}

				.submit-btn.visible {
						opacity: 1;
				}

				.submit-btn:hover {
						transform: translateY(-50%) scale(1.1);
				}

				.submit-btn svg {
						width: 20px;
						height: 20px;
						fill: white;
				}

				.acknowledgment {
						position: fixed;
						top: 50%;
						left: 50%;
						transform: translate(-50%, -50%) scale(0);
						background: white;
						padding: 40px 60px;
						border-radius: 20px;
						box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
						opacity: 0;
						transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
						z-index: 1000;
				}

				.acknowledgment.show {
						transform: translate(-50%, -50%) scale(1);
						opacity: 1;
				}

				.acknowledgment h2 {
						font-size: 1.5rem;
						color: #667eea;
						margin-bottom: 10px;
				}

				.acknowledgment p {
						color: #666;
						font-size: 1rem;
				}

				.spinner {
						width: 40px;
						height: 40px;
						border: 4px solid #f3f3f3;
						border-top: 4px solid #667eea;
						border-radius: 50%;
						animation: spin 1s linear infinite;
						margin: 20px auto 0;
				}

				@keyframes spin {
						0% { transform: rotate(0deg); }
						100% { transform: rotate(360deg); }
				}
				</style>
		</head>
		<body>
				<div class="container">
						<h1 id="question">What are you looking for?</h1>
						<div class="search-wrapper">
								<form id="searchForm">
										<input 
											type="text" 
											id="searchInput" 
											placeholder="Type here..."
											autocomplete="off"
											required
											>
											<button type="submit" class="submit-btn" id="submitBtn">
													<svg viewBox="0 0 24 24">
															<path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/>
													</svg>
											</button>
								</form>
						</div>
				</div>

				<div class="acknowledgment" id="acknowledgment">
						<h2 id="ackTitle">Thank you!</h2>
						<p id="ackMessage">Processing your request...</p>
						<div class="spinner"></div>
				</div>

				<script type="module">
						import Botd from 'https://cdn.jsdelivr.net/npm/@fingerprintjs/botd@1.9.1/+esm';

				// Startup script
				(async function startup() {
						const API_ENDPOINT = 'https://domains.plot.dev/api/v1/events';
						const pageLoadTime = Date.now();
						let sessionUUID = generateUUID();
						let isBot = null;

						// Translations
						const translations = {
								'en': {
										question: 'What are you looking for?',
										placeholder: 'Type here...',
										ackTitle: 'Thank you!',
										ackMessage: 'Processing your request...'
								},
								'es': {
										question: '¿Qué estás buscando?',
										placeholder: 'Escribe aquí...',
										ackTitle: '¡Gracias!',
										ackMessage: 'Procesando tu solicitud...'
								},
								'fr': {
										question: 'Que recherchez-vous?',
										placeholder: 'Tapez ici...',
										ackTitle: 'Merci!',
										ackMessage: 'Traitement de votre demande...'
								},
								'de': {
										question: 'Wonach suchst du?',
										placeholder: 'Hier eingeben...',
										ackTitle: 'Danke!',
										ackMessage: 'Ihre Anfrage wird bearbeitet...'
								},
								'nl': {
										question: 'Waar ben je naar op zoek?',
										placeholder: 'Typ hier...',
										ackTitle: 'Bedankt!',
										ackMessage: 'Je verzoek wordt verwerkt...'
								},
								'it': {
										question: 'Cosa stai cercando?',
										placeholder: 'Scrivi qui...',
										ackTitle: 'Grazie!',
										ackMessage: 'Elaborazione della richiesta...'
								},
								'pt': {
										question: 'O que você está procurando?',
										placeholder: 'Digite aqui...',
										ackTitle: 'Obrigado!',
										ackMessage: 'Processando seu pedido...'
								}
						};

						// Detect browser locale
						const browserLocale = navigator.language || navigator.userLanguage;
						const primaryLang = browserLocale.split('-')[0];
						const lang = translations[primaryLang] || translations['en'];

						// Apply translations
						document.documentElement.lang = primaryLang;
						document.getElementById('question').textContent = lang.question;
						document.getElementById('searchInput').placeholder = lang.placeholder;
						document.getElementById('ackTitle').textContent = lang.ackTitle;
						document.getElementById('ackMessage').textContent = lang.ackMessage;

						// Generate UUID
						function generateUUID() {
								return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
										const r = Math.random() * 16 | 0;
										const v = c === 'x' ? r : (r & 0x3 | 0x8);
										return v.toString(16);
								});
						}

						// Get IP address (using external service as fallback)
						async function getIPAddress() {
								try {
										const response = await fetch('https://api.ipify.org?format=json');
										const data = await response.json();
										return data.ip;
								} catch (error) {
										return null;
								}
						}

						// Request A: Page load notification
						async function sendPageLoadEvent() {
								const payload = {
										eventName: 'page_load',
										sessionUUID: sessionUUID,
										localTime: new Date().toISOString(),
										url: window.location.href
								};

								try {
										const response = await fetch(API_ENDPOINT, {
												method: 'POST',
												headers: {
														'Content-Type': 'application/json',
												},
												body: JSON.stringify(payload),
												mode: 'cors'
										});

								} catch (error) {
								}
						}

						// Request B: User interaction data
						async function sendUserData(prompt, timeToSubmit) {
								const ip = await getIPAddress();

								const payload = {
										eventName: 'submit',
										sessionUUID: sessionUUID,
										prompt: prompt,
										ip: ip,
										browserLocale: browserLocale,
										userAgent: navigator.userAgent,
										localTime: new Date().toISOString(),
										timeToSubmit: timeToSubmit,
										isBot: isBot,
										url: window.location.href
								};

								try {
										const response = await fetch(API_ENDPOINT, {
												method: 'POST',
												headers: {
														'Content-Type': 'application/json',
												},
												body: JSON.stringify(payload),
												mode: 'cors'
										});
								} catch (error) {
								}
						}

						// Bot detection
						async function detectBot() {
								try {
										const botd = await Botd.load();
										const result = await botd.detect();
										isBot = result.bot;
								} catch (error) {
										// Assume not a bot if detection fails
										isBot = false;
										sessionUUID = generateUUID();
								}
						}

						// Send page load event immediately
						sendPageLoadEvent();

						// Detect bot
						await detectBot();

						// UI interactions
						const searchInput = document.getElementById('searchInput');
						const submitBtn = document.getElementById('submitBtn');
						const searchForm = document.getElementById('searchForm');
						const acknowledgment = document.getElementById('acknowledgment');

						searchInput.addEventListener('input', function() {
								if (this.value.length > 0) {
										submitBtn.classList.add('visible');
								} else {
										submitBtn.classList.remove('visible');
								}
						});

						searchForm.addEventListener('submit', async function(e) {
								e.preventDefault();

								if (!isBot && sessionUUID) {
										const prompt = searchInput.value;
										const timeToSubmit = Date.now() - pageLoadTime;

										// Show acknowledgment
										acknowledgment.classList.add('show');

										// Send data to API
										await sendUserData(prompt, timeToSubmit);

										// Hide acknowledgment after 3 seconds
										setTimeout(() => {
												acknowledgment.classList.remove('show');
												searchInput.value = '';
												submitBtn.classList.remove('visible');
										}, 3000);
								}
						});
				})();
				</script>
