"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

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

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

var _orientation = require("subfirelib/ui/orientation");

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

var _classnames = _interopRequireDefault(require("classnames"));

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

require("subfirelib/app/main.css");

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

var _ThePlayer = _interopRequireDefault(require("./ThePlayer"));

var _components = require("./components");

var _PlaylistGrid = _interopRequireDefault(require("subfirelib/browsers/playlists/PlaylistGrid"));

var _RadioGrid = _interopRequireDefault(require("subfirelib/browsers/playlists/RadioGrid"));

var _PlaylistSongs = _interopRequireDefault(require("subfirelib/browsers/playlists/PlaylistSongs"));

var _ArtistAlbums = _interopRequireDefault(require("subfirelib/browsers/id3/ArtistAlbums"));

var _AlbumSongs = _interopRequireDefault(require("subfirelib/browsers/id3/AlbumSongs"));

var _MusicDirectory = _interopRequireDefault(require("subfirelib/browsers/md/MusicDirectory"));

var _AutoPlayer = _interopRequireDefault(require("./components/players/AutoPlayer"));

var _PortraitPlayer = _interopRequireDefault(require("./components/players/PortraitPlayer"));

var _FooterPlayer = _interopRequireDefault(require("./components/players/FooterPlayer"));

var _RoutePlayerLoader = _interopRequireDefault(require("subfirelib/loader/RoutePlayerLoader"));

var _LoginCredentials = _interopRequireDefault(require("subfirelib/credentials/LoginCredentials"));

var _AuthCodeSource = _interopRequireDefault(require("subfirelib/credentials/AuthCodeSource"));

var _AuthCodeClient = _interopRequireDefault(require("subfirelib/credentials/AuthCodeClient"));

var _VideoLibrary = _interopRequireDefault(require("@material-ui/icons/VideoLibrary"));

var _MusicFolderChooser = _interopRequireDefault(require("subfirelib/browsers/MusicFolderChooser"));

var _PodcastsBrowser = _interopRequireDefault(require("subfirelib/browsers/PodcastsBrowser"));

var _BookmarksBrowser = _interopRequireDefault(require("subfirelib/browsers/BookmarksBrowser"));

var _AlbumsBrowser = _interopRequireDefault(require("subfirelib/browsers/albums/AlbumsBrowser"));

var _ArtistsList = _interopRequireDefault(require("subfirelib/browsers/id3/ArtistsList"));

var _MusicDirectoryList = _interopRequireDefault(require("subfirelib/browsers/md/MusicDirectoryList"));

var _FuzzyImageBackground = _interopRequireDefault(require("subfirelib/ui/FuzzyImageBackground"));

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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-disable-line
// eslint-disable-line
// eslint-disable-line
// import {
//   Portrait,
//   Landscape,
//   PortraitGrid as PG,
//   LandscapeGrid as LG,
//   isLandscape,
//   useWindowSize
// } from 'subfirelib/ui/orientation';
// import { Th1 } from 'subfirelib/ui/TG';
const useStyles = (0, _styles.makeStyles)(theme => ({
  content: {
    overflowX: 'hidden',
    overflowY: 'scroll',
    height: 'calc(100% - 64px - 56px)',
    paddingTop: 0,
    paddingBottom: 0,
    paddingLeft: 0,
    paddingRight: 0
  }
}));

