import { combineReducers, createStore } from 'redux'; // action constants

const CHANGE_LANG = 'CHANGE_LANG';
const CHANGE_THEME = 'CHANGE_THEME';
const CHANGE_FONT = 'CHANGE_FONT';
const SET_ROUTE_HISTORY = 'SET_ROUTE_HISTORY';
const SET_FILTER = "SET_FILTER"; // Initial State

const langState = {
  lang: 'en' //localStorage.getItem('currentLang') ? localStorage.getItem('currentLang') : 'en'

};
const themeState = {
  theme: 'blue' //localStorage.getItem('currentTheme') ? localStorage.getItem('currentTheme') : 'blue'

};
const fontState = {
  font: 'medium-font' //localStorage.getItem('currentFont') ? localStorage.getItem('currentFont') : 'medium-font'

};
const filterState = {
  month: '',
  year: '',
  monthList: [],
  yearList: []
}; // actions.js
// to change the language 

export const changeLang = lang => ({
  type: CHANGE_LANG,
  lang
}); // to change the theme

export const changeTheme = theme => ({
  type: CHANGE_THEME,
  theme
}); // to change the theme

export const changeFont = font => ({
  type: CHANGE_FONT,
  font
}); // Set the filter 

export const setFilter = filter => ({
  type: SET_FILTER,
  filter
}); // to change the theme

export const setRouteHistory = history => ({
  type: SET_ROUTE_HISTORY,
  history
}); // actions.js
// to setup guid after login

export const setGuid = guid => ({
  type: 'SET_GUID',
  guid
});
export const setUserList = userList => ({
  type: 'SET_USER_LIST',
  userList
});
export const setSelectedService = selectedService => ({
  type: 'SET_SELECTED_SERVICE',
  selectedService
});
export const set_RN2_RN3_Details = rn2_rn3_details => ({
  type: 'SET_RN2_RN3_DETAILS',
  rn2_rn3_details
});
export const set_RN13_Preview_history = rn13_preview_history => ({
  type: 'SET_RN13_PREVIEW_HISTORY',
  rn13_preview_history
});
export const set_RN7_Preview_history = rn7_preview_history => ({
  type: 'SET_RN7_PREVIEW_HISTORY',
  rn7_preview_history
});
export const set_RN9_Preview_history = rn9_preview_history => ({
  type: 'SET_RN9_PREVIEW_HISTORY',
  rn9_preview_history
});
export const setPKIDetails = pki_details => ({
  type: 'SET_PKI_DETAILS',
  pki_details
});
export const setRN1_App = RN1_app_details => ({
  type: 'SET_RN1_APP_DETAILS',
  RN1_app_details
});
export const setRN2_RN3_App = RN2_RN3_app_details => ({
  type: 'SET_RN2_RN3_APP_DETAILS',
  RN2_RN3_app_details
});
export const setRN2_RN3_MOHUser = RN2_RN3_mohuser_app_details => ({
  type: 'SET_RN2_RN3_MOHUSERAPP_DETAILS',
  RN2_RN3_mohuser_app_details
});
export const setREDocumentRegionDetails = reregion_details => ({
  type: 'SET_RE_REGION_DETAILS',
  reregion_details
});
export const setLN1A_App = ln1A_app_details => ({
  type: 'SET_LN1A_APP_DETAILS',
  ln1A_app_details
});
export const setApplicantUserType = applicantUserType => ({
  type: 'SET_APPLICANT_USERTYPE',
  applicantUserType
});
export const setCreatedUserTypeID = createdUserTypeID => ({
  type: 'SET_CREATED_USERTYPE_ID',
  createdUserTypeID
});
export const setApplicantUserTypeData = applicantUserTypeData => ({
  type: 'SET_APPLICANT_USERTYPE_ENGLISH',
  applicantUserTypeData
});
export const setApplicableService = applicableService => ({
  type: 'SET_APPLICABLE_SERVICE',
  applicableService
});
export const setApplicableSubService = applicableSubService => ({
  type: 'SET_APPLICABLE_SUB_SERVICE',
  applicableSubService
});
export const setRN4KrookiNumber = rn4KrookiNumber => ({
  type: 'SET_RN4_KrookiNumber',
  rn4KrookiNumber
});
export const setRN4_App = rn4_app_details => ({
  type: 'SET_RN4_APP_DETAILS',
  rn4_app_details
});
export const setResourceDetails = resourceDetails => ({
  type: 'SET_RESOURCE_DETAILS',
  resourceDetails
});
export const setApplicationInternalStatus = applicationInternalStatus => ({
  type: 'SET_APPLICATION_INTERNAL_STATUS',
  applicationInternalStatus
});
export const setRN13_App = rn13_app_details => ({
  type: 'SET_RN13_APP_DETAILS',
  rn13_app_details
});
export const setRN7_App = rn7_app_details => ({
  type: 'SET_RN7_APP_DETAILS',
  rn7_app_details
});
export const setRN9_App = rn9_app_details => ({
  type: 'SET_RN9_APP_DETAILS',
  rn9_app_details
});
export const setRN10_App = rn10_app_details => ({
  type: 'SET_RN10_APP_DETAILS',
  rn10_app_details
});
export const setRN5_App = rn5_app_details => ({
  type: 'SET_RN5_APP_DETAILS',
  rn5_app_details
});
export const setAppInfo = appInfo => ({
  type: 'SET_APP_INFO',
  appInfo
});
export const setDocs_Details = docs_upload_details => ({
  type: 'SET_DOCS_DETAILS',
  docs_upload_details
});
export const setApplicantUserID = applicantUserID => ({
  type: 'SET_APPLICANT_USERID',
  applicantUserID
});
export const setMyInvolvedPartyDetails = myInvolvedPartyDetails => ({
  type: 'SET_MY_INVOLVED_PARTY_DETAILS',
  myInvolvedPartyDetails
});
export const setOrganizationDetails = organizationDetails => ({
  type: 'SET_ORGANIZATION_DETAILS',
  organizationDetails
});
export const setOrganizationUserDetails = organizationUserDetails => ({
  type: 'SET_ORGANIZATION_USER_DETAILS',
  organizationUserDetails
});
export const setOrgUserValidator = orgUserValidator => ({
  type: 'SET_ORG_USER_VALIDATOR',
  orgUserValidator
});
export const setProxyUserDetails = proxyUserDetails => ({
  type: 'SET_PROXY_USER_DETAILS',
  proxyUserDetails
});
export const setProfileUserDetails = profileUserDetails => ({
  type: 'SET_PROFILE_USER_DETAILS',
  profileUserDetails
}); // reducers.js

