#!/usr/bin/env node

// Show current authenticated user and their assigned issues
// Usage: linear-me.js [--issues]

import { getClient, truncate } from "./lib.js";

const showIssues = process.argv.includes("--issues");

const client = getClient();

const me = await client.viewer;
console.log(`User: ${me.name}`);
console.log(`Email: ${me.email}`);
console.log(`ID: ${me.id}`);

if (showIssues) {
	const issues = await me.assignedIssues({
		first: 25,
		filter: {
			state: { type: { nin: ["completed", "canceled"] } },
		},
		orderBy: "updatedAt",
	});

	console.log(`\n--- Active Assigned Issues (${issues.nodes.length}) ---`);
	for (const issue of issues.nodes) {
		const state = await issue.state;
		console.log(
			`${issue.identifier.padEnd(12)} ${(state?.name || "?").padEnd(14)} ${(issue.priorityLabel || "").padEnd(8)} ${truncate(issue.title, 80)}`
		);
	}
}
