import FactoryItem from './FactoryItem';
import { useEffect } from 'react';
import QualityAbnormal from './qualityAbnormal';
import DeviceAbnormal from './deviceAbnormal';
import DeviceCountTable from './deviceCount';
import styles from '../../index.less';
import { Modal } from 'antd';
import { useState } from 'react';
import { useIntl } from 'umi';
type EquipmentDetailCriteria = KANBAN.ProductionComprehens.EquipmentDetailCriteria;
type ErrorDetailSetting = KANBAN.ProductionComprehens.ErrorDetailSetting;

const Abnormal: React.FC<{
  abnormalProdData: any;
  abnormalQualityData: any;
  abnormalDeviceData: any;
  factoryLine: Array<any>;
  setting: ErrorDetailSetting;
}> = ({ abnormalProdData, abnormalQualityData, abnormalDeviceData, factoryLine, setting, }) => {
  const intl = useIntl();
  const [isModalOpen, setIsModalOpen] = useState(false);
  const [criteria, setCriteria] = useState<EquipmentDetailCriteria>();
  const closeModal = () => setIsModalOpen(false);
  const openModal = (type: number) => {
    setIsModalOpen(true);
    setCriteria({
      workshopName: setting.workshopName || '',
      current: 1,
      pageSize: 10,
      status: type,
    });
  };
  useEffect(() => {
    let timer: NodeJS.Timer | null = null;
    let leftScroll = document.getElementById('leftScroll')
    if (leftScroll) {
      if (timer !== null) clearInterval(timer);
      timer = setInterval(() => {
        leftScroll.scrollTop += 40
        if (leftScroll.scrollTop + leftScroll.offsetHeight >= leftScroll.scrollHeight) {
          leftScroll.scrollTop = 0
        }
      }, setting.rowMovingTime * 1000)
    }
    return () => {
      if (timer !== null) clearInterval(timer);
    }
  }, [setting]);
  return (
    <>
      <div className={styles.leftWrapper} id="leftScroll">
        {factoryLine.map((factory) => (
          <div className={styles.Factorycard} >
            <div>{factory.name}</div>
            <div className={styles.itemContainer} >
              <FactoryItem data={factory.arr} setting={setting} />
            </div>
          </div>
        ))}
      </div>
    </>
  );
};

export default Abnormal;
