"use strict";

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

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

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

var _uuid = require("uuid");

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

function useCredentialsStorage() {
  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 === '__new__') {
      key = (0, _uuid.v4)();
      delete creds.creds['__new__']; // clean up the mess from 3.0
    }

    creds.creds[key] = update;
    creds.current = key;
    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 = useCredentialsStorage;
exports.default = _default;