# @ts-check

import formatHotkey_replace from './replace'
import formatHotkey_split from './split'
import formatHotkey_toLowerCase from './toLowerCase'
import formatHotkey_trim from './trim'

formatHotkey_formatKeyFormatHotkey =
###* @type import('./formatHotkey').FormatHotkey1 ###
(key) ->

  ###* @type string[] ###
  formatHotkey_listKey = []

  formatHotkey_key = formatHotkey_toLowerCase key
  formatHotkey_key = formatHotkey_replace formatHotkey_key, ' ', ''
  formatHotkey_key = formatHotkey_replace formatHotkey_key, '-', ''

  formatHotkey_listSplit = formatHotkey_split formatHotkey_key, '+'
  if formatHotkey_listSplit.Length() then formatHotkey_listKey.Push formatHotkey_listSplit...

  return formatHotkey_listKey

formatHotkey_pickPrefixFormatHotkey =
###* @type import('./formatHotkey').FormatHotkey2 ###
(listKey) ->

  if listKey.Length() == 1 then return ['', listKey]

  formatHotkey_prefix = ''
  ###* @type string[] ###
  formatHotkey_listNew = []

  for formatHotkey_key in listKey

    if formatHotkey_key == 'alt'
      formatHotkey_prefix = "#{formatHotkey_prefix}!"
      continue

    if formatHotkey_key == 'ctrl'
      formatHotkey_prefix = "#{formatHotkey_prefix}^"
      continue

    if formatHotkey_key == 'shift'
      formatHotkey_prefix = "#{formatHotkey_prefix}+"
      continue

    if formatHotkey_key == 'win'
      formatHotkey_prefix = "#{formatHotkey_prefix}#"
      continue

    formatHotkey_listNew.Push formatHotkey_key

  return [formatHotkey_prefix, formatHotkey_listNew]

###* @type import('./formatHotkey').FormatHotkey ###
export default (key) ->

  formatHotkey_listKey = formatHotkey_formatKeyFormatHotkey key

  [formatHotkey_prefix, formatHotkey_listKey] = formatHotkey_pickPrefixFormatHotkey formatHotkey_listKey

  formatHotkey_result = ''
  for formatHotkey_it in formatHotkey_listKey
    formatHotkey_result = "#{formatHotkey_result} & #{formatHotkey_it}"

  return formatHotkey_replace "#{formatHotkey_prefix}#{formatHotkey_trim formatHotkey_result, ' &'}", ':', ' '