<script setup lang="ts">
import { StatusType } from '@/models';
import { computed } from 'vue';

const props = withDefaults(
  defineProps<{
    pending: number;
    color?: StatusType;
  }>(),
  { pending: 0, color: StatusType.Information },
);

const classes = computed(() => {
  return `is-${props.color}`;
});
const sanitizedPending = computed(() => {
  return props.pending > 99 ? '99+' : props.pending;
});
</script>

<template>
  <span class="ui-badge__container" v-if="pending > 0">
    <slot></slot>
    <span v-if="pending > 0" :class="classes" class="ui-badge__badge">
      {{ sanitizedPending }}
    </span>
  </span>
  <template v-else>
    <slot></slot>
  </template>
</template>

<style scoped lang="scss">
.ui-badge__container {
  display: flex;

  &.not-pending {
    display: initial;
  }

  .ui-badge__badge {
    margin-top: -3px;
    color: var(--bms-white);
    border-radius: 50%;
    font-size: 0.5em;
    height: 1.9em;
    width: 1.9em;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;

    &.is-default {
      background-color: var(--bms-grey-100);
    }

    &.is-information {
      background-color: var(--bms-main-100);
    }

    &.is-warning {
      background-color: var(--bms-orange-100);
    }

    &.is-danger {
      background-color: var(--bms-red-100);
    }

    &.is-success {
      background-color: var(--bms-green-100);
    }
  }
}
</style>
