<commit_before><template>
  <div
    key="SecondaryActions"
    class="WalletHeading__SecondaryActions flex content-end"
  >
    <ButtonDropdown
      v-if="registrationTypes.length"
      :classes="buttonStyle"
      :items="registrationTypes"
      title="Registration"
    >
      <ButtonModal
        slot="button"
        slot-scope="{ item, triggerClose }"
        v-tooltip="item.tooltip"
        :label="item.label"
        :disabled="item.disabled"
        class="ButtonDropdown__ButtonModal option-heading-button whitespace-no-wrap w-full"
        :class="{
          'ButtonDropdown__ButtonModal__disabled': item.disabled
        }"
        @toggle="triggerClose"
      >
        <template slot-scope="{ toggle, isOpen }">
          <TransactionModal
            v-if="isOpen"
            :type="item.type"
            :group="item.group || 1"
            @cancel="closeTransactionModal(toggle, isOpen)"
            @sent="closeTransactionModal(toggle, isOpen)"
          />
        </template>
      </ButtonModal>
    </ButtonDropdown>

    <ButtonModal
      :class="buttonStyle"
      :label="currentWallet.isContact ? $t('WALLET_HEADING.ACTIONS.CONTACT_NAME') : $t('WALLET_HEADING.ACTIONS.WALLET_NAME')"
      icon="name"
    >
      <template slot-scope="{ toggle, isOpen }">
        <ContactRenameModal
          v-if="currentWallet.isContact && isOpen"
          :wallet="currentWallet"
          @cancel="toggle"
          @renamed="toggle"
        />

        <WalletRenameModal
          v-if="!currentWallet.isContact && isOpen"
          :wallet="currentWallet"
          @cancel="toggle"
          @renamed="toggle"
        />
      </template>
    </ButtonModal>

    <ButtonModal
      v-show="!currentWallet.isLedger"
      :class="buttonStyle"
      :label="$t('WALLET_HEADING.ACTIONS.DELETE_WALLET')"
      icon="delete-wallet"
    >
      <template slot-scope="{ toggle, isOpen }">
        <WalletRemovalConfirmation
          v-if="isOpen"
          :wallet="currentWallet"
          @cancel="toggle"
          @removed="onRemoval"
        />
      </template>
    </ButtonModal>
  </div>
</template>

<script>
import { TRANSACTION_TYPES } from '@config'
import { ButtonDropdown, ButtonModal } from '@/components/Button'
import { ContactRenameModal } from '@/components/Contact'
import { WalletRenameModal, WalletRemovalConfirmation } from '@/components/Wallet'
import { TransactionModal } from '@/components/Transaction'
import WalletService from '@/services/wallet'

export default {
  name: 'WalletHeadingSecondaryActions',

  components: {
    ButtonDropdown,
    ButtonModal,
    ContactRenameModal,
    WalletRenameModal,
    WalletRemovalConfirmation,
    TransactionModal
  },

  data: () => ({
    registrationTypes: []
  }),

  computed: {
    buttonStyle () {
      return 'option-heading-button whitespace-no-wrap mr-2 px-3 py-2'
    },

    currentNetwork () {
      return this.$store.getters['session/network']
    },

    currentWallet () {
      return this.wallet_fromRoute
    }
  },

  async mounted () {
    this.registrationTypes = await this.getRegistrationTypes()
  },

  methods: {
    async onRemoval () {
      this.$router.push({ name: 'wallets' })
    },

    closeTransactionModal (toggleMethod, isOpen) {
      if (isOpen) {
        toggleMethod()
      }
    },

    async getRegistrationTypes () {
      const types = []

      if (this.currentWallet.isContact) {
        return []
      }

      if (!this.currentWallet.isLedger && !this.currentWallet.multiSignature) {
        if (!this.currentWallet.secondPublicKey) {
          types.push({
            label: this.$t('WALLET_HEADING.ACTIONS.SECOND_PASSPHRASE'),
            type: TRANSACTION_TYPES.GROUP_1.SECOND_SIGNATURE
          })
        }

        if (!this.currentWallet.isDelegate) {
          types.push({
            label: this.$t('WALLET_HEADING.ACTIONS.REGISTER_DELEGATE'),
            type: TRANSACTION_TYPES.GROUP_1.DELEGATE_REGISTRATION
          })
        }
      }

      // TODO: Remove ledger check when ledger app supports multisig, business & bridgechain transactions
      if (this.currentWallet.isLedger || !this.currentNetwork.constants || !this.currentNetwork.constants.aip11) {
        return types
      }

      if (!this.currentWallet.multiSignature) {
        types.push({
          label: this.$t('WALLET_HEADING.ACTIONS.REGISTER_MULTISIGNATURE'),
          type: TRANSACTION_TYPES.GROUP_1.MULTI_SIGNATURE
        })
      }

      if (!this.currentWallet.isLedger && WalletService.canResignDelegate(this.currentWallet)) {
        types.push({
          label: this.$t('WALLET_HEADING.ACTIONS.RESIGN_DELEGATE'),
          type: TRANSACTION_TYPES.GROUP_1.DELEGATE_RESIGNATION
        })
      }

      if (!WalletService.isBusiness(this.currentWallet)) {
        types.push({
          label: this.$t('WALLET_HEADING.ACTIONS.BUSINESS.REGISTER'),
          group: 2,
          type: TRANSACTION_TYPES.GROUP_2.BUSINESS_REGISTRATION
        })
      } else if (WalletService.isBusiness(this.currentWallet, false)) {
        types.push({
          label: this.$t('WALLET_HEADING.ACTIONS.BUSINESS.UPDATE'),
          group: 2,
          type: TRANSACTION_TYPES.GROUP_2.BUSINESS_UPDATE
        })
      }

      if (WalletService.canResignBusiness(this.currentWallet)) {
        const businessResignOption = {
          label: this.$t('WALLET_HEADING.ACTIONS.BUSINESS.RESIGN'),
          group: 2,
          type: TRANSACTION_TYPES.GROUP_2.BUSINESS_RESIGNATION
        }

        if (await WalletService.hasBridgechains(this.currentWallet, this)) {
          businessResignOption.disabled = true
          businessResignOption.tooltip = {
            content: this.$t('WALLET_HEADING.ACTIONS.BUSINESS.CANNOT_RESIGN'),
            placement: 'left'
          }
        }

        types.push(businessResignOption)
      }

      return types
    }
  }
}
</script>

