import { L as ListView } from '../index-f41abfce.js';
export { L as default } from '../index-f41abfce.js';
import React__default, { forwardRef, useRef, useState, useEffect, useMemo, useImperativeHandle, useCallback } from 'react';
import { Tooltip, Checkbox } from 'antd';
import { InfiniteLoader, AutoSizer, List } from 'react-virtualized';
import IconFont from '../IconFont/index.js';
import CBox from '../CBox/index.js';
import { cloneDeep, debounce, concat } from 'lodash';
import { _ as _extends } from '../_rollupPluginBabelHelpers-736b301a.js';
import { C as CheckList } from '../index-6ef7005c.js';
import HightLevel from '../HightLevel/index.js';
import { useSize } from 'ahooks';
import { B as BaseList } from '../index-fcf1ad06.js';
import '@zenview/micro-utils';
import '../TreeTitle/index.js';
import '../SearchInput/index.js';
import '@zenview/micro-basic-library';

function computedCuurentGrid$1() {
  const width = document.body.clientWidth;
  if (width >= 1600) {
    return "xxl";
  }
  if (width >= 1200 && width < 1600) {
    return "xl";
  }
  if (width >= 992 && width < 1200) {
    return "lg";
  }
  if (width >= 768 && width < 992) {
    return "md";
  }
  if (width >= 576 && width < 768) {
    return "sm";
  }
  if (width < 576) {
    return "xs";
  }
}

// 切割数组 1维变2维
function arraySliceForX$1(arr, x = 3) {
  let newArr = [];
  for (let i = 0, l = arr.length; i < l; i++) {
    if (newArr.length === 0) {
      newArr.push([]);
    }
    if (newArr[newArr.length - 1].length > x - 1) {
      newArr.push([]);
    }
    newArr[newArr.length - 1].push(arr[i]);
  }
  return newArr;
}
const simpleGrid$1 = {
  xxl: 4,
  xl: 6,
  lg: 6,
  md: 7,
  sm: 24,
  xs: 24
};

