import { MyBetaModalFormProps, MyButtons, renderTextHelper } from '@/common';
import { MyModal } from '@/components/MyModal';
import { Apis } from '@/gen/Apis';
import { CompanyEmployeesTypeEnum, SexEnum } from '@/gen/Enums';
import { ProCard, ProDescriptions } from '@ant-design/pro-components';
import { Space, Spin } from 'antd';
import { useState } from 'react';

export default function EmployeeShow(props: MyBetaModalFormProps) {
  const [loading, setLoading] = useState(true);
  const [data, setData] = useState<any>({});

  return (
    <MyModal
      title={props.title || '查看员工信息'}
      type={props.item?.type || 'primary'}
      width="600px"
      trigger={
        <MyButtons.View
          title={props.title || '查看'}
          type={props.item?.type || 'primary'}
        />
      }
      onOpen={() => {
        if (props?.item?.id) {
          setLoading(true);
          Apis.Company.CompanyEmployees.Show({ id: props.item.id })
            .then((res) => {
              setData(res?.data || {});
            })
            .catch((error) => {
              console.error('获取员工信息失败:', error);
            })
            .finally(() => {
              setLoading(false);
            });
        }
      }}
      node={
        <Space direction="vertical" style={{ width: '100%' }}>
          <ProCard>
            <Spin spinning={loading}>
              <ProDescriptions column={2} title="">
                <ProDescriptions.Item label="姓名">
                  {data?.name}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="工号">
                  {data?.employee_id}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="手机号">
                  {data?.phone}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="性别">
                  <renderTextHelper.Tag
                    Enums={SexEnum}
                    value={data?.sex || '-'}
                    key="sex"
                  />
                </ProDescriptions.Item>
                <ProDescriptions.Item label="员工类型">
                  <renderTextHelper.Tag
                    Enums={CompanyEmployeesTypeEnum}
                    value={data?.type || '-'}
                    key="type"
                  />
                </ProDescriptions.Item>
                <ProDescriptions.Item label="组织">
                  {data?.organizations_name}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="岗位">
                  {data?.positions_name}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="角色">
                  {data?.sys_roles_name}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="备注" span={2}>
                  {data?.remark}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="创建时间">
                  {data?.created_at}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="最近修改">
                  {data?.updated_at}
                </ProDescriptions.Item>
              </ProDescriptions>
            </Spin>
          </ProCard>
        </Space>
      }
    />
  );
}
