Compare commits

...

8 Commits
main ... ai-dev

Author SHA1 Message Date
Flatlogic Bot
f00876fc81 Edit app-9xzmfic2e4g1/src/db/api.ts via Editor 2026-03-05 19:13:11 +00:00
Flatlogic Bot
7faea1370f Edit app-9xzmfic2e4g1/src/components/trip/Timeline.tsx via Editor 2026-03-05 19:12:40 +00:00
Flatlogic Bot
21a18c02e1 Edit app-9xzmfic2e4g1/.env via Editor 2026-03-05 18:39:30 +00:00
Flatlogic Bot
fada1b63a2 Edit app-9xzmfic2e4g1/src/constants/planner.ts via Editor 2026-03-05 18:04:26 +00:00
Flatlogic Bot
cdc4fc9abe Edit app-9xzmfic2e4g1/.env via Editor 2026-03-05 17:48:51 +00:00
Flatlogic Bot
8deb4450d6 yüklendi 2026-03-05 15:25:57 +00:00
Flatlogic Bot
827a0a1f77 Edit app-9xzmfic2e4g1/src/db/api.ts via Editor 2026-03-05 15:19:59 +00:00
Flatlogic Bot
79212cbccd Edit app-9xzmfic2e4g1/src/components/trip/Map.tsx via Editor 2026-03-05 15:19:34 +00:00
5 changed files with 358 additions and 570 deletions

View File

@ -1,5 +1,5 @@
VITE_SUPABASE_URL=https://ofqojaxiopqxahfvxpmx.supabase.co VITE_SUPABASE_URL=https://bhaumxerateojqvleoyw.supabase.co
VITE_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9mcW9qYXhpb3BxeGFoZnZ4cG14Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzIyODExMjAsImV4cCI6MjA4Nzg1NzEyMH0.CVyjWPp9ldCd5qxA4TbViD5MJ0axbEWfGr-1n1pPjn0 VITE_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJoYXVteGVyYXRlb2pxdmxlb3l3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjczNTQ4OTksImV4cCI6MjA4MjkzMDg5OX0.uyF3i17AaNd6CN5yWrGMR4vFsJ-boPrfKZYByXKBqUE
VITE_GOOGLE_MAPS_API_KEY=AIzaSyCLPiqNWwFSUS0X15YvTdHZxrb-2LXoYlw VITE_GOOGLE_MAPS_API_KEY=AIzaSyBbXWk7VhZfzn9txrAr9N-faAPuKy_LnKw
VITE_APP_ID=app-9xzmfic2e4g1 VITE_APP_ID=app-9xzmfic2e4g1
VITE_FORM_ID=form-9xzmfic2e4g1 VITE_FORM_ID=form-9xzmfic2e4g1

View File

