/*
# Bookmarks Manager.
*/

// Name: bookmarksManager
// Description: Manage bookmarks. Open a bookmark from a list of bookmarks.
// Author: Vivek Kodira

import "@johnlindquist/kit";

// NOTE: This array should ideally be part of another file and imported here. You'd have one for each group of bookmarks
// This is just a sample array to demonstrate the concept. 
// TIP: Make the name as descriptive as possible. Since ScriptKit supports fuzzy search, you will find the bookmark easier

export const tools = [
  {
    name: "ScriptKit: API", 
    value: "https://johnlindquist.github.io/kit-docs/",
  },
  {
    name: "ScriptKit: gitrepo",
    value: "https://github.com/johnlindquist/kit",
  },
  {
    name: "ScriptKit: website",
    value: "https://www.scriptkit.com/",
  },
  {
    name: "Jest: CLI config",
    value: "https://jestjs.io/docs/cli",
  },
  {
    name: "ESlint docs",
    value: "https://eslint.org/docs/latest/",
  },
  {
    name: "Github Search documentation",
    value:
      "https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests",
  },
  {
    name: "Material UI | MUI Component list",
    value: "https://mui.com/material-ui/all-components/",
  },
];

/* Actual start of script. */
export const bookmarks = [
  ...tools, // Spread each set of bookmarks into the main array
];

// Not used by this script but can be exported so you can open several bookmarks at one go
// Ex: open all the bookmarks associated with a particular project
export const openBookMarks = async (bookmarksToOpen) => {
  for (let bookmark of bookmarksToOpen) {
    const chosenBookmark = bookmarks.find((b) => b.name.includes(bookmark));
    if (chosenBookmark) {
      await exec(`open "${chosenBookmark.value}"`);
    }
  }
};

let url = await arg(
  { strict: false, ignoreBlur: true, placeholder: `Select bookmark` },
  bookmarks
);

exec(`open "${url}"`);