|
3 | 3 | import { Upload, Terminal } from 'lucide-svelte';
|
4 | 4 | import { petStore, selectedPetStore, petHelpers, selectedPetHelpers } from '$lib/stores/pets';
|
5 | 5 | import type { PetPanelData } from '$lib/types/Pet.js';
|
| 6 | + import Modal from '../ui/Modal.svelte'; |
| 7 | + import MemorialModal from '../ui/MemorialModal.svelte'; |
6 | 8 |
|
7 | 9 | let pets: PetPanelData[] = [];
|
8 | 10 | // Derived lists
|
|
12 | 14 | let showCreateForm = false;
|
13 | 15 | let imageInput: HTMLInputElement;
|
14 | 16 |
|
| 17 | + // Archive workflow state |
| 18 | + let confirmArchiveOpen = false; |
| 19 | + let petToArchive: PetPanelData | null = null; |
| 20 | + let memorialOpen = false; |
| 21 | + let memorialPet: PetPanelData | null = null; |
| 22 | +
|
15 | 23 | const speciesSuggestions = ['dog','cat','bird','reptile','fish','rabbit','hamster','other'] as const;
|
16 | 24 | const ageUnitSuggestions = ['years','months','weeks'] as const;
|
17 | 25 | const genderSuggestions = ['male','female','unknown'] as const;
|
|
209 | 217 | }
|
210 | 218 |
|
211 | 219 | function archivePet(petId: string) {
|
212 |
| - petHelpers.archive(petId); |
213 |
| - if (selectedPetId === petId) { |
214 |
| - selectedPetHelpers.clear(); |
215 |
| - } |
| 220 | + const p = pets.find((x) => x.id === petId) || null; |
| 221 | + petToArchive = p; |
| 222 | + confirmArchiveOpen = true; |
216 | 223 | }
|
217 | 224 |
|
218 |
| - function unarchivePet(petId: string) { |
219 |
| - petHelpers.unarchive(petId); |
220 |
| - } |
| 225 | + function confirmArchive() { |
| 226 | + if (!petToArchive) return; |
| 227 | + petHelpers.archive(petToArchive.id); |
| 228 | + if (selectedPetId === petToArchive.id) { |
| 229 | + selectedPetHelpers.clear(); |
| 230 | + } |
| 231 | + confirmArchiveOpen = false; |
| 232 | + petToArchive = null; |
| 233 | + } |
| 234 | +
|
| 235 | + function cancelArchive() { |
| 236 | + confirmArchiveOpen = false; |
| 237 | + petToArchive = null; |
| 238 | + } |
| 239 | +
|
| 240 | + function unarchivePet(petId: string) { |
| 241 | + petHelpers.unarchive(petId); |
| 242 | + } |
| 243 | +
|
| 244 | + function openMemorial(petId: string) { |
| 245 | + memorialPet = pets.find((p) => p.id === petId) || null; |
| 246 | + memorialOpen = true; |
| 247 | + } |
| 248 | +
|
| 249 | + function closeMemorial() { |
| 250 | + memorialOpen = false; |
| 251 | + memorialPet = null; |
| 252 | + } |
221 | 253 | </script>
|
222 | 254 |
|
223 | 255 | <div class="pet-panel h-full" style="background: var(--petalytics-bg);">
|
|
362 | 394 | <span class="value" style="color: var(--petalytics-subtle);">
|
363 | 395 | {pet.species || 'pet'} | {pet.breed || '—'} | {pet.age}{pet.ageUnit === 'months' ? 'm' : pet.ageUnit === 'weeks' ? 'w' : 'y'}
|
364 | 396 | </span>
|
365 |
| - </div> |
366 |
| - <div class="px-2 pb-2 flex justify-end"> |
367 |
| - <button class="arrow-btn" onclick={() => archivePet(pet.id)}>archive</button> |
368 |
| - </div> |
| 397 | + <div class="ml-2 flex items-center gap-2"> |
| 398 | + <button class="arrow-btn" onclick={() => selectPet(pet.id)}>select</button> |
| 399 | + <button class="arrow-btn" onclick={() => archivePet(pet.id)}>archive</button> |
| 400 | + </div> |
| 401 | + </div> |
369 | 402 | {/each}
|
370 | 403 | {/if}
|
371 | 404 |
|
372 | 405 | <!-- Archived list -->
|
373 | 406 | <div class="my-3"><div class="border-t" style="border-color: var(--petalytics-border);"></div></div>
|
374 |
| - <div class="cli-row px-2 py-1"> |
| 407 | + <div class="cli-row px-2 py-1" style="background: color-mix(in oklab, var(--petalytics-overlay) 60%, transparent);"> |
375 | 408 | <span style="color: var(--petalytics-subtle);">#</span>
|
376 | 409 | <span class="ml-2" style="color: var(--petalytics-gold);">archived_pets</span>
|
377 | 410 | </div>
|
378 | 411 | {#if archivedPets.length === 0}
|
379 | 412 | <div class="px-2 py-2" style="color: var(--petalytics-subtle);">none</div>
|
380 | 413 | {:else}
|
381 | 414 | {#each archivedPets as pet}
|
382 |
| - <div class="cli-row px-2 py-1"> |
| 415 | + <div class="cli-row px-2 py-1" style="opacity: 0.9;"> |
383 | 416 | <span class="label" style="color: var(--petalytics-text);">{pet.name}</span>
|
384 | 417 | <span class="value" style="color: var(--petalytics-subtle);">
|
385 | 418 | {pet.species || 'pet'} | {pet.breed || '—'} | {pet.age}{pet.ageUnit === 'months' ? 'm' : pet.ageUnit === 'weeks' ? 'w' : 'y'}
|
386 | 419 | </span>
|
387 | 420 | </div>
|
388 | 421 | <div class="px-2 pb-2 flex justify-end">
|
389 |
| - <button class="arrow-btn" onclick={() => unarchivePet(pet.id)}>unarchive</button> |
| 422 | + <button class="arrow-btn" onclick={() => openMemorial(pet.id)}>view_memories</button> |
390 | 423 | </div>
|
391 | 424 | {/each}
|
392 | 425 | {/if}
|
393 | 426 | </div>
|
394 | 427 | </div>
|
395 | 428 |
|
| 429 | +<!-- Archive confirmation modal --> |
| 430 | +<Modal isOpen={confirmArchiveOpen} title="Archive Pet" size="sm" onclose={cancelArchive}> |
| 431 | + <div class="space-y-4 font-mono"> |
| 432 | + <p>Mark {petToArchive?.name} as passed away?</p> |
| 433 | + <div class="flex justify-end gap-2"> |
| 434 | + <button class="button-secondary" onclick={cancelArchive}>Cancel</button> |
| 435 | + <button class="button" onclick={confirmArchive}>Confirm</button> |
| 436 | + </div> |
| 437 | + </div> |
| 438 | +</Modal> |
| 439 | + |
| 440 | +<!-- Memorial modal for archived pet --> |
| 441 | +<MemorialModal isOpen={memorialOpen} pet={memorialPet} onclose={closeMemorial} /> |
| 442 | + |
396 | 443 | <style>
|
397 | 444 | .cli-row {
|
398 | 445 | display: flex;
|
|
0 commit comments