@ -73,23 +73,70 @@ export function TripMap({ itinerary, activePlaceId, onMarkerClick, onAddPlace }:
setAdded(false); setAdded(false);
}, [itineraryKey]); }, [itineraryKey]);
// ── Fetch rich details ──────────────────────────────────────────────────── // ── Fetch rich details via Google Places API ─────────────────────────────
const fetchPlaceDetail = useCallback(async (poi: SelectedPOI) => { const fetchPlaceDetail = useCallback((poi: SelectedPOI) => {
if (!placesServiceRef.current) return;
setDetailLoading(true); setDetailLoading(true);
setPlaceDetail(null); setPlaceDetail(null);
setActiveTab('about'); setActiveTab('about');
try {
const data = await api.getPlaceDetails({ placesServiceRef.current.getDetails(
place_id: poi.place_id, {
name: poi.name, placeId: poi.place_id,
category: poi.category, fields: [
}); 'place_id', 'name', 'editorial_summary', 'rating', 'user_ratings_total',
setPlaceDetail(data); 'opening_hours', 'reviews', 'types', 'formatted_address',
} catch (e) { ],
console.error('Place detail fetch error:', e); },
} finally { (place, status) => {
setDetailLoading(false); setDetailLoading(false);
} if (status !== google.maps.places.PlacesServiceStatus.OK || !place) return;
// Build why_visit from types + editorial_summary
const typeLabels: Record<string, string> = {
tourist_attraction: 'Turistik bir cazibe noktası — ziyaret değer.',
museum: 'Tarihi ve kültürel bir müze deneyimi sunar.',
restaurant: 'Yerel lezzetleri keşfetmek için harika bir mekan.',
park: 'Doğayla iç içe dinlenme ve yürüyüş imkânı.',
lodging: 'Konforlu konaklama seçeneği.',
natural_feature: 'Eşsiz doğal güzelliğiyle öne çıkan bir yer.',
church: 'Tarihi ve mimari açıdan ilgi çekici bir yapı.',
mosque: 'Tarihi ve mimari açıdan ilgi çekici bir yapı.',
point_of_interest: 'Bölgenin önemli ilgi noktalarından biri.',
};
const whyVisit: string[] = [];
if (place.editorial_summary?.overview) whyVisit.push(place.editorial_summary.overview);
for (const t of (place.types || [])) {
const label = typeLabels[t];
if (label && !whyVisit.includes(label)) { whyVisit.push(label); break; }
}
// Build tips from top-rated reviews
const tips: string[] = (place.reviews || [])
.filter(r => r.rating >= 4 && r.text?.length > 30)
.slice(0, 2)
.map(r => `"${r.text.slice(0, 120).trim()}…"`);
const detail: PlaceDetail = {
place_id: place.place_id || poi.place_id,
name: place.name || poi.name,
summary: place.editorial_summary?.overview || '',
rating: place.rating,
total_ratings: place.user_ratings_total,
is_open_now: place.opening_hours?.isOpen?.() ?? null,
opening_hours: place.opening_hours?.weekday_text || null,
why_visit: whyVisit,
tips,
reviews: (place.reviews || []).map(r => ({
author: r.author_name,
rating: r.rating,
text: r.text,
time: r.relative_time_description,
})),
};
setPlaceDetail(detail);
}
);
}, []); }, []);
// ── Handle add ──────────────────────────────────────────────────────────── // ── Handle add ────────────────────────────────────────────────────────────
@ -147,43 +194,41 @@ export function TripMap({ itinerary, activePlaceId, onMarkerClick, onAddPlace }:
placesServiceRef.current = new google.maps.places.PlacesService(map); placesServiceRef.current = new google.maps.places.PlacesService(map);
// ── POI tıklama ─────────────────────────────────────────────────── // ── POI tıklama ───────────────────────────────────────────────────
if (onAddPlace) { // POI tiklama - her zaman calisir, detay panelini acar
map.addListener('click', (e: google.maps.MapMouseEvent & { placeId?: string }) => { map.addListener('click', (e: google.maps.MapMouseEvent & { placeId?: string }) => {
if (!e.placeId) return; if (!e.placeId) return;
e.stop?.(); e.stop?.();
const placeId = e.placeId; const placeId = e.placeId;
setAdded(false); setAdded(false);
// Önce temel bilgiyi Google'dan çek, sonra panel aç placesServiceRef.current?.getDetails(
placesServiceRef.current?.getDetails( {
{ placeId,
placeId, fields: ['place_id', 'name', 'formatted_address', 'geometry', 'rating', 'photos', 'types'],
fields: ['place_id', 'name', 'formatted_address', 'geometry', 'rating', 'photos', 'types'], },
}, (place, status) => {
(place, status) => { if (status !== google.maps.places.PlacesServiceStatus.OK || !place?.geometry?.location) return;
if (status !== google.maps.places.PlacesServiceStatus.OK || !place?.geometry?.location) return;
const photoUrl = place.photos?.[0]?.getUrl({ maxWidth: 600 }) || ''; const photoUrl = place.photos?.[0]?.getUrl({ maxWidth: 600 }) || '';
const category = (place.types?.[0] || 'point_of_interest').replace(/_/g, ' '); const category = (place.types?.[0] || 'point_of_interest').replace(/_/g, ' ');
const poi: SelectedPOI = { const poi: SelectedPOI = {
place_id: place.place_id || placeId, place_id: place.place_id || placeId,
name: place.name || '', name: place.name || '',
lat: place.geometry.location.lat(), lat: place.geometry.location.lat(),
lng: place.geometry.location.lng(), lng: place.geometry.location.lng(),
photoUrl, photoUrl,
category, category,
formatted_address: place.formatted_address || '', formatted_address: place.formatted_address || '',
rating: place.rating, rating: place.rating,
}; };
setSelectedPOI(poi); setSelectedPOI(poi);
fetchPlaceDetail(poi); fetchPlaceDetail(poi);
} }
); );
}); });
}
setGoogleMap(map); setGoogleMap(map);
} }

View File