export const filter = (state = filterState, action) => {
  switch (action.type) {
    case SET_FILTER:
      return { ...state,
        ...action.filter
      };

    default:
      return state;
  }
};
export const guid = (state = {}, action) => {
  switch (action.type) {
    case 'SET_GUID':
      return action.guid;

    default:
      return state;
  }
};
export const userList = (state = {}, action) => {
  switch (action.type) {
    case 'SET_USER_LIST':
      return action.userList;

    default:
      return state;
  }
};
export const selectedService = (state = {}, action) => {
  switch (action.type) {
    case 'SET_SELECTED_SERVICE':
      return action.selectedService;

    default:
      return state;
  }
};
export const myInvolvedPartyDetails = (state = {}, action) => {
  switch (action.type) {
    case 'SET_MY_INVOLVED_PARTY_DETAILS':
      return action.myInvolvedPartyDetails;

    default:
      return state;
  }
};
export const rn2_rn3_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN2_RN3_DETAILS':
      return action.rn2_rn3_details;

    default:
      return state;
  }
};
export const rn13_preview_history = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN13_PREVIEW_HISTORY':
      return action.rn13_preview_history;

    default:
      return state;
  }
};
export const rn7_preview_history = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN7_PREVIEW_HISTORY':
      return action.rn7_preview_history;

    default:
      return state;
  }
};
export const rn9_preview_history = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN9_PREVIEW_HISTORY':
      return action.rn9_preview_history;

    default:
      return state;
  }
};
export const pki_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_PKI_DETAILS':
      return action.pki_details;

    default:
      return state;
  }
};
export const RN1_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN1_APP_DETAILS':
      return action.RN1_app_details;

    default:
      return state;
  }
};
export const RN2_RN3_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN2_RN3_APP_DETAILS':
      return action.RN2_RN3_app_details;

    default:
      return state;
  }
};
export const RN2_RN3_mohuser_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN2_RN3_MOHUSERAPP_DETAILS':
      return action.RN2_RN3_mohuser_app_details;

    default:
      return state;
  }
};
export const reregion_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RE_REGION_DETAILS':
      return action.reregion_details;

    default:
      return state;
  }
};
export const ln1A_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_LN1A_APP_DETAILS':
      return action.ln1A_app_details;

    default:
      return state;
  }
};
export const applicantUserType = (state = {}, action) => {
  switch (action.type) {
    case 'SET_APPLICANT_USERTYPE':
      return action.applicantUserType;

    default:
      return state;
  }
};
export const createdUserTypeID = (state = "", action) => {
  switch (action.type) {
    case 'SET_CREATED_USERTYPE_ID':
      return action.createdUserTypeID;

    default:
      return state;
  }
};
export const applicantUserTypeData = (state = {}, action) => {
  switch (action.type) {
    case 'SET_APPLICANT_USERTYPE_ENGLISH':
      return action.applicantUserTypeData;

    default:
      return state;
  }
};
export const applicableService = (state = {}, action) => {
  switch (action.type) {
    case 'SET_APPLICABLE_SERVICE':
      return action.applicableService;

    default:
      return state;
  }
};
export const applicableSubService = (state = {}, action) => {
  switch (action.type) {
    case 'SET_APPLICABLE_SUB_SERVICE':
      return action.applicableSubService;

    default:
      return state;
  }
};
export const rn4KrookiNumber = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN4_KrookiNumber':
      return action.rn4KrookiNumber;

    default:
      return state;
  }
};
export const rn4_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN4_APP_DETAILS':
      return action.rn4_app_details;

    default:
      return state;
  }
};
export const resourceDetails = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RESOURCE_DETAILS':
      return action.resourceDetails;

    default:
      return state;
  }
};
export const applicationInternalStatus = (state = {}, action) => {
  switch (action.type) {
    case 'SET_APPLICATION_INTERNAL_STATUS':
      return action.applicationInternalStatus;

    default:
      return state;
  }
};
export const rn13_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN13_APP_DETAILS':
      return action.rn13_app_details;

    default:
      return state;
  }
};
export const rn7_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN7_APP_DETAILS':
      return action.rn7_app_details;

    default:
      return state;
  }
};
export const rn9_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN9_APP_DETAILS':
      return action.rn9_app_details;

    default:
      return state;
  }
};
export const rn10_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN10_APP_DETAILS':
      return action.rn10_app_details;

    default:
      return state;
  }
};
export const rn5_app_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_RN5_APP_DETAILS':
      return action.rn5_app_details;
    // case 'CLEAR':
    //     return state;

    default:
      return state;
  }
};
export const appInfo = (state = {}, action) => {
  switch (action.type) {
    case 'SET_APP_INFO':
      return action.appInfo;
    // case 'CLEAR':
    //     return state;

    default:
      return state;
  }
};
export const docs_upload_details = (state = {}, action) => {
  switch (action.type) {
    case 'SET_DOCS_DETAILS':
      return action.docs_upload_details;

    default:
      return state;
  }
};
export const applicantUserID = (state = {}, action) => {
  switch (action.type) {
    case 'SET_APPLICANT_USERID':
      return action.applicantUserID;

    default:
      return state;
  }
};
export const organizationDetails = (state = {}, action) => {
  switch (action.type) {
    case 'SET_ORGANIZATION_DETAILS':
      return action.organizationDetails;

    default:
      return state;
  }
};
export const organizationUserDetails = (state = {}, action) => {
  switch (action.type) {
    case 'SET_ORGANIZATION_USER_DETAILS':
      return action.organizationUserDetails;

    default:
      return state;
  }
};
export const orgUserValidator = (state = {}, action) => {
  switch (action.type) {
    case 'SET_ORG_USER_VALIDATOR':
      return action.orgUserValidator;

    default:
      return state;
  }
};
export const proxyUserDetails = (state = {}, action) => {
  switch (action.type) {
    case 'SET_PROXY_USER_DETAILS':
      return action.proxyUserDetails;

    default:
      return state;
  }
};
export const profileUserDetails = (state = {}, action) => {
  switch (action.type) {
    case 'SET_PROFILE_USER_DETAILS':
      return action.profileUserDetails;

    default:
      return state;
  }
}; // reducers.js

