import services from '@/services';
import { useRequest } from 'ahooks';
import { useEffect } from 'react';
import styles from './index.less';
import TopItem from './TopItem';
import { useModel } from '@umijs/max';
import EmptySpace from '@/components/EmptySpace';

export default ({ items }: { items: any }) => {
  const { initialState } = useModel('@@initialState');
  const { areaId } = initialState;
  const { data, runAsync } = useRequest(
    services.Physicalsign.getlistTopNItems,
    { manual: true },
  );
  useEffect(() => {
    if (!items) return;
    runAsync({
      objectId: items.objectId,
      indexId: items.id,
      n: 5,
      indexType: 1,
      physicalSignType: 1
    });
  }, [items?.objectId]);
  return (
    <div className={styles.container}>
      {
        data?.data?.length ? (
          <>
            {data?.data?.map((item, index) => {
              return <TopItem key={index} data={item} level={index + 1} />;
            })}
          </>
        ) : <EmptySpace describe="暂无数据" style={{ padding: '10% 0' }} />
      }
    </div>
  );
};
