import { PipedriveClient, err } from "../client.js";
import type { ToolDefinition, ToolResult } from "../types.js";

export const tools: ToolDefinition[] = [
  {
    name: "pipedrive_app_revenue_dashboard",
    description: "Revenue analytics and forecasting",
    inputSchema: {
      type: "object",
      properties: {},
    },
  },
];

function escapeHtml(s: string | undefined): string {
  return (s || "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
}

export async function handle(
  client: PipedriveClient,
  name: string,
  args: Record<string, unknown>
): Promise<ToolResult> {
  try {
    const html = `
      <div style="font-family:-apple-system,BlinkMacSystemFont,sans-serif;background:#0d0d1a;color:#e0e0e0;padding:24px;border-radius:16px;">
        <h2 style="margin:0 0 16px;color:#fff;">🎯 Revenue Dashboard</h2>
        <div style="background:#1a1a2e;padding:20px;border-radius:8px;">
          <p style="color:#888;">This app provides Revenue analytics and forecasting</p>
        </div>
      </div>
    `;

    return {
      content: [{ type: "text", text: "Revenue Dashboard loaded successfully" }],
      structuredContent: { type: "html", html },
    };
  } catch (error) {
    return err(error);
  }
}
