<template xmlns="">
  <view class="">
    <view v-if="props.showBack" :class="{'action':select === 0}" class="p-f back-box" @click="clickHandle">
      <ly-icon :color="color" :size="60" name="icon-fanhui"/>
    </view>
    <view class="p-f bottom-right">
      <view class="flex-between-center w50">
        <view class="">
          <ly-icon :color="machineStore.scan?'#00ce48':'red'" :size="50" name="icon-shuakaqi"/>
        </view>
        <view v-if="configStore.mType === 7" class="m-l-20">
          <ly-icon :color="machineStore.bmi?'#00CE48':'red'" :size="45" name="icon-dianzicheng"/>
        </view>
      </view>
    </view>
    <view class="p-f mac-info" @click="toSetting">
      MAC:{{ userStore.mac || '未登录' }}
    </view>
  </view>
</template>

<script setup>
import {inject, onBeforeUnmount, onMounted, reactive} from "vue";
import {navigateBack, navTo, showToast} from "@/utils/app";
import {useUserStore} from "@/store/useUserStore";
import debounce from "@/utils/debounce";
import {machineFun} from "@/utils/machine/machineFun";
import {useConfigStore} from "@/store/useConfigStore";
import {useMachineStore} from "@/store/useMachineStore";

const $machine = inject('$machine')

const debounces = new debounce()

const userStore = useUserStore()
const configStore = useConfigStore()
const machineStore = useMachineStore()

const emits = defineEmits(['backClick'])
const props = defineProps({
  showBack: {
    type: Boolean,
    default: true,
  },
  autoBack: {
    type: Boolean,
    default: true
  },
  color: {
    type: String,
    default: '#000'
  },
  select: {
    type: [String, Number],
    default: -1
  },
})

const clickHandle = () => {
  if (props.autoBack) {
    navigateBack()
  } else {
    emits('backClick')
  }
}

const toSetting = () => {
  debounces.secondCountDown('toSetting', {
    time: 5000,
    limit: 10,
    repetition_time: 0,
    run: (num, count, statue) => {
      if (count > 5) showToast(`再点击${10 - count}次`)
    },
    success: () => {
      console.log('success')
      navTo('pages/setting/index')
    },
    fail: () => {
      console.log('fail')
    },
  })
}


// 挂载完成之后
onMounted(async (r) => {
  machineFun.setUsbNotify(true)
  machineFun.getOnlineUsb($machine)
})
// 页面卸载前
onBeforeUnmount(() => {
  machineFun.setUsbNotify(false)
})
</script>

<style lang="scss" scoped>
.mac-info {
  bottom: 10rpx;
  right: 20rpx;
  font-size: 25rpx;
  color: #cccccc;
}

.bottom-right {
  bottom: 10rpx;
  left: 20rpx;
}

.back-box {
  //width: 30vw;
  height: 200px;
  z-index: 99;
}
</style>
