"""Logout command - clear stored credentials."""

import typer

from nogic.config import Config
from nogic import telemetry, ui


def logout():
    """Log out of your Nogic account (clear stored API key)."""
    config = Config.load()

    if not config.api_key:
        ui.info("You are not logged in.")
        raise typer.Exit(0)

    config.api_key = None
    config.save_global()

    ui.console.print()
    ui.success("Logged out successfully.")
    ui.dim("Credentials cleared.")

    telemetry.capture("cli_logout", {"success": True})
