Back to Home

ESO Lua File v101044

ingame/inventory/inventoryslot.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
local slotTypeIndex = 0
local function CreateSlotType(slotType)
    slotTypeIndex = slotTypeIndex + 1
    _G[slotType] = slotTypeIndex
end
CreateSlotType("SLOT_TYPE_QUEST_ITEM")
CreateSlotType("SLOT_TYPE_ITEM")
CreateSlotType("SLOT_TYPE_EQUIPMENT")
CreateSlotType("SLOT_TYPE_MY_TRADE")
CreateSlotType("SLOT_TYPE_THEIR_TRADE")
CreateSlotType("SLOT_TYPE_STORE_BUY")
CreateSlotType("SLOT_TYPE_STORE_BUYBACK")
CreateSlotType("SLOT_TYPE_BUY_MULTIPLE")
CreateSlotType("SLOT_TYPE_BANK_ITEM")
CreateSlotType("SLOT_TYPE_GUILD_BANK_ITEM")
CreateSlotType("SLOT_TYPE_MAIL_QUEUED_ATTACHMENT")
CreateSlotType("SLOT_TYPE_MAIL_ATTACHMENT")
CreateSlotType("SLOT_TYPE_LOOT")
CreateSlotType("SLOT_TYPE_ACHIEVEMENT_REWARD")
CreateSlotType("SLOT_TYPE_PENDING_CHARGE")
CreateSlotType("SLOT_TYPE_ENCHANTMENT")
CreateSlotType("SLOT_TYPE_ENCHANTMENT_RESULT")
CreateSlotType("SLOT_TYPE_TRADING_HOUSE_POST_ITEM")
CreateSlotType("SLOT_TYPE_TRADING_HOUSE_ITEM_RESULT")
CreateSlotType("SLOT_TYPE_TRADING_HOUSE_ITEM_LISTING")
CreateSlotType("SLOT_TYPE_REPAIR")
CreateSlotType("SLOT_TYPE_PENDING_REPAIR")
CreateSlotType("SLOT_TYPE_STACK_SPLIT")
CreateSlotType("SLOT_TYPE_CRAFTING_COMPONENT")
CreateSlotType("SLOT_TYPE_PENDING_CRAFTING_COMPONENT")
CreateSlotType("SLOT_TYPE_MULTIPLE_PENDING_CRAFTING_COMPONENTS")
CreateSlotType("SLOT_TYPE_SMITHING_MATERIAL")
CreateSlotType("SLOT_TYPE_SMITHING_STYLE")
CreateSlotType("SLOT_TYPE_SMITHING_TRAIT")
CreateSlotType("SLOT_TYPE_SMITHING_BOOSTER")
CreateSlotType("SLOT_TYPE_LIST_DIALOG_ITEM")
CreateSlotType("SLOT_TYPE_DYEABLE_EQUIPMENT")
CreateSlotType("SLOT_TYPE_GUILD_SPECIFIC_ITEM")
CreateSlotType("SLOT_TYPE_LAUNDER")
CreateSlotType("SLOT_TYPE_GAMEPAD_INVENTORY_ITEM")
CreateSlotType("SLOT_TYPE_COLLECTIONS_INVENTORY")
CreateSlotType("SLOT_TYPE_CRAFT_BAG_ITEM")
CreateSlotType("SLOT_TYPE_PENDING_RETRAIT_ITEM")
--
-- Setup
--
function ZO_InventorySlot_SetType(slotControl, slotType)
    slotControl.slotType = slotType
end
function ZO_InventorySlot_GetType(slotControl)
    return slotControl.slotType
end
function ZO_InventorySlot_GetStackCount(slotControl)
    return slotControl.stackCount or 0
end
local splittableTypes =
{
    [SLOT_TYPE_BANK_ITEM] = true,
    [SLOT_TYPE_ITEM] = true,
    [SLOT_TYPE_GAMEPAD_INVENTORY_ITEM] = true,
}
function ZO_InventorySlot_IsSplittableType(slotControl)
    return splittableTypes[slotControl.slotType]
end
function ZO_ItemSlot_SetupIconUsableAndLockedColor(control, meetsUsageRequirement, locked)
    if meetsUsageRequirement == nil then
        meetsUsageRequirement = true
    end
    if locked == nil then
        locked = false
    end
    if control then
        if meetsUsageRequirement then
            control:SetColor(1, 1, 1)
        else 
            control:SetColor(1, 0, 0)
        end
        if locked then
            control:SetAlpha(0.5)
        else
            control:SetAlpha(1)
        end
    end
end
function ZO_ItemSlot_SetupTextUsableAndLockedColor(control, meetsUsageRequirement, locked)
    if locked == nil then
        locked = false
    end
    if control then
        if locked then
            control:SetAlpha(0.3)
        else
            control:SetAlpha(1)
        end
    end
end
function ZO_ItemSlot_SetupUsableAndLockedColor(slotControl, meetsUsageRequirement, locked)
    local iconControl = GetControl(slotControl, "Icon")
    ZO_ItemSlot_SetupIconUsableAndLockedColor(iconControl, meetsUsageRequirement, locked)
end
local USE_LOWERCASE_NUMBER_SUFFIXES = false
function ZO_ItemSlot_SetupSlotBase(slotControl, stackCount, iconFile, meetsUsageRequirement, locked, visible)
    local showSlot = true
    if type(visible) == "function" then
        showSlot = visible()
    elseif visible ~= nil then
        showSlot = visible
    end
    slotControl:SetHidden(not showSlot)
    local iconControl = GetControl(slotControl, "Icon")
    if iconControl then
        if iconFile == nil or iconFile == "" then
            iconControl:SetHidden(true)
        else
            iconControl:SetTexture(iconFile)
            iconControl:SetHidden(false)
        end
    end
    slotControl.stackCount = stackCount
    local stackCountLabel = GetControl(slotControl, "StackCount")
    if stackCount > 1 or slotControl.alwaysShowStackCount then
        stackCountLabel:SetText(ZO_AbbreviateAndLocalizeNumber(stackCount, NUMBER_ABBREVIATION_PRECISION_TENTHS, USE_LOWERCASE_NUMBER_SUFFIXES))
    else
        stackCountLabel:SetText("")
    end
end
function ZO_ItemSlot_SetupSlot(slotControl, stackCount, iconFile, meetsUsageRequirement, locked, visible)
    ZO_ItemSlot_SetupSlotBase(slotControl, stackCount, iconFile, meetsUsageRequirement, locked, visible)
    -- Looks like this can be combined with the logic above, but certain animations (crafting) cannot
    -- call ZO_ItemSlot_SetupUsableAndLockedColor, so keep that in mind if refactoring.
    if stackCount > 1 or slotControl.alwaysShowStackCount then
        local stackCountLabel = GetControl(slotControl, "StackCount")
        if slotControl.minStackCount and stackCount < slotControl.minStackCount then
            stackCountLabel:SetColor(1, 0, 0)
        else
            stackCountLabel:SetColor(1, 1, 1)
        end
    end
    ZO_ItemSlot_SetupUsableAndLockedColor(slotControl, meetsUsageRequirement, locked)
end
function ZO_ItemSlot_SetAlwaysShowStackCount(slotControl, alwaysShowStackCount, minStackCount)
    slotControl.alwaysShowStackCount = alwaysShowStackCount
    slotControl.minStackCount = minStackCount or 1
end
function ZO_ItemSlot_GetAlwaysShowStackCount(slotControl)
    return slotControl.alwaysShowStackCount
end
-- Bind a slot control to a specific type/bag/slot
-- This should be called for all item slots (trade, mail, store, backpack, bank, crafting, etc...)
-- The meaning of slotIndex/bagId are specific to those systems, but this is the API to bind the
-- data to the UI control.
function ZO_Inventory_BindSlot(slotControl, slotType, slotIndex, bagId)
    ZO_InventorySlot_SetType(slotControl, slotType)
    slotControl.slotIndex = slotIndex
    slotControl.bagId = bagId
end
function ZO_Inventory_GetBagAndIndex(slotControl)
    return slotControl.bagId, ZO_Inventory_GetSlotIndex(slotControl)
end
function ZO_Inventory_GetSlotIndex(slotControl)
    return slotControl.slotIndex
end
    local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(slotControl)
    return SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex)
end
function ZO_Inventory_SetupSlot(slotControl, stackCount, iconFile, meetsUsageRequirement, locked)
    ZO_ItemSlot_SetupSlot(slotControl, stackCount, iconFile, meetsUsageRequirement, locked)
    slotControl.inCooldown = false
    slotControl.cooldown = GetControl(slotControl, "Cooldown")
    slotControl.cooldown:SetTexture(iconFile)
    ZO_InventorySlot_UpdateCooldowns(slotControl)
end
function ZO_Inventory_SetupQuestSlot(slotControl, questIndex, toolIndex, stepIndex, conditionIndex)
    slotControl.questIndex = questIndex
    slotControl.toolIndex = toolIndex
    slotControl.stepIndex = stepIndex
    slotControl.conditionIndex = conditionIndex
end
--Player Inventory Row
function ZO_PlayerInventorySlot_SetupUsableAndLockedColor(slotControl, meetsUsageRequirement, locked)
    ZO_ItemSlot_SetupTextUsableAndLockedColor(slotControl:GetNamedChild("Name"), meetsUsageRequirement, locked)
    ZO_ItemSlot_SetupTextUsableAndLockedColor(slotControl:GetNamedChild("SellPriceText"), meetsUsageRequirement, locked)
    ZO_ItemSlot_SetupUsableAndLockedColor(slotControl:GetNamedChild("Button"), meetsUsageRequirement, locked)
end
function ZO_PlayerInventorySlot_SetupSlot(slotControl, stackCount, iconFile, meetsUsageRequirement, locked)
    ZO_Inventory_SetupSlot(slotControl:GetNamedChild("Button"), stackCount, iconFile, meetsUsageRequirement, locked)
    ZO_PlayerInventorySlot_SetupUsableAndLockedColor(slotControl, meetsUsageRequirement, locked)
end
--
-- Control Utils
--
    -- Figure out what got passed in...inventorySlot could be a list or button type...
    local buttonPart = inventorySlot
    local listPart
    local multiIconPart
    local controlType = inventorySlot:GetType()
    if controlType == CT_CONTROL and buttonPart.slotControlType and buttonPart.slotControlType == "listSlot" then
        listPart = inventorySlot
        buttonPart = inventorySlot:GetNamedChild("Button")
        multiIconPart = inventorySlot:GetNamedChild("MultiIcon")
    elseif controlType == CT_BUTTON then
        listPart = buttonPart:GetParent()
    end
    return buttonPart, listPart, multiIconPart
end
local g_highlightAnimationProvider = ZO_ReversibleAnimationProvider:New("ShowOnMouseOverLabelAnimation")
local g_controlScaleAnimationProvider = ZO_ReversibleAnimationProvider:New("IconSlotMouseOverAnimation")
function ZO_InventorySlot_SetHighlightHidden(listPart, hidden, instant)
    if listPart then
        local highlight = listPart:GetNamedChild("Highlight")
        if highlight and highlight:GetType() == CT_TEXTURE then
            if hidden then
                g_highlightAnimationProvider:PlayBackward(highlight, instant)
            else
                g_highlightAnimationProvider:PlayForward(highlight, instant)
            end
        end
    end
end
function ZO_InventorySlot_SetControlScaledUp(control, scaledUp, instant)
    if control then
        if scaledUp then
            g_controlScaleAnimationProvider:PlayForward(control, instant)
        else
            g_controlScaleAnimationProvider:PlayBackward(control, instant)
        end                
    end
end
function ZO_InventorySlot_OnPoolReset(inventorySlot)
    local buttonPart, listPart, multiIconPart = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
    local INSTANT = true
    ZO_InventorySlot_SetHighlightHidden(listPart, true, INSTANT)
    ZO_InventorySlot_SetControlScaledUp(buttonPart, false, INSTANT)
    ZO_InventorySlot_SetControlScaledUp(multiIconPart, false, INSTANT)
    ZO_ObjectPool_DefaultResetControl(inventorySlot)
end
--
-- Cooldowns
--
local NO_LEADING_EDGE = false
local function UpdateCooldown(inventorySlot, remaining, duration)
    inventorySlot.inCooldown = (remaining > 0) and (duration > 0)
    if inventorySlot.inCooldown then
        inventorySlot.cooldown:StartCooldown(remaining, duration, CD_TYPE_RADIAL, CD_TIME_TYPE_TIME_UNTIL, NO_LEADING_EDGE)
    else
        inventorySlot.cooldown:ResetCooldown()
    end
    inventorySlot.cooldown:SetHidden(not inventorySlot.inCooldown)
end
local function QuestItemUpdateCooldown(inventorySlot)
    if(inventorySlot) then
        local remaining, duration = GetQuestToolCooldownInfo(inventorySlot.questIndex, inventorySlot.toolIndex)
        UpdateCooldown(inventorySlot, remaining, duration)
    end
    return true
end
local function ItemUpdateCooldown(inventorySlot)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local remaining, duration = GetItemCooldownInfo(bag, index)
    UpdateCooldown(inventorySlot, remaining, duration)
    return true
end
local function CollectibleItemUpdateCooldown(inventorySlot)
    local remaining, duration = GetCollectibleCooldownAndDuration(inventorySlot.collectibleId)
    UpdateCooldown(inventorySlot, remaining, duration)
    return true
end
local InventoryUpdateCooldown =
{
    [SLOT_TYPE_ITEM] =
    {
        function(inventorySlot)
            return ItemUpdateCooldown(inventorySlot)
        end
    },
    [SLOT_TYPE_QUEST_ITEM] =
    {
        function(inventorySlot)
            return QuestItemUpdateCooldown(inventorySlot)
        end
    },
    [SLOT_TYPE_COLLECTIONS_INVENTORY] = 
    {
        function(inventorySlot)
            return CollectibleItemUpdateCooldown(inventorySlot)
        end
    }
}
function ZO_InventorySlot_UpdateCooldowns(inventorySlot)
    local inventorySlotButton = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
    RunHandlers(InventoryUpdateCooldown, inventorySlotButton)
end
function ZO_GamepadItemSlot_UpdateCooldowns(inventorySlot, remaining, duration)
    UpdateCooldown(inventorySlot, remaining, duration)
end
--
-- Actions that can be performed on InventorySlots (via various clicks and context menus)
--
-- Determines whether the specified item furnishing can be placed in the current house.
function ZO_CanPlaceItemInCurrentHouse(bagId, slotIndex)
    return HasItemInSlot(bagId, slotIndex) and IsItemPlaceableFurniture(bagId, slotIndex) and (not IsItemStolen(bagId, slotIndex)) and ZO_CanPlaceFurnitureInCurrentHouse()
end
-- Attempts to begin placement of the specified item furnishing in the current house.
function ZO_TryPlaceFurnitureFromInventorySlot(bagId, slotIndex)
    if not ZO_CanPlaceItemInCurrentHouse(bagId, slotIndex) then
        return false
    end
    if GetHousingEditorMode() ~= HOUSING_EDITOR_MODE_SELECTION then
        SCENE_MANAGER:ShowBaseScene()
        if HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_SELECTION) ~= HOUSING_REQUEST_RESULT_SUCCESS then
            return false
        end
    end
    local success = HousingEditorCreateItemFurnitureForPlacement(bagId, slotIndex)
    return success
end
local function IsSendingMail()
    if MAIL_SEND and not MAIL_SEND:IsHidden() then
        return true
    elseif MAIL_GAMEPAD and MAIL_GAMEPAD:GetSend():IsAttachingItems() then
        return true
    end
    return false
end
local function CanUseSecondaryActionOnSlot(inventorySlot)
    if not inventorySlot then
        return false
    end
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    return not (QUICKSLOT_KEYBOARD and QUICKSLOT_KEYBOARD:AreQuickSlotsShowing())
           and not (TRADING_HOUSE_SEARCH and TRADING_HOUSE_SEARCH:IsAtTradingHouse())
           and not (ZO_Store_IsShopping and ZO_Store_IsShopping())
           and not IsSendingMail()
           and not (TRADE_WINDOW and TRADE_WINDOW:IsTrading())
           and not IsBankOpen()
           and not IsGuildBankOpen()
           and not (GetItemActorCategory(bag, index) == GAMEPLAY_ACTOR_CATEGORY_COMPANION)
end
local function CanUseItemQuestItem(inventorySlot)
    if inventorySlot then
        if inventorySlot.toolIndex then
            return CanUseQuestTool(inventorySlot.questIndex, inventorySlot.toolIndex)
        elseif inventorySlot.conditionIndex then
            return CanUseQuestItem(inventorySlot.questIndex, inventorySlot.stepIndex, inventorySlot.conditionIndex)
        end
    end
    return false