@ -160,6 +160,16 @@ function DaySection({
)} )}
</div> </div>
{/* Day story — AI hikayesi */}
{day.day_story && (
<div className="mx-1 flex items-start gap-2.5 px-3 py-2.5 bg-gradient-to-r from-orange-50 to-amber-50 border border-orange-100 rounded-xl">
<Wand2 className="h-3.5 w-3.5 text-orange-500 shrink-0 mt-0.5" />
<p className="text-[12px] text-orange-800 font-medium leading-relaxed italic">
{day.day_story}
</p>
</div>
)}
{/* Empty state */} {/* Empty state */}
{day.items.length === 0 && ( {day.items.length === 0 && (
<div className="mx-2 py-12 flex flex-col items-center gap-3 border-2 border-dashed border-gray-100 rounded-2xl bg-gray-50/50"> <div className="mx-2 py-12 flex flex-col items-center gap-3 border-2 border-dashed border-gray-100 rounded-2xl bg-gray-50/50">
@ -437,6 +447,22 @@ function SortableItem({
<p className="text-[11px] font-medium italic text-orange-800">{item.notes}</p> <p className="text-[11px] font-medium italic text-orange-800">{item.notes}</p>
</div> </div>
)} )}
{/* why_visit — neden bu yer */}
{item.why_visit && (
<div className="mt-2 flex items-start gap-2 px-2 py-1.5 bg-blue-50 rounded-lg border border-blue-100">
<MapPin className="h-3 w-3 text-blue-500 shrink-0 mt-0.5" />
<p className="text-[11px] text-blue-700 font-medium leading-snug">{item.why_visit}</p>
</div>
)}
{/* personal_tip — kişisel ipucu */}
{item.personal_tip && (
<div className="mt-1.5 flex items-start gap-2 px-2 py-1.5 bg-amber-50 rounded-lg border border-amber-100">
<Star className="h-3 w-3 text-amber-500 shrink-0 mt-0.5" />
<p className="text-[11px] text-amber-700 font-medium leading-snug">{item.personal_tip}</p>
</div>
)}
</CardContent> </CardContent>
</Card> </Card>
</div> </div>

View File

@ -1,529 +1,243 @@
import { useState, useMemo, useCallback, memo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '@/contexts/AuthContext';
import api from '@/db/api';
import { Label } from '@/components/ui/label';
import { Form, FormField, FormItem, FormMessage } from '@/components/ui/form';
import { toast } from 'sonner';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod'
import * as z from 'zod';
import { format, differenceInDays } from 'date-fns';
import { import {
Loader2, ArrowRight, ArrowLeft, Sparkles, User, Users, Heart, Compass,
MapPin, Calendar, Users, Coffee, Heart, Car, Bus, Shuffle, Navigation,
Car, Wallet, CheckCircle2, ChevronRight, Wallet, CreditCard, Star, Crown,
PersonStanding, Tent, Building2, Home, Castle,
TreePine, Landmark, Camera,
Zap, UtensilsCrossed, Wind,
CheckCircle2, Sparkles, Flame, MapPin,
} from 'lucide-react'; } from 'lucide-react';
import { parseApiError } from '@/utils/errorHandler';
import { retryWithBackoff, withTimeout } from '@/utils/retryWithBackoff';
import { motion, AnimatePresence } from 'framer-motion';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import { LOADING_STEPS, TRAVEL_TYPE_OPTIONS, BUDGET_OPTIONS, TRANSPORT_OPTIONS, ACCOMMODATION_OPTIONS, INTEREST_OPTIONS } from '@/constants/planner'; // ─── Travel Types ─────────────────────────────────────────────────────────────
import { DateSelector } from '@/components/planner/DateSelector'; export const TRAVEL_TYPE_OPTIONS = [
import { TravelerInput } from '@/components/planner/TravelerInput'; {
import { AccommodationSelector } from '@/components/planner/AccommodationSelector'; id: 'solo',
import { InterestsGrid } from '@/components/planner/InterestsGrid'; label: 'Yalnız',
import { TravelTypeSelector } from '@/components/planner/TravelTypeSelector'; description: 'Özgür, bağımsız keşif',
import { TransportSelector } from '@/components/planner/TransportSelector'; icon: User,
import { BudgetSelector } from '@/components/planner/BudgetSelector'; bg: 'bg-violet-50',
border: 'border-violet-400',
text: 'text-violet-600',
gradient: 'from-violet-500 to-purple-600',
},
{
id: 'couple',
label: 'Çift',
description: 'Romantik kaçamak',
icon: Heart,
bg: 'bg-rose-50',
border: 'border-rose-400',
text: 'text-rose-600',
gradient: 'from-rose-500 to-pink-600',
},
{
id: 'family',
label: 'Aile',
description: 'Herkese uygun aktiviteler',
icon: Users,
bg: 'bg-amber-50',
border: 'border-amber-400',
text: 'text-amber-600',
gradient: 'from-amber-500 to-orange-600',
},
{
id: 'friends',
label: 'Arkadaşlar',
description: 'Macera & eğlence dolu',
icon: Compass,
bg: 'bg-emerald-50',
border: 'border-emerald-400',
text: 'text-emerald-600',
gradient: 'from-emerald-500 to-teal-600',
},
];
// ─── Schema ─────────────────────────────────────────────────────────────────── // ─── Transport Options ────────────────────────────────────────────────────────
const formSchema = z.object({ export const TRANSPORT_OPTIONS = [
dateRange: z.object({ {
from: z.date({ required_error: 'Başlangıç tarihi gereklidir' }), id: 'rental',
to: z.date({ required_error: 'Bitiş tarihi gereklidir' }), label: 'Kiralık Araç',
}) description: 'En özgür seçenek, uzak noktalara ulaşım',
.refine(d => d.from >= new Date(new Date().setHours(0, 0, 0, 0)), { icon: Car,
message: 'Başlangıç tarihi bugünden önce olamaz', bg: 'bg-blue-50',
}) border: 'border-blue-400',
.refine(d => d.to > d.from, { text: 'text-blue-600',
message: 'Bitiş tarihi başlangıç tarihinden sonra olmalıdır', gradient: 'from-blue-500 to-indigo-600',
}) },
.refine(d => { {
const days = differenceInDays(d.to, d.from) + 1; id: 'transfer',
return days >= 1 && days <= 14; label: 'Özel Transfer',
}, { message: 'Seyahat süresi 114 gün arasında olmalıdır' }), description: 'Konforlu, planlı güzergahlar',
travelType: z.string().min(1, 'Seyahat tipi seçiniz'), icon: Navigation,
travelers: z.number().min(1).max(15), bg: 'bg-purple-50',
accommodation: z.string(), border: 'border-purple-400',
transport: z.string().min(1, 'Ulaşım tercihi seçiniz'), text: 'text-purple-600',
budget: z.string().min(1, 'Bütçe aralığı seçiniz'), gradient: 'from-purple-500 to-violet-600',
interests: z.array(z.string()).min(1, 'En az 1 ilgi alanı seçiniz').max(6), },
}); {
id: 'shuttle',
label: 'Servis / Minibüs',
description: 'Popüler turist güzergahları',
icon: Bus,
bg: 'bg-orange-50',
border: 'border-orange-400',
text: 'text-orange-600',
gradient: 'from-orange-500 to-amber-600',
},
{
id: 'mixed',
label: 'Karma',
description: 'Esnek kombinasyon',
icon: Shuffle,
bg: 'bg-teal-50',
border: 'border-teal-400',
text: 'text-teal-600',
gradient: 'from-teal-500 to-cyan-600',
},
];
type FormValues = z.infer<typeof formSchema>; // ─── Budget Options ───────────────────────────────────────────────────────────
export const BUDGET_OPTIONS = [
{
id: 'budget',
label: 'Ekonomik',
description: '₺5001.000 / gün',
icon: Wallet,
bg: 'bg-green-50',
border: 'border-green-400',
text: 'text-green-600',
gradient: 'from-green-500 to-emerald-600',
},
{
id: 'moderate',
label: 'Orta',
description: '₺1.0002.500 / gün',
icon: CreditCard,
bg: 'bg-sky-50',
border: 'border-sky-400',
text: 'text-sky-600',
gradient: 'from-sky-500 to-blue-600',
},
{
id: 'comfort',
label: 'Konforlu',
description: '₺2.5005.000 / gün',
icon: Star,
bg: 'bg-amber-50',
border: 'border-amber-400',
text: 'text-amber-600',
gradient: 'from-amber-500 to-yellow-600',
},
{
id: 'luxury',
label: 'Lüks',
description: '₺5.000+ / gün',
icon: Crown,
bg: 'bg-rose-50',
border: 'border-rose-400',
text: 'text-rose-600',
gradient: 'from-rose-500 to-pink-600',
},
];
// ─── Steps ──────────────────────────────────────────────────────────────────── // ─── Accommodation Options ────────────────────────────────────────────────────
const STEPS = [ export const ACCOMMODATION_OPTIONS = [
{ id: 'dates', title: 'Tarihler', icon: Calendar, description: 'Ne zaman gidiyorsunuz?' }, {
{ id: 'travelType', title: 'Seyahat Tipi', icon: PersonStanding, description: 'Nasıl bir seyahat?' }, id: 'cave',
{ id: 'travelers', title: 'Grup & Konaklama', icon: Users, description: 'Kiminle, nerede kalıyorsunuz?' }, label: 'Mağara Otel',
{ id: 'transport', title: 'Ulaşım', icon: Car, description: 'Nasıl seyahat edeceksiniz?' }, description: 'Eşsiz Kapadokya deneyimi',
{ id: 'budget', title: 'Bütçe', icon: Wallet, description: 'Ne kadar harcamayı planlıyorsunuz?' }, icon: Castle,
{ id: 'interests', title: 'İlgi Alanları', icon: Heart, description: 'Neleri keşfetmek istersiniz?' }, },
] as const; {
id: 'center',
label: 'Merkez Otel',
description: 'Göreme veya Ürgüp merkezi',
icon: Building2,
},
{
id: 'boutique',
label: 'Butik Otel',
description: 'Küçük, şık tesisler',
icon: Home,
},
{
id: 'camping',
label: 'Kamp',
description: 'Doğayla iç içe',
icon: Tent,
},
];
// ─── Summary label helpers ──────────────────────────────────────────────────── // ─── Interest Options ─────────────────────────────────────────────────────────
function getSummaryLabel(stepId: string, values: Partial<FormValues>): string | null { export const INTEREST_OPTIONS = [
switch (stepId) { {
case 'dates': id: 'balloon',
if (values.dateRange?.from && values.dateRange?.to) label: 'Balon Turu',
return `${format(values.dateRange.from, 'd MMM')} ${format(values.dateRange.to, 'd MMM')}`; description: 'Şafakta gökyüzü',
return null; icon: Wind,
case 'travelType': bg: 'bg-sky-50',
return TRAVEL_TYPE_OPTIONS.find(o => o.id === values.travelType)?.label ?? null; border: 'border-sky-300',
case 'travelers': text: 'text-sky-600',
return values.travelers ? `${values.travelers} kişi` : null; gradient: 'from-sky-400 to-blue-500',
case 'transport': },
return TRANSPORT_OPTIONS.find(o => o.id === values.transport)?.label ?? null; {
case 'budget': id: 'nature',
return BUDGET_OPTIONS.find(o => o.id === values.budget)?.label ?? null; label: 'Doğa & Yürüyüş',
case 'interests': description: 'Vadiler ve izler',
return values.interests?.length ? `${values.interests.length} seçildi` : null; icon: TreePine,
default: bg: 'bg-emerald-50',
return null; border: 'border-emerald-300',
} text: 'text-emerald-600',
} gradient: 'from-emerald-400 to-green-500',
},
{
id: 'history',
label: 'Tarih & Kültür',
description: 'Yeraltı şehirleri, kiliseler',
icon: Landmark,
bg: 'bg-amber-50',
border: 'border-amber-300',
text: 'text-amber-600',
gradient: 'from-amber-400 to-orange-500',
},
{
id: 'photography',
label: 'Fotoğrafçılık',
description: 'En iyi manzara noktaları',
icon: Camera,
bg: 'bg-violet-50',
border: 'border-violet-300',
text: 'text-violet-600',
gradient: 'from-violet-400 to-purple-500',
},
{
id: 'adventure',
label: 'Macera',
description: 'ATV, atçılık, zipline',
icon: Zap,
bg: 'bg-orange-50',
border: 'border-orange-300',
text: 'text-orange-600',
gradient: 'from-orange-400 to-red-500',
},
{
id: 'gastronomy',
label: 'Gastronomi',
description: 'Yerel mutfak, şarap tadımı',
icon: UtensilsCrossed,
bg: 'bg-rose-50',
border: 'border-rose-300',
text: 'text-rose-600',
gradient: 'from-rose-400 to-pink-500',
},
];
// ─── PlannerPage ────────────────────────────────────────────────────────────── // ─── Loading Steps ────────────────────────────────────────────────────────────
const PlannerPage = () => { export const LOADING_STEPS = [
const { user } = useAuth(); { label: 'Tercihleriniz analiz ediliyor...', progress: 15, icon: Sparkles },
const navigate = useNavigate(); { label: 'AI rotanızı oluşturuyor...', progress: 35, icon: Flame },
const [loading, setLoading] = useState(false); { label: 'Google Maps ile doğrulanıyor...', progress: 55, icon: MapPin },
const [loadingStep, setLoadingStep] = useState(0); { label: 'Fotoğraflar ve detaylar yükleniyor...', progress: 75, icon: Camera },
const [currentStep, setCurrentStep] = useState(0); { label: 'Güzergahlar hesaplanıyor...', progress: 90, icon: Navigation },
const [datePickerOpen, setDatePickerOpen] = useState(false); { label: 'Rotanız hazırlanıyor!', progress: 100, icon: CheckCircle2 },
];
const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
defaultValues: {
dateRange: { from: undefined, to: undefined },
travelType: '',
travelers: 2,
accommodation: 'center',
transport: '',
budget: '',
interests: [],
},
});
const watchedValues = form.watch();
// ── Navigation ──────────────────────────────────────────────────────────────
const nextStep = async () => {
const stepId = STEPS[currentStep].id;
const fieldMap: Record<string, keyof FormValues | (keyof FormValues)[]> = {
dates: 'dateRange',
travelType: 'travelType',
travelers: ['travelers', 'accommodation'],
transport: 'transport',
budget: 'budget',
interests: 'interests',
};
const fields = fieldMap[stepId];
const isValid = await form.trigger(Array.isArray(fields) ? fields : [fields]);
if (isValid && currentStep < STEPS.length - 1) setCurrentStep(p => p + 1);
};
const prevStep = () => { if (currentStep > 0) setCurrentStep(p => p - 1); };
const handleInterestToggle = useCallback((id: string) => {
const current = form.getValues('interests');
const next = current.includes(id) ? current.filter(i => i !== id) : [...current, id];
form.setValue('interests', next, { shouldValidate: true });
}, [form]);
const simulateLoadingSteps = useCallback(() => {
setLoadingStep(0);
const iv = setInterval(() => {
setLoadingStep(prev => {
if (prev < LOADING_STEPS.length - 1) return prev + 1;
clearInterval(iv);
return prev;
});
}, 2500);
return iv;
}, []);
// ── Submit ──────────────────────────────────────────────────────────────────
const onSubmit = async (data: FormValues) => {
setLoading(true);
const iv = simulateLoadingSteps();
try {
const startDate = format(data.dateRange.from, 'yyyy-MM-dd');
const endDate = format(data.dateRange.to, 'yyyy-MM-dd');
const result = await retryWithBackoff(
() => withTimeout(
api.generateItinerary({
startDate, endDate,
interests: data.interests,
dailySchedule: 'moderate',
preferences: `Type:${data.travelType}, Accommodation:${data.accommodation}, Transport:${data.transport}, Budget:${data.budget}, Travelers:${data.travelers}`,
}),
45000,
new Error('Sunucu yanıt vermiyor, lütfen tekrar deneyin.')
),
{ maxRetries: 2, initialDelay: 1000, maxDelay: 5000 }
);
clearInterval(iv);
if (user) {
const saved = await api.saveTrip({
user_id: user.id,
title: 'Kapadokya Gezisi',
destination: 'Cappadocia',
start_date: startDate,
end_date: endDate,
preferences: { startDate, endDate, interests: data.interests, dailySchedule: 'moderate', preferences: '' },
itinerary: result,
});
navigate(`/trip/${saved.id}`);
toast.success('Rotanız hazır!');
} else {
sessionStorage.setItem('pending_trip', JSON.stringify(result));
navigate('/login', { state: { from: '/planner', message: 'Planınızı kaydetmek için giriş yapın' } });
}
} catch (err) {
clearInterval(iv);
if (err instanceof Error && err.name === 'AbortError') return;
toast.error('Hata oluştu', { description: parseApiError(err).userMessage });
} finally {
setLoading(false);
setLoadingStep(0);
}
};
const progress = ((currentStep + 1) / STEPS.length) * 100;
// ── Loading screen ──────────────────────────────────────────────────────────
if (loading) {
return (
<div className="h-screen w-full flex flex-col items-center justify-center bg-secondary relative overflow-hidden">
<div className="absolute inset-0 opacity-15">
<img
src="https://images.unsplash.com/photo-1541167760496-1628856ab772?auto=format&fit=crop&q=80&w=2400"
alt=""
className="w-full h-full object-cover grayscale"
/>
</div>
<div className="absolute inset-0 bg-secondary/60" />
<div className="relative z-10 max-w-md w-full px-8 text-center space-y-10">
<motion.div
initial={{ opacity: 0, scale: 0.8 }}
animate={{ opacity: 1, scale: 1 }}
className="relative mx-auto w-24 h-24"
>
<div className="absolute inset-0 bg-primary rounded-2xl animate-pulse opacity-30 scale-110" />
<div className="w-24 h-24 bg-primary rounded-2xl flex items-center justify-center shadow-2xl shadow-primary/30">
<Loader2 className="h-11 w-11 text-white animate-spin" />
</div>
</motion.div>
<div className="space-y-5">
<AnimatePresence mode="wait">
<motion.h2
key={loadingStep}
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -12 }}
className="text-3xl font-black text-white tracking-tighter uppercase"
>
{LOADING_STEPS[loadingStep].label}
</motion.h2>
</AnimatePresence>
<div className="w-full h-2 bg-white/10 rounded-full overflow-hidden">
<motion.div
className="h-full bg-primary rounded-full"
initial={{ width: 0 }}
animate={{ width: `${LOADING_STEPS[loadingStep].progress}%` }}
transition={{ duration: 0.6, ease: 'easeInOut' }}
/>
</div>
<div className="flex justify-between text-[10px] font-bold text-white/30 uppercase tracking-widest px-1">
<span>Hazırlanıyor</span>
<span>{LOADING_STEPS[loadingStep].progress}%</span>
</div>
</div>
<p className="text-white/30 text-xs font-medium italic">
Size özel Kapadokya efsanesi kurguluyoruz...
</p>
</div>
</div>
);
}
// ── Main layout ─────────────────────────────────────────────────────────────
return (
<div className="min-h-screen bg-background flex flex-col lg:flex-row overflow-hidden">
{/* ── Sidebar ─────────────────────────────────────────────────────────── */}
<div className="w-full lg:w-[300px] xl:w-[360px] bg-secondary flex flex-col relative overflow-hidden shrink-0">
{/* Decorative orbs */}
<div className="absolute top-0 left-0 w-72 h-72 bg-primary/10 rounded-full blur-3xl -translate-x-1/2 -translate-y-1/2 pointer-events-none" />
<div className="absolute bottom-0 right-0 w-64 h-64 bg-accent/5 rounded-full blur-3xl translate-x-1/3 translate-y-1/3 pointer-events-none" />
<div className="relative z-10 flex flex-col h-full p-8 lg:p-10 gap-8">
{/* Logo */}
<div className="flex items-center gap-3">
<div className="w-9 h-9 bg-primary rounded-xl flex items-center justify-center text-white shadow-lg shadow-primary/20">
<MapPin className="h-4 w-4" />
</div>
<span className="text-base font-black text-white tracking-tight uppercase">
Kapadokya <span className="text-primary">Efsanesi</span>
</span>
</div>
{/* Headline */}
<div className="space-y-2">
<h1 className="text-3xl xl:text-4xl font-black text-white leading-none tracking-tighter uppercase">
ROTANIZI<br /><span className="text-primary">TASARLAYIN</span>
</h1>
<p className="text-white/35 text-sm font-medium italic">
"Size özel kurgulanmış seyahat mimarisi."
</p>
</div>
{/* Step list */}
<div className="flex-1 space-y-1.5">
{STEPS.map((step, i) => {
const Icon = step.icon;
const isActive = i === currentStep;
const isCompleted = i < currentStep;
const summaryLabel = getSummaryLabel(step.id, watchedValues);
return (
<motion.div
key={step.id}
animate={{ opacity: isActive || isCompleted ? 1 : 0.35 }}
className={cn(
'flex items-center gap-3 px-3 py-2.5 rounded-xl transition-all duration-200 group',
isActive && 'bg-white/8'
)}
>
{/* Step indicator */}
<div className={cn(
'w-8 h-8 rounded-lg flex items-center justify-center shrink-0 transition-all duration-300',
isActive ? 'bg-primary text-white shadow-md shadow-primary/30 scale-110'
: isCompleted ? 'bg-white/10 text-primary'
: 'bg-white/5 text-white/20'
)}>
{isCompleted
? <CheckCircle2 className="h-4 w-4" />
: <Icon className="h-4 w-4" />
}
</div>
{/* Labels */}
<div className="flex-1 min-w-0">
<div className={cn(
'text-[9px] font-black uppercase tracking-[0.15em]',
isActive ? 'text-primary' : 'text-white/25'
)}>
{String(i + 1).padStart(2, '0')}
</div>
<div className={cn(
'text-sm font-bold leading-tight truncate',
isActive ? 'text-white' : isCompleted ? 'text-white/60' : 'text-white/30'
)}>
{step.title}
</div>
</div>
{/* Summary pill */}
{isCompleted && summaryLabel && (
<span className="text-[9px] font-black text-primary/70 bg-primary/10 px-2 py-0.5 rounded-full shrink-0 max-w-[80px] truncate">
{summaryLabel}
</span>
)}
{isActive && (
<ChevronRight className="h-3.5 w-3.5 text-primary/60 shrink-0" />
)}
</motion.div>
);
})}
</div>
{/* Progress bar */}
<div className="space-y-2 pt-2 border-t border-white/8">
<div className="flex justify-between text-[10px] font-bold text-white/25 uppercase tracking-widest">
<span>İlerleme</span>
<span>{Math.round(progress)}%</span>
</div>
<div className="h-1 bg-white/8 rounded-full overflow-hidden">
<motion.div
className="h-full bg-primary rounded-full"
animate={{ width: `${progress}%` }}
transition={{ duration: 0.5, ease: 'easeOut' }}
/>
</div>
</div>
</div>
</div>
{/* ── Main Form Area ──────────────────────────────────────────────────── */}
<div className="flex-1 bg-white dark:bg-card overflow-y-auto">
<div className="max-w-2xl mx-auto min-h-full flex flex-col px-8 py-10 lg:py-14 lg:px-16">
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="flex-1 flex flex-col">
<AnimatePresence mode="wait">
<motion.div
key={currentStep}
initial={{ opacity: 0, x: 24 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -24 }}
transition={{ duration: 0.35, ease: 'easeOut' }}
className="flex-1 space-y-10"
>
{/* Step header */}
<div className="space-y-2">
<div className="flex items-center gap-2 text-[10px] font-black text-primary uppercase tracking-[0.2em]">
<span>Adım {currentStep + 1}/{STEPS.length}</span>
<span className="w-12 h-0.5 bg-primary/20 rounded-full" />
<span>{STEPS[currentStep].title}</span>
</div>
<h2 className="text-3xl md:text-4xl xl:text-5xl font-black text-gray-900 dark:text-white tracking-tighter leading-[0.95] uppercase">
{STEPS[currentStep].description}
</h2>
</div>
{/* Step content */}
<div className="pt-2">
{/* Step 0 — Dates */}
{currentStep === 0 && (
<FormField control={form.control} name="dateRange" render={({ field }) => (
<FormItem className="space-y-3">
<Label className="text-[10px] font-black uppercase tracking-[0.2em] text-primary">Seyahat Takvimi</Label>
<DateSelector
date={field.value}
onDateChange={field.onChange}
isOpen={datePickerOpen}
onOpenChange={setDatePickerOpen}
/>
<FormMessage />
</FormItem>
)} />
)}
{/* Step 1 — Travel Type */}
{currentStep === 1 && (
<FormField control={form.control} name="travelType" render={({ field }) => (
<FormItem className="space-y-3">
<Label className="text-[10px] font-black uppercase tracking-[0.2em] text-primary">Seyahat Tarzı</Label>
<TravelTypeSelector selectedId={field.value} onSelect={field.onChange} />
<FormMessage />
</FormItem>
)} />
)}
{/* Step 2 — Travelers & Accommodation */}
{currentStep === 2 && (
<div className="space-y-8">
<FormField control={form.control} name="travelers" render={({ field }) => (
<FormItem className="space-y-3">
<Label className="text-[10px] font-black uppercase tracking-[0.2em] text-primary">Grup Büyüklüğü</Label>
<TravelerInput value={field.value} onChange={field.onChange} />
<FormMessage />
</FormItem>
)} />
<FormField control={form.control} name="accommodation" render={({ field }) => (
<FormItem className="space-y-3">
<Label className="text-[10px] font-black uppercase tracking-[0.2em] text-primary">Konaklama Tarzı</Label>
<AccommodationSelector selectedId={field.value} onSelect={field.onChange} />
<FormMessage />
</FormItem>
)} />
</div>
)}
{/* Step 3 — Transport */}
{currentStep === 3 && (
<FormField control={form.control} name="transport" render={({ field }) => (
<FormItem className="space-y-3">
<Label className="text-[10px] font-black uppercase tracking-[0.2em] text-primary">Ulaşım Tercihi</Label>
<TransportSelector selectedId={field.value} onSelect={field.onChange} />
<FormMessage />
</FormItem>
)} />
)}
{/* Step 4 — Budget */}
{currentStep === 4 && (
<FormField control={form.control} name="budget" render={({ field }) => (
<FormItem className="space-y-3">
<Label className="text-[10px] font-black uppercase tracking-[0.2em] text-primary">Günlük Bütçe</Label>
<BudgetSelector selectedId={field.value} onSelect={field.onChange} />
<FormMessage />
</FormItem>
)} />
)}
{/* Step 5 — Interests */}
{currentStep === 5 && (
<FormField control={form.control} name="interests" render={({ field }) => (
<FormItem className="space-y-3">
<div className="flex justify-between items-center">
<Label className="text-[10px] font-black uppercase tracking-[0.2em] text-primary">İlgi Alanları</Label>
<span className="text-[10px] font-bold text-gray-400">{field.value.length}/6 Seçildi</span>
</div>
<InterestsGrid selectedInterests={field.value} onToggle={handleInterestToggle} />
<FormMessage />
</FormItem>
)} />
)}
</div>
</motion.div>
</AnimatePresence>
{/* Navigation */}
<div className="pt-10 mt-auto flex items-center justify-between gap-4 border-t border-gray-100 dark:border-white/8">
<Button
type="button"
variant="ghost"
size="lg"
onClick={prevStep}
disabled={currentStep === 0}
className="h-13 px-7 text-sm font-bold rounded-xl hover:bg-gray-50 group disabled:opacity-30"
>
<ArrowLeft className="mr-2 h-4 w-4 group-hover:-translate-x-1 transition-transform" />
Geri
</Button>
{currentStep < STEPS.length - 1 ? (
<Button
type="button"
size="lg"
onClick={nextStep}
className="h-13 px-10 text-sm font-black bg-primary hover:bg-primary/90 rounded-xl shadow-lg shadow-primary/20 group uppercase tracking-widest"
>
Devam Et
<ArrowRight className="ml-2 h-4 w-4 group-hover:translate-x-1 transition-transform" />
</Button>
) : (
<Button
type="submit"
size="lg"
className="h-13 px-12 text-sm font-black bg-primary hover:bg-primary/90 rounded-xl shadow-lg shadow-primary/20 uppercase tracking-widest"
>
Rotayı Oluştur
<Sparkles className="ml-2 h-4 w-4 animate-pulse" />
</Button>
)}
</div>
</form>
</Form>
</div>
</div>
</div>
);
};
export default memo(PlannerPage);

View File

@ -14,6 +14,8 @@ export interface Place {
start_time: string; start_time: string;
end_time: string; end_time: string;
notes?: string; notes?: string;
personal_tip?: string;
why_visit?: string;
} }
export interface ItineraryDay { export interface ItineraryDay {
@ -22,6 +24,7 @@ export interface ItineraryDay {
total_distance?: string; total_distance?: string;
total_duration?: string; total_duration?: string;
notes?: string; notes?: string;
day_story?: string;
} }
export interface Trip { export interface Trip {