-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.html
More file actions
412 lines (372 loc) · 34 KB
/
interface.html
File metadata and controls
412 lines (372 loc) · 34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MovieWizard</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');
body { font-family: 'Outfit', sans-serif; background-color: #0f172a; color: #e2e8f0; }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }
.fade-in { animation: fadeIn 0.4s ease-out forwards; }
.slide-up { animation: slideUp 0.4s ease-out forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
input[type=range] { -webkit-appearance: none; background: transparent; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 24px; width: 24px; border-radius: 50%; background: #38bdf8; cursor: pointer; margin-top: -10px; box-shadow: 0 0 10px rgba(56, 189, 248, 0.5); }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 4px; cursor: pointer; background: #334155; border-radius: 2px; }
.movie-card:hover .overlay { opacity: 1; }
.movie-card { transition: transform 0.2s; }
.movie-card:hover { transform: scale(1.02); }
.genre-checkbox:checked+label { font-weight: bold; }
</style>
</head>
<body class="h-screen flex flex-col overflow-hidden">
<!-- Header -->
<header class="flex-none p-6 flex justify-between items-center bg-slate-900 border-b border-slate-800 z-10">
<div class="flex items-center gap-2">
<i class="fa-solid fa-wand-magic-sparkles text-sky-400 text-2xl"></i>
<h1 class="text-xl font-bold tracking-tight text-white">Movie<span class="text-sky-400">Wizard</span></h1>
</div>
<div id="live-counter-container" class="hidden flex items-center gap-3 bg-slate-800 px-4 py-2 rounded-full border border-slate-700">
<span class="text-xs text-slate-400 uppercase font-semibold">Matches</span>
<span id="live-count" class="text-sky-400 font-mono font-bold text-lg">0</span>
</div>
</header>
<main class="flex-grow relative overflow-y-auto w-full max-w-4xl mx-auto p-4 md:p-8 flex flex-col justify-center">
<!-- Step 0: API Key -->
<div id="step-0" class="step-content w-full max-w-md mx-auto fade-in">
<div class="text-center mb-8">
<div class="w-16 h-16 bg-slate-800 rounded-2xl flex items-center justify-center mx-auto mb-4 border border-slate-700">
<i class="fa-solid fa-key text-2xl text-sky-400"></i>
</div>
<h2 class="text-2xl font-bold mb-2">Setup API Key</h2>
<p class="text-slate-400 text-sm">Enter your TMDb API Key (v3) to begin.</p>
</div>
<div class="bg-slate-800/50 p-6 rounded-2xl border border-slate-700">
<input type="text" id="api-key-input" placeholder="e.g. d392d5b8..." class="w-full bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white focus:outline-none focus:border-sky-500 mb-4">
<button onclick="saveApiKey(event)" class="w-full bg-sky-500 hover:bg-sky-400 text-white font-semibold py-3 rounded-xl transition-all">Start Wizard</button>
</div>
</div>
<!-- Wizard -->
<div id="wizard-container" class="hidden w-full h-full flex flex-col">
<div class="flex-none mb-8">
<div class="flex justify-between items-center mb-4">
<div class="flex gap-2">
<div onclick="goToStep(1)" class="step-dot w-8 h-8 rounded-full border-2 border-slate-700 flex items-center justify-center cursor-pointer font-bold text-xs" id="dot-1">1</div>
<div onclick="goToStep(2)" class="step-dot w-8 h-8 rounded-full border-2 border-slate-700 flex items-center justify-center cursor-pointer font-bold text-xs" id="dot-2">2</div>
<div onclick="goToStep(3)" class="step-dot w-8 h-8 rounded-full border-2 border-slate-700 flex items-center justify-center cursor-pointer font-bold text-xs" id="dot-3">3</div>
<div onclick="goToStep(4)" class="step-dot w-8 h-8 rounded-full border-2 border-slate-700 flex items-center justify-center cursor-pointer font-bold text-xs" id="dot-4">4</div>
<div onclick="goToStep(5)" class="step-dot w-8 h-8 rounded-full border-2 border-slate-700 flex items-center justify-center cursor-pointer font-bold text-xs" id="dot-5">5</div>
</div>
<div class="text-right">
<span id="step-label" class="block text-xs font-bold text-sky-400 uppercase tracking-widest">Genre</span>
<span id="step-counter" class="text-[10px] text-slate-500 uppercase tracking-wider">Step 1 of 5</span>
</div>
</div>
<div class="h-1 bg-slate-800 rounded-full overflow-hidden">
<div id="progress-bar" class="h-full bg-sky-500 transition-all duration-500 w-1/5"></div>
</div>
</div>
<div class="flex-grow overflow-y-auto pr-2 custom-scrollbar">
<!-- Step 1: Genres -->
<div id="step-1" class="step-block space-y-6">
<div class="flex justify-between items-center">
<div>
<h3 class="text-xl font-bold">What's the vibe?</h3>
<p id="genre-mode-desc" class="text-sm text-slate-400">Green = Include, Red = Exclude</p>
</div>
<button onclick="toggleGenreMode()" id="genre-mode-btn" class="px-4 py-2 rounded-lg border border-emerald-500 text-emerald-400 text-xs font-bold bg-emerald-500/10">Mode: Include</button>
</div>
<div>
<h4 class="text-xs font-bold text-slate-500 uppercase mb-3">Quick Combos</h4>
<div class="flex flex-wrap gap-2">
<button onclick="applyCombinedGenre('Romance', 'Comedy')" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-xl text-xs hover:border-sky-500 transition-all">Romance + Comedy</button>
<button onclick="applyCombinedGenre('Action', 'Adventure')" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-xl text-xs hover:border-sky-500 transition-all">Action + Adventure</button>
<button onclick="applyCombinedGenre('Horror', 'Thriller')" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-xl text-xs hover:border-sky-500 transition-all">Horror + Thriller</button>
<button onclick="applyCombinedGenre('Science Fiction', 'Action')" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-xl text-xs hover:border-sky-500 transition-all">Sci-Fi + Action</button>
</div>
</div>
<div id="genre-grid" class="grid grid-cols-2 md:grid-cols-3 gap-3"></div>
</div>
<!-- Step 2: Rating & Votes -->
<div id="step-2" class="step-block hidden space-y-8">
<div class="bg-slate-800/50 p-6 rounded-2xl border border-slate-700">
<div class="flex justify-between mb-2"><span class="text-slate-400 font-medium text-sm">Minimum Score</span><span id="rating-val" class="text-sky-400 font-bold">6.0+</span></div>
<input type="range" id="rating-slider" min="0" max="10" step="0.5" value="6" class="w-full">
</div>
<div class="bg-slate-800/50 p-6 rounded-2xl border border-slate-700">
<div class="flex justify-between mb-2"><span class="text-slate-400 font-medium text-sm">Score Ceiling</span><span id="rating-max-val" class="text-sky-400 font-bold">10.0-</span></div>
<input type="range" id="rating-max-slider" min="0" max="10" step="0.5" value="10" class="w-full">
</div>
<div class="bg-slate-800/50 p-6 rounded-2xl border border-slate-700">
<div class="flex justify-between mb-2"><span class="text-slate-400 font-medium text-sm">Minimum Votes</span><span id="votes-val" class="text-sky-400 font-bold">0+</span></div>
<input type="range" id="votes-slider" min="0" max="5000" step="50" value="0" class="w-full">
</div>
</div>
<!-- Step 3: Advanced Specs -->
<div id="step-3" class="step-block hidden space-y-8">
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
<div class="space-y-4">
<label class="block text-xs font-bold text-slate-500 uppercase">Watch Region</label>
<select id="region-select" onchange="setRegion(this.value)" class="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 text-white">
<option value="US">United States</option><option value="GB">United Kingdom</option><option value="SE">Sweden</option><option value="DE">Germany</option><option value="FR">France</option><option value="JP">Japan</option><option value="KR">South Korea</option>
</select>
<label class="block text-xs font-bold text-slate-500 uppercase">Original Language</label>
<select id="lang-select" onchange="setLanguage(this.value)" class="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 text-white">
<option value="">Any Language</option><option value="en">English</option><option value="ja">Japanese</option><option value="fr">French</option><option value="es">Spanish</option><option value="ko">Korean</option>
</select>
</div>
<div class="space-y-2">
<label class="block text-xs font-bold text-slate-500 uppercase">Runtime</label>
<div class="grid grid-cols-1 gap-2">
<button onclick="setRuntime(event, 0, 90)" class="runtime-btn p-3 bg-slate-800 border border-slate-700 rounded-xl text-sm text-left flex justify-between">Short <span>< 90m</span></button>
<button onclick="setRuntime(event, 90, 150)" class="runtime-btn p-3 bg-slate-800 border border-slate-700 rounded-xl text-sm text-left flex justify-between">Standard <span>90-150m</span></button>
<button onclick="setRuntime(event, 150, 999)" class="runtime-btn p-3 bg-slate-800 border border-slate-700 rounded-xl text-sm text-left flex justify-between">Epic <span>2.5h+</span></button>
</div>
</div>
</div>
<div>
<h4 class="text-xs font-bold text-slate-500 uppercase mb-3">Certification (Age Rating)</h4>
<div class="grid grid-cols-2 gap-4">
<select id="cert-country" onchange="setCertCountry(this.value)" class="bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 text-sm">
<option value="">Select Country...</option><option value="US">USA (MPAA)</option><option value="GB">UK (BBFC)</option><option value="DE">Germany (FSK)</option>
</select>
<select id="certification" onchange="setCertification(this.value)" class="bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 text-sm">
<option value="">Select Rating...</option>
</select>
</div>
</div>
<div class="space-y-4">
<h4 class="text-xs font-bold text-slate-500 uppercase">Streaming Providers</h4>
<div id="provider-grid" class="grid grid-cols-3 md:grid-cols-5 gap-3"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="relative"><label class="block text-xs font-bold text-slate-500 uppercase mb-2">Include Keywords</label>
<input type="text" id="keyword-input" placeholder="Search..." oninput="handleTagInput(event, 'keyword')" class="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 text-sm">
<div id="keyword-suggestions" class="absolute top-full left-0 right-0 bg-slate-900 border border-slate-700 rounded-xl mt-1 z-50 hidden max-h-40 overflow-y-auto"></div>
<div id="selected-keywords" class="flex flex-wrap gap-2 mt-2"></div>
</div>
<div class="relative"><label class="block text-xs font-bold text-slate-500 uppercase mb-2">Include Cast/People</label>
<input type="text" id="person-input" placeholder="Search actor..." oninput="handleTagInput(event, 'person')" class="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 text-sm">
<div id="person-suggestions" class="absolute top-full left-0 right-0 bg-slate-900 border border-slate-700 rounded-xl mt-1 z-50 hidden max-h-40 overflow-y-auto"></div>
<div id="selected-person" class="flex flex-wrap gap-2 mt-2"></div>
</div>
</div>
</div>
<!-- Step 4: Era -->
<div id="step-4" class="step-block hidden space-y-8">
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<button onclick="setEra(event, 'any')" class="era-btn p-6 bg-slate-800 border border-slate-700 rounded-2xl text-left">Any Era</button>
<button onclick="setEra(event, 'new')" class="era-btn p-6 bg-slate-800 border border-slate-700 rounded-2xl text-left">Modern (2010+)</button>
<button onclick="setEra(event, 'classic')" class="era-btn p-6 bg-slate-800 border border-slate-700 rounded-2xl text-left">Classics (<2000)</button>
</div>
</div>
<!-- Step 5: Sort -->
<div id="step-5" class="step-block hidden space-y-4">
<label class="flex items-center p-4 bg-slate-800 border border-slate-700 rounded-2xl cursor-pointer hover:bg-slate-700">
<input type="radio" name="sort" value="popularity.desc" checked class="mr-4 w-5 h-5 accent-sky-500">
<div class="font-bold text-white">Popularity</div>
</label>
<label class="flex items-center p-4 bg-slate-800 border border-slate-700 rounded-2xl cursor-pointer hover:bg-slate-700">
<input type="radio" name="sort" value="vote_average.desc" class="mr-4 w-5 h-5 accent-sky-500">
<div class="font-bold text-white">Top Rated</div>
</label>
<label class="flex items-center p-4 bg-slate-800 border border-slate-700 rounded-2xl cursor-pointer hover:bg-slate-700">
<input type="radio" name="sort" value="revenue.desc" class="mr-4 w-5 h-5 accent-sky-500">
<div class="font-bold text-white">Revenue (Blockbusters)</div>
</label>
<label class="flex items-center p-4 bg-slate-800 border border-slate-700 rounded-2xl cursor-pointer hover:bg-slate-700">
<input type="radio" name="sort" value="shuffle" class="mr-4 w-5 h-5 accent-sky-500">
<div class="font-bold text-white">Shuffle Results</div>
</label>
</div>
</div>
</div>
<!-- Results -->
<div id="results-view" class="hidden w-full h-full flex flex-col fade-in">
<div class="flex justify-between items-center mb-6"><h2 class="text-2xl font-bold">Matches</h2>
<div class="flex gap-2">
<button onclick="modifyFilters()" class="bg-slate-800 px-4 py-2 rounded-xl text-sm font-bold border border-slate-700">Modify</button>
<button onclick="location.reload()" class="bg-slate-800 px-4 py-2 rounded-xl text-sm font-bold border border-slate-700">Reset</button>
</div>
</div>
<div id="movies-grid" class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6 overflow-y-auto pr-2 pb-12"></div>
<div id="loading-spinner" class="hidden py-20 text-center"><p class="animate-pulse text-sky-400 font-bold">Brewing matches...</p></div>
<div id="results-pagination" class="hidden py-8 text-center"><button onclick="loadMoreResults(event)" class="bg-sky-500 px-8 py-3 rounded-xl font-bold active:scale-95">Load More Results</button></div>
</div>
</main>
<footer id="wizard-footer" class="hidden flex-none p-6 border-t border-slate-800 bg-slate-900/95 backdrop-blur z-20">
<div class="max-w-4xl mx-auto w-full flex justify-between">
<button id="back-btn" onclick="changeStep(-1)" class="text-slate-400 px-4 py-2 disabled:opacity-0">Back</button>
<button id="next-btn" onclick="changeStep(1)" class="bg-sky-500 hover:bg-sky-400 text-white font-bold py-3 px-8 rounded-xl">Next</button>
</div>
</footer>
<script>
// --- Configuration & State ---
let currentStep = 1, apiKey = '', genres = [], currentPage = 1, totalPagesAvailable = 1;
let filters = { genres: new Set(), excludedGenres: new Set(), genreMode: 'include', rating: 6, ratingMax: 10, minVotes: 0, era: 'any', sortBy: 'popularity.desc', runtime: { min: 0, max: 999 }, providers: new Set(), watchRegion: 'US', language: '', keywords: '', person: '', certCountry: '', certification: '' };
const providers = [{id: 8, name: 'Netflix'}, {id: 337, name: 'Disney+'}, {id: 9, name: 'Prime'}, {id: 1899, name: 'HBO Max'}, {id: 350, name: 'Apple TV'}, {id: 15, name: 'Hulu'}, {id: 531, name: 'Paramount'}, {id: 386, name: 'Peacock'}, {id: 11, name: 'Mubi'}];
const certs = { "US": ["G", "PG", "PG-13", "R", "NC-17"], "GB": ["U", "PG", "12A", "15", "18"], "DE": ["0", "6", "12", "16", "18"] };
const ui = { countDisplay: document.getElementById('live-count'), progressBar: document.getElementById('progress-bar'), nextBtn: document.getElementById('next-btn'), backBtn: document.getElementById('back-btn'), ratingVal: document.getElementById('rating-val'), ratingMaxVal: document.getElementById('rating-max-val'), votesVal: document.getElementById('votes-val') };
const views = { setup: document.getElementById('step-0'), wizard: document.getElementById('wizard-container'), results: document.getElementById('results-view'), footer: document.getElementById('wizard-footer'), liveCounter: document.getElementById('live-counter-container') };
// --- Helpers ---
function escapeHTML(s) { return s ? s.replace(/[&<>"']/g, m => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[m])) : ''; }
function animateValue(obj, start, end, duration) { let startTimestamp = null; const step = (timestamp) => { if (!startTimestamp) startTimestamp = timestamp; const progress = Math.min((timestamp - startTimestamp) / duration, 1); obj.innerHTML = Math.floor(progress * (end - start) + start).toLocaleString(); if (progress < 1) window.requestAnimationFrame(step); }; window.requestAnimationFrame(step); }
// --- API & Logic ---
let debounceTimer, abortCtrl;
function debouncedFetch() { clearTimeout(debounceTimer); debounceTimer = setTimeout(fetchLiveCount, 500); }
async function fetchLiveCount() {
if (abortCtrl) abortCtrl.abort(); abortCtrl = new AbortController();
try {
const res = await fetch(buildApiUrl(1), { signal: abortCtrl.signal });
if (res.ok) { const data = await res.json(); animateValue(ui.countDisplay, parseInt(ui.countDisplay.innerText.replace(/,/g, '')) || 0, data.total_results || 0, 400); }
} catch (e) { if (e.name !== 'AbortError') ui.countDisplay.innerText = "Err"; }
}
function buildApiUrl(p = 1) {
const params = new URLSearchParams({ api_key: apiKey, include_adult: 'false', include_video: 'false', page: p, sort_by: filters.sortBy === 'shuffle' ? 'popularity.desc' : filters.sortBy, 'vote_average.gte': filters.rating, 'vote_average.lte': filters.ratingMax, 'vote_count.gte': filters.minVotes, 'watch_region': filters.watchRegion });
if (filters.genres.size) params.set('with_genres', Array.from(filters.genres).join(','));
if (filters.excludedGenres.size) params.set('without_genres', Array.from(filters.excludedGenres).join(','));
if (filters.runtime.min > 0) params.set('with_runtime.gte', filters.runtime.min);
if (filters.runtime.max < 999) params.set('with_runtime.lte', filters.runtime.max);
if (filters.providers.size) params.set('with_watch_providers', Array.from(filters.providers).join('|'));
if (filters.language) params.set('with_original_language', filters.language);
if (filters.keywords) params.set('with_keywords', filters.keywords);
if (filters.person) params.set('with_people', filters.person);
if (filters.certCountry && filters.certification) { params.set('certification_country', filters.certCountry); params.set('certification', filters.certification); }
if (filters.era === 'new') params.set('primary_release_date.gte', '2010-01-01');
else if (filters.era === 'classic') params.set('primary_release_date.lte', '1999-12-31');
return `https://api.themoviedb.org/3/discover/movie?${params.toString()}`;
}
async function saveApiKey(e) {
const val = document.getElementById('api-key-input').value.trim();
if (!val) return alert("Key required");
apiKey = val; e.currentTarget.disabled = true; e.currentTarget.innerText = "Verifying...";
try {
const res = await fetch(`https://api.themoviedb.org/3/genre/movie/list?api_key=${apiKey}`);
if (res.ok) { const data = await res.json(); genres = data.genres; renderGenres(); renderProviders(); startWizard(); }
else { alert("Invalid Key"); e.currentTarget.disabled = false; e.currentTarget.innerText = "Start Wizard"; }
} catch (e) { alert("Network Error"); e.currentTarget.disabled = false; e.currentTarget.innerText = "Start Wizard"; }
}
function startWizard() { views.setup.classList.add('hidden'); views.wizard.classList.remove('hidden'); views.footer.classList.remove('hidden'); views.liveCounter.classList.remove('hidden'); updateUI(); fetchLiveCount(); }
function updateUI() {
document.querySelectorAll('.step-block').forEach(el => el.classList.add('hidden'));
document.getElementById(`step-${currentStep}`).classList.remove('hidden');
const progress = (currentStep / 5) * 100; ui.progressBar.style.width = `${progress}%`;
document.querySelectorAll('.step-dot').forEach((dot, i) => {
dot.classList.remove('border-sky-500', 'bg-sky-500', 'text-white', 'text-slate-500');
if (i + 1 === currentStep) dot.classList.add('border-sky-500', 'text-sky-500');
else if (i + 1 < currentStep) dot.classList.add('bg-sky-500', 'border-sky-500', 'text-white');
else dot.classList.add('text-slate-500');
});
const labels = ['', 'Genre', 'Rating', 'Specs', 'Era', 'Sort'];
document.getElementById('step-label').innerText = labels[currentStep];
document.getElementById('step-counter').innerText = `Step ${currentStep} of 5`;
ui.backBtn.disabled = currentStep === 1;
ui.nextBtn.innerHTML = currentStep === 5 ? 'See Results <i class="fa-solid fa-check ml-2"></i>' : 'Next <i class="fa-solid fa-arrow-right ml-2"></i>';
}
function changeStep(dir) { if (currentStep === 5 && dir === 1) { showResults(); return; } currentStep += dir; updateUI(); }
function goToStep(s) { currentStep = s; updateUI(); }
function applyCombinedGenre(g1, g2) {
const id1 = genres.find(g => g.name === g1)?.id;
const id2 = genres.find(g => g.name === g2)?.id;
if (id1 && id2) {
const cb1 = document.getElementById(`g-${id1}`);
const cb2 = document.getElementById(`g-${id2}`);
if (cb1 && !cb1.checked) { cb1.checked = true; toggleGenre(id1, cb1); }
if (cb2 && !cb2.checked) { cb2.checked = true; toggleGenre(id2, cb2); }
}
}
function renderGenres() { document.getElementById('genre-grid').innerHTML = genres.map(g => `<div class="relative"><input type="checkbox" id="g-${g.id}" class="genre-checkbox hidden" onchange="toggleGenre(${g.id}, this)"><label for="g-${g.id}" class="block w-full p-3 bg-slate-800 border border-slate-700 rounded-xl cursor-pointer hover:bg-slate-700 text-center text-sm transition-all">${g.name}</label></div>`).join(''); }
function renderProviders() { document.getElementById('provider-grid').innerHTML = providers.map(p => `<div class="relative"><input type="checkbox" id="p-${p.id}" class="toggle-checkbox hidden" onchange="toggleProvider(${p.id})"><label for="p-${p.id}" class="block p-3 bg-slate-800 border border-slate-700 rounded-xl text-center text-[10px] font-bold cursor-pointer hover:bg-slate-700 transition-all">${p.name}</label></div>`).join(''); }
function toggleGenreMode() {
filters.genreMode = filters.genreMode === 'include' ? 'exclude' : 'include';
const btn = document.getElementById('genre-mode-btn');
btn.innerText = `Mode: ${filters.genreMode === 'include' ? 'Include' : 'Exclude'}`;
btn.className = `px-4 py-2 rounded-lg border text-xs font-bold ${filters.genreMode === 'include' ? 'border-emerald-500 text-emerald-400 bg-emerald-500/10' : 'border-red-500 text-red-400 bg-red-500/10'}`;
}
function toggleGenre(id, cb) {
if (cb.checked) {
if (filters.genreMode === 'include') { filters.genres.add(id); cb.nextElementSibling.classList.add('bg-emerald-500', 'text-slate-900', 'border-emerald-500'); }
else { filters.excludedGenres.add(id); cb.nextElementSibling.classList.add('bg-red-500', 'text-white', 'border-red-500'); }
} else {
filters.genres.delete(id); filters.excludedGenres.delete(id);
cb.nextElementSibling.classList.remove('bg-emerald-500', 'text-slate-900', 'bg-red-500', 'text-white', 'border-emerald-500', 'border-red-500');
}
debouncedFetch();
}
document.getElementById('rating-slider').oninput = (e) => { filters.rating = e.target.value; ui.ratingVal.innerText = `${e.target.value}+`; debouncedFetch(); };
document.getElementById('rating-max-slider').oninput = (e) => { filters.ratingMax = e.target.value; ui.ratingMaxVal.innerText = `${e.target.value}-`; debouncedFetch(); };
document.getElementById('votes-slider').oninput = (e) => { filters.minVotes = e.target.value; ui.votesVal.innerText = `${e.target.value}+`; debouncedFetch(); };
function setLanguage(v) { filters.language = v; debouncedFetch(); }
function setRegion(v) { filters.watchRegion = v; debouncedFetch(); }
function toggleProvider(id) { if (filters.providers.has(id)) filters.providers.delete(id); else filters.providers.add(id); debouncedFetch(); }
function setCertCountry(v) {
filters.certCountry = v;
const sel = document.getElementById('certification'); sel.innerHTML = '<option value="">Select Rating...</option>' + (certs[v] || []).map(c => `<option value="${c}">${c}</option>`).join('');
debouncedFetch();
}
function setCertification(v) { filters.certification = v; debouncedFetch(); }
function setRuntime(e, min, max) {
if (filters.runtime.min === min && filters.runtime.max === max) { filters.runtime = { min: 0, max: 999 }; e.currentTarget.classList.remove('bg-sky-500', 'text-white', 'border-sky-500'); }
else { document.querySelectorAll('.runtime-btn').forEach(b => b.classList.remove('bg-sky-500', 'text-white', 'border-sky-500')); filters.runtime = { min, max }; e.currentTarget.classList.add('bg-sky-500', 'text-white', 'border-sky-500'); }
debouncedFetch();
}
function setEra(e, type) { document.querySelectorAll('.era-btn').forEach(b => b.classList.remove('border-sky-500', 'ring-1', 'ring-sky-500/50')); filters.era = type; e.currentTarget.classList.add('border-sky-500', 'ring-1', 'ring-sky-500/50'); debouncedFetch(); }
async function handleTagInput(e, type) {
const q = e.target.value; if (q.length < 2) return;
const res = await fetch(`https://api.themoviedb.org/3/search/${type === 'keyword' ? 'keyword' : 'person'}?api_key=${apiKey}&query=${q}`);
const data = await res.json();
const container = document.getElementById(`${type}-suggestions`);
container.innerHTML = data.results.slice(0, 5).map(k => `<div onclick="addTag('${type}', ${k.id}, '${escapeHTML(k.name || k.title).replace(/'/g, "\\'")}')" class="p-3 hover:bg-slate-800 cursor-pointer text-xs border-b border-slate-800 text-white">${k.name || k.title}</div>`).join('');
container.classList.remove('hidden');
}
function addTag(type, id, name) {
const list = filters[type].split(',').filter(x => x);
if (!list.includes(id.toString())) {
list.push(id); filters[type] = list.join(',');
const chip = document.createElement('span');
chip.className = "px-3 py-1 rounded-full text-[10px] font-bold flex items-center gap-2 bg-sky-500/20 text-sky-400 border border-sky-500/30 mb-2 mr-2";
chip.innerHTML = `${escapeHTML(name)} <i class="fa-solid fa-xmark cursor-pointer" onclick="this.parentElement.remove(); removeTagValue('${type}', '${id}')"></i>`;
document.getElementById(`selected-${type}`).appendChild(chip); debouncedFetch();
}
document.querySelectorAll('[id$="-suggestions"]').forEach(s => s.classList.add('hidden'));
document.getElementById(`${type}-input`).value = '';
}
function removeTagValue(t, id) { let list = filters[t].split(',').filter(x => x && x !== id.toString()); filters[t] = list.join(','); debouncedFetch(); }
async function showResults() {
currentPage = 1; document.getElementById('movies-grid').innerHTML = '';
views.wizard.classList.add('hidden'); views.footer.classList.add('hidden'); views.results.classList.remove('hidden'); views.liveCounter.classList.add('hidden');
fetchResults();
}
async function fetchResults() {
const grid = document.getElementById('movies-grid'), spinner = document.getElementById('loading-spinner');
spinner.classList.remove('hidden');
try {
const res = await fetch(buildApiUrl(currentPage));
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json(); spinner.classList.add('hidden');
let movies = data.results; if (filters.sortBy === 'shuffle') movies = movies.sort(() => Math.random() - 0.5);
movies.forEach(m => {
const poster = m.poster_path ? `https://image.tmdb.org/t/p/w500${m.poster_path}` : 'https://via.placeholder.com/500x750/1e293b/475569?text=No+Poster';
const year = m.release_date ? m.release_date.split('-')[0] : 'N/A';
const card = document.createElement('a'); card.href = `https://letterboxd.com/tmdb/${m.id}`;
card.target="_blank"; card.rel="noopener noreferrer";
card.className = "movie-card relative rounded-xl overflow-hidden shadow-2xl bg-slate-800 group h-full flex flex-col";
card.innerHTML = `<div class="aspect-[2/3] w-full relative overflow-hidden"><img src="${poster}" class="w-full h-full object-cover"><div class="overlay absolute inset-0 bg-black/80 opacity-0 transition-opacity duration-300 p-4 flex flex-col justify-center text-center"><p class="text-slate-300 text-[10px] line-clamp-6 mb-2">${escapeHTML(m.overview)}</p><span class="text-sky-400 font-bold text-lg">★ ${m.vote_average.toFixed(1)}</span></div><div class="absolute top-2 right-2 bg-slate-900/80 px-2 py-1 rounded text-[10px] font-bold text-white border border-slate-700">${year}</div></div><div class="p-3 bg-slate-800 flex-grow"><h3 class="font-bold text-sm text-white truncate">${escapeHTML(m.title)}</h3></div>`;
grid.appendChild(card);
});
const pag = document.getElementById('results-pagination');
if (data.total_pages > currentPage) pag.classList.remove('hidden'); else pag.classList.add('hidden');
} catch (e) { spinner.innerHTML = `<p class="text-red-400">Error: ${e.message}</p>`; }
}
function loadMoreResults(e) { currentPage++; e.target.disabled = true; e.target.innerText = "Loading..."; fetchResults().then(() => { e.target.disabled = false; e.target.innerText = "Load More Results"; }); }
function modifyFilters() { views.results.classList.add('hidden'); views.wizard.classList.remove('hidden'); views.footer.classList.remove('hidden'); views.liveCounter.classList.remove('hidden'); }
</script>
</body>
</html>