"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toggleHighlight = exports.setPreviousEditedDesignAreaIdentier = exports.selectDesignArea = exports.recalculateDesignArea = exports.clearDesignAreaSelection = exports.actionTypes = void 0;
var _Selectors = require("./Selectors");
var _Actions = require("../DesignView/Actions");
var _createActionWithGlobalState = require("../../../Utils/Redux/createActionWithGlobalState");
var actionTypes = exports.actionTypes = {
  SELECT_DESIGN_AREA: 'DesignArea/SELECT_DESIGN_AREA',
  CLEAR_DESIGN_AREA_SELECTION: 'DesignArea/CLEAR_DESIGN_AREA_SELECTION',
  TOGGLE_HIGHLIGHT: 'DesignArea/TOGGLE_HIGHLIGHT',
  SET_PREVIOUS_EDITED_DESIGN_AREA: 'DesignArea/SET_PREVIOUS_EDITED_DESIGN_AREA',
  RECALCULATE_DESIGN_AREA: 'DesignArea/RECALCULATE_DESIGN_AREA'
};
var selectDesignArea = exports.selectDesignArea = function selectDesignArea(designAreaIdentifier) {
  return function (dispatch, getState) {
    dispatch({
      type: actionTypes.SELECT_DESIGN_AREA,
      designAreaIdentifier: designAreaIdentifier
    });
    var designArea = (0, _Selectors.getSelectedDesignArea)(getState());
    dispatch((0, _Actions.selectDesignView)(designArea.designView.identifier));
  };
};
var clearDesignAreaSelection = exports.clearDesignAreaSelection = function clearDesignAreaSelection() {
  var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  return function (dispatch, getState) {
    var notEmpty = Object.keys(getState().designArea.selectedDesignArea).length > 0;
    if (force || notEmpty) {
      dispatch({
        type: actionTypes.CLEAR_DESIGN_AREA_SELECTION,
        force: force
      });
    }
  };
};
var setPreviousEditedDesignAreaIdentier = exports.setPreviousEditedDesignAreaIdentier = function setPreviousEditedDesignAreaIdentier(designAreaIdentifier) {
  return {
    type: actionTypes.SET_PREVIOUS_EDITED_DESIGN_AREA,
    designAreaIdentifier: designAreaIdentifier
  };
};
var toggleHighlight = exports.toggleHighlight = function toggleHighlight(showHighlight) {
  return {
    type: actionTypes.TOGGLE_HIGHLIGHT,
    showHighlight: showHighlight
  };
};
var recalculateDesignArea = exports.recalculateDesignArea = function recalculateDesignArea() {
  return (0, _createActionWithGlobalState.createActionWithGlobalState)({
    type: actionTypes.RECALCULATE_DESIGN_AREA
  });
};