import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { u as useViewHandler } from './index-bbdfb97a.js';
import { useState, useEffect } from 'react';

var useCustomDimensions = function useCustomDimensions() {
  var viewHandler = useViewHandler();
  var _useState = useState(),
    _useState2 = _slicedToArray(_useState, 2),
    dimensions = _useState2[0],
    setDimensions = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    dimOnlyForOneArticle = _useState4[0],
    setDimOnlyForOneArticle = _useState4[1];
  useEffect(function () {
    var _viewHandler$productS;
    if (!viewHandler.divaWebPlanner.actSet()) return;
    (_viewHandler$productS = viewHandler.productState.customDimensions) === null || _viewHandler$productS === void 0 || _viewHandler$productS.then(function (res) {
      setDimensions(res);
      var dict = res.reduce(function (basketIdsDict, d) {
        if (!basketIdsDict[d.dimensionId]) {
          basketIdsDict[d.dimensionId] = [d.dimension];
        } else if (!basketIdsDict[d.dimensionId].includes(d.dimension)) basketIdsDict[d.dimensionId].push(d.dimension);
        return basketIdsDict;
      }, {});
      setDimOnlyForOneArticle(!Object.values(dict).find(function (v) {
        return v.length > 1;
      }));
    });
  }, [viewHandler.divaWebPlanner.actSet(), viewHandler.settingsState.configChanged]);
  return {
    dimensions: dimensions,
    dimOnlyForOneArticle: dimOnlyForOneArticle
  };
};

export { useCustomDimensions as u };
