<script setup lang="ts">
import { computed } from 'vue';
import type { SelectOption } from 'naive-ui';

defineOptions({
  name: 'JobOperateView'
});

const visible = defineModel<boolean>('visible', { default: false });
const props = withDefaults(
  defineProps<{
    rowData: Api.SystemManage.Job | null;
    statusOptions?: Api.SystemManage.DictInfo[];
    jobGroupOptions: Array<SelectOption>;
    misfirePolicyOptions: Array<SelectOption>;
  }>(),
  {
    statusOptions: () => []
  }
);

const filterJobGroup = computed(() => {
  const jobGroup = props.jobGroupOptions?.find(item => item.value === props.rowData?.jobGroup);
  return jobGroup?.label || '/';
});
const filterStatus = computed(() => {
  const status = props.statusOptions.find(item => item.dictValue === props.rowData?.status);
  return status?.dictLabel || '/';
});
const filterMisfirePolicy = computed(() => {
  const misfirePolicy = props.misfirePolicyOptions.find(item => item.value === props.rowData?.misfirePolicy);
  return misfirePolicy?.label || '/';
});
</script>

<template>
  <NModal v-model:show="visible" title="任务详细：" preset="card" class="w-800px">
    <NScrollbar class="pr-20px">
      <NForm label-placement="left" require-mark-placement="left" :label-width="130">
        <NGrid responsive="screen" item-responsive>
          <NFormItemGi span="24 m:12" label="任务编号：" path="jobId">
            {{ rowData?.jobId }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="任务组名：" path="jobGroup">
            {{ filterJobGroup }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="任务名称：" path="jobName">
            {{ rowData?.jobName }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="创建时间：" path="createTime">
            {{ rowData?.createTime }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="cron表达式：" path="cronExpression">
            {{ rowData?.cronExpression }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="下次执行时间：" path="nextValidTime">
            {{ rowData?.nextValidTime }}
          </NFormItemGi>
          <NFormItemGi span="24" label="调用目标方法：" path="invokeTarget">
            {{ rowData?.invokeTarget }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="状态：" path="status">
            {{ filterStatus }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="是否并发：" path="concurrent">
            {{ rowData?.concurrent === '0' ? '允许' : '禁止' }}
          </NFormItemGi>
          <NFormItemGi span="24" label="错误策略：" path="misfirePolicy">
            {{ filterMisfirePolicy }}
          </NFormItemGi>
        </NGrid>
      </NForm>
    </NScrollbar>
    <template #footer>
      <NSpace justify="end" :size="16">
        <NButton @click="visible = false">关闭</NButton>
      </NSpace>
    </template>
  </NModal>
</template>

<style scoped></style>
