Untitled

mail@pastecode.io avatar
unknown
html
a year ago
7.9 kB
0
Indexable
Never
<!DOCTYPE html>
<html>
<head>
    <title>Dinner Decider</title>
    <style>
        body {
            background-color: #252525;
            color: #ffffff;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
        }

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

        h1 {
            color: #ffffff;
            text-align: center;
            font-size: 42px;
            margin-bottom: 10px;
        }

        .subtitle {
            color: #ff0000;
            text-align: center;
            font-size: 22px;
            text-transform: uppercase;
            margin-bottom: 30px;
        }

        form {
            display: flex;
            flex-direction: column;
        }

        label {
            margin-top: 10px;
            font-size: 18px;
        }

        input[type="text"] {
            padding: 10px;
            margin-bottom: 10px;
            border: none;
            border-radius: 5px;
            background-color: #f1f1f1;
            color: #000000;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }

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

        button {
            padding: 10px 20px;
            background-color: #ff0000;
            color: #ffffff;
            border: none;
            border-radius: 5px;
            font-size: 18px;
            cursor: pointer;
            margin-top: 20px;
            transition: background-color 0.3s ease 2s;
        }

        button:hover {
            background-color: #cc0000;
        }

        hr {
            border: none;
            border-top: 2px solid #ff0000;
            margin-top: 40px;
        }

        .dropdown {
            position: relative;
            display: inline-block;
            margin-bottom: 20px;
        }

        .dropdown-content {
            display: none;
            position: absolute;
            background-color: #f9f9f9;
            min-width: 160px;
            box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
            z-index: 1;
            padding: 10px;
            border-radius: 5px;
            transition: opacity 0.3s ease 2s;
        }

        .dropdown:hover .dropdown-content {
            display: block;
        }

        .dropdown-content a {
            color: #000000;
            padding: 5px 10px;
            display: block;
            text-decoration: none;
            cursor: pointer;
        }

        .dropdown-content a:hover {
            background-color: #e0e0e0;
        }

        .filter-button {
            padding: 10px 20px;
            background-color: #ff0000;
            color: #ffffff;
            border: none;
            border-radius: 5px;
            font-size: 18px;
            cursor: pointer;
            margin-top: 20px;
            transition: background-color 0.3s ease 2s;
        }

        .selected-filter {
            display: inline-block;
            background-color: #ff0000;
            color: #ffffff;
            padding: 10px 20px;
            margin-right: 5px;
            border-radius: 5px;
            cursor: pointer;
            position: relative;
            transition: background-color 0.3s ease;
        }

        .selected-filter:hover::after {
            content: "x";
            position: absolute;
            top: 0;
            right: 0;
            padding: 2px;
            background-color: #ff0000;
            color: #ffffff;
            border-radius: 50%;
            font-size: 12px;
        }

        .restaurant-info {
            margin-top: 20px;
            font-size: 18px;
            background-color: #ff0000;
            padding: 10px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Dinner Decider</h1>
        <p class="subtitle">We can decide for you!</p>
        <hr>
        <form id="searchForm">
            <label for="zipCode">Zip Code:</label>
            <input type="text" id="zipCode" name="zipCode" placeholder="Enter zip code" required>
            
            <div class="dropdown">
                <button class="filter-button">Filter</button>
                <div class="dropdown-content">
                    <a href="#" onclick="addFilter('Fast Food')">Fast Food</a>
                    <a href="#" onclick="addFilter('Dine in')">Dine in</a>
                    <a href="#" onclick="addFilter('Movie Dine')">Movie Dine</a>
                    <a href="#" onclick="addFilter('Bar Food')">Bar Food</a>
                    <a href="#" onclick="addFilter('Activity and Food')">Activity and Food</a>
                </div>
            </div>
            
            <div id="selectedFilters"></div>

            <button type="submit">Search</button>

            <div id="restaurantInfo" class="restaurant-info"></div>
        </form>
    </div>

    <script>
        
        const apiKey = 'AIzaSyBPmuilKhkeG_ZQWdBNHZEnD4QcER3bKMk';

const selectedFiltersContainer = document.getElementById('selectedFilters');
const restaurantInfoContainer = document.getElementById('restaurantInfo');

function addFilter(filter) {
  const filterButton = document.createElement('button');
  filterButton.className = 'selected-filter';
  filterButton.textContent = filter;
  filterButton.addEventListener('click', function() {
    filterButton.remove();
  });
  selectedFiltersContainer.appendChild(filterButton);

  const filterDropdown = document.querySelector('.dropdown-content');
  filterDropdown.style.marginRight = `${selectedFiltersContainer.offsetWidth + 10}px`;
}

function displayRestaurantInfo(name, address, type) {
  restaurantInfoContainer.innerHTML = `
    <h2>${name}</h2>
    <p><strong>Address:</strong> ${address}</p>
    <p><strong>Type of Food:</strong> ${type}</p>
  `;
}

document.getElementById('searchForm').addEventListener('submit', function(event) {
  event.preventDefault();

  const zipCode = document.getElementById('zipCode').value;

  const apiUrl = `https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${zipCode}&key=${apiKey}`;
  const url = `https://cors-anywhere.herokuapp.com/${apiUrl}`;

  // Make API request using 'url' and handle the response data as needed
  fetch(url)
    .then(response => response.json())
    .then(data => {
      const results = data.results;
      if (results.length > 0) {
        const filteredResults = applyFilters(results);
        if (filteredResults.length > 0) {
          const randomIndex = Math.floor(Math.random() * filteredResults.length);
          const restaurant = filteredResults[randomIndex];
          const name = restaurant.name;
          const address = restaurant.vicinity;
        
          displayRestaurantInfo(name, address, types);
        } else {
          displayRestaurantInfo('No Results', '', '', '');
        }
      } else {
        displayRestaurantInfo('No Results', '', '', '');
      }
    })
    .catch(error => {
      console.error(error);
      displayRestaurantInfo('Error', '', '', '');
    });
});

function applyFilters(results) {
  const selectedFilters = Array.from(selectedFiltersContainer.getElementsByClassName('selected-filter'));
  const filters = selectedFilters.map(filter => filter.textContent);

  const filteredResults = results.filter(restaurant => {
    const types = restaurant.types;
    return filters.every(filter => types.includes(filter));
  });

  return filteredResults;
}

    </script>
</body>
</html>