<script setup>
import PlayIcon from '@vicons/ionicons5/Play'
import { inject } from 'vue'

const running = inject('running')
const log = inject('log')
const steps = inject('steps')
const current_step = inject('current_step')
const current_state = inject('current_state')

async function start() {
  log.value = ''
  running.value = true
  for (const [i, step] of steps.value.entries()) {
    current_step.value = i + 1
    current_state.value = 'process'
    for (const cmd of step.command) {
      await pywebview.api.run(cmd, step.cwd)
    }
  }
  current_state.value = 'finish'
  running.value = false
}
</script>

<template>
  <n-button class="float" type="primary" :loading="running" :disabled="running" @click="start">
    <template #icon>
      <n-icon>
        <play-icon />
      </n-icon>
    </template>
    {{ running ? '' : '运行' }}
  </n-button>
</template>

<style scoped>
.float {
  position: absolute;
  right: 28px;
  bottom: 28px;
  opacity: 0.8;
}

.float:hover {
  opacity: 1;
}
</style>