end
local function TryUseQuestItem(inventorySlot)
    if inventorySlot then
        if inventorySlot.toolIndex then
            UseQuestTool(inventorySlot.questIndex, inventorySlot.toolIndex)
        elseif inventorySlot.conditionIndex then
            UseQuestItem(inventorySlot.questIndex, inventorySlot.stepIndex, inventorySlot.conditionIndex)
        end
    end
end
function ZO_InventorySlot_CanQuickslotItem(inventorySlot)
    if inventorySlot.filterData then
        if ZO_IsElementInNumericallyIndexedTable(inventorySlot.filterData, ITEMFILTERTYPE_QUICKSLOT) then
            return true
        elseif ZO_IsElementInNumericallyIndexedTable(inventorySlot.filterData, ITEMFILTERTYPE_QUEST_QUICKSLOT) then
            return true
        end
    end
    return false
end
function ZO_InventorySlot_CanSplitItemStack(inventorySlot)
    if ZO_InventorySlot_GetStackCount(inventorySlot) > 1 then
        local hasFreeSlot = FindFirstEmptySlotInBag(inventorySlot.bagId) ~= nil
        if not hasFreeSlot then
            if inventorySlot.bagId == BAG_BANK then
                hasFreeSlot = FindFirstEmptySlotInBag(BAG_SUBSCRIBER_BANK)
            elseif inventorySlot.bagId == BAG_SUBSCRIBER_BANK then
                hasFreeSlot = FindFirstEmptySlotInBag(BAG_BANK)
            end
        end
        return hasFreeSlot        
    end
end
function ZO_InventorySlot_TrySplitStack(inventorySlot)
    if GetCursorContentType() == MOUSE_CONTENT_EMPTY then
        return ZO_StackSplit_SplitItem(inventorySlot)
    end
end
do
    local g_listDialog
        if not g_listDialog then
            local function SetupItemRow(rowControl, slotInfo)
                local bag, index = slotInfo.bag, slotInfo.index
                local icon, _, _, _, _, _, _, _, displayQuality = GetItemInfo(bag, index)
                local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, displayQuality)
                local nameControl = rowControl:GetNamedChild("Name")
                nameControl:SetText(zo_strformat(SI_TOOLTIP_ITEM_NAME, GetItemName(bag, index)))
                nameControl:SetColor(r, g, b, 1)
                local inventorySlot = rowControl:GetNamedChild("Button")
                ZO_Inventory_BindSlot(inventorySlot, SLOT_TYPE_LIST_DIALOG_ITEM, index, bag)
                ZO_Inventory_SetupSlot(inventorySlot, slotInfo.stack, icon)
                rowControl:GetNamedChild("Selected"):SetHidden(g_listDialog:GetSelectedItem() ~= slotInfo)
                local statusTextureControl = rowControl:GetNamedChild("StatusTexture")
                if IsItemInArmory(bag, index) then
                    statusTextureControl:SetTexture(ZO_IN_ARMORY_BUILD_ICON)
                    statusTextureControl:SetHidden(false)
                else
                    statusTextureControl:SetHidden(true)
                end
                if g_listDialog:GetSelectedItem() then
                    g_listDialog:SetFirstButtonEnabled(true)
                end
            end
            g_listDialog = ZO_ListDialog:New("ZO_ListDialogInventorySlot", 52, SetupItemRow)
        end
        g_listDialog:SetFirstButtonEnabled(false)
        return g_listDialog
    end
    local g_multiSelectListDialog
        if not g_multiSelectListDialog then
            local function SetupItemRow(rowControl, slotInfo)
                local bag, index = slotInfo.bag, slotInfo.index
                local icon, _, _, _, _, _, _, _, displayQuality = GetItemInfo(bag, index)
                local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, displayQuality)
                local nameControl = rowControl:GetNamedChild("Name")
                nameControl:SetText(zo_strformat(SI_TOOLTIP_ITEM_NAME, GetItemName(bag, index)))
                nameControl:SetColor(r, g, b, 1)
                local inventorySlot = rowControl:GetNamedChild("Button")
                ZO_Inventory_BindSlot(inventorySlot, SLOT_TYPE_LIST_DIALOG_ITEM, index, bag)
                ZO_Inventory_SetupSlot(inventorySlot, slotInfo.stack, icon)
                rowControl:GetNamedChild("Selected"):SetHidden(not g_multiSelectListDialog:IsItemSelected(slotInfo))
                local statusTextureControl = rowControl:GetNamedChild("StatusTexture")
                if IsItemInArmory(bag, index) then
                    statusTextureControl:SetTexture(ZO_IN_ARMORY_BUILD_ICON)
                    statusTextureControl:SetHidden(false)
                else
                    statusTextureControl:SetHidden(true)
                end
                if #g_multiSelectListDialog:GetSelectedItems() > 0 then
                    g_multiSelectListDialog:SetFirstButtonEnabled(true)
                else
                    g_multiSelectListDialog:SetFirstButtonEnabled(false)
                end
            end
            g_multiSelectListDialog = ZO_MultiSelectListDialog:New("ZO_ListDialogInventorySlot", 52, SetupItemRow)
        end
        g_multiSelectListDialog:SetFirstButtonEnabled(false)
        return g_multiSelectListDialog
    end
end
local function CanEnchantItem(inventorySlot)
    if CanUseSecondaryActionOnSlot(inventorySlot) then
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        return IsItemEnchantable(bag, index)
    end
end
local function TryEnchantItem(inventorySlot)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local function DoEnchant()
        SYSTEMS:GetObject("enchant"):BeginItemImprovement(bag, index)
    end
    if IsItemBoPAndTradeable(bag, index) then
        ZO_Dialogs_ShowPlatformDialog("CONFIRM_MODIFY_TRADE_BOP", {onAcceptCallback = DoEnchant}, {mainTextParams={GetItemName(bag, index)}})
    else
        DoEnchant()
    end
    
end
local function CanConvertToStyle(inventorySlot, toStyle)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    if CanUseSecondaryActionOnSlot(inventorySlot) and not IsItemPlayerLocked(bag, index) then
        return CanConvertItemStyle(bag, index, toStyle)
    end
end
local function IsSlotLocked(inventorySlot)
    local slotData = ZO_Inventory_GetSlotDataForInventoryControl(inventorySlot)
    if slotData then
        return slotData.locked
    end
end
local function CanChargeItem(inventorySlot)
    if CanUseSecondaryActionOnSlot(inventorySlot) then
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        return IsItemChargeable(bag, index)
    end
end
local function TryChargingItem(inventorySlot)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local charges, maxCharges = GetChargeInfoForItem(bag, index)
    if charges == maxCharges then
        ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString("SI_SOULGEMITEMCHARGINGREASON", SOUL_GEM_ITEM_CHARGING_ALREADY_CHARGED))
    else
        SYSTEMS:GetObject("soulgem"):BeginItemImprovement(bag, index)
    end
end
local function CanKitRepairItem(inventorySlot)
    if CanUseSecondaryActionOnSlot(inventorySlot) then
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        return DoesItemHaveDurability(bag, index)
    end
end
local function TryKitRepairItem(inventorySlot)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local condition = GetItemCondition(bag, index)
    if condition == 100 then
        ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString("SI_ITEMREPAIRREASON", ITEM_REPAIR_ALREADY_REPAIRED))
    else
        SYSTEMS:GetObject("repair"):BeginItemImprovement(bag, index)
    end
end
local function PlaceInventoryItem(inventorySlot)
    local cursorType = GetCursorContentType()
    if cursorType ~= MOUSE_CONTENT_EMPTY then
        local sourceBag = GetCursorBagId()
        local sourceSlot = GetCursorSlotIndex()
        local destBag, destSlot = ZO_Inventory_GetBagAndIndex(inventorySlot)
        ClearCursor()
        if ZO_InventorySlot_WillItemBecomeBoundOnEquip(sourceBag, sourceSlot) then
            local itemDisplayQuality = GetItemDisplayQuality(sourceBag, sourceSlot)
            local itemQualityColor = GetItemQualityColor(itemDisplayQuality)
            ZO_Dialogs_ShowPlatformDialog("CONFIRM_EQUIP_ITEM", { onAcceptCallback = function() RequestMoveItem(sourceBag, sourceSlot, destBag, destSlot) end }, { mainTextParams = { itemQualityColor:Colorize(GetItemName(sourceBag, sourceSlot)) } })
        else
            RequestMoveItem(sourceBag, sourceSlot, destBag, destSlot)
        end
        return true
    end
end
function TryPlaceInventoryItemInEmptySlot(targetBag)
    local emptySlotIndex = FindFirstEmptySlotInBag(targetBag)
    if not emptySlotIndex and IsESOPlusSubscriber() then
        -- The player may be trying to split a stack. If they're transacting on the bank or
        -- subscriber bank, then the other bag is also a valid target for the split item.
        if targetBag == BAG_BANK then
            targetBag = BAG_SUBSCRIBER_BANK
            emptySlotIndex = FindFirstEmptySlotInBag(targetBag)
        elseif targetBag == BAG_SUBSCRIBER_BANK then
            targetBag = BAG_BANK
            emptySlotIndex = FindFirstEmptySlotInBag(targetBag)
        end
    end
    if emptySlotIndex ~= nil then
        PlaceInInventory(targetBag, emptySlotIndex)
    else
        local errorStringId = (targetBag == BAG_BACKPACK) and SI_INVENTORY_ERROR_INVENTORY_FULL or SI_INVENTORY_ERROR_BANK_FULL
        ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, errorStringId)
    end
end
local function TryGuildBankDepositItem(sourceBag, sourceSlot)
    local guildId = GetSelectedGuildBankId()
    if guildId then
        if not DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_DEPOSIT) then
            ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_NO_DEPOSIT_PERMISSION)
            return
        end
        if not DoesGuildHavePrivilege(guildId, GUILD_PRIVILEGE_BANK_DEPOSIT) then
            ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_GUILD_TOO_SMALL)
            return
        end
        if IsItemStolen(sourceBag, sourceSlot) then
            ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_NO_DEPOSIT_STOLEN_ITEM)
            return
        end
        if GetNumBagFreeSlots(BAG_GUILDBANK) == 0 then
            ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_NO_SPACE_LEFT)
            return
        end
        local soundCategory = GetItemSoundCategory(sourceBag, sourceSlot)
        PlayItemSound(soundCategory, ITEM_SOUND_ACTION_PICKUP)
        TransferToGuildBank(sourceBag, sourceSlot)
    end
    ClearCursor()
end
local function TryGuildBankWithdrawItem(sourceSlotIndex)
    local guildId = GetSelectedGuildBankId()
    if guildId then
        if not DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_WITHDRAW) then
            ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_NO_WITHDRAW_PERMISSION)
            return
        end
        if not DoesBagHaveSpaceFor(BAG_BACKPACK, BAG_GUILDBANK, sourceSlotIndex) then
            ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, SI_INVENTORY_ERROR_INVENTORY_FULL)
            return
        end
        local soundCategory = GetItemSoundCategory(BAG_GUILDBANK, sourceSlotIndex)
        PlayItemSound(soundCategory, ITEM_SOUND_ACTION_PICKUP)
        TransferFromGuildBank(sourceSlotIndex)
    end
    ClearCursor()
end
function ZO_TryMoveToInventoryFromBagAndSlot(bag, slotIndex)
    if DoesBagHaveSpaceFor(BAG_BACKPACK, bag, slotIndex) then
        local transferDialog = SYSTEMS:GetObject("ItemTransferDialog")
        transferDialog:StartTransfer(bag, slotIndex, BAG_BACKPACK)
    else
        ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, SI_INVENTORY_ERROR_INVENTORY_FULL)
    end
     ClearCursor()
end
local function TryMoveToInventory(inventorySlot)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
end
local function PlaceInventoryItemInStorage(targetInventorySlot)
    -- When moving your items between bags/slots there are special-cased rules
    -- that need to apply...instead of using the landing area for the empty slot
    -- and trying to swap/stack items each dropped item will only try to stack.
    -- If it can't stack on what it was dropped on, then it will attempt to place itself in an empty slot.
    -- Swapping is only allowed when dragging from backpack to an equip slot, never the other way around.
    local targetType = ZO_InventorySlot_GetType(targetInventorySlot)
    local targetBag, targetSlotIndex = ZO_Inventory_GetBagAndIndex(targetInventorySlot)
    local targetItemId = GetItemInstanceId(targetBag, targetSlotIndex)
    local sourceType = GetCursorContentType()
    local sourceBag, sourceSlotIndex = GetCursorBagId(), GetCursorSlotIndex()
    local sourceItemId = GetItemInstanceId(sourceBag, sourceSlotIndex)
    -- Transferring from Craft Bag is going to be handled independently here because it has special needs
    if sourceBag == BAG_VIRTUAL then
        -- We can really only transfer from the Craft Bag to the BACKPACK and when we transfer
        -- we want to prompt the option to choose a quantity (up to 200)
        if sourceType == MOUSE_CONTENT_INVENTORY_ITEM then
            if targetType == SLOT_TYPE_ITEM and targetBag == BAG_BACKPACK then
                ZO_TryMoveToInventoryFromBagAndSlot(sourceBag, sourceSlotIndex)
                return true
            end
        end
        return false
    elseif targetType == SLOT_TYPE_ITEM or targetType == SLOT_TYPE_BANK_ITEM then
        if sourceType == MOUSE_CONTENT_EQUIPPED_ITEM then
            TryPlaceInventoryItemInEmptySlot(targetBag)
            return true
        elseif sourceType == MOUSE_CONTENT_INVENTORY_ITEM then
            -- if the items can stack, move the source to the clicked slot, otherwise try to move to an empty slot.
            -- never swap!
            if sourceBag == BAG_GUILDBANK then
                TryGuildBankWithdrawItem(sourceSlotIndex)
                return true
            else
                if sourceItemId == targetItemId then
                    PlaceInInventory(targetBag, targetSlotIndex)
                    return true
                else
                    if sourceBag == targetBag then
                        ClearCursor()
                    else
                        TryPlaceInventoryItemInEmptySlot(targetBag)
                    end
                    return true
                end
            end
        elseif sourceType == MOUSE_CONTENT_QUEST_ITEM then
            ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_INVENTORY_ERROR_NO_QUEST_ITEMS_IN_BANK))
            return false
        end
    elseif targetType == SLOT_TYPE_GUILD_BANK_ITEM then
        if sourceType == MOUSE_CONTENT_QUEST_ITEM then
            ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_INVENTORY_ERROR_NO_QUEST_ITEMS_IN_BANK))
            return false
        elseif sourceBag == BAG_GUILDBANK then
             ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_INVENTORY_ERROR_CANNOT_STACK_GUILD_BANK))
             ClearCursor()
            return false
        else
            TryGuildBankDepositItem(sourceBag, sourceSlotIndex)
            return true
        end
    end
    -- No special behavior...
    return PlaceInventoryItem(targetInventorySlot)
end
local function TryBankItem(inventorySlot)
    if IsBankOpen() then
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if bag == BAG_BANK or bag == BAG_SUBSCRIBER_BANK or IsHouseBankBag(bag) then
            --Withdraw
            if DoesBagHaveSpaceFor(BAG_BACKPACK, bag, index) then
                PickupInventoryItem(bag, index)
                PlaceInTransfer()
            else
                ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, SI_INVENTORY_ERROR_INVENTORY_FULL)
            end
        else
            --Deposit
            if IsItemStolen(bag, index) then
                ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, SI_STOLEN_ITEM_CANNOT_DEPOSIT_MESSAGE)
            else
                local bankingBag = GetBankingBag()
                local canAlsoBePlacedInSubscriberBank = bankingBag == BAG_BANK
                if DoesBagHaveSpaceFor(bankingBag, bag, index) or (canAlsoBePlacedInSubscriberBank and DoesBagHaveSpaceFor(BAG_SUBSCRIBER_BANK, bag, index)) then
                    PickupInventoryItem(bag, index)
                    PlaceInTransfer()
                else
                    if canAlsoBePlacedInSubscriberBank and not IsESOPlusSubscriber() then
                        if GetNumBagUsedSlots(BAG_SUBSCRIBER_BANK) > 0 then
                            TriggerTutorial(TUTORIAL_TRIGGER_BANK_OVERFULL)
                        else
                            TriggerTutorial(TUTORIAL_TRIGGER_BANK_FULL_NO_ESO_PLUS)
                        end
                    end
                    ZO_AlertEvent(EVENT_BANK_IS_FULL)
                end                
             end
        end
        return true
    end
end
local function CanMoveToCraftBag(bagId, slotIndex)
    return HasCraftBagAccess() and CanItemBeVirtual(bagId, slotIndex) and not IsItemStolen(bagId, slotIndex)