function Main(props) {
  // const dimensions = useWindowSize();
  (0, _hooks.useLoginSnacker)();
  const history = (0, _reactRouter.useHistory)();
  const classes = useStyles();
  const defaultTheme = (0, _styles.useTheme)();
  const {
    theme: imageTheme = defaultTheme
  } = (0, _hooks.useImageColorTheme)();
  const {
    pushToTop,
    justPlaySong
  } = (0, _hooks.useQueue)(); // const { pathname } = useLocation();
  // const isPlaylists = pathname.startsWith('/playlists');
  // const [ac, setAC] = useState((<></>));
  // useEffect(() => {
  //   console.log('effect', pathname);
  //   // setAC((<><span>{pathname}</span></>));
  // }, [pathname]);

  return /*#__PURE__*/_react.default.createElement("div", {
    className: "subfire"
  }, /*#__PURE__*/_react.default.createElement(_reactRouter.Switch, null, /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/player"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "page-bg"
  }), /*#__PURE__*/_react.default.createElement("div", {
    style: {
      position: 'relative',
      top: 0,
      height: '100vh'
    }
  }, /*#__PURE__*/_react.default.createElement(_styles.ThemeProvider, {
    theme: imageTheme
  }, /*#__PURE__*/_react.default.createElement(_ThePlayer.default, {
    render: (components, currentPlaying, queue) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_FuzzyImageBackground.default, {
      selector: ".page-bg",
      image: currentPlaying.artwork,
      showBackground: true,
      fadeBackground: false
    }), /*#__PURE__*/_react.default.createElement(_orientation.Landscape, null, /*#__PURE__*/_react.default.createElement(_AutoPlayer.default, {
      components: components,
      currentPlaying: currentPlaying,
      queue: queue
    })), /*#__PURE__*/_react.default.createElement(_orientation.Portrait, null, /*#__PURE__*/_react.default.createElement(_PortraitPlayer.default, {
      components: components,
      currentPlaying: currentPlaying,
      queue: queue
    })))
  })))), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/load(ing)/:type/:id/:mode?",
    exact: true,
    strict: true
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "page-bg"
  }), /*#__PURE__*/_react.default.createElement(_RoutePlayerLoader.default, {
    targetRoute: "/player"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/bookmark/:bookmarkId/:position/loading/:type/:id/:mode?",
    exact: true,
    strict: true
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "page-bg"
  }), /*#__PURE__*/_react.default.createElement(_RoutePlayerLoader.default, {
    targetRoute: "/player"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, null, /*#__PURE__*/_react.default.createElement("div", {
    className: "home-bg"
  }), /*#__PURE__*/_react.default.createElement(_components.MainHeader, null), /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(classes.content, 'main-content')
  }, /*#__PURE__*/_react.default.createElement(_reactRouter.Switch, null, /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/playlists/:pltype"
  }, /*#__PURE__*/_react.default.createElement(_PlaylistGrid.default, {
    onClick: e => {
      console.log('onClick', e);
      history.push("/loading/playlist/".concat(e));
    },
    onImageClick: e => {
      console.log('onImageClick', e);
      history.push("/playlist/".concat(e));
    },
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/radio"
  }, /*#__PURE__*/_react.default.createElement(_RadioGrid.default, {
    onClick: e => {
      console.log('onClick', e);
      history.push("/loading/radiostation/".concat(e));
    },
    onImageClick: e => {
      console.log('onImageClick', e);
      history.push("/loading/radiostation/".concat(e));
    },
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/playlist/:id"
  }, /*#__PURE__*/_react.default.createElement(_PlaylistSongs.default, {
    onSongClick: song => {
      console.log("/loading/song/".concat(song.id, " - the route thats used for remote control, so use it here"));
      pushToTop(song, true);
    },
    showBackButton: true,
    showActions: true,
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/albums"
  }, /*#__PURE__*/_react.default.createElement(_AlbumsBrowser.default, {
    secondaryActionLabel: "Play",
    SecondaryIcon: _VideoLibrary.default,
    onAlbumClick: (id, id3) => {
      console.log('go to album', id, id3);
      if (id3) history.push("/album/".concat(id));else history.push("/directory/".concat(id));
    },
    onAlbumSecondaryClick: (id, id3) => {
      console.log('play album', id, id3);
      if (id3) history.push("/loading/albumAction/".concat(id, "/play"));else history.push("/loading/directoryAction/".concat(id, "/play"));
    },
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/album/:id"
  }, /*#__PURE__*/_react.default.createElement(_AlbumSongs.default, {
    showAlbumActions: true,
    showAlbumInfo: true,
    onSongClick: song => {
      console.log("/loading/song/".concat(song.id, " - the route thats used for remote control, so use it here"));
      pushToTop(song, true);
    },
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/artist/:id"
  }, /*#__PURE__*/_react.default.createElement(_ArtistAlbums.default, {
    showArtistActions: true,
    showArtistInfo: true,
    onAlbumClick: id => {
      console.log('go to album', id);
      history.push("/album/".concat(id));
    },
    onAlbumPlayClick: id => history.push("/loading/albumAction/".concat(id, "/play")),
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/artists"
  }, /*#__PURE__*/_react.default.createElement(_MusicFolderChooser.default, {
    native: false
  }), /*#__PURE__*/_react.default.createElement(_ArtistsList.default, {
    secondaryActionLabel: "play all",
    SecondaryIcon: _VideoLibrary.default,
    onArtistClick: id => {
      console.log('go to artist', id);
      history.push("/artist/".concat(id));
    },
    onArtistSecondaryClick: id => {
      console.log('play all artist songs', id);
      history.push("/loading/artistAction/".concat(id, "/all"));
    },
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/directory/:id"
  }, /*#__PURE__*/_react.default.createElement(_MusicDirectory.default, {
    showDirectoryActions: true,
    secondaryActionLabel: "play all",
    SecondaryIcon: _VideoLibrary.default,
    onDirectoryClick: id => {
      console.log('go to directory', id);
      history.push("/directory/".concat(id));
    },
    onDirectorySecondaryClick: id => history.push("/loading/directoryAction/".concat(id, "/play")),
    onSongClick: song => {
      console.log("/loading/song/".concat(song.id, " - the route thats used for remote control, so use it here"));
      pushToTop(song, true);
    },
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/indexes"
  }, /*#__PURE__*/_react.default.createElement(_MusicFolderChooser.default, {
    native: false
  }), /*#__PURE__*/_react.default.createElement(_MusicDirectoryList.default, {
    secondaryActionLabel: "play all",
    SecondaryIcon: _VideoLibrary.default,
    onArtistClick: e => {
      console.log('go to index directory', e);
      history.push("/directory/".concat(e));
    },
    onArtistSecondaryClick: e => {
      console.log('play all artist songs', e);
      history.push("/loading/directoryAction/".concat(e, "/all"));
    },
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/podcasts"
  }, /*#__PURE__*/_react.default.createElement(_PodcastsBrowser.default, {
    onClick: e => {
      console.log('onClick', e);
      justPlaySong(e);
    },
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/bookmarks"
  }, /*#__PURE__*/_react.default.createElement(_BookmarksBrowser.default, {
    onClick: (b, p) => {
      console.log('onClick', b, p);
      history.push(p);
    },
    onDeleteClick: b => {
      console.log('onDeleteClick', b);
    },
    scrollSelector: ".main-content"
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, null, /*#__PURE__*/_react.default.createElement(_components.NavGrid, null)))), /*#__PURE__*/_react.default.createElement(_ThePlayer.default, {
    render: (components, currentPlaying, queue) => /*#__PURE__*/_react.default.createElement(_FooterPlayer.default, {
      components: components,
      currentPlaying: currentPlaying,
      queue: queue
    })
  }), /*#__PURE__*/_react.default.createElement(_reactRouter.Switch, null, /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/login"
  }, /*#__PURE__*/_react.default.createElement(_LoginCredentials.default, {
    handleClose: history.goBack
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/linkSource"
  }, /*#__PURE__*/_react.default.createElement(_AuthCodeSource.default, {
    handleClose: history.goBack
  })), /*#__PURE__*/_react.default.createElement(_reactRouter.Route, {
    path: "/linkClient"
  }, /*#__PURE__*/_react.default.createElement(_AuthCodeClient.default, {
    handleClose: history.goBack
  }))))), /*#__PURE__*/_react.default.createElement(_components.SubsonicQueueAudio, null));
}

var _default = Main;
exports.default = _default;