<script setup>
import Button from 'primevue/button';
import { usePlantStateStore} from "@/stores/plantState.js";
import { watchEffect } from 'vue';
import Card from 'primevue/card';
import ProgressSpinner from 'primevue/progressspinner';

const plantStateStore = usePlantStateStore();

watchEffect(() => {
  document.documentElement.style.setProperty('--background-image', 'url(' + plantStateStore.imageBase64 + ')');
});

import { onMounted, ref } from 'vue';
onMounted(() => {
  loadHealthCheck();
});

const isLoading = ref(true);

function loadHealthCheck() {
  plantStateStore.healthCheck().finally(() => {
    isLoading.value = false;
  });
}
</script>

<template>
  <div class="row">
    <div class="card">
      <div class="content">
        <h1>Here's how your plant is feeling today</h1>
      </div>
    </div>
    <Card v-if="!isLoading">
      <template #title>
        <h3>Recognized plant: {{ plantStateStore.plantData.plant_characteristics.morphological.plant_type }}</h3>
      </template>
      <template #subtitle>
        <h4>{{ plantStateStore.health.health_status }}</h4>
      </template>
      <template #content>
        <ul>
          <li>Healthy: {{ plantStateStore.health.health_breakdown.Healthy }}% </li>
          <li>Dying: {{ plantStateStore.health.health_breakdown.Dead }}% </li>
          <li>Diseased: {{ plantStateStore.health.health_breakdown.Diseased }}% </li>
          <li>Dehydrated : {{ plantStateStore.health.health_breakdown.Dehydrated }}% </li>
        </ul>
      </template>
  </Card>
    <ProgressSpinner v-else></ProgressSpinner>

  </div>
  <div class="under">
    <Button icon="pi pi-arrow-right" label="Continue" aria-label="Home" @click="$router.push('/simulate')"> </Button>
  </div>
</template>

<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Playwrite+HU:wght@100..400&family=Roboto+Flex:opsz,wght@8..144,100..1000&family=Rubik:ital,wght@0,300..900;1,300..900&display=swap');

.row {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

:deep(.p-card) {
  width: 100%;
  max-width: 35rem;
  margin: 0 auto;
}

li {
  margin-bottom: 0.7rem;
  margin-left: 1rem;
  font-size: 110%;
}

.card {
  position: relative;
  width: 100%;
  max-width: 35rem;
  height: 40rem;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: var(--background-image);
  background-size: cover;
  background-position: center;
}

.card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.9) 0%,
    rgba(0, 0, 0, 0.7) 30%,
    rgba(0, 0, 0, 0.4) 70%,
    rgba(0, 0, 0, 0.2) 100%
  );
}

.content {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 2rem;
  color: white;
}

h1 {
  font-family: 'Playwrite HU', sans-serif;
  font-size: 2.5rem;
  margin-bottom: 1rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.under {
  display: flex;
  justify-content: stretch;
  gap: 1rem;
  margin-top: 2rem;
  width: 100%;
}

:deep(.p-button) {
  flex-grow: 1;
}

:deep(.p-button-label) {
  font-weight: bold;
}
</style>
