"use strict";

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

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

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

var _v = _interopRequireDefault(require("uuid/v4"));

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

function createDemo() {
  const SubFireDemo = {
    name: 'SubFire Demo',
    server: 'https://subfiresuite.com/ampache',
    username: 'guest',
    password: 'guest1',
    bitrate: '0'
  };
  const demo = (0, _v.default)();
  const creds = {};
  creds[demo] = SubFireDemo;
  return {
    creds: creds,
    current: demo
  };
}

function useCredentials() {
  const [creds, setCreds] = (0, _reactUse.useLocalStorage)('subsonic.credentials', createDemo());

  function setCurrent(current) {
    creds.current = current;
    setCreds({ ...creds
    });
  }

  const current = creds.creds[creds.current];

  function updateCreds(key, update) {
    if (!key) key = (0, _v.default)();
    creds.creds[key] = update;
    setCreds({ ...creds
    });
  }

  function deleteCreds(key) {
    delete creds.creds[key];
    setCreds({ ...creds
    });
  } // for credentials link-up


  function importCreds(newCreds) {
    const mergedCreds = { ...creds,
      ...newCreds
    };
    setCreds(mergedCreds);
  }

  return [current, creds.creds, creds.current, setCurrent, updateCreds, deleteCreds, importCreds];
}

var _default = useCredentials;
exports.default = _default;