import { type CodeConfigData } from '@/pages/CodeConfig/List';
import { Flex, Typography } from 'antd';
import classNames from 'classnames';
import { useState } from 'react';
import styles from './index.less';

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

function CodeConfigItem({ item, onClick }: CodeConfigItemProps) {
  const [isEllipsis, setIsEllipsis] = useState(false);
  return (
    <div className={styles['code-config-item']} onClick={() => onClick?.(item)}>
      <Flex justify="space-between" align="center" style={{ marginBottom: '15px' }}>
        <Typography.Paragraph
          className={styles['code-config-item__name']}
          ellipsis={{ tooltip: item.code_repo_name }}
        >
          {item.code_repo_name}
        </Typography.Paragraph>
        <div
          className={classNames(
            styles['code-config-item__tag'],
            item.is_public
              ? styles['code-config-item__tag--public']
              : styles['code-config-item__tag--private'],
          )}
        >
          {item.is_public ? '公开' : '私有'}
        </div>
      </Flex>
      <Typography.Paragraph
        className={styles['code-config-item__url']}
        ellipsis={{
          rows: 2,
          tooltip: isEllipsis ? item.git_url : false, // 仅当省略时显示 tooltip
          onEllipsis: (ellipsis) => setIsEllipsis(ellipsis),
        }}
      >
        {item.git_url}
      </Typography.Paragraph>
      <Typography.Paragraph
        className={styles['code-config-item__branch']}
        ellipsis={{ tooltip: item.git_branch }}
      >
        {item.git_branch}
      </Typography.Paragraph>
    </div>
  );
}

export default CodeConfigItem;
