<template>
  <div class="n-form-suffix">
    <n-icon class="n-form-suffix-icon" :type="_icon.icon" size="16" scene="default"
            :title="_icon.title" :disabled="!isAvailable" @click="onClick"></n-icon>
  </div>
</template>

<script>
import NIcon from '@uif/next/lib/components/icon'
import {isObjectLike, normalizeValue, prop} from '@uif/next/lib/utils/tools'
import {fireInputEvent} from '_common/formUtils'

export default {
  components: {NIcon},
  props: {
    input: prop.object(),
    // 完整 inputs
    inputs: prop.array()
  },
  computed: {
    _icon ({input}) {
      return isObjectLike(input.icon) ? input.icon : {icon: input.icon, title: null, isAvailable: true}
    },
    isAvailable ({input, _icon}) {
      return normalizeValue(_icon.isAvailable, input)
    }
  },
  methods: {
    onClick (event) {
      fireInputEvent('onIconClick', event, this.input, this.inputs)
      this.$emit('icon-click', this.input, event)
    }
  }
}
</script>
