"use strict";

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

var _react = _interopRequireWildcard(require("react"));

var _Welcome = _interopRequireDefault(require("subfirelib/storybook/Welcome"));

var _reactRouterDom = require("react-router-dom");

var _CredentialsContext = require("subfirelib/hooks/contexts/CredentialsContext");

var _SubsonicContext = require("subfirelib/hooks/contexts/SubsonicContext");

var _PlaylistsContext = require("subfirelib/hooks/contexts/PlaylistsContext");

var _useRemoteReceiver = require("subfirelib/hooks/useRemoteReceiver");

var _useRemoteSender = require("subfirelib/hooks/useRemoteSender");

var _notistack = require("notistack");

var _Button = _interopRequireDefault(require("@material-ui/core/Button"));

var _styles = require("@material-ui/core/styles");

var _amber = _interopRequireDefault(require("@material-ui/core/colors/amber"));

var _hooks = require("subfirelib/hooks");

var _TG = require("subfirelib/ui/TG");

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/* eslint react/prop-types: 0 */
let defaultTheme = (0, _styles.createMuiTheme)({
  palette: {
    primary: _amber.default,
    secondary: {
      main: '#283593'
    },
    type: 'dark'
  }
});
defaultTheme = (0, _styles.responsiveFontSizes)(defaultTheme);

function App(props) {
  (0, _react.useEffect)(() => {
    document.body.classList.add('subfire');
    return () => {
      document.body.classList.remove('subfire');
    };
  }, []);
  const isOnline = (0, _hooks.useNetwork)();
  const Main = props.Main || _Welcome.default;
  const theme = props.theme || defaultTheme;

  const notistackRef = /*#__PURE__*/_react.default.createRef();

  const onClickDismiss = key => () => {
    notistackRef.current.closeSnackbar(key);
  };

  if (!isOnline) {
    return /*#__PURE__*/_react.default.createElement(_styles.ThemeProvider, {
      theme: theme
    }, /*#__PURE__*/_react.default.createElement(_TG.Th4, null, "This application has no offline mode - it requires a network to connect to your Subsonic server."));
  }

  return /*#__PURE__*/_react.default.createElement(_styles.ThemeProvider, {
    theme: theme
  }, /*#__PURE__*/_react.default.createElement(_notistack.SnackbarProvider, {
    ref: notistackRef,
    action: key => /*#__PURE__*/_react.default.createElement(_Button.default, {
      style: {
        color: '#ffffff'
      },
      size: "small",
      onClick: onClickDismiss(key)
    }, "Dismiss")
  }, /*#__PURE__*/_react.default.createElement(_CredentialsContext.CredentialsProvider, null, /*#__PURE__*/_react.default.createElement(_SubsonicContext.SubsonicProvider, null, /*#__PURE__*/_react.default.createElement(_PlaylistsContext.PlaylistsProvider, null, /*#__PURE__*/_react.default.createElement(_useRemoteReceiver.RemoteReceiverProvider, null, /*#__PURE__*/_react.default.createElement(_useRemoteSender.RemoteSenderProvider, null, /*#__PURE__*/_react.default.createElement(_reactRouterDom.HashRouter, {
    basename: "/"
  }, /*#__PURE__*/_react.default.createElement(Main, null)))))))));
}

var _default = App;
exports.default = _default;