import clock from '@/assets/img/clock.png';
import creatByImg from '@/assets/img/creatBy.png';
import KFIcon from '@/components/KFIcon';
import { AvailableRange } from '@/enums';
import { type CodeConfigData } from '@/pages/CodeConfig/List';
import { formatDate } from '@/utils/date';
import { Button, Flex, Typography } from 'antd';
import styles from './index.less';

type CodeConfigItemProps = {
  item: CodeConfigData;
  onClick?: (item: CodeConfigData) => void;
  onRemove?: (item: CodeConfigData) => void;
};

function CodeConfigItem({ item, onClick, onRemove }: CodeConfigItemProps) {
  return (
    <div className={styles['code-config-item']} onClick={() => onClick?.(item)}>
      <Flex justify="space-between" align="center" style={{ marginBottom: '20px', height: '32px' }}>
        <Typography.Paragraph
          className={styles['code-config-item__name']}
          ellipsis={{ tooltip: item.code_repo_name }}
        >
          {item.code_repo_name}
        </Typography.Paragraph>
        <div className={styles['code-config-item__tag']}>
          {item.code_repo_vis === AvailableRange.Public ? '公开' : '私有'}
        </div>
        <Button
          type="text"
          shape="circle"
          style={{ marginLeft: 'auto', right: 0 }}
          onClick={(e) => {
            e.stopPropagation();
            onRemove?.(item);
          }}
        >
          <KFIcon type="icon-shanchu" font={17} />
        </Button>
      </Flex>
      <Typography.Paragraph
        className={styles['code-config-item__url']}
        ellipsis={{ tooltip: item.git_url }}
        style={{ marginBottom: '8px' }}
      >
        {item.git_url}
      </Typography.Paragraph>
      <div className={styles['code-config-item__url']} style={{ marginBottom: '20px' }}>
        {item.git_branch}
      </div>
      <Flex justify="space-between">
        <div className={styles['code-config-item__time']}>
          <img style={{ width: '17px', marginRight: '6px' }} src={creatByImg} alt="" />
          <span>{item.create_by}</span>
        </div>
        <div className={styles['code-config-item__time']}>
          <img style={{ width: '12px', marginRight: '5px' }} src={clock} alt="" />
          <span>最近更新: {formatDate(item.update_time, 'YYYY-MM-DD')}</span>
        </div>
      </Flex>
    </div>
  );
}

export default CodeConfigItem;
