File size: 12,488 Bytes
b4531e8
e7b0a32
b4531e8
 
e7b0a32
213c234
a519169
782d90b
 
 
b4531e8
 
 
 
 
 
 
 
08c694c
213c234
b4531e8
782d90b
cf131a8
782d90b
a519169
 
 
 
 
e7b0a32
 
 
 
 
 
 
b4531e8
 
 
0803fb8
 
 
b4531e8
 
 
 
 
 
 
 
 
 
 
 
c8a8763
 
 
 
 
 
 
 
213c234
 
 
 
 
 
 
 
 
 
 
 
b4531e8
 
e7b0a32
c8a8763
 
e44e2df
a519169
5761465
930c40e
5761465
 
 
 
 
 
 
 
 
 
 
 
cfa3d9f
5761465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8a8763
 
 
5761465
c8a8763
b4531e8
 
 
 
 
c8a8763
a519169
c8a8763
 
 
 
 
 
 
 
 
782d90b
 
 
08c694c
c8a8763
b4531e8
 
c8a8763
 
 
 
e59cea4
08c694c
 
 
 
c8a8763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
782d90b
c8a8763
08c694c
782d90b
 
891a1e1
782d90b
08c694c
 
 
 
782d90b
 
987557b
 
 
 
782d90b
 
c8a8763
 
b4531e8
 
c8a8763
 
0803fb8
b4531e8
 
 
 
 
f12c994
e7b0a32
f12c994
 
 
 
c8a8763
e7b0a32
b4531e8
 
 
 
c8a8763
 
b4531e8
 
c8a8763
b4531e8
 
c8a8763
 
0797961
5761465
 
f444918
 
 
5761465
a519169
5761465
c77c1ad
5761465
 
 
 
 
f444918
6a7c6e8
 
dfcba44
 
a519169
930c40e
 
 
a519169
5761465
 
 
 
 
 
 
 
 
 
 
 
 
cfa3d9f
 
 
 
 
 
 
 
 
 
5761465
f444918
 
5761465
f444918
5761465
 
f444918
 
 
 
5761465
 
 
 
 
 
 
 
 
f444918
5761465
 
 
 
 
 
 
f444918
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4531e8
 
5761465
b4531e8
c8a8763
b4531e8
5761465
 
b4531e8
 
5761465
c8a8763
5761465
 
930c40e
 
c8a8763
 
5761465
930c40e
 
5761465
930c40e
c8a8763
 
 
 
 
 
5761465
c8a8763
5761465
c8a8763
 
 
 
 
 
 
 
5761465
 
c8a8763
 
 
 
 
 
 
a519169
c8a8763
a519169
c8a8763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4531e8
 
 
 
c8a8763
 
 
 
 
 
 
 
 
b4531e8
 
c8a8763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4531e8
 
 
08c694c
 
 
 
 
 
 
b4531e8
 
 
 
c8a8763
b4531e8
 
 
 
 
 
 
 
 
 
c8a8763
b4531e8
c8a8763
b4531e8
 
782d90b
 
 
 
 
 
 
c8a8763
e44e2df
 
 
 
 
c8a8763
b4531e8
 
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<script lang="ts">
  import { onMount } from 'svelte';
  import type { PicletInstance } from '$lib/db/schema';
  import { deletePicletInstance } from '$lib/db/piclets';
  import { uiStore } from '$lib/stores/ui';
  import { downloadPicletCard } from '$lib/services/picletExport';
  import { TYPE_DATA } from '$lib/types/picletTypes';
  import AbilityDisplay from './AbilityDisplay.svelte';
  import MoveDisplay from './MoveDisplay.svelte';
  import { picletInstanceToBattleDefinition } from '$lib/utils/battleConversion';
  
  interface Props {
    instance: PicletInstance;
    onClose: () => void;
    onDeleted?: () => void;
  }
  
  let { instance, onClose, onDeleted }: Props = $props();
  let selectedTab = $state<'about' | 'abilities'>('about');
  let isSharing = $state(false);
  
  // Convert to battle definition to get enhanced ability data
  const battleDefinition = $derived(picletInstanceToBattleDefinition(instance));
  
  // Type-based styling
  const typeData = $derived(TYPE_DATA[instance.primaryType]);
  const typeColor = $derived(typeData.color);
  const typeLogoPath = $derived(`/classes/${instance.primaryType}.png`);
  
  onMount(() => {
    uiStore.openDetailPage();
    return () => {
      uiStore.closeDetailPage();
    };
  });
  
  async function handleDelete() {
    if (!instance.id) return;
    
    const confirmed = confirm(`Are you sure you want to release ${instance.nickname || instance.typeId}? This action cannot be undone.`);
    if (!confirmed) return;
    
    try {
      await deletePicletInstance(instance.id);
      onDeleted?.();
      onClose();
    } catch (err) {
      console.error('Failed to delete piclet:', err);
    }
  }
  
  function getStatPercentage(value: number, max: number = 255): number {
    return Math.round((value / max) * 100);
  }
  
  function getHpColor(current: number, max: number): string {
    const ratio = current / max;
    if (ratio < 0.2) return '#ff3b30';
    if (ratio < 0.5) return '#ff9500';
    return '#34c759';
  }
  
  
  async function handleShare() {
    isSharing = true;
    try {
      await downloadPicletCard(instance);
    } catch (err) {
      console.error('Failed to share piclet:', err);
      alert('Failed to create shareable image');
    } finally {
      isSharing = false;
    }
  }
