import dicomParser from 'dicom-parser'
import * as cornerstone from '@cornerstonejs/core'
import * as cornerstoneTools from '@cornerstonejs/tools'
import cornerstoneDICOMImageLoader from '@cornerstonejs/dicom-image-loader'
import intel from './d-intel.json'
cornerstone.init({
  gpuTier: intel
})
cornerstone.Settings.getRuntimeSettings().set('useCursors', false)
window.cornerstone = cornerstone
window.cornerstoneTools = cornerstoneTools
const { preferSizeOverAccuracy, useNorm16Texture } =
  cornerstone.getConfiguration().rendering

export default function initCornerstoneDICOMImageLoader() {
  cornerstoneDICOMImageLoader.external.cornerstone = cornerstone
  cornerstoneDICOMImageLoader.external.dicomParser = dicomParser
  cornerstoneDICOMImageLoader.configure({
    useWebWorkers: false,
    decodeConfig: {
      convertFloatPixelDataToInt: false,
      use16BitDataType: preferSizeOverAccuracy || useNorm16Texture
    }
  })
  // let maxWebWorkers = 1

  // if (navigator.hardwareConcurrency) {
  //   maxWebWorkers = Math.min(navigator.hardwareConcurrency, 7)
  // }

  // var config = {
  //   maxWebWorkers,
  //   startWebWorkersOnDemand: false,
  //   taskConfiguration: {
  //     decodeTask: {
  //       initializeCodecsOnStartup: false,
  //       strict: false
  //     }
  //   }
  // }

  // cornerstoneDICOMImageLoader.webWorkerManager.initialize(config)
}
