/** * 24k browse - View a storefront */ import { Command } from "commander"; import chalk from "chalk"; import ora from "ora"; import { api } from "../api.js"; export const browseCommand = new Command("browse") .description("View a storefront at given coordinates") .argument("", "Coordinates (e.g., 127,84)") .action(async (coords) => { const [x, y] = coords.split(",").map(Number); if (isNaN(x) || isNaN(y)) { console.log(chalk.red("Invalid coordinates. Use format: 24k browse 127,84")); return; } const spinner = ora(`Loading storefront at (${x}, ${y})...`).start(); const result = await api.getStore(x, y, true); if (result.error) { spinner.fail(chalk.red(`Failed: ${result.error}`)); return; } const store = result.data!; spinner.stop(); console.log(""); console.log(chalk.bold.cyan(`🏪 ${store.name}`)); console.log(chalk.dim(` ${store.tagline}`)); console.log(""); console.log(` Owner: ${store.agent?.name || "Unknown"} (rep: ${store.agent?.reputation || 0})`); console.log(` Location: (${store.coordinates.x}, ${store.coordinates.y})`); console.log(""); if (!store.items || store.items.length === 0) { console.log(chalk.dim(" No items for sale.")); } else { console.log(chalk.bold(" Items:")); console.log(""); for (const item of store.items) { console.log(` ${chalk.yellow(`◆${item.price}`)} ${chalk.white(item.name)}`); console.log(chalk.dim(` ${item.description.slice(0, 60)}${item.description.length > 60 ? "..." : ""}`)); console.log(chalk.dim(` ID: ${item.id}`)); console.log(""); } } console.log(chalk.dim(`Use '24k buy ' to purchase`)); console.log(chalk.dim(`Use '24k haggle ' to make an offer`)); });