<template>
  <main class="flex flex-col items-stretch | w-full">
    <Header :title="page.content.title" />

    <DialogWrapper v-if="dialog.content" />

    <div class="kanban">
      <ProjectStep v-for="step in page.steps" :key="step" :step="step">
      </ProjectStep>
    </div>
  </main>
</template>

<script setup>
import ProjectStep from "../components/project/ProjectStep.vue";
import Header from "../components/project/Header.vue";
import DialogWrapper from "../components/project/DialogWrapper.vue";
import { usePageStore } from "../stores/page";
import { storeToRefs } from "pinia";
import { watch } from "vue";
import { useDialogStore } from "../stores/dialog";
import { useRoute } from "vue-router";

const { page } = storeToRefs(usePageStore());
const dialog = useDialogStore();

const route = useRoute();

if (route.query.dialog) {
  openDialog(route.query.dialog);
}

watch(
  () => route.query.dialog,
  (targetStepSlug) => {
    if (targetStepSlug) {
      const targetStep = page.value.steps.find(
        (step) => step.slug === targetStepSlug
      );
      dialog.content = targetStep;
    } else {
      dialog.content = null;
    }
  }
);

function openDialog(targetStepSlug) {
  const targetStep = page.value.steps.find(
    (step) => step.slug === targetStepSlug
  );
  dialog.content = targetStep;
}
</script>

<style scope>
/* Porject details */
.project-details textarea {
  resize: none;
  max-height: 5rem;
}
.project-details__filters button:first-of-type {
  margin-right: calc(var(--space-12) + 1px);
}
.project-details__filters button:first-of-type::after {
  content: "";
  width: 1px;
  height: 1.7rem;
  background-color: var(--color-black-20);
  position: absolute;
  right: calc(-0.75rem);
}

/* Masonry */
.masonry > * {
  margin-bottom: var(--space-16);
}
.masonry > *:only-child {
  column-span: all;
  transform: translateY(50%);
}
@media (min-width: 40rem) {
  .masonry {
    column-count: 2;
  }
}
@media (min-width: 65rem) {
  .masonry {
    column-count: 3;
  }
}
@media (min-width: 90rem) {
  .masonry {
    column-count: 4;
  }
}

/* Image */
.image {
  border-radius: var(--rounded-2xl);
  overflow: hidden;
  position: relative;
  cursor: pointer;
}
.image.has-description::after {
  content: "";
  display: inline-block;
  width: 1rem;
  height: 1rem;
  background: var(--icon-color, currentColor);
  mask-repeat: no-repeat;
  mask-position: center;
  mask-size: 1rem;
  mask-image: var(--icon-description);
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
}
.image[aria-selected="true"] {
  outline: 2px solid var(--color-focus-ring);
}
.image[aria-selected="true"]::after {
  content: attr(data-count);
  position: absolute;
  top: var(--space-12);
  right: var(--space-12);
  border-radius: 50%;
  color: var(--color-white);
  font-weight: 700;
  background: var(--color-grey-800);
  display: grid;
  place-items: center;
  text-align: center;
  width: 1.5rem;
  height: 1.5rem;
}
.image .tag {
  position: absolute;
  top: var(--space-12);
  left: var(--space-12);
}

/* Kanban */
.kanban {
  --header-height: 2.25rem; /* 36px */
  --header-bg-color: var(--color-grey-200);
  --header-title-bg-color: var(--color-grey-700);
  --gap: var(--gutter);
  position: relative;
  display: flex;
  gap: var(--gap);
  overflow-x: auto;
  margin: 0 calc(-1 * var(--gutter));
  padding: 0 var(--gutter);
  height: calc(100vh - var(--gutter) * 2 - var(--header-height) - 2.25rem);
}
</style>
