PatientsSearch.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. "use client"
  2. import { Card, CardContent } from "@/components/ui/card"
  3. import { Input } from "@/components/ui/input"
  4. import { Badge } from "@/components/ui/badge"
  5. import { Button } from "@/components/ui/button"
  6. import { Search, X, Filter } from "lucide-react"
  7. import { useState } from "react"
  8. interface PatientsSearchProps {
  9. searchTerm: string
  10. onSearchChange: (value: string) => void
  11. totalPatients: number
  12. filteredCount: number
  13. showFilters?: boolean
  14. }
  15. export default function PatientsSearch({
  16. searchTerm,
  17. onSearchChange,
  18. totalPatients,
  19. filteredCount,
  20. showFilters = false
  21. }: PatientsSearchProps) {
  22. const [activeFilter, setActiveFilter] = useState<string>("all")
  23. const handleClearSearch = () => {
  24. onSearchChange("")
  25. }
  26. const isFiltering = searchTerm.length > 0
  27. return (
  28. <Card>
  29. <CardContent className="pt-6 space-y-4">
  30. {/* Barra de búsqueda principal */}
  31. <div className="relative">
  32. <Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400" />
  33. <Input
  34. placeholder="Buscar por nombre, apellido, email o teléfono..."
  35. value={searchTerm}
  36. onChange={(e) => onSearchChange(e.target.value)}
  37. className="pl-10 pr-10 h-11"
  38. />
  39. {searchTerm && (
  40. <button
  41. onClick={handleClearSearch}
  42. className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600 transition-colors"
  43. >
  44. <X className="h-4 w-4" />
  45. </button>
  46. )}
  47. </div>
  48. {/* Filtros rápidos y estadísticas */}
  49. <div className="flex items-center justify-between flex-wrap gap-3">
  50. <div className="flex items-center gap-2 flex-wrap">
  51. {showFilters && (
  52. <>
  53. <span className="text-sm text-gray-600 font-medium">Filtros:</span>
  54. <Badge
  55. variant={activeFilter === "all" ? "default" : "outline"}
  56. className="cursor-pointer hover:bg-primary/90"
  57. onClick={() => setActiveFilter("all")}
  58. >
  59. Todos
  60. </Badge>
  61. <Badge
  62. variant={activeFilter === "recent" ? "default" : "outline"}
  63. className="cursor-pointer hover:bg-primary/90"
  64. onClick={() => setActiveFilter("recent")}
  65. >
  66. Recientes
  67. </Badge>
  68. <Badge
  69. variant={activeFilter === "active" ? "default" : "outline"}
  70. className="cursor-pointer hover:bg-primary/90"
  71. onClick={() => setActiveFilter("active")}
  72. >
  73. Activos
  74. </Badge>
  75. </>
  76. )}
  77. </div>
  78. {/* Contador de resultados */}
  79. <div className="flex items-center gap-2">
  80. {isFiltering ? (
  81. <div className="flex items-center gap-2">
  82. <span className="text-sm text-gray-600">
  83. Mostrando <span className="font-semibold text-primary">{filteredCount}</span> de{" "}
  84. <span className="font-semibold">{totalPatients}</span> pacientes
  85. </span>
  86. {filteredCount === 0 && (
  87. <Badge variant="secondary" className="text-xs">
  88. Sin resultados
  89. </Badge>
  90. )}
  91. </div>
  92. ) : (
  93. <span className="text-sm text-gray-600">
  94. <span className="font-semibold text-primary">{totalPatients}</span> pacientes en total
  95. </span>
  96. )}
  97. </div>
  98. </div>
  99. {/* Sugerencias de búsqueda */}
  100. {!isFiltering && totalPatients > 0 && (
  101. <div className="pt-2 border-t">
  102. <div className="flex items-center gap-2 text-xs text-gray-500">
  103. <Filter className="h-3 w-3" />
  104. <span>Tip: Puedes buscar por nombre, apellido, email o información médica</span>
  105. </div>
  106. </div>
  107. )}
  108. {/* Mensaje cuando no hay resultados */}
  109. {isFiltering && filteredCount === 0 && (
  110. <div className="pt-2 border-t">
  111. <div className="text-sm text-amber-600 bg-amber-50 rounded-lg p-3 flex items-center gap-2">
  112. <Search className="h-4 w-4" />
  113. <span>No se encontraron pacientes con &quot;{searchTerm}&quot;</span>
  114. </div>
  115. </div>
  116. )}
  117. </CardContent>
  118. </Card>
  119. )
  120. }