const ScrollList$1 = /*#__PURE__*/forwardRef(function InfiniteScrollLayout(props, ref) {
  const {
    data,
    itemGrid,
    itemHeight,
    threshold,
    isNoData,
    className = '',
    hasLoadPrev,
    loadPrev,
    prethreshold
  } = props;
  const infiniteRef = useRef(null);
  const loadingRef = useRef(false);
  const scrollRef = useRef(false);
  const [showBackTop, setShowBackUp] = useState(false);
  const [currentGrid, setContentGrid] = useState(computedCuurentGrid$1());
  let debounced = null;
  useEffect(() => {
    const bindResizeEvent = () => {
      setContentGrid(computedCuurentGrid$1());
    };
    window.addEventListener('resize', bindResizeEvent, false);
    return () => {
      debounced && debounced.cancel();
      window.removeEventListener('resize', bindResizeEvent, false);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  const rowCount = useMemo(() => Math.floor(24 / itemGrid[currentGrid]), [itemGrid, currentGrid]);
  const renderData = useMemo(() => arraySliceForX$1(data, rowCount), [data, rowCount]);
  function forceUpdateGrid() {
    infiniteRef.current && infiniteRef.current._registeredChild.forceUpdateGrid();
  }
  function scrollToPosition(...args) {
    infiniteRef.current && infiniteRef.current._registeredChild.scrollToPosition(...args);
  }
  function scrollToRow(...args) {
    infiniteRef.current && infiniteRef.current._registeredChild.scrollToRow(...args);
  }
  useImperativeHandle(ref, () => ({
    forceUpdateGrid,
    scrollToRow,
    scrollToPosition
  }));
  const loadMore = async () => {
    if (props.hasLoadMore && props.loadMore && !loadingRef.current) {
      loadingRef.current = true;
      await props.loadMore();
      loadingRef.current = false;
    }
  };
  function onListScroll(options) {
    if (hasLoadPrev && !loadingRef.current && loadPrev && options.scrollTop === 0 && scrollRef.current) {
      loadingRef.current = true;
      loadPrev().then(dataLength => {
        if (dataLength) {
          const row = Math.ceil(dataLength / rowCount);
          if (row > 0) {
            scrollToPosition(row * itemHeight);
          }
        }
        loadingRef.current = false;
      });
    }
    if (!scrollRef.current && options.scrollTop >= prethreshold) {
      scrollRef.current = true;
    }
    debounced && debounced.cancel();
    debounced = debounce(() => {
      const flag = options.scrollTop > 200;
      if (showBackTop !== flag) {
        setShowBackUp(flag);
      }
      props.onScroll && props.onScroll(options);
    }, 500);
    debounced();
  }
  function rowRender({
    key,
    index,
    style
  }) {
    const {
      gutter,
      paddingRow,
      rowClass,
      hasLoadMore,
      itemClass
    } = props;
    let rowData = renderData[index] || [];
    let len = rowCount - rowData.length;
    if (rowData.length < rowCount) {
      for (let i = 0; i < len; i++) {
        rowData.push(null);
      }
    }
    return /*#__PURE__*/React__default.createElement("div", {
      key: key,
      style: {
        ...style,
        padding: `0 ${paddingRow}`
      },
      className: `row-group-part  ${rowClass}`
    }, rowData.map((v, i) => /*#__PURE__*/React__default.createElement("div", {
      key: `${key}-${i}`,
      className: `row-item-part ${v === null && hasLoadMore ? 'row-item-placeholder' : ''} ${v !== null ? itemClass : ''}`,
      style: {
        width: `${100 / 24 * itemGrid[currentGrid]}%`,
        height: itemHeight,
        marginRight: gutter,
        paddingBottom: gutter
      }
    }, v && props.renderItem(v, i))));
  }
  function _isRowLoaded({
    index
  }) {
    return !!renderData[index];
  }
  return /*#__PURE__*/React__default.createElement(CBox, {
    className: `lm-c-infinite-scroll-layout ${isNoData ? 'infinite-scroll-empty' : ''} ${className}`
  }, /*#__PURE__*/React__default.createElement(InfiniteLoader, {
    isRowLoaded: _isRowLoaded,
    loadMoreRows: loadMore,
    rowCount: renderData.length + 1,
    ref: infiniteRef,
    threshold: threshold
  }, ({
    onRowsRendered,
    registerChild
  }) => {
    return /*#__PURE__*/React__default.createElement(AutoSizer, null, ({
      width,
      height
    }) => /*#__PURE__*/React__default.createElement(List, {
      width: width,
      onRowsRendered: onRowsRendered,
      ref: registerChild,
      height: height,
      rowCount: renderData.length,
      rowHeight: itemHeight,
      rowRenderer: rowRender,
      onScroll: onListScroll
    }));
  }), props.hasBackTop && showBackTop && /*#__PURE__*/React__default.createElement(Tooltip, {
    title: "\u8FD4\u56DE\u9876\u90E8",
    placement: "top"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "scoll-back-top",
    onClick: () => scrollToPosition(0)
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Arrow_MoveUp"
  }))));
});
ScrollList$1.defaultProps = {
  itemHeight: 200,
  gutter: 20,
  itemGrid: cloneDeep(simpleGrid$1),
  hasLoadMore: true,
  hasLoadPrev: true,
  threshold: 5,
  prethreshold: 200,
  hasBackTop: false,
  data: []
};

/**
 * @列表剧中盒子
 * @param {*} props
 */
const ListBox$1 = props => {
  const {
    className = '',
    children,
    style = {},
    offsetOptions = {
      xxl: 2,
      xl: 1
    }
  } = props;
  const [offset, setOffset] = useState(() => {
    const offsetGrad = computedCuurentGrid$1();
    return offsetOptions[offsetGrad] ? offsetOptions[offsetGrad] : 0;
  });
  useEffect(() => {
    function resize() {
      const offsetGrad = computedCuurentGrid$1();
      setOffset(offsetOptions[offsetGrad] ? offsetOptions[offsetGrad] : 0);
    }
    window.addEventListener('resize', resize);
    return () => {
      window.removeEventListener('resize', resize);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  const paddingRow = useMemo(() => `${offset === 0 ? '20px' : 100 / 24 * offset + '%'}`, [offset]);
  return /*#__PURE__*/React__default.createElement("div", {
    style: style,
    className: className
  }, /*#__PURE__*/React__default.cloneElement(children, {
    paddingRow
  }));
};

const CardList$1 = ({
  className = '',
  data,
  offsetOptions = {
    xxl: 3,
    xl: 2
  },
  listRef,
  itemGrid,
  itemHeight,
  loadMore,
  hasLoadMore,
  isNoData,
  renderItem,
  gutter = 14,
  ...rest
}) => {
  return /*#__PURE__*/React__default.createElement(ListBox$1, {
    offsetOptions: offsetOptions,
    className: className
  }, /*#__PURE__*/React__default.createElement(ScrollList$1, _extends({
    ref: listRef,
    gutter: gutter,
    itemGrid: itemGrid,
    itemHeight: itemHeight,
    loadMore: loadMore,
    hasLoadMore: hasLoadMore,
    hasBackTop: true,
    isNoData: isNoData,
    data: data,
    renderItem: renderItem
  }, rest)));
};

function RenderItem({
  item,
  checkedKeys,
  activeKey,
  index,
  style,
  itemNameKey,
  renderItemExt,
  whatIcon,
  itemKey,
  checkable,
  keywords,
  onItemDrag,
  onItemDrop,
  onChecked,
  onClickItem,
  key,
  onMouseOverItem,
  onMouseOutItem
}) {
  const checked = checkedKeys ? checkedKeys.includes(item[itemKey]) : false;
  const active = !activeKey ? false : Array.isArray(activeKey) ? activeKey.includes(item[itemKey]) : activeKey === item[itemKey];
  const itemIcon = whatIcon ? whatIcon(item) : null;
  const itemClick = useCallback(e => {
    e.stopPropagation();
  }, []);
  return /*#__PURE__*/React__default.createElement("div", {
    style: style,
    className: `list-item ${checkable ? 'has-check-box' : ''} ${active ? 'list-item-active' : ''}`,
    draggable: true,
    key: key,
    onClick: () => onClickItem && onClickItem(item),
    onMouseOver: () => onMouseOverItem && onMouseOverItem(item),
    onMouseOut: () => onMouseOutItem && onMouseOutItem(item),
    onDragStart: e => onItemDrag(e, index),
    onDrop: e => onItemDrop(e, index),
    onDragOver: event => event.preventDefault()
  }, /*#__PURE__*/React__default.createElement("label", null, checkable && /*#__PURE__*/React__default.createElement(Checkbox, {
    value: item[itemKey],
    onClick: itemClick,
    checked: checked,
    onChange: onChecked
  }), /*#__PURE__*/React__default.createElement("div", {
    className: `item-info`
  }, itemIcon, keywords ? /*#__PURE__*/React__default.createElement(HightLevel, {
    name: item[itemNameKey],
    keyword: keywords
  }) : /*#__PURE__*/React__default.createElement("span", {
    title: item[itemNameKey]
  }, item[itemNameKey])), renderItemExt && renderItemExt(item)));
}

class DragList extends React__default.Component {
  constructor(...args) {
    super(...args);
    this.onItemDrag = (event, index) => {
      event.dataTransfer.setData('dragIndex', index);
    };
    this.onItemDrop = (event, index) => {
      const drapIndex = event.dataTransfer.getData('dragIndex');
      this.props.dragOver && this.props.dragOver({
        dragIndex: +drapIndex,
        dropIndex: index
      });
    };
  }
  render() {
    return /*#__PURE__*/React__default.createElement(CheckList, _extends({}, this.props, {
      CustomRender: /*#__PURE__*/React__default.createElement(RenderItem, {
        onItemDrag: this.onItemDrag,
        onItemDrop: this.onItemDrop
      })
    }));
  }
}

function computedCuurentGrid() {
  const width = document.body.clientWidth;
  if (width >= 1600) {
    return "xxl";
  }
  if (width >= 1200 && width < 1600) {
    return "xl";
  }
  if (width >= 992 && width < 1200) {
    return "lg";
  }
  if (width >= 768 && width < 992) {
    return "md";
  }
  if (width >= 576 && width < 768) {
    return "sm";
  }
  if (width < 576) {
    return "xs";
  }
}

// 切割数组 1维变2维
function arraySliceForX(arr, x = 3) {
  let newArr = [];
  for (let i = 0, l = arr.length; i < l; i++) {
    if (newArr.length === 0) {
      newArr.push([]);
    }
    if (newArr[newArr.length - 1].length > x - 1) {
      newArr.push([]);
    }
    newArr[newArr.length - 1].push(arr[i]);
  }
  return newArr;
}
const simpleGrid = {
  xxl: 4,
  xl: 6,
  lg: 6,
  md: 7,
  sm: 24,
  xs: 24
};

const ScrollList = /*#__PURE__*/forwardRef(function InfiniteScrollLayout(props, ref) {
  var _toppingRef$current;
  const {
    data,
    itemGrid,
    itemHeight,
    threshold,
    isNoData,
    className = '',
    toppingConfig,
    hasLoadPrev,
    loadPrev,
    prethreshold
  } = props;
  const infiniteRef = useRef(null);
  const loadingRef = useRef(false);
  const scrollRef = useRef(false);
  const toppingRef = useRef(false);
  const scrollbarWidth = getScrollbarWidth();
  const [showBackTop, setShowBackUp] = useState(false);
  const [topping, setTopping] = useState(false);
  const [currentGrid, setContentGrid] = useState(computedCuurentGrid());
  let debounced = null;
  useEffect(() => {
    const bindResizeEvent = () => {
      setContentGrid(computedCuurentGrid());
    };
    window.addEventListener('resize', bindResizeEvent, false);
    return () => {
      debounced && debounced.cancel();
      window.removeEventListener('resize', bindResizeEvent, false);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  const {
    toppingHeight,
    headerHeight,
    headerComponent,
    toppingComponent
  } = toppingConfig;
  const rowCount = useMemo(() => Math.floor(24 / itemGrid[currentGrid]), [itemGrid, currentGrid]);
  const renderData = useMemo(() => {
    let arr = arraySliceForX(data, rowCount);
    arr = concat([[], [], []], arr); //前3行渲染做特殊处理
    return arr;
  }, [data, rowCount]);
  function forceUpdateGrid() {
    infiniteRef.current && infiniteRef.current._registeredChild.forceUpdateGrid();
  }
  function scrollToPosition(...args) {
    infiniteRef.current && infiniteRef.current._registeredChild.scrollToPosition(...args);
  }
  function scrollToRow(...args) {
    infiniteRef.current && infiniteRef.current._registeredChild.scrollToRow(...args);
  }
  useImperativeHandle(ref, () => ({
    forceUpdateGrid,
    scrollToRow,
    scrollToPosition
  }));
  const loadMore = async () => {
    if (props.hasLoadMore && props.loadMore && !loadingRef.current) {
      loadingRef.current = true;
      await props.loadMore();
      loadingRef.current = false;
    }
  };
  function onListScroll(options) {
    if (options.scrollTop >= headerHeight) {
      setTopping(true);
    } else {
      setTopping(false);
    }
    if (hasLoadPrev && !loadingRef.current && loadPrev && options.scrollTop === 0 && scrollRef.current) {
      loadingRef.current = true;
      loadPrev().then(dataLength => {
        if (dataLength) {
          const row = Math.ceil(dataLength / rowCount);
          if (row > 0) {
            scrollToPosition(row * itemHeight);
          }
        }
        loadingRef.current = false;
      });
    }
    if (!scrollRef.current && options.scrollTop >= prethreshold) {
      scrollRef.current = true;
    }
    debounced && debounced.cancel();
    debounced = debounce(() => {
      const flag = options.scrollTop > 200;
      if (showBackTop !== flag) {
        setShowBackUp(flag);
      }
      props.onScroll && props.onScroll(options);
    }, 100);
    debounced();
  }
  function getScrollbarWidth() {
    let scrollDiv = document.createElement('div');
    scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;';
    document.body.appendChild(scrollDiv);
    let scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
    document.body.removeChild(scrollDiv);
    return scrollbarWidth;
  }
  function rowRender({
    key,
    index,
    style
  }) {
    const {
      gutter,
      paddingRow,
      rowClass,
      hasLoadMore,
      itemClass
    } = props;
    let rowData = renderData[index] || [];
    let len = rowCount - rowData.length;
    if (rowData.length < rowCount) {
      for (let i = 0; i < len; i++) {
        rowData.push(null);
      }
    }
    return /*#__PURE__*/React__default.createElement("div", {
      key: key,
      style: {
        ...style,
        padding: `0 ${paddingRow}`
      },
      className: `row-group-part  ${rowClass}`
    }, (rowData === null || rowData === void 0 ? void 0 : rowData.length) && rowData.map((v, i) => /*#__PURE__*/React__default.createElement("div", {
      key: `${key}-${i}`,
      className: `row-item-part ${v === null && hasLoadMore ? 'row-item-placeholder' : ''} ${v !== null ? itemClass : ''}`,
      style: {
        width: `${100 / 24 * itemGrid[currentGrid]}%`,
        height: itemHeight,
        marginRight: gutter,
        paddingBottom: gutter
      }
    }, v && props.renderItem(v, i))));
  }
  const size = useSize(toppingRef.current && ((_toppingRef$current = toppingRef.current) === null || _toppingRef$current === void 0 ? void 0 : _toppingRef$current.querySelector('.ReactVirtualized__Grid__innerScrollContainer')));
  const boxSize = useSize(toppingRef.current);
  const hasScrollbar = useMemo(() => (boxSize === null || boxSize === void 0 ? void 0 : boxSize.width) - (size === null || size === void 0 ? void 0 : size.width) !== 0, [boxSize === null || boxSize === void 0 ? void 0 : boxSize.width, size === null || size === void 0 ? void 0 : size.width]);
  function _isRowLoaded({
    index
  }) {
    return !!renderData[index];
  }
  const boxWidth = useMemo(() => hasScrollbar ? `calc(100% - ${scrollbarWidth}px)` : '100%', [hasScrollbar, scrollbarWidth]);
  console.log(boxWidth);
  return /*#__PURE__*/React__default.createElement(CBox, {
    boxRef: toppingRef,
    className: `lm-c-top-scroll-layout  ${className}`
  }, /*#__PURE__*/React__default.createElement("div", {
    style: {
      width: boxWidth
    },
    className: "topping-scroll-tip"
  }), topping ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
    style: {
      width: boxWidth,
      height: toppingHeight,
      top: 0,
      zIndex: 22,
      boxShadow: topping ? '0px 5px 14px rgba(0, 0, 0, 0.05)' : 'none'
    },
    className: "list-topping-box"
  }, toppingComponent), /*#__PURE__*/React__default.createElement("div", {
    style: {
      width: boxWidth
    },
    className: "topping-scroll-tip-mask"
  }), " ") : '', /*#__PURE__*/React__default.createElement(InfiniteLoader, {
    isRowLoaded: _isRowLoaded,
    loadMoreRows: loadMore,
    rowCount: renderData.length + 1,
    ref: infiniteRef,
    threshold: threshold
  }, ({
    onRowsRendered,
    registerChild
  }) => {
    return /*#__PURE__*/React__default.createElement(AutoSizer, null, ({
      width,
      height
    }) => {
      return /*#__PURE__*/React__default.createElement(List, {
        width: width,
        onRowsRendered: onRowsRendered,
        ref: registerChild,
        height: headerHeight + toppingHeight >= height ? headerHeight + toppingHeight : height - 20,
        rowCount: renderData.length,
        rowHeight: item => {
          if (toppingConfig) {
            if (item.index === 0) {
              return headerHeight || 0;
            }
            if (item.index === 1) {
              return toppingHeight || 0;
            }
            if (item.index === 2) {
              return 0;
            }
          }
          return itemHeight;
        },
        rowRenderer: item => {
          if (toppingConfig) {
            if (item.index === 0) {
              return headerComponent;
            }
            if (item.index === 1) {
              return /*#__PURE__*/React__default.createElement("div", {
                style: {
                  height: toppingHeight,
                  opacity: topping ? 0 : 1
                },
                className: ` list-topping-box`
              }, toppingComponent);
            }
            if (item.index === 2) {
              return isNoData ? /*#__PURE__*/React__default.createElement("div", {
                className: "topping-scroll-nodata-view",
                style: {
                  height: `calc(100% - ${headerHeight + toppingHeight}px)`,
                  top: `${headerHeight + toppingHeight}px`,
                  backgroundPosition: `center ${100}px`
                }
              }) : topping ? null : /*#__PURE__*/React__default.createElement("div", {
                style: {
                  top: headerHeight,
                  height
                },
                className: "topping-scroll-tip-inner"
              });
            }
          }
          return rowRender(item);
        },
        onScroll: onListScroll
      });
    });
  }), props.hasBackTop && showBackTop && /*#__PURE__*/React__default.createElement(Tooltip, {
    title: "\u8FD4\u56DE\u9876\u90E8",
    placement: "top"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "scoll-back-top",
    onClick: () => scrollToPosition(0)
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-a-zhiding3"
  }))));
});
ScrollList.defaultProps = {
  itemHeight: 200,
  gutter: 20,
  itemGrid: cloneDeep(simpleGrid),
  hasLoadMore: true,
  hasLoadPrev: true,
  threshold: 5,
  prethreshold: 200,
  hasBackTop: false,
  data: []
};

/**
 * @列表剧中盒子
 * @param {*} props
 */
const ListBox = props => {
  const {
    className = '',
    children,
    style = {},
    offsetOptions = {
      xxl: 2,
      xl: 1
    }
  } = props;
  const [offset, setOffset] = useState(() => {
    const offsetGrad = computedCuurentGrid$1();
    return offsetOptions[offsetGrad] ? offsetOptions[offsetGrad] : 0;
  });
  useEffect(() => {
    function resize() {
      const offsetGrad = computedCuurentGrid$1();
      setOffset(offsetOptions[offsetGrad] ? offsetOptions[offsetGrad] : 0);
    }
    window.addEventListener('resize', resize);
    return () => {
      window.removeEventListener('resize', resize);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  const paddingRow = useMemo(() => `${offset === 0 ? '20px' : 100 / 24 * offset + '%'}`, [offset]);
  return /*#__PURE__*/React__default.createElement("div", {
    style: style,
    className: className
  }, /*#__PURE__*/React__default.cloneElement(children, {
    paddingRow
  }));
};

const CardList = ({
  className = '',
  data,
  offsetOptions = {
    xxl: 3,
    xl: 2
  },
  listRef,
  itemGrid,
  itemHeight,
  loadMore,
  hasLoadMore,
  isNoData,
  renderItem,
  gutter = 14,
  ...rest
}) => {
  return /*#__PURE__*/React__default.createElement(ListBox, {
    offsetOptions: offsetOptions,
    style: {
      position: 'relative'
    },
    className: className
  }, /*#__PURE__*/React__default.createElement(ScrollList, _extends({
    ref: listRef,
    gutter: gutter,
    itemGrid: itemGrid,
    itemHeight: itemHeight,
    loadMore: loadMore,
    hasLoadMore: hasLoadMore,
    hasBackTop: true,
    isNoData: isNoData,
    data: data,
    renderItem: renderItem
  }, rest)));
};

ListView.ScrollList = ScrollList$1;
ListView.CardList = CardList$1;
ListView.CheckList = CheckList;
ListView.DragList = DragList;
ListView.TopScrollList = ScrollList;
ListView.TopCardList = CardList;
ListView.Base = BaseList;
//# sourceMappingURL=index.js.map