<style scoped>
.ButtonDropdown__list {
  background-color: var(--theme-option-heading-button);
}

.ButtonDropdown__ButtonModal__disabled {
  background-color: var(--theme-option-heading-button-disabled);
  color: var(--theme-option-heading-button-text-disabled);
  @apply .cursor-not-allowed;
}<commit_msg>fix: access the vue-i18n property at the root (#1779)<commit_after><template>
  <div
    key="SecondaryActions"
    class="WalletHeading__SecondaryActions flex content-end"
  >
    <ButtonDropdown
      v-if="registrationTypes.length"
      :classes="buttonStyle"
      :items="registrationTypes"
      title="Registration"
    >
      <ButtonModal
        slot="button"
        slot-scope="{ item, triggerClose }"
        v-tooltip="item.tooltip"
        :label="item.label"
        :disabled="item.disabled"
        class="ButtonDropdown__ButtonModal option-heading-button whitespace-no-wrap w-full"
        :class="{
          'ButtonDropdown__ButtonModal__disabled': item.disabled
        }"
        @toggle="triggerClose"
      >
        <template slot-scope="{ toggle, isOpen }">
          <TransactionModal
            v-if="isOpen"
            :type="item.type"
            :group="item.group || 1"
            @cancel="closeTransactionModal(toggle, isOpen)"
            @sent="closeTransactionModal(toggle, isOpen)"
          />
        </template>
      </ButtonModal>
    </ButtonDropdown>

    <ButtonModal
      :class="buttonStyle"
      :label="currentWallet.isContact ? $t('WALLET_HEADING.ACTIONS.CONTACT_NAME') : $t('WALLET_HEADING.ACTIONS.WALLET_NAME')"
      icon="name"
    >
      <template slot-scope="{ toggle, isOpen }">
        <ContactRenameModal
          v-if="currentWallet.isContact && isOpen"
          :wallet="currentWallet"
          @cancel="toggle"
          @renamed="toggle"
        />

        <WalletRenameModal
          v-if="!currentWallet.isContact && isOpen"
          :wallet="currentWallet"
          @cancel="toggle"
          @renamed="toggle"
        />
      </template>
    </ButtonModal>

    <ButtonModal
      v-show="!currentWallet.isLedger"
      :class="buttonStyle"
      :label="$t('WALLET_HEADING.ACTIONS.DELETE_WALLET')"
      icon="delete-wallet"
    >
      <template slot-scope="{ toggle, isOpen }">
        <WalletRemovalConfirmation
          v-if="isOpen"
          :wallet="currentWallet"
          @cancel="toggle"
          @removed="onRemoval"
        />
      </template>
    </ButtonModal>
  </div>
</template>

