import { useState } from "react";
import { ExpensesProvider } from "./ExpensesProvider";
import { ExpensesTabContent } from "./components/ExpensesTabContent";
import { PeriodicExpensesTabContent } from "./components/PeriodicExpensesTabContent";

const tabs = [
  { id: "expenses", label: "Gastos" },
  { id: "periodic", label: "Gastos Periódicos" },
] as const;

type TabId = (typeof tabs)[number]["id"];

function ExpensesPageInner() {
  const [activeTab, setActiveTab] = useState<TabId>("expenses");

  return (
    <div className="space-y-4">
      <h1 className="text-2xl font-semibold">Gastos</h1>

      <div className="flex gap-1 border-b">
        {tabs.map((tab) => (
          <button
            key={tab.id}
            type="button"
            onClick={() => setActiveTab(tab.id)}
            className={
              activeTab === tab.id
                ? "-mb-px border-b-2 border-primary px-3 pb-2 text-sm font-medium text-foreground"
                : "px-3 pb-2 text-sm font-medium text-muted-foreground transition-colors hover:text-foreground"
            }
          >
            {tab.label}
          </button>
        ))}
      </div>

      {activeTab === "expenses" && <ExpensesTabContent />}
      {activeTab === "periodic" && <PeriodicExpensesTabContent />}
    </div>
  );
}

export function ExpensesPage() {
  return (
    <ExpensesProvider>
      <ExpensesPageInner />
    </ExpensesProvider>
  );
}
