import { List, Loading } from '@taroify/core';
import { ReactNode } from 'react';

import './index.less';

interface IPlaceholderProps {
  hasMore: boolean;
  loadingMore: boolean;
  loadMoreError: boolean;
  noMoreText: ReactNode;
  loadMoreErrorText: ReactNode;
}

function ListPlaceholder(props: Partial<IPlaceholderProps>) {
  const { hasMore, loadingMore, loadMoreError, noMoreText, loadMoreErrorText } = props;

  let content: ReactNode = '';
  if (loadingMore) {
    content = <Loading>加载中...</Loading>;
  } else if (loadMoreError) {
    content = loadMoreErrorText ?? '加载失败，请下拉刷新重试';
  } else if (!hasMore) {
    content = noMoreText ?? '没有更多了';
  }

  if (!content) {
    return null;
  }

  return <List.Placeholder>{content}</List.Placeholder>;
}

export default ListPlaceholder;