export const lang = (state = langState, action) => {
  switch (action.type) {
    case CHANGE_LANG:
      localStorage.setItem('currentLang', action.lang);
      return { ...state,
        ...{
          lang: action.lang
        }
      };

    default:
      return state;
  }
};
export const theme = (state = themeState, action) => {
  switch (action.type) {
    case CHANGE_THEME:
      localStorage.setItem('currentTheme', action.theme);
      return { ...state,
        ...{
          theme: action.theme
        }
      };

    default:
      return state;
  }
};
export const font = (state = fontState, action) => {
  switch (action.type) {
    case CHANGE_FONT:
      localStorage.setItem('currentFont', action.font);
      return { ...state,
        ...{
          font: action.font
        }
      };

    default:
      return state;
  }
};
export const routeHistory = (state = {
  history: ''
}, action) => {
  switch (action.type) {
    case SET_ROUTE_HISTORY:
      // localStorage.setItem('currentFont', action.history)
      return { ...state,
        ...{
          history: action.history
        }
      };

    default:
      return state;
  }
};
export const reducers = combineReducers({
  guid,
  pki_details,
  RN1_app_details,
  RN2_RN3_app_details,
  RN2_RN3_mohuser_app_details,
  reregion_details,
  ln1A_app_details,
  rn2_rn3_details,
  rn13_preview_history,
  rn7_preview_history,
  rn9_preview_history,
  applicantUserType,
  applicantUserTypeData,
  applicableService,
  applicableSubService,
  rn4KrookiNumber,
  rn4_app_details,
  resourceDetails,
  applicationInternalStatus,
  rn13_app_details,
  rn7_app_details,
  rn9_app_details,
  rn10_app_details,
  rn5_app_details,
  docs_upload_details,
  appInfo,
  applicantUserID,
  myInvolvedPartyDetails,
  organizationDetails,
  organizationUserDetails,
  orgUserValidator,
  proxyUserDetails,
  lang,
  theme,
  font,
  selectedService,
  routeHistory,
  filter,
  userList,
  createdUserTypeID,
  profileUserDetails
}); // store.js

export function configureStore(initialState = {}) {
  const store = createStore(reducers, initialState, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());
  return store;
}
;
export const store = configureStore();