import _ from 'lodash';

const defaultStoreStructure = {
  settings: {
    wideScreen: true,
    threadPreview: true,
    adsRemove: true,
    linkHelper: true,
    notifyQuote: true,
    emotionHelper: true,
    minimizeQuote: true,
    quickPostQuotation: true,
    reloadButton: true,
    delay: 1, // minute
  },
  authInfo: {},
  quotes: [],
  quickLinks: [
    {
      id: 'voz_living_f17',
      label: 'F17',
      link: 'https://vozforums.com/forumdisplay.php?f=17',
    },
  ],
  followThreads: {},
  threadTracker: {},
  currentPost: {},
  userStyle: 'default',
};

export default defaultStoreStructure;

const defaultSettingKeys = _.keys(defaultStoreStructure);

/* eslint-disable no-undef */
export const getChromeLocalStore = (keys = defaultSettingKeys) => (
  new Promise(resolve => {
    chrome.storage.local.get(keys, items => {
      if (_.isEmpty(items)) {
        const result = { };
        let outKeys = keys;
        if (_.isString(outKeys)) {
          outKeys = [outKeys];
        }
        outKeys.forEach(key => {
          result[key] = defaultStoreStructure[key];
        });
        resolve(result);
      } else {
        const result = items;
        keys.forEach(key => {
          if (_.isUndefined(result[key])) {
            result[key] = defaultStoreStructure[key];
          }
        });
        resolve(result);
      }
    });
  })
);

export const setChromeLocalStore = items => (
  new Promise(resolve => {
    chrome.storage.local.set(items, () => resolve(true));
  })
);
/* eslint-enable no-undef */

@@ -476,16 +476,136 @@
 %0A    %7D,%0A
+    %7B%0A      id: 'voz_living_f33',%0A      label: 'F33',%0A      link: 'https://vozforums.com/forumdisplay.php?f=33',%0A    %7D,%0A
   %5D,%0A  f

add f33 to default quicklink