import { getRegulationList, deleteRegulation } from '@/services/regulation';
import { ProFormTextArea, ProForm, PageContainer, ProTable } from '@ant-design/pro-components';
import { Button, message, Popconfirm } from 'antd';
import { useNavigate } from 'react-router-dom';
import { queryTable } from '@/utils/request';
import { useRef, useState, useEffect } from 'react';

const IntroductionList = (props) => {
  const actionRef = useRef();
  const navigate = useNavigate();

  const handleDelete = (id) => {
    if (id) {
      deleteRegulation(id).then((res) => {
        // message.success('删除成功');
        actionRef.current.reload();
      });
    }
  };

  const columns = [
    {
      title: 'id',
      dataIndex: 'id',
      width: 100,
      search: false,
      hideInTable: true,
    },

    {
      title: '内容',
      dataIndex: 'detail',
      width: 400,
      search: false,
    },
    {
      title: '操作',
      valueType: 'option',
      width: 100,
      render: (_, record) => [
        <Button
          key={2}
          style={{ padding: 0 }}
          type="link"
          onClick={() => {
            console.log(record, ']]');
            navigate(`/cms/rotationChart/introduction/edit?id=${record.id}`);
          }}
        >
          编辑
        </Button>,

        <Popconfirm
          key={3}
          title="您是否确认删除 ?"
          onConfirm={() => handleDelete(record.id)}
          okText="确定"
          cancelText="取消"
        >
          {/* manualPush */}
          <Button style={{ padding: 0 }} type="link">
            删除
          </Button>
        </Popconfirm>,
      ],
    },
  ];

  return (
    <PageContainer>
      <ProTable
        search={false}
        actionRef={actionRef}
        rowKey="id"
        toolBarRender={() => [
          <Button
            key="2"
            type="primary"
            onClick={() => {
              navigate('/cms/rotationChart/introduction/edit');
            }}
          >
            新增
          </Button>,
        ]}
        request={queryTable(getRegulationList)}
        columns={columns}
      />
    </PageContainer>
  );
}

export default IntroductionList;