</script>

<div class="detail-page">
    <div class="content-scroll">
      <!-- Header Card -->
      <div class="header-card">
        <div class="card-background" style="--type-color: {typeColor}; --type-logo: url('{typeLogoPath}')">
          <!-- Faded Logo Background -->
          <div class="logo-background"></div>
          
          <!-- Card Header -->
          <div class="card-header">
            <button 
              class="back-btn-card" 
              onclick={onClose} 
              aria-label="Go back"
            >
              <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M19 12H5m0 0l7 7m-7-7l7-7"></path>
              </svg>
            </button>
            <h1 class="card-title">{instance.nickname || instance.typeId}</h1>
            <button 
              class="share-button" 
              onclick={handleShare} 
              disabled={isSharing}
              aria-label="Share Piclet"
            >
              <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <circle cx="18" cy="5" r="3"></circle>
                <circle cx="6" cy="12" r="3"></circle>
                <circle cx="18" cy="19" r="3"></circle>
                <line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line>
                <line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line>
              </svg>
            </button>
          </div>

          <!-- Large Image Section -->
          <div class="large-image-section">
            <div class="large-image-container">
              <img 
                src={instance.imageData || instance.imageUrl} 
                alt={instance.nickname || instance.typeId}
                class="large-piclet-image"
              />
            </div>
          </div>
        </div>
      </div>
      
      <!-- Tab Bar -->
      <div class="tab-bar" style="--type-color: {typeColor}">
        <button 
          class="tab-button" 
          class:active={selectedTab === 'about'}
          onclick={() => selectedTab = 'about'}
        >
          About
        </button>
        <button 
          class="tab-button" 
          class:active={selectedTab === 'abilities'}
          onclick={() => selectedTab = 'abilities'}
        >
          Abilities
        </button>
      </div>
      
      <!-- Tab Content -->
      <div class="tab-content">
        {#if selectedTab === 'about'}
          <div class="content-card">
            <p class="description">{instance.description}</p>
            
            <div class="divider"></div>
            
            <h3 class="section-heading">Stats</h3>
            <div class="stats-list">
              <div class="stat-row">
                <span>Attack</span>
                <span class="stat-value">{instance.attack}</span>
              </div>
              <div class="stat-row">
                <span>Defense</span>
                <span class="stat-value">{instance.defense}</span>
              </div>
              <div class="stat-row">
                <span>Field Attack</span>
                <span class="stat-value">{instance.fieldAttack}</span>
              </div>
              <div class="stat-row">
                <span>Field Defense</span>
                <span class="stat-value">{instance.fieldDefense}</span>
              </div>
              <div class="stat-row">
                <span>Speed</span>
                <span class="stat-value">{instance.speed}</span>
              </div>
            </div>
            
            <div class="divider"></div>
            
            <div class="stat-summary">
              <div class="summary-item">
                <span class="summary-label">BST</span>
                <span class="summary-value">{instance.bst}</span>
              </div>
              <div class="summary-item">
                <span class="summary-label">Tier</span>
                <span class="summary-value">{instance.tier.toUpperCase()}</span>
              </div>
            </div>
          </div>
        {:else if selectedTab === 'abilities'}
          <div class="content-card">
            <h3 class="section-heading">Special Ability</h3>
            <AbilityDisplay 
              ability={battleDefinition.specialAbility}
              expanded={true}
            />
            
            <div class="divider"></div>
            
            <h3 class="section-heading">Moves</h3>
            <div class="moves-list">
              {#each instance.moves as move, index}
                <MoveDisplay 
                  {move}
                  expanded={true}
                />
              {/each}
            </div>
          </div>
        {/if}
      </div>
      
      <!-- Actions -->
      <div class="bottom-actions">
        <button class="btn btn-danger" onclick={handleDelete}>Release Piclet</button>
      </div>
    </div>
</div>

<style>
  .detail-page {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f2f2f7;
    z-index: 1000;
    display: flex;
    flex-direction: column;
  }
  
  /* Content Scroll */
  .content-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Header Card */
  .header-card {
    margin-bottom: 16px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    position: relative;
  }
  
  .card-background {
    background: linear-gradient(135deg, var(--type-color, #4CAF50) 0%, color-mix(in srgb, var(--type-color, #4CAF50) 80%, white) 100%);
    padding: 24px;
    padding-top: calc(24px + env(safe-area-inset-top, 0));
    position: relative;
    overflow: hidden;
  }
  
  .logo-background {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 120px;
    height: 120px;
    background-image: var(--type-logo);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.15;
    pointer-events: none;
    z-index: 1;
  }
  
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    position: relative;
    z-index: 2;
  }
  
  .card-title {
    margin: 0;
    font-size: 24px;
    font-weight: bold;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    flex: 1;
    text-align: center;
  }
  
  .back-btn-card {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
  }
  
  .back-btn-card:hover {
    background: rgba(255, 255, 255, 0.3);
  }
  
  .share-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
  }
  
  .share-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
  }
  
  .share-button:active {
    transform: scale(0.95);
  }
  
  .share-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  
  .share-button svg {
    width: 20px;
    height: 20px;
  }
  
  .large-image-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 2;
  }
  
  .large-image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 360px;
    height: 360px;
  }
  
  .large-piclet-image {
    width: 360px;
    height: 360px;
    object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
  }
  
  
  /* Tab Bar */
  .tab-bar {
    margin: 0 16px 16px;
    height: 36px;
    background: #e5e5ea;
    border-radius: 12px;
    display: flex;
    padding: 2px;
  }
  
  .tab-button {
    flex: 1;
    background: none;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #8e8e93;
    cursor: pointer;
    transition: all 0.2s;
  }
  
  .tab-button.active {
    background: var(--type-color, #4CAF50);
    color: white;
    box-shadow: 0 2px 4px color-mix(in srgb, var(--type-color, #4CAF50) 30%, transparent);
  }
  
  /* Tab Content */
  .tab-content {
    margin: 0 16px 16px;
  }
  
  .content-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    border: 0.5px solid #c6c6c8;
  }
  
  .description {
    margin: 0 0 16px;
    font-size: 16px;
    line-height: 1.4;
    color: #000;
  }
  
  
  /* Stats Tab */
  
  .stats-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  
  .stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 15px;
  }
  
  .stat-value {
    font-weight: 600;
  }
  
  .divider {
    height: 1px;
    background: #e5e5ea;
    margin: 16px 0;
  }
  
  .stat-summary {
    display: flex;
    justify-content: space-around;
  }
  
  .summary-item {
    text-align: center;
  }
  
  .summary-label {
    display: block;
    font-size: 14px;
    color: #8e8e93;
    margin-bottom: 4px;
  }
  
  .summary-value {
    font-size: 16px;
    font-weight: bold;
    color: #000;
  }
  
  
  /* Bottom Actions */
  .bottom-actions {
    padding: 16px;
    background: white;
    border-top: 0.5px solid #c6c6c8;
    text-align: center;
  }
  
  .section-heading {
    font-size: 18px;
    font-weight: 600;
    color: #495057;
    margin: 0 0 12px 0;
  }
  
  .btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
  }
  
  .btn:active {
    transform: scale(0.95);
  }
  
  .btn-danger {
    background: #ff3b30;
    color: white;
    width: 100%;
  }
  
  /* Enhanced ability and move display styles */
  .moves-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  
  @media (min-width: 768px) {
    .detail-page {
      position: relative;
      max-width: 600px;
      margin: 0 auto;
      box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    }
  }
</style>