<template>
  <div>
    <group>
      <x-switch
        v-model="show1"
        title="Toggle"
        @on-change="show1change"
      />
    </group>
    <loading
      :show="show1"
      :text="text1"
    />
  </div>
</template>

<script>
import { Loading, Group, XSwitch } from '../components/_index'

export default {
  components: {
    Loading,
    Group,
    XSwitch
  },
  data () {
    return {
      show1: false,
      text1: 'Processing'
    }
  },
  methods: {
    show1change (val) {
      if (val) {
        tick(0, (percent) => {
          if (percent === 100) {
            this.show1 = false
            this.text1 = 'Start processing'
            return
          }
          this.text1 = `${percent}% completed`
        })
      }
    }
  }
}

function tick (i, cb) {
  setTimeout(function () {
    i++
    cb(i)
    if (i < 100) {
      tick(i, cb)
    }
  }, 50)
}
</script>