end
local function TryMoveToCraftBag(bagId, slotIndex)
    local slotData = SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex)
    if slotData then
        if slotData.isGemmable then
            ZO_Dialogs_ShowPlatformDialog("CONFIRM_STOW_GEMIFIABLE", { sourceBagId = bagId, sourceSlotIndex = slotIndex })
        else
            local transferDialog = SYSTEMS:GetObject("ItemTransferDialog")
            transferDialog:StartTransfer(bagId, slotIndex, BAG_VIRTUAL)
            return true
        end
    end
end
local function TryPreviewDyeStamp(inventorySlot)
    -- get item info and pass it to the preview dye stamp view
    -- there, the player can spin the model and confirm or deny using the stamp
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local itemLink = GetItemLink(bag, index)
    local dyeStampId = GetItemLinkDyeStampId(itemLink)
    local onUseType = GetItemLinkItemUseType(itemLink)
    if onUseType == ITEM_USE_TYPE_ITEM_DYE_STAMP then
        local dyeStampUseResult = CanPlayerUseItemDyeStamp(dyeStampId)
        if dyeStampUseResult ~= DYE_STAMP_USE_RESULT_NONE then
            ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString("SI_DYESTAMPUSERESULT", dyeStampUseResult))
            return
        end
    elseif onUseType == ITEM_USE_TYPE_COSTUME_DYE_STAMP then
        local dyeStampUseResult = CanPlayerUseCostumeDyeStamp(dyeStampId)
        if dyeStampUseResult ~= DYE_STAMP_USE_RESULT_NONE then
            ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString("SI_DYESTAMPUSERESULT", dyeStampUseResult))
            return
        end
    end
    SYSTEMS:GetObject("dyeStamp_Confirmation"):SetTargetItem(bag, index)
    SYSTEMS:PushScene("dyeStampConfirmation")
end
local function TryPreviewItem(bag, slot)
    SYSTEMS:GetObject("itemPreview"):PreviewInventoryItem(bag, slot)
    if not IsInGamepadPreferredMode() then
        INVENTORY_MENU_BAR:UpdateInventoryKeybinds()
    end
end
-- If called on an item inventory slot, returns the index of the attachment slot that's holding it, or nil if it's not attached.
local function GetQueuedItemAttachmentSlotIndex(inventorySlot)
    local bag, attachmentIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
    if bag then
        for i = 1, MAIL_MAX_ATTACHED_ITEMS do
            local bagId, slotIndex = GetQueuedItemAttachmentInfo(i)
            if bagId == bag and attachmentIndex == slotIndex then
                return i
            end
        end
    end
end
local function IsItemAlreadyAttachedToMail(inventorySlot)
    local index = GetQueuedItemAttachmentSlotIndex(inventorySlot)
    if index then
        return GetQueuedItemAttachmentInfo(index) ~= 0
    end
end
local function TryMailItem(inventorySlot)
    if IsSendingMail() then
        for i = 1, MAIL_MAX_ATTACHED_ITEMS do
            local queuedFromBag = GetQueuedItemAttachmentInfo(i)
            if queuedFromBag == 0 then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                local result = QueueItemAttachment(bag, index, i)
                if result == MAIL_ATTACHMENT_RESULT_ALREADY_ATTACHED then
                    ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_ALREADY_ATTACHED))
                elseif result == MAIL_ATTACHMENT_RESULT_BOUND then
                    ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_BOUND))
                elseif result == MAIL_ATTACHMENT_RESULT_ITEM_NOT_FOUND then
                    ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_ITEM_NOT_FOUND))
                elseif result == MAIL_ATTACHMENT_RESULT_LOCKED then
                    ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_LOCKED))
                elseif result == MAIL_ATTACHMENT_RESULT_STOLEN then
                    ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_STOLEN_ITEM_CANNOT_MAIL_MESSAGE))
                else
                    UpdateMouseoverCommand(inventorySlot)
                end
                return true
            end
        end
        ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_ATTACHMENTS_FULL))
        return true
    end
end
local function RemoveQueuedAttachment(inventorySlot)
    local index = GetQueuedItemAttachmentSlotIndex(inventorySlot)
    UpdateMouseoverCommand(inventorySlot)
end
local function CanTradeItem(inventorySlot)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    return TRADE_WINDOW:IsTrading() and not IsItemBound(bag, index)
end
local function IsItemAlreadyBeingTraded(inventorySlot)
    if ZO_InventorySlot_GetType(inventorySlot) == SLOT_TYPE_MY_TRADE then
        local _, _, stackCount = GetTradeItemInfo(TRADE_ME, ZO_Inventory_GetSlotIndex(inventorySlot))
        if stackCount > 0 then
            return true
        end
    else
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        return ZO_IsItemCurrentlyOfferedForTrade(bag, index)
    end
    return false
end
local function TryTradeItem(inventorySlot)
    if TRADE_WINDOW:IsTrading() then
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        TRADE_WINDOW:AddItemToTrade(bag, index)
        return true
    end
end
local function TryRemoveFromTrade(inventorySlot)
    if TRADE_WINDOW:IsTrading() then
        if ZO_InventorySlot_GetType(inventorySlot) == SLOT_TYPE_MY_TRADE then
            local tradeIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
            local bagId, slotId = GetTradeItemBagAndSlot(TRADE_ME, tradeIndex)
            if bagId and slotId then
                local soundCategory = GetItemSoundCategory(bagId, slotId)
                PlayItemSound(soundCategory, ITEM_SOUND_ACTION_PICKUP)
                TradeRemoveItem(tradeIndex)
            end
        else
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            for i = 1, TRADE_NUM_SLOTS do
                local bagId, slotIndex = GetTradeItemBagAndSlot(TRADE_ME, i)
                if bagId and slotIndex and bagId == bag and slotIndex == index then
                    local soundCategory = GetItemSoundCategory(bagId, slotIndex)
                    PlayItemSound(soundCategory, ITEM_SOUND_ACTION_PICKUP)
                    TradeRemoveItem(i)
                    break
                end
            end
        end
        UpdateMouseoverCommand(inventorySlot)
    end
end
-- To prevent double-click attempting to equip items when at a store, this should just return whether or not the player is shopping.
-- We always want to try to sell when the user does the "primary" action at a store so that they don't mistakenly equip a 0-cost
-- item which replaces their existing gear...and then when the user continues to hit "E" or double-clicks they end up selling gear
-- they don't want to.
local function CanSellItem(inventorySlot)
    return ZO_Store_IsShopping() and not SYSTEMS:GetObject("fence"):IsLaundering()
end
local function CanLaunderItem(inventorySlot)
    return ZO_Store_IsShopping() and SYSTEMS:GetObject("fence"):IsLaundering()
end
local function TrySellItem(inventorySlot)
    local itemData = {}
    if CanSellItem() then
        itemData.stackCount = ZO_InventorySlot_GetStackCount(inventorySlot)
        if itemData.stackCount > 0 then
            itemData.bag, itemData.slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
            if IsItemStolen(itemData.bag, itemData.slot) then
                local totalSells, sellsUsed = GetFenceSellTransactionInfo()
                if sellsUsed == totalSells then
                    ZO_Alert(UI_ALERT_CATEGORY_ALERT, SOUNDS.NEGATIVE_CLICK, GetString("SI_STOREFAILURE", STORE_FAILURE_AT_FENCE_LIMIT))
                    return
                end
            end
            itemData.itemName = GetItemName(itemData.bag, itemData.slot)
            itemData.functionalQuality = GetItemFunctionalQuality(itemData.bag, itemData.slot)
            itemData.displayQuality = GetItemDisplayQuality(itemData.bag, itemData.slot)
            -- itemData.quality is deprecated, included here for addon backwards compatibility
            itemData.quality = itemData.functionalQuality
            if SCENE_MANAGER:IsShowing("fence_keyboard") and itemData.functionalQuality >= ITEM_FUNCTIONAL_QUALITY_ARTIFACT then
                ZO_Dialogs_ShowDialog("CANT_BUYBACK_FROM_FENCE", itemData)
            elseif IsItemInArmory(itemData.bag, itemData.slot) then
                local armoryBuildList = { GetItemArmoryBuildList(itemData.bag, itemData.slot) }
                local buildListString = ZO_GenerateCommaSeparatedListWithAnd(armoryBuildList)
                ZO_Dialogs_ShowDialog("CONFIRM_SELL_ARMORY_ITEM_PROMPT", itemData, { mainTextParams = { ZO_SELECTED_TEXT:Colorize(buildListString), #armoryBuildList }})
            else
                SellInventoryItem(itemData.bag, itemData.slot, itemData.stackCount)
            end
            return true
        end
    end
end
local function TryLaunderItem(inventorySlot)
    local totalLaunders, laundersUsed = GetFenceLaunderTransactionInfo()
    if laundersUsed == totalLaunders then
        ZO_Alert(UI_ALERT_CATEGORY_ALERT, SOUNDS.NEGATIVE_CLICK, GetString("SI_ITEMLAUNDERRESULT", ITEM_LAUNDER_RESULT_AT_LIMIT))
        return
    end
    if CanLaunderItem() then
        local stackCount = ZO_InventorySlot_GetStackCount(inventorySlot)
        if stackCount > 0 then
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            LaunderItem(bag, index, stackCount)
            return true
        end
    end
end
local function CanBuyMultiple(inventorySlot)
    return not (inventorySlot.isCollectible or inventorySlot.isUnique)
end
local function CanEquipItem(inventorySlot)
    if not IsSlotLocked(inventorySlot) then
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if bag ~= BAG_WORN and bag ~= BAG_COMPANION_WORN then
            local itemActorCategory = GetItemActorCategory(bag, index)
            if itemActorCategory == GAMEPLAY_ACTOR_CATEGORY_COMPANION and GetInteractionType() ~= INTERACTION_COMPANION_MENU then
                return false
            end
            local equipType = GetItemEquipType(bag, index)
            return equipType ~= EQUIP_TYPE_INVALID
        end
    end
    return false
end
local function TryEquipItem(inventorySlot)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local function DoEquip()
        local equipSucceeds, possibleError = IsEquipable(bag, index)
        if equipSucceeds then
            ClearCursor()
            local wornBag = GetItemActorCategory(bag, index) == GAMEPLAY_ACTOR_CATEGORY_PLAYER and BAG_WORN or BAG_COMPANION_WORN
            RequestEquipItem(bag, index, wornBag)
            return true
        end
        ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, possibleError)
    end
    if ZO_InventorySlot_WillItemBecomeBoundOnEquip(bag, index) then
        local itemDisplayQuality = GetItemDisplayQuality(bag, index)
        local itemDisplayQualityColor = GetItemQualityColor(itemDisplayQuality)
        ZO_Dialogs_ShowPlatformDialog("CONFIRM_EQUIP_ITEM", { onAcceptCallback = DoEquip }, { mainTextParams = { itemDisplayQualityColor:Colorize(GetItemName(bag, index)) } })
    else
        DoEquip()
    end
end
local function CanUnequipItem(inventorySlot)
    local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
    if bag == BAG_WORN or bag == BAG_COMPANION_WORN then
        local _, stackCount = GetItemInfo(bag, slot)
        return stackCount > 0
    end
    return false
end
local function TryUnequipItem(inventorySlot)
    local bag, equipSlot = ZO_Inventory_GetBagAndIndex(inventorySlot)
    RequestUnequipItem(bag, equipSlot)
end
local function TryPickupQuestItem(inventorySlot)
    if inventorySlot.questIndex then
        if inventorySlot.toolIndex then
            PickupQuestTool(inventorySlot.questIndex, inventorySlot.toolIndex)
        else
            PickupQuestItem(inventorySlot.questIndex, inventorySlot.stepIndex, inventorySlot.conditionIndex)
        end
        return true
    end
end
local destroyableItems =
{
    [SLOT_TYPE_ITEM] = true,
    [SLOT_TYPE_EQUIPMENT] = true,
    [SLOT_TYPE_BANK_ITEM] = true,
    [SLOT_TYPE_GAMEPAD_INVENTORY_ITEM] = true,
    [SLOT_TYPE_CRAFT_BAG_ITEM] = false, -- There's no good reason to destroy from the Craft Bag
}
function ZO_InventorySlot_CanDestroyItem(inventorySlot)
    local slotType = ZO_InventorySlot_GetType(inventorySlot)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    if destroyableItems[slotType] and not IsItemPlayerLocked(bag, index) then
        if slotType == SLOT_TYPE_EQUIPMENT then
            return CanUnequipItem(inventorySlot) -- if you can unequip it, it can be destroyed.
        else
            return true
        end
    end
end
function ZO_InventorySlot_InitiateDestroyItem(inventorySlot)
    if IsSlotLocked(inventorySlot) then
        ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_ERROR_ITEM_LOCKED))
        return false
    end
    -- Attempt to pick it up as a quest item, if that fails, attempt to pick it up as an inventory item
    if(not TryPickupQuestItem(inventorySlot)) then
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        PickupInventoryItem(bag, index)
    end
    -- Initiates the destruction request...(could either abandon quest or destroy the item)
    return true
end
local function CanUseItemWithOnUseType(onUseType)
    if onUseType == ITEM_USE_TYPE_ITEM_DYE_STAMP
       or onUseType == ITEM_USE_TYPE_COSTUME_DYE_STAMP
       or onUseType == ITEM_USE_TYPE_KEEP_RECALL_STONE
       or onUseType == ITEM_USE_TYPE_SKILL_RESPEC
       or onUseType == ITEM_USE_TYPE_MORPH_RESPEC
       or onUseType == ITEM_USE_TYPE_ATTRIBUTE_RESPEC
    then
        return false
    end
    return true
end
local function CanUseItem(inventorySlot)
    local hasCooldown = inventorySlot.IsOnCooldown and inventorySlot:IsOnCooldown()
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local usable, onlyFromActionSlot = IsItemUsable(bag, index)
    local canInteractWithItem = CanInteractWithItem(bag, index)
    local onUseType = GetItemUseType(bag, index)
    local canUseItemWithOnUseType = CanUseItemWithOnUseType(onUseType)
    return usable and not onlyFromActionSlot and canInteractWithItem and not hasCooldown and canUseItemWithOnUseType
end
local function TryUseItem(inventorySlot)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local usable, onlyFromActionSlot = IsItemUsable(bag, index)
    if usable and not onlyFromActionSlot then
        ClearCursor()
        UseItem(bag, index)
        return true
    end
end
function ZO_InventorySlot_InitiateConfirmUseItem(inventorySlot)
    if IsSlotLocked(inventorySlot) then
        ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_ERROR_ITEM_LOCKED))
        return false
    end
    local bag, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
    InitiateConfirmUseInventoryItem(bag, slotIndex)
    return true
end
local function TryShowRecallMap(inventorySlot)
    TryUseItem(inventorySlot)
end
local function TryStartSkillRespec(inventorySlot)
    TryUseItem(inventorySlot)
end
local function TryStartAttributeRespec(inventorySlot)
    TryUseItem(inventorySlot)
end
local function TryBindItem(bagId, slotIndex)
    local function OnAcceptCallback()
        BindItem(bagId, slotIndex)
    end
    if ZO_InventorySlot_WillItemBecomeBoundOnEquip(bagId, slotIndex) then
        local itemDisplayQuality = GetItemDisplayQuality(bagId, slotIndex)
        local itemDisplayQualityColor = GetItemQualityColor(itemDisplayQuality)
        ZO_Dialogs_ShowPlatformDialog("CONFIRM_BIND_ITEM", { onAcceptCallback = OnAcceptCallback }, { mainTextParams = { itemDisplayQualityColor:Colorize(GetItemName(bagId, slotIndex)) } })
    end
end
local function TryBuyMultiple(inventorySlot)
    ZO_BuyMultiple_OpenBuyMultiple(inventorySlot.index)
end
local function BuyItemFromStore(inventorySlot)
    local storeItemId = inventorySlot.index
    local itemData = {
        currencyType1 = inventorySlot.specialCurrencyType1,
        currencyType2 = inventorySlot.specialCurrencyType2,
        price = inventorySlot.moneyCost,
        currencyQuantity1 = inventorySlot.specialCurrencyQuantity1,
        currencyQuantity2 = inventorySlot.specialCurrencyQuantity2,
        meetsRequirementsToBuy = inventorySlot.meetsRequirements
    }
    if not ZO_Currency_TryShowThresholdDialog(storeItemId, inventorySlot.stackCount, itemData) then
        BuyStoreItem(storeItemId, 1)
    end
    return true
end
function TakeLoot(slot)
    if slot.lootEntry.currencyType then
        LootCurrency(slot.lootEntry.currencyType)
    else
        LootItemById(slot.lootEntry.lootId)
    end
end
local function IsItemAlreadyBeingPosted(inventorySlot)
    local postedBag, postedSlot, postedQuantity = GetPendingItemPost()
    if ZO_InventorySlot_GetType(inventorySlot) == SLOT_TYPE_TRADING_HOUSE_POST_ITEM then
        return postedQuantity > 0
    end
    local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
    return postedQuantity > 0 and bag == postedBag and slot == postedSlot
