'use client';

import { useState } from 'react';
import { useAuth } from '@/lib/auth';
import { apiRequest } from '@/lib/api';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';

const AdminPage = () => {
    const [message, setMessage] = useState('');
    const [error, setError] = useState('');
    const auth = useAuth();

    const handleScan = async () => {
        setError('');
        setMessage('Scanning...');
        try {
            const data = await apiRequest('/videos/scan', { method: 'POST', token: auth.token });
            setMessage(data.message);
        } catch (err: any) {
            setError(err.message);
        }
    };
    
    const users = [{email: 'admin@example.com', role: 'admin'}, {email: 'user@example.com', role: 'user'}];
    const votes = [{video_id: 'xyz', decision: 'approve', reason: 'Good clip'}];

    if (auth.user?.role !== 'admin') {
        return <p>Access Denied. You must be an admin to view this page.</p>;
    }

    return (
        <div className="space-y-8">
            <Card>
                <CardHeader>
                    <CardTitle>Admin Actions</CardTitle>
                </CardHeader>
                <CardContent>
                    <Button onClick={handleScan}>Scan Videos Directory</Button>
                    {message && <p className="mt-4 text-green-600">{message}</p>}
                    {error && <p className="mt-4 text-red-600">{error}</p>}
                </CardContent>
            </Card>

            <Card>
                <CardHeader><CardTitle>Users</CardTitle></CardHeader>
                <CardContent>
                    <p>User list functionality would go here.</p>
                </CardContent>
            </Card>

            <Card>
                <CardHeader><CardTitle>Votes</CardTitle></CardHeader>
                <CardContent>
                    <p>Vote list functionality would go here.</p>
                </CardContent>
            </Card>
        </div>
    );
};

export default AdminPage;