import TyComponent from '../common/component'

TyComponent({
  source: true,
  externalClasses: ['icon-class', 'label-class', 'custom-class'],
  behaviors: ['wx://form-field'],
  relations: {
    '../ht-radio-group/index': {
      type: 'ancestor',
      linked(parent) {
        this.parent = parent
      },
      unlinked() {
        this.parent = null
      },
    }
  },
  properties: {

    name: null,
    value: null,
    disabled: Boolean,
    useIconSlot: Boolean,
    checkedColor: String,
    labelPosition: {
      type: String,
      value: 'right'
    },
    labelDisabled: Boolean,
    shape: {
      type: String,
      value: 'round'
    },
    iconSize: {
      type: null,
      value: 20
    }

  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    emitChange(value) {
      const instance = this.parent || this
      instance.$emit('input', value)
      instance.$emit('change', value)
    },
    onChange() {
      if (!this.data.disabled) {
        this.emitChange(this.data.name)
      }
    },
    onClickLabel() {
      const _a = this.data
      const disabled = _a.disabled
      const labelDisabled = _a.labelDisabled
      const name = _a.name
      if (!disabled && !labelDisabled) {
        this.emitChange(name)
      }
    }
  }
})
