<script>
  import getInnerListeners from './getInnerListeners'

  export default {
    name: 'mpx-checkbox',
    data () {
      return {
        isChecked: false
      }
    },
    props: {
      value: {
        type: String,
        default: ''
      },
      disabled: Boolean,
      checked: Boolean,
      color: {
        type: String,
        default: '#09BB07'
      }
    },
    created () {
      this.isChecked = this.checked
    },
    render (createElement) {
      let mergeAfter = {
        listeners: {
          click: () => {
            if (this.disabled) {
              return
            }
            this.isChecked = !this.isChecked
            if (this.group) {
              this.group.notifyChange()
            }
          }
        },
        force: true
      }
      const style = global.__style === 'v2' ? 'v2' : 'v1'
      const data = {
        class: [this.disabled ? 'mpx-checkbox-disabled' : 'mpx-checkbox', this.isChecked && 'mpx-checkbox-input-checked-' + style],
        on: getInnerListeners(this, { mergeAfter })
      }

      return createElement('div', data, this.$slots.default)
    }
  }
</script>

<style lang="stylus">
  @font-face {
    font-weight normal
    font-style normal
    font-family "weui"
    src url('data:application/octet-stream;base64,AAEAAAALAIAAAwAwR1NVQrD+s+0AAAE4AAAAQk9TLzJAKEx+AAABfAAAAFZjbWFw65cFHQAAAhwAAAJQZ2x5ZvCRR/EAAASUAAAKtGhlYWQLKIN9AAAA4AAAADZoaGVhCCwD+gAAALwAAAAkaG10eEJo//8AAAHUAAAASGxvY2EYqhW6AAAEbAAAACZtYXhwASEAVQAAARgAAAAgbmFtZeNcHtgAAA9IAAAB5nBvc3T6bLhLAAARMAAAAOYAAQAAA+gAAABaA+j/////A+kAAQAAAAAAAAAAAAAAAAAAABIAAQAAAAEAACkCj3dfDzz1AAsD6AAAAADUER9XAAAAANQRH1f//wAAA+kD6gAAAAgAAgAAAAAAAAABAAAAEgBJAAUAAAAAAAIAAAAKAAoAAAD/AAAAAAAAAAEAAAAKAB4ALAABREZMVAAIAAQAAAAAAAAAAQAAAAFsaWdhAAgAAAABAAAAAQAEAAQAAAABAAgAAQAGAAAAAQAAAAAAAQOwAZAABQAIAnoCvAAAAIwCegK8AAAB4AAxAQIAAAIABQMAAAAAAAAAAAAAAAAAAA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AKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAQIBAwEEAQUBBgEHAQgBCQEKAQsBDAENAQ4BDwEQAREBEgETAAZjaXJjbGUIZG93bmxvYWQEaW5mbwxzYWZlX3N1Y2Nlc3MJc2FmZV93YXJuB3N1Y2Nlc3MOc3VjY2Vzcy1jaXJjbGURc3VjY2Vzcy1uby1jaXJjbGUHd2FpdGluZw53YWl0aW5nLWNpcmNsZQR3YXJuC2luZm8tY2lyY2xlBmNhbmNlbAZzZWFyY2gFY2xlYXIEYmFjawZkZWxldGUAAAAA') format('truetype')
  }
  .mpx-checkbox,
  .mpx-checkbox-disabled
    margin 3px 3px 3px 4px
    display: inline-flex
    align-items center
    margin-right: 5px
    appearance: none
    outline: 0
    text-indent: 0
    border: 1px solid #D1D1D1
    background-color: #FFFFFF
    border-radius: 3px
    width: 22px
    height: 22px
    position: relative
    vertical-align: middle
    &.mpx-checkbox-input-checked-v1
      color: #09BB07
      &:before
        font: normal normal normal 14px/1 "weui"
        content: "\EA08"
        font-size: 22px
        position: absolute
        top: 50%
        left: 50%
        transform: translate(-50%, -48%) scale(0.73)
        -webkit-transform: translate(-50%, -48%) scale(0.73)
    &.mpx-checkbox-input-checked-v2
      &:before
        color: #09BB07
        display: inline-block
        width: 22px
        height: 22px
        content: ""
        position: absolute
        top: 50%
        left: 50%
        transform: translate(-50%, -48%) scale(0.73)
        -webkit-transform: translate(-50%, -48%) scale(0.73)
        mask-position: 50% 50%
        -webkit-mask-position: 50% 50%
        -webkit-mask-repeat: no-repeat
        mask-repeat: no-repeat
        -webkit-mask-size: 100%
        mask-size: 100%
        background-color: currentColor
        mask-image: url('data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M8.657%2018.435L3%2012.778l1.414-1.414%204.95%204.95L20.678%205l1.414%201.414-12.02%2012.021a1%201%200%2001-1.415%200z%22%20fill-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E')
        -webkit-mask-image: url('data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M8.657%2018.435L3%2012.778l1.414-1.414%204.95%204.95L20.678%205l1.414%201.414-12.02%2012.021a1%201%200%2001-1.415%200z%22%20fill-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E')
  .mpx-checkbox-disabled
    border: 1px solid #d1d1d1
    background: #e1e1e1
    &.mpx-checkbox-input-checked-v1
      color: #9D9D9D
    &.mpx-checkbox-input-checked-v2
      &:before
        color: #9D9D9D
</style>
