File size: 5,242 Bytes
57f5158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Space Icons Registry — giống pattern usernameColors
 *
 * Cách hoạt động:
 *   1. Server chỉ lưu + trả về `icon_id` (string), KHÔNG lưu URL
 *   2. Frontend có registry này để map `icon_id` → React Component + label
 *   3. Muốn thêm icon mới? Chỉ cần sửa file này ở FE, KHÔNG cần đụng DB
 *
 * Cách dùng ở FE:
 *   import { getSpaceIconComponent, getSpaceIconLabel, spaceIconIds } from "../constants/spaceIcons";
 *
 *   const Icon = getSpaceIconComponent(space.icon_id); // React component
 *   const label = getSpaceIconLabel(space.icon_id);     // "Tốt nghiệp"
 *
 * API Request (FE → Server):
 *   POST /spaces
 *   { name: "Lớp Toán", icon: "graduation", ... }
 *
 * API Response (Server → FE):
 *   { id: "...", name: "Lớp Toán", icon: "graduation", ... }
 */

import {
  PiGraduationCap,
  PiRobot,
  PiFolder,
  PiPencil,
  PiComputerTower,
  PiBooks,
  PiStudent,
  PiFlask,
  PiFunction,
  PiChartBar,
  PiCode,
  PiGlobe,
  PiMusicNotes,
  PiPalette,
  PiCamera,
  PiGameController,
  PiHeart,
  PiStar,
  PiRocket,
  PiBrain,
  PiCalculator,
  PiCalendar,
  PiUsers,
  PiTrophy,
  PiFlag,
  PiSun,
  PiMoon,
  PiCloud,
  PiHouse,
  PiCar,
  PiAirplane,
  PiBasketball,
  PiGuitar,
  PiPhone,
  PiLaptop,
  PiCoffee,
  PiPizza,
  PiFirstAid,
  PiLockKey,
  PiMoney,
  PiGift,
  PiFire,
  PiSnowflake,
} from "react-icons/pi";

// ==================== Registry ====================

export const spaceIcons = [
  { id: "graduation", label: "Tốt nghiệp", component: PiGraduationCap },
  { id: "robot", label: "Robot", component: PiRobot },
  { id: "folder", label: "Thư mục", component: PiFolder },
  { id: "pencil", label: "Bút chì", component: PiPencil },
  { id: "computer", label: "Máy tính", component: PiComputerTower },
  { id: "books", label: "Sách", component: PiBooks },
  { id: "student", label: "Học sinh", component: PiStudent },
  { id: "flask", label: "Thí nghiệm", component: PiFlask },
  { id: "function", label: "Hàm số", component: PiFunction },
  { id: "chart", label: "Biểu đồ", component: PiChartBar },
  { id: "code", label: "Lập trình", component: PiCode },
  { id: "globe", label: "Thế giới", component: PiGlobe },
  { id: "music", label: "Âm nhạc", component: PiMusicNotes },
  { id: "palette", label: "Mỹ thuật", component: PiPalette },
  { id: "camera", label: "Nhiếp ảnh", component: PiCamera },
  { id: "game", label: "Game", component: PiGameController },
  { id: "heart", label: "Yêu thích", component: PiHeart },
  { id: "star", label: "Ngôi sao", component: PiStar },
  { id: "rocket", label: "Tên lửa", component: PiRocket },
  { id: "brain", label: "Trí tuệ", component: PiBrain },
  { id: "calculator", label: "Máy tính", component: PiCalculator },
  { id: "calendar", label: "Lịch", component: PiCalendar },
  { id: "users", label: "Nhóm", component: PiUsers },
  { id: "trophy", label: "Cúp", component: PiTrophy },
  { id: "flag", label: "Cờ", component: PiFlag },
  { id: "sun", label: "Mặt trờii", component: PiSun },
  { id: "moon", label: "Mặt trăng", component: PiMoon },
  { id: "cloud", label: "Mây", component: PiCloud },
  { id: "house", label: "Nhà", component: PiHouse },
  { id: "car", label: "Xe hơi", component: PiCar },
  { id: "airplane", label: "Máy bay", component: PiAirplane },
  { id: "basketball", label: "Bóng rổ", component: PiBasketball },
  { id: "guitar", label: "Guitar", component: PiGuitar },
  { id: "phone", label: "Điện thoại", component: PiPhone },
  { id: "laptop", label: "Laptop", component: PiLaptop },
  { id: "coffee", label: "Cà phê", component: PiCoffee },
  { id: "pizza", label: "Pizza", component: PiPizza },
  { id: "firstaid", label: "Sơ cứu", component: PiFirstAid },
  { id: "lock", label: "Khóa", component: PiLockKey },
  { id: "money", label: "Tiền", component: PiMoney },
  { id: "gift", label: "Quà", component: PiGift },
  { id: "fire", label: "Lửa", component: PiFire },
  { id: "snowflake", label: "Bông tuyết", component: PiSnowflake },
];

// ==================== Derived Maps ====================

const componentMap = Object.fromEntries(
  spaceIcons.map((s) => [s.id, s.component])
);

const labelMap = Object.fromEntries(
  spaceIcons.map((s) => [s.id, s.label])
);

// ==================== Exports ====================

export const spaceIconIds = spaceIcons.map((s) => s.id);

/**
 * Get React icon component by icon_id
 * @param {string} iconId
 * @returns {React.ComponentType|null}
 */
export function getSpaceIconComponent(iconId) {
  return componentMap[iconId] || null;
}

/**
 * Get display label by icon_id
 * @param {string} iconId
 * @returns {string}
 */
export function getSpaceIconLabel(iconId) {
  return labelMap[iconId] || iconId;
}

/**
 * Check if an icon_id is valid
 * @param {string} iconId
 * @returns {boolean}
 */
export function isValidSpaceIcon(iconId) {
  return iconId in componentMap;
}

/**
 * Get full icon data by icon_id
 * @param {string} iconId
 * @returns {{id: string, label: string, component: React.ComponentType}|undefined}
 */
export function getSpaceIconData(iconId) {
  return spaceIcons.find((s) => s.id === iconId);
}