<template>
  <NuxtLayout name="default">
    <div class="dashboard-container">
      <header class="dashboard-header">
        <div class="header-copy">
          <p class="section-kicker">Operations</p>
          <h1 class="font-display text-3xl font-bold tracking-tight text-m-text">
            Backup
          </h1>
          <p class="header-description">
            Centralisez la selection des dossiers, l'execution des scripts et le telechargement
            des fichiers depuis une seule vue.
          </p>
        </div>
      </header>
      <div class="dashboard-grid">
        <section class="grid-left" aria-label="Commandes de sauvegarde">
          <BackupButtonSee
            class="animate-fade-in-up backup-selector"
            style="animation-delay: 120ms"
            @select="selectedBackup = $event"
          />
          <BackupRun
            class="animate-fade-in-up"
            style="animation-delay: 180ms"
          />
        </section>

        <section class="grid-middle" aria-labelledby="backup-files-title">
          <div class="files-panel animate-fade-in-up" style="animation-delay: 240ms">
            <div class="files-panel-header">
              <div>
                <p class="section-kicker">Fichiers</p>
                <h2 id="backup-files-title" class="files-panel-title">
                  Historique des sauvegardes
                </h2>
              </div>
              <p class="files-panel-meta">
                {{ selectedBackup ? `Source ${selectedBackup}` : "En attente de selection" }}
              </p>
            </div>

            <BackupList
              class="backup-list-mobile"
              :folder="selectedBackup"
            />
          </div>
        </section>
      </div>
    </div>
  </NuxtLayout>
</template>

<script setup lang="ts">
import { ref } from "vue"
import BackupRun from "~/components/BackupRun.vue"

definePageMeta({ layout: false })

const selectedBackup = ref<string | null>(null)
</script>

<style scoped>
.dashboard-container {
  padding: 2rem 2.5rem;
}

.dashboard-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: 1.5rem;
  align-items: end;
  margin-bottom: 1.5rem;
}

.header-copy {
  min-width: 0;
}

.section-kicker {
  margin: 0 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgb(var(--m-accent));
}

.header-description {
  max-width: 62ch;
  margin-top: 0.9rem;
  color: rgb(var(--m-muted));
  line-height: 1.65;
}

.selection-card {
  padding: 1.25rem;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgb(var(--m-secondary)), rgb(var(--m-tertiary)));
}

.selection-label {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgb(var(--m-muted));
}

.selection-value {
  margin: 0.65rem 0 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: rgb(var(--m-text));
}

.selection-description {
  margin: 0.5rem 0 0;
  color: rgb(var(--m-muted));
  line-height: 1.6;
}

.intro-panel {
  position: relative;
  overflow: hidden;
  margin-bottom: 1.5rem;
  padding: 1.5rem;
  border-radius: 20px;
  background:
    radial-gradient(circle at top right, rgb(var(--m-accent) / 0.12), transparent 28%),
    linear-gradient(180deg, rgb(var(--m-secondary)), rgb(var(--m-secondary) / 0.82));
}

.intro-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgb(var(--m-accent) / 0.08);
  border-radius: inherit;
  pointer-events: none;
}

.intro-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 2.2vw, 2rem);
  font-weight: 700;
  line-height: 1.15;
  color: rgb(var(--m-text));
}

.intro-description {
  max-width: 68ch;
  margin: 0.85rem 0 0;
  color: rgb(var(--m-muted));
  line-height: 1.7;
}

.workflow-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.workflow-step {
  padding: 1rem;
  border: 1px solid rgb(var(--m-accent) / 0.08);
  border-radius: 16px;
  background: rgb(var(--m-bg) / 0.24);
  backdrop-filter: blur(4px);
}

.workflow-index {
  display: inline-block;
  margin-bottom: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  color: rgb(var(--m-accent));
}

.workflow-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: rgb(var(--m-text));
}

.workflow-text {
  margin: 0.45rem 0 0;
  color: rgb(var(--m-muted));
  line-height: 1.6;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.grid-left,
.grid-middle {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

.files-panel {
  padding: 1.25rem;
  border-radius: 20px;
  background: rgb(var(--m-secondary) / 0.4);
  border: 1px solid rgb(var(--m-accent) / 0.08);
}

.files-panel-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.files-panel-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: rgb(var(--m-text));
}

.files-panel-meta {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(var(--m-muted));
  text-align: right;
}

@media (max-width: 1180px) {
  .dashboard-header,
  .dashboard-grid,
  .workflow-grid {
    grid-template-columns: 1fr;
  }

  .files-panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .files-panel-meta {
    text-align: left;
  }
}

@media (max-width: 820px) {
  .dashboard-container {
    padding: 4.5rem 1.25rem 1.25rem;
  }

  .intro-panel,
  .selection-card,
  .files-panel {
    padding: 1rem;
  }

  .workflow-grid {
    margin-top: 1rem;
  }
}
</style>
