import { useMemo, useState } from 'react' import { Link, useSearchParams } from 'react-router-dom' import { Eye, Plus, Stethoscope, UserCheck, UserX, Building2 } from 'lucide-react' import { PageShell } from '@/layouts/PageShell' import { StatCard } from '@/components/dashboard/StatCard' import { Card, CardContent } from '@/components/ui/card' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { StatusBadge } from '@/components/ui/status-badge' import { PersonAvatar } from '@/components/ui/avatar' import { TableToolbar, type TableFilter } from '@/components/table/TableToolbar' import { RowActions } from '@/components/table/RowActions' import { doctors as seed, organisations } from '@/mocks/data' import type { Doctor } from '@/types' const HOSPITAL_TYPES = new Set(['hospital', 'clinic']) export function DoctorsPage() { const [params] = useSearchParams() const orgFilterParam = params.get('orgId') ?? 'all' const [rows] = useState([...seed]) const [q, setQ] = useState('') const [status, setStatus] = useState('all') const [orgId, setOrgId] = useState(orgFilterParam) const hospitalOrgs = useMemo( () => organisations.filter((o) => HOSPITAL_TYPES.has(o.orgType) && o.status !== 'rejected'), [], ) const kpis = useMemo(() => { const scoped = orgId === 'all' ? rows : rows.filter((d) => d.orgId === orgId) return { total: scoped.length, active: scoped.filter((d) => d.status === 'active').length, inactive: scoped.filter((d) => d.status === 'inactive').length, linked: scoped.filter((d) => d.hasLinkedAccount).length, hospitals: hospitalOrgs.length, } }, [rows, orgId, hospitalOrgs.length]) const filtered = useMemo(() => { return rows.filter((d) => { if (orgId !== 'all' && d.orgId !== orgId) return false if (status !== 'all' && d.status !== status) return false if (q) { const needle = q.toLowerCase() if ( !d.name.toLowerCase().includes(needle) && !d.specialty.toLowerCase().includes(needle) && !d.licenseNumber.toLowerCase().includes(needle) && !d.orgName.toLowerCase().includes(needle) && !d.email.toLowerCase().includes(needle) ) { return false } } return true }) }, [rows, q, status, orgId]) const filters: TableFilter[] = [ { id: 'status', label: 'Status', value: status, onChange: setStatus, options: [ { value: 'all', label: 'All statuses' }, { value: 'active', label: 'Active' }, { value: 'inactive', label: 'Inactive' }, ], }, { id: 'org', label: 'Hospital', value: orgId, onChange: setOrgId, options: [ { value: 'all', label: 'All hospitals' }, ...hospitalOrgs.map((o) => ({ value: o.id, label: o.name })), ], }, ] const newHref = orgId !== 'all' ? `/doctors/new?orgId=${orgId}` : '/doctors/new' return (
{ setQ('') setStatus('all') setOrgId('all') }} actions={ } /> Doctor Specialty Hospital License Account Status Actions {filtered.length === 0 ? ( No doctors match these filters ) : null} {filtered.map((d) => ( {d.name} {d.specialty} {d.orgName} {d.licenseNumber} {d.hasLinkedAccount ? 'Linked' : 'Invite pending'} , to: `/doctors/${d.id}` }, ]} /> ))}
) }