<template>
  <div
    @click.stop
    class="notification-actions"
    :class="{ 'notification-actions_show': isShow }"
  >
    <ui-btn-close @click="close" dense />
    <q-space />
    <ui-btn-menu v-if="notification.actions.length > 1" dense class="q-mr-xs">
      <ui-menu>
        <ui-menu-group>
          <ui-menu-item
            v-for="(action, index) in notification.actions"
            :key="`${index}-action-${notification.id}`"
            tag="a"
            target="_blank"
            :href="action.link"
          >
            {{ action.label }}
          </ui-menu-item>
        </ui-menu-group>
      </ui-menu>
    </ui-btn-menu>
  </div>
</template>

<style lang="sass" scoped>
.notification-actions
  display: flex
  align-items: center
  margin-left: auto
  transition: opacity 0.15s
  opacity: 0

  &_show
    opacity: 1
</style>

<script lang="ts">
import { Component, Emit, Prop, Vue } from 'vue-property-decorator'
import { NotificationEvent } from '@/widgets/notifications/types/NotificationEvent'
import UiBtnMenu from '@/lib-components/buttons/UiBtnMenu.vue'
import UiMenu from '@/lib-components/menu/UiMenu.vue'
import UiMenuGroup from '@/lib-components/menu/UiMenuGroup.vue'
import UiMenuItem from '@/lib-components/menu/UiMenuItem.vue'
import UiBtnClose from '@/lib-components/buttons/UiBtnClose.vue'

@Component({
  components: { UiBtnClose, UiMenuItem, UiMenuGroup, UiMenu, UiBtnMenu },
  inheritAttrs: false,
})
export default class UiNotificationItemActions extends Vue {
  @Prop(Object) notification!: NotificationEvent
  @Prop(Boolean) isShow!: boolean

  @Emit()
  close() {
    return true
  }
}
</script>
