<template>
  <div class="tenantsMenu-tenants-item" @click="emits('changeTenant')">
    <div
      class="tenantsMenu-tenants-item-label"
      :data-testid="`item-${tenant.id}`"
    >
      <Clock :size="12" v-if="tenant.isFavorite" />
      <UiTenantImage :tenant="tenant" />
      {{ tenant.label }}<em>- {{ tenant.information }}</em>
    </div>
    <BmsIconButton
      class="remove-tenant-button"
      v-if="tenant.isFavorite"
      @click.stop="emits('removeFavorite')"
    >
      <X />
    </BmsIconButton>
  </div>
</template>

<script setup lang="ts">
import { Clock, X } from 'lucide-vue-next';
import { Tenant } from '@/models';
import BmsIconButton from '../button/BmsIconButton.vue';
import UiTenantImage from './UiTenantImage.vue';

defineProps<{
  tenant: Tenant;
}>();

const emits = defineEmits<{
  removeFavorite: [];
  changeTenant: [];
}>();
</script>

<style scoped lang="scss">
.tenantsMenu-tenants-item {
  min-height: 40px;
  padding: 4px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;

  &:hover {
    background: light-dark(var(--bms-grey-10), var(--bms-grey-140));

    :deep(.remove-tenant-button) {
      display: inherit;
      &:hover {
        background-color: light-dark(var(--bms-grey-25), var(--bms-grey-100));
      }
    }
  }

  &-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 0.2em;

    em {
      opacity: 0.48;
      font-size: 12px;
      font-style: normal;
      margin-left: 0.4em;
    }
  }

  :deep(svg) {
    flex-shrink: 0;
  }

  .site-logo {
    width: 1em;
    height: 1em;
  }
  :deep(.remove-tenant-button) {
    padding: 0;
    display: none;
  }

  .ui-button.is-icon.is-compact {
    min-height: auto;
    min-width: auto;
    width: auto;
  }
}
</style>
