@jsb188/mday 1.1.5 → 1.1.6

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.
package/src/utils/log.ts CHANGED
@@ -1,10 +1,31 @@
1
1
  import i18n from '@jsb188/app/i18n';
2
- import type { ColorEnum } from '@jsb188/app/types/app.d';
3
- import type { OrganizationOperationEnum } from '@jsb188/app/types/organization.d';
2
+ import type { OrganizationOperationEnum } from '../types/organization.d';
4
3
  import { formatCurrency, formatDecimal } from '@jsb188/app/utils/number';
5
- import { textWithBrackets, ucFirst } from '@jsb188/app/utils/string';
6
- import { ARABLE_ACTIVITIES_GROUPED } from '../constants/log';
7
- import type { LogTypeEnum } from '../types/log';
4
+ import { formatReferenceNumber, joinReadable, textWithBrackets, ucFirst } from '@jsb188/app/utils/string';
5
+ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
6
+ import {
7
+ ARABLE_ACTIVITIES_GROUPED,
8
+ FARMERS_MARKET_ACTIVITIES_GROUPED,
9
+ LIVESTOCK_ACTIVITIES_GROUPED,
10
+ LOG_TYPES_BY_OPERATION
11
+ } from '../constants/log';
12
+ import type { LogEntryData, LogTypeEnum, LogContentName } from '../types/log.d';
13
+
14
+ /**
15
+ * Get content type for log by activity
16
+ */
17
+
18
+ export function getLogContentName(activity: string): LogContentName {
19
+ const value = {
20
+ 'SALE_PRODUCE_ORDER': 'invoice',
21
+ 'OTHER_SALE_ORDER': 'invoice',
22
+ 'FEED_PURCHASE': 'invoice',
23
+ 'OTHER_SUPPLY_PURCHASE_ACTIVITY': 'invoice',
24
+ 'MARKET_CREDIT_RECEIPT': 'receipt',
25
+ }[activity as string] || 'log';
26
+
27
+ return value as LogContentName;
28
+ }
8
29
 
9
30
  /**
10
31
  * Map log type to a color
@@ -12,23 +33,22 @@ import type { LogTypeEnum } from '../types/log';
12
33
  * @returns The color associated with the journal type
13
34
  */
14
35
 
