<script lang="ts" setup>
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'

const {monthState} = toRefs(useCronStore())
const months = [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ]
</script>

<template>
  <ElRadioGroup v-model="monthState.mode" class="select-panel">
    <ElRadio value="none">不指定</ElRadio>
    <ElRadio value="every">每月</ElRadio>
    <ElRadio value="period1">
      <span>周期，从</span>
      <ElSelect v-model="monthState.period1.start" size="small">
        <ElOption v-for="(month,i) in months" :key="'monthState.period1.start' + i" :label="month" :value="i"/>
      </ElSelect>
      <span>到</span>
      <ElSelect v-model="monthState.period1.end" size="small">
        <ElOption v-for="(month,i) in months" :key="'monthState.period1.end' + i" :disabled="i <= monthState.period1.start" :label="month" :value="i"/>
      </ElSelect>
    </ElRadio>
    <ElRadio value="period2">
      <span>周期，从</span>
      <ElSelect v-model="monthState.period2.start" size="small">
        <ElOption v-for="(month,i) in months" :key="'monthState.period2.start' + i" :label="month" :value="i"/>
      </ElSelect>
      <span>开始，每</span>
      <ElInputNumber v-model="monthState.period2.end" :controls="false" :max="12" :min="1" size="small"/>
      <span>个月执行一次</span>
    </ElRadio>
    <ElRadio value="specify">
      <div>指定</div>
      <ElCheckboxGroup v-model="monthState.specify">
        <ElCheckbox v-for="(month,i) in months" :key="'monthState.specify' + i" :label="month" :value="i"/>
      </ElCheckboxGroup>
    </ElRadio>
  </ElRadioGroup>
</template>

<style lang="stylus" scoped>
.select-panel {
  flex-direction column
  align-items start
  gap 10px
  width 100%;
  flex-wrap nowrap

  :deep(.el-input-number) {
    margin 0 10px
    width: 80px
  }

  :deep(.el-select) {
    margin 0 10px
    width: 80px
  }

  :deep(.el-checkbox-group) {
    position absolute
    top 0
    left 60px
    display flex
    flex-wrap wrap
    gap 10px
    width 420px

    .el-checkbox {
      width 60px;
      margin 0
    }
  }
}
</style>
