<template>
  <!-- TODO: dynamiser la valeur de l'attribut style: url('inspiration.cover') -->
  <div
    id="inspirations-dropdown"
    class="flex flex-col"
    :style="'--image: url(\'' + current.cover + '\');'"
  >
    <label for="inspirations-select" class="text-sm"
      >Choisir une inspiration</label
    >
    <Select
      id="inspirations-select"
      v-model="current"
      :options="all"
      optionLabel="title"
      class="font-serif"
      data-icon="chevron-single-down"
      checkmark
    />
  </div>
</template>

<script setup>
import { ref, watch } from "vue";

const { all } = defineProps({
  all: Array,
});

const current = ref(all[0]);

watch(current, (newValue) => {
  changeInspiration(newValue);
});

const emit = defineEmits(["update:currentInspiration"]);

function changeInspiration(inspiration) {
  emit("update:currentInspiration", inspiration);
}
</script>

<style>
#inspirations-dropdown {
  --row-gap: 0;
  align-items: flex-start;
  position: absolute;
  top: 0;
  right: 0;
  background: var(--color-background);
  border-radius: var(--rounded-lg);
  height: 3.75rem;
  width: 20rem;
  padding: var(--space-8) var(--space-48) var(--space-8) var(--space-64);
  margin-bottom: var(--space-16);
}
#inspirations-dropdown::before {
  content: "";
  position: absolute;
  left: var(--space-8);
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--rounded-md);
  background-image: var(--image);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

[role="combobox"],
#inspirations-select_list {
  border: 1px solid var(--color-grey-200);
}
[role="combobox"]:hover {
  outline: 1px solid var(--color-grey-400);
  border-color: var(--color-background);
}
[role="combobox"][aria-expanded="true"] {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: -2px;
  border-color: transparent;
}
#inspirations-select,
[role="combobox"] {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.875rem var(--space-48) var(--space-8) var(--space-64);
  cursor: pointer;
}

/* Icon */
#inspirations-select svg {
  display: none; /* Hide default component svg */
}
#inspirations-select[data-icon]::before {
  --icon-color: var(--color-grey-700);
  position: absolute;
  right: var(--space-8);
  top: 0.625rem;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0.625rem;
}
#inspirations-dropdown label {
  color: var(--color-grey-700);
  letter-spacing: var(--tracking-wider);
}

/* Options */
#inspirations-select_list {
  margin-top: var(--space-4);
  border-radius: var(--rounded-md);
  background: var(--color-background);
  box-shadow: var(--shadow);
  padding: var(--space-8);
}
#inspirations-select_list > * {
  font-family: var(--font-serif);
  padding: var(--space-8) var(--space-8) var(--space-8) var(--space-48);
  border-radius: var(--rounded-sm);
  position: relative;
  display: flex;
  align-items: center;
  height: 2.75rem;
  cursor: pointer;
}
#inspirations-select_list > * + * {
  margin-top: var(--space-4);
}
#inspirations-select_list > *::before {
  content: "";
  position: absolute;
  left: var(--space-8);
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--rounded-sm);
  background-image: var(--image);
  background-color: var(--color-grey-200);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}
#inspirations-select_list > *:hover {
  background-color: var(--color-grey-50);
}
#inspirations-select_list > *:focus,
#inspirations-select_list > *:focus-visible,
#inspirations-select_list > [data-p-focused="true"] {
  outline: 2px solid var(--color-focus-ring);
}
/* Check */
#inspirations-select_list > * > svg {
  position: absolute;
  left: 0.875rem;
  width: 1rem;
  height: 1rem;
  color: var(--color-grey-700);
}
</style>