end
local function TryInitiatingItemPost(inventorySlot)
    local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local _, stackCount = GetItemInfo(bag, slot)
    if(stackCount > 0) then
        if (IsItemStolen(bag, slot)) then
            ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_STOLEN_ITEM_CANNOT_LIST_MESSAGE))
        else
            SetPendingItemPost(bag, slot, stackCount)
            UpdateMouseoverCommand(inventorySlot)
        end
    end
end
local function ClearItemPost(inventorySlot)
    SetPendingItemPost(BAG_BACKPACK, 0, 0) 
    UpdateMouseoverCommand(inventorySlot)
end
local function TryBuyingGuildSpecificItem(inventorySlot)
    if TRADING_HOUSE:VerifyBuyItemAndShowErrors(inventorySlot) then
        local guildSpecificItemIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
        TRADING_HOUSE:ConfirmPendingGuildSpecificPurchase(guildSpecificItemIndex)
    end
end
local function TryBuyingTradingHouseItem(inventorySlot)
    if TRADING_HOUSE:VerifyBuyItemAndShowErrors(inventorySlot) then
        local tradingHouseIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
        SetPendingItemPurchase(tradingHouseIndex)
    end
end
local function TryCancellingTradingHouseListing(inventorySlot)
    local listingIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
    TRADING_HOUSE:ShowCancelListingConfirmation(listingIndex)
end
local function TryVendorRepairItem(inventorySlot)
    local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
    RepairItem(bag, slot)
    PlaySound(SOUNDS.INVENTORY_ITEM_REPAIR)
end
local function CanItemBeAddedToCraft(inventorySlot)
    local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
    if SYSTEMS:IsShowing(ZO_ALCHEMY_SYSTEM_NAME) then
        return SYSTEMS:GetObject(ZO_ALCHEMY_SYSTEM_NAME):CanItemBeAddedToCraft(bag, slot)
    elseif ZO_Enchanting_IsSceneShowing() then
        return ZO_Enchanting_GetVisibleEnchanting():CanItemBeAddedToCraft(bag, slot)
    elseif ZO_FishFillet_IsSceneShowing() then
        return ZO_FishFillet_GetVisibleFishFillet():CanItemBeAddedToCraft(bag, slot)
    elseif ZO_Smithing_IsSceneShowing() then
        return ZO_Smithing_GetActiveObject():CanItemBeAddedToCraft(bag, slot)
    elseif ZO_RETRAIT_STATION_MANAGER:IsRetraitSceneShowing() then
        return SYSTEMS:GetObject("retrait"):CanItemBeAddedToCraft(bag, slot)
    end
    return false
end
local function IsItemAlreadySlottedToCraft(inventorySlot)
    local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
    if SYSTEMS:IsShowing(ZO_ALCHEMY_SYSTEM_NAME) then
        return SYSTEMS:GetObject(ZO_ALCHEMY_SYSTEM_NAME):IsItemAlreadySlottedToCraft(bag, slot)
    elseif ZO_Enchanting_IsSceneShowing() then
    elseif ZO_FishFillet_IsSceneShowing() then
    elseif ZO_Smithing_IsSceneShowing() then
        return ZO_Smithing_GetActiveObject():IsItemAlreadySlottedToCraft(bag, slot)
    elseif ZO_RETRAIT_STATION_MANAGER:IsRetraitSceneShowing() then
        return SYSTEMS:GetObject("retrait"):IsItemAlreadySlottedToCraft(bag, slot)
    end
    return false
end
local function TryAddItemToCraft(inventorySlot)
    local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
    if SYSTEMS:IsShowing(ZO_ALCHEMY_SYSTEM_NAME) then
        SYSTEMS:GetObject(ZO_ALCHEMY_SYSTEM_NAME):AddItemToCraft(bag, slot)
    elseif ZO_Enchanting_IsSceneShowing() then
        ZO_Enchanting_GetVisibleEnchanting():AddItemToCraft(bag, slot)
    elseif ZO_FishFillet_IsSceneShowing() then
        ZO_FishFillet_GetVisibleFishFillet():AddItemToCraft(bag, slot)
    elseif ZO_Smithing_IsSceneShowing() then
        ZO_Smithing_GetActiveObject():AddItemToCraft(bag, slot)
    elseif ZO_RETRAIT_STATION_MANAGER:IsRetraitSceneShowing() then
        SYSTEMS:GetObject("retrait"):AddItemToCraft(bag, slot)
    end
    UpdateMouseoverCommand(inventorySlot)
end
local function TryRemoveItemFromCraft(inventorySlot)
    local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
    if SYSTEMS:IsShowing(ZO_ALCHEMY_SYSTEM_NAME) then
        SYSTEMS:GetObject(ZO_ALCHEMY_SYSTEM_NAME):RemoveItemFromCraft(bag, slot)
    elseif ZO_Enchanting_IsSceneShowing() then
    elseif ZO_Smithing_IsSceneShowing() then
        ZO_Smithing_GetActiveObject():RemoveItemFromCraft(bag, slot)
    elseif ZO_RETRAIT_STATION_MANAGER:IsRetraitSceneShowing() then
        SYSTEMS:GetObject("retrait"):RemoveItemFromCraft(bag, slot)
    elseif ZO_FishFillet_IsSceneShowing() then
        ZO_FishFillet_GetActiveObject():RemoveItemFromCraft(bag, slot)
    end
    UpdateMouseoverCommand(inventorySlot)
end
local function TryRemoveAllFromCraft()
    if ZO_Enchanting_IsSceneShowing() then
    elseif ZO_Smithing_IsSceneShowing() then
    end
end
local function IsCraftingSlotType(slotType)
    return slotType == SLOT_TYPE_CRAFTING_COMPONENT
        or slotType == SLOT_TYPE_PENDING_CRAFTING_COMPONENT
        or slotType == SLOT_TYPE_MULTIPLE_PENDING_CRAFTING_COMPONENTS
        or slotType == SLOT_TYPE_SMITHING_MATERIAL
        or slotType == SLOT_TYPE_SMITHING_STYLE
        or slotType == SLOT_TYPE_SMITHING_TRAIT
        or slotType == SLOT_TYPE_SMITHING_BOOSTER
        or slotType == SLOT_TYPE_PENDING_RETRAIT_ITEM
end
local function ShouldHandleClick(inventorySlot)
    local slotType = ZO_InventorySlot_GetType(inventorySlot)
    -- TODO: Really just needs to check if a slot has something in it and isn't locked.
    -- Needs to support all types. Also, bag/bank slots always have something because
    -- inventory is a list...only occupied rows are shown.
    if slotType == SLOT_TYPE_ITEM or slotType == SLOT_TYPE_BANK_ITEM then
        -- TODO: Check locked state here...locked slots do nothing?
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if PLAYER_INVENTORY:IsSlotOccupied(bag, index) then
            return true
        end
        return false
    elseif IsCraftingSlotType(slotType) then
        return not ZO_CraftingUtils_IsPerformingCraftProcess()
    end
    return true
end
local g_slotActions = ZO_InventorySlotActions:New()
local function DiscoverSlotActionFromType(actionContainer, inventorySlot, ...)
    local slotType = ZO_InventorySlot_GetType(inventorySlot)
    local action = actionContainer[slotType]
    if action then
        action(inventorySlot, ...)
    end
end
local function DefaultUseItemFunction(inventorySlot, slotActions)
    if CanUseItem(inventorySlot) then
        local bag, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
        local onUseType = GetItemUseType(bag, slotIndex)
        if onUseType == ITEM_USE_TYPE_COMBINATION then
            slotActions:AddSlotAction(SI_ITEM_ACTION_USE, function() ZO_InventorySlot_InitiateConfirmUseItem(inventorySlot) end, "primary", nil, {visibleWhenDead = false})
        else
            slotActions:AddSlotAction(SI_ITEM_ACTION_USE, function() TryUseItem(inventorySlot) end, "primary", nil, {visibleWhenDead = false})
        end
    end
end
local useActions =
{
    [SLOT_TYPE_QUEST_ITEM] = function(inventorySlot, slotActions)
        if CanUseItemQuestItem(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_USE, function() TryUseQuestItem(inventorySlot) end, "primary", nil, {visibleWhenDead = true})
        end
    end,
    [SLOT_TYPE_ITEM] = DefaultUseItemFunction,
    [SLOT_TYPE_GAMEPAD_INVENTORY_ITEM] = DefaultUseItemFunction,
    [SLOT_TYPE_CRAFT_BAG_ITEM] = DefaultUseItemFunction,
    [SLOT_TYPE_COLLECTIONS_INVENTORY] = function(inventorySlot, slotActions)
        local textEnum
        local category = inventorySlot.categoryType
        if category == COLLECTIBLE_CATEGORY_TYPE_MEMENTO then
            textEnum = SI_COLLECTIBLE_ACTION_USE
        elseif inventorySlot.active then
            if category == COLLECTIBLE_CATEGORY_TYPE_ASSISTANT or category == COLLECTIBLE_CATEGORY_TYPE_VANITY_PET or category == COLLECTIBLE_CATEGORY_TYPE_COMPANION then
                textEnum = SI_COLLECTIBLE_ACTION_DISMISS
            else
                textEnum = SI_COLLECTIBLE_ACTION_PUT_AWAY
            end
        else
            textEnum = SI_COLLECTIBLE_ACTION_SET_ACTIVE
        end
        local useCollectibleCallback = function()
            local collectibleData = ZO_COLLECTIBLE_DATA_MANAGER:GetCollectibleDataById(inventorySlot.collectibleId)
            collectibleData:Use(GAMEPLAY_ACTOR_CATEGORY_PLAYER)
        end
        slotActions:AddSlotAction(textEnum, useCollectibleCallback, "primary", nil, {visibleWhenDead = false})
    end,
}
local function MarkAsPlayerLockedHelper(bag, index, isPlayerLocked)
    SetItemIsPlayerLocked(bag, index, isPlayerLocked)
    PlaySound(isPlayerLocked and SOUNDS.INVENTORY_ITEM_LOCKED or SOUNDS.INVENTORY_ITEM_UNLOCKED)
end
local function MarkAsJunkHelper(bag, index, isJunk)
    SetItemIsJunk(bag, index, isJunk)
    PlaySound(isJunk and SOUNDS.INVENTORY_ITEM_JUNKED or SOUNDS.INVENTORY_ITEM_UNJUNKED)
end
local function GetBagItemLink(inventorySlot, linkStyle)
    local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local slotType = ZO_InventorySlot_GetType(inventorySlot)
    if(slotType == SLOT_TYPE_EQUIPMENT or slotType == SLOT_TYPE_DYEABLE_EQUIPMENT) then
        local _, stackCount = GetItemInfo(bag, index)
        if(stackCount == 0) then
            return -- nothing here, can't link
        end
    end
    return GetItemLink(bag, index, linkStyle)
end
local function GetQuestItemSlotLink(inventorySlot, linkStyle)
    if(inventorySlot.toolIndex) then
        return GetQuestToolLink(inventorySlot.questIndex, inventorySlot.toolIndex, linkStyle)
    else
        return GetQuestItemLink(inventorySlot.questIndex, inventorySlot.stepIndex, inventorySlot.conditionIndex, linkStyle)
    end
end
local function GetInventoryCollectibleLink(slot, linkStyle)
    return GetCollectibleLink(slot.collectibleId, linkStyle)
end
local function GetLootLink(lootSlot, linkStyle)
    if not lootSlot.lootEntry.currencyType then
        return GetLootItemLink(lootSlot.lootEntry.lootId, linkStyle)
    end
end
local function GetAchievementRewardLink(achievementRewardItem, linkStyle)
    local achievementId = ZO_Inventory_GetBagAndIndex(achievementRewardItem)
    local hasRewardItem = GetAchievementRewardItem(achievementId)
    if hasRewardItem then
        return GetAchievementItemLink(achievementId, linkStyle)
    end
end
local function GetSmithingBoosterLink(inventorySlot, linkStyle)
    return GetSmithingImprovementItemLink(inventorySlot.craftingType, inventorySlot.index, linkStyle)
end
local function GetTradingHouseSearchResultLink(inventorySlot, linkStyle)
    return GetTradingHouseSearchResultItemLink(ZO_Inventory_GetSlotIndex(inventorySlot), linkStyle)
end
local function GetTradingHouseListingLink(inventorySlot, linkStyle)
    return GetTradingHouseListingItemLink(ZO_Inventory_GetSlotIndex(inventorySlot), linkStyle)
end
local function GetGuildSpecificLink(inventorySlot, linkStyle)
    return GetGuildSpecificItemLink(ZO_Inventory_GetSlotIndex(inventorySlot), linkStyle)
end
local function IsCraftingActionVisible()
end
local function LinkHelper(slotActions, actionName, link)
    if link and link ~= "" then
        if actionName == "link_to_chat" and IsChatSystemAvailableForCurrentPlatform() then
            local linkFn = function()
                local formattedLink = zo_strformat(SI_TOOLTIP_ITEM_NAME, link)
                if IsInGamepadPreferredMode() then
                    ZO_LinkHandler_InsertLinkAndSubmit(formattedLink)
                else
                    ZO_LinkHandler_InsertLink(formattedLink)
                end
            end
            slotActions:AddSlotAction(SI_ITEM_ACTION_LINK_TO_CHAT, linkFn, "secondary", nil, {visibleWhenDead = true})
        elseif actionName == "report_item" and GetLinkType(link) == LINK_TYPE_ITEM then
            slotActions:AddSlotAction(SI_ITEM_ACTION_REPORT_ITEM, 
                                        function()
                                            if IsInGamepadPreferredMode() then
                                                KEYBIND_STRIP:RemoveAllKeyButtonGroups()
                                                HELP_ITEM_ASSISTANCE_GAMEPAD:InitWithDetails(link)
                                                -- if we open up the help menu while interacting, we want to make sure that we are not
                                                -- just pushing the previous scene onto the stack since it will end the interaction
                                                -- and make the scene invalid when coming back to it after the help scene is closed
                                                local sceneName = HELP_ITEM_ASSISTANCE_GAMEPAD:GetSceneName()
                                                if INTERACT_WINDOW:IsInteracting() then
                                                    SCENE_MANAGER:Show(sceneName)
                                                else
                                                    SCENE_MANAGER:Push(sceneName)
                                                end
                                            else
                                                HELP_CUSTOMER_SUPPORT_KEYBOARD:OpenScreen(HELP_CUSTOMER_SERVICE_ITEM_ASSISTANCE_KEYBOARD:GetFragment())
                                                HELP_CUSTOMER_SERVICE_ITEM_ASSISTANCE_KEYBOARD:SetDetailsFromItemLink(link)
                                            end
                                        end,
                                        "secondary")
        end
    end
