import TyComponent from '../common/component'

TyComponent({
  source: true,
  externalClasses: ['custom-class'],
  behaviors: ['wx://form-field'],
  relations: {
    '../ht-radio/index': {
      type: 'descendant',
      linked(child) {
        this.children = this.children || []
        this.children.push(child)
        this.updateChild(child)
      },
      unlinked(child) {
        this.children = this.children.filter(function (item) {
          return item !== child
        })
      }
    }
  },
  properties: {

    value: {
      type: null,
      observer: 'updateChildren'
    },
    disabled: {
      type: Boolean,
      observer: 'updateChildren'
    }
  },

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

  },

  /**
   * 组件的方法列表
   */
  methods: {
    updateChildren() {
      const _this = this;
      (this.children || []).forEach(function (child) {
        return _this.updateChild(child)
      })
    },
    updateChild(child) {
      const _a = this.data; const value = _a.value; const
        disabled = _a.disabled
      child.setData({
        value,
        disabled: disabled || child.data.disabled
      })
    }
  }
})
