@isaiahiroko/tilmart-ngx-apps-admin 0.2.9 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,634 @@
1
+ import * as i0 from '@angular/core';
2
+ import { EventEmitter, Output, Input, Component, NgModule } from '@angular/core';
3
+ import * as i1$1 from '@angular/router';
4
+ import { RouterModule } from '@angular/router';
5
+ import { BaseDirective, notify, SharedModule } from '@thescaffold/ngx-core';
6
+ import * as i1 from '@angular/forms';
7
+ import { FormsModule } from '@angular/forms';
8
+ import { firstValueFrom } from 'rxjs';
9
+ import * as i3 from '@angular/common';
10
+
11
+ // index/DELIVERY.md §8.3 — a reusable multi-select for Nigerian states, grouped
12
+ // by geopolitical zone: a tri-state checkbox per zone, one per state, search,
13
+ // removable chips of the current selection and per-option hints/badges. Pay-on-
14
+ // delivery rules and delivery zones can adopt it later.
15
+ class StateMultiselectComponent {
16
+ constructor() {
17
+ this.zones = [];
18
+ this.selected = [];
19
+ this.selectedChange = new EventEmitter();
20
+ this.query = '';
21
+ this.closed = new Set();
22
+ this.allCollapsed = false;
23
+ }
24
+ get total() {
25
+ return this.zones.reduce((n, z) => n + z.states.length, 0);
26
+ }
27
+ get allOpen() {
28
+ return !this.allCollapsed;
29
+ }
30
+ has(state) {
31
+ return this.selected.some((s) => s.toLowerCase() === state.toLowerCase());
32
+ }
33
+ visible(z) {
34
+ const q = this.query.trim().toLowerCase();
35
+ return q ? z.states.filter((o) => o.state.toLowerCase().includes(q)) : z.states;
36
+ }
37
+ zoneCount(z) {
38
+ return z.states.filter((o) => this.has(o.state)).length;
39
+ }
40
+ zoneState(z) {
41
+ const n = this.zoneCount(z);
42
+ return n === 0 ? 'none' : n === z.states.length ? 'all' : 'some';
43
+ }
44
+ toggleZone(z) {
45
+ const names = z.states.map((o) => o.state);
46
+ const next = this.zoneState(z) === 'all'
47
+ ? this.selected.filter((s) => !names.some((n) => n.toLowerCase() === s.toLowerCase()))
48
+ : [...this.selected, ...names.filter((n) => !this.has(n))];
49
+ this.emit(next);
50
+ }
51
+ toggle(state) {
52
+ this.emit(this.has(state)
53
+ ? this.selected.filter((s) => s.toLowerCase() !== state.toLowerCase())
54
+ : [...this.selected, state]);
55
+ }
56
+ clear() {
57
+ this.emit([]);
58
+ }
59
+ isOpen(code) {
60
+ // searching opens every matching zone so results are never hidden
61
+ return !!this.query.trim() || !this.closed.has(code);
62
+ }
63
+ toggleOpen(code) {
64
+ this.closed.has(code) ? this.closed.delete(code) : this.closed.add(code);
65
+ }
66
+ toggleAllOpen() {
67
+ this.allCollapsed = !this.allCollapsed;
68
+ this.closed = this.allCollapsed ? new Set(this.zones.map((z) => z.code)) : new Set();
69
+ }
70
+ emit(next) {
71
+ this.selected = next;
72
+ this.selectedChange.emit(next);
73
+ }
74
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: StateMultiselectComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
75
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: StateMultiselectComponent, isStandalone: true, selector: "x-state-multiselect", inputs: { zones: "zones", selected: "selected" }, outputs: { selectedChange: "selectedChange" }, ngImport: i0, template: `
76
+ <div class="sms" data-testid="state-multiselect">
77
+ <div class="sms-bar">
78
+ <input class="sms-search" type="search" placeholder="Search states…" [(ngModel)]="query" data-testid="sms-search" />
79
+ <span class="sms-count" data-testid="sms-count">{{ selected.length }} of {{ total }} selected</span>
80
+ <button type="button" class="sms-link" (click)="clear()" [disabled]="!selected.length" data-testid="sms-clear">Clear</button>
81
+ <button type="button" class="sms-link" (click)="toggleAllOpen()">{{ allOpen ? 'Collapse all' : 'Expand all' }}</button>
82
+ </div>
83
+
84
+ @if (selected.length) {
85
+ <div class="sms-chips" data-testid="sms-chips">
86
+ @for (s of selected; track s) {
87
+ <span class="sms-chip">{{ s }}<button type="button" aria-label="Remove {{ s }}" (click)="toggle(s)">×</button></span>
88
+ }
89
+ </div>
90
+ }
91
+
92
+ @for (z of zones; track z.code) {
93
+ @if (visible(z).length) {
94
+ <div class="sms-zone" [attr.data-zone]="z.code">
95
+ <div class="sms-zone-head">
96
+ <input
97
+ type="checkbox"
98
+ [checked]="zoneState(z) === 'all'"
99
+ [indeterminate]="zoneState(z) === 'some'"
100
+ (change)="toggleZone(z)"
101
+ [attr.aria-label]="'Select all ' + z.name"
102
+ [attr.data-testid]="'sms-zone-' + z.code"
103
+ />
104
+ <button type="button" class="sms-zone-name" (click)="toggleOpen(z.code)">
105
+ <span class="sms-caret">{{ isOpen(z.code) ? '▾' : '▸' }}</span> {{ z.name }}
106
+ </button>
107
+ <span class="sms-zone-count">{{ zoneCount(z) }}/{{ z.states.length }}</span>
108
+ </div>
109
+ @if (isOpen(z.code)) {
110
+ <div class="sms-states">
111
+ @for (o of visible(z); track o.state) {
112
+ <label class="sms-state" [class.is-on]="has(o.state)">
113
+ <input type="checkbox" [checked]="has(o.state)" (change)="toggle(o.state)" [attr.data-testid]="'sms-state-' + o.state" />
114
+ <span>{{ o.state }}</span>
115
+ @if (o.badge) { <span class="sms-badge" [attr.title]="o.badgeTitle">{{ o.badge }}</span> }
116
+ @if (o.hint) { <span class="sms-hint">({{ o.hint }})</span> }
117
+ </label>
118
+ }
119
+ </div>
120
+ }
121
+ </div>
122
+ }
123
+ }
124
+ </div>
125
+ `, isInline: true, styles: [".sms{display:flex;flex-direction:column;gap:10px}.sms-bar{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.sms-search{flex:1 1 180px;min-width:140px;padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px}.sms-count{font-size:12.5px;color:var(--color-text-muted)}.sms-link{appearance:none;background:none;border:0;color:var(--color-accent-hover, #0b3a82);font-size:12.5px;font-weight:700;cursor:pointer;padding:2px 4px}.sms-link:disabled{opacity:.4;cursor:default}.sms-chips{display:flex;flex-wrap:wrap;gap:6px}.sms-chip{display:inline-flex;align-items:center;gap:4px;padding:2px 4px 2px 9px;border-radius:999px;background:color-mix(in srgb,var(--color-brand, #0b3a82) 12%,transparent);font-size:12px;font-weight:600}.sms-chip button{appearance:none;border:0;background:transparent;cursor:pointer;font-size:14px;line-height:1;color:inherit;padding:0 5px}.sms-zone{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px)}.sms-zone-head{display:flex;align-items:center;gap:8px;padding:7px 10px}.sms-zone-name{appearance:none;background:none;border:0;font:inherit;font-weight:700;font-size:13.5px;color:inherit;cursor:pointer;flex:1;text-align:left;padding:0}.sms-caret{display:inline-block;width:14px;color:var(--color-text-muted)}.sms-zone-count{font-size:12px;color:var(--color-text-muted)}.sms-states{display:grid;grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:4px 12px;padding:4px 12px 10px 34px}.sms-state{display:flex;align-items:center;gap:6px;font-size:13px;cursor:pointer}.sms-state.is-on{font-weight:700}.sms-hint{color:var(--color-text-muted);font-size:12px;font-weight:400}.sms-badge{font-size:12px}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] }); }
126
+ }
127
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: StateMultiselectComponent, decorators: [{
128
+ type: Component,
129
+ args: [{ selector: 'x-state-multiselect', standalone: true, imports: [FormsModule], template: `
130
+ <div class="sms" data-testid="state-multiselect">
131
+ <div class="sms-bar">
132
+ <input class="sms-search" type="search" placeholder="Search states…" [(ngModel)]="query" data-testid="sms-search" />
133
+ <span class="sms-count" data-testid="sms-count">{{ selected.length }} of {{ total }} selected</span>
134
+ <button type="button" class="sms-link" (click)="clear()" [disabled]="!selected.length" data-testid="sms-clear">Clear</button>
135
+ <button type="button" class="sms-link" (click)="toggleAllOpen()">{{ allOpen ? 'Collapse all' : 'Expand all' }}</button>
136
+ </div>
137
+
138
+ @if (selected.length) {
139
+ <div class="sms-chips" data-testid="sms-chips">
140
+ @for (s of selected; track s) {
141
+ <span class="sms-chip">{{ s }}<button type="button" aria-label="Remove {{ s }}" (click)="toggle(s)">×</button></span>
142
+ }
143
+ </div>
144
+ }
145
+
146
+ @for (z of zones; track z.code) {
147
+ @if (visible(z).length) {
148
+ <div class="sms-zone" [attr.data-zone]="z.code">
149
+ <div class="sms-zone-head">
150
+ <input
151
+ type="checkbox"
152
+ [checked]="zoneState(z) === 'all'"
153
+ [indeterminate]="zoneState(z) === 'some'"
154
+ (change)="toggleZone(z)"
155
+ [attr.aria-label]="'Select all ' + z.name"
156
+ [attr.data-testid]="'sms-zone-' + z.code"
157
+ />
158
+ <button type="button" class="sms-zone-name" (click)="toggleOpen(z.code)">
159
+ <span class="sms-caret">{{ isOpen(z.code) ? '▾' : '▸' }}</span> {{ z.name }}
160
+ </button>
161
+ <span class="sms-zone-count">{{ zoneCount(z) }}/{{ z.states.length }}</span>
162
+ </div>
163
+ @if (isOpen(z.code)) {
164
+ <div class="sms-states">
165
+ @for (o of visible(z); track o.state) {
166
+ <label class="sms-state" [class.is-on]="has(o.state)">
167
+ <input type="checkbox" [checked]="has(o.state)" (change)="toggle(o.state)" [attr.data-testid]="'sms-state-' + o.state" />
168
+ <span>{{ o.state }}</span>
169
+ @if (o.badge) { <span class="sms-badge" [attr.title]="o.badgeTitle">{{ o.badge }}</span> }
170
+ @if (o.hint) { <span class="sms-hint">({{ o.hint }})</span> }
171
+ </label>
172
+ }
173
+ </div>
174
+ }
175
+ </div>
176
+ }
177
+ }
178
+ </div>
179
+ `, styles: [".sms{display:flex;flex-direction:column;gap:10px}.sms-bar{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.sms-search{flex:1 1 180px;min-width:140px;padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px}.sms-count{font-size:12.5px;color:var(--color-text-muted)}.sms-link{appearance:none;background:none;border:0;color:var(--color-accent-hover, #0b3a82);font-size:12.5px;font-weight:700;cursor:pointer;padding:2px 4px}.sms-link:disabled{opacity:.4;cursor:default}.sms-chips{display:flex;flex-wrap:wrap;gap:6px}.sms-chip{display:inline-flex;align-items:center;gap:4px;padding:2px 4px 2px 9px;border-radius:999px;background:color-mix(in srgb,var(--color-brand, #0b3a82) 12%,transparent);font-size:12px;font-weight:600}.sms-chip button{appearance:none;border:0;background:transparent;cursor:pointer;font-size:14px;line-height:1;color:inherit;padding:0 5px}.sms-zone{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px)}.sms-zone-head{display:flex;align-items:center;gap:8px;padding:7px 10px}.sms-zone-name{appearance:none;background:none;border:0;font:inherit;font-weight:700;font-size:13.5px;color:inherit;cursor:pointer;flex:1;text-align:left;padding:0}.sms-caret{display:inline-block;width:14px;color:var(--color-text-muted)}.sms-zone-count{font-size:12px;color:var(--color-text-muted)}.sms-states{display:grid;grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:4px 12px;padding:4px 12px 10px 34px}.sms-state{display:flex;align-items:center;gap:6px;font-size:13px;cursor:pointer}.sms-state.is-on{font-weight:700}.sms-hint{color:var(--color-text-muted);font-size:12px;font-weight:400}.sms-badge{font-size:12px}\n"] }]
180
+ }], propDecorators: { zones: [{
181
+ type: Input
182
+ }], selected: [{
183
+ type: Input
184
+ }], selectedChange: [{
185
+ type: Output
186
+ }] } });
187
+
188
+ // Fields persisted on the stock location (everything else on `draft` is derived).
189
+ const SITE_FIELDS = [
190
+ 'name', 'type', 'street', 'city', 'state', 'lga', 'landmark', 'lat', 'lng', 'phone', 'contactName',
191
+ 'contactEmail', 'openingHours', 'pickupNote', 'priority', 'pickupEnabled', 'providerStationIds',
192
+ ];
193
+ const IMPORT_TEMPLATE = 'sku,location,quantity\nSKU-001,Lagos Central Warehouse,25\nSKU-002,Abuja,10\n';
194
+ // index/DELIVERY.md §8.3 / §8.10 — Settings ▸ Pickup locations. A stock location
195
+ // IS the pickup location: one record holds the goods and the address a courier
196
+ // collects from. Admins decide which destination states each site ships (multi-
197
+ // select), see coverage at a glance, and assign stock to locations (move/import).
198
+ class PickupLocationsComponent extends BaseDirective {
199
+ constructor() {
200
+ super(...arguments);
201
+ this.tab = 'locations';
202
+ this.loading = true;
203
+ this.health = null;
204
+ this.coverage = null;
205
+ this.stateOptions = [];
206
+ this.lgaOptions = [];
207
+ this.stations = [];
208
+ // list
209
+ this.search = '';
210
+ this.showAll = false;
211
+ // edit
212
+ this.selectedId = null;
213
+ this.draft = null;
214
+ this.draftStates = [];
215
+ this.originalStates = [];
216
+ this.saving = false;
217
+ this.formError = '';
218
+ // coverage table
219
+ this.coverageZone = '';
220
+ this.coverageAttention = false;
221
+ this.coverageSelected = new Set();
222
+ this.bulkSite = '';
223
+ // inventory: move
224
+ this.moveFrom = '';
225
+ this.moveRows = [];
226
+ this.moveLoading = false;
227
+ this.moveTo = '';
228
+ this.newLoc = { name: '', state: '', city: '' };
229
+ this.showNewLoc = false;
230
+ this.moving = false;
231
+ this.moveResult = null;
232
+ // inventory: import
233
+ this.importText = '';
234
+ this.importMode = 'set';
235
+ this.importReport = null;
236
+ this.importNewStates = {};
237
+ this.importing = false;
238
+ this.importTemplate = 'data:text/csv;charset=utf-8,' + encodeURIComponent(IMPORT_TEMPLATE);
239
+ this.init = () => {
240
+ void this.refresh();
241
+ void this.loadStates();
242
+ };
243
+ }
244
+ // ── data ──────────────────────────────────────────────────────────────
245
+ async safe(obs) {
246
+ try {
247
+ return (await firstValueFrom(obs));
248
+ }
249
+ catch (e) {
250
+ const body = e?.error ?? e;
251
+ const msg = body?.message?.message ?? body?.message ?? e?.message ?? 'That did not work.';
252
+ this.formError = String(msg);
253
+ notify(String(msg), undefined, 'error');
254
+ return undefined;
255
+ }
256
+ }
257
+ async refresh() {
258
+ const [cov, health] = await Promise.all([
259
+ this.safe(this.apiService.get('apps/commerce/stock-location/coverage/overview')),
260
+ this.safe(this.apiService.get('apps/commerce/logistics/health')),
261
+ ]);
262
+ this.coverage = cov?.data ?? null;
263
+ this.health = health?.data ?? null;
264
+ this.loading = false;
265
+ }
266
+ async loadStates() {
267
+ const res = await this.safe(this.apiService.on('apps/commerce/static-list-item').getMany({ listKey: 'ng-state', perPage: 200 }));
268
+ this.stateOptions = (res?.data ?? []).map((r) => ({ value: r.code, label: r.label }));
269
+ }
270
+ async loadLgas(state) {
271
+ this.lgaOptions = [];
272
+ if (!state)
273
+ return;
274
+ const res = await this.safe(this.apiService.on('apps/commerce/static-list-item').getMany({ listKey: 'ng-lga', parentCode: state, perPage: 200 }));
275
+ this.lgaOptions = (res?.data ?? []).map((r) => ({ value: r.code, label: r.label }));
276
+ }
277
+ async loadStations(state) {
278
+ this.stations = [];
279
+ if (!state)
280
+ return;
281
+ const res = await this.safe(this.apiService.get(`apps/commerce/logistics/stations?state=${encodeURIComponent(state)}`));
282
+ this.stations = res?.data ?? [];
283
+ }
284
+ // ── derived ───────────────────────────────────────────────────────────
285
+ get sites() {
286
+ const all = this.coverage?.sites ?? [];
287
+ const q = this.search.trim().toLowerCase();
288
+ return all
289
+ .filter((s) => this.showAll || s.pickupEnabled || (s.state && !/^tbc/i.test(s.state)) || s.stock?.units > 0 || s.id === this.selectedId)
290
+ .filter((s) => !q || `${s.name} ${s.city ?? ''} ${s.state ?? ''}`.toLowerCase().includes(q))
291
+ .sort((a, b) => Number(b.ready) - Number(a.ready) || b.shipsTo.length - a.shipsTo.length || a.name.localeCompare(b.name));
292
+ }
293
+ get hiddenSites() {
294
+ return (this.coverage?.sites?.length ?? 0) - this.sites.length;
295
+ }
296
+ get zones() {
297
+ if (!this.coverage)
298
+ return [];
299
+ const sitesById = new Map((this.coverage.sites ?? []).map((s) => [s.id, s]));
300
+ return this.coverage.zones.map((z) => ({
301
+ code: z.code,
302
+ name: z.name,
303
+ states: z.states.map((s) => ({
304
+ state: s.state,
305
+ // who ships it now (when it is someone else), so ticking it clearly *moves* it
306
+ hint: s.stockLocationId && s.stockLocationId !== this.selectedId ? sitesById.get(s.stockLocationId)?.name : undefined,
307
+ badge: s.sitesInState?.length ? '📦' : undefined,
308
+ badgeTitle: s.sitesInState?.length ? `Stock site in ${s.state}: ${s.sitesInState.join(', ')}` : undefined,
309
+ })),
310
+ }));
311
+ }
312
+ get selectedSite() {
313
+ return (this.coverage?.sites ?? []).find((s) => s.id === this.selectedId);
314
+ }
315
+ /** What Save will move / unassign — shown before the admin commits. */
316
+ get pending() {
317
+ const owner = new Map();
318
+ const sitesById = new Map((this.coverage?.sites ?? []).map((s) => [s.id, s]));
319
+ for (const z of this.coverage?.zones ?? [])
320
+ for (const s of z.states)
321
+ if (s.stockLocationId)
322
+ owner.set(s.state, s.stockLocationId);
323
+ const moved = [];
324
+ const added = [];
325
+ for (const state of this.draftStates) {
326
+ if (this.originalStates.includes(state))
327
+ continue;
328
+ const o = owner.get(state);
329
+ if (o && o !== this.selectedId)
330
+ moved.push({ state, from: sitesById.get(o)?.name ?? 'another site' });
331
+ else
332
+ added.push(state);
333
+ }
334
+ const unassigned = this.originalStates.filter((s) => !this.draftStates.includes(s));
335
+ return { moved, added, unassigned };
336
+ }
337
+ get pendingText() {
338
+ const p = this.pending;
339
+ const parts = [];
340
+ if (p.moved.length)
341
+ parts.push(`moves ${p.moved.length} state${p.moved.length > 1 ? 's' : ''}: ${p.moved.map((m) => `${m.state} (from ${m.from})`).join(', ')}`);
342
+ if (p.added.length)
343
+ parts.push(`adds ${p.added.join(', ')}`);
344
+ if (p.unassigned.length)
345
+ parts.push(`unassigns ${p.unassigned.join(', ')} (those orders will be served automatically by whichever ready site holds the goods)`);
346
+ return parts.length ? `Saving ${parts.join('; ')}.` : '';
347
+ }
348
+ get healthText() {
349
+ const h = this.health;
350
+ if (!h)
351
+ return '';
352
+ if (h.status === 'healthy')
353
+ return `${(h.provider ?? '').toUpperCase()} delivery is working.`;
354
+ const why = h.reason === 'wallet_insufficient' ? 'the GIG wallet is too low — please top it up'
355
+ : h.reason === 'credentials_rejected' ? 'GIG rejected our login'
356
+ : 'GIG is not responding';
357
+ return `${(h.provider ?? '').toUpperCase()} is failing: ${why}.`;
358
+ }
359
+ // ── list / edit ───────────────────────────────────────────────────────
360
+ async select(site) {
361
+ this.formError = '';
362
+ this.selectedId = site.id;
363
+ const res = await this.safe(this.apiService.get(`apps/commerce/stock-location/${site.id}`));
364
+ this.draft = { ...(res?.data ?? site) };
365
+ this.draft.providerStationIds = this.draft.providerStationIds ?? {};
366
+ this.originalStates = [...(site.shipsTo ?? [])];
367
+ this.draftStates = [...this.originalStates];
368
+ await Promise.all([this.loadLgas(this.draft.state), this.loadStations(this.draft.state)]);
369
+ }
370
+ newSite() {
371
+ this.selectedId = null;
372
+ this.formError = '';
373
+ this.draft = { name: '', type: 'warehouse', state: '', city: '', street: '', phone: '', openingHours: '', pickupEnabled: false, priority: 0, providerStationIds: {} };
374
+ this.originalStates = [];
375
+ this.draftStates = [];
376
+ this.lgaOptions = [];
377
+ this.stations = [];
378
+ }
379
+ async onStateChange() {
380
+ this.draft.lga = '';
381
+ this.draft.providerStationIds = {};
382
+ await Promise.all([this.loadLgas(this.draft.state), this.loadStations(this.draft.state)]);
383
+ }
384
+ get gigStation() {
385
+ return String(this.draft?.providerStationIds?.gig ?? '');
386
+ }
387
+ set gigStation(v) {
388
+ this.draft.providerStationIds = v ? { ...this.draft.providerStationIds, gig: Number(v) } : {};
389
+ }
390
+ close() {
391
+ this.draft = null;
392
+ this.selectedId = null;
393
+ this.formError = '';
394
+ }
395
+ async save() {
396
+ if (!this.draft?.name?.trim()) {
397
+ this.formError = 'Give the location a name.';
398
+ return;
399
+ }
400
+ this.saving = true;
401
+ this.formError = '';
402
+ try {
403
+ const payload = {};
404
+ for (const k of SITE_FIELDS)
405
+ if (this.draft[k] !== undefined && this.draft[k] !== null && this.draft[k] !== '')
406
+ payload[k] = this.draft[k];
407
+ for (const k of ['lat', 'lng', 'priority'])
408
+ if (payload[k] !== undefined)
409
+ payload[k] = Number(payload[k]);
410
+ let id = this.selectedId;
411
+ if (id) {
412
+ const r = await this.safe(this.apiService.patch(`apps/commerce/stock-location/${id}`, payload));
413
+ if (!r)
414
+ return;
415
+ }
416
+ else {
417
+ const r = await this.safe(this.apiService.post('apps/commerce/stock-location', payload));
418
+ if (!r)
419
+ return;
420
+ id = r.data?.id;
421
+ }
422
+ const changed = this.pending.moved.length + this.pending.added.length + this.pending.unassigned.length > 0;
423
+ if (id && changed) {
424
+ const r = await this.safe(this.apiService.put(`apps/commerce/stock-location/${id}/ships-to`, { states: this.draftStates }));
425
+ if (!r)
426
+ return;
427
+ }
428
+ notify('Saved.', undefined, 'success');
429
+ await this.refresh();
430
+ const fresh = this.coverage?.sites?.find((s) => s.id === id);
431
+ if (fresh)
432
+ await this.select(fresh);
433
+ }
434
+ finally {
435
+ this.saving = false;
436
+ }
437
+ }
438
+ async remove() {
439
+ if (!this.selectedId)
440
+ return;
441
+ if (this.draftStates.length && !confirm(`This site ships ${this.draftStates.length} state(s). Delete it anyway? They will fall back to automatic routing.`))
442
+ return;
443
+ const r = await this.safe(this.apiService.delete(`apps/commerce/stock-location/${this.selectedId}`));
444
+ if (!r)
445
+ return;
446
+ this.close();
447
+ await this.refresh();
448
+ }
449
+ // ── health ────────────────────────────────────────────────────────────
450
+ async syncStations() {
451
+ const r = await this.safe(this.apiService.post('apps/commerce/logistics/sync-stations', {}));
452
+ if (r?.data) {
453
+ notify(`Synced ${r.data.stations} stations.` + (r.data.needChoice?.length ? ` Choose a preferred station for: ${r.data.needChoice.join(', ')}.` : ''), undefined, 'success');
454
+ await this.refresh();
455
+ }
456
+ }
457
+ // ── coverage table ────────────────────────────────────────────────────
458
+ get coverageRows() {
459
+ const rows = [];
460
+ for (const z of this.coverage?.zones ?? []) {
461
+ if (this.coverageZone && z.code !== this.coverageZone)
462
+ continue;
463
+ for (const s of z.states) {
464
+ const attention = !s.stockLocationId || !s.ready;
465
+ if (this.coverageAttention && !attention)
466
+ continue;
467
+ rows.push({ ...s, zone: z.name, attention });
468
+ }
469
+ }
470
+ return rows;
471
+ }
472
+ toggleRow(state) {
473
+ this.coverageSelected.has(state) ? this.coverageSelected.delete(state) : this.coverageSelected.add(state);
474
+ }
475
+ async assignOne(state, siteId) {
476
+ const r = await this.safe(this.apiService.post('apps/commerce/stock-location/assign', { states: [state], stockLocationId: siteId || null }));
477
+ if (r)
478
+ await this.refresh();
479
+ }
480
+ async assignSelected(siteId) {
481
+ const states = [...this.coverageSelected];
482
+ if (!states.length)
483
+ return;
484
+ const r = await this.safe(this.apiService.post('apps/commerce/stock-location/assign', { states, stockLocationId: siteId || null }));
485
+ if (r) {
486
+ this.coverageSelected.clear();
487
+ this.bulkSite = '';
488
+ notify(siteId ? `Assigned ${states.length} state(s).` : `Unassigned ${states.length} state(s).`, undefined, 'success');
489
+ await this.refresh();
490
+ }
491
+ }
492
+ // ── inventory: move ───────────────────────────────────────────────────
493
+ async loadMoveRows() {
494
+ this.moveRows = [];
495
+ this.moveResult = null;
496
+ if (!this.moveFrom)
497
+ return;
498
+ this.moveLoading = true;
499
+ try {
500
+ const res = await this.safe(this.apiService.on('apps/commerce/stock-level').getMany({ locationId: this.moveFrom, perPage: 200 }));
501
+ const levels = (res?.data ?? []).filter((l) => l.available > 0);
502
+ this.moveRows = await Promise.all(levels.slice(0, 100).map(async (l) => {
503
+ const v = await firstValueFrom(this.apiService.get(`apps/commerce/product-variant/${l.variantId}`)).catch(() => undefined);
504
+ return { id: l.id, variantId: l.variantId, sku: v?.data?.sku ?? l.variantId.slice(0, 8), available: l.available, reserved: l.reserved, checked: false };
505
+ }));
506
+ }
507
+ finally {
508
+ this.moveLoading = false;
509
+ }
510
+ }
511
+ get moveSelected() {
512
+ return this.moveRows.filter((r) => r.checked).length;
513
+ }
514
+ toggleAllMove(on) {
515
+ this.moveRows.forEach((r) => (r.checked = on));
516
+ }
517
+ async createInlineLocation() {
518
+ if (!this.newLoc.name.trim() || !this.newLoc.state) {
519
+ notify('A new location needs a name and a state.', undefined, 'error');
520
+ return;
521
+ }
522
+ const r = await this.safe(this.apiService.post('apps/commerce/stock-location', { name: this.newLoc.name.trim(), type: 'warehouse', state: this.newLoc.state, city: this.newLoc.city || undefined, pickupEnabled: false }));
523
+ if (r?.data?.id) {
524
+ notify('Location created. Add its pickup details under "By location" to let a courier collect there.', undefined, 'success');
525
+ this.showNewLoc = false;
526
+ this.newLoc = { name: '', state: '', city: '' };
527
+ await this.refresh();
528
+ this.moveTo = r.data.id;
529
+ }
530
+ }
531
+ async moveStock() {
532
+ const levelIds = this.moveRows.filter((r) => r.checked).map((r) => r.id);
533
+ if (!levelIds.length || !this.moveTo)
534
+ return;
535
+ this.moving = true;
536
+ try {
537
+ const r = await this.safe(this.apiService.post('apps/commerce/stock-location/move-stock', { levelIds, toLocationId: this.moveTo }));
538
+ if (r?.data) {
539
+ this.moveResult = r.data;
540
+ notify(`Moved ${r.data.units} unit(s) across ${r.data.moved} row(s).`, undefined, 'success');
541
+ await this.loadMoveRows();
542
+ this.moveResult = r.data;
543
+ await this.refresh();
544
+ }
545
+ }
546
+ finally {
547
+ this.moving = false;
548
+ }
549
+ }
550
+ // ── inventory: import ─────────────────────────────────────────────────
551
+ onImportFile(ev) {
552
+ const file = ev.target.files?.[0];
553
+ if (!file)
554
+ return;
555
+ const reader = new FileReader();
556
+ reader.onload = () => {
557
+ this.importText = String(reader.result ?? '');
558
+ this.importReport = null;
559
+ };
560
+ reader.readAsText(file);
561
+ }
562
+ parseImport() {
563
+ const lines = this.importText.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
564
+ const rows = lines.map((l) => l.split(/,|\t|;/).map((c) => c.trim().replace(/^"|"$/g, '')));
565
+ const start = /sku/i.test(rows[0]?.[0] ?? '') ? 1 : 0;
566
+ return rows.slice(start).map(([sku, location, quantity]) => ({ sku, location, quantity: Number(quantity) }));
567
+ }
568
+ async previewImport() {
569
+ await this.runImport(true);
570
+ }
571
+ async applyImport() {
572
+ await this.runImport(false);
573
+ }
574
+ async runImport(dryRun) {
575
+ const rows = this.parseImport();
576
+ if (!rows.length) {
577
+ notify('Paste or upload rows as: sku, location, quantity.', undefined, 'error');
578
+ return;
579
+ }
580
+ this.importing = true;
581
+ try {
582
+ const newLocations = {};
583
+ for (const [name, state] of Object.entries(this.importNewStates))
584
+ if (state)
585
+ newLocations[name] = { state };
586
+ const r = await this.safe(this.apiService.post('apps/commerce/stock-location/import-stock', { rows, mode: this.importMode, dryRun, newLocations }));
587
+ if (!r?.data)
588
+ return;
589
+ this.importReport = r.data;
590
+ for (const n of r.data.unknownLocations ?? [])
591
+ this.importNewStates[n] ??= '';
592
+ if (!dryRun) {
593
+ notify(`Imported ${r.data.applied} row(s).`, undefined, 'success');
594
+ await this.refresh();
595
+ }
596
+ }
597
+ finally {
598
+ this.importing = false;
599
+ }
600
+ }
601
+ get canApplyImport() {
602
+ const r = this.importReport;
603
+ return !!r && r.dryRun && r.applied > 0 && !(r.unknownLocations ?? []).length && !(r.invalid ?? []).length;
604
+ }
605
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: PickupLocationsComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
606
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: PickupLocationsComponent, isStandalone: false, selector: "x-pickup-locations", usesInheritance: true, ngImport: i0, template: "<div class=\"x-page-head\">\n <div class=\"x-page-title\">Pickup locations</div>\n <div class=\"x-page-subtitle\">\n The addresses a courier collects parcels from. Each is also a stock location \u2014 choose which states it ships, and where your stock is held.\n </div>\n</div>\n\n@if (health) {\n <div class=\"pl-health\" [class.is-bad]=\"health.status !== 'healthy'\" data-testid=\"delivery-health\">\n <span class=\"pl-dot\"></span>\n <div class=\"pl-health-text\">\n <strong>{{ healthText }}</strong>\n @if (health.waitingBookings) {\n <span class=\"pl-muted\"> {{ health.waitingBookings }} booking(s) waiting.</span>\n }\n @if (health.circuitOpen) {\n <span class=\"pl-muted\"> Customers currently see \u201Cdelivery unavailable\u201D.</span>\n }\n </div>\n <button type=\"button\" class=\"pl-btn\" (click)=\"syncStations()\" data-testid=\"sync-stations\">Sync carrier stations</button>\n </div>\n}\n\n<nav class=\"pl-tabs\">\n <button type=\"button\" class=\"pl-tab\" [class.is-active]=\"tab === 'locations'\" (click)=\"tab = 'locations'\" data-testid=\"tab-locations\">By location</button>\n <button type=\"button\" class=\"pl-tab\" [class.is-active]=\"tab === 'coverage'\" (click)=\"tab = 'coverage'\" data-testid=\"tab-coverage\">Coverage table</button>\n <button type=\"button\" class=\"pl-tab\" [class.is-active]=\"tab === 'inventory'\" (click)=\"tab = 'inventory'\" data-testid=\"tab-inventory\">Stock &amp; inventory</button>\n</nav>\n\n@if (loading) {\n <p class=\"pl-muted\">Loading\u2026</p>\n} @else {\n @if (coverage?.sitesHoldingStockNotReady?.length) {\n <div class=\"pl-banner\" data-testid=\"not-ready-banner\">\n \u26A0 {{ coverage.sitesHoldingStockNotReady.join(', ') }} hold{{ coverage.sitesHoldingStockNotReady.length > 1 ? '' : 's' }} stock but\n {{ coverage.sitesHoldingStockNotReady.length > 1 ? 'aren\u2019t' : 'isn\u2019t' }} ready for pickup \u2014 orders for those states ship from other sites.\n </div>\n }\n\n <!-- \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 By location \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (tab === 'locations') {\n <div class=\"pl-split\">\n <aside class=\"pl-list\">\n <div class=\"pl-list-head\">\n <input class=\"pl-input\" type=\"search\" placeholder=\"Search locations\u2026\" [(ngModel)]=\"search\" data-testid=\"location-search\" />\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" (click)=\"newSite()\" data-testid=\"add-location\">+ Add location</button>\n </div>\n @for (s of sites; track s.id) {\n <button type=\"button\" class=\"pl-site\" [class.is-active]=\"selectedId === s.id\" (click)=\"select(s)\" [attr.data-testid]=\"'site-' + s.name\">\n <span class=\"pl-site-name\">\n <span class=\"pl-status\" [class.ok]=\"s.ready\" [class.warn]=\"!s.ready\" [title]=\"s.ready ? 'Ready' : (s.pickupEnabled ? 'Needs details' : 'Pickup not enabled')\">{{ s.ready ? '\u2713' : (s.pickupEnabled ? '\u26A0' : '\u23F8') }}</span>\n {{ s.name }}\n </span>\n <span class=\"pl-site-meta\">\n {{ s.shipsTo.length }} states \u00B7 {{ s.stock.units ? (s.stock.products + ' products in stock') : 'no stock yet' }}\n </span>\n </button>\n } @empty {\n <p class=\"pl-muted\">No locations match.</p>\n }\n @if (hiddenSites > 0 || showAll) {\n <label class=\"pl-showall\"><input type=\"checkbox\" [(ngModel)]=\"showAll\" /> Show all {{ coverage?.sites?.length }} stock locations</label>\n }\n <button type=\"button\" class=\"pl-link\" (click)=\"tab = 'coverage'\">Coverage table \u2192</button>\n </aside>\n\n <section class=\"pl-form\" data-testid=\"location-form\">\n @if (!draft) {\n <p class=\"pl-muted\">Choose a location on the left, or add a new one.</p>\n } @else {\n <div class=\"pl-form-head\">\n <h2>{{ selectedId ? draft.name : 'New location' }}</h2>\n <div class=\"pl-actions\">\n @if (selectedId) { <button type=\"button\" class=\"pl-btn pl-danger\" (click)=\"remove()\">Delete</button> }\n <button type=\"button\" class=\"pl-btn\" (click)=\"close()\">Close</button>\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" [disabled]=\"saving\" (click)=\"save()\" data-testid=\"save-location\">{{ saving ? 'Saving\u2026' : 'Save' }}</button>\n </div>\n </div>\n\n @if (selectedSite && !selectedSite.detailsOk) {\n <div class=\"pl-notice\" data-testid=\"placeholder-notice\">Details are still placeholders \u2014 fill in <strong>{{ selectedSite.missing.join(', ') }}</strong> before this site can be enabled for pickup.</div>\n }\n @if (formError) { <div class=\"pl-error\" role=\"alert\" data-testid=\"form-error\">{{ formError }}</div> }\n\n <div class=\"pl-grid\">\n <label class=\"pl-f\">Name <input class=\"pl-input\" [(ngModel)]=\"draft.name\" data-testid=\"f-name\" /></label>\n <label class=\"pl-f pl-check\"><input type=\"checkbox\" [(ngModel)]=\"draft.pickupEnabled\" data-testid=\"f-enabled\" /> A courier may collect here (pickup enabled)</label>\n <label class=\"pl-f pl-wide\">Street address <input class=\"pl-input\" [(ngModel)]=\"draft.street\" data-testid=\"f-street\" /></label>\n <label class=\"pl-f\">State\n <select class=\"pl-input\" [(ngModel)]=\"draft.state\" (ngModelChange)=\"onStateChange()\" data-testid=\"f-state\">\n <option value=\"\">Choose\u2026</option>\n @for (o of stateOptions; track o.value) { <option [value]=\"o.value\">{{ o.label }}</option> }\n </select>\n </label>\n <label class=\"pl-f\">LGA\n <select class=\"pl-input\" [(ngModel)]=\"draft.lga\">\n <option value=\"\">\u2014</option>\n @for (o of lgaOptions; track o.value) { <option [value]=\"o.value\">{{ o.label }}</option> }\n </select>\n </label>\n <label class=\"pl-f\">City / town <input class=\"pl-input\" [(ngModel)]=\"draft.city\" data-testid=\"f-city\" /></label>\n <label class=\"pl-f\">Landmark <input class=\"pl-input\" [(ngModel)]=\"draft.landmark\" /></label>\n <label class=\"pl-f\">Phone <input class=\"pl-input\" [(ngModel)]=\"draft.phone\" data-testid=\"f-phone\" /></label>\n <label class=\"pl-f\">Contact name <input class=\"pl-input\" [(ngModel)]=\"draft.contactName\" /></label>\n <label class=\"pl-f\">Contact email <input class=\"pl-input\" type=\"email\" [(ngModel)]=\"draft.contactEmail\" /></label>\n <label class=\"pl-f\">Courier can collect <input class=\"pl-input\" placeholder=\"Mon\u2013Sat 9am\u20135pm\" [(ngModel)]=\"draft.openingHours\" data-testid=\"f-hours\" /></label>\n <label class=\"pl-f pl-wide\">Note for the rider <input class=\"pl-input\" placeholder=\"Gate B, ask for dispatch\u2026\" [(ngModel)]=\"draft.pickupNote\" /></label>\n <label class=\"pl-f\">Priority <input class=\"pl-input\" type=\"number\" [(ngModel)]=\"draft.priority\" /></label>\n <label class=\"pl-f\">GIG station\n <select class=\"pl-input\" [(ngModel)]=\"gigStation\" data-testid=\"f-station\">\n <option value=\"\">Automatic</option>\n @for (st of stations; track st.id) { <option [value]=\"st.providerCode\">{{ st.providerName }}{{ st.isPreferred ? ' (preferred)' : '' }}</option> }\n </select>\n </label>\n </div>\n\n @if (selectedSite) {\n <div class=\"pl-stock\">\n Stock held here: <strong>{{ selectedSite.stock.products }}</strong> product(s), <strong>{{ selectedSite.stock.units }}</strong> unit(s).\n <button type=\"button\" class=\"pl-link\" (click)=\"tab = 'inventory'; moveFrom = selectedId || ''; loadMoveRows()\">Manage stock \u2192</button>\n </div>\n @for (p of selectedSite.providers | keyvalue; track p.key) {\n <div class=\"pl-provider\" [class.ok]=\"p.value.ok\">{{ $any(p.key).toUpperCase() }}: {{ p.value.ok ? '\u2713 can collect here' : ('\u26A0 ' + (p.value.reason || 'not available')) }}</div>\n }\n }\n\n @if (selectedId || draft.name) {\n <h3 class=\"pl-h3\">Ships orders going to\u2026</h3>\n <x-state-multiselect [zones]=\"zones\" [(selected)]=\"draftStates\"></x-state-multiselect>\n <p class=\"pl-pending\" data-testid=\"pending-summary\">{{ pendingText || 'No changes pending.' }}</p>\n }\n }\n </section>\n </div>\n }\n\n <!-- \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Coverage table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (tab === 'coverage') {\n <div class=\"pl-cov-bar\">\n <select class=\"pl-input\" [(ngModel)]=\"coverageZone\" data-testid=\"cov-zone\">\n <option value=\"\">All zones</option>\n @for (z of coverage?.zones; track z.code) { <option [value]=\"z.code\">{{ z.name }}</option> }\n </select>\n <label class=\"pl-check\"><input type=\"checkbox\" [(ngModel)]=\"coverageAttention\" data-testid=\"cov-attention\" /> Needs attention only</label>\n <span class=\"pl-grow\"></span>\n @if (coverageSelected.size) {\n <span class=\"pl-muted\">{{ coverageSelected.size }} selected \u2192</span>\n <select class=\"pl-input\" [(ngModel)]=\"bulkSite\" data-testid=\"cov-bulk-site\">\n <option value=\"\">Choose a location\u2026</option>\n @for (s of coverage?.sites; track s.id) { @if (s.state || s.pickupEnabled) { <option [value]=\"s.id\">{{ s.name }}</option> } }\n </select>\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" [disabled]=\"!bulkSite\" (click)=\"assignSelected(bulkSite)\" data-testid=\"cov-assign\">Assign</button>\n <button type=\"button\" class=\"pl-btn\" (click)=\"assignSelected(null)\" data-testid=\"cov-unassign\">Unassign</button>\n }\n </div>\n <table class=\"pl-table\" data-testid=\"coverage-table\">\n <thead><tr><th></th><th>State</th><th>Zone</th><th>Stock site in state</th><th>Ships from</th><th>Ready?</th></tr></thead>\n <tbody>\n @for (r of coverageRows; track r.state) {\n <tr [class.is-attn]=\"r.attention\">\n <td><input type=\"checkbox\" [checked]=\"coverageSelected.has(r.state)\" (change)=\"toggleRow(r.state)\" [attr.data-testid]=\"'cov-row-' + r.state\" /></td>\n <td>{{ r.state }}</td>\n <td>{{ r.zone }}</td>\n <td>{{ r.sitesInState?.join(', ') || '\u2014' }}</td>\n <td>\n <select class=\"pl-input\" [ngModel]=\"r.stockLocationId || ''\" (ngModelChange)=\"assignOne(r.state, $event)\" [attr.data-testid]=\"'cov-site-' + r.state\">\n <option value=\"\">\u2014 none \u2014</option>\n @for (s of coverage?.sites; track s.id) { @if (s.state || s.pickupEnabled || s.id === r.stockLocationId) { <option [value]=\"s.id\">{{ s.name }}</option> } }\n </select>\n </td>\n <td>{{ !r.stockLocationId ? '\u2014 unassigned' : r.ready ? '\u2713' : '\u26A0 not ready' }}</td>\n </tr>\n }\n </tbody>\n </table>\n }\n\n <!-- \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Stock & inventory \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (tab === 'inventory') {\n <div class=\"pl-inv\">\n <section class=\"pl-card\">\n <h3 class=\"pl-h3\">Move stock between locations</h3>\n <div class=\"pl-row\">\n <label class=\"pl-f\">From\n <select class=\"pl-input\" [(ngModel)]=\"moveFrom\" (ngModelChange)=\"loadMoveRows()\" data-testid=\"move-from\">\n <option value=\"\">Choose a location\u2026</option>\n @for (s of coverage?.sites; track s.id) { @if (s.stock.units > 0) { <option [value]=\"s.id\">{{ s.name }} ({{ s.stock.units }} units)</option> } }\n </select>\n </label>\n </div>\n @if (moveLoading) { <p class=\"pl-muted\">Loading stock\u2026</p> }\n @if (moveRows.length) {\n <table class=\"pl-table\" data-testid=\"move-table\">\n <thead><tr><th><input type=\"checkbox\" (change)=\"toggleAllMove($any($event.target).checked)\" aria-label=\"Select all\" /></th><th>SKU</th><th>Available</th><th>Reserved (stays)</th></tr></thead>\n <tbody>\n @for (r of moveRows; track r.id) {\n <tr><td><input type=\"checkbox\" [(ngModel)]=\"r.checked\" /></td><td>{{ r.sku }}</td><td>{{ r.available }}</td><td>{{ r.reserved }}</td></tr>\n }\n </tbody>\n </table>\n <div class=\"pl-row\">\n <label class=\"pl-f\">Move to\n <select class=\"pl-input\" [(ngModel)]=\"moveTo\" data-testid=\"move-to\">\n <option value=\"\">Choose a location\u2026</option>\n @for (s of coverage?.sites; track s.id) { @if (s.id !== moveFrom && (s.state || s.stock.units > 0 || s.pickupEnabled)) { <option [value]=\"s.id\">{{ s.name }}</option> } }\n </select>\n </label>\n <button type=\"button\" class=\"pl-link\" (click)=\"showNewLoc = !showNewLoc\" data-testid=\"new-location-toggle\">+ New location</button>\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" [disabled]=\"!moveSelected || !moveTo || moving\" (click)=\"moveStock()\" data-testid=\"move-submit\">\n {{ moving ? 'Moving\u2026' : 'Move ' + moveSelected + ' selected' }}\n </button>\n </div>\n @if (showNewLoc) {\n <div class=\"pl-inline-new\" data-testid=\"new-location-form\">\n <input class=\"pl-input\" placeholder=\"Name\" [(ngModel)]=\"newLoc.name\" data-testid=\"nl-name\" />\n <select class=\"pl-input\" [(ngModel)]=\"newLoc.state\" data-testid=\"nl-state\">\n <option value=\"\">State\u2026</option>\n @for (o of stateOptions; track o.value) { <option [value]=\"o.value\">{{ o.label }}</option> }\n </select>\n <input class=\"pl-input\" placeholder=\"City (optional)\" [(ngModel)]=\"newLoc.city\" />\n <button type=\"button\" class=\"pl-btn\" (click)=\"createInlineLocation()\" data-testid=\"nl-create\">Create</button>\n <span class=\"pl-muted\">Add pickup details later under \u201CBy location\u201D.</span>\n </div>\n }\n @if (moveResult) {\n <p class=\"pl-ok\" data-testid=\"move-result\">Moved {{ moveResult.units }} unit(s) across {{ moveResult.moved }} row(s){{ moveResult.skipped ? '; ' + moveResult.skipped + ' skipped' : '' }}.</p>\n }\n } @else if (moveFrom && !moveLoading) {\n <p class=\"pl-muted\">That location has no available stock to move.</p>\n }\n </section>\n\n <section class=\"pl-card\">\n <h3 class=\"pl-h3\">Import stock</h3>\n <p class=\"pl-muted\">One row per line: <code>sku, location, quantity</code>. <a [href]=\"importTemplate\" download=\"stock-import-template.csv\">Download a template</a>.</p>\n <textarea class=\"pl-input pl-textarea\" rows=\"6\" placeholder=\"sku,location,quantity\" [(ngModel)]=\"importText\" data-testid=\"import-text\"></textarea>\n <div class=\"pl-row\">\n <input type=\"file\" accept=\".csv,.txt,text/csv\" (change)=\"onImportFile($event)\" />\n <label class=\"pl-check\"><input type=\"radio\" name=\"imode\" value=\"set\" [(ngModel)]=\"importMode\" /> Set quantity</label>\n <label class=\"pl-check\"><input type=\"radio\" name=\"imode\" value=\"add\" [(ngModel)]=\"importMode\" /> Add to quantity</label>\n <button type=\"button\" class=\"pl-btn\" [disabled]=\"importing || !importText.trim()\" (click)=\"previewImport()\" data-testid=\"import-preview\">Preview</button>\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" [disabled]=\"importing || !canApplyImport\" (click)=\"applyImport()\" data-testid=\"import-apply\">Apply</button>\n </div>\n @if (importReport) {\n <div class=\"pl-report\" data-testid=\"import-report\">\n <p>{{ importReport.dryRun ? 'Preview' : 'Imported' }}: <strong>{{ importReport.applied }}</strong> of {{ importReport.rows }} row(s) OK.</p>\n @if (importReport.unknownSkus?.length) { <p class=\"pl-error\">Unknown SKUs: {{ importReport.unknownSkus.join(', ') }}</p> }\n @if (importReport.invalid?.length) { <p class=\"pl-error\">Problems: @for (i of importReport.invalid; track i.row) { row {{ i.row }} \u2014 {{ i.reason }}; }</p> }\n @if (importReport.unknownLocations?.length) {\n <p class=\"pl-error\">These locations don\u2019t exist yet \u2014 pick a state to create them:</p>\n @for (n of importReport.unknownLocations; track n) {\n <div class=\"pl-row\"><span>{{ n }}</span>\n <select class=\"pl-input\" [(ngModel)]=\"importNewStates[n]\" (ngModelChange)=\"previewImport()\" [attr.data-testid]=\"'import-newloc-' + n\">\n <option value=\"\">State\u2026</option>\n @for (o of stateOptions; track o.value) { <option [value]=\"o.value\">{{ o.label }}</option> }\n </select>\n </div>\n }\n }\n @if (importReport.createdLocations?.length) { <p class=\"pl-muted\">Will create: {{ importReport.createdLocations.join(', ') }}.</p> }\n </div>\n }\n </section>\n </div>\n }\n}\n", styles: [".x-page-head{margin-bottom:16px}.x-page-title{font-size:24px;font-weight:800;color:var(--color-text)}.x-page-subtitle{font-size:13.5px;color:var(--color-text-muted);margin-top:2px}.pl-muted{color:var(--color-text-muted);font-size:13px}.pl-ok{color:var(--color-success, #1a7f37);font-weight:600}.pl-error{color:var(--color-danger, #c0362c);font-size:13px}.pl-grow{flex:1}.pl-h3{margin:18px 0 8px;font-size:14px;font-weight:800}.pl-health{display:flex;align-items:center;gap:10px;padding:10px 14px;margin-bottom:14px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);font-size:13.5px}.pl-health .pl-dot{width:10px;height:10px;border-radius:50%;background:#1a7f37;flex:none}.pl-health.is-bad{border-color:#c0362c;background:color-mix(in srgb,#c0362c 8%,transparent)}.pl-health.is-bad .pl-dot{background:#c0362c}.pl-health-text{flex:1}.pl-banner,.pl-notice{padding:10px 14px;margin-bottom:14px;border-radius:var(--radius-md, 8px);background:color-mix(in srgb,#f59e0b 14%,transparent);border:1px solid color-mix(in srgb,#f59e0b 45%,transparent);font-size:13px}.pl-tabs{display:flex;gap:6px;margin-bottom:16px;border-bottom:1px solid var(--color-border)}.pl-tab{appearance:none;background:transparent;border:0;border-bottom:2px solid transparent;padding:8px 12px;font-size:13.5px;font-weight:600;color:var(--color-text-muted);cursor:pointer}.pl-tab.is-active{color:var(--color-text);border-bottom-color:var(--color-brand)}.pl-btn{border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:6px 14px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted);white-space:nowrap}.pl-btn:disabled{opacity:.5;cursor:default}.pl-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover)}.pl-danger{color:var(--color-danger, #c0362c)}.pl-link{appearance:none;background:none;border:0;padding:4px 0;color:var(--color-accent-hover, #0b3a82);font-weight:700;font-size:12.5px;cursor:pointer;text-align:left}.pl-input{width:100%;padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px}.pl-textarea{font-family:ui-monospace,monospace}.pl-split{display:grid;grid-template-columns:290px 1fr;gap:20px;align-items:start}@media(max-width:900px){.pl-split{grid-template-columns:1fr}}.pl-list{display:flex;flex-direction:column;gap:6px}.pl-list-head{display:flex;flex-direction:column;gap:8px;margin-bottom:4px}.pl-site{display:flex;flex-direction:column;gap:2px;text-align:left;padding:9px 12px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;cursor:pointer;font:inherit}.pl-site.is-active{border-color:var(--color-brand);box-shadow:0 0 0 2px color-mix(in srgb,var(--color-brand, #0b3a82) 18%,transparent)}.pl-site-name{font-weight:700;font-size:13.5px}.pl-site-meta{font-size:12px;color:var(--color-text-muted)}.pl-status.ok{color:#1a7f37}.pl-status.warn{color:#b45309}.pl-showall{font-size:12px;color:var(--color-text-muted);display:flex;gap:6px;align-items:center}.pl-form{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:16px;min-height:120px}.pl-form-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:12px}.pl-form-head h2{margin:0;font-size:17px}.pl-actions{display:flex;gap:8px}.pl-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:12px 14px}.pl-f{display:flex;flex-direction:column;gap:4px;font-size:12.5px;font-weight:600;color:var(--color-text-muted)}.pl-f.pl-wide{grid-column:1/-1}.pl-check{display:flex;flex-direction:row;align-items:center;gap:8px;font-size:13px;font-weight:600}.pl-stock{margin-top:14px;font-size:13px}.pl-provider{font-size:12.5px;color:#b45309;margin-top:4px}.pl-provider.ok{color:#1a7f37}.pl-pending{margin:12px 0 0;font-size:13px;padding:8px 12px;border-radius:var(--radius-md, 8px);background:color-mix(in srgb,var(--color-brand, #0b3a82) 7%,transparent)}.pl-cov-bar,.pl-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin-bottom:12px}.pl-cov-bar .pl-input,.pl-row .pl-input{width:auto;min-width:160px}.pl-table{width:100%;border-collapse:collapse;font-size:13px}.pl-table th,.pl-table td{padding:6px 10px;border-bottom:1px solid var(--color-border);text-align:left}.pl-table tr.is-attn td:first-child+td{color:#b45309}.pl-inv{display:grid;gap:20px;grid-template-columns:repeat(auto-fit,minmax(380px,1fr));align-items:start}.pl-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:16px}.pl-inline-new{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin:8px 0;padding:10px;border:1px dashed var(--color-border);border-radius:var(--radius-md, 8px)}.pl-inline-new .pl-input{width:auto;min-width:140px}.pl-report{margin-top:12px;font-size:13px}\n"], dependencies: [{ kind: "directive", type: i1.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i1.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i1.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i1.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i1.RadioControlValueAccessor, selector: "input[type=radio][formControlName],input[type=radio][formControl],input[type=radio][ngModel]", inputs: ["name", "formControlName", "value"] }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: StateMultiselectComponent, selector: "x-state-multiselect", inputs: ["zones", "selected"], outputs: ["selectedChange"] }, { kind: "pipe", type: i3.KeyValuePipe, name: "keyvalue" }] }); }
607
+ }
608
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: PickupLocationsComponent, decorators: [{
609
+ type: Component,
610
+ args: [{ standalone: false, selector: 'x-pickup-locations', template: "<div class=\"x-page-head\">\n <div class=\"x-page-title\">Pickup locations</div>\n <div class=\"x-page-subtitle\">\n The addresses a courier collects parcels from. Each is also a stock location \u2014 choose which states it ships, and where your stock is held.\n </div>\n</div>\n\n@if (health) {\n <div class=\"pl-health\" [class.is-bad]=\"health.status !== 'healthy'\" data-testid=\"delivery-health\">\n <span class=\"pl-dot\"></span>\n <div class=\"pl-health-text\">\n <strong>{{ healthText }}</strong>\n @if (health.waitingBookings) {\n <span class=\"pl-muted\"> {{ health.waitingBookings }} booking(s) waiting.</span>\n }\n @if (health.circuitOpen) {\n <span class=\"pl-muted\"> Customers currently see \u201Cdelivery unavailable\u201D.</span>\n }\n </div>\n <button type=\"button\" class=\"pl-btn\" (click)=\"syncStations()\" data-testid=\"sync-stations\">Sync carrier stations</button>\n </div>\n}\n\n<nav class=\"pl-tabs\">\n <button type=\"button\" class=\"pl-tab\" [class.is-active]=\"tab === 'locations'\" (click)=\"tab = 'locations'\" data-testid=\"tab-locations\">By location</button>\n <button type=\"button\" class=\"pl-tab\" [class.is-active]=\"tab === 'coverage'\" (click)=\"tab = 'coverage'\" data-testid=\"tab-coverage\">Coverage table</button>\n <button type=\"button\" class=\"pl-tab\" [class.is-active]=\"tab === 'inventory'\" (click)=\"tab = 'inventory'\" data-testid=\"tab-inventory\">Stock &amp; inventory</button>\n</nav>\n\n@if (loading) {\n <p class=\"pl-muted\">Loading\u2026</p>\n} @else {\n @if (coverage?.sitesHoldingStockNotReady?.length) {\n <div class=\"pl-banner\" data-testid=\"not-ready-banner\">\n \u26A0 {{ coverage.sitesHoldingStockNotReady.join(', ') }} hold{{ coverage.sitesHoldingStockNotReady.length > 1 ? '' : 's' }} stock but\n {{ coverage.sitesHoldingStockNotReady.length > 1 ? 'aren\u2019t' : 'isn\u2019t' }} ready for pickup \u2014 orders for those states ship from other sites.\n </div>\n }\n\n <!-- \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 By location \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (tab === 'locations') {\n <div class=\"pl-split\">\n <aside class=\"pl-list\">\n <div class=\"pl-list-head\">\n <input class=\"pl-input\" type=\"search\" placeholder=\"Search locations\u2026\" [(ngModel)]=\"search\" data-testid=\"location-search\" />\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" (click)=\"newSite()\" data-testid=\"add-location\">+ Add location</button>\n </div>\n @for (s of sites; track s.id) {\n <button type=\"button\" class=\"pl-site\" [class.is-active]=\"selectedId === s.id\" (click)=\"select(s)\" [attr.data-testid]=\"'site-' + s.name\">\n <span class=\"pl-site-name\">\n <span class=\"pl-status\" [class.ok]=\"s.ready\" [class.warn]=\"!s.ready\" [title]=\"s.ready ? 'Ready' : (s.pickupEnabled ? 'Needs details' : 'Pickup not enabled')\">{{ s.ready ? '\u2713' : (s.pickupEnabled ? '\u26A0' : '\u23F8') }}</span>\n {{ s.name }}\n </span>\n <span class=\"pl-site-meta\">\n {{ s.shipsTo.length }} states \u00B7 {{ s.stock.units ? (s.stock.products + ' products in stock') : 'no stock yet' }}\n </span>\n </button>\n } @empty {\n <p class=\"pl-muted\">No locations match.</p>\n }\n @if (hiddenSites > 0 || showAll) {\n <label class=\"pl-showall\"><input type=\"checkbox\" [(ngModel)]=\"showAll\" /> Show all {{ coverage?.sites?.length }} stock locations</label>\n }\n <button type=\"button\" class=\"pl-link\" (click)=\"tab = 'coverage'\">Coverage table \u2192</button>\n </aside>\n\n <section class=\"pl-form\" data-testid=\"location-form\">\n @if (!draft) {\n <p class=\"pl-muted\">Choose a location on the left, or add a new one.</p>\n } @else {\n <div class=\"pl-form-head\">\n <h2>{{ selectedId ? draft.name : 'New location' }}</h2>\n <div class=\"pl-actions\">\n @if (selectedId) { <button type=\"button\" class=\"pl-btn pl-danger\" (click)=\"remove()\">Delete</button> }\n <button type=\"button\" class=\"pl-btn\" (click)=\"close()\">Close</button>\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" [disabled]=\"saving\" (click)=\"save()\" data-testid=\"save-location\">{{ saving ? 'Saving\u2026' : 'Save' }}</button>\n </div>\n </div>\n\n @if (selectedSite && !selectedSite.detailsOk) {\n <div class=\"pl-notice\" data-testid=\"placeholder-notice\">Details are still placeholders \u2014 fill in <strong>{{ selectedSite.missing.join(', ') }}</strong> before this site can be enabled for pickup.</div>\n }\n @if (formError) { <div class=\"pl-error\" role=\"alert\" data-testid=\"form-error\">{{ formError }}</div> }\n\n <div class=\"pl-grid\">\n <label class=\"pl-f\">Name <input class=\"pl-input\" [(ngModel)]=\"draft.name\" data-testid=\"f-name\" /></label>\n <label class=\"pl-f pl-check\"><input type=\"checkbox\" [(ngModel)]=\"draft.pickupEnabled\" data-testid=\"f-enabled\" /> A courier may collect here (pickup enabled)</label>\n <label class=\"pl-f pl-wide\">Street address <input class=\"pl-input\" [(ngModel)]=\"draft.street\" data-testid=\"f-street\" /></label>\n <label class=\"pl-f\">State\n <select class=\"pl-input\" [(ngModel)]=\"draft.state\" (ngModelChange)=\"onStateChange()\" data-testid=\"f-state\">\n <option value=\"\">Choose\u2026</option>\n @for (o of stateOptions; track o.value) { <option [value]=\"o.value\">{{ o.label }}</option> }\n </select>\n </label>\n <label class=\"pl-f\">LGA\n <select class=\"pl-input\" [(ngModel)]=\"draft.lga\">\n <option value=\"\">\u2014</option>\n @for (o of lgaOptions; track o.value) { <option [value]=\"o.value\">{{ o.label }}</option> }\n </select>\n </label>\n <label class=\"pl-f\">City / town <input class=\"pl-input\" [(ngModel)]=\"draft.city\" data-testid=\"f-city\" /></label>\n <label class=\"pl-f\">Landmark <input class=\"pl-input\" [(ngModel)]=\"draft.landmark\" /></label>\n <label class=\"pl-f\">Phone <input class=\"pl-input\" [(ngModel)]=\"draft.phone\" data-testid=\"f-phone\" /></label>\n <label class=\"pl-f\">Contact name <input class=\"pl-input\" [(ngModel)]=\"draft.contactName\" /></label>\n <label class=\"pl-f\">Contact email <input class=\"pl-input\" type=\"email\" [(ngModel)]=\"draft.contactEmail\" /></label>\n <label class=\"pl-f\">Courier can collect <input class=\"pl-input\" placeholder=\"Mon\u2013Sat 9am\u20135pm\" [(ngModel)]=\"draft.openingHours\" data-testid=\"f-hours\" /></label>\n <label class=\"pl-f pl-wide\">Note for the rider <input class=\"pl-input\" placeholder=\"Gate B, ask for dispatch\u2026\" [(ngModel)]=\"draft.pickupNote\" /></label>\n <label class=\"pl-f\">Priority <input class=\"pl-input\" type=\"number\" [(ngModel)]=\"draft.priority\" /></label>\n <label class=\"pl-f\">GIG station\n <select class=\"pl-input\" [(ngModel)]=\"gigStation\" data-testid=\"f-station\">\n <option value=\"\">Automatic</option>\n @for (st of stations; track st.id) { <option [value]=\"st.providerCode\">{{ st.providerName }}{{ st.isPreferred ? ' (preferred)' : '' }}</option> }\n </select>\n </label>\n </div>\n\n @if (selectedSite) {\n <div class=\"pl-stock\">\n Stock held here: <strong>{{ selectedSite.stock.products }}</strong> product(s), <strong>{{ selectedSite.stock.units }}</strong> unit(s).\n <button type=\"button\" class=\"pl-link\" (click)=\"tab = 'inventory'; moveFrom = selectedId || ''; loadMoveRows()\">Manage stock \u2192</button>\n </div>\n @for (p of selectedSite.providers | keyvalue; track p.key) {\n <div class=\"pl-provider\" [class.ok]=\"p.value.ok\">{{ $any(p.key).toUpperCase() }}: {{ p.value.ok ? '\u2713 can collect here' : ('\u26A0 ' + (p.value.reason || 'not available')) }}</div>\n }\n }\n\n @if (selectedId || draft.name) {\n <h3 class=\"pl-h3\">Ships orders going to\u2026</h3>\n <x-state-multiselect [zones]=\"zones\" [(selected)]=\"draftStates\"></x-state-multiselect>\n <p class=\"pl-pending\" data-testid=\"pending-summary\">{{ pendingText || 'No changes pending.' }}</p>\n }\n }\n </section>\n </div>\n }\n\n <!-- \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Coverage table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (tab === 'coverage') {\n <div class=\"pl-cov-bar\">\n <select class=\"pl-input\" [(ngModel)]=\"coverageZone\" data-testid=\"cov-zone\">\n <option value=\"\">All zones</option>\n @for (z of coverage?.zones; track z.code) { <option [value]=\"z.code\">{{ z.name }}</option> }\n </select>\n <label class=\"pl-check\"><input type=\"checkbox\" [(ngModel)]=\"coverageAttention\" data-testid=\"cov-attention\" /> Needs attention only</label>\n <span class=\"pl-grow\"></span>\n @if (coverageSelected.size) {\n <span class=\"pl-muted\">{{ coverageSelected.size }} selected \u2192</span>\n <select class=\"pl-input\" [(ngModel)]=\"bulkSite\" data-testid=\"cov-bulk-site\">\n <option value=\"\">Choose a location\u2026</option>\n @for (s of coverage?.sites; track s.id) { @if (s.state || s.pickupEnabled) { <option [value]=\"s.id\">{{ s.name }}</option> } }\n </select>\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" [disabled]=\"!bulkSite\" (click)=\"assignSelected(bulkSite)\" data-testid=\"cov-assign\">Assign</button>\n <button type=\"button\" class=\"pl-btn\" (click)=\"assignSelected(null)\" data-testid=\"cov-unassign\">Unassign</button>\n }\n </div>\n <table class=\"pl-table\" data-testid=\"coverage-table\">\n <thead><tr><th></th><th>State</th><th>Zone</th><th>Stock site in state</th><th>Ships from</th><th>Ready?</th></tr></thead>\n <tbody>\n @for (r of coverageRows; track r.state) {\n <tr [class.is-attn]=\"r.attention\">\n <td><input type=\"checkbox\" [checked]=\"coverageSelected.has(r.state)\" (change)=\"toggleRow(r.state)\" [attr.data-testid]=\"'cov-row-' + r.state\" /></td>\n <td>{{ r.state }}</td>\n <td>{{ r.zone }}</td>\n <td>{{ r.sitesInState?.join(', ') || '\u2014' }}</td>\n <td>\n <select class=\"pl-input\" [ngModel]=\"r.stockLocationId || ''\" (ngModelChange)=\"assignOne(r.state, $event)\" [attr.data-testid]=\"'cov-site-' + r.state\">\n <option value=\"\">\u2014 none \u2014</option>\n @for (s of coverage?.sites; track s.id) { @if (s.state || s.pickupEnabled || s.id === r.stockLocationId) { <option [value]=\"s.id\">{{ s.name }}</option> } }\n </select>\n </td>\n <td>{{ !r.stockLocationId ? '\u2014 unassigned' : r.ready ? '\u2713' : '\u26A0 not ready' }}</td>\n </tr>\n }\n </tbody>\n </table>\n }\n\n <!-- \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Stock & inventory \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (tab === 'inventory') {\n <div class=\"pl-inv\">\n <section class=\"pl-card\">\n <h3 class=\"pl-h3\">Move stock between locations</h3>\n <div class=\"pl-row\">\n <label class=\"pl-f\">From\n <select class=\"pl-input\" [(ngModel)]=\"moveFrom\" (ngModelChange)=\"loadMoveRows()\" data-testid=\"move-from\">\n <option value=\"\">Choose a location\u2026</option>\n @for (s of coverage?.sites; track s.id) { @if (s.stock.units > 0) { <option [value]=\"s.id\">{{ s.name }} ({{ s.stock.units }} units)</option> } }\n </select>\n </label>\n </div>\n @if (moveLoading) { <p class=\"pl-muted\">Loading stock\u2026</p> }\n @if (moveRows.length) {\n <table class=\"pl-table\" data-testid=\"move-table\">\n <thead><tr><th><input type=\"checkbox\" (change)=\"toggleAllMove($any($event.target).checked)\" aria-label=\"Select all\" /></th><th>SKU</th><th>Available</th><th>Reserved (stays)</th></tr></thead>\n <tbody>\n @for (r of moveRows; track r.id) {\n <tr><td><input type=\"checkbox\" [(ngModel)]=\"r.checked\" /></td><td>{{ r.sku }}</td><td>{{ r.available }}</td><td>{{ r.reserved }}</td></tr>\n }\n </tbody>\n </table>\n <div class=\"pl-row\">\n <label class=\"pl-f\">Move to\n <select class=\"pl-input\" [(ngModel)]=\"moveTo\" data-testid=\"move-to\">\n <option value=\"\">Choose a location\u2026</option>\n @for (s of coverage?.sites; track s.id) { @if (s.id !== moveFrom && (s.state || s.stock.units > 0 || s.pickupEnabled)) { <option [value]=\"s.id\">{{ s.name }}</option> } }\n </select>\n </label>\n <button type=\"button\" class=\"pl-link\" (click)=\"showNewLoc = !showNewLoc\" data-testid=\"new-location-toggle\">+ New location</button>\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" [disabled]=\"!moveSelected || !moveTo || moving\" (click)=\"moveStock()\" data-testid=\"move-submit\">\n {{ moving ? 'Moving\u2026' : 'Move ' + moveSelected + ' selected' }}\n </button>\n </div>\n @if (showNewLoc) {\n <div class=\"pl-inline-new\" data-testid=\"new-location-form\">\n <input class=\"pl-input\" placeholder=\"Name\" [(ngModel)]=\"newLoc.name\" data-testid=\"nl-name\" />\n <select class=\"pl-input\" [(ngModel)]=\"newLoc.state\" data-testid=\"nl-state\">\n <option value=\"\">State\u2026</option>\n @for (o of stateOptions; track o.value) { <option [value]=\"o.value\">{{ o.label }}</option> }\n </select>\n <input class=\"pl-input\" placeholder=\"City (optional)\" [(ngModel)]=\"newLoc.city\" />\n <button type=\"button\" class=\"pl-btn\" (click)=\"createInlineLocation()\" data-testid=\"nl-create\">Create</button>\n <span class=\"pl-muted\">Add pickup details later under \u201CBy location\u201D.</span>\n </div>\n }\n @if (moveResult) {\n <p class=\"pl-ok\" data-testid=\"move-result\">Moved {{ moveResult.units }} unit(s) across {{ moveResult.moved }} row(s){{ moveResult.skipped ? '; ' + moveResult.skipped + ' skipped' : '' }}.</p>\n }\n } @else if (moveFrom && !moveLoading) {\n <p class=\"pl-muted\">That location has no available stock to move.</p>\n }\n </section>\n\n <section class=\"pl-card\">\n <h3 class=\"pl-h3\">Import stock</h3>\n <p class=\"pl-muted\">One row per line: <code>sku, location, quantity</code>. <a [href]=\"importTemplate\" download=\"stock-import-template.csv\">Download a template</a>.</p>\n <textarea class=\"pl-input pl-textarea\" rows=\"6\" placeholder=\"sku,location,quantity\" [(ngModel)]=\"importText\" data-testid=\"import-text\"></textarea>\n <div class=\"pl-row\">\n <input type=\"file\" accept=\".csv,.txt,text/csv\" (change)=\"onImportFile($event)\" />\n <label class=\"pl-check\"><input type=\"radio\" name=\"imode\" value=\"set\" [(ngModel)]=\"importMode\" /> Set quantity</label>\n <label class=\"pl-check\"><input type=\"radio\" name=\"imode\" value=\"add\" [(ngModel)]=\"importMode\" /> Add to quantity</label>\n <button type=\"button\" class=\"pl-btn\" [disabled]=\"importing || !importText.trim()\" (click)=\"previewImport()\" data-testid=\"import-preview\">Preview</button>\n <button type=\"button\" class=\"pl-btn pl-btn-primary\" [disabled]=\"importing || !canApplyImport\" (click)=\"applyImport()\" data-testid=\"import-apply\">Apply</button>\n </div>\n @if (importReport) {\n <div class=\"pl-report\" data-testid=\"import-report\">\n <p>{{ importReport.dryRun ? 'Preview' : 'Imported' }}: <strong>{{ importReport.applied }}</strong> of {{ importReport.rows }} row(s) OK.</p>\n @if (importReport.unknownSkus?.length) { <p class=\"pl-error\">Unknown SKUs: {{ importReport.unknownSkus.join(', ') }}</p> }\n @if (importReport.invalid?.length) { <p class=\"pl-error\">Problems: @for (i of importReport.invalid; track i.row) { row {{ i.row }} \u2014 {{ i.reason }}; }</p> }\n @if (importReport.unknownLocations?.length) {\n <p class=\"pl-error\">These locations don\u2019t exist yet \u2014 pick a state to create them:</p>\n @for (n of importReport.unknownLocations; track n) {\n <div class=\"pl-row\"><span>{{ n }}</span>\n <select class=\"pl-input\" [(ngModel)]=\"importNewStates[n]\" (ngModelChange)=\"previewImport()\" [attr.data-testid]=\"'import-newloc-' + n\">\n <option value=\"\">State\u2026</option>\n @for (o of stateOptions; track o.value) { <option [value]=\"o.value\">{{ o.label }}</option> }\n </select>\n </div>\n }\n }\n @if (importReport.createdLocations?.length) { <p class=\"pl-muted\">Will create: {{ importReport.createdLocations.join(', ') }}.</p> }\n </div>\n }\n </section>\n </div>\n }\n}\n", styles: [".x-page-head{margin-bottom:16px}.x-page-title{font-size:24px;font-weight:800;color:var(--color-text)}.x-page-subtitle{font-size:13.5px;color:var(--color-text-muted);margin-top:2px}.pl-muted{color:var(--color-text-muted);font-size:13px}.pl-ok{color:var(--color-success, #1a7f37);font-weight:600}.pl-error{color:var(--color-danger, #c0362c);font-size:13px}.pl-grow{flex:1}.pl-h3{margin:18px 0 8px;font-size:14px;font-weight:800}.pl-health{display:flex;align-items:center;gap:10px;padding:10px 14px;margin-bottom:14px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);font-size:13.5px}.pl-health .pl-dot{width:10px;height:10px;border-radius:50%;background:#1a7f37;flex:none}.pl-health.is-bad{border-color:#c0362c;background:color-mix(in srgb,#c0362c 8%,transparent)}.pl-health.is-bad .pl-dot{background:#c0362c}.pl-health-text{flex:1}.pl-banner,.pl-notice{padding:10px 14px;margin-bottom:14px;border-radius:var(--radius-md, 8px);background:color-mix(in srgb,#f59e0b 14%,transparent);border:1px solid color-mix(in srgb,#f59e0b 45%,transparent);font-size:13px}.pl-tabs{display:flex;gap:6px;margin-bottom:16px;border-bottom:1px solid var(--color-border)}.pl-tab{appearance:none;background:transparent;border:0;border-bottom:2px solid transparent;padding:8px 12px;font-size:13.5px;font-weight:600;color:var(--color-text-muted);cursor:pointer}.pl-tab.is-active{color:var(--color-text);border-bottom-color:var(--color-brand)}.pl-btn{border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:6px 14px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted);white-space:nowrap}.pl-btn:disabled{opacity:.5;cursor:default}.pl-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover)}.pl-danger{color:var(--color-danger, #c0362c)}.pl-link{appearance:none;background:none;border:0;padding:4px 0;color:var(--color-accent-hover, #0b3a82);font-weight:700;font-size:12.5px;cursor:pointer;text-align:left}.pl-input{width:100%;padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px}.pl-textarea{font-family:ui-monospace,monospace}.pl-split{display:grid;grid-template-columns:290px 1fr;gap:20px;align-items:start}@media(max-width:900px){.pl-split{grid-template-columns:1fr}}.pl-list{display:flex;flex-direction:column;gap:6px}.pl-list-head{display:flex;flex-direction:column;gap:8px;margin-bottom:4px}.pl-site{display:flex;flex-direction:column;gap:2px;text-align:left;padding:9px 12px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;cursor:pointer;font:inherit}.pl-site.is-active{border-color:var(--color-brand);box-shadow:0 0 0 2px color-mix(in srgb,var(--color-brand, #0b3a82) 18%,transparent)}.pl-site-name{font-weight:700;font-size:13.5px}.pl-site-meta{font-size:12px;color:var(--color-text-muted)}.pl-status.ok{color:#1a7f37}.pl-status.warn{color:#b45309}.pl-showall{font-size:12px;color:var(--color-text-muted);display:flex;gap:6px;align-items:center}.pl-form{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:16px;min-height:120px}.pl-form-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:12px}.pl-form-head h2{margin:0;font-size:17px}.pl-actions{display:flex;gap:8px}.pl-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:12px 14px}.pl-f{display:flex;flex-direction:column;gap:4px;font-size:12.5px;font-weight:600;color:var(--color-text-muted)}.pl-f.pl-wide{grid-column:1/-1}.pl-check{display:flex;flex-direction:row;align-items:center;gap:8px;font-size:13px;font-weight:600}.pl-stock{margin-top:14px;font-size:13px}.pl-provider{font-size:12.5px;color:#b45309;margin-top:4px}.pl-provider.ok{color:#1a7f37}.pl-pending{margin:12px 0 0;font-size:13px;padding:8px 12px;border-radius:var(--radius-md, 8px);background:color-mix(in srgb,var(--color-brand, #0b3a82) 7%,transparent)}.pl-cov-bar,.pl-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin-bottom:12px}.pl-cov-bar .pl-input,.pl-row .pl-input{width:auto;min-width:160px}.pl-table{width:100%;border-collapse:collapse;font-size:13px}.pl-table th,.pl-table td{padding:6px 10px;border-bottom:1px solid var(--color-border);text-align:left}.pl-table tr.is-attn td:first-child+td{color:#b45309}.pl-inv{display:grid;gap:20px;grid-template-columns:repeat(auto-fit,minmax(380px,1fr));align-items:start}.pl-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:16px}.pl-inline-new{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin:8px 0;padding:10px;border:1px dashed var(--color-border);border-radius:var(--radius-md, 8px)}.pl-inline-new .pl-input{width:auto;min-width:140px}.pl-report{margin-top:12px;font-size:13px}\n"] }]
611
+ }] });
612
+
613
+ class PickupLocationsModule {
614
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: PickupLocationsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
615
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.16", ngImport: i0, type: PickupLocationsModule, declarations: [PickupLocationsComponent], imports: [SharedModule,
616
+ StateMultiselectComponent, i1$1.RouterModule] }); }
617
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: PickupLocationsModule, imports: [SharedModule,
618
+ StateMultiselectComponent,
619
+ RouterModule.forChild([{ path: '', component: PickupLocationsComponent }])] }); }
620
+ }
621
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: PickupLocationsModule, decorators: [{
622
+ type: NgModule,
623
+ args: [{
624
+ declarations: [PickupLocationsComponent],
625
+ imports: [
626
+ SharedModule,
627
+ StateMultiselectComponent,
628
+ RouterModule.forChild([{ path: '', component: PickupLocationsComponent }]),
629
+ ],
630
+ }]
631
+ }] });
632
+
633
+ export { PickupLocationsModule };
634
+ //# sourceMappingURL=isaiahiroko-tilmart-ngx-apps-admin-pickup-locations.module-CKCz9CBw.mjs.map