Liferay.Loader.define("app-builder-web@1.0.73/js/pages/table-view/EditTableViewContext.es", ['module', 'exports', 'require', 'frontend-js-react-web$react'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = exports.reducer = exports.initialState = exports.UPDATE_FOCUSED_COLUMN = exports.UPDATE_FILTER_VALUE = exports.UPDATE_FIELD_TYPES = exports.UPDATE_EDITING_LANGUAGE_ID = exports.UPDATE_DATA_LIST_VIEW_NAME = exports.UPDATE_DATA_LIST_VIEW = exports.UPDATE_DATA_DEFINITION = exports.REMOVE_FILTER_VALUE = exports.REMOVE_DATA_LIST_VIEW_FIELD = exports.ADD_DATA_LIST_VIEW_FIELD = void 0;

    var _react = require("frontend-js-react-web$react");

    function _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

    function _nonIterableSpread() {
      throw new TypeError("Invalid attempt to spread non-iterable instance");
    }

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    var ADD_DATA_LIST_VIEW_FIELD = 'ADD_DATA_LIST_VIEW_FIELD';
    exports.ADD_DATA_LIST_VIEW_FIELD = ADD_DATA_LIST_VIEW_FIELD;
    var REMOVE_DATA_LIST_VIEW_FIELD = 'REMOVE_DATA_LIST_VIEW_FIELD';
    exports.REMOVE_DATA_LIST_VIEW_FIELD = REMOVE_DATA_LIST_VIEW_FIELD;
    var REMOVE_FILTER_VALUE = 'REMOVE_FILTER_VALUE';
    exports.REMOVE_FILTER_VALUE = REMOVE_FILTER_VALUE;
    var UPDATE_DATA_DEFINITION = 'UPDATE_DATA_DEFINITION';
    exports.UPDATE_DATA_DEFINITION = UPDATE_DATA_DEFINITION;
    var UPDATE_DATA_LIST_VIEW = 'UPDATE_DATA_LIST_VIEW';
    exports.UPDATE_DATA_LIST_VIEW = UPDATE_DATA_LIST_VIEW;
    var UPDATE_DATA_LIST_VIEW_NAME = 'UPDATE_DATA_LIST_VIEW_NAME';
    exports.UPDATE_DATA_LIST_VIEW_NAME = UPDATE_DATA_LIST_VIEW_NAME;
    var UPDATE_EDITING_LANGUAGE_ID = 'UPDATE_EDITING_LANGUAGE_ID';
    exports.UPDATE_EDITING_LANGUAGE_ID = UPDATE_EDITING_LANGUAGE_ID;
    var UPDATE_FIELD_TYPES = 'UPDATE_FIELD_TYPES';
    exports.UPDATE_FIELD_TYPES = UPDATE_FIELD_TYPES;
    var UPDATE_FILTER_VALUE = 'UPDATE_FILTER_VALUE';
    exports.UPDATE_FILTER_VALUE = UPDATE_FILTER_VALUE;
    var UPDATE_FOCUSED_COLUMN = 'UPDATE_FOCUSED_COLUMN';
    exports.UPDATE_FOCUSED_COLUMN = UPDATE_FOCUSED_COLUMN;
    var initialState = {
      dataDefinition: {
        dataDefinitionFields: []
      },
      dataListView: {
        appliedFilters: {},
        fieldNames: [],
        name: {
          en_US: ''
        }
      },
      fieldTypes: [],
      focusedColumn: null
    };
    exports.initialState = initialState;

    var reducer = function reducer() {
      var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
      var action = arguments.length > 1 ? arguments[1] : undefined;

      switch (action.type) {
        case ADD_DATA_LIST_VIEW_FIELD:
          {
            var dataListView = state.dataListView;
            var _action$payload = action.payload,
                fieldName = _action$payload.fieldName,
                index = _action$payload.index;
            var fieldNames = dataListView.fieldNames;
            return _objectSpread(_objectSpread({}, state), {}, {
              dataListView: _objectSpread(_objectSpread({}, dataListView), {}, {
                fieldNames: fieldNames ? [].concat(_toConsumableArray(fieldNames.slice(0, index)), [fieldName], _toConsumableArray(fieldNames.slice(index))) : [fieldName]
              })
            });
          }

        case REMOVE_DATA_LIST_VIEW_FIELD:
          {
            var _dataListView = state.dataListView;
            var _fieldName = action.payload.fieldName;
            return _objectSpread(_objectSpread({}, state), {}, {
              dataListView: _objectSpread(_objectSpread({}, _dataListView), {}, {
                fieldNames: _dataListView.fieldNames.filter(function (name) {
                  return name != _fieldName;
                })
              }),
              focusedColumn: null
            });
          }

        case REMOVE_FILTER_VALUE:
          {
            var _fieldName2 = action.payload.fieldName;
            var _dataListView2 = state.dataListView;

            var appliedFilters = _objectSpread({}, _dataListView2.appliedFilters);

            delete appliedFilters[_fieldName2];
            return _objectSpread(_objectSpread({}, state), {}, {
              dataListView: _objectSpread(_objectSpread({}, _dataListView2), {}, {
                appliedFilters: appliedFilters
              })
            });
          }

        case UPDATE_DATA_DEFINITION:
          {
            var dataDefinition = action.payload.dataDefinition;
            return _objectSpread(_objectSpread({}, state), {}, {
              dataDefinition: dataDefinition
            });
          }

        case UPDATE_DATA_LIST_VIEW:
          {
            var _dataListView3 = action.payload.dataListView;
            return _objectSpread(_objectSpread({}, state), {}, {
              dataListView: _dataListView3
            });
          }

        case UPDATE_DATA_LIST_VIEW_NAME:
          {
            var name = action.payload.name;
            return _objectSpread(_objectSpread({}, state), {}, {
              dataListView: _objectSpread(_objectSpread({}, state.dataListView), {}, {
                name: name
              })
            });
          }

        case UPDATE_EDITING_LANGUAGE_ID:
          {
            return _objectSpread(_objectSpread({}, state), {}, {
              editingLanguageId: action.payload
            });
          }

        case UPDATE_FIELD_TYPES:
          {
            var fieldTypes = action.payload.fieldTypes;
            return _objectSpread(_objectSpread({}, state), {}, {
              fieldTypes: fieldTypes
            });
          }

        case UPDATE_FILTER_VALUE:
          {
            var _action$payload2 = action.payload,
                _fieldName3 = _action$payload2.fieldName,
                value = _action$payload2.value;
            return _objectSpread(_objectSpread({}, state), {}, {
              dataListView: _objectSpread(_objectSpread({}, state.dataListView), {}, {
                appliedFilters: _objectSpread(_objectSpread({}, state.dataListView.appliedFilters), {}, _defineProperty({}, _fieldName3, value))
              })
            });
          }

        case UPDATE_FOCUSED_COLUMN:
          {
            var _fieldName4 = action.payload.fieldName;
            return _objectSpread(_objectSpread({}, state), {}, {
              focusedColumn: _fieldName4
            });
          }

        default:
          {
            return state;
          }
      }
    };

    exports.reducer = reducer;

    var _default = /*#__PURE__*/(0, _react.createContext)();

    exports.default = _default;
    //# sourceMappingURL=EditTableViewContext.es.js.map
  }
});
//# sourceMappingURL=EditTableViewContext.es.js.map