import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type'
import { D1siteListType } from '@/pages/D_storeManage/D1storage/type'
import { D1_APIgetInfo } from '@/store/action/D1storage'
import { statusStorageObj } from '@/utils/tableData'
import React, { useCallback, useEffect, useState } from 'react'

type Props = {
  isLook?: boolean
  info: C1GoodType
}

function Y22com({ isLook, info }: Props) {
  const [detail, setDetail] = useState({} as D1siteListType)

  const getInfoFu = useCallback(async () => {
    if (info.siteId) {
      const res = await D1_APIgetInfo(info.siteId)
      if (res.code === 0) setDetail(res.data || {})
    }
  }, [info.siteId])

  useEffect(() => {
    getInfoFu()
  }, [getInfoFu])

  return (
    <div className='Y22com'>
      <div className='Y22sta'>库存状态：{statusStorageObj[info.statusStorage] || '（空）'}</div>

      {/* 表格 */}
      {!info.statusStorage || [0, 4, 6].includes(info.statusStorage) ? (
        <div className='Y22No'>当前状态无库存信息</div>
      ) : (
        <div className='Y22Info'>
          <div className='Y22row Y22row1'>
            <div>库存信息</div>
            <div>库存详情</div>
          </div>

          {info.id ? (
            <>
              <div className='Y22row'>
                <div>仓库名称</div>
                <div>{detail.storageName || '（空）'}</div>
              </div>
              <div className='Y22row'>
                <div>仓库编码</div>
                <div>{detail.num || '（空）'}</div>
              </div>
              <div className='Y22row'>
                <div>仓库负责人</div>
                <div>{detail.managerUser || '（空）'}</div>
              </div>
              <div className='Y22row'>
                <div>区域名称</div>
                <div>{detail.regionName || '（空）'}</div>
              </div>
              <div className='Y22row'>
                <div>排架</div>
                <div>{detail.layer1 || '（空）'}</div>
              </div>
              <div className='Y22row'>
                <div>层数</div>
                <div>{detail.layer2 || '（空）'}</div>
              </div>
              <div className='Y22row'>
                <div>层格</div>
                <div>{detail.layer3 || '（空）'}</div>
              </div>
            </>
          ) : (
            <div className='Y22rowNo'>暂无数据</div>
          )}
        </div>
      )}
    </div>
  )
}

const MemoY22com = React.memo(Y22com)

export default MemoY22com
