"use client";

import { useState } from "react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { toast } from "sonner";

export default function AdminDashboard() {
  const [auth, setAuth] = useState(false);
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");

  if (!auth) {
    return (
      <div className="flex h-screen items-center justify-center p-4">
        <Card className="w-full max-w-sm p-6 space-y-4">
          <h2 className="text-2xl font-bold">Admin Login</h2>
          <Input placeholder="Email" onChange={(e) => setEmail(e.target.value)} />
          <Input type="password" placeholder="Password" onChange={(e) => setPassword(e.target.value)} />
          <Button className="w-full" onClick={() => { 
            if (email === "fredmitugo@gmail.com" && password === "fredchumari3#") setAuth(true);
            else toast.error("Invalid credentials");
          }}>Login</Button>
        </Card>
      </div>
    );
  }

  return (
    <ThemeProvider>
      <div className="p-8 space-y-8">
        <h1 className="text-3xl font-bold">Admin Dashboard</h1>
        <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
          <Card className="p-6">
            <h3 className="font-bold mb-4">User Management</h3>
            <p>Active Users: 15,234</p>
          </Card>
          <Card className="p-6 space-y-4">
            <h3 className="font-bold">M-Pesa STK Trigger</h3>
            <Button onClick={() => toast.success("STK Push initiated to +254115642074")}>Trigger Payment (+254115642074)</Button>
          </Card>
          <Card className="p-6 space-y-4">
            <h3 className="font-bold">AI Operations</h3>
            <Button variant="secondary" onClick={() => toast.info("AI Market Analysis Triggered")}>Trigger Market Analysis</Button>
            <Button onClick={() => toast.info("Signal Broadcasted to Subscribers")}>Broadcast Signal</Button>
          </Card>
        </div>
      </div>
    </ThemeProvider>
  );
}