<template>
  <Popover
    class="ExtraButtons"
    trigger="click"
    placement="top"
    :offset="{ y: 5 }"
    :bound-to="{ x: 'container' }"
    remove-padding
    @show="onShow"
    @close="onClose"
  >
    <template #content="{close}">
      <div class="dropdown-menu">
        <button
          v-if="canMute && !status.thread_muted"
          class="button-default dropdown-item dropdown-item-icon"
          @click.prevent="muteConversation"
        >
          <FAIcon
            fixed-width
            icon="eye-slash"
          /><span>{{ $t("status.mute_conversation") }}</span>
        </button>
        <button
          v-if="canMute && status.thread_muted"
          class="button-default dropdown-item dropdown-item-icon"
          @click.prevent="unmuteConversation"
        >
          <FAIcon
            fixed-width
            icon="eye-slash"
          /><span>{{ $t("status.unmute_conversation") }}</span>
        </button>
        <button
          v-if="!status.pinned && canPin"
          class="button-default dropdown-item dropdown-item-icon"
          @click.prevent="pinStatus"
          @click="close"
        >
          <FAIcon
            fixed-width
            icon="thumbtack"
          /><span>{{ $t("status.pin") }}</span>
        </button>
        <button
          v-if="status.pinned && canPin"
          class="button-default dropdown-item dropdown-item-icon"
          @click.prevent="unpinStatus"
          @click="close"
        >
          <FAIcon
            fixed-width
            icon="thumbtack"
          /><span>{{ $t("status.unpin") }}</span>
        </button>
        <template v-if="canBookmark">
          <button
            v-if="!status.bookmarked"
            class="button-default dropdown-item dropdown-item-icon"
            @click.prevent="bookmarkStatus"
            @click="close"
          >
            <FAIcon
              fixed-width
              :icon="['far', 'bookmark']"
            /><span>{{ $t("status.bookmark") }}</span>
          </button>
          <button
            v-if="status.bookmarked"
            class="button-default dropdown-item dropdown-item-icon"
            @click.prevent="unbookmarkStatus"
            @click="close"
          >
            <FAIcon
              fixed-width
              icon="bookmark"
            /><span>{{ $t("status.unbookmark") }}</span>
          </button>
        </template>
        <button
          v-if="ownStatus && editingAvailable"
          class="button-default dropdown-item dropdown-item-icon"
          @click.prevent="editStatus"
          @click="close"
        >
          <FAIcon
            fixed-width
            icon="pen"
          /><span>{{ $t("status.edit") }}</span>
        </button>
        <button
          v-if="isEdited && editingAvailable"
          class="button-default dropdown-item dropdown-item-icon"
          @click.prevent="showStatusHistory"
          @click="close"
        >
          <FAIcon
            fixed-width
            icon="history"
          /><span>{{ $t("status.status_history") }}</span>
        </button>
        <button
          v-if="canDelete"
          class="button-default dropdown-item dropdown-item-icon"
          @click.prevent="deleteStatus"
          @click="close"
        >
          <FAIcon
            fixed-width
            icon="times"
          /><span>{{ $t("status.delete") }}</span>
        </button>
        <button
          class="button-default dropdown-item dropdown-item-icon"
          @click.prevent="copyLink"
          @click="close"
        >
          <FAIcon
            fixed-width
            icon="share-alt"
          /><span>{{ $t("status.copy_link") }}</span>
        </button>
        <a
          v-if="!status.is_local"
          class="button-default dropdown-item dropdown-item-icon"
          title="Source"
          :href="status.external_url"
          target="_blank"
        >
          <FAIcon
            fixed-width
            icon="external-link-alt"
          /><span>{{ $t("status.external_source") }}</span>
        </a>
        <button
          class="button-default dropdown-item dropdown-item-icon"
          @click.prevent="reportStatus"
          @click="close"
        >
          <FAIcon
            fixed-width
            :icon="['far', 'flag']"
          /><span>{{ $t("user_card.report") }}</span>
        </button>
      </div>
    </template>
    <template #trigger>
      <span class="button-unstyled popover-trigger">
        <FALayers class="fa-old-padding-layer">
          <FAIcon
            class="fa-scale-110 "
            icon="ellipsis-h"
          />
          <FAIcon
            v-show="!expanded"
            class="focus-marker"
            transform="shrink-6 up-8 right-16"
            icon="plus"
          />
          <FAIcon
            v-show="expanded"
            class="focus-marker"
            transform="shrink-6 up-8 right-16"
            icon="times"
          />
        </FALayers>
      </span>
    </template>
  </Popover>
</template>

<script src="./extra_buttons.js"></script>

<style lang="scss">
@import '../../_variables.scss';
@import '../../_mixins.scss';

.ExtraButtons {
  /* override of popover internal stuff */
  .popover-trigger-button {
    width: auto;
  }

  .popover-trigger {
    position: static;
    padding: 10px;
    margin: -10px;

    &:hover .svg-inline--fa {
      color: $fallback--text;
      color: var(--text, $fallback--text);
    }

  }

  .popover-trigger-button {
    @include unfocused-style {
      .focus-marker {
        visibility: hidden;
      }
    }

    @include focused-style {
      .focus-marker {
        visibility: visible;
      }
    }
  }
}
</style>
