/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-03-03 15:18:14
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2025-02-18 15:09:20
 * @FilePath: /KC-MiddlePlatform/src/components/KCInput/index.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { createFromIconfontCN } from '@ant-design/icons';
import { ProFormText } from '@ant-design/pro-form';
import { ProFormFieldItemProps } from '@ant-design/pro-form/lib/interface';

import { Input, InputProps, InputRef } from 'antd';
import Password from 'antd/lib/input/Password';

export type KCInput = ProFormFieldItemProps<InputProps, InputRef> & {
  Password?: typeof Password;
  search?: boolean; //开启搜索输入
  onChange?: (e: any) => void;
  onSearch?: () => void;
  style?: React.CSSProperties | undefined;
  placeholder?: string | undefined;
};

const IconFont = createFromIconfontCN({
  scriptUrl: '',
});

export const KCInput = (props: KCInput) => {
  const { fieldProps, search, onChange, onSearch = () => {}, style, placeholder, ...rest } = props;

  if (search) {
    return (
      <Input
        allowClear
        onChange={(e) => onChange && onChange(e)}
        placeholder={placeholder}
        style={{ ...style }}
        suffix={<IconFont type="iconsousuo" onClick={() => onSearch()} />}
        onPressEnter={() => onSearch()}
      />
    );
  }

  return <ProFormText {...rest} style={{ ...style }} placeholder={placeholder} fieldProps={{ ...fieldProps }} />;
};
