import {
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  usePageTabs,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { CustomerOpinionsTypeEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Image } from 'antd';

export default function Index({ title = '投诉建议' }) {
  // 注册当前页面为标签页
  usePageTabs({
    tabKey: 'customer_opinions',
    tabLabel: title,
  });

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="customer_opinions"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Customer.CustomerOpinions.List,
          )
        }
        // toolBarRender={(action) => [
        //   <MyImportModal
        //     key="ImportHouse"
        //     title="批量导入"
        //     type="danger"
        //     size="middle"
        //     templateApi={Apis.Bill.HouseBills.DownloadTemplate}
        //     importApi={Apis.Bill.HouseBills.Import}
        //     reload={action?.reload}
        //   />,
        //   <BillCreate key="Create" reload={action?.reload} title={title} />,
        // ]}
        columns={[
          MyColumns.ID(),
          // MyColumns.EnumTag({
          //   title: '反馈来源',
          //   dataIndex: 'payment_method',
          //   valueEnum: HouseOrdersPaymentMethodEnum,
          // }),
          MyColumns.EnumTag({
            title: '反馈类型',
            dataIndex: 'type',
            valueEnum: CustomerOpinionsTypeEnum,
          }),
          {
            title: '反馈内容',
            dataIndex: 'content',
            search: false,
          },
          {
            title: '反馈内容',
            dataIndex: 'content',
            width: 120, // 关键：固定列宽（若父容器过窄，可设 minWidth: 200 优先保证列宽）
            render: (text) => (
              <div
                style={{
                  width: '100%', // 继承列宽
                  // height: '60px', // 设置固定高度，约显示3行文本
                  overflow: 'hidden', // 超出隐藏
                  textOverflow: 'ellipsis', // 省略号
                  display: '-webkit-box',
                  WebkitBoxOrient: 'vertical',
                  WebkitLineClamp: 1, // 显示3行
                }}
              >
                {text}
              </div>
            ),
          },
          {
            title: '附件',
            dataIndex: 'images',
            search: false,
            render: (_, record) => {
              if (!Array.isArray(record.images) || record.images.length === 0) {
                return '无附件';
              }
              return (
                <div style={{ display: 'flex', flexWrap: 'wrap' }}>
                  {record.images.map((item: any, index: number) => {
                    if (item.type && item.type.includes('image')) {
                      return (
                        <Image
                          key={index}
                          width={40}
                          height={30}
                          src={item.url}
                          style={{
                            marginRight: 8,
                            marginBottom: 8,
                            objectFit: 'cover',
                          }}
                        />
                      );
                    } else if (item.type && item.type.includes('video')) {
                      return (
                        <video
                          key={index}
                          width={40}
                          height={30}
                          controls
                          style={{
                            marginRight: 8,
                            marginBottom: 8,
                            objectFit: 'cover',
                          }}
                          src={item.url}
                        />
                      );
                    }
                    return null;
                  })}
                </div>
              );
            },
          },
          MyColumns.CreatedAt(),
          // MyColumns.Option({
          //   render: (_, item: any, index, action) => (
          //     <Space key={index}>
          //       <CustomerOpinionShow
          //         item={item}
          //         title="详情"
          //         reload={action?.reload}
          //       />
          //       <MyButtons.Delete
          //         onConfirm={() =>
          //           Apis.Common.Admins.Delete({ id: item.id }).then(() =>
          //             action?.reload(),
          //           )
          //         }
          //       />
          //     </Space>
          //   ),
          // }),
        ]}
      />
    </MyPageContainer>
  );
}
