"use client" import { useState, useEffect, useRef } from 'react' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { EnhancedCard, EnhancedCardContent, EnhancedCardHeader, EnhancedCardTitle } from '@/components/ui/enhanced-card' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { TrendingUp, TrendingDown, BarChart3, Activity, Clock, MapPin, Building2, DollarSign, Zap, Target, Users, Eye, X, Maximize2, Minimize2 } from 'lucide-react' export interface PriceData { timestamp: Date price: number change: number changePercent: number volume?: number confidence: 'high' | 'medium' | 'low' } export interface MarketMetric { id: string name: string value: number change: number changePercent: number trend: 'up' | 'down' | 'stable' unit: string category: 'price' | 'volume' | 'inventory' | 'demand' } interface DynamicPricingModalProps { isOpen: boolean onClose: () => void propertyId: string propertyName: string propertyAddress: string currentPrice: number priceHistory: PriceData[] marketMetrics: MarketMetric[] className?: string } const formatCurrency = (value: number) => { return new Intl.NumberFormat('en-CA', { style: 'currency', currency: 'CAD', minimumFractionDigits: 0, maximumFractionDigits: 0, }).format(value) } const formatNumber = (value: number, unit: string) => { if (unit === '%') return `${value.toFixed(1)}%` if (unit === 'units') return value.toLocaleString() if (unit === 'days') return `${value} days` return value.toLocaleString() } const getConfidenceColor = (confidence: 'high' | 'medium' | 'low') => { switch (confidence) { case 'high': return 'text-green-600 bg-green-50' case 'medium': return 'text-yellow-600 bg-yellow-50' case 'low': return 'text-red-600 bg-red-50' } } const getTrendIcon = (trend: 'up' | 'down' | 'stable') => { switch (trend) { case 'up': return TrendingUp case 'down': return TrendingDown case 'stable': return Activity } } const getTrendColor = (trend: 'up' | 'down' | 'stable') => { switch (trend) { case 'up': return 'text-green-600' case 'down': return 'text-red-600' case 'stable': return 'text-gray-600' } } export default function DynamicPricingModal({ isOpen, onClose, propertyId, propertyName, propertyAddress, currentPrice, priceHistory, marketMetrics, className }: DynamicPricingModalProps) { const [isExpanded, setIsExpanded] = useState(false) const [selectedTimeframe, setSelectedTimeframe] = useState<'1D' | '1W' | '1M' | '3M' | '1Y'>('1D') const [livePrice, setLivePrice] = useState(currentPrice) const [priceChange, setPriceChange] = useState(0) const [isAnimating, setIsAnimating] = useState(false) const chartRef = useRef(null) // Simulate live price updates useEffect(() => { if (!isOpen) return const interval = setInterval(() => { const variation = (Math.random() - 0.5) * 0.02 // ±1% variation const newPrice = currentPrice * (1 + variation) const change = newPrice - livePrice setIsAnimating(true) setLivePrice(newPrice) setPriceChange(change) setTimeout(() => setIsAnimating(false), 500) }, 3000) return () => clearInterval(interval) }, [isOpen, currentPrice, livePrice]) const latestData = priceHistory[priceHistory.length - 1] const changePercent = ((livePrice - currentPrice) / currentPrice) * 100 return (
{propertyName}

{propertyAddress}

{/* Live Price Display */}
LIVE PRICE LIVE
{formatCurrency(livePrice)}
= 0 ? 'text-green-600' : 'text-red-600' }`}> {changePercent >= 0 ? ( ) : ( )} {formatCurrency(Math.abs(priceChange))} ({Math.abs(changePercent).toFixed(2)}%)
24h High
{formatCurrency(currentPrice * 1.05)}
24h Low
{formatCurrency(currentPrice * 0.95)}
{latestData?.confidence.toUpperCase()} CONFIDENCE
{/* Price Chart Visualization */}
Price Movement
{(['1D', '1W', '1M', '3M', '1Y'] as const).map((timeframe) => ( ))}
{/* Simplified chart visualization */}
{priceHistory.slice(-20).map((data, index) => { const height = ((data.price - Math.min(...priceHistory.map(d => d.price))) / (Math.max(...priceHistory.map(d => d.price)) - Math.min(...priceHistory.map(d => d.price)))) * 160 + 20 return (
= 0 ? 'bg-green-400' : 'bg-red-400' }`} style={{ height: `${height}px` }} title={`${formatCurrency(data.price)} (${data.changePercent > 0 ? '+' : ''}${data.changePercent.toFixed(2)}%)`} /> ) })} {/* Live price indicator */}
Past 20 intervals
Price Up
Price Down
Live
{/* Market Metrics */}
Live Market Metrics
{marketMetrics.map((metric) => { const TrendIcon = getTrendIcon(metric.trend) const trendColor = getTrendColor(metric.trend) return (

{metric.name}

{formatNumber(metric.value, metric.unit)}
= 0 ? 'text-green-600' : 'text-red-600' }`}> {metric.changePercent >= 0 ? '+' : ''} {metric.changePercent.toFixed(1)}% vs yesterday
) })}
{/* Quick Actions */}
Last updated: {new Date().toLocaleTimeString()} Auto-refresh: 3s
) }