'ui';
if (!global.clickShow) {
  threads.start(function () {
    global.clickShow = function (dom) {
      if (dom) {
        var window1 = floaty.rawWindow(
          <vertical gravity="bottom">
            <text id="status" text="" textColor="white" bg="#DF04CD" alpha="0.8"
              w="*" h="*" gravity="center" />
          </vertical>,
        )
        const rect = dom.bounds()
        window1.setSize(rect.width(), rect.height())
        window1.setPosition(rect.left, rect.top)
        sleep(100)
        window1.close()
      }
    }
  })
}

if (!global.floatyWindow) {
  threads.start(() => {

    global.floatyWindow = floaty.window(
      <vertical radius="20">
        <vertical id="start" bg="#000000" alpha="0.5" padding='6' gravity="center">
          <img w="16" h="16" layout_gravity="center" src="data:image/png;base64,[encoded data, 9700 characters]" />
          <text text="开始" textColor="white" textSize="8" gravity="center" />
        </vertical>
        <vertical id="stop" bg="#000000" alpha="0.5" padding='6' gravity="center" marginTop="1">
          <img w="16" h="16" layout_gravity="center" src="data:image/png;base64,[encoded data, 8984 characters]" />
          <text text="停止" textColor="white" textSize="8" gravity="center" />
        </vertical>
      </vertical>
    )

    floatyWindow.setPosition(0, device.height / 2 - 600)

    floatyWindow.stop.click(() => {
      toastLog('停止脚本!')
      global.robotStop()
    })
    // 点击开始
    let lockStart
    floatyWindow.start.click(() => {
      if (lockStart) {
        return
      }
      if (!global.curRobot) {
        toastLog('请先启动脚本!')
        return
      }
      global.curRobot()
      lockStart = true
      setTimeout(() => {
        lockStart = false
      }, 1000);
    })
  })
}


