import { ProTable, type ProColumns } from '@ant-design/pro-components';
import { Tag } from 'antd';
import PageContainer from '@/components/common/PageContainer';
import { companyApi, CompanyResp, CompanySearchParam } from '@/api/company';

export default function CompanyList() {
  const columns: ProColumns<CompanyResp>[] = [
    { title: '검색어', dataIndex: 'searchKeyword', hideInTable: true,
      fieldProps: { placeholder: '회사명 / 사업자번호' } },
    { title: '회사코드', dataIndex: 'companyCode', width: 100, search: false },
    { title: '회사명', dataIndex: 'companyName', width: 180,
      render: (_, r) => <strong>{r.companyName}</strong> },
    { title: '구분', dataIndex: 'companyType', width: 100, search: false },
    { title: '사업자번호', dataIndex: 'bizNo', width: 130, search: false },
    { title: '담당자', dataIndex: 'contactName', width: 100, search: false },
    { title: '연락처', dataIndex: 'contactPhone', width: 130, search: false },
    { title: '이메일', dataIndex: 'contactEmail', width: 200, search: false },
    {
      title: '활성', dataIndex: 'isActive', width: 80,
      render: (_, r) => <Tag color={r.isActive === 'Y' ? 'success' : 'default'}>
        {r.isActive === 'Y' ? '활성' : '비활성'}</Tag>,
    },
  ];

  return (
    <PageContainer title="보험사 관리" description="제휴 보험사 정보 / 데이터 수신 프로파일">
      <ProTable<CompanyResp, CompanySearchParam>
        rowKey="companyId"
        columns={columns}
        request={async (params) => {
          const { current, pageSize, ...rest } = params as any;
          const res = await companyApi.list({ ...rest, pageNum: current, pageSize });
          return { data: res.list, total: res.total, success: true };
        }}
        pagination={{ pageSize: 20, showTotal: (t) => `총 ${t.toLocaleString()}건` }}
        search={{ labelWidth: 'auto', searchText: '검색', resetText: '초기화', collapsed: false, collapseRender: false }}
        options={{ density: false, fullScreen: true, reload: true, setting: true }}
        dateFormatter="string"
      />
    </PageContainer>
  );
}
