← back to Wine Finder

public/test.html

247 lines

<!DOCTYPE html>
<html>
<head>
<style>
body {
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  background: #0a0a0a;
  color: #ffffff;
  min-height: 100vh;
}

.header {
  background: #111111;
  padding: 20px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.header h1 {
  margin: 0;
  font-size: 32px;
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.container {
  max-width: 1200px;
  margin: 40px auto;
  padding: 0 20px;
}

.card {
  background: #111111;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 32px;
  margin-bottom: 20px;
}

.search-box {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.search-input {
  flex: 1;
  padding: 14px 20px;
  background: #151515;
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: #ffffff;
  font-size: 16px;
}

.search-input:focus {
  outline: none;
  border-color: #ec4899;
}

.btn {
  padding: 14px 32px;
  background: linear-gradient(135deg, #ec4899, #db2777);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
}

.btn:hover {
  transform: translateY(-2px);
}

.quick-search {
  margin-top: 20px;
  text-align: center;
}

.quick-search-label {
  font-size: 14px;
  color: #999;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.quick-btn {
  padding: 10px 24px;
  margin: 0 6px;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.quick-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}

#results {
  display: none;
}

.wine-item {
  background: #151515;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 12px;
}

.wine-name {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.wine-price {
  font-size: 24px;
  font-weight: 700;
  color: #ec4899;
}
</style>
</head>
<body>
<div class="header">
  <h1>🍷 Red Thunder Wine Tracker</h1>
  <p style="margin: 5px 0 0 0; color: #666; font-size: 12px; letter-spacing: 2px;">PREMIUM WINE INTELLIGENCE</p>
</div>

<div class="container">
  <div class="card">
    <h2 style="margin: 0 0 20px 0; font-size: 24px;">Search Wines</h2>
    <div class="search-box">
      <input type="text" id="search" class="search-input" placeholder="Enter wine name or winery...">
      <button class="btn" onclick="searchWines()">Search</button>
    </div>
    <div class="quick-search">
      <p class="quick-search-label">Quick Search</p>
      <button class="quick-btn" onclick="quickSearch('foxen')">Foxen</button>
      <button class="quick-btn" onclick="quickSearch('navarro')">Navarro</button>
      <button class="quick-btn" onclick="quickSearch('cabernet')">Cabernet</button>
      <button class="quick-btn" onclick="quickSearch('pinot')">Pinot Noir</button>
    </div>
  </div>

  <div class="card" id="results">
    <h2 style="margin: 0 0 20px 0; font-size: 24px;">Results</h2>
    <div id="wineList"></div>
  </div>
</div>

<script>
// Auto-login on page load
async function autoLogin() {
  try {
    await fetch('/auth/login', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ username: 'admin', password: '2025' }),
      credentials: 'include'
    });
    console.log('Auto-login completed');
  } catch (e) {
    console.log('Auto-login error:', e);
  }
}

async function searchWines() {
  const query = document.getElementById('search').value;
  console.log('searchWines called with query:', query);

  if (!query) {
    alert('Please enter a search term');
    return;
  }

  // Show loading
  document.getElementById('wineList').innerHTML = '<div style="text-align: center; padding: 40px; color: #999;">🔍 Searching for "' + query + '"...</div>';
  document.getElementById('results').style.display = 'block';

  try {
    // Ensure we're logged in
    console.log('Logging in...');
    await autoLogin();
    console.log('Login complete, now searching...');

    const response = await fetch('/api/scraper/search', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ query }),
      credentials: 'include'
    });

    console.log('Response status:', response.status);
    const data = await response.json();
    console.log('Search response:', data);
    console.log('Wines found:', data.wines ? data.wines.length : 0);

    if (data.success && data.wines && data.wines.length > 0) {
      const html = data.wines.map(wine => `
        <div class="wine-item">
          <div class="wine-name">${wine.name}</div>
          <div class="wine-price">$${wine.price.toFixed(2)}</div>
          <div style="margin-top: 8px; font-size: 14px; color: #999;">
            ${wine.vintage} • ${wine.rating} pts • ${wine.availability}
          </div>
        </div>
      `).join('');
      document.getElementById('wineList').innerHTML = html;
      console.log('Displayed', data.wines.length, 'wines');
    } else {
      document.getElementById('wineList').innerHTML = '<div style="text-align: center; padding: 40px; color: #999;">No wines found. Try "cabernet" or "pinot"</div>';
    }
  } catch (error) {
    console.error('Search error:', error);
    document.getElementById('wineList').innerHTML = '<div style="text-align: center; padding: 40px; color: #ef4444;">❌ Search failed: ' + error.message + '<br><br>Check console (F12) for details</div>';
  }
}

// Quick search function
function quickSearch(query) {
  document.getElementById('search').value = query;
  searchWines();
}

// Auto-login when page loads
autoLogin();

document.getElementById('search').addEventListener('keypress', (e) => {
  if (e.key === 'Enter') searchWines();
});
</script>
</body>
</html>