end
-- TODO: Remove implementation dependencies by writing objects that encapsulate all the fields like .componentId, or .lootEntry.lootId, etc...)
-- The need for this table would be removed by allowing a single construct like: slotActions:AddSlotAction(str_id, function() inventorySlot:LinkToChat() end, ...)
local linkHelperActions =
{
    [SLOT_TYPE_QUEST_ITEM] =                    function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetQuestItemSlotLink, inventorySlot)) end,
    [SLOT_TYPE_ITEM] =                          function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_EQUIPMENT] =                     function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_BANK_ITEM] =                     function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_GUILD_BANK_ITEM] =               function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_MY_TRADE] =                      function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetTradeItemLink, TRADE_ME, inventorySlot.index)) end,
    [SLOT_TYPE_THEIR_TRADE] =                   function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetTradeItemLink, TRADE_THEM, inventorySlot.index)) end,
    [SLOT_TYPE_STORE_BUY] =                     function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetStoreItemLink, inventorySlot.index)) end,
    [SLOT_TYPE_BUY_MULTIPLE] =                  function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetStoreItemLink, inventorySlot.index)) end,
    [SLOT_TYPE_STORE_BUYBACK] =                 function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBuybackItemLink, inventorySlot.index)) end,
    [SLOT_TYPE_MAIL_QUEUED_ATTACHMENT] =        function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetMailQueuedAttachmentLink, GetQueuedItemAttachmentSlotIndex(inventorySlot))) end,
    [SLOT_TYPE_MAIL_ATTACHMENT] =               function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetAttachedItemLink, MAIL_INBOX:GetOpenMailId(), ZO_Inventory_GetSlotIndex(inventorySlot))) end,
    [SLOT_TYPE_ACHIEVEMENT_REWARD] =            function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetAchievementRewardLink, inventorySlot)) end,
    [SLOT_TYPE_LOOT] =                          function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetLootLink, inventorySlot)) end,
    [SLOT_TYPE_TRADING_HOUSE_POST_ITEM] =       function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_REPAIR] =                        function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_CRAFTING_COMPONENT] =            function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_PENDING_CRAFTING_COMPONENT] =    function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_SMITHING_MATERIAL] =             function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetSmithingPatternMaterialItemLink, inventorySlot.patternIndex, inventorySlot.materialIndex)) end,
    [SLOT_TYPE_SMITHING_STYLE] =                function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetItemStyleMaterialLink, inventorySlot.styleIndex)) end,
    [SLOT_TYPE_SMITHING_TRAIT] =                function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, inventorySlot.traitType ~= ITEM_TRAIT_TYPE_NONE and ZO_LinkHandler_CreateChatLink(GetSmithingTraitItemLink, inventorySlot.traitIndex)) end,
    [SLOT_TYPE_SMITHING_BOOSTER] =              function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetSmithingBoosterLink, inventorySlot)) end,
    [SLOT_TYPE_DYEABLE_EQUIPMENT] =             function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_TRADING_HOUSE_ITEM_RESULT] =     function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetTradingHouseSearchResultLink, inventorySlot)) end,
    [SLOT_TYPE_TRADING_HOUSE_ITEM_LISTING] =    function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetTradingHouseListingLink, inventorySlot)) end,
    [SLOT_TYPE_GUILD_SPECIFIC_ITEM] =           function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetGuildSpecificLink, inventorySlot)) end,
    [SLOT_TYPE_GAMEPAD_INVENTORY_ITEM] =        function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_COLLECTIONS_INVENTORY] =         function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetInventoryCollectibleLink, inventorySlot)) end,
    [SLOT_TYPE_CRAFT_BAG_ITEM] =                function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
    [SLOT_TYPE_PENDING_RETRAIT_ITEM] =          function(inventorySlot, slotActions, actionName) LinkHelper(slotActions, actionName, ZO_LinkHandler_CreateChatLink(GetBagItemLink, inventorySlot)) end,
}
---- Quickslot Action Handlers ----
local QUICKSLOT_SHARED_OPTIONS = {visibleWhenDead = true}
local function AddQuickslotRemoveAction(slotActions, slot)
    slotActions:AddSlotAction(SI_ITEM_ACTION_REMOVE_FROM_QUICKSLOT, function() ClearSlot(slot, HOTBAR_CATEGORY_QUICKSLOT_WHEEL) end, "primary", nil, QUICKSLOT_SHARED_OPTIONS)
end
local function AddQuickslotAddAction(callback, slotActions)
    slotActions:AddSlotAction(SI_ITEM_ACTION_MAP_TO_QUICKSLOT, callback, "primary", nil, QUICKSLOT_SHARED_OPTIONS)
end
local function ItemQuickslotAction(inventorySlot, slotActions)
    if QUICKSLOT_KEYBOARD:AreQuickSlotsShowing() then
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        local currentSlot = FindActionSlotMatchingItem(bag, index, HOTBAR_CATEGORY_QUICKSLOT_WHEEL)
        if currentSlot then
            AddQuickslotRemoveAction(slotActions, currentSlot)
        else
            local validSlot = GetFirstFreeValidSlotForItem(bag, index, HOTBAR_CATEGORY_QUICKSLOT_WHEEL)
            if validSlot then
                AddQuickslotAddAction(function()
                     SelectSlotItem(bag, index, validSlot, HOTBAR_CATEGORY_QUICKSLOT_WHEEL)
                 end, slotActions)
            end
        end
    end
end
local function ApplySimpleQuickslotAction(slotActions, actionType, actionId)
    if QUICKSLOT_KEYBOARD:AreQuickSlotsShowing() then
        local currentSlot = FindActionSlotMatchingSimpleAction(actionType, actionId, HOTBAR_CATEGORY_QUICKSLOT_WHEEL)
        if currentSlot then
            AddQuickslotRemoveAction(slotActions, currentSlot)
        else
            local validSlot = GetFirstFreeValidSlotForSimpleAction(actionType, actionId, HOTBAR_CATEGORY_QUICKSLOT_WHEEL)
            if validSlot then
                AddQuickslotAddAction(function()
                    SelectSlotSimpleAction(actionType, actionId, validSlot, HOTBAR_CATEGORY_QUICKSLOT_WHEEL)
                end, slotActions)
            end
        end
    end
end
local function CollectibleQuickslotAction(slot, slotActions)
    ApplySimpleQuickslotAction(slotActions, ACTION_TYPE_COLLECTIBLE, slot.collectibleId)
end
local function QuestItemQuickslotAction(slot, slotActions)
    local questItemId
    if slot.toolIndex then
        questItemId = GetQuestToolQuestItemId(slot.questIndex, slot.toolIndex)
    else
        questItemId = GetQuestConditionQuestItemId(slot.questIndex, slot.stepIndex, slot.conditionIndex)
    end
    ApplySimpleQuickslotAction(slotActions, ACTION_TYPE_QUEST_ITEM, questItemId)
