import { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { ChevronLeft, ChevronRight, RefreshCw } from 'lucide-react'; import { cn } from '@/lib/utils'; import { ReactNode } from 'react'; interface BrowserAddressBarProps { currentPath?: string; onNavigate?: (path: string) => void; onRefresh?: () => void; onBack?: () => void; onForward?: () => void; canGoBack?: boolean; canGoForward?: boolean; className?: string; extraContent?: ReactNode; } export function BrowserAddressBar({ currentPath = '/', onNavigate, onRefresh, onBack, onForward, canGoBack = false, canGoForward = false, className, extraContent, }: BrowserAddressBarProps) { const [inputValue, setInputValue] = useState(currentPath); // Update input value when currentPath changes (e.g., when iframe navigates) useEffect(() => { setInputValue(currentPath); }, [currentPath]); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!onNavigate) return; let path = inputValue.trim(); // Ensure path starts with / if (!path.startsWith('/')) { path = '/' + path; } onNavigate(path); }; const handleInputChange = (e: React.ChangeEvent) => { setInputValue(e.target.value); }; return (
{/* Navigation buttons */}
{/* Address bar */}
{/* Extra content */} {extraContent}
); }