<!DOCTYPE html>
<html lang="sv" ng-app="mealMenuApp">
<head>
  <meta charset="utf-8" />
  <title>Veckomeny</title>

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular-sanitize.js"></script>
  <script src="~/js/menu.js"></script>

  <link rel="stylesheet" href="~/css/menu.css" />
</head>
<body ng-controller="MealMenuController">
  <div class="meal-menu-page">
    <div class="menu-header">
      <h1>Veckomeny</h1>
      <div class="top-buttons">
        <button id="toggle-view" class="toggle-view-btn" ng-click="toggleView()" title="Byt vy">🗒️</button>
        <button id="toggle-theme" class="theme-toggle-btn" title="Byt tema">🌙</button>
      </div>
    </div>

    <div class="date-picker">
      <button ng-click="goToPreviousWeek()">← Föregående vecka</button>
      <span>Vecka {{selectedWeek}} – {{selectedYear}}</span>
      <button ng-click="goToNextWeek()">Nästa vecka →</button>
    </div>

    <div ng-switch="viewMode">
      <div ng-switch-when="list" class="list-view">
        <div ng-repeat="day in daysOfWeek" class="day-item">
          <div class="day-header">{{day}}</div>
          <div class="meal-info" ng-if="menu[day]">
            <div ng-if="menu[day].breakfastMealId" class="meal-selection">
              <a href="/Meal/View/{{menu[day].breakfastMealId}}"><strong>Frukost:</strong> {{menu[day].breakfastMealName}}</a>
            </div>
            <div ng-if="menu[day].lunchMealId" class="meal-selection">
              <a href="/Meal/View/{{menu[day].lunchMealId}}"><strong>Lunch:</strong> {{menu[day].lunchMealName}}</a>
            </div>
            <div ng-if="menu[day].dinnerMealId" class="meal-selection">
              <a href="/Meal/View/{{menu[day].dinnerMealId}}"><strong>Middag:</strong> {{menu[day].dinnerMealName}}</a>
            </div>
          </div>
          <div ng-if="!menu[day]">
            <span class="not-assigned">Inte bestämd</span>
          </div>
        </div>
      </div>

    <div ng-switch-when="card" class="card-view">
        <div class="card-container">
        <div ng-repeat="day in daysOfWeek"
                class="meal-card"
                ng-attr-data-has-image="{{getDayImage(day) ? 'true' : 'false'}}"
                ng-style="getDayImage(day) ? {'background-image': 'url(' + getDayImage(day) + ')'} : {}"
                ng-click="openMeal(getMealIdByDay(day))">
            <div class="card-content">
            <div class="day">{{day}}</div>
            <div class="meal" ng-if="menu[day].dinnerMealName">Middag: {{menu[day].dinnerMealName}}</div>
            <div class="meal" ng-if="menu[day].lunchMealName">Lunch: {{menu[day].lunchMealName}}</div>
            <div class="meal" ng-if="menu[day].breakfastMealName">Frukost: {{menu[day].breakfastMealName}}</div>
            <div class="meal" ng-if="menu[day] && !menu[day].breakfastMealName && !menu[day].lunchMealName && !menu[day].dinnerMealName">Inte bestämd</div>
            </div>
        </div>
        </div>
    </div>


      <div class="school-meals card-view">
        <h2>Skolmat</h2>


        <div ng-repeat="school in schoolMealsBySchool">
          <div class="school-meal-title" ng-click="toggleSchoolExpanded(school)">
            <span class="chevron" ng-class="{ rotated: school.expanded }">&#x25BC;</span>
            {{ school.name }}
          </div>

          <div class="card-container" ng-show="school.expanded">
            <div class="meal-card" ng-repeat="day in school.days">           
              <div class="card-content school-meal-card-content">
                <div class="day">{{ day.weekday }}</div>
                <div class="meal" ng-repeat="meal in day.courses">{{ meal }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>

            <!-- Floating button för att öppna popup -->
            <button class="floating-btn" ng-click="toggleWishFlyout()" ng-if="isLoggedIn">+</button>
            <!-- Popup för önskad rätt -->
            <div class="wish-flyout" ng-show="showWishFlyout">
                <form ng-submit="submitWish()">
                    <h3>Önska mat</h3>
                    <label for="wishName">Namn</label>
                    <input type="text"
                           ng-model="newWishName"
                           placeholder="Skriv eller sök rätt"
                           ng-change="checkExistingMeal()"
                           autocomplete="off">

                    <!-- Autocomplete-lista -->
                    <ul class="autocomplete-list" ng-if="existingMeals.length > 0">
                        <li ng-repeat="meal in existingMeals" ng-click="selectExistingMeal(meal)">
                            {{ meal.Name }}
                        </li>
                    </ul>

                    <!-- Receptfält visas bara om ingen befintlig rätt hittas -->
                    <textarea ng-if="showRecipeField" ng-model="newWishRecipe" placeholder="Skriv recept"></textarea>

                    <button type="submit">Skicka önskan</button>
                </form>
            </div>

</div>
</body>
</html>
