<script setup lang="ts" name="MenuCard">
import { ref, onMounted, computed } from 'vue'
import noMenu from '@/static/image/noMenu.png'
const props = defineProps<{
  item: any,
  displayIndex:number,
  openIndex:number
}>()

const emit = defineEmits<{
  'page-week-menu': [item: any],
  'change-open-index':[index:number]
}>()

const displayYindex = ref(0)
function displayDay(val:number) {
  emit('change-open-index', props.displayIndex)
  displayYindex.value = val
}

function pageWeekMenu() {
  emit('page-week-menu', props.item)
}
const isFold = computed(() => {
  return props.displayIndex !== props.openIndex
})
</script>

<template>
  <div class="supply-card-container" :class="{ 'is-fold': isFold }">
    <div class="title flex-container justify-container">
      <span>
        {{ props.item.menuName}}
      </span>
      <span class="blue-text" @click="pageWeekMenu">一周食谱</span>
    </div>
    <van-divider />
    <div class="flex-container justify-container">
      <div
        v-for="(xitem,yindex) in props.item.detailList"
        :key="yindex"
        class="flex-container day-item"
        :class="[displayYindex === yindex && props.displayIndex === props.openIndex ? 'active-day-item' : '',
                 props.item.detailList[displayYindex].specificList.length === 0 && displayYindex === yindex && props.displayIndex === props.openIndex ? 'activenomenu-day-item' : ''
        ]"
        @click.stop="displayDay(yindex)">
        <div class="menuWeek">
          {{xitem.menuWeek}}
        </div>
        <div class="text">
          {{xitem.menuTime.split('-')[xitem.menuTime.split('-').length - 1]}}
        </div>
      </div>
    </div>
    <div v-if="props.displayIndex === props.openIndex">
      <van-divider />
      <div v-if="props.item.detailList[displayYindex].specificList.length > 0">
        <div class="flex-container meal-item meal-breakfast">
          <div class="label">早餐：</div>
          <div class="value">
            {{ props.item.detailList[displayYindex].specificList[0].menuBreakfast }}
          </div>
        </div>
        <div class="flex-container meal-item meal-lunch">
          <div class="label">午餐：</div>
          <div class="value">
            {{ props.item.detailList[displayYindex].specificList[0].menuLunch }}
          </div>
        </div>
        <div class="flex-container meal-item meal-dinner">
          <div class="label">晚餐：</div>
          <div class="value">
            {{ props.item.detailList[displayYindex].specificList[0].menuDinner }}
          </div>
        </div>
      </div>
      <div v-else class="no-menu-container">
        <img style="height: 16rem;width: 16rem;" :src="noMenu" alt="">
        <div class="no-menu-text">暂无食谱</div>
      </div>


    </div>
  </div>
</template>

<style lang="less" scoped>
  .supply-card-container {
    position: relative;
    padding: 0.9rem 0.8rem 1.9rem 0.8rem;
    background-color: #fff;
    overflow: hidden;
    border-radius: 24rpx;
    box-shadow: 0 4rpx 40rpx  rgba(64, 103, 251, 0.14);
    transition: all 0.3s ease;
    .title{
      padding: 0.5rem;
      padding-bottom: 0;
      .blue-text{
        color: rgba(55, 108, 220, 1);
      }
    }
    .flex-center {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .theader {
      color: #333;
      font-size: 1.3rem;
    }
    .shadow {
      position: absolute;
      bottom: 0;
      left: 0;
      padding-bottom: 0.5rem;
      width: 100%;
      background: linear-gradient(to top, rgba(255, 255, 255, 1) 0, rgba(255, 255, 255, 1) 2.6rem, transparent 2.6rem, rgba(255, 255, 255, 0) 100%);
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      align-items: center;
      font-size: 1.3rem;
      color: var(--van-primary-color);
    }
  }
  .is-fold {
    transition: all 0.3s;
    .shadow {
      height: 2.5rem;
    }
  }
  .flex-container {
    display: flex;
    align-items: center;
  }
  .justify-container {
    justify-content: space-between;
  }
  .day-item {
    flex-direction: column;
    align-items: center;
    padding: 1rem 1.2rem;
    .menuWeek {
      font-size: 1rem;
      color: rgba(37, 37, 37, 1);
    }

    .text {
      margin-top: 1rem;
      font-size: 1.2rem;
      color: rgba(37, 37, 37, 1);
    }
  }
  .active-day-item {
    border-radius: 9px;
    background: rgba(79, 129, 240, 1);
    box-shadow: 3px 5px 10px  rgba(79, 129, 240, 0.35);
    padding: 1rem 1.2rem;
    .menuWeek {
      font-size: 1rem;
      color: #fff;
    }
    .text {
      margin-top: 1rem;
      font-size: 1.2rem;
      color: #fff;
    }
  }
  .activenomenu-day-item {
    border-radius: 9px;
    background: rgba(197, 198, 201, 1);
    box-shadow: 3px 5px 10px  rgba(137, 137, 137, 0.35);
    padding: 1rem 1.2rem;
    .menuWeek {
      font-size: 1rem;
      color: #fff;
    }
    .text {
      margin-top: 1rem;
      font-size: 1.2rem;
      color: #fff;
    }
  }
  .meal-item{
    margin-top: 0.8rem;
    padding: 0.4rem 0;
    &:first-child{
      margin-top: 0;
    }
  }
  .meal-breakfast {
    position: relative;
    &::after{
      position: absolute;
      display: inline;
      content: '';
      width: 3.5rem;
      height:0.5rem;
      background-color: rgba(255, 105, 105, 0.4);
      bottom: 0.5rem;
    }
  }
  .meal-lunch {
    position: relative;
    &::after{
      position: absolute;
      display: inline;
      content: '';
      width: 3.5rem;
      height:0.5rem;
      background-color: rgba(71, 115, 252, 0.4);
      bottom: 0.5rem;
    }
  }
  .meal-dinner {
    position: relative;
    &::after{
      position: absolute;
      display: inline;
      content: '';
      width: 3.5rem;
      height:0.5rem;
      background-color: rgba(180, 255, 105, 0.4);
      bottom: 0.5rem;
    }
  }
  .no-menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    .no-menu-text {
      margin-top: -5rem;
      font-size: 1.2rem;
      color: rgba(71, 115, 252, 1);
    }
  }
</style>
