import Component from '@ember/component'
import { oneWay, notEmpty } from '@ember/object/computed'

import layout from 'leaf-semantic-core/templates/components/leaf-multiple-toggler'


MultipleToggler = Component.extend(
  layout: layout


  #tagName: 'button'
  classNames: ['ui', 'labeled', 'button']


  'btn-class': null
  'lbl-class': null

  attributeBindings: ['btype:type']
  btype: 'button'

  icon: null
  text: null

  options: []
  value: null

  disposition: 'left'

  currentValue: oneWay('value')

  initialize: false

  didInsertElement: ->
    @_super(arguments...)
    @set('value', @get('options.firstObject'))


  nextValue: ->
    { currentValue,
      options } = @getProperties('currentValue', 'options')

    i = options.indexOf(currentValue)
    options[ if ( i == options.length - 1) then 0 else ( i + 1 )]


  select: (value) ->
    @sendAction('on-change', value)

  selectNext: ->
    @select(@nextValue())

  click: (e) ->
    unless @get('dropdown')
      @selectNext()
)


export default MultipleToggler