'use client';

import { useState } from 'react';
import { useQuery } from '@tanstack/react-query';
import { Download } from 'lucide-react';
import DataTable from '@/components/ui/DataTable';
import Badge from '@/components/ui/Badge';
import ActionButton from '@/components/ui/ActionButton';
import { reportsApi } from '@/lib/api';
import { formatDateTime, formatCurrency } from '@/lib/utils';

export default function OperationalreportsPage() {
  const [filters, setFilters] = useState({ search: '', reportType: '' });

  const { data, isLoading } = useQuery({
    queryKey: ['operational-reports', filters],
    queryFn: () => reportsApi.getOperationalReports(filters),
  });

  const columns = [
      { key: 'reportType', label: 'Type', render: (report: any) => <Badge>{report.reportType}</Badge> },
      { key: 'period', label: 'Period', render: (report: any) => report.period || 'N/A' },
      { key: 'generatedBy', label: 'Generated By', render: (report: any) => report.generatedBy?.fullName || 'System' },
      { key: 'createdAt', label: 'Generated', render: (report: any) => formatDateTime(report.createdAt) },
    ];

  return (
    <div className="space-y-6">
      <div className="flex items-center justify-between">
        <div>
          <h1 className="text-2xl font-bold text-foreground">Operational Reports</h1>
          <p className="text-muted-foreground">View operational reports and analytics</p>
        </div>
        <ActionButton icon={Download} variant="secondary">Export</ActionButton>
      </div>

      <div className="card">
        <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
          
      <div>
        <label className="label">Search</label>
        <input type="text" placeholder="Search..." className="input" value={filters.search} onChange={(e) => setFilters({ ...filters, search: e.target.value })} />
      </div>
      <div>
        <label className="label">Report Type</label>
        <select className="input" value={filters.reportType} onChange={(e) => setFilters({ ...filters, reportType: e.target.value })}>
          <option value="">All Types</option>
          <option value="REVENUE">Revenue</option>
          <option value="OCCUPANCY">Occupancy</option>
          <option value="PERFORMANCE">Performance</option>
        </select>
      </div>
    
        </div>
      </div>

      <DataTable
        data={data?.items || data || []}
        columns={columns}
        loading={isLoading}
        emptyMessage="No operational reports found"
      />
    </div>
  );
}
