import { useState } from 'react';
import { X, Plus, BarChart3, Search, Layers } from 'lucide-react';
import { PairItem } from '../pairs/PairItem';
import { Skeleton } from '../ui/Spinner';
import { Button } from '../ui/Button';
import type { Pair, Signal } from '../../types';
interface MobileDrawerProps {
isOpen: boolean;
onClose: () => void;
pairs: Pair[];
signals: Signal[];
isLoading: boolean;
selectedSymbol: string | null;
onSelect: (symbol: string | null) => void;
onOpenAddModal: () => void;
}
export function MobileDrawer({
isOpen,
onClose,
pairs,
signals,
isLoading,
selectedSymbol,
onSelect,
onOpenAddModal,
}: MobileDrawerProps) {
const [searchQuery, setSearchQuery] = useState('');
if (!isOpen) return null;
const signalMap = new Map(signals.map((s) => [s.symbol, s]));
const activePairCount = pairs.filter((p) => p.is_active).length;
const filteredPairs = pairs.filter((p) =>
p.symbol.toLowerCase().includes(searchQuery.toLowerCase().trim())
);
const activePairs = [...filteredPairs.filter((p) => p.is_active)].sort((a, b) =>
a.symbol.localeCompare(b.symbol)
);
const inactivePairs = filteredPairs.filter((p) => !p.is_active);
const handleSelect = (symbol: string | null) => {
onSelect(symbol);
onClose();
};
return (
{/* Backdrop */}
{/* Slide-over panel */}
{/* Header */}
Trading Pairs
{activePairCount > 0 && (
{activePairCount} Aktif
)}
{/* Quick All Pairs filter button */}
{selectedSymbol && (
)}
{/* Search box */}
setSearchQuery(e.target.value)}
className="input-field w-full pl-8 pr-3 py-1.5 text-xs font-mono"
/>
{searchQuery && (
)}
{/* Add Pair Button */}
{/* Pair List */}
{isLoading ? (
{[...Array(5)].map((_, i) => (
))}
) : filteredPairs.length === 0 ? (
{searchQuery ? `Tidak ada pair "${searchQuery}"` : 'Belum ada pair ditambahkan'}
) : (
{activePairs.map((pair) => (
handleSelect(sym)}
/>
))}
{inactivePairs.length > 0 && (
<>
{inactivePairs.map((pair) => (
handleSelect(sym)}
/>
))}
>
)}
)}
{/* Footer Statistics */}
{(['LONG', 'SHORT', 'NEUTRAL'] as const).map((dir) => {
const activeSymbolSet = new Set(pairs.filter((p) => p.is_active).map((p) => p.symbol));
const count = signals.filter(
(s) => activeSymbolSet.has(s.symbol) && s.direction === dir
).length;
return (
);
})}
);
}