import 'package:flutter/material.dart';
import '../core/localization/app_localizations.dart';
import '../core/theme/app_colors.dart';
import '../data/app_data_scope.dart';
import '../data/location_scope.dart';
import '../services/contextual_recommendation_service.dart';
import '../features/poi/poi_detail_page.dart';
import '../features/tours/tour_detail_page.dart';
import 'opening_hours.dart';
import 'remote_image.dart';
class HomeNowSection extends StatelessWidget {
const HomeNowSection({super.key});
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
const service = ContextualRecommendationService();
final store = AppDataScope.of(context);
final location = LocationScope.of(context);
final lang = Localizations.localeOf(context).languageCode;
final pos = location.position;
final pois = service.nearbyOpenPois(
pois: store.pois,
userLat: pos?.latitude,
userLon: pos?.longitude,
limit: 5,
);
final tours = service.toursForNow(store.tours, limit: 4);
if (pois.isEmpty && tours.isEmpty) return const SizedBox.shrink();
final hour = DateTime.now().hour;
final headline = hour < 12
? l10n.t('homeMorningHeadline')
: hour < 17
? l10n.t('homeNowHeadline')
: l10n.t('homeEveningHeadline');
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(headline,
style: Theme.of(context)
.textTheme
.titleLarge
?.copyWith(fontWeight: FontWeight.w900))),
const Icon(Icons.auto_awesome_rounded, color: AppColors.heartRed),
],
),
const SizedBox(height: 5),
Text(pos == null ? l10n.t('homeNowTimeBased') : l10n.t('homeNowNearby'),
style: const TextStyle(color: AppColors.mutedInk)),
if (pois.isNotEmpty) ...[
const SizedBox(height: 13),
SizedBox(
height: 205,
child: ListView.separated(
scrollDirection: Axis.horizontal,
itemCount: pois.length,
separatorBuilder: (_, __) => const SizedBox(width: 11),
itemBuilder: (context, index) {
final poi = pois[index];
return SizedBox(
width: 230,
child: Material(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
child: InkWell(
borderRadius: BorderRadius.circular(20),
onTap: () => Navigator.of(context).push(MaterialPageRoute(
builder: (_) => PoiDetailPage(poi: poi))),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RemoteImage(
url: poi.imageUrl,
height: 112,
width: double.infinity,
borderRadius: const BorderRadius.vertical(
top: Radius.circular(20)),
fallbackIcon: Icons.place_outlined),
Padding(
padding: const EdgeInsets.fromLTRB(12, 10, 12, 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
OpeningStatusBadge(
openingHours: poi.openingHours),
const SizedBox(height: 5),
Text(poi.title.get(lang),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontWeight: FontWeight.w900)),
]),
),
],
),
),
),
);
},
),
),
],
if (tours.isNotEmpty) ...[
const SizedBox(height: 12),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
for (final tour in tours.take(3))
ActionChip(
avatar: const Icon(Icons.route_rounded, size: 18),
label: Text(
'${tour.title.get(lang)} · ${tour.durationMinutes} Min.'),
onPressed: () => Navigator.of(context).push(MaterialPageRoute(
builder: (_) => TourDetailPage(tour: tour))),
),
],
),
],
],
);
}
}

