File size: 3,793 Bytes
b4531e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7428b13
b4531e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf7c859
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
<script lang="ts">
  import type { PicletInstance } from '$lib/db/schema';
  import PicletCard from './PicletCard.svelte';
  import { moveToRoster } from '$lib/db/piclets';
  
  interface Props {
    position: number;
    availablePiclets: PicletInstance[];
    onClose: () => void;
    onAdded?: () => void;
  }
  
  let { position, availablePiclets, onClose, onAdded }: Props = $props();
  let isAdding = $state(false);
  
  async function handleAddToRoster(piclet: PicletInstance) {
    if (!piclet.id || isAdding) return;
    
    isAdding = true;
    try {
      await moveToRoster(piclet.id, position);
      onAdded?.();
      onClose();
    } catch (err) {
      console.error('Failed to add to roster:', err);
    } finally {
      isAdding = false;
    }
  }
</script>

<div class="dialog-overlay" onclick={(e) => e.target === e.currentTarget && onClose()} onkeydown={(e) => e.key === 'Escape' && onClose()} role="button" tabindex="0" aria-label="Close dialog">
  <div class="dialog-content">
    <header class="dialog-header">
      <h2>Add to Roster</h2>
      <button class="close-btn" onclick={onClose} aria-label="Close">
        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
          <path d="M6 18L18 6M6 6l12 12"></path>
        </svg>
      </button>
    </header>
    
    <div class="dialog-body">
      {#if availablePiclets.length === 0}
        <div class="empty-state">
          <p>No piclets available in storage.</p>
          <p class="hint">Scan objects to discover new piclets!</p>
        </div>
      {:else}
        <p class="instruction">Select a piclet to add to position {position + 1}:</p>
        <div class="piclets-grid">
          {#each availablePiclets as piclet}
            <button 
              class="piclet-option"
              onclick={() => handleAddToRoster(piclet)}
              disabled={isAdding}
            >
              <PicletCard piclet={piclet} size={100} />
            </button>
          {/each}
        </div>
      {/if}
    </div>
  </div>
</div>

<style>
  .dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
  }
  
  .dialog-content {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  
  .dialog-header {
    padding: 1rem;
    border-bottom: 1px solid #e5e5ea;
    position: relative;
  }
  
  .dialog-header h2 {
    margin: 0;
    text-align: center;
    font-size: 1.25rem;
  }
  
  .close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    padding: 0;
    width: 24px;
    height: 24px;
    cursor: pointer;
    color: #8e8e93;
  }
  
  .dialog-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
  }
  
  .empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
  }
  
  .empty-state p {
    margin: 0 0 0.5rem;
  }
  
  .hint {
    font-size: 0.875rem;
    color: #8e8e93;
  }
  
  .instruction {
    margin: 0 0 1rem;
    color: #666;
    text-align: center;
  }
  
  .piclets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 1rem;
    justify-items: center;
  }
  
  .piclet-option {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: transform 0.2s;
  }
  
  .piclet-option:not(:disabled):hover {
    transform: scale(1.05);
  }
  
  .piclet-option:not(:disabled):active {
    transform: scale(0.95);
  }
  
  .piclet-option:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }
</style>