import type { FC } from 'react'
import React from 'react'
import cn from 'classnames'
import { ArrowUpRightIcon } from '@heroicons/react/24/outline'
import { useTranslation } from 'react-i18next'
import { StatusItem } from '../../list'
import { DocumentTitle } from '../index'
import s from './style.module.css'
import { SegmentIndexTag } from './index'
import Switch from '@/app/components/base/switch'
import Divider from '@/app/components/base/divider'
import Indicator from '@/app/components/header/indicator'
import { formatNumber } from '@/utils/format'
import type { SegmentDetailModel } from '@/models/datasets'
const ProgressBar: FC<{ percent: number; loading: boolean }> = ({ percent, loading }) => {
  return (
    
      
      {loading ? null : percent.toFixed(2)}
     
  )
}
export type UsageScene = 'doc' | 'hitTesting'
type ISegmentCardProps = {
  loading: boolean
  detail?: SegmentDetailModel & { document: { name: string } }
  score?: number
  onClick?: () => void
  onChangeSwitch?: (segId: string, enabled: boolean) => Promise
  scene?: UsageScene
  className?: string
}
const SegmentCard: FC = ({
  detail = {},
  score,
  onClick,
  onChangeSwitch,
  loading = true,
  scene = 'doc',
  className = '',
}) => {
  const { t } = useTranslation()
  const {
    id,
    position,
    enabled,
    content,
    word_count,
    hit_count,
    index_node_hash,
    answer,
  } = detail as any
  const isDocScene = scene === 'doc'
  const renderContent = () => {
    if (answer) {
      return (
        <>
          
          
        >
      )
    }
    return content
  }
  return (
     onClick?.()}
    >
      
        {isDocScene
          ? <>
            
            
              {loading
                ? (
                  
                )
                : (
                  <>
                    
                    
                      
                      ) =>
                          e.stopPropagation()
                        }
                        className="inline-flex items-center"
                      >
                         {
                            await onChangeSwitch?.(id, val)
                          }}
                        />
                      
                     
                  >
                )}
            
          >
          : 
}
      
      {loading
        ? (
          
        )
        : (
          isDocScene
            ? <>
              
                {renderContent()}
              
              
                
                  
                  {formatNumber(word_count)}
                 
                
                  
                  {formatNumber(hit_count)}
                 
                
               
            >
            : <>
              
                {renderContent()}
              
              
                
                
                  
                  
                    {t('datasetHitTesting.viewChart')}
                    
                   
                 
               
            >
        )}
    
 
  )
}
export default SegmentCard