end
internalassert(ACTION_TYPE_MAX_VALUE == 10, "Update quickslot actions")
local quickslotActions =
{
    [SLOT_TYPE_ITEM] = ItemQuickslotAction,
    [SLOT_TYPE_GAMEPAD_INVENTORY_ITEM] = ItemQuickslotAction,
    [SLOT_TYPE_COLLECTIONS_INVENTORY] = CollectibleQuickslotAction,
    [SLOT_TYPE_QUEST_ITEM] = QuestItemQuickslotAction,
}
---- Rename Action Handlers ----
local renameActions = 
{
    [SLOT_TYPE_COLLECTIONS_INVENTORY] = function(slot, slotActions)
        local collectibleId = slot.collectibleId
        local collectibleData = ZO_COLLECTIBLE_DATA_MANAGER:GetCollectibleDataById(collectibleId)
        if collectibleData and collectibleData:IsRenameable() then
            slotActions:AddSlotAction(SI_COLLECTIBLE_ACTION_RENAME, ZO_CollectionsBook.GetShowRenameDialogClosure(collectibleId), "keybind1")
        end
    end
}
local actionHandlers =
{
    ["use"] = function(inventorySlot, slotActions)
        DiscoverSlotActionFromType(useActions, inventorySlot, slotActions)
    end,
    ["mail_attach"] = function(inventorySlot, slotActions)
        if IsSendingMail() and not IsItemAlreadyAttachedToMail(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_MAIL_ATTACH, function() TryMailItem(inventorySlot) end, "primary")
        end
    end,
    ["mail_detach"] = function(inventorySlot, slotActions)
        if IsSendingMail() and IsItemAlreadyAttachedToMail(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_MAIL_DETACH, function() RemoveQueuedAttachment(inventorySlot) end, "primary")
        end
    end,
    ["bank_deposit"] = function(inventorySlot, slotActions)
        if IsBankOpen() then
            slotActions:AddSlotAction(SI_ITEM_ACTION_BANK_DEPOSIT, function() TryBankItem(inventorySlot) end, "primary")
        end
    end,
    ["bank_withdraw"] = function(inventorySlot, slotActions)
        if IsBankOpen() then
            slotActions:AddSlotAction(SI_ITEM_ACTION_BANK_WITHDRAW, function() TryBankItem(inventorySlot) end, "primary")
        end
    end,
    ["guild_bank_deposit"] = function(inventorySlot, slotActions)
        if GetSelectedGuildBankId() then
            slotActions:AddSlotAction(SI_ITEM_ACTION_BANK_DEPOSIT,  function()
                local bag, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
                TryGuildBankDepositItem(bag, slotIndex)
            end, "primary")
        end
    end,
    ["guild_bank_withdraw"] = function(inventorySlot, slotActions)
        if GetSelectedGuildBankId() then
            slotActions:AddSlotAction(SI_ITEM_ACTION_BANK_WITHDRAW, function()
                local _, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
                TryGuildBankWithdrawItem(slotIndex)
            end, "primary")
        end
    end,
    ["trade_add"] = function(inventorySlot, slotActions)
        if TRADE_WINDOW:IsTrading() and CanTradeItem(inventorySlot) and not IsItemAlreadyBeingTraded(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_TRADE_ADD, function() TryTradeItem(inventorySlot) end, "primary")
        end
    end,
    ["trade_remove"] = function(inventorySlot, slotActions)
        if TRADE_WINDOW:IsTrading() and IsItemAlreadyBeingTraded(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_TRADE_REMOVE, function() TryRemoveFromTrade(inventorySlot) end, "primary")
        end
    end,
    ["sell"] = function(inventorySlot, slotActions)
        if CanSellItem(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_SELL, function() TrySellItem(inventorySlot) end, "primary")
        end
    end,
    ["launder"] = function(inventorySlot, slotActions)
        if CanLaunderItem() then
            slotActions:AddSlotAction(SI_ITEM_ACTION_LAUNDER, function() TryLaunderItem(inventorySlot) end, "primary")
        end
    end,
    ["buy"] = function(inventorySlot, slotActions)
        if not inventorySlot.locked then
            slotActions:AddSlotAction(SI_ITEM_ACTION_BUY, function() BuyItemFromStore(inventorySlot) end, "primary")
        end
    end,
    ["buy_multiple"] = function(inventorySlot, slotActions)
        if CanBuyMultiple(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_BUY_MULTIPLE, function() TryBuyMultiple(inventorySlot) end, "secondary")
        end
    end,
    ["buyback"] = function(inventorySlot, slotActions)
        slotActions:AddSlotAction(SI_ITEM_ACTION_BUYBACK, function() BuybackItem(inventorySlot.index) end, "primary")
    end,
    ["equip"] = function(inventorySlot, slotActions)
        if CanEquipItem(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_EQUIP, function() TryEquipItem(inventorySlot) end, "primary", nil, {visibleWhenDead = false})
        end
    end,
    ["gamepad_equip"] = function(inventorySlot, slotActions)
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        local itemActorCategory = GetItemActorCategory(bag, index)
        local playerSceneShown = itemActorCategory == GAMEPLAY_ACTOR_CATEGORY_PLAYER and GAMEPAD_INVENTORY_ROOT_SCENE:IsShowing()
        local companionSceneShown = itemActorCategory == GAMEPLAY_ACTOR_CATEGORY_COMPANION and COMPANION_EQUIPMENT_GAMEPAD_SCENE:IsShowing()
        if (playerSceneShown or companionSceneShown) and IsEquipable(bag, index) and CanEquipItem(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_EQUIP, function()
                if playerSceneShown then
                    GAMEPAD_INVENTORY:TryEquipItem(inventorySlot)
                else
                    COMPANION_EQUIPMENT_GAMEPAD:TryEquipItem(inventorySlot)
                end
            end, "primary")
        end
    end,
    ["unequip"] = function(inventorySlot, slotActions)
        if CanUnequipItem(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_UNEQUIP, function() TryUnequipItem(inventorySlot) end, "primary")
        end
    end,
    ["take_loot"] = function(inventorySlot, slotActions)
        slotActions:AddSlotAction(SI_ITEM_ACTION_LOOT_TAKE, function() TakeLoot(inventorySlot) end, "primary", function() return false end)
    end,
    ["destroy"] = function(inventorySlot, slotActions)
        if not IsSlotLocked(inventorySlot) and ZO_InventorySlot_CanDestroyItem(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_DESTROY, function() ZO_InventorySlot_InitiateDestroyItem(inventorySlot) end, "secondary")
        end
    end,
    ["split_stack"] = function(inventorySlot, slotActions)
        if ZO_InventorySlot_CanSplitItemStack(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_SPLIT_STACK, function() ZO_InventorySlot_TrySplitStack(inventorySlot) end, "secondary")
        end
    end,
    ["enchant"] = function(inventorySlot, slotActions)
        if CanEnchantItem(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_ENCHANT, function() TryEnchantItem(inventorySlot) end, "keybind1")
        end
    end,
    ["charge"] = function(inventorySlot, slotActions)
        if CanChargeItem(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_CHARGE, function() TryChargingItem(inventorySlot) end, "keybind2")
        end
    end,
    ["kit_repair"] = function(inventorySlot, slotActions)
        if CanKitRepairItem(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_REPAIR, function() TryKitRepairItem(inventorySlot) end, "keybind2")
        end
    end,
    ["link_to_chat"] = function(inventorySlot, slotActions)
        if ZO_InventorySlot_GetStackCount(inventorySlot) > 0 or ZO_ItemSlot_GetAlwaysShowStackCount(inventorySlot) then
            DiscoverSlotActionFromType(linkHelperActions, inventorySlot, slotActions, "link_to_chat")
        end
    end,
    ["link_to_quest"] = function(inventorySlot, slotActions)
        slotActions:AddSlotAction(SI_ITEM_ACTION_SHOW_QUEST, function()  
            SYSTEMS:GetObject("questJournal"):OpenQuestJournalToQuest(inventorySlot.questIndex)
        end, "link_to_quest")
    end,
    ["report_item"] = function(inventorySlot, slotActions)
        if ZO_InventorySlot_GetStackCount(inventorySlot) > 0 or ZO_ItemSlot_GetAlwaysShowStackCount(inventorySlot) then
            DiscoverSlotActionFromType(linkHelperActions, inventorySlot, slotActions, "report_item")
        end
    end,
    ["mark_as_locked"] = function(inventorySlot, slotActions)
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if not IsSlotLocked(inventorySlot) and CanItemBePlayerLocked(bag, index) and not IsItemPlayerLocked(bag, index) and not (QUICKSLOT_KEYBOARD and QUICKSLOT_KEYBOARD:AreQuickSlotsShowing()) and not IsItemAlreadySlottedToCraft(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_MARK_AS_LOCKED, function() MarkAsPlayerLockedHelper(bag, index, true) end, "secondary")
        end
    end,
    ["unmark_as_locked"] = function(inventorySlot, slotActions)
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if not IsSlotLocked(inventorySlot) and CanItemBePlayerLocked(bag, index) and IsItemPlayerLocked(bag, index) and not (QUICKSLOT_KEYBOARD and QUICKSLOT_KEYBOARD:AreQuickSlotsShowing()) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_UNMARK_AS_LOCKED, function() MarkAsPlayerLockedHelper(bag, index, false) end, "secondary")
        end
    end,
    ["mark_as_junk"] = function(inventorySlot, slotActions)
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        local actorCategory = GetItemActorCategory(bag, index)
        if not IsInGamepadPreferredMode() and actorCategory ~= GAMEPLAY_ACTOR_CATEGORY_COMPANION and not IsSlotLocked(inventorySlot) and CanItemBeMarkedAsJunk(bag, index) and not IsItemJunk(bag, index) and not QUICKSLOT_KEYBOARD:AreQuickSlotsShowing() then
            slotActions:AddSlotAction(SI_ITEM_ACTION_MARK_AS_JUNK, function() MarkAsJunkHelper(bag, index, true) end, "secondary")
        end
    end,
    ["unmark_as_junk"] = function(inventorySlot, slotActions)
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if not IsInGamepadPreferredMode() and not IsSlotLocked(inventorySlot) and CanItemBeMarkedAsJunk(bag, index) and IsItemJunk(bag, index) and not QUICKSLOT_KEYBOARD:AreQuickSlotsShowing() then
            slotActions:AddSlotAction(SI_ITEM_ACTION_UNMARK_AS_JUNK, function() MarkAsJunkHelper(bag, index, false) end, "secondary")
        end
    end,
    ["quickslot"] = function(inventorySlot, slotActions)
        if not IsInGamepadPreferredMode() then
            DiscoverSlotActionFromType(quickslotActions, inventorySlot, slotActions)
        end
    end,
    ["trading_house_post"] = function(inventorySlot, slotActions)
        if TRADING_HOUSE_SEARCH:IsAtTradingHouse() and not IsItemAlreadyBeingPosted(inventorySlot) then
            slotActions:AddSlotAction(SI_TRADING_HOUSE_ADD_ITEM_TO_LISTING, function() TryInitiatingItemPost(inventorySlot) end, "primary")
        end
    end,
    ["trading_house_search_from_sell"] = function(inventorySlot, slotActions)
        if TRADING_HOUSE_SEARCH:IsAtTradingHouse() then
            slotActions:AddSlotAction(SI_TRADING_HOUSE_SEARCH_FROM_ITEM, function()
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                local itemLink = GetItemLink(bag, index)
                TRADING_HOUSE:SearchForItemLink(itemLink)
            end, "keybind3")
        end
    end,
    ["trading_house_search_from_results"] = function(inventorySlot, slotActions)
        if TRADING_HOUSE_SEARCH:IsAtTradingHouse() then
            slotActions:AddSlotAction(SI_TRADING_HOUSE_SEARCH_FROM_ITEM, function()
                local resultIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
                local itemLink = GetTradingHouseSearchResultItemLink(resultIndex)
                TRADING_HOUSE:SearchForItemLink(itemLink)
            end, "primary")
        end
    end,
    ["trading_house_search_from_listings"] = function(inventorySlot, slotActions)
        if TRADING_HOUSE_SEARCH:IsAtTradingHouse() then
            slotActions:AddSlotAction(SI_TRADING_HOUSE_SEARCH_FROM_ITEM, function()
                local listingIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
                local itemLink = GetTradingHouseListingItemLink(listingIndex)
                TRADING_HOUSE:SearchForItemLink(itemLink)
            end, "primary")
        end
    end,
    ["trading_house_remove_pending_post"] = function(inventorySlot, slotActions)
        if TRADING_HOUSE_SEARCH:IsAtTradingHouse() and IsItemAlreadyBeingPosted(inventorySlot) then
            slotActions:AddSlotAction(SI_TRADING_HOUSE_REMOVE_PENDING_POST, function() ClearItemPost(inventorySlot) end, "primary")
        end
    end,
    ["trading_house_buy_item"] = function(inventorySlot, slotActions)
        if TRADING_HOUSE:CanBuyItem(inventorySlot) then
            slotActions:AddSlotAction(SI_TRADING_HOUSE_BUY_ITEM, function() TryBuyingTradingHouseItem(inventorySlot) end, "primary")
        end
    end,
    ["trading_house_cancel_listing"] = function(inventorySlot, slotActions)
        slotActions:AddSlotAction(SI_TRADING_HOUSE_CANCEL_LISTING, function() TryCancellingTradingHouseListing(inventorySlot) end, "secondary")
    end,
    ["convert_to_imperial_style"] = function(inventorySlot, slotActions)
        local imperialStyleId = GetImperialStyleId()
        if CanConvertToStyle(inventorySlot, imperialStyleId) then
            local imperialStyleName = GetItemStyleName(imperialStyleId)
            slotActions:AddSlotAction(SI_ITEM_ACTION_CONVERT_TO_IMPERIAL_STYLE, function() ZO_Dialogs_ShowPlatformDialog("CONVERT_STYLE_MOVED", nil, { mainTextParams = { imperialStyleName }, titleParams = { imperialStyleName } }) end, "secondary")
        end
    end,
    ["convert_to_morag_tong_style"] = function(inventorySlot, slotActions)
        local moragTongStyleId = GetMoragTongStyleId()
        if CanConvertToStyle(inventorySlot, moragTongStyleId) then
            local moragStyleName = GetItemStyleName(moragTongStyleId)
            slotActions:AddSlotAction(SI_ITEM_ACTION_CONVERT_TO_MORAG_TONG_STYLE, function() ZO_Dialogs_ShowPlatformDialog("CONVERT_STYLE_MOVED", nil, { mainTextParams = { moragStyleName }, titleParams = { moragStyleName } }) end, "secondary")
        end
    end,
    ["vendor_repair"] = function(inventorySlot, slotActions)
        slotActions:AddSlotAction(SI_ITEM_ACTION_REPAIR, function() TryVendorRepairItem(inventorySlot) end, "primary")
    end,
                                
    ["add_to_craft"] = function(inventorySlot, slotActions)
        if not IsItemAlreadySlottedToCraft(inventorySlot) and CanItemBeAddedToCraft(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_ADD_TO_CRAFT, function() TryAddItemToCraft(inventorySlot) end, "primary", IsCraftingActionVisible)
        end
    end,
                            
    ["remove_from_craft"] = function(inventorySlot, slotActions)
        local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if bag and slot and IsItemAlreadySlottedToCraft(inventorySlot) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_REMOVE_FROM_CRAFT, function() TryRemoveItemFromCraft(inventorySlot) end, "primary", IsCraftingActionVisible)
        end
    end,
    ["remove_all_from_craft"] = function(inventorySlot, slotActions)
        slotActions:AddSlotAction(SI_ITEM_ACTION_REMOVE_FROM_CRAFT, TryRemoveAllFromCraft, "primary")
    end,
    ["buy_guild_specific_item"] = function(inventorySlot, slotActions)
        if TRADING_HOUSE:CanBuyItem(inventorySlot) then
            slotActions:AddSlotAction(SI_TRADING_HOUSE_BUY_ITEM, function() TryBuyingGuildSpecificItem(inventorySlot) end, "primary")
        end
    end,
    ["rename"] = function(inventorySlot, slotActions)
        DiscoverSlotActionFromType(renameActions, inventorySlot, slotActions)
    end,
    ["move_to_inventory"] = function(inventorySlot, slotActions)
        slotActions:AddSlotAction(SI_ITEM_ACTION_REMOVE_ITEMS_FROM_CRAFT_BAG, function() TryMoveToInventory(inventorySlot) end, "primary")
    end,
    ["move_to_craft_bag"] = function(inventorySlot, slotActions)
        local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if CanMoveToCraftBag(bagId, slotIndex) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_ADD_ITEMS_TO_CRAFT_BAG, function() TryMoveToCraftBag(bagId, slotIndex) end, "secondary")
        end
    end,
    ["preview_dye_stamp"] = function(inventorySlot, slotActions)
        local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if GetItemType(bag, slot) == ITEMTYPE_DYE_STAMP and IsCharacterPreviewingAvailable() then
            slotActions:AddSlotAction(SI_ITEM_ACTION_PREVIEW_DYE_STAMP, function() TryPreviewDyeStamp(inventorySlot) end, "primary")
        end
    end,
    ["show_map_keep_recall"] = function(inventorySlot, slotActions)
        local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if GetItemUseType(bag, slot) == ITEM_USE_TYPE_KEEP_RECALL_STONE then
            slotActions:AddSlotAction(SI_ITEM_ACTION_SHOW_MAP, function() TryShowRecallMap(inventorySlot) end, "primary")
        end
    end,
    ["start_skill_respec"] = function(inventorySlot, slotActions)
        local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
        local itemUseType = GetItemUseType(bag, slot)
        if itemUseType == ITEM_USE_TYPE_SKILL_RESPEC or itemUseType == ITEM_USE_TYPE_MORPH_RESPEC then
            slotActions:AddSlotAction(SI_ITEM_ACTION_START_SKILL_RESPEC, function() TryStartSkillRespec(inventorySlot) end, "primary")
        end
    end,
    ["start_attribute_respec"] = function(inventorySlot, slotActions)
        local bag, slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
        local itemUseType = GetItemUseType(bag, slot)
        if itemUseType == ITEM_USE_TYPE_ATTRIBUTE_RESPEC then
            slotActions:AddSlotAction(SI_ITEM_ACTION_START_ATTRIBUTE_RESPEC, function() TryStartAttributeRespec(inventorySlot) end, "primary")
        end
    end,
    ["bind"] = function(inventorySlot, slotActions)
        if not IsSlotLocked(inventorySlot) then
            local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
            if ZO_InventorySlot_WillItemBecomeBoundOnEquip(bagId, slotIndex) then
                slotActions:AddSlotAction(SI_ITEM_ACTION_BIND, function() TryBindItem(bagId, slotIndex) end, "secondary", nil, {visibleWhenDead = false})
            end
        end
    end,
    ["preview"] = function(inventorySlot, slotActions)
        local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
        local itemActorCategory = GetItemActorCategory(bag, index)
        -- Companion preview is not yet supported
         if itemActorCategory == GAMEPLAY_ACTOR_CATEGORY_COMPANION then
            return false
        end
        local itemPreview = SYSTEMS:GetObject("itemPreview")
        if itemPreview:GetFragment():IsShowing() and not IsInGamepadPreferredMode() and CanInventoryItemBePreviewed(bag, index) and IsCharacterPreviewingAvailable() then
            slotActions:AddSlotAction(SI_ITEM_ACTION_PREVIEW, function() TryPreviewItem(bag, index) end, "keybind1")
        end
    end,
    ["place_furniture"] = function(inventorySlot, slotActions)
        local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
        if ZO_CanPlaceItemInCurrentHouse(bagId, slotIndex) then
            slotActions:AddSlotAction(SI_ITEM_ACTION_PLACE_FURNITURE, function() ZO_TryPlaceFurnitureFromInventorySlot(bagId, slotIndex) end)
        end
    end,
}
local NON_INTERACTABLE_ITEM_ACTIONS = { "link_to_chat", "report_item" }
-- Order the possible action types in priority order, actions are marked as primary/secondary in the functions above
-- The order of the rest of the secondary actions in the table determines the order they appear on the context menu
local potentialActionsForSlotType =
{
    [SLOT_TYPE_QUEST_ITEM] =                           { "quickslot", "use", "link_to_chat", "link_to_quest" },
    [SLOT_TYPE_ITEM] =                                 { "quickslot", "mail_attach", "mail_detach", "trade_add", "trade_remove", "trading_house_post", "trading_house_remove_pending_post", "trading_house_search_from_sell", "bank_deposit", "guild_bank_deposit", "sell", "launder", "place_furniture", "equip", "use", "preview_dye_stamp", "show_map_keep_recall", "start_skill_respec", "start_attribute_respec", "split_stack", "enchant", "preview", "mark_as_locked", "unmark_as_locked", "bind", "charge", "kit_repair", "move_to_craft_bag", "link_to_chat", "mark_as_junk", "unmark_as_junk", "convert_to_imperial_style", "convert_to_morag_tong_style", "destroy", "report_item" },
    [SLOT_TYPE_EQUIPMENT] =                            { "unequip", "enchant", "mark_as_locked", "unmark_as_locked", "bind", "charge", "kit_repair", "link_to_chat", "convert_to_imperial_style", "convert_to_morag_tong_style", "destroy", "report_item" },
    [SLOT_TYPE_MY_TRADE] =                             { "trade_remove", "link_to_chat", "report_item" },
    [SLOT_TYPE_THEIR_TRADE] =                          NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_STORE_BUY] =                            { "buy", "buy_multiple", "link_to_chat", "report_item" },
    [SLOT_TYPE_STORE_BUYBACK] =                        { "buyback", "link_to_chat", "report_item" },
    [SLOT_TYPE_BUY_MULTIPLE] =                         NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_BANK_ITEM] =                            { "bank_withdraw", "place_furniture", "split_stack", "mark_as_locked", "unmark_as_locked", "bind", "link_to_chat", "mark_as_junk", "unmark_as_junk", "report_item" },
    [SLOT_TYPE_GUILD_BANK_ITEM] =                      { "guild_bank_withdraw", "link_to_chat", "report_item" },
    [SLOT_TYPE_MAIL_QUEUED_ATTACHMENT] =               { "mail_detach", "link_to_chat", "report_item" },
    [SLOT_TYPE_MAIL_ATTACHMENT] =                      NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_LOOT] =                                 { "take_loot", "link_to_chat", "report_item" },
    [SLOT_TYPE_ACHIEVEMENT_REWARD] =                   NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_TRADING_HOUSE_POST_ITEM] =              { "trading_house_remove_pending_post", "link_to_chat", "report_item" },
    [SLOT_TYPE_TRADING_HOUSE_ITEM_RESULT] =            { "trading_house_buy_item", "link_to_chat", "trading_house_search_from_results" },
    [SLOT_TYPE_TRADING_HOUSE_ITEM_LISTING] =           { "trading_house_cancel_listing", "link_to_chat", "trading_house_search_from_listings" },
    [SLOT_TYPE_REPAIR] =                               { "vendor_repair", "link_to_chat", "destroy", "report_item" },
    [SLOT_TYPE_PENDING_REPAIR] =                       NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_CRAFTING_COMPONENT] =                   { "add_to_craft", "remove_from_craft", "mark_as_locked", "unmark_as_locked", "link_to_chat", "report_item" },
    [SLOT_TYPE_PENDING_CRAFTING_COMPONENT] =           { "remove_from_craft", "link_to_chat", "report_item" },
    [SLOT_TYPE_MULTIPLE_PENDING_CRAFTING_COMPONENTS] = { "remove_all_from_craft", },
    [SLOT_TYPE_SMITHING_MATERIAL] =                    NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_SMITHING_STYLE] =                       NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_SMITHING_TRAIT] =                       NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_SMITHING_BOOSTER] =                     NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_DYEABLE_EQUIPMENT] =                    NON_INTERACTABLE_ITEM_ACTIONS,
    [SLOT_TYPE_GUILD_SPECIFIC_ITEM] =                  { "buy_guild_specific_item", "link_to_chat" },
    [SLOT_TYPE_GAMEPAD_INVENTORY_ITEM] =               { "quickslot", "mail_attach", "mail_detach", "bank_deposit", "guild_bank_deposit", "place_furniture", "gamepad_equip", "unequip", "use", "preview_dye_stamp", "start_skill_respec", "start_attribute_respec", "show_map_keep_recall", "split_stack", "enchant", "mark_as_locked", "unmark_as_locked", "bind", "charge", "kit_repair", "move_to_craft_bag", "link_to_chat", "convert_to_imperial_style", "convert_to_morag_tong_style", "destroy", "report_item" },
    [SLOT_TYPE_COLLECTIONS_INVENTORY] =                { "quickslot", "use", "rename", "link_to_chat" },
    [SLOT_TYPE_CRAFT_BAG_ITEM] =                       { "move_to_inventory", "use", "link_to_chat", "report_item" },
    [SLOT_TYPE_PENDING_RETRAIT_ITEM] =                 { "remove_from_craft", "link_to_chat", "report_item" },
}
-- Checks to see if a certain slot type should completely disable all actions
local blanketDisableActionsForSlotType =
{
    [SLOT_TYPE_EQUIPMENT] = function(inventorySlot)
        return ZO_Character_IsReadOnly()
    end,
}
function ZO_InventorySlot_DiscoverSlotActionsFromActionList(inventorySlot, slotActions)
    local slotType = ZO_InventorySlot_GetType(inventorySlot)
    local potentialActions = potentialActionsForSlotType[slotType]
    if potentialActions then
        if not blanketDisableActionsForSlotType[slotType] or not blanketDisableActionsForSlotType[slotType]() then
            for _, action in ipairs(potentialActions) do
                local actionHandler = actionHandlers[action]
                actionHandler(inventorySlot, slotActions)
            end
        end
    end
end
local function PerClickInitializeActions(inventorySlot, useContextMenu)
    g_slotActions:Clear()
    g_slotActions:SetInventorySlot(inventorySlot)
    g_slotActions:SetContextMenuMode(useContextMenu)
    ZO_InventorySlot_DiscoverSlotActionsFromActionList(inventorySlot, g_slotActions)
end
function ZO_InventorySlot_ShowContextMenu(inventorySlot)
    PerClickInitializeActions(inventorySlot, INVENTORY_SLOT_ACTIONS_USE_CONTEXT_MENU)
    g_slotActions:Show()
end
function ZO_InventorySlot_DoPrimaryAction(inventorySlot)
    inventorySlot = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
    PerClickInitializeActions(inventorySlot, INVENTORY_SLOT_ACTIONS_PREVENT_CONTEXT_MENU)
    local actionPerformed = g_slotActions:DoPrimaryAction()
    --If no action was performed, check to see if the item used can only be used from the quickslot menu.
    if actionPerformed == false then
        local itemLink = GetItemLink(inventorySlot.bagId, inventorySlot.slotIndex)
        if IsItemLinkOnlyUsableFromQuickslot(itemLink) then
            ZO_AlertEvent(EVENT_UI_ERROR, SI_ITEM_FORMAT_STR_ONLY_USABLE_FROM_ACTION_SLOT)
        end
    end
end
function ItemSlotHasFilterType(slotFilterData, itemFilterType)
    local hasFilterType = false
    if slotFilterData ~= nil and itemFilterType ~= nil then
        for i = 1, #slotFilterData do
            if slotFilterData[i] == itemFilterType then
                hasFilterType = true
                break
            end
        end
    end
    return hasFilterType
end
function ZO_InventorySlot_OnSlotClicked(inventorySlot, button)
    inventorySlot = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
    if button == MOUSE_BUTTON_INDEX_LEFT then
        -- Left clicks are only used as drops at the moment, use the receive drag handlers
        ZO_InventorySlot_OnReceiveDrag(inventorySlot)
    elseif button == MOUSE_BUTTON_INDEX_RIGHT then
        -- Right clicks only open the context menu
        if ShouldHandleClick(inventorySlot) then
            ZO_InventorySlot_ShowContextMenu(inventorySlot)
        end
    end