<script>
import { TRANSACTION_TYPES } from '@config'
import { ButtonDropdown, ButtonModal } from '@/components/Button'
import { ContactRenameModal } from '@/components/Contact'
import { WalletRenameModal, WalletRemovalConfirmation } from '@/components/Wallet'
import { TransactionModal } from '@/components/Transaction'
import WalletService from '@/services/wallet'

export default {
  name: 'WalletHeadingSecondaryActions',

  components: {
    ButtonDropdown,
    ButtonModal,
    ContactRenameModal,
    WalletRenameModal,
    WalletRemovalConfirmation,
    TransactionModal
  },

  data: () => ({
    registrationTypes: []
  }),

  computed: {
    buttonStyle () {
      return 'option-heading-button whitespace-no-wrap mr-2 px-3 py-2'
    },

    currentNetwork () {
      return this.$store.getters['session/network']
    },

    currentWallet () {
      return this.wallet_fromRoute
    }
  },

  async mounted () {
    this.registrationTypes = await this.getRegistrationTypes()
  },

  methods: {
    async onRemoval () {
      this.$router.push({ name: 'wallets' })
    },

    closeTransactionModal (toggleMethod, isOpen) {
      if (isOpen) {
        toggleMethod()
      }
    },

    async getRegistrationTypes () {
      const types = []

      if (this.currentWallet.isContact) {
        return []
      }

      if (!this.currentWallet.isLedger && !this.currentWallet.multiSignature) {
        if (!this.currentWallet.secondPublicKey) {
          types.push({
            label: this.$t('WALLET_HEADING.ACTIONS.SECOND_PASSPHRASE'),
            type: TRANSACTION_TYPES.GROUP_1.SECOND_SIGNATURE
          })
        }

        if (!this.currentWallet.isDelegate) {
          types.push({
            label: this.$t('WALLET_HEADING.ACTIONS.REGISTER_DELEGATE'),
            type: TRANSACTION_TYPES.GROUP_1.DELEGATE_REGISTRATION
          })
        }
      }

      // TODO: Remove ledger check when ledger app supports multisig, business & bridgechain transactions
      if (this.currentWallet.isLedger || !this.currentNetwork.constants || !this.currentNetwork.constants.aip11) {
        return types
      }

      if (!this.currentWallet.multiSignature) {
        types.push({
          label: this.$t('WALLET_HEADING.ACTIONS.REGISTER_MULTISIGNATURE'),
          type: TRANSACTION_TYPES.GROUP_1.MULTI_SIGNATURE
        })
      }

      if (!this.currentWallet.isLedger && WalletService.canResignDelegate(this.currentWallet)) {
        types.push({
          label: this.$t('WALLET_HEADING.ACTIONS.RESIGN_DELEGATE'),
          type: TRANSACTION_TYPES.GROUP_1.DELEGATE_RESIGNATION
        })
      }

      if (!WalletService.isBusiness(this.currentWallet)) {
        types.push({
          label: this.$t('WALLET_HEADING.ACTIONS.BUSINESS.REGISTER'),
          group: 2,
          type: TRANSACTION_TYPES.GROUP_2.BUSINESS_REGISTRATION
        })
      } else if (WalletService.isBusiness(this.currentWallet, false)) {
        types.push({
          label: this.$t('WALLET_HEADING.ACTIONS.BUSINESS.UPDATE'),
          group: 2,
          type: TRANSACTION_TYPES.GROUP_2.BUSINESS_UPDATE
        })
      }

      if (WalletService.canResignBusiness(this.currentWallet)) {
        const businessResignOption = {
          label: this.$t('WALLET_HEADING.ACTIONS.BUSINESS.RESIGN'),
          group: 2,
          type: TRANSACTION_TYPES.GROUP_2.BUSINESS_RESIGNATION
        }

        if (await WalletService.hasBridgechains(this.currentWallet, this)) {
          businessResignOption.disabled = true
          businessResignOption.tooltip = {
            content: this.$root.$t('WALLET_HEADING.ACTIONS.BUSINESS.CANNOT_RESIGN'),
            placement: 'left'
          }
        }

        types.push(businessResignOption)
      }

      return types
    }
  }
}
</script>

<style scoped>
.ButtonDropdown__list {
  background-color: var(--theme-option-heading-button);
}

.ButtonDropdown__ButtonModal__disabled {
  background-color: var(--theme-option-heading-button-disabled);
  color: var(--theme-option-heading-button-text-disabled);
  @apply .cursor-not-allowed;
}
{'fraction_non_alphanumeric': 0.12189453438050969, 'fraction_numerical': 0.0030453598333066195, 'mean_word_length': 2.4886776628459604, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2772727', 'n_tokens_mistral': 3850, 'n_tokens_neox': 3829, 'n_words': 548}