import React from 'react'
import {amisRender, commonInfo, crudCommonOptions, paginationTemplate} from '../../util/amis.tsx'

function TaskTemplateList() {
  return (
    <div className="task-template-list">
      {amisRender(
        {
          type: 'page',
          title: '任务模板',
          body: [
            {
              type: 'crud',
              api: `get:${commonInfo.baseUrl}/task/template/list`,
              ...crudCommonOptions(),
              ...paginationTemplate(15),
              loadOnce: true,
              columns: [
                {
                  name: 'name',
                  label: '名称',
                  width: 150,
                },
                {
                  name: 'description',
                  label: '描述',
                },
                {
                  type: 'operation',
                  label: '操作',
                  width: 100,
                  buttons: [
                    {
                      type: 'action',
                      label: '执行',
                      level: 'link',
                      actionType: 'ajax',
                      api: {
                        method: 'post',
                        url: `${commonInfo.baseUrl}/task/execute`,
                        data: {
                          templateId: '${id}',
                        },
                      },
                      confirmText: '确认执行模板<span class="text-lg font-bold mx-2">${name}</span>？',
                      confirmTitle: '执行',
                    },
                  ],
                },
              ],
            },
          ],
        },
      )}
    </div>
  )
}

export default React.memo(TaskTemplateList)