import type { FC } from 'react'
import React, { useState } 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 Modal from '@/app/components/base/modal'
import Button from '@/app/components/base/button'
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'
import { AlertCircle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback'
import { Trash03 } from '@/app/components/base/icons/src/vender/line/general'
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
  onDelete?: (segId: string) => Promise
  scene?: UsageScene
  className?: string
  archived?: boolean
  embeddingAvailable?: boolean
}
const SegmentCard: FC = ({
  detail = {},
  score,
  onClick,
  onChangeSwitch,
  onDelete,
  loading = true,
  scene = 'doc',
  className = '',
  archived,
  embeddingAvailable,
}) => {
  const { t } = useTranslation()
  const {
    id,
    position,
    enabled,
    content,
    word_count,
    hit_count,
    index_node_hash,
    answer,
  } = detail as Required['detail']
  const isDocScene = scene === 'doc'
  const [showModal, setShowModal] = useState(false)
  const renderContent = () => {
    if (answer) {
      return (
        <>
          
          
        >
      )
    }
    return content
  }
  return (
     onClick?.()}
    >
      
        {isDocScene
          ? <>
            
            
              {loading
                ? (
                  
                )
                : (
                  <>
                    
                    {embeddingAvailable && (
                      
                        
                        ) =>
                            e.stopPropagation()
                          }
                          className="inline-flex items-center"
                        >
                           {
                              await onChangeSwitch?.(id, val)
                            }}
                          />
                        
                       
                    )}
                  >
                )}
            
          >
          : (
            score !== null
              ? (
                
              )
              : null
          )}
      
      {loading
        ? (
          
        )
        : (
          isDocScene
            ? <>
              
                {renderContent()}
              
              
                
                  
                  {formatNumber(word_count)}
                 
                
                  
                  {formatNumber(hit_count)}
                 
                
                {!archived && embeddingAvailable && (
                  
 {
                    e.stopPropagation()
                    setShowModal(true)
                  }}>
                    
                  
                )}
              
 
            >
            : <>
              
                {renderContent()}
              
              
                
                
                  
                  
                    {t('datasetHitTesting.viewChart')}
                    
                   
               
            >
        )}
      {showModal && 
 setShowModal(false)} className={s.delModal} closable>
        
          
          {t('datasetDocuments.segment.delete')}
          
            
            
          
         
      }