"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = require("react");

var _RemotesActions = _interopRequireDefault(require("subfire/actions/RemotesActions"));

var _reactRouter = require("react-router");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

class RemoteConfigInit extends _react.Component {
  static getDerivedStateFromProps(props, lastState) {
    const s = props.SubsonicSource;

    if (s && s.initialized) {
      const id = s.fetcher._s + '-' + s.fetcher._u; // console.log(lastState.initialized, id);

      if (id !== lastState.initialized) {
        lastState.initialized = false;
      }
    }

    return lastState;
  }

  constructor(props) {
    super(props);
    this.state = {
      initialized: false
    };
  }

  shouldComponentUpdate(nextProps, nextState) {
    return nextState.initialized === false;
  }

  componentDidUpdate() {
    if (this.state.initialized) return;
    if (!this.props.SubsonicSource || !this.props.SubsonicSource.initialized) return;

    _RemotesActions.default.initRemoteState.defer(this.props.SubsonicSource, this.props.history);

    const s = this.props.SubsonicSource;
    const id = s.fetcher._s + '-' + s.fetcher._u;
    this.setState({
      initialized: id
    });
  }

  componentDidMount() {
    if (this.state.initialized) return;
    if (!this.props.SubsonicSource || !this.props.SubsonicSource.initialized) return;

    _RemotesActions.default.initRemoteState.defer(this.props.SubsonicSource, this.props.history);

    const s = this.props.SubsonicSource;
    const id = s.fetcher._s + '-' + s.fetcher._u;
    this.setState({
      initialized: id
    });
  }

  render() {
    return null;
  }

}

var _default = (0, _reactRouter.withRouter)(RemoteConfigInit);

exports.default = _default;