import React from 'react';
import 'hoist-non-react-statics';
import { ReactReduxContext } from 'react-redux';
import invariant from 'invariant';
import { conformsTo, isFunction, isObject, isString, isEmpty } from 'lodash';
import { c as createReducer } from './TopicsListComponent-95e44af6.js';
import styled from 'styled-components';

/**
 * Validate the shape of redux store
 */

function checkStore(store) {
  const shape = {
    dispatch: isFunction,
    subscribe: isFunction,
    getState: isFunction,
    replaceReducer: isFunction,
    runSaga: isFunction,
    injectedReducers: isObject,
    injectedSagas: isObject
  };
  invariant(conformsTo(store, shape), '(app/utils...) injectors: Expected a valid redux store');
}

function injectReducerFactory(store, isValid) {
  return function injectReducer(key, reducer) {
    if (!isValid) checkStore(store);
    invariant(isString(key) && !isEmpty(key) && isFunction(reducer), '(app/utils...) injectReducer: Expected `reducer` to be a reducer function'); // Check `store.injectedReducers[key] === reducer` for hot reloading when a key is the same but a reducer is different

    if (Reflect.has(store.injectedReducers, key) && store.injectedReducers[key] === reducer) return;
    store.injectedReducers[key] = reducer; // eslint-disable-line no-param-reassign

    store.replaceReducer(createReducer(store.injectedReducers));
  };
}
function getInjectors(store) {
  checkStore(store);
  return {
    injectReducer: injectReducerFactory(store, true)
  };
}

const useInjectReducer = ({
  key,
  reducer
}) => {
  const context = React.useContext(ReactReduxContext);
  React.useEffect(() => {
    getInjectors(context.store).injectReducer(key, reducer);
  }, []);
};

const RESTART_ON_REMOUNT = '@@saga-injector/restart-on-remount';
const DAEMON = '@@saga-injector/daemon';
const ONCE_TILL_UNMOUNT = '@@saga-injector/once-till-unmount'; // const conf = window.REACT_COMMENTS_DJANGO_CONFIG

const conf = window.REACT_COMMENTS_DJANGO_CONFIG;
let API_URL_POSTFIX = '';
let API_URL_DOMAIN = '';

if (conf) {
  ({
    API_URL_POSTFIX
  } = conf);

  if ('API_URL_DOMAIN' in conf) {
    ({
      API_URL_DOMAIN
    } = conf);
  }
}

const API_PREFIX = `${API_URL_DOMAIN}/api/v1/${API_URL_POSTFIX}`;

const H2 = styled.h2.withConfig({
  displayName: "H2",
  componentId: "sc-1ujnxqo-0"
})(["font-size:1.5em;"]);

export { API_PREFIX as A, DAEMON as D, H2 as H, ONCE_TILL_UNMOUNT as O, RESTART_ON_REMOUNT as R, checkStore as c, useInjectReducer as u };
//# sourceMappingURL=index-210b5d62.js.map
