<template>
  <div :class="getClass">
    <div class="main-info">
      <Check
        class="bms-notification__icon"
        v-if="notification.type === NotificationType.success"
      />
      <X class="bms-notification__icon" v-else />

      <div class="bms-notification__content">{{ notification.text }}</div>

      <BmsIconButton
        class="bms-notification__close-button"
        @click="closeNotification"
      >
        <Trash2 />
      </BmsIconButton>
    </div>
    <div
      v-if="notification.details"
      class="details"
      @click="emit('openDetails')"
    >
      Voir plus de détails
    </div>
  </div>
</template>

<script setup lang="ts">
import { Check, Trash2, X } from 'lucide-vue-next';
import { computed } from 'vue';
import { Notification, NotificationType } from './notification.model';
import BmsIconButton from '@/components/button/BmsIconButton.vue';

const props = defineProps<{
  notification: Notification;
}>();

const emit = defineEmits(['close', 'openDetails']);

const getClass = computed(() => {
  return ['bms-notification', `bms-notification--${props.notification.type}`];
});

const closeNotification = () => {
  emit('close');
};
</script>

<style lang="scss" scoped>
.bms-notification {
  --notification-background-color: var(--bms-white);

  display: flex;
  flex-direction: column;
  width: 100%;
  border-radius: var(--bms-border-radius);
  background-color: var(--notification-background-color);
  color: var(--bms-white);
  position: relative;
  box-shadow: var(--bms-box-shadow-elevated);

  .main-info {
    display: flex;
    align-items: center;
    gap: 1em;
    padding: 0.75em;
    padding-right: 3em;
  }

  .details {
    border-top: 1px solid white;
    text-align: center;
    padding: 0.5em;
    border-radius: 0 0 var(--bms-border-radius) var(--bms-border-radius);

    &:hover {
      cursor: pointer;
    }
  }

  &--success {
    --notification-background-color: var(--bms-success-color);
  }

  &--error {
    --notification-background-color: var(--bms-danger-color);
  }

  &__icon {
    display: block;
    line-height: 1;
    width: 1em;
    height: 1em;
    flex-shrink: 0;
  }

  &__content {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* number of lines to show */
    line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  :deep(.bms-notification__close-button) {
    position: absolute;
    right: 0.2em;
    color: var(--bms-white);
    &:hover {
      color: var(--notification-background-color);
    }
  }
}
</style>
