import "@johnlindquist/kit"
let searchQuery = await arg("Enter a search query: ");
const url = `https://en.wikipedia.org/w/api.php?action=query&generator=search&gsrlimit=20&prop=pageimages%7Cextracts&exintro&explaintext&exlimit=max&format=json&gsrsearch=${searchQuery}`;
const result = await get(url);
let articleId = await arg("Please choose an article: ", Object.keys(result.data.query.pages).map(
(id) => ({
name: result.data.query.pages[id].title,
description: `https://en.wikipedia.org/wiki/${result.data.query.pages[id].title}`,
preview: () => `
<h3>${result.data.query.pages[id].title}</h3>
<p>${result.data.query.pages[id].extract}</p>`,
value: result.data.query.pages[id].pageid
})
))
browse(`https://en.wikipedia.org/?curid=${articleId}`)