end
--
-- Mouse Over
--
local SHOW_COLLECTIBLE_NICKNAME, SHOW_COLLECTIBLE_PURCHASABLE_HINT, SHOW_COLLECTIBLE_BLOCK_REASON = true, true, true
local InventoryEnter =
{
    [SLOT_TYPE_QUEST_ITEM] =
    {
        function(inventorySlot)
            if(inventorySlot) then
                if inventorySlot.toolIndex then
                    ItemTooltip:SetQuestTool(inventorySlot.questIndex, inventorySlot.toolIndex)
                else
                    ItemTooltip:SetQuestItem(inventorySlot.questIndex, inventorySlot.stepIndex, inventorySlot.conditionIndex)
                end
            end
            return true, ItemTooltip
        end,
    },
    [SLOT_TYPE_ITEM] =
    {
        function(inventorySlot)
            local data = ZO_Inventory_GetSlotDataForInventoryControl(inventorySlot)
            if data then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                ItemTooltip:SetBagItem(bag, index)
                return true, ItemTooltip
            else
                return false, ItemTooltip
            end
        end
    },
    [SLOT_TYPE_BANK_ITEM] =
    {
        function(inventorySlot)
            local data = ZO_Inventory_GetSlotDataForInventoryControl(inventorySlot)
            if data then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                ItemTooltip:SetBagItem(bag, index)
                return true, ItemTooltip
            else
                return false, ItemTooltip
            end
        end
    },
    [SLOT_TYPE_GUILD_BANK_ITEM] =
    {
        function(inventorySlot)
            local data = ZO_Inventory_GetSlotDataForInventoryControl(inventorySlot)
            if data then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                ItemTooltip:SetBagItem(bag, index)
                return true, ItemTooltip
            else
                return false, ItemTooltip
            end
        end
    },
    [SLOT_TYPE_EQUIPMENT] =
    {
        function(inventorySlot)
            local wornBag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            local isEquipped = GetWornItemInfo(wornBag, index)
            if isEquipped then
                ItemTooltip:SetWornItem(index, wornBag)
                return true, ItemTooltip
            else
                SetTooltipText(InformationTooltip, zo_strformat(SI_CHARACTER_EQUIP_SLOT_FORMAT, GetString("SI_EQUIPSLOT", index)))
                return true, InformationTooltip
            end
        end
    },
    [SLOT_TYPE_MY_TRADE] =
    {
        function(inventorySlot)
            local _, _, stackCount = GetTradeItemInfo(TRADE_ME, ZO_Inventory_GetSlotIndex(inventorySlot))
            if(stackCount > 0) then
                ItemTooltip:SetTradeItem(TRADE_ME, ZO_Inventory_GetSlotIndex(inventorySlot))
                return true, ItemTooltip
            end
        end
    },
    [SLOT_TYPE_THEIR_TRADE] =
    {
        function(inventorySlot)
            local _, _, stackCount = GetTradeItemInfo(TRADE_THEM, ZO_Inventory_GetSlotIndex(inventorySlot))
            if(stackCount > 0) then
                ItemTooltip:SetTradeItem(TRADE_THEM, ZO_Inventory_GetSlotIndex(inventorySlot))
                return true, ItemTooltip
            end
        end
    },
    [SLOT_TYPE_STORE_BUYBACK] =
    {
        function(inventorySlot)
            ItemTooltip:SetBuybackItem(inventorySlot.index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_STORE_BUY] =
    {
        function(inventorySlot)
            ItemTooltip:SetStoreItem(inventorySlot.index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_BUY_MULTIPLE] =
    {
        function(inventorySlot)
            ItemTooltip:SetStoreItem(inventorySlot.index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_MAIL_QUEUED_ATTACHMENT] =
    {
        function(inventorySlot)
            if inventorySlot.bagId then -- If this is because money looks like a queued attachment, we should probably split it out into its own fields in the compose mail pane...
                ItemTooltip:SetBagItem(inventorySlot.bagId, inventorySlot.slotIndex)
                return true, ItemTooltip
            end
        end
    },
    [SLOT_TYPE_MAIL_ATTACHMENT] =
    {
        function(inventorySlot)
            local attachmentIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
            if(attachmentIndex) then
                if inventorySlot.money then
                    if inventorySlot.money > 0 then
                        ZO_ItemTooltip_SetMoney(ItemTooltip, inventorySlot.money)
                        return true, ItemTooltip
                    end
                elseif(inventorySlot.stackCount > 0) then
                    ItemTooltip:SetAttachedMailItem(MAIL_INBOX:GetOpenMailId(), attachmentIndex)
                    return true, ItemTooltip
                end
            end
        end
    },
    [SLOT_TYPE_LOOT] =
    {
        function(inventorySlot)
            local entry = inventorySlot.lootEntry
            if entry then
                if entry.currencyType then
                    ItemTooltip:SetCurrency(entry.currencyType, entry.currencyAmount)
                    return true, ItemTooltip
                else
                    ItemTooltip:SetLootItem(entry.lootId)
                    return true, ItemTooltip
                end
            end
        end
    },
    [SLOT_TYPE_ACHIEVEMENT_REWARD] =
    {
        function(inventorySlot)
            ItemTooltip:SetAchievementRewardItem(inventorySlot.achievement.achievementId, inventorySlot.rewardIndex)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_PENDING_CHARGE] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            ItemTooltip:SetBagItem(bag, index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_ENCHANTMENT] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            ItemTooltip:SetBagItem(bag, index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_ENCHANTMENT_RESULT] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            ItemTooltip:SetItemUsingEnchantment(bag, index, inventorySlot.enchantmentBagId, inventorySlot.enchantmentSlotIndex)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_TRADING_HOUSE_POST_ITEM] =
    {
        function(inventorySlot)
            if(ZO_InventorySlot_GetStackCount(inventorySlot) > 0) then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                ItemTooltip:SetBagItem(bag, index)
                return true, ItemTooltip
            end
        end,
    },
    [SLOT_TYPE_TRADING_HOUSE_ITEM_RESULT] =
    {
        function(inventorySlot)
            local tradingHouseIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
            ItemTooltip:SetTradingHouseItem(tradingHouseIndex)
            return true, ItemTooltip
        end,
    },
    [SLOT_TYPE_TRADING_HOUSE_ITEM_LISTING] =
    {
        function(inventorySlot)
            local tradingHouseListingIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
            ItemTooltip:SetTradingHouseListing(tradingHouseListingIndex)
            return true, ItemTooltip
        end,
    },
    [SLOT_TYPE_REPAIR] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            ItemTooltip:SetBagItem(bag, index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_PENDING_REPAIR] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            ItemTooltip:SetBagItem(bag, index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_STACK_SPLIT] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            ItemTooltip:SetBagItem(bag, index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_CRAFTING_COMPONENT] =
    {
        function(inventorySlot)
            if not ZO_CraftingUtils_IsPerformingCraftProcess() then
                if SYSTEMS:IsShowing(ZO_ALCHEMY_SYSTEM_NAME) then
                    return true, nil -- no tooltip, but keep mouseover behavior
                end
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                ItemTooltip:SetBagItem(bag, index)
                if SCENE_MANAGER:IsShowing("enchanting") then
                    ENCHANTING:OnMouseEnterCraftingComponent(bag, index)
                end
                return true, ItemTooltip
            end
        end
    },
    [SLOT_TYPE_PENDING_CRAFTING_COMPONENT] =
    {
        function(inventorySlot)
            if not ZO_CraftingUtils_IsPerformingCraftProcess() then
                if SYSTEMS:IsShowing(ZO_ALCHEMY_SYSTEM_NAME) then
                    return true, nil -- no tooltip, but keep mouseover behavior
                end
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                if bag and index then
                    ItemTooltip:SetBagItem(bag, index)
                    return true, ItemTooltip
                end
            end
        end
    },
    [SLOT_TYPE_SMITHING_BOOSTER] =
    {
        function(inventorySlot)
            if not ZO_CraftingUtils_IsPerformingCraftProcess() then
                ItemTooltip:SetSmithingImprovementItem(inventorySlot.craftingType, inventorySlot.index)
                return true, ItemTooltip
            end
        end
    },
    [SLOT_TYPE_LIST_DIALOG_ITEM] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            ItemTooltip:SetBagItem(bag, index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_DYEABLE_EQUIPMENT] =
    {
        function(inventorySlot)
            local wornBag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            local isEquipped = GetWornItemInfo(wornBag, index)
            if isEquipped then
                ItemTooltip:SetWornItem(index, wornBag)
                return true, ItemTooltip
            else
                SetTooltipText(InformationTooltip, zo_strformat(SI_CHARACTER_EQUIP_SLOT_FORMAT, GetString("SI_EQUIPSLOT", index)))
                return true, InformationTooltip
            end
        end
    },
    [SLOT_TYPE_GUILD_SPECIFIC_ITEM] =
    {
        function(inventorySlot)
            local guildSpecificItemIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
            ItemTooltip:SetGuildSpecificItem(guildSpecificItemIndex)
            return true, ItemTooltip
        end,
    },
    [SLOT_TYPE_COLLECTIONS_INVENTORY] =
    {
        function(inventorySlot)
            ItemTooltip:SetCollectible(inventorySlot.collectibleId, SHOW_COLLECTIBLE_NICKNAME, SHOW_COLLECTIBLE_PURCHASABLE_HINT, SHOW_COLLECTIBLE_BLOCK_REASON)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_CRAFT_BAG_ITEM] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            ItemTooltip:SetBagItem(bag, index)
            return true, ItemTooltip
        end
    },
    [SLOT_TYPE_PENDING_RETRAIT_ITEM] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            if bag and index then
                ItemTooltip:SetBagItem(bag, index)
                return true, ItemTooltip
            end
            return false
        end
    },
}
local g_mouseoverCommand = ZO_ItemSlotActionsController:New(KEYBIND_STRIP_ALIGN_RIGHT, { "UI_SHORTCUT_SECONDARY", "UI_SHORTCUT_TERTIARY", "UI_SHORTCUT_QUATERNARY" })
-- defined local above
function UpdateMouseoverCommand(inventorySlot)
    -- we check if inventorySlot == nil here to ensure that slot keybinds are removed, even if we have switched from keyboard to gamepad.
    if not IsInGamepadPreferredMode() or inventorySlot == nil then
        g_mouseoverCommand:SetInventorySlot(inventorySlot)
    end
    if g_updateCallback then
        g_updateCallback(inventorySlot)
    end
end
end
    if not tooltip:IsControlHidden() then
        if not tooltip.showAnimation then
            tooltip.showAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("DelayedTooltipFadeAnimation", tooltip)
        end
        tooltip:SetAlpha(0)
        tooltip.showAnimation:PlayFromStart()
    end
end
local NO_COMPARISON_TOOLTIPS_FOR_SLOT_TYPE =
{
    [SLOT_TYPE_PENDING_CHARGE] = true,
    [SLOT_TYPE_ENCHANTMENT] = true,
    [SLOT_TYPE_ENCHANTMENT_RESULT] = true,
    [SLOT_TYPE_REPAIR] = true,
    [SLOT_TYPE_PENDING_REPAIR] = true,
    [SLOT_TYPE_CRAFTING_COMPONENT] = true,
    [SLOT_TYPE_PENDING_CRAFTING_COMPONENT] = true,
    [SLOT_TYPE_SMITHING_MATERIAL] = true,
    [SLOT_TYPE_SMITHING_STYLE] = true,
    [SLOT_TYPE_SMITHING_TRAIT] = true,
    [SLOT_TYPE_SMITHING_BOOSTER] = true,
    [SLOT_TYPE_LIST_DIALOG_ITEM] = true,
    [SLOT_TYPE_PENDING_RETRAIT_ITEM] = true,
    [SLOT_TYPE_TRADING_HOUSE_ITEM_LISTING] = true,
}
    if not control:IsHidden() and control.currencyControl then
        local currencyControls = { control.currencyControl }
        if type(control.currencyControl) == "table" then
            currencyControls = control.currencyControl
        end
        local cursorPositionX, cursorPositionY = GetUIMousePosition()
        for _, currencyControl in ipairs(currencyControls) do
            if not currencyControl:IsHidden() and currencyControl:IsPointInside(cursorPositionX, cursorPositionY) then
                ZO_CurrencyTemplate_OnMouseEnter(currencyControl)
            else
                ZO_CurrencyTemplate_OnMouseExit(currencyControl)
            end
        end
    end
end
function ZO_InventorySlot_OnMouseEnter(inventorySlot)
    local buttonPart, listPart, multiIconPart = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
    if inventorySlot.slotControlType == "listSlot" then
        if ZO_InventorySlot_GetStackCount(buttonPart) > 0 or ZO_InventorySlot_GetStackCount(listPart) > 0 then
            ZO_InventorySlot_SetControlScaledUp(buttonPart, true)
            ZO_InventorySlot_SetControlScaledUp(multiIconPart, true)
        end
    end
    InitializeTooltip(ItemTooltip)
    InitializeTooltip(InformationTooltip)
    ZO_InventorySlot_SetHighlightHidden(listPart, false)
    if inventorySlot.currencyControl then
        inventorySlot:SetHandler("OnUpdate", function() ZO_InventorySlot_OnUpdate(inventorySlot) end)
    end
    -- ESO-747254: This function will be called recursively in RunHandlers. Since
    -- we only want the tooltip build once, we only call RunHandlers on the initial
    -- call and not on the recursive calls. InitializeTooltips nees to be called regardless
    -- recursion since the recursive process will also call MouseExit and clear the tooltip.
    if inventorySlot.isBuildingTooltip then
        return false
    end
    inventorySlot.isBuildingTooltip = true
    local success, tooltipUsed = RunHandlers(InventoryEnter, buttonPart)
    inventorySlot.isBuildingTooltip = nil
    if success then
        if tooltipUsed == ItemTooltip and not NO_COMPARISON_TOOLTIPS_FOR_SLOT_TYPE[ZO_InventorySlot_GetType(buttonPart)] then
            tooltipUsed:HideComparativeTooltips()
            tooltipUsed:ShowComparativeTooltips()
            ZO_PlayShowAnimationOnComparisonTooltip(ComparativeTooltip1)
            ZO_PlayShowAnimationOnComparisonTooltip(ComparativeTooltip2)
            
            if inventorySlot.dataEntry then
                local bagId = inventorySlot.dataEntry.data.bagId
                local slotId = inventorySlot.dataEntry.data.slotIndex
                ZO_CharacterWindowStats_ShowComparisonValues(bagId, slotId)
            end
        end
        ItemTooltip:SetHidden(tooltipUsed ~= ItemTooltip)
        InformationTooltip:SetHidden(tooltipUsed ~= InformationTooltip)
        if tooltipUsed then
            if buttonPart.customTooltipAnchor then
                buttonPart.customTooltipAnchor(tooltipUsed, buttonPart, ComparativeTooltip1, ComparativeTooltip2)
            else
                ZO_Tooltips_SetupDynamicTooltipAnchors(tooltipUsed, buttonPart.tooltipAnchor or buttonPart, ComparativeTooltip1, ComparativeTooltip2)
            end
        end
        UpdateMouseoverCommand(buttonPart)
        return true
    else
        ItemTooltip:SetHidden(true)
        InformationTooltip:SetHidden(true)
        return false
    end
end
--
-- When the slot that the user is currently moused over changes (e.g. you equipped an item...)
-- this handler will force update the tooltip again.
--
    if slotControl then 
        if ItemTooltip:GetOwner() == slotControl or InformationTooltip:GetOwner() == slotControl or WINDOW_MANAGER:GetMouseOverControl() == slotControl then
            ZO_InventorySlot_OnMouseEnter(slotControl)
        end
    end
end
local function OnActiveWeaponPairChanged(event, activeWeaponPair)
    if(not ComparativeTooltip1:IsHidden() or not ComparativeTooltip2:IsHidden()) then
        local tooltipAttachedTo = ComparativeTooltip1:GetOwner()
        if tooltipAttachedTo then
            local tooltipAttachedToOwner = tooltipAttachedTo:GetOwner()
            if tooltipAttachedToOwner then
                ZO_InventorySlot_OnMouseEnter(tooltipAttachedToOwner)
            end
        end
    end
end
    if g_mouseoverCommand and g_mouseoverCommand.inventorySlot then
        UpdateMouseoverCommand(g_mouseoverCommand.inventorySlot) 
    end
end
CALLBACK_MANAGER:RegisterCallback("WornSlotUpdate", ZO_InventorySlot_HandleInventoryUpdate)
CALLBACK_MANAGER:RegisterCallback("InventorySlotUpdate", ZO_InventorySlot_HandleInventoryUpdate)
EVENT_MANAGER:RegisterForEvent("InventorySlot", EVENT_ACTIVE_WEAPON_PAIR_CHANGED, OnActiveWeaponPairChanged)
EVENT_MANAGER:RegisterForEvent("InventorySlot", EVENT_ACTION_SLOT_UPDATED, RefreshMouseOverCommandIfActive)
EVENT_MANAGER:RegisterForEvent("InventorySlot", EVENT_PLAYER_DEAD, RefreshMouseOverCommandIfActive)
EVENT_MANAGER:RegisterForEvent("InventorySlot", EVENT_PLAYER_REINCARNATED, RefreshMouseOverCommandIfActive)
EVENT_MANAGER:RegisterForEvent("InventorySlot", EVENT_VISUAL_LAYER_CHANGED, RefreshMouseOverCommandIfActive)
local function OnTradeSlotChanged(eventCode, who)
    if who == TRADE_ME then
    end
