const { setSelectedText } = await kit("text");
function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}
const snippetMap = {
  useState: {
    args: [() => arg("variable name"), () => arg("variable value")],
    template: (name, value) =>
      `const [${name}, set${capitalizeFirstLetter(name)}] = useState(${value})`,
  },
  name: "Jakub Olek",
  date: new Date().toLocaleDateString("en-GB", {
    year: "numeric",
    month: "long",
    day: "numeric",
  }),
  test: {
    args: [() => arg("should")],
    template: (testName) => `test("should ${testName}", function() {
  })`,
  },
  component: {
    args: [() => arg("component name")],
    template: (componentName) => `function ${capitalizeFirstLetter(
      componentName
    )}() {
      return
    }`,
  },
};
const snippetName = await arg("Snippet", Object.keys(snippetMap));
let result = snippetMap[snippetName];
const { args, template } = result;
if (template) {
  const variables = [];
  if (args) {
    for (let i = 0; i < args.length; i++) {
      const variable = args[i];
      if (typeof variable !== "string") {
        variables.push(await variable());
      }
    }
  }
  setSelectedText(template(...variables));
} else {
  setSelectedText(result);
}