import React, { useState, useEffect } from 'react'; import axios from 'axios'; import { Card, Button, Typography, Space, Spin, message, Tooltip as AntTooltip, Collapse, Empty } from 'antd'; import { PlayCircleOutlined, ReloadOutlined, HistoryOutlined, InfoCircleOutlined, CustomerServiceOutlined, CalendarOutlined, DownOutlined } from '@ant-design/icons'; import Tooltip from './Tooltip'; import TrackList from './TrackList'; const { Title, Text, Paragraph } = Typography; const PlaylistsSection = () => { const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState({ sixHour: false, daily: false }); const [playlists, setPlaylists] = useState(null); const [history, setHistory] = useState([]); const [loadingHistory, setLoadingHistory] = useState(false); const [showHistory, setShowHistory] = useState(false); const fetchPlaylists = async () => { try { const response = await axios.get('/api/playlists'); setPlaylists(response.data); } catch (error) { console.error('Failed to fetch playlists:', error); message.error('Failed to load playlist metadata'); } finally { setLoading(false); } }; const fetchHistory = async () => { if (loadingHistory) return; setLoadingHistory(true); try { const response = await axios.get('/api/playlists/history'); setHistory(response.data.history || []); } catch (error) { console.error('Failed to fetch playlist history:', error); message.error('Failed to load playlist history'); } finally { setLoadingHistory(false); } }; useEffect(() => { fetchPlaylists(); }, []); useEffect(() => { if (showHistory && history.length === 0) { fetchHistory(); } }, [showHistory]); const handleRefresh = async (type) => { const isSixHour = type === 'six-hour'; setRefreshing(prev => ({ ...prev, [isSixHour ? 'sixHour' : 'daily']: true })); try { const endpoint = isSixHour ? '/api/playlists/refresh/six-hour' : '/api/playlists/refresh/daily'; await axios.post(endpoint); message.success(`${isSixHour ? '6-Hour' : 'Daily'} playlist refreshed!`); await fetchPlaylists(); if (showHistory) fetchHistory(); } catch (error) { console.error(`Refresh failed for ${type}:`, error); message.error(`Failed to refresh ${type} playlist`); } finally { setRefreshing(prev => ({ ...prev, [isSixHour ? 'sixHour' : 'daily']: false })); } }; if (loading) return