import { MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import MyShow from '../modals/SurveyResponsesShow';

interface SurveyResponsesListProps {
  title?: string;
  releaseId?: number;
}

export default function SurveyResponsesList({
  title = '客户提交问卷',
  releaseId,
}: SurveyResponsesListProps) {
  return (
    <ProTable
      {...MyProTableProps.props}
      headerTitle={`${title}列表`}
      request={async (params, sort) =>
        MyProTableProps.request(
          { ...params, ...(releaseId ? { release_id: releaseId } : {}) },
          sort,
          Apis.Survey.SurveyResponses.List,
        )
      }
      columns={[
        // MyColumns.ID({
        //   search: false,
        // }),
        { dataIndex: ['survey', 'name'], title: '问卷', search: false },
        { dataIndex: 'survey_id', title: '问卷ID', hidden: true },
        { dataIndex: 'release_id', title: '发布ID', hidden: true },
        { dataIndex: 'customers_id', title: '客户ID', hidden: true },
        { dataIndex: 'customer_phone', title: '客户手机号', hidden: true },
        {
          dataIndex: 'customer',
          title: '回答客户',
          search: false,
          render: (_, item: any) => {
            return `${item?.customer?.phone}_${item?.customer?.name}`;
          },
        },
        { dataIndex: 'total_score', title: '总得分', search: false },
        MyColumns.CreatedAt(),
        MyColumns.Option({
          width: 120,
          render: (_, item: any) => <MyShow key="show" item={item} />,
        }),
      ]}
    />
  );
}
