"use strict";

require("core-js/modules/web.dom-collections.iterator");

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

var _react = require("react");

var _reactUse = require("react-use");

var _silence2sec = _interopRequireDefault(require("subfirelib/static/silence2sec.mp3"));

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

const initLastPlaying = {
  queue: [],
  idx: -1,
  queueName: 'Last Time...',
  queueRule: '' // holds the equiv of the bookmark syntax

};
const emptytrack = {
  album: '',
  albumId: '-1',
  artist: '',
  year: null,
  coverArt: '-1',
  albumYear: 'restarting the play queue',
  contentType: 'audio/mp3',
  duration: 2,
  title: 'restarting...',
  track: 1,
  localPath: _silence2sec.default
};
exports.emptytrack = emptytrack;

const useQueue = () => {
  const [queue, _setQueue] = (0, _reactUse.useLocalStorage)('subsonic.lastPlaying', initLastPlaying);
  const [restartingTitle, setRestartingTitle] = (0, _react.useState)('restarting...');
  queue.queueName = queue.queueName || 'Last Time...';
  queue.queue = queue.queue || [];
  emptytrack.title = restartingTitle;

  function nextSong() {
    let idx = queue.idx + 1;
    if (idx >= queue.queue.length) idx = 0;
    const newQueue = { ...queue,
      idx
    };

    _setQueue(newQueue);
  }

  function prevSong() {}

  function skipAlbum() {}

  function setCurrentQueue(songlist, idx, queueName, queueRule) {
    if (songlist.length === 1) {
      songlist.push(emptytrack);
    }

    const newQueue = {
      queue: songlist,
      idx,
      queueName,
      queueRule
    };

    _setQueue(newQueue);
  }

  const current = queue.idx === -1 ? {} : queue.queue[queue.idx];
  return [queue, current, {
    setCurrentQueue,
    nextSong,
    skipAlbum,
    prevSong,
    setRestartingTitle
  }, _setQueue];
};

exports.useQueue = useQueue;
var _default = useQueue;
exports.default = _default;