'use client'

import { useEffect, useState, useContext } from 'react'
import { useRecoilValue } from 'recoil'
import { floorPlanObjectState } from '@/store/floorPlanObjectAtom'
import { useMessage } from '@/hooks/useMessage'
import { useCanvasMenu } from '@/hooks/common/useCanvasMenu'
import SingleDatePicker from '../common/datepicker/SingleDatePicker'
import EstimateFileUploader from './EstimateFileUploader'
import { useAxios } from '@/hooks/useAxios'
import { globalLocaleStore } from '@/store/localeAtom'
import { isEmptyArray, isNotEmptyArray, isObjectNotEmpty, queryStringFormatter } from '@/util/common-utils'
import dayjs from 'dayjs'
import { useCommonCode } from '@/hooks/common/useCommonCode'
import { useEstimateController } from '@/hooks/floorPlan/estimate/useEstimateController'
import { SessionContext } from '@/app/SessionProvider'
import Select, { components } from 'react-select'
import { convertNumberToPriceDecimal, convertNumberToPriceDecimalToFixed } from '@/util/common-utils'
import ProductFeaturesPop from './popup/ProductFeaturesPop'
import { v4 as uuidv4 } from 'uuid'

export default function Estimate({ params }) {
  const [uniqueData, setUniqueData] = useState([])
  const [handlePricingFlag, setHandlePricingFlag] = useState(false)
  const [specialNoteFirstFlg, setSpecialNoteFirstFlg] = useState(false)
  const fixedKey = 'itemKey'
  const [itemChangeYn, setItemChangeYn] = useState(false)
  const { session } = useContext(SessionContext)
  const [objectNo, setObjectNo] = useState('') //물건번호
  const [planNo, setPlanNo] = useState('') //플랜번호

  const [files, setFiles] = useState([]) // 보내는 첨부파일
  const [originFiles, setOriginFiles] = useState([]) //기존 첨부파일

  const [showPriceCd, setShowPriceCd] = useState('')

  const [showContentCode, setShowContentCode] = useState('ATTR001')

  const [productFeaturesPopupOpen, setProductFeaturesPopupOpen] = useState(false) //견적특이사항 팝업
  const [showProductFeatureData, setShowProductFeatureData] = useState([]) //팝업에 보여줄 견적특이사항 데이터

  const [selection, setSelection] = useState(new Set())
  //견적특이사항 접고 펼치기
  const [hidden, setHidden] = useState(false)

  //아이템 자동완성 리스트
  const [displayItemList, setDisplayItemList] = useState([])

  //공통코드
  const { findCommonCode } = useCommonCode()
  const [honorificCodeList, setHonorificCodeList] = useState([]) //경칭 공통코드

  const [storePriceList, setStorePriceList] = useState([]) //가격표시 option

  const [startDate, setStartDate] = useState(new Date())
  const singleDatePickerProps = {
    startDate,
    setStartDate,
  }

  const objectRecoil = useRecoilValue(floorPlanObjectState)

  //견적서 상세데이터
  const { estimateContextState, setEstimateContextState, addItem, handleEstimateFileDownload } = useEstimateController(params.pid)

  //견적특이사항 List
  const [specialNoteList, setSpecialNoteList] = useState([])
  const [popShowSpecialNoteList, setPopShowSpecialNoteList] = useState([])

  const globalLocaleState = useRecoilValue(globalLocaleStore)
  const { get, promisePost } = useAxios(globalLocaleState)

  const { getMessage } = useMessage()

  const { setMenuNumber } = useCanvasMenu()

  //새로 추가한 첨부파일 props
  const fileUploadProps = {
    uploadFiles: files,
    setUploadFiles: setFiles,
  }

  useEffect(() => {
    setMenuNumber(5)
    setObjectNo(objectRecoil.floorPlanObjectNo)
    setPlanNo(params.pid)

    // 공통코드
    const code1 = findCommonCode(200800)
    if (code1 != null) {
      setHonorificCodeList(code1)
    }

    //아이템 자동완성 목록 가져오기
    const param = {
      saleStoreId: session.storeId,
    }
    const apiUrl = `/api/display-item/item-list?${queryStringFormatter(param)}`
    get({ url: apiUrl }).then((res) => {
      if (res.length > 0) {
        setDisplayItemList(res)
      }
    })
    //견적특이사항 API호출
    //여러개 선택하면 구분자로 (、)
    //제품영역 팝업용
    let url = '/api/estimate/special-note-list'
    get({ url: url }).then((res) => {
      if (isNotEmptyArray(res)) {
        setPopShowSpecialNoteList(res)
      }
    })
  }, [])

  useEffect(() => {
    //견적특이사항 API호출
    //여러개 선택하면 구분자로 (、)
    //체크용
    if (!specialNoteFirstFlg) {
      let url = `/api/estimate/special-note-title-list`
      get({ url: url }).then((res) => {
        if (isNotEmptyArray(res)) {
          if (estimateContextState?.estimateOption) {
            res.map((row) => {
              let estimateOption = estimateContextState?.estimateOption?.split('、')
              row.check = false
              estimateOption.map((row2) => {
                if (row.pkgYn === '0') {
                  if (row2 === row.code) {
                    row.check = true
                  }
                } else {
                  if (row.code.includes(row2)) {
                    row.check = true
                    return
                  }
                }
              })
              //detail과 상관없이 디폴트 체크목록
              //ATTR003,ATTR007
              if (row.code === 'ATTR003') {
                row.check = true
              }
              if (row.code === 'ATTR007') {
                row.check = true
              }
            })

            setSpecialNoteList(res)

            setSpecialNoteFirstFlg(true)
          }
        }
      })
    }
  }, [estimateContextState?.estimateOption])

  //API데이터로 견적일 셋팅
  let begin = 1
  useEffect(() => {
    if (begin === 1) {
      setStartDate(estimateContextState?.estimateDate)
      begin++
    }
  }, [estimateContextState?.estimateDate])

  //견적일 set
  useEffect(() => {
    let estimateDate = dayjs(startDate).format('YYYY-MM-DD')
    if (begin === 1) {
      setEstimateContextState({ estimateDate: estimateDate })
    }
  }, [startDate])

  useEffect(() => {
    //선택된 견적특이사항 setEstimateContextState

    if (isNotEmptyArray(specialNoteList)) {
      const liveCheckedData = specialNoteList.filter((row) => row.check === true)

      const data = []
      for (let ele of liveCheckedData) {
        data.push(ele.code)
      }

      const newData = data.join('、')
      //저장용 보내기
      setEstimateContextState({ estimateOption: newData, specialNoteList: specialNoteList, uniqueData: uniqueData })
    }
  }, [specialNoteList])

  // 견적특이사항 remark 보여주기
  const settingShowContent = (code) => {
    setShowContentCode(code)
    // event.stopPropagation()
  }

  // 추가한 첨부파일 estimateContextState에 넣기
  useEffect(() => {
    if (isNotEmptyArray(files)) {
      let fileList = []
      files.map((row) => {
        fileList.push(row.data)
        setEstimateContextState({ fileList: row.data, newFileList: fileList })
      })
    } else {
      setEstimateContextState({ fileList: [] })
    }
  }, [files])

  useEffect(() => {
    // console.log('USEEFFECT originFiles::::::::::', originFiles)
    // if (originFiles.length > 0) {
    //   setEstimateContextState({
    //     originFiles: originFiles,
    //   })
    // }
  }, [originFiles])

  //상세에서 내려온 첨부파일 set 만들기
  useEffect(() => {
    if (isNotEmptyArray(estimateContextState.fileList)) {
      //드래그영역 비워주기
      setFiles([])
      setOriginFiles(estimateContextState.fileList)
    }
  }, [estimateContextState?.fileList])

  // 삭제누른 첨부파일 복원
  const returnOriginFile = (no) => {
    originFiles.map((file) => {
      if (file.no === no) {
        file.delFlg = '0'
      }
    })
    setOriginFiles((prev) => {
      return [...prev]
    })
    setEstimateContextState({
      originFiles: originFiles,
    })
  }
  // 기존첨부파일 삭제 (플래그값 추가?) 저장할때 플래그값에 따라 진짜 삭제
  const deleteOriginFile = (no) => {
    originFiles.map((file) => {
      if (file.no === no) {
        file.delFlg = '1'
      }
    })

    setOriginFiles((prev) => {
      return [...prev]
    })
    setEstimateContextState({
      originFiles: originFiles,
    })
    alert(getMessage('estimate.detail.alert.delFile'))
  }

  //가격표시 option 목록 최초세팅 && 주문분류 변경시
  useEffect(() => {
    if (estimateContextState.estimateType !== '') {
      const param = {
        saleStoreId: session.storeId,
        sapSalesStoreCd: session.custCd,
        docTpCd: estimateContextState?.estimateType,
      }

      const apiUrl = `/api/estimate/price/store-price-list?${queryStringFormatter(param)}`
      get({ url: apiUrl }).then((res) => {
        if (isNotEmptyArray(res?.data)) {
          setStorePriceList(res.data)
        }
      })

      if (estimateContextState.estimateType === 'YJSS') {
        if (specialNoteList.length > 0) {
          specialNoteList.map((item) => {
            if (item.code === 'ATTR002') {
              item.check = false
            }
          })
        }

        //YJSS UNIT_PIRCE로 프라이싱 실행
        if (handlePricingFlag) {
          handlePricing('UNIT_PRICE')
        }
      } else {
        if (specialNoteList.length > 0) {
          specialNoteList.map((item) => {
            if (item.code === 'ATTR002') {
              item.check = true
            }
          })
        }

        //YJOD로 돌아가도 UNIT_PRICE로 프라이싱 실행해서 정가로 셋팅
        if (handlePricingFlag) {
          handlePricing('UNIT_PRICE')
        }
      }

      setItemChangeYn(true)
    }
  }, [estimateContextState?.estimateType])

  useEffect(() => {
    if (estimateContextState?.priceCd) {
      setShowPriceCd(estimateContextState.priceCd)
    }
  }, [estimateContextState?.priceCd])

  //가격 표시 option 변경 이벤트
  const onChangeStorePriceList = (priceCd) => {
    const param = {
      saleStoreId: session.storeId,
      sapSalesStoreCd: session.custCd,
      docTpCd: priceCd,
    }

    //프라이싱 했을때 priceCd setEstimateContextState
    //화면에 보여지는 값은 showPriceCd로 관리
    setShowPriceCd(priceCd)

    const apiUrl = `/api/estimate/price/store-price-list?${queryStringFormatter(param)}`
    get({ url: apiUrl }).then((res) => {
      if (isNotEmptyArray(res?.data)) {
        setStorePriceList(res.data)
      }
    })
  }

  const makeUniqueSpecialNoteCd = (itemList) => {
    let pushData = []
    let uniquSet = new Set()

    itemList.forEach((item) => {
      if (item.delFlg === '0') {
        if (item.specialNoteCd) {
          let splitData = item.specialNoteCd.split('、')
          splitData.forEach((note) => {
            if (!uniquSet.has(note)) {
              uniquSet.add(note)
              pushData.push(note)
            }
          })

          setSpecialNoteFirstFlg(false)
        }
      }
    })

    setUniqueData(pushData)
    specialNoteList.map((item) => {
      if (item.pkgYn === '1') {
        let flg = '0'
        let codes = item.code
        for (let i = 0; i < pushData.length; i++) {
          if (codes.indexOf(pushData[i]) > -1) {
            flg = '1'
          }
        }

        if (flg === '1') {
          item.check = true
        } else {
          item.check = false
        }
      }
    })
    setEstimateContextState({
      specialNoteList: specialNoteList,
      uniqueData: uniqueData,
    })
  }

  //Pricing 버튼
  const handlePricing = async (showPriceCd) => {
    const param = {
      saleStoreId: session.storeId,
      sapSalesStoreCd: session.custCd,
      docTpCd: estimateContextState.estimateType,
      priceCd: showPriceCd,
      itemIdList: estimateContextState.itemList.filter((item) => item.delFlg === '0' && item.paDispOrder === null),
    }

    if (param.itemIdList.length > 0) {
      let pass = true

      param.itemIdList.map((item) => {
        if (item.itemId === '') {
          pass = false
        }
      })

      if (!pass) {
        //Pricing이 누락된 아이템이 있습니다. Pricing을 진행해주세요.
        return alert(getMessage('estimate.detail.showPrice.pricingBtn.noItemId'))
      }
    }

    await promisePost({ url: '/api/estimate/price/item-price-list', data: param }).then((res) => {
      let updateList = []
      if (res) {
        if (res.status === 200) {
          const data = res.data
          //기존itemList랑 프라이싱결과랑 비교해서 단가만 업뎃 서로 갯수가 안맞을 수 있음 없는 itemId면 unitPrice 0으로
          //itemId로 비교해서 salePrice만 업데이트
          if (data.result.code === 200) {
            setEstimateContextState({
              pkgAsp: data?.data?.pkgUnitPrice,
            })
            //주택PKG단가 체인지 이벤트 발생시키기
            onChangePkgAsp(data.data.pkgUnitPrice)

            if (isNotEmptyArray(data.data2)) {
              estimateContextState.itemList.map((item) => {
                // console.log('기존아이템::', item)
                let checkYn = false
                for (let i = 0; i < data.data2.length; i++) {
                  // console.log('프라이싱결과아이템:::', data.data2[i])
                  if (data.data2[i]) {
                    if (data.data2[i].itemId === item.itemId) {
                      updateList.push({
                        ...item,
                        openFlg: data.data2[i].unitPrice === '0.0' ? '1' : '0',
                        salePrice: data.data2[i].unitPrice === null ? '0' : data.data2[i].unitPrice,
                        saleTotPrice: (item.amount * data.data2[i].unitPrice).toString(),
                      })
                      checkYn = true
                      break
                    }
                  }
                }

                if (!checkYn) {
                  updateList.push({ ...item, salePrice: '0', saleTotPrice: '0' })
                }
              })

              setEstimateContextState({
                priceCd: showPriceCd,
                itemList: updateList,
              })

              setItemChangeYn(true)
            }
          }
        }
      }
    })
  }

  const getAbledItems = (items) => {
    return items.filter((items) => items.paDispOrder === null)
  }

  const onChangeSelectAll = (e) => {
    if (e.target.checked) {
      const allCheckedSelection = new Set(getAbledItems(estimateContextState.itemList).map((item) => item.dispOrder))

      setSelection(allCheckedSelection)
    } else {
      setSelection(new Set())
    }
  }

  const isSelectedAll = () => {
    return selection.size === getAbledItems(estimateContextState.itemList).length
  }

  //row 체크박스 컨트롤
  const onChangeSelect = (dispOrder) => {
    const newSelection = new Set(selection)
    if (newSelection.has(dispOrder)) {
      newSelection.delete(dispOrder)
    } else {
      newSelection.add(dispOrder)
    }

    setSelection(newSelection)
  }

  //주택PKG input 변경
  const onChangePkgAsp = (value) => {
    if (estimateContextState.estimateType === 'YJSS') {
      let pkgAsp = Number(value.replace(/[^-\.0-9]/g, '').replaceAll(',', ''))
      if (isNaN(pkgAsp)) {
        pkgAsp = 0
      } else {
        pkgAsp = pkgAsp.toLocaleString()
      }
      //현재 PKG용량값 가져오기

      let totVolKw = estimateContextState.totVolKw * 1000
      let pkgTotPrice = pkgAsp?.replaceAll(',', '') * totVolKw * 1000

      setEstimateContextState({
        pkgAsp: pkgAsp,
        pkgTotPrice: pkgTotPrice.toFixed(3),
      })
      //아이템들 중 조건에 맞는애들 뽑아서 상단 공급가액 부가세 총액 수정
      setItemChangeYn(true)
    }
  }

  // 수량 변경
  const onChangeAmount = (value, dispOrder, index) => {
    //itemChangeFlg = 1, partAdd = 0 셋팅
    let amount = Number(value.replace(/[^0-9]/g, '').replaceAll(',', ''))
    if (isNaN(amount)) {
      amount = '0'
    } else {
      amount = amount.toLocaleString()
    }

    let updateList = []
    let updates = {}
    updates.amount = amount
    updates.itemChangeFlg = '1'
    updates.partAdd = '0'
    updates.saleTotPrice = (Number(amount.replaceAll(',', '')) * estimateContextState.itemList[index].salePrice.replaceAll(',', '')).toLocaleString()
    updates.showSaleTotPrice = (
      Number(amount.replaceAll(',', '')) * estimateContextState.itemList[index].showSalePrice?.replaceAll(',', '')
    ).toLocaleString()

    updateList = estimateContextState.itemList.map((item) => {
      if (item.dispOrder === dispOrder) {
        return { ...item, ...updates }
      } else if (item.paDispOrder === dispOrder) {
        return { ...item, ...updates, amount: (item.bomAmount * amount?.replaceAll(',', '')).toLocaleString(), saleTotPrice: '0' }
      } else {
        return item
      }
    })

    setEstimateContextState({
      itemList: updateList,
    })

    setItemChangeYn(true)
  }

  // 단가 변경
  const onChangeSalePrice = (value, dispOrder, index) => {
    //itemChangeFlg, partAdd 받아온 그대로
    let salePrice = Number(value.replace(/[^0-9]/g, '').replaceAll(',', ''))
    if (isNaN(salePrice)) {
      salePrice = 0
    } else {
      salePrice = salePrice.toLocaleString()
    }
    let updateList = []
    let updates = {}
    updates.salePrice = salePrice
    updates.saleTotPrice = (Number(salePrice.replaceAll(',', '')) * estimateContextState.itemList[index].amount.replaceAll(',', '')).toLocaleString()
    updates.showSalePrice = updates.salePrice
    updates.showSaleTotPrice = updates.saleTotPrice

    updateList = estimateContextState.itemList.map((item) => {
      if (item.dispOrder === dispOrder) {
        return { ...item, ...updates }
      } else {
        return item
      }
    })

    setEstimateContextState({
      itemList: updateList,
    })

    setItemChangeYn(true)
  }

  // 아이템 자동완성 검색시 아이템 추가/변경시
  const onChangeDisplayItem = (itemId, dispOrder, index) => {
    const param = {
      itemId: itemId,
    }
    const apiUrl = `/api/display-item/item-detail?${queryStringFormatter(param)}`
    let updateList = []
    let updates = {}
    get({ url: apiUrl }).then((res) => {
      // console.log('아이템디테일::::::::', res)
      updates.objectNo = objectNo
      updates.planNo = planNo
      updates.itemId = res.itemId
      updates.itemNo = res.itemNo
      updates.itemName = res.itemName
      updates.itemChangeFlg = '1' //무조건 1
      updates.partAdd = '1' //무조건1 NEW
      updates.fileUploadFlg = res.fileUploadFlg
      updates.unit = res.unit
      updates.unitPrice = res.salePrice //unitPrice도 salePrice로
      updates.moduleFlg = res.moduleFlg
      updates.pkgMaterialFlg = res.pkgMaterialFlg
      updates.pnowW = res.pnowW
      updates.salePrice = res.salePrice
      updates.specification = res.specification
      updates.unit = res.unit
      updates.specialNoteCd = res.spnAttrCds
      updates.itemGroup = res.itemGroup
      updates.delFlg = '0' // 삭제플래그 0
      updates.saleTotPrice = (res.salePrice * estimateContextState.itemList[index].amount).toString()
      updates.amount = ''
      updates.openFlg = res.openFlg

      if (estimateContextState.estimateType === 'YJSS') {
        if (res.pkgMaterialFlg === '0') {
          updates.showSalePrice = '0'
          updates.showSaleTotPrice = '0'
        }
      } else {
        if (res.openFlg === '1') {
          updates.showSalePrice = '0'
          updates.showSaleTotPrice = '0'
        }
      }

      //104671
      let bomList = res.itemBomList

      updateList = estimateContextState.itemList.map((item) => {
        if (item.dispOrder === dispOrder) {
          if (item?.addFlg) {
            return { ...item, ...updates, saleTotPrice: '' }
          } else {
            if (estimateContextState.estimateType === 'YJSS') {
              return { ...item, ...updates, salePrice: '', saleTotPrice: '' }
            } else {
              return { ...item, ...updates }
            }
          }
        } else if (item.paDispOrder === dispOrder) {
          //봄제품을 바꿨을떄
          return { ...item, delFlg: '1' }
        } else {
          return item
        }
      })

      //paDispOrder
      if (bomList) {
        bomList.map((bomItem, index) => {
          let maxItemDispOrder = Math.max(...estimateContextState.itemList.map((item) => item.dispOrder))
          if (maxItemDispOrder == dispOrder) {
            bomItem.dispOrder = (index + 1 + maxItemDispOrder).toString()
            bomItem.paDispOrder = dispOrder
            bomItem.salePrice = '0'
            bomItem.saleTotPrice = '0'
            bomItem.unitPrice = '0'
          } else {
            bomItem.dispOrder = (index + 1 + Number(dispOrder)).toString()
            bomItem.paDispOrder = dispOrder
            bomItem.salePrice = '0'
            bomItem.saleTotPrice = '0'
            bomItem.unitPrice = '0'
          }

          bomItem.delFlg = '0'
          bomItem.objectNo = objectNo
          bomItem.planNo = planNo
          bomItem.addFlg = true //봄 추가시도 addFlg
        })

        setEstimateContextState({
          itemList: [...updateList, ...bomList],
        })
      } else {
        setEstimateContextState({
          itemList: updateList,
        })
      }

      setItemChangeYn(true)
    })
  }

  //제품 삭제
  const removeItem = () => {
    const array = [...selection]
    let delList = []
    estimateContextState.itemList.filter((row) => {
      array.map((row2) => {
        if (row2 === row.dispOrder) {
          delList.push({ ...row })
        }
        if (row2 === row.paDispOrder) {
          delList.push({ ...row })
        }
      })
    })

    const updateList = estimateContextState.itemList.map((item) => {
      const isDeleted = delList.some((row) => item.delFlg === '1' || item.dispOrder === row.dispOrder)
      return {
        ...item,
        delFlg: isDeleted ? '1' : '0',
      }
    })

    let delCnt = 0
    updateList.map((item) => {
      if (item.delFlg === '1') {
        delCnt++
      }
    })

    if (delCnt === updateList.length) {
      return alert(getMessage('estimate.detail.save.requiredItem'))
    }

    setEstimateContextState({
      itemList: updateList,
    })

    setSelection(new Set())
    setItemChangeYn(true)
  }

  useEffect(() => {
    if (itemChangeYn) {
      let totals = {
        totAmount: 0,
        totVolKw: 0,
        supplyPrice: 0,
        vatPrice: 0,
        totPrice: 0,
        addSupplyPrice: 0,
        pkgTotPrice: 0,
      }

      const calculateYJODTotals = (itemList) => {
        itemList.sort((a, b) => a.dispOrder - b.dispOrder)
        makeUniqueSpecialNoteCd(itemList)

        itemList.forEach((item) => {
          // console.log('YJOD::::::', item)
          delete item.showSalePrice
          delete item.showSaleTotPrice
          if (item.delFlg === '0') {
            let amount = Number(item.amount?.replace(/[^0-9]/g, '').replaceAll(',', '')) || 0
            let price = Number(item.saleTotPrice?.replaceAll(',', '')) || 0

            if (item.moduleFlg === '1') {
              const volKw = (item.pnowW * amount) / 1000
              totals.totVolKw += volKw
            }
            totals.totAmount += amount
            totals.supplyPrice += price

            if (item.openFlg === '1') {
              item.showSalePrice = '0'
              item.showSaleTotPrice = '0'
            }
          }
        })

        totals.vatPrice = totals.supplyPrice * 0.1
        totals.totPrice = totals.supplyPrice + totals.vatPrice
      }

      const calculateYJSSTotals = (itemList) => {
        itemList.sort((a, b) => a.dispOrder - b.dispOrder)
        makeUniqueSpecialNoteCd(itemList)
        itemList.forEach((item) => {
          // console.log('YJSSS::', item)
          if (item.delFlg === '0') {
            let amount = Number(item.amount?.replace(/[^0-9]/g, '').replaceAll(',', '')) || 0
            let salePrice = Number(item.salePrice?.replaceAll(',', '')) || 0
            if (item.moduleFlg === '1') {
              const volKw = (item.pnowW * amount) / 1000
              totals.totVolKw += volKw
            }

            totals.totAmount += amount
            if (item.pkgMaterialFlg === '1') {
              const saleTotPrice = amount * salePrice
              totals.addSupplyPrice += saleTotPrice
            }

            if (!item.paDispOrder) {
              if (item.pkgMaterialFlg === '0') {
                item.showSalePrice = '0'
                item.showSaleTotPrice = '0'
              }
            }
          }
        })

        totals.pkgTotPrice = Number(estimateContextState.pkgAsp.replaceAll(',', '')) * totals.totVolKw * 1000
        totals.supplyPrice = totals.addSupplyPrice + totals.pkgTotPrice
        totals.vatPrice = totals.supplyPrice * 0.1
        totals.totPrice = totals.supplyPrice + totals.vatPrice
      }

      if (estimateContextState.estimateType === 'YJOD') {
        calculateYJODTotals(estimateContextState.itemList)
        setEstimateContextState({
          totAmount: totals.totAmount,
          totVolKw: totals.totVolKw.toFixed(3),
          supplyPrice: totals.supplyPrice.toFixed(3),
          vatPrice: totals.vatPrice.toFixed(3),
          totPrice: totals.totPrice.toFixed(3),
        })
      } else if (estimateContextState.estimateType === 'YJSS') {
        calculateYJSSTotals(estimateContextState.itemList)
        setEstimateContextState({
          pkgTotPrice: totals.pkgTotPrice,
          totAmount: totals.totAmount,
          totVolKw: totals.totVolKw.toFixed(3),
          supplyPrice: totals.supplyPrice.toFixed(3),
          vatPrice: totals.vatPrice.toFixed(3),
          totPrice: totals.totPrice.toFixed(3),
        })
      }

      setItemChangeYn(false)
    } else {
      estimateContextState.itemList.forEach((item) => {
        if (estimateContextState.estimateType === 'YJSS' && !item.paDispOrder && item.pkgMaterialFlg === '0') {
          item.showSalePrice = '0'
          item.showSaleTotPrice = '0'
        }
      })

      estimateContextState.itemList.forEach((item) => {
        if (estimateContextState.estimateType === 'YJOD' && item.openFlg === '1') {
          item.showSalePrice = '0'
          item.showSaleTotPrice = '0'
        }
      })
    }
  }, [itemChangeYn, estimateContextState.itemList])

  //안건명 인풋 변경
  const handleBlurObjectName = (e) => {
    setEstimateContextState({ objectName: e.target.value })
  }

  //담당자 인풋 변경
  const handleBlurCharger = (e) => {
    setEstimateContextState({ charger: e.target.value })
  }

  //비고 인풋 변경
  const handleBlurRemarks = (e) => {
    setEstimateContextState({ remarks: e.target.value })
  }

  return (
    <div className="sub-content estimate">
      <div className="sub-content-inner">
        {/* 물건번호, 견적서번호, 등록일, 변경일시 시작 */}
        <div className="sub-content-box">
          <div className="sub-table-box">
            <div className="estimate-list-wrap one">
              <div className="estimate-box">
                <div className="estimate-tit">{getMessage('estimate.detail.objectNo')}</div>
                <div className="estimate-name">
                  {objectNo} (Plan No: {planNo})
                </div>
              </div>
              <div className="estimate-box">
                <div className="estimate-tit">{getMessage('estimate.detail.docNo')}</div>
                <div className="estimate-name">{estimateContextState.docNo}</div>
              </div>
              <div className="estimate-box">
                <div className="estimate-tit">{getMessage('estimate.detail.drawingEstimateCreateDate')}</div>
                <div className="estimate-name">
                  {estimateContextState?.drawingEstimateCreateDate
                    ? `${dayjs(estimateContextState.drawingEstimateCreateDate).format('YYYY.MM.DD')}`
                    : ''}
                </div>
              </div>
              <div className="estimate-box">
                <div className="estimate-tit">{getMessage('estimate.detail.lastEditDatetime')}</div>
                <div className="estimate-name">
                  {estimateContextState?.lastEditDatetime ? `${dayjs(estimateContextState.lastEditDatetime).format('YYYY.MM.DD HH:mm')}` : ''}
                </div>
              </div>
            </div>
          </div>
        </div>
        {/* 물건번호, 견적서번호, 등록일, 변경일시 끝 */}
        {/* 기본정보 시작 */}
        <div className="sub-content-box">
          <div className="sub-table-box">
            <div className="table-box-title-wrap">
              <div className="title-wrap">
                <h3>{getMessage('estimate.detail.header.title')}</h3>
              </div>
            </div>
            <div className="common-table bt-able">
              <table>
                <colgroup>
                  <col style={{ width: '160px' }} />
                  <col />
                  <col style={{ width: '160px' }} />
                  <col />
                </colgroup>
                <tbody>
                  <tr>
                    {/* 1차 판매점명 */}
                    <th>{getMessage('estimate.detail.saleStoreId')}</th>
                    <td>{estimateContextState?.firstSaleStoreName}</td>
                    {/* 견적일 */}
                    <th>
                      {getMessage('estimate.detail.estimateDate')} <span className="important">*</span>
                    </th>
                    <td>
                      <div className="date-picker" style={{ width: '350px' }}>
                        <SingleDatePicker {...singleDatePickerProps} />
                      </div>
                    </td>
                  </tr>
                  <tr>
                    {/* 2차 판매점명 */}
                    <th>{getMessage('estimate.detail.otherSaleStoreId')}</th>
                    <td>{estimateContextState?.agencySaleStoreName}</td>
                    {/* 담당자 */}
                    <th>
                      {getMessage('estimate.detail.receiveUser')} <span className="important">*</span>
                    </th>
                    <td>
                      <div className="input-wrap" style={{ width: '350px' }}>
                        <input type="text" className="input-light" defaultValue={estimateContextState?.charger} onBlur={handleBlurCharger} />
                      </div>
                    </td>
                  </tr>
                  <tr>
                    {/* 안건명 */}
                    <th>
                      {getMessage('estimate.detail.objectName')} <span className="important">*</span>
                    </th>
                    <td colSpan={3}>
                      <div className="form-flex-wrap">
                        <div className="input-wrap mr5" style={{ width: '610px' }}>
                          <input type="text" className="input-light" defaultValue={estimateContextState?.objectName} onBlur={handleBlurObjectName} />
                        </div>
                        <div className="select-wrap" style={{ width: '200px' }}>
                          <Select
                            id="objectNameOmit"
                            instanceId="objectNameOmit"
                            className="react-select-custom"
                            classNamePrefix="custom"
                            placeholder="Select"
                            options={honorificCodeList}
                            onChange={(e) => {
                              if (isObjectNotEmpty(e)) {
                                setEstimateContextState({ objectNameOmit: e.clCodeNm })
                              } else {
                                setEstimateContextState({ objectNameOmit: '' })
                              }
                            }}
                            getOptionLabel={(x) => x.clCodeNm}
                            getOptionValue={(x) => x.clCode}
                            isClearable={false}
                            isSearchable={false}
                            value={honorificCodeList.filter(function (option) {
                              return option.clCodeNm === estimateContextState.objectNameOmit
                            })}
                          />
                        </div>
                      </div>
                    </td>
                  </tr>
                  <tr>
                    {/* 물건정보에서 입력한 메모 */}
                    <th>{getMessage('estimate.detail.objectRemarks')}</th>
                    <td colSpan={3}>{estimateContextState?.objectRemarks}</td>
                  </tr>
                  <tr>
                    {/* 주문분류 */}
                    <th>
                      {getMessage('estimate.detail.estimateType')} <span className="important">*</span>
                    </th>
                    <td colSpan={3}>
                      <div className="radio-wrap">
                        <div className="d-check-radio light mr10">
                          <input
                            type="radio"
                            name="estimateType"
                            id="YJSS"
                            value={'YJSS'}
                            checked={estimateContextState?.estimateType === 'YJSS' ? true : false}
                            onChange={(e) => {
                              //주문분류
                              setHandlePricingFlag(true)
                              setEstimateContextState({ estimateType: e.target.value })
                            }}
                          />
                          <label htmlFor="YJSS">{getMessage('estimate.detail.estimateType.yjss')}</label>
                        </div>
                        <div className="d-check-radio light">
                          <input
                            type="radio"
                            name="estimateType"
                            id="YJOD"
                            value={'YJOD'}
                            checked={estimateContextState?.estimateType === 'YJOD' ? true : false}
                            onChange={(e) => {
                              setHandlePricingFlag(true)
                              setEstimateContextState({ estimateType: e.target.value })
                            }}
                          />
                          <label htmlFor="YJOD">{getMessage('estimate.detail.estimateType.yjod')}</label>
                        </div>
                      </div>
                    </td>
                  </tr>
                  <tr>
                    {/* 지붕재・사양시공 최대4개*/}
                    <th>{getMessage('estimate.detail.roofCns')}</th>
                    <td colSpan={3}>
                      {estimateContextState?.roofMaterialIdMulti?.split('、').map((row, index) => {
                        //지붕재
                        let roofList = row
                        let roofListLength = estimateContextState?.roofMaterialIdMulti?.split('、').length
                        let style = 'mb5'
                        if (roofListLength == index + 1) {
                          style = ''
                        }
                        //사양시공
                        let constructSpecificationMulti = estimateContextState?.constructSpecificationMulti?.split('、')

                        return (
                          <>
                            <div className={`form-flex-wrap ${style}`} key={fixedKey}>
                              <div className="input-wrap mr5" style={{ width: '610px' }} key={`roof${index}`}>
                                <input type="text" className="input-light" value={roofList} readOnly />
                              </div>
                              <div className="input-wrap" style={{ width: '200px' }}>
                                <input type="text" className="input-light" value={constructSpecificationMulti[index]} readOnly />
                              </div>
                            </div>
                          </>
                        )
                      })}
                    </td>
                  </tr>
                  <tr>
                    {/* 비고 */}
                    <th>{getMessage('estimate.detail.remarks')}</th>
                    <td colSpan={3}>
                      <div className="input-wrap">
                        <input type="text" className="input-light" defaultValue={estimateContextState?.remarks} onBlur={handleBlurRemarks} />
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
            {/* 파일첨부 시작 */}
            <div className="table-box-title-wrap">
              <div className="title-wrap">
                <h3>{getMessage('estimate.detail.header.fileList1')}</h3>
                <div className="d-check-box light mr5">
                  <input
                    type="checkbox"
                    id="next"
                    checked={estimateContextState?.fileFlg === '0' ? false : true}
                    onChange={(e) => {
                      setEstimateContextState({
                        fileFlg: e.target.checked ? '1' : '0',
                      })
                      if (e.target.checked) {
                        if (specialNoteList.length > 0) {
                          specialNoteList.map((item) => {
                            if (item.code === 'ATTR019') {
                              item.check = true
                            }
                          })
                        }
                      } else {
                        if (specialNoteList.length > 0) {
                          specialNoteList.map((item) => {
                            if (item.code === 'ATTR019') {
                              item.check = false
                            }
                          })
                        }
                      }
                    }}
                  />
                  <label htmlFor="next" style={{ color: '#101010' }}>
                    {getMessage('estimate.detail.fileFlg')}
                  </label>
                </div>
              </div>
            </div>
            <div className="common-table mb10">
              <table>
                <colgroup>
                  <col style={{ width: '160px' }} />
                  <col />
                </colgroup>
                <tbody>
                  <tr>
                    <th>{getMessage('estimate.detail.header.fileList1')}</th>
                    <td>
                      <EstimateFileUploader {...fileUploadProps} />
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
            {/* 첨부파일 목록 시작 */}
            {originFiles.length > 0 && (
              <div className="common-table bt-able">
                <table>
                  <colgroup>
                    <col style={{ width: '160px' }} />
                    <col />
                  </colgroup>
                  <tbody>
                    <tr>
                      <th>{getMessage('estimate.detail.header.fileList2')}</th>
                      <td>
                        <div className="drag-file-box">
                          <ul className="file-list">
                            {originFiles.map((originFile) => {
                              return (
                                <li className="file-item" key={uuidv4()}>
                                  <div className="file-item-wrap">
                                    <span
                                      style={{ display: originFile.delFlg === '0' ? '' : 'none' }}
                                      onClick={() => handleEstimateFileDownload(originFile)}
                                    >
                                      {originFile.faileName}
                                      <button
                                        type="button"
                                        className="delete"
                                        onClick={(e) => {
                                          deleteOriginFile(originFile.no)
                                          e.stopPropagation()
                                        }}
                                      ></button>
                                    </span>
                                    <div className="return-wrap" style={{ display: originFile.delFlg !== '0' ? '' : 'none' }}>
                                      <span className="return">{originFile.faileName}</span>
                                      <button
                                        type="button"
                                        className="return-btn"
                                        onClick={(e) => {
                                          returnOriginFile(originFile.no)
                                          e.stopPropagation()
                                        }}
                                      >
                                        <i className="return-ico"></i>
                                        {getMessage('estimate.detail.fileList2.btn.return')}
                                      </button>
                                    </div>
                                  </div>
                                </li>
                              )
                            })}
                          </ul>
                        </div>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
            )}
            {/* 첨부파일 목록 끝 */}
            {/* 파일첨부 끝 */}
            {/* 견적특이사항 시작 */}
            <div className="table-box-title-wrap">
              <div className="title-wrap">
                <h3 className="product">{getMessage('estimate.detail.header.specialEstimate')}</h3>
                <div className="product_tit">{getMessage('estimate.detail.header.specialEstimateProductInfo')}</div>
              </div>
              <div className="left-unit-box">
                <button className={`estimate-arr-btn down mr5 ${hidden ? '' : 'on'}`} onClick={() => setHidden(false)}></button>
                <button className={`estimate-arr-btn up ${hidden ? 'on' : ''}`} onClick={() => setHidden(true)}></button>
              </div>
            </div>
            {/* 견적 특이사항 코드영역시작 */}
            <div className={`estimate-check-wrap ${hidden ? 'hide' : ''}`}>
              <div className="estimate-check-inner">
                <div className="special-note-check-wrap">
                  {/* SpecialNoteList반복문 */}
                  {specialNoteList.length > 0 &&
                    specialNoteList.map((row) => {
                      return (
                        <div key={uuidv4()} className="special-note-check-item">
                          <div className="special-note-check-box">
                            <div className="d-check-box light">
                              <input
                                type="checkbox"
                                id={row.code}
                                checked={!!row.check}
                                disabled={row.code === 'ATTR001' || row.pkgYn === '1' ? true : false}
                                onClick={(event) => {
                                  setSpecialNoteList((specialNote) =>
                                    specialNote.map((temp) => (temp.code === row.code ? { ...temp, check: !temp.check } : temp)),
                                  )
                                }}
                              />
                              <label htmlFor={row.code}></label>
                            </div>
                            <span
                              className="check-name"
                              onClick={() => {
                                settingShowContent(row.code)
                              }}
                            >
                              {row.codeNm}
                            </span>
                          </div>
                        </div>
                      )
                    })}
                </div>
                {/* 견적특이사항 선택한 내용 영역시작 */}
                <div className="calculation-estimate">
                  {specialNoteList.map((row) => {
                    if (row.code === showContentCode) {
                      let showcontent = popShowSpecialNoteList.find((item) => {
                        return item.code === showContentCode
                      })

                      if (isObjectNotEmpty(showcontent)) {
                        return (
                          <dl key={uuidv4()}>
                            <dt>{showcontent.codeNm}</dt>
                            <dd dangerouslySetInnerHTML={{ __html: showcontent.remarks }} style={{ whiteSpace: 'pre-wrap' }}></dd>
                          </dl>
                        )
                      } else {
                        let pushData = []
                        popShowSpecialNoteList.map((item) => {
                          let option = showContentCode.split('、')
                          option.map((item2) => {
                            if (item.code === item2) {
                              pushData.push(item)
                            }
                          })
                        })
                        return pushData.map((item) => (
                          <dl key={uuidv4()}>
                            <dt>{item.codeNm}</dt>
                            <dd dangerouslySetInnerHTML={{ __html: item.remarks }} style={{ whiteSpace: 'pre-wrap' }}></dd>
                          </dl>
                        ))
                      }
                    }
                  })}
                </div>
                {/* 견적특이사항 선택한 내용 영역끝 */}
              </div>
            </div>

            {/* 견적 특이사항 코드영역 끝 */}

            {/* 견적특이사항 영역끝 */}
            {/* 제품정보 시작 */}
            <div className="table-box-title-wrap">
              <div className="title-wrap">
                <h3>{getMessage('estimate.detail.header.specialEstimateProductInfo')}</h3>
              </div>
            </div>
            <div className="esimate-wrap">
              <div className="estimate-list-wrap one">
                <div className="estimate-box">
                  <div className="estimate-tit">{getMessage('estimate.detail.sepcialEstimateProductInfo.totAmount')}</div>
                  <div className="estimate-name blue">{convertNumberToPriceDecimal(estimateContextState?.totAmount)}</div>
                </div>
                <div className="estimate-box">
                  <div className="estimate-tit">{getMessage('estimate.detail.sepcialEstimateProductInfo.totVolKw')}</div>
                  <div className="estimate-name blue">{convertNumberToPriceDecimalToFixed(estimateContextState?.totVolKw, 3)}</div>
                </div>
                <div className="estimate-box">
                  <div className="estimate-tit">{getMessage('estimate.detail.sepcialEstimateProductInfo.supplyPrice')}</div>
                  <div className="estimate-name blue">{convertNumberToPriceDecimal(estimateContextState?.supplyPrice)}</div>
                </div>
                <div className="estimate-box">
                  <div className="estimate-tit">{getMessage('estimate.detail.sepcialEstimateProductInfo.vatPrice')}</div>
                  <div className="estimate-name blue">{convertNumberToPriceDecimal(estimateContextState?.vatPrice)}</div>
                </div>
                <div className="estimate-box">
                  <div className="estimate-tit">{getMessage('estimate.detail.sepcialEstimateProductInfo.totPrice')}</div>
                  <div className="estimate-name red">{convertNumberToPriceDecimal(estimateContextState?.totPrice)}</div>
                </div>
              </div>
            </div>
            {/* YJOD면 아래영역 숨김 */}
            <div className="common-table bt-able" style={{ display: estimateContextState?.estimateType === 'YJSS' ? '' : 'none' }}>
              <table>
                <colgroup>
                  <col style={{ width: '160px' }} />
                  <col />
                  <col style={{ width: '160px' }} />
                  <col />
                  <col style={{ width: '160px' }} />
                  <col />
                </colgroup>
                <tbody>
                  <tr>
                    <th>
                      {getMessage('estimate.detail.sepcialEstimateProductInfo.pkgUnitPrice')}
                      <span className="important">*</span>
                    </th>
                    <td>
                      <div className="input-wrap">
                        <input
                          type="text"
                          className="input-light"
                          value={estimateContextState?.estimateType === 'YJSS' ? estimateContextState?.pkgAsp : '0'}
                          onChange={(e) => {
                            onChangePkgAsp(e.target.value)
                          }}
                        />
                      </div>
                    </td>
                    <th>{getMessage('estimate.detail.sepcialEstimateProductInfo.pkgWeight')}</th>
                    <td>{convertNumberToPriceDecimalToFixed(estimateContextState?.totVolKw, 3)}</td>
                    <th>{getMessage('estimate.detail.sepcialEstimateProductInfo.pkgPrice')}</th>
                    <td>{convertNumberToPriceDecimal(estimateContextState?.pkgTotPrice)}</td>
                  </tr>
                </tbody>
              </table>
            </div>
            {/* 제품정보 끝 */}
            {/* 가격표시영역시작 */}
            <div className="estimate-product-option">
              <div className="product-price-wrap">
                <div className="product-price-tit">{getMessage('estimate.detail.header.showPrice')}</div>
                <div className="select-wrap">
                  {session?.storeLvl === '1' ? (
                    <select
                      key={uuidv4()}
                      className="select-light"
                      onChange={(e) => {
                        onChangeStorePriceList(e.target.value)
                      }}
                      value={showPriceCd}
                    >
                      {storePriceList.length > 0 && storePriceList.map((row) => <option value={row.priceCd}>{row.priceNm}</option>)}
                    </select>
                  ) : (
                    <select key={uuidv4()} className="select-light">
                      <option value="UNIT_PRICE">{getMessage('estimate.detail.header.unitPrice')}</option>
                    </select>
                  )}
                </div>
                <button
                  type="button"
                  className="btn-origin grey ml5"
                  onClick={() => {
                    setHandlePricingFlag(true)
                    handlePricing(showPriceCd)
                  }}
                >
                  {getMessage('estimate.detail.showPrice.pricingBtn')}
                </button>
              </div>
              <div className="product-edit-wrap">
                <ul className="product-edit-explane">
                  <li className="explane-item item01">
                    <span className="ico"></span>
                    {getMessage('estimate.detail.showPrice.description1')}
                  </li>
                  <li className="explane-item item02">
                    <span className="ico"></span>
                    {getMessage('estimate.detail.showPrice.description2')}
                  </li>
                  <li className="explane-item item03">
                    <span className="ico"></span>
                    {getMessage('estimate.detail.showPrice.description3')}
                  </li>
                  <li className="explane-item item04">
                    <span className="ico"></span>
                    {getMessage('estimate.detail.showPrice.description4')}
                  </li>
                </ul>
                <div className="product-edit-btn">
                  <button
                    className="btn-origin navy mr5"
                    type="button"
                    onClick={() => {
                      addItem()
                    }}
                  >
                    <span className="plus"></span>
                    {getMessage('estimate.detail.showPrice.addItem')}
                  </button>
                  <button className="btn-origin grey" type="button" onClick={removeItem}>
                    <span className="minus"></span>
                    {getMessage('estimate.detail.showPrice.delItem')}
                  </button>
                </div>
              </div>
            </div>
            {/* 가격표시영역끝 */}
            {/* html테이블시작 */}
            <div className="esimate-table">
              <table>
                <colgroup>
                  <col width={50} />
                  <col width={60} />
                  <col />
                  <col width={300} />
                  <col width={90} />
                  <col width={80} />
                  <col width={170} />
                  <col width={190} />
                </colgroup>
                <thead>
                  <tr>
                    <th>
                      <div className="d-check-box pop no-text">
                        <input type="checkbox" id="ch97" checked={isSelectedAll()} onChange={onChangeSelectAll} />
                        <label htmlFor="ch97"></label>
                      </div>
                    </th>
                    <th>{getMessage('estimate.detail.itemTableHeader.dispOrder')}</th>
                    <th>{getMessage('estimate.detail.itemTableHeader.itemId')}</th>
                    <th>{getMessage('estimate.detail.itemTableHeader.itemNo')}</th>
                    <th>{getMessage('estimate.detail.itemTableHeader.amount')}</th>
                    <th>{getMessage('estimate.detail.itemTableHeader.unit')}</th>
                    <th>{getMessage('estimate.detail.itemTableHeader.salePrice')}</th>
                    <th>{getMessage('estimate.detail.itemTableHeader.saleTotPrice')}</th>
                  </tr>
                </thead>
                <tbody>
                  {estimateContextState?.itemList.length > 0 &&
                    estimateContextState.itemList.map((item, index) => {
                      if (item.delFlg === '0') {
                        return (
                          <tr key={item?.dispOrder || index}>
                            <td className="al-c">
                              <div className="d-check-box light no-text">
                                <input
                                  type="checkbox"
                                  id={item?.dispOrder}
                                  disabled={!!item?.paDispOrder}
                                  onChange={() => onChangeSelect(item.dispOrder)}
                                  checked={!!selection.has(item.dispOrder)}
                                />
                                <label htmlFor={item?.dispOrder}></label>
                              </div>
                            </td>
                            <td className="al-r">{item?.dispOrder}</td>
                            <td>
                              <div className="form-flex-wrap">
                                <div className="select-wrap mr5">
                                  <Select
                                    id="long-value-select1"
                                    instanceId="long-value-select1"
                                    className="react-select-custom"
                                    classNamePrefix="custom"
                                    placeholder="Select"
                                    options={displayItemList}
                                    onChange={(e) => {
                                      if (isObjectNotEmpty(e)) {
                                        onChangeDisplayItem(e.itemId, item.dispOrder, index)
                                      }
                                    }}
                                    getOptionLabel={(x) => x.itemName}
                                    getOptionValue={(x) => x.itemId}
                                    isClearable={false}
                                    isDisabled={!!item?.paDispOrder}
                                    value={displayItemList.filter(function (option) {
                                      return option.itemId === item.itemId
                                    })}
                                  />
                                </div>
                                {item?.itemChangeFlg === '1' && (
                                  <div className="btn-area">
                                    <span className="tb_ico change_check"></span>
                                  </div>
                                )}
                              </div>
                            </td>
                            <td>
                              <div className="form-flex-wrap">
                                <div className="name">{item?.itemNo}</div>
                                <div className="icon-wrap">
                                  {item?.fileUploadFlg === '1' && <span className="tb_ico file_check"></span>}
                                  {item?.specialNoteCd && (
                                    <button
                                      type="button"
                                      className="grid-tip"
                                      onClick={() => {
                                        setProductFeaturesPopupOpen(true)
                                        setShowProductFeatureData(item?.specialNoteCd)
                                      }}
                                    ></button>
                                  )}
                                </div>
                              </div>
                            </td>
                            <td>
                              <div className="input-wrap" style={{ width: '100%' }}>
                                <input
                                  type="text"
                                  className="input-light al-r"
                                  value={convertNumberToPriceDecimal(item?.amount?.replaceAll(',', ''))}
                                  disabled={item.itemId === '' || !!item?.paDispOrder}
                                  onChange={(e) => {
                                    onChangeAmount(e.target.value, item.dispOrder, index)
                                  }}
                                  maxLength={6}
                                />
                              </div>
                            </td>
                            <td>{item.unit}</td>
                            <td>
                              <div className="form-flex-wrap">
                                <div className="input-wrap mr5">
                                  <input
                                    type="text"
                                    className="input-light al-r"
                                    value={convertNumberToPriceDecimal(item?.showSalePrice === '0' ? null : item?.salePrice?.replaceAll(',', ''))}
                                    disabled={
                                      estimateContextState?.estimateType === 'YJSS'
                                        ? item?.paDispOrder
                                          ? true
                                          : item.pkgMaterialFlg !== '1'
                                        : item.itemId === '' || !!item?.paDispOrder
                                          ? true
                                          : item.openFlg === '1'
                                            ? true
                                            : false
                                    }
                                    onChange={(e) => {
                                      onChangeSalePrice(e.target.value, item.dispOrder, index)
                                    }}
                                    maxLength={12}
                                  />
                                </div>
                                {item.openFlg === '1' && (
                                  <div className="btn-area">
                                    <span className="tb_ico open_check"></span>
                                  </div>
                                )}
                              </div>
                            </td>
                            <td className="al-r">
                              {convertNumberToPriceDecimal(
                                item?.showSaleTotPrice === '0'
                                  ? null
                                  : item?.amount === ''
                                    ? null
                                    : item?.saleTotPrice === '0'
                                      ? null
                                      : item?.saleTotPrice?.replaceAll(',', ''),
                              )}
                            </td>
                          </tr>
                        )
                      } else {
                        return null
                      }
                    })}
                </tbody>
              </table>
            </div>

            {/* html테이블끝 */}
          </div>
        </div>
        {/* 기본정보끝 */}
      </div>
      {productFeaturesPopupOpen && (
        <ProductFeaturesPop
          popShowSpecialNoteList={popShowSpecialNoteList}
          showProductFeatureData={showProductFeatureData}
          setProductFeaturesPopupOpen={setProductFeaturesPopupOpen}
        />
      )}
    </div>
  )
}