15
- export function getLogCategoryColor(type: LogTypeEnum): ColorEnum {
16
- let logTypeToColor;
17
-
36
+ export function getLogCategoryColor(type: LogTypeEnum) {
18
37
  // Do switch operation here
19
38
  // switch (operation) {
20
39
  // case 'ARABLE':
21
- // case 'LogEntryArable':
40
+ // case 'LogArable':
22
41
  // // ..
23
42
  // break;
24
43
  // case 'LIVESTOCK':
25
- // case 'LogEntryLivestock':
44
+ // case 'LogLivestock':
26
45
  // // ..
27
46
  // break;
28
47
  // default:
29
48
  // }
30
49
 
31
- logTypeToColor = {
50
+ const logTypeToColor = {
51
+ // #### ARABLE
32
52
  SEED: 'brown',
33
53
  PLANTING: 'amber',
34
54
  FIELD: 'lime',
@@ -37,13 +57,49 @@ export function getLogCategoryColor(type: LogTypeEnum): ColorEnum {
37
57
  SALES: 'blue',
38
58
  WATER: 'violet',
39
59
  DELETED: 'medium',
40
- } as Record<LogTypeEnum, ColorEnum>;
60
+
61
+ // #### ARABLE - Food Safety
62
+ HYGIENE: 'teal',
63
+ SANITATION: 'sky',
64
+ EQUIPMENTS: 'indigo',
65
+ BIOSECURITY: 'green',
66
+ EMPLOYEES: 'yellow',
67
+
68
+ // #### FARMERS_MARKET
69
+ MARKET_RECEIPTS: 'blue',
70
+ MARKET_OPERATIONS: 'rose',
71
+
72
+ // #### LIVESTOCK
73
+ SUPPLY_PURCHASE: 'brown',
74
+ LIVESTOCK_LIFE_CYCLE: 'amber',
75
+ LIVESTOCK_TRACKING: 'lime',
76
+ PASTURE_LAND_MANAGEMENT: 'green',
77
+ LIVESTOCK_HEALTHCARE: 'teal',
78
+ LIVESTOCK_SALE: 'blue',
79
+
80
+ // #### Merged into every operation
81
+ AI_TASK: 'slate',
82
+ } as Record<LogTypeEnum, string>;
41
83
 
42
84
  // Default to zinc if type is not found
43
85
  const color = logTypeToColor[type] || 'zinc';
44
86
  return color;
45
87
  }
46
88
 
89
+ /**
90
+ * Get all log types for the given organization operation
91
+ * @param operation - The operation of the organization
92
+ * @returns Array of log types for the operation
93
+ */
94
+
95
+ export function getLogTypesForOperation(operation: OrganizationOperationEnum, includeAITask: boolean): LogTypeEnum[] {
96
+ const logTypes = (LOG_TYPES_BY_OPERATION[operation] || []) as LogTypeEnum[];
97
+ if (includeAITask) {
98
+ return logTypes;
99
+ }
100
+ return logTypes.filter((type) => type !== 'AI_TASK');
101
+ }
102
+
47
103
  /**
48
104
  * Get log type from activity; bassed on organization's industry-based operation
49
105
  * @param operation - The operation of the organization
@@ -51,18 +107,40 @@ export function getLogCategoryColor(type: LogTypeEnum): ColorEnum {
51
107
  * @returns The log type or null if not found
52
108
  */
53
109
 
54
- export function getLogTypeFromActivity(operation: OrganizationOperationEnum | string, activity: any) {
110
+ export function getLogTypeFromActivity(operation: OrganizationOperationEnum | string, activity: any): LogTypeEnum | null {
111
+ let logGroup;
55
112
  switch (operation) {
56
113
  case 'ARABLE':
57
- case 'LogEntryArable':
58
- return ARABLE_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity))?.[0] || null;
114
+ case 'LogArable':
115
+ logGroup = ARABLE_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
116
+ break;
59
117
  case 'LIVESTOCK':
60
- case 'LogEntryLivestock':
61
- return null; // Livestock activities are not defined in this context
118
+ case 'LogLivestock':
119
+ logGroup = LIVESTOCK_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
120
+ break;
121
+ case 'FARMERS_MARKET':
122
+ case 'LogFarmersMarket':
123
+ logGroup = FARMERS_MARKET_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
124
+ break;
62
125
  default:
63
126
  console.warn('(!1) Cannot get log type from unknown operation type:', operation);
64
127
  return null;
65
128
  }
129
+
130
+ return logGroup?.[0] as LogTypeEnum || null;
131
+ }
132
+
133
+ /**
134
+ * For UI visualization, use this function to get the shortest activity text
135
+ * @param activity - The activity of the log entry
136
+ * @returns i18n text for activity
137
+ */
138
+
139
+ export function getActivityText(activity: any, tryShortForm?: boolean): string {
140
+ if (tryShortForm && i18n.has(`log.activity_short.${activity}`)) {
141
+ return i18n.t(`log.activity_short.${activity}`);
142
+ }
143
+ return i18n.t(`log.activity.${activity}`);
66
144
  }
67
145
 
68
146
  /**
@@ -82,34 +160,712 @@ export function getLogEntryTitle(d: any, isServer?: boolean, logType_?: string,
82
160
  switch (iface || __typename || __table) {
83
161
  case 'ARABLE':
84
162
  case 'logs_arable':
85
- case 'LogEntryArable': {
86
- const quantityText = [formatDecimal(md.quantity, true, true), md.unit].filter(Boolean).join(' ');
163
+ case 'LogArable': {
164
+ const quantityText = joinReadable([formatDecimal(md.quantity, true, true), md.unit], ' ', ' ');
87
165
 
88
- let cropName = ucFirst(md.crop);
166
+ let titleItem = ucFirst(md.item);
89
167
  let logSpecificText = '';
90
168
 
91
169
  if (logType === 'WATER') {
92
- logSpecificText = [md.concentration, md.concentration && md.concentrationUnit].filter(Boolean).join(' ');
93
- } else if (logType === 'SALES') {
94
- if (!cropName) {
95
- cropName = i18n.t('log.unknown_crop');
170
+ logSpecificText = joinReadable([md.concentration, md.concentration && md.concentrationUnit], ' ', ' ');
171
+ } else if (['SEED', 'SALES'].includes(logType)) {
172
+ if (!titleItem) {
173
+ titleItem = i18n.t('log.unknown_crop');
96
174
  }
97
- logSpecificText = formatCurrency(md.price, 'en-US', 'USD');
175
+ const totalPrice = (md?.values || []).reduce((sum: number, item: any) => sum + Number(item.value || 0), 0);
176
+ logSpecificText = formatCurrency(totalPrice, false);
98
177
  }
99
178
 
179
+ // console.log(md);
180
+ // console.log('titleItem', titleItem);
181
+
100
182
  return textWithBrackets(
101
- cropName,
183
+ titleItem,
102
184
  [
103
185
  logSpecificText + (logSpecificText && quantityText ? ',' : ''),
104
186
  quantityText,
105
187
  ],
106
188
  );
107
189
  }
190
+ case 'FARMERS_MARKET':
191
+ case 'logs_farmers_market':
192
+ case 'LogFarmersMarket': {
193
+ let creditsText = '';
194
+ if (Array.isArray(md.values) && md.values.length) {
195
+ creditsText = md.values.map((item: any) => {
196
+ return `${formatCurrency(item.value, false)} ${item.label}`;
197
+ }).join(', ');
198
+
199
+ const totalAmount = md.values.reduce((sum: number, item: any) => sum + Number(item.value || 0), 0);
200
+ creditsText += ` = ${i18n.t('form.total')}: ${formatCurrency(totalAmount, false)}`;
201
+ }
202
+
203
+ const voidText = isServer && md.voided ? i18n.t('form.void').toUpperCase() : '';
204
+ return `${creditsText && voidText ? '(' + voidText + ')' : voidText} ${creditsText}`.trim();
205
+ }
206
+ case 'LIVESTOCK':
108
207
  case 'logs_livestock':
109
- case 'LogEntryLivestock': {
110
- // .. live stock logs here ..
208
+ case 'LogLivestock': {
209
+ if (['SUPPLY_PURCHASE', 'LIVESTOCK_SALE'].includes(logType)) {
210
+ return joinReadable(
211
+ [
212
+ formatReferenceNumber(md?.referenceNumber),
213
+ formatCurrency((md?.values || []).reduce((sum: number, item: any) => sum + Number(item.value || 0), 0), false),
214
+ ],
215
+ ' - ',
216
+ ' - ',
217
+ );
218
+ }
219
+
220
+ if (isServer) {
221
+ let livestockText = '';
222
+ if (md.livestock) {
223
+ livestockText += 'Species: ' + ucFirst(md.livestock) + '\n';
224
+ }
225
+ if (d.livestockGroup) {
226
+ livestockText += 'Group: ' + d.livestockGroup + '\n';
227
+ }
228
+ if (Array.isArray(d.livestockIdentifiers) && d.livestockIdentifiers.length) {
229
+ livestockText += 'Animal ID(s): ' + d.livestockIdentifiers.join(', ') + '\n';
230
+ }
231
+ if (d.damIdentifier) {
232
+ livestockText += 'Dam ID: ' + d.damIdentifier + '\n';
233
+ }
234
+ return livestockText.trim();
235
+ }
236
+
237
+ return textWithBrackets(
238
+ ucFirst(md.livestock),
239
+ (d.livestockGroup ? [d.livestockGroup] : []).concat(
240
+ (d.livestockIdentifiers || []).map((id: string) => `#${id}`),
241
+ ).join(', ') + (
242
+ d.damIdentifier ? ` (Dam: #${d.damIdentifier})` : ''
243
+ ),
244
+ [' - ', ''],
245
+ );
111
246
  }
112
247
  default:
113
248
  }
114
249
  return '..';
115
250
  }
251
+
252
+ /**
253
+ * Get the text format for this log
254
+ * @param log - Log entry object from database
255
+ * @return Log in text format
256
+ */
257
+
258
+ export function getTextFormatLog(log: LogEntryData) {
259
+ const { notes } = log.details;
260
+ const title = getLogEntryTitle(log.details || {}, true);
261
+ return (title + '\n\n' + (notes + '')).trim();
262
+ }
263
+
264
+ const PRODUCE_WORDS = [
265
+ 'little gem',
266
+ 'lil gem',
267
+ 'romaine',
268
+ 'cauliflow',
269
+ 'broccoli',
270
+ 'piracicab',
271
+ 'mesclun',
272
+ 'spinach',
273
+ 'mustard green',
274
+ 'arugula',
275
+ 'kale',
276
+ 'kohlrab',
277
+ 'cabbag',
278
+ 'parsley',
279
+ 'beoc raab',
280
+ 'wasabina',
281
+ 'chervil',
282
+ 'basil',
283
+ 'artichoke',
284
+ 'romanesco',
285
+ 'zucchini',
286
+ 'zuchini',
287
+ 'potato',
288
+ 'eggplant',
289
+ 'jalapeno',
290
+ 'jalapeño',
291
+ 'carrot',
292
+ 'midnight light',
293
+ 'cilantro',
294
+ 'bennings green',
295
+ 'lettuce',
296
+ 'escarol',
297
+ 'raddish',
298
+ 'radish',
299
+ 'bean',
300
+ 'stringbean',
301
+ 'stinging kettle',
302
+ 'radicchio',
303
+ 'braci ardenti',
304
+ 'braci adenti',
305
+ 'chicory',
306
+ 'puntarelle',
307
+ 'chioggia',
308
+ 'beet',
309
+ 'thaddeus',
310
+ 'sunshine kabocha',
311
+ 'yellow star patty',
312
+ 'butternut squash',
313
+ 'butternutsquash',
314
+ 'asparagus',
315
+ 'acorn squash',
316
+ 'acornsquash',
317
+ 'delicata squash',
318
+ 'hubbard squash',
319
+ 'hubbard',
320
+ 'red kuri',
321
+ 'squash',
322
+ 'cargo pump',
323
+ 'pumpkin',
324
+ 'cucumber',
325
+ 'shiso',
326
+ 'shinto',
327
+ 'thyme',
328
+ 'rosemary',
329
+ 'di lusia',
330
+ 'di lusio',
331
+ 'treviso',
332
+ 'scallion',
333
+ 'scalion',
334
+ 'spring onion',
335
+ 'springonion',
336
+ 'onion',
337
+ 'shallot',
338
+ 'wasabi',
339
+ 'lavendar',
340
+ 'lavender',
341
+ 'anise hyssop',
342
+ 'alyssum',
343
+ 'marjoram',
344
+ 'mint',
345
+ 'sorrel',
346
+ 'tomato',
347
+ 'grapes',
348
+ 'apricot',
349
+ 'peach',
350
+ 'plum',
351
+ 'blueberr',
352
+ 'billberr',
353
+ 'blackberr',
354
+ 'raspberr',
355
+ 'cloudberr',
356
+ 'cloud berr',
357
+ 'sweet pepper',
358
+ 'bell pepper',
359
+ 'strawberr',
360
+ 'berry',
361
+
362
+ // Leave at end for backup
363
+ 'marciano',
364
+ 'spretnak',
365
+ 'newham',
366
+ 'red butter',
367
+ 'frisee',
368
+ 'cresta',
369
+ 'cardoon',
370
+ 'cynara cardunculus',
371
+ 'cardunculus',
372
+ 'butternut',
373
+ 'green gem',
374
+ 'red gem',
375
+ 'starry night',
376
+ 'benning',
377
+ 'summar savor',
378
+ 'summer savor',
379
+ 'summery savor',
380
+ 'summary savor',
381
+ 'delicata',
382
+ 'matador',
383
+ 'green curl',
384
+ 'red oak',
385
+ 'flower',
386
+ 'yellow tooth',
387
+ 'sage\\b',
388
+ 'sages\\b',
389
+ 'okra',
390
+ 'flor\\b',
391
+ 'gems\\b',
392
+ 'pump\\b',
393
+ 'cruced\\b',
394
+ 'star\\b',
395
+ 'stars\\b',
396
+ 'seed',
397
+ 'pepper',
398
+ 'chilli',
399
+ 'mix\\b',
400
+ 'chard',
401
+ 'nettle',
402
+ 'savory',
403
+ 'dino',
404
+
405
+ // log activities
406
+ // NOTE: If i18n words change, these have to change too
407
+ 'soil',
408
+ 'irrigation',
409
+ 'fertilization',
410
+ 'crop protection',
411
+ 'crop monitoring',
412
+ 'direct seed',
413
+ 'pruning',
414
+ 'trellising',
415
+ 'preparing crops',
416
+ 'crops',
417
+ 'estimating yield',
418
+ 'other harvest',
419
+ 'grading produce',
420
+ 'moving produce',
421
+ 'cold storage temperature',
422
+ 'post harvest',
423
+ 'sale',
424
+ 'water testing',
425
+ 'chlorine level',
426
+ 'field',
427
+ ];
428
+
429
+ /**
430
+ * Get the icon name from crop name by using regex
431
+ * @param crop - The name of the crop
432
+ * @param note - Additional note that may contain crop type
433
+ * @param defaultIcon - The default icon to return if no match is found
434
+ * @returns The icon name or a default icon if no match is found
435
+ */
436
+
437
+ export function getIconNameForArable(crop?: string | undefined, note?: string | null, defaultIcon?: string): string {
438
+ if (crop) {
439
+ const regex = new RegExp(`\\b(${PRODUCE_WORDS.join('|')})`, 'gi');
440
+ const match = crop.replace('-', ' ').match(regex);
441
+ if (match) {
442
+ let matchedWord;
443
+ if (match.length === 1) {
444
+ matchedWord = match[0].toLowerCase();
445
+ } else {
446
+ // If multiple matches, choose the first match from produce words
447
+ const lcMatch = match.map((m) => m.toLowerCase());
448
+ matchedWord = PRODUCE_WORDS.find((word) => lcMatch.includes(word));
449
+ }
450
+
451
+ switch (matchedWord) {
452
+ case 'little gem':
453
+ case 'lil gem':
454
+ case 'marciano':
455
+ case 'red butter':
456
+ case 'green gem':
457
+ case 'red gem':
458
+ case 'gems':
459
+ case 'spretnak':
460
+ case 'newham':
461
+ return 'vegetable-lettuce-top';
462
+ case 'lettuce':
463
+ case 'red oak':
464
+ case 'romaine':
465
+ case 'escarol':
466
+ case 'radicchio':
467
+ case 'braci ardenti':
468
+ case 'braci adenti':
469
+ case 'di lusia':
470
+ case 'di lusio':
471
+ case 'treviso':
472
+ case 'thaddeus':
473
+ case 'cruced':
474
+ return 'vegetable-lettuce';
475
+ case 'lavendar':
476
+ case 'lavender':
477
+ case 'anise hyssop':
478
+ case 'alyssum':
479
+ return 'vegetable-lavender';
480
+ case 'basil':
481
+ return 'vegetable-basil';
482
+ case 'chioggia':
483
+ case 'beet':
484
+ case 'yellow tooth':
485
+ return 'vegetable-beet';
486
+ case 'cauliflow':
487
+ case 'broccoli':
488
+ case 'piracicab':
489
+ return 'vegetable-broccoli';
490
+ case 'pumpkin':
491
+ case 'pump':
492
+ case 'cargo pump':
493
+ case 'bennings green':
494
+ case 'benning':
495
+ return 'vegetable-pumpkin';
496
+ case 'mesclun':
497
+ case 'spinach':
498
+ case 'chard':
499
+ case 'mustard green':
500
+ case 'mix':
501
+ return 'vegetable-spinach';
502
+ case 'tomato':
503
+ return 'vegetable-tomato';
504
+ case 'grapes':
505
+ return 'fruit-grapes';
506
+ case 'apricot':
507
+ case 'peach':
508
+ case 'plum':
509
+ return 'fruit-apricot';
510
+ case 'raspberr':
511
+ return 'raspberry';
512
+ case 'blackberr':
513
+ case 'cloudberr':
514
+ case 'cloud berr':
515
+ return 'fruit-cloud-berry';
516
+ case 'blueberr':
517
+ case 'billberr':
518
+ case 'berry':
519
+ return 'fruit-billberry-blackberry-blueberry';
520
+ case 'asparagus':
521
+ return 'vegetable-asparagus';
522
+ case 'sunshine kabocha':
523
+ case 'acorn squash':
524
+ case 'acornsquash':
525
+ case 'yellow star patty':
526
+ case 'sweet pepper':
527
+ case 'bell pepper':
528
+ return 'vegetable-acornsquash';
529
+ case 'strawberr':
530
+ return 'fruit-strawberry';
531
+ case 'pepper':
532
+ case 'chilli':
533
+ return 'seasoning-chilli';
534
+ case 'delicata':
535
+ case 'delicata squash':
536
+ return 'vegetable-delicata-squash';
537
+ case 'hubbard squash':
538
+ case 'hubbard':
539
+ case 'red kuri':
540
+ return 'vegetable-hubbard-squash';
541
+ case 'shinto':
542
+ case 'cucumber':
543
+ return 'vegetable-cucumber';
544
+ case 'butternut squash':
545
+ case 'butternutsquash':
546
+ case 'butternut':
547
+ case 'squash':
548
+ case 'starry night':
549
+ return 'vegetable-butternutsquash';
550
+ case 'summar savor':
551
+ case 'summer savor':
552
+ case 'summery savor':
553
+ case 'summary savor':
554
+ case 'thyme':
555
+ case 'rosemary':
556
+ case 'savory':
557
+ return 'vegetable-thyme';
558
+ case 'arugula':
559
+ case 'chicory':
560
+ case 'puntarelle':
561
+ case 'frisee':
562
+ case 'kale':
563
+ case 'dino':
564
+ case 'green curl':
565
+ return 'vegetable-arugula';
566
+ case 'parsley':
567
+ case 'beoc raab':
568
+ case 'wasabina':
569
+ case 'chervil':
570
+ return 'vegetable-parsley';
571
+ case 'carrot':
572
+ return 'vegetable-carrot';
573
+ case 'artichoke':
574
+ case 'romanesco':
575
+ case 'star':
576
+ case 'stars':
577
+ return 'vegetable-artichoke';
578
+ case 'cabbag':
579
+ return 'vegetable-cabbage';
580
+ case 'kohlrab':
581
+ return 'vegetable-kohlrabi';
582
+ case 'zucchini':
583
+ case 'zuchini':
584
+ case 'midnight light':
585
+ return 'vegetable-zucchini';
586
+ case 'potato':
587
+ return 'vegetable-potato';
588
+ case 'eggplant':
589
+ return 'vegetable-eggplant';
590
+ case 'jalapeno':
591
+ case 'jalapeño':
592
+ return 'vegetable-jalapeno';
593
+ case 'stinging kettle':
594
+ case 'nettle':
595
+ case 'cardoon':
596
+ case 'cynara cardunculus':
597
+ case 'cardunculus':
598
+ case 'cresta':
599
+ case 'shiso':
600
+ return 'vegetable-stinging-kettle';
601
+ case 'okra':
602
+ return 'vegetable-okra';
603
+ case 'sage':
604
+ case 'marjoram':
605
+ case 'sorrel':
606
+ case 'mint':
607
+ return 'plant-1';
608
+ case 'scallion':
609
+ case 'scalion':
610
+ case 'spring onion':
611
+ case 'springonion':
612
+ return 'vegetable-scallion';
613
+ case 'seed':
614
+ return 'gardening-seed-bag';
615
+ case 'onion':
616
+ case 'shallot':
617
+ case 'matador':
618
+ return 'vegetable-onion';
619
+ case 'bean':
620
+ case 'stringbean':
621
+ return 'vegetable-stringbean-1';
622
+ case 'cilantro':
623
+ case 'flor':
624
+ return 'vegetable-cilantro';
625
+ case 'raddish':
626
+ case 'radish':
627
+ return 'vegetable-radish';
628
+ case 'wasabi':
629
+ return 'vegetable-wasabi';
630
+ case 'flower':
631
+ return 'flower';
632
+ case 'soil':
633
+ return 'product-growth-tree-box';
634
+ case 'irrigation':
635
+ return 'gardening-sprinkler';
636
+ case 'direct seed':
637
+ return 'agriculture-machine-seeder';
638
+ case 'fertilization':
639
+ return 'organic-bag-leaf';
640
+ case 'crop protection':
641
+ return 'gardening-tools-1';
642
+ case 'crop monitoring':
643
+ case 'field':
644
+ return 'farming-barn-sun';
645
+ case 'pruning':
646
+ return 'gardening-scissors';
647
+ case 'trellising':
648
+ return 'barbed-wire-fence';
649
+ case 'preparing crops':
650
+ return 'protein-gluten-wheat';
651
+ case 'crops':
652
+ return 'harvest-product';
653
+ case 'estimating yield':
654
+ case 'other harvest':
655
+ return 'crop-info-biotech-1';
656
+ case 'grading produce':
657
+ case 'moving produce':
658
+ return 'harvest-product';
659
+ case 'post harvest':
660
+ return 'warehouse-storage';
661
+ case 'cold storage temperature':
662
+ return 'temperature-control-warehouse-1';
663
+ case 'sale':
664
+ return 'receipt-dollar';
665
+ case 'water testing':
666
+ case 'chlorine level':
667
+ return 'organic-flask';
668
+ default:
669
+ console.log('Missing switchcase for crop:', crop);
670
+ }
671
+ }
672
+
673
+ // console.log('No match found for crop:', crop);
674
+ }
675
+
676
+ if (note) {
677
+ return getIconNameForArable(note, null, defaultIcon);
678
+ }
679
+
680
+ return defaultIcon || 'seedling';
681
+ }
682
+
683
+ /**
684
+ * Get the icon name for livestock using regex
685
+ * @param purchasedItem - The name of the purchased item
686
+ * @param note - Additional note that may contain livestock type
687
+ * @param defaultIcon - The default icon to return if no match is found
688
+ * @returns The icon name or a default icon if no match is found
689
+ */
690
+
691
+ export function getIconNameForLivestock(
692
+ purchasedItem?: string | null,
693
+ note?: string | null,
694
+ defaultIcon?: string,
695
+ ): string {
696
+ if (purchasedItem) {
697
+ // return 'seedling';
698
+ const LIVESTOCK_WORDS = [
699
+ 'hay\\b',
700
+ 'cow',
701
+ 'calf',
702
+ 'cattle',
703
+ 'bull',
704
+ 'sheep',
705
+ ];
706
+
707
+ const regex = new RegExp(`\\b(${LIVESTOCK_WORDS.join('|')})`, 'gi');
708
+ const match = purchasedItem.replace('-', ' ').match(regex);
709
+ if (match) {
710
+ let matchedWord;
711
+ if (match.length === 1) {
712
+ matchedWord = match[0].toLowerCase();
713
+ } else {
714
+ // If multiple matches, choose the first match from produce words
715
+ const lcMatch = match.map((m) => m.toLowerCase());
716
+ matchedWord = LIVESTOCK_WORDS.find((word) => lcMatch.includes(word));
717
+ }
718
+
719
+ switch (matchedWord) {
720
+ case 'hay':
721
+ return 'farming-hay';
722
+ case 'cow':
723
+ case 'calf':
724
+ case 'cattle':
725
+ case 'bull':
726
+ return 'livestock-cow-body';
727
+ default:
728
+ console.log('Missing switchcase for crop:', purchasedItem);
729
+ }
730
+ }
731
+
732
+ console.log('No match found for crop:', purchasedItem);
733
+ }
734
+
735
+ if (note) {
736
+ return getIconNameForLivestock(note, null, defaultIcon);
737
+ }
738
+
739
+ return defaultIcon || 'oat-2';
740
+ }
741
+
742
+ /**
743
+ * Get the icon name for farmers market using regex
744
+ * @param purchasedItem - The name of the purchased item
745
+ * @param note - Additional note that may contain livestock type
746
+ * @param defaultIcon - The default icon to return if no match is found
747
+ * @returns The icon name or a default icon if no match is found
748
+ */
749
+
750
+ export function getIconNameForFarmersMarket(
751
+ purchasedItem?: string | null,
752
+ note?: string | null,
753
+ defaultIcon?: string,
754
+ ): string {
755
+ if (purchasedItem) {
756
+ // return 'seedling';
757
+ const FARMERS_MARKET_WORDS = [
758
+ 'hay\\b',
759
+ 'cow',
760
+ 'calf',
761
+ 'cattle',
762
+ 'bull',
763
+ 'sheep',
764
+ ];
765
+
766
+ const regex = new RegExp(`\\b(${FARMERS_MARKET_WORDS.join('|')})`, 'gi');
767
+ const match = purchasedItem.replace('-', ' ').match(regex);
768
+ if (match) {
769
+ let matchedWord;
770
+ if (match.length === 1) {
771
+ matchedWord = match[0].toLowerCase();
772
+ } else {
773
+ // If multiple matches, choose the first match from produce words
774
+ const lcMatch = match.map((m) => m.toLowerCase());
775
+ matchedWord = FARMERS_MARKET_WORDS.find((word) => lcMatch.includes(word));
776
+ }
777
+
778
+ switch (matchedWord) {
779
+ case 'hay':
780
+ return 'farming-hay';
781
+ case 'cow':
782
+ case 'calf':
783
+ case 'cattle':
784
+ case 'bull':
785
+ return 'livestock-cow-body';
786
+ default:
787
+ console.log('Missing switchcase for crop:', purchasedItem);
788
+ }
789
+ }
790
+
791
+ // console.log('No match found for farmers market:', purchasedItem);
792
+ }
793
+
794
+ if (note) {
795
+ return getIconNameForFarmersMarket(note, null, defaultIcon);
796
+ }
797
+
798
+ return defaultIcon || 'farmers-market-kiosk';
799
+ }
800
+
801
+ /**
802
+ * Get any icon name for any word
803
+ */
804
+
805
+ export function getIconNameForWord(
806
+ decidingWord: any,
807
+ text1: string,
808
+ text2?: string | null,
809
+ defaultIcon?: string,
810
+ ) {
811
+ switch (decidingWord) {
812
+ case 'ARABLE':
813
+ case 'LogArable':
814
+ return getIconNameForArable(text1, text2, defaultIcon);
815
+ case 'LIVESTOCK':
816
+ case 'LogLivestock':
817
+ return getIconNameForLivestock(text1, text2, defaultIcon);
818
+ case 'FARMERS_MARKET':
819
+ case 'LogFarmersMarket':
820
+ return getIconNameForFarmersMarket(text1, text2, defaultIcon);
821
+ default:
822
+ // titleIconName = COMMON_ICON_NAMES.document;
823
+ }
824
+ return 'circle';
825
+ }
826
+
827
+ /**
828
+ * Get icon name for any operation using regex
829
+ * @param details - GraphQL log details object
830
+ * @param defaultIcon - The default icon to return if no match is found
831
+ * @returns The icon name or a default icon if no match is found
832
+ */
833
+
834
+ export function getIconNameForLog(
835
+ details: any,
836
+ preferActivityText?: boolean,
837
+ defaultIcon_?: string,
838
+ ) {
839
+ // "crop" is deprecation support -- it should be "item" going forward
840
+ const text1 = preferActivityText ? details.activity : details.item;
841
+ const text2 = preferActivityText ? (details.title + ' ' + details.notes) : details.notes;
842
+ // @ts-ignore - allow dynamic key access
843
+ const defaultIcon = (preferActivityText && COMMON_ICON_NAMES[details.activity]) || defaultIcon_;
844
+
845
+ // console.log('defaultIcon', preferActivityText, details.activity, defaultIcon);
846
+
847
+ return getIconNameForWord(details.__typename, text1, text2, defaultIcon);
848
+ }
849
+
850
+ /**
851
+ * Get title for log
852
+ */
853
+
854
+ export function getTitleForLog(details: any): string {
855
+ switch (details.__typename) {
856
+ case 'LogFarmersMarket':
857
+ {
858
+ // Check if text from values is short, else rely on the AI summary
859
+ const valuesText = (details.values || []).map((item: any) => {
860
+ return `${item.label} ${item.value ? formatCurrency(item.value, false) : ''}`.trim();
861
+ }).join(', ');
862
+
863
+ if (valuesText.length <= 40) {
864
+ return valuesText;
865
+ }
866
+ }
867
+ break;
868
+ default:
869
+ }
870
+ return details.item;
871
+ }