import React from 'react'
import {amisRender, commonInfo, remoteOptions} from '../../util/amis.tsx'
import {useNavigate} from 'react-router'

function TaskScheduleSave() {
  const navigate = useNavigate()
  return (
    <div className="task-template-save">
      {amisRender(
        {
          type: 'page',
          title: '任务模板添加',
          body: [
            {
              debug: commonInfo.debug,
              type: 'form',
              api: `post:${commonInfo.baseUrl}/task_schedule/save`,
              wrapWithPanel: false,
              mode: 'horizontal',
              labelAlign: 'left',
              onEvent: {
                submitSucc: {
                  actions: [
                    {
                      actionType: 'custom',
                      // @ts-ignore
                      script: (context, action, event) => {
                        navigate(-1)
                      },
                    },
                  ],
                },
              },
              body: [
                {
                  name: 'templateId',
                  label: '名称',
                  required: true,
                  selectFirst: true,
                  ...remoteOptions('select', 'task_template_id'),
                },
                {
                  type: 'input-text',
                  name: 'cron',
                  label: '定时策略',
                  required: true,
                  clearable: true,
                },
                {
                  type: 'button-toolbar',
                  buttons: [
                    {
                      type: 'action',
                      label: '提交',
                      actionType: 'submit',
                      level: 'primary',
                    },
                    {
                      type: 'action',
                      label: '重置',
                      actionType: 'reset',
                    },
                    {
                      type: 'action',
                      label: '返回',
                      onEvent: {
                        click: {
                          actions: [
                            {
                              actionType: 'custom',
                              // @ts-ignore
                              script: (context, action, event) => {
                                navigate(-1)
                              },
                            },
                          ],
                        },
                      },
                    },
                  ],
                },
              ],
            },
          ],
        },
      )}
    </div>
  )
}

export default React.memo(TaskScheduleSave)