import { MyBetaModalFormProps } from '@/common';
import { MyModal } from '@/components/MyModal';
import { Apis } from '@/gen/Apis';
import { List } from 'antd';
import { useRef, useState } from 'react';
interface DataType {
  key: React.Key;
  id: React.Key;
  is_enabled: boolean;
}
const scoreInfo = {
  '1': '非常不满意',
  '2': '比较不满意',
  '3': '满意',
  '4': '比较满意',
  '5': '非常满意',
};

export default function SurveyResponsesShow(
  props: MyBetaModalFormProps & {
    onChange?: (selectedRows: DataType[]) => void;
  },
) {
  const modalRef = useRef<any>();
  const [data, setShow] = useState<any>({});
  const loadShow = () => {
    Apis.Survey.SurveyResponses.Show({ id: props?.item?.id }).then((res) => {
      setShow(res?.data);
    });
  };

  return (
    <MyModal
      title="回答详情"
      width="800px"
      myRef={modalRef}
      onOpen={() => {
        loadShow();
        console.log(props?.item?.list);
      }}
      node={
        <>
          <List
            itemLayout="horizontal"
            dataSource={data?.questions_with_answers}
            renderItem={(item: any, index: number) => (
              <List.Item>
                <List.Item.Meta
                  title={`${index + 1}.题目：${item?.title}`}
                  description={
                    item?.type === 'Score'
                      ? `客户选择：${
                          scoreInfo[
                            item?.answer?.score as keyof typeof scoreInfo
                          ]
                        }（${item?.answer?.score}分）`
                      : `客户回答：${item?.answer?.answer_content}`
                  }
                />
              </List.Item>
            )}
          />
        </>
      }
    ></MyModal>
  );
}
