const inicialState = {};
///////////////////////////////     REDUCERS     ///////////////////////////////
export function formReducer(state = inicialState, action) {
  switch (action.type) {
    case FormActions.METADATA_LOADED:
      return Object.assign(Object.assign({}, state), { formMetadata: action.payload, currentSheet: undefined });
    case FormActions.CHANGE_TAB:
      return Object.assign(Object.assign({}, state), { currentSheet: action.payload });
    default:
      return state;
  }
}
/////////////////////////////// ACTION CREATORS ///////////////////////////////
export function loadMetadata(formMetadata) {
  return {
    type: FormActions.METADATA_LOADED,
    payload: formMetadata
  };
}
export function changeTab(currentSheet) {
  return {
    type: FormActions.CHANGE_TAB,
    payload: typeof currentSheet === "string" ? currentSheet : currentSheet.tabKey
  };
}
///////////////////////////////    SELECTORS    ///////////////////////////////
export function selectFormMetadata(state) {
  return state.formMetadata;
}
export function selectCurrentSheetId(state) {
  return state.currentSheet;
}
export function selectCurrentSheet(state) {
  const currentSheetId = selectCurrentSheetId(state);
  return currentSheetId ? state.formMetadata.getSheet(currentSheetId) : Array.from(state.formMetadata.getAllSheets().values())[0];
}
///////////////////////////////      TYPES      ///////////////////////////////
var FormActions;
(function (FormActions) {
  FormActions["METADATA_LOADED"] = "FORM/METADATA_LOADED";
  FormActions["CHANGE_TAB"] = "FORM/CHANGE_TAB";
})(FormActions || (FormActions = {}));