end
EVENT_MANAGER:RegisterForEvent("InventorySlot", EVENT_TRADE_ITEM_ADDED, OnTradeSlotChanged)
EVENT_MANAGER:RegisterForEvent("InventorySlot", EVENT_TRADE_ITEM_REMOVED, OnTradeSlotChanged)
EVENT_MANAGER:RegisterForEvent("InventorySlot", EVENT_TRADE_ITEM_UPDATED, OnTradeSlotChanged)
EVENT_MANAGER:RegisterForEvent("InventorySlot", EVENT_CRAFT_STARTED, function() g_slotActions:Clear() end)
--
-- Mouse Exit
--
    if not tooltip:IsControlHidden() then
        if tooltip.showAnimation then
            tooltip.showAnimation:PlayBackward()
        end
    end
end
function ZO_InventorySlot_OnMouseExit(inventorySlot)
    local buttonPart, listPart, multiIconPart = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
    ClearTooltip(ItemTooltip)
    ClearTooltip(InformationTooltip)
    ZO_PlayHideAnimationOnComparisonTooltip(ComparativeTooltip1)
    ZO_PlayHideAnimationOnComparisonTooltip(ComparativeTooltip2)
    ZO_InventorySlot_SetControlScaledUp(buttonPart, false)
    ZO_InventorySlot_SetControlScaledUp(multiIconPart, false)
    ZO_InventorySlot_SetHighlightHidden(listPart, true)
    --Perform any additional MouseExit actions
    if ZO_Enchanting_IsSceneShowing() then
    end
    if inventorySlot.currencyControl then
        inventorySlot:SetHandler("OnUpdate", nil)
    end
end
--
-- Drag Start
--
local InventoryDragStart =
{
    [SLOT_TYPE_ITEM] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            PickupInventoryItem(bag, index)
            return true
        end
    },    
    [SLOT_TYPE_BANK_ITEM] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            PickupInventoryItem(bag, index)
            return true
        end
    },
    [SLOT_TYPE_GUILD_BANK_ITEM] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            PickupInventoryItem(bag, index)
            return true
        end
    },
    [SLOT_TYPE_EQUIPMENT] =
    {
        function(inventorySlot)
            if not ZO_Character_IsReadOnly() then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                PickupEquippedItem(index, bag)
                return true
            end
        end
    },
    [SLOT_TYPE_MY_TRADE] =
    {
        function(inventorySlot)
            local index = ZO_Inventory_GetSlotIndex(inventorySlot)
            PickupTradeItem(index)
            return true
        end
    },
    [SLOT_TYPE_QUEST_ITEM] =
    {
        function(inventorySlot)
            TryPickupQuestItem(inventorySlot)
            return true
        end
    },
    [SLOT_TYPE_MAIL_QUEUED_ATTACHMENT] =
    {
        function(inventorySlot)
            -- Mail case shouldn't use ZO_Inventory_GetBagAndIndex, it's a good reason to actually wrap this stuff in a real object
            local bagId, slotIndex = inventorySlot.bagId, inventorySlot.slotIndex
            if bagId and slotIndex then
                RemoveQueuedItemAttachment(inventorySlot.slotIndex)
                PickupInventoryItem(bagId, slotIndex)
                return true
            end
        end
    },
    [SLOT_TYPE_STORE_BUY] =
    {
        function(inventorySlot)
            PickupStoreItem(inventorySlot.index)
            return true
        end
    },
    [SLOT_TYPE_STORE_BUYBACK] =
    {
        function(inventorySlot)
            PickupStoreBuybackItem(inventorySlot.index)
            return true
        end
    },
    [SLOT_TYPE_TRADING_HOUSE_POST_ITEM] =
    {
        function(inventorySlot)
            if(ZO_InventorySlot_GetStackCount(inventorySlot) > 0) then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                if IsItemStolen(bag, index) then
                    ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_STOLEN_ITEM_CANNOT_LIST_MESSAGE))
                    return false
                else
                    SetPendingItemPost(BAG_BACKPACK, 0, 0)
                    PickupInventoryItem(bag, index)
                    return true
                end
            end
        end
    },
    [SLOT_TYPE_REPAIR] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            PickupInventoryItem(bag, index)
            return true
        end
    },
    [SLOT_TYPE_CRAFTING_COMPONENT] =
    {
        function(inventorySlot)
            if not (ZO_CraftingUtils_IsPerformingCraftProcess() or IsItemAlreadySlottedToCraft(inventorySlot)) then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                PickupInventoryItem(bag, index)
                return true
            end
        end
    },
    [SLOT_TYPE_PENDING_CRAFTING_COMPONENT] =
    {
        function(inventorySlot)
            if not ZO_CraftingUtils_IsPerformingCraftProcess() then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                if bag and index then
                    if SYSTEMS:IsShowing(ZO_ALCHEMY_SYSTEM_NAME) then
                        SYSTEMS:GetObject(ZO_ALCHEMY_SYSTEM_NAME):RemoveItemFromCraft(bag, index)
                    elseif ZO_Enchanting_IsSceneShowing() then
                        ZO_Enchanting_GetVisibleEnchanting():RemoveItemFromCraft(bag, index)
                    elseif ZO_Smithing_IsSceneShowing() then
                        ZO_Smithing_GetActiveObject():RemoveItemFromCraft(bag, index)
                   elseif ZO_FishFillet_IsSceneShowing() then
                        ZO_FishFillet_GetActiveObject():RemoveItemFromCraft(bag, index)
                    end
                    PickupInventoryItem(bag, index)
                end
                return true
            end
        end
    },
    [SLOT_TYPE_COLLECTIONS_INVENTORY] =
    {
        function(inventorySlot)
            PickupCollectible(inventorySlot.collectibleId)
            return true
        end
    },
    [SLOT_TYPE_CRAFT_BAG_ITEM] =
    {
        function(inventorySlot)
            local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
            PickupInventoryItem(bag, index)
            return true
        end
    },
    [SLOT_TYPE_PENDING_RETRAIT_ITEM] =
    {
        function(inventorySlot)
            if not ZO_CraftingUtils_IsPerformingCraftProcess() then
                local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
                if bag and index then
                    if ZO_RETRAIT_KEYBOARD then
                        local keyboardRetraitSceneName = SYSTEMS:GetKeyboardRootScene("retrait"):GetName()
                        if SCENE_MANAGER:IsShowing(keyboardRetraitSceneName) then
                            ZO_RETRAIT_KEYBOARD:RemoveItemFromCraft(bag, index)
                            PickupInventoryItem(bag, index)
                        end
                    end
                end
            end
            return true
        end
    },
}
function ZO_InventorySlot_OnDragStart(inventorySlot)
    if not IsInGamepadPreferredMode() then
        if IsUnitDead("player") then
            if not QUICKSLOT_KEYBOARD:AreQuickSlotsShowing() then
                ZO_AlertEvent(EVENT_UI_ERROR, SI_CANNOT_DO_THAT_WHILE_DEAD)
                return
            end
        end
        if GetCursorContentType() == MOUSE_CONTENT_EMPTY then
            inventorySlot = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
            return RunHandlers(InventoryDragStart, inventorySlot)
        end
    end
end
--
-- Drag End
--
local InventoryReceiveDrag =
{
    [SLOT_TYPE_ITEM] =
    {
        function(inventorySlot)
            return PlaceInventoryItemInStorage(inventorySlot)
        end
    },
    [SLOT_TYPE_EQUIPMENT] =
    {
        function(inventorySlot)
            if not ZO_Character_IsReadOnly() then
                return PlaceInventoryItem(inventorySlot)
            end
        end
    },
    [SLOT_TYPE_BANK_ITEM] =
    {
        function(inventorySlot)
            return PlaceInventoryItemInStorage(inventorySlot)
        end
    },
    [SLOT_TYPE_GUILD_BANK_ITEM] =
    {
        function(inventorySlot)
            return PlaceInventoryItemInStorage(inventorySlot)
        end
    },
    [SLOT_TYPE_MY_TRADE] =
    {
        function(inventorySlot)
            PlaceInTradeWindow(inventorySlot.index)
            return true
        end
    },
    [SLOT_TYPE_MAIL_QUEUED_ATTACHMENT] =
    {
        function(inventorySlot)
            local attachmentIndex = inventorySlot.slotIndex
            if attachmentIndex then
                PlaceInAttachmentSlot(attachmentIndex)
            end
            return true
        end
    },
    [SLOT_TYPE_STORE_BUY] =
    {
        function(inventorySlot)
            PlaceInStoreWindow()
            return true
        end
    },
    [SLOT_TYPE_TRADING_HOUSE_POST_ITEM] =
    {
        function(inventorySlot)
            local bag, index = GetCursorBagId(), GetCursorSlotIndex()
            if index and bag == BAG_BACKPACK then
                PlaceInTradingHouse()
                return true
            end
        end
    },
    [SLOT_TYPE_CRAFTING_COMPONENT] =
    {
        function(inventorySlot)
            ClearCursor()
            return true
        end
    },
    [SLOT_TYPE_PENDING_CRAFTING_COMPONENT] =
    {
        function(inventorySlot)
            if not ZO_CraftingUtils_IsPerformingCraftProcess() then
                local bagId, slotIndex = GetCursorBagId(), GetCursorSlotIndex()
                if bagId and slotIndex then
                    ClearCursor()
                    if SYSTEMS:IsShowing(ZO_ALCHEMY_SYSTEM_NAME) then
                        SYSTEMS:GetObject(ZO_ALCHEMY_SYSTEM_NAME):OnItemReceiveDrag(inventorySlot, bagId, slotIndex)
                    elseif SCENE_MANAGER:IsShowing("enchanting") then
                        ENCHANTING:OnItemReceiveDrag(inventorySlot, bagId, slotIndex)
                    elseif SCENE_MANAGER:IsShowing("provisioner") then
                        PROVISIONER.filletPanel:OnItemReceiveDrag(inventorySlot, bagId, slotIndex)
                    elseif ZO_Smithing_IsSceneShowing() then
                        ZO_Smithing_GetActiveObject():OnItemReceiveDrag(inventorySlot, bagId, slotIndex)
                    end
                    return true
                end
            end
        end
    },
    [SLOT_TYPE_MULTIPLE_PENDING_CRAFTING_COMPONENTS] =
    {
        function(inventorySlot)
            if not ZO_CraftingUtils_IsPerformingCraftProcess() then
                local bagId, slotIndex = GetCursorBagId(), GetCursorSlotIndex()
                if bagId and slotIndex then
                    ClearCursor()
                    if SCENE_MANAGER:IsShowing("enchanting") then
                        ENCHANTING:OnItemReceiveDrag(inventorySlot, bagId, slotIndex)
                    elseif ZO_Smithing_IsSceneShowing() then
                        ZO_Smithing_GetActiveObject():OnItemReceiveDrag(inventorySlot, bagId, slotIndex)
                    end
                    return true
                end
            end
        end
    },
    [SLOT_TYPE_CRAFT_BAG_ITEM] =
    {
        function(inventorySlot)
            local bagId, slotIndex = GetCursorBagId(), GetCursorSlotIndex()
            if CanMoveToCraftBag(bagId, slotIndex) then
                ClearCursor()
                return TryMoveToCraftBag(bagId, slotIndex)
            end
        end
    },
    [SLOT_TYPE_PENDING_RETRAIT_ITEM] =
    {
        function(inventorySlot)
            if not ZO_CraftingUtils_IsPerformingCraftProcess() then
                local bagId, slotIndex = GetCursorBagId(), GetCursorSlotIndex()
                if bagId and slotIndex then
                    ClearCursor()
                    if ZO_RETRAIT_KEYBOARD then
                        local keyboardRetraitSceneName = SYSTEMS:GetKeyboardRootScene("retrait"):GetName()
                        if SCENE_MANAGER:IsShowing(keyboardRetraitSceneName) then
                            ZO_RETRAIT_KEYBOARD:OnItemReceiveDrag(inventorySlot, bagId, slotIndex)
                        end
                    end
                    return true
                end
            end
            return false
        end
    },
}
function ZO_InventorySlot_OnReceiveDrag(inventorySlot)
    if GetCursorContentType() ~= MOUSE_CONTENT_EMPTY then
        local inventorySlotButton = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
        RunHandlers(InventoryReceiveDrag, inventorySlotButton)
    end
end
end
function ZO_InventorySlot_WillItemBecomeBoundOnEquip(bagId, slotIndex)
    if GetItemBindType(bagId, slotIndex) == BIND_TYPE_ON_EQUIP or IsItemBoPAndTradeable(bagId, slotIndex) then
        return not IsItemBound(bagId, slotIndex)
    end
    return false
end
    ZO_InventorySlot_SetHighlightHidden(listPart, false)
    local slotData = control:GetParent().dataEntry.data
    local traitInformation = slotData.traitInformation
    if traitInformation and traitInformation ~= ITEM_TRAIT_INFORMATION_NONE then
        local itemTrait = slotData.itemTrait or GetItemTrait(slotData.bagId, slotData.slotIndex)
        local traitName = GetString("SI_ITEMTRAITTYPE", itemTrait)
        local traitInformationString = GetString("SI_ITEMTRAITINFORMATION", traitInformation)
        InitializeTooltip(InformationTooltip, control, TOPRIGHT, -10, 0, TOPLEFT)
        InformationTooltip:AddLine(zo_strformat(SI_INVENTORY_TRAIT_STATUS_TOOLTIP, traitName, ZO_SELECTED_TEXT:Colorize(traitInformationString)), "", ZO_NORMAL_TEXT:UnpackRGB())
        if traitInformation == ITEM_TRAIT_INFORMATION_RETRAITED then
            InformationTooltip:AddLine(GetString(SI_INVENTORY_TRAIT_STATUS_RETRAITED_NOT_RESEARCHABLE), "", ZO_NORMAL_TEXT:UnpackRGB())
        elseif traitInformation == ITEM_TRAIT_INFORMATION_RECONSTRUCTED then
            InformationTooltip:AddLine(GetString(SI_INVENTORY_TRAIT_STATUS_RECONSTRUCTED_NOT_RESEARCHABLE), "", ZO_NORMAL_TEXT:UnpackRGB())
        end
    end
end
    ClearTooltip(InformationTooltip)
    ZO_InventorySlot_SetHighlightHidden(listPart, true)
end
    ZO_InventorySlot_SetHighlightHidden(listPart, false)
    local slotData = control:GetParent().dataEntry.data
    if slotData.sellInformation ~= ITEM_SELL_INFORMATION_NONE then
        InitializeTooltip(InformationTooltip, control, TOPRIGHT, -10, 0, TOPLEFT)
        InformationTooltip:AddLine(GetString("SI_ITEMSELLINFORMATION", slotData.sellInformation), "", ZO_NORMAL_TEXT:UnpackRGB())
    end
end
    ClearTooltip(InformationTooltip)
    ZO_InventorySlot_SetHighlightHidden(listPart, true)
end
do
    local g_tooltipLines = {}
        local slotData = control:GetParent():GetParent().dataEntry.data
        ZO_ClearNumericallyIndexedTable(g_tooltipLines)
        if slotData.isPlayerLocked then
            table.insert(g_tooltipLines, GetString(SI_INVENTORY_PLAYER_LOCKED_ITEM_TOOLTIP))
        end
        if slotData.brandNew then
            table.insert(g_tooltipLines, GetString(SI_INVENTORY_NEW_ITEM_TOOLTIP))
        end
        if slotData.stolen then
            table.insert(g_tooltipLines, GetString(SI_INVENTORY_STOLEN_ITEM_TOOLTIP))
        end
        if slotData.isBoPTradeable then
            table.insert(g_tooltipLines, GetString(SI_INVENTORY_TRADE_BOP_ITEM_TOOLTIP))
        end
        if slotData.isGemmable then
            table.insert(g_tooltipLines, GetString(SI_INVENTORY_GEMMABLE_ITEM_TOOLTIP))
        end
        if slotData.bagId == BAG_WORN then
            table.insert(g_tooltipLines, GetString(SI_INVENTORY_EQUIPPED_ITEM_TOOLTIP))
        end
        if slotData.isInArmory then
            table.insert(g_tooltipLines, GetString(SI_INVENTORY_ARMORY_BUILD_ITEM_TOOLTIP))
        end
        if #g_tooltipLines > 0 then
            InitializeTooltip(InformationTooltip, control, TOPRIGHT, -10, 0, TOPLEFT)
            for _, lineText in ipairs(g_tooltipLines) do
                InformationTooltip:AddLine(lineText, "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
            end
        end
    end
end