'use client' import { useState } from 'react' import { useAppStore } from '@/store' import { PREDEFINED_KERNELS, KERNEL_CATEGORIES, getKernelsByCategory } from '@/lib/kernels' import type { KernelCategory } from '@/lib/kernels' import { Button, Card, CardContent, Badge, Input } from '@/components/ui' import { cn } from '@/utils/helpers' import { Search, SlidersHorizontal, Plus } from 'lucide-react' export function KernelSelector() { const { selectedKernel, setSelectedKernel, customKernelMatrix, customKernelSize, customKernelNormalize, setCustomKernel, setCustomKernelSize, setCustomKernelNormalize, updateCustomKernelCell } = useAppStore() const [activeCategory, setActiveCategory] = useState('blur') const [searchQuery, setSearchQuery] = useState('') const [showCustom, setShowCustom] = useState(false) const filteredKernels = PREDEFINED_KERNELS.filter( (k) => k.name.toLowerCase().includes(searchQuery.toLowerCase()) || k.category.toLowerCase().includes(searchQuery.toLowerCase()) || k.description.toLowerCase().includes(searchQuery.toLowerCase()) ) const kernelsByCategory = KERNEL_CATEGORIES.map((cat) => ({ ...cat, kernels: getKernelsByCategory(cat.value).filter((k) => k.name.toLowerCase().includes(searchQuery.toLowerCase()) ), })) const handleKernelSelect = (kernel: typeof PREDEFINED_KERNELS[0]) => { setSelectedKernel(kernel) setShowCustom(false) } const handleCustomKernelSubmit = () => { const kernel = { id: `custom-${Date.now()}`, name: `Custom ${customKernelSize}×${customKernelSize}`, category: 'custom' as KernelCategory, matrix: customKernelMatrix, size: customKernelSize, normalize: customKernelNormalize, description: 'User-defined custom kernel', } setSelectedKernel(kernel) } return (

Kernel Selector

{/* Search */}
setSearchQuery(e.target.value)} className="w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg dark:border-gray-600 dark:bg-gray-800 dark:text-white" />
{/* Category Tabs */}
{KERNEL_CATEGORIES.map((cat) => ( ))}
{/* Custom Kernel Editor */} {showCustom && (

Custom Kernel Editor

setCustomKernelSize(Math.max(3, Math.min(9, parseInt(e.target.value) || 3)))} min={3} max={9} step={2} className="w-24" />
{Array.from({ length: customKernelSize }, (_, row) => Array.from({ length: customKernelSize }, (_, col) => ( updateCustomKernelCell(row, col, parseFloat(e.target.value) || 0)} className="w-full h-8 text-center text-sm border border-gray-300 rounded dark:border-gray-600 dark:bg-gray-700" /> )) )}
)} {/* Kernel List */}
{kernelsByCategory .filter((cat) => cat.kernels.length > 0) .map((cat) => (

{cat.label}

{cat.kernels.map((kernel) => ( ))}
))} {filteredKernels.length === 0 && (
No kernels found matching “{searchQuery}”
)}
) }