File size: 10,810 Bytes
91939c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useState } from "react";
import { useSelector } from "react-redux";
import {
  PiRobot,
  PiBrain,
  PiGraduationCap,
  PiCode,
  PiFlask,
  PiBook,
  PiStar,
  PiRocket,
  PiLightning,
  PiSparkle,
  PiGlobe,
  PiHeart,
  PiShield,
  PiWrench,
  PiMagnifyingGlass,
  PiChartLine,
  PiPenNib,
  PiMusicNotes,
  PiCamera,
  PiGameController,
  PiPencil,
} from "react-icons/pi";
import {
  FiSearch,
  FiEdit2,
  FiTrash2,
  FiGlobe as FiGlobeIcon,
  FiLock,
} from "react-icons/fi";

const iconMap = {
  robot: PiRobot,
  brain: PiBrain,
  graduation: PiGraduationCap,
  code: PiCode,
  flask: PiFlask,
  book: PiBook,
  star: PiStar,
  rocket: PiRocket,
  lightning: PiLightning,
  sparkle: PiSparkle,
  globe: PiGlobe,
  heart: PiHeart,
  shield: PiShield,
  wrench: PiWrench,
  search: PiMagnifyingGlass,
  chart: PiChartLine,
  pen: PiPenNib,
  music: PiMusicNotes,
  camera: PiCamera,
  game: PiGameController,
  pencil: PiPencil,
};

// Mock data - sau này sẽ thay bằng API call
const mockAgents = [
  {
    id: "math-tutor",
    name: "Trợ lý Toán học",
    icon: "graduation",
    color: "#6366f1",
    description: "Giải thích các bài toán từ cơ bản đến nâng cao",
    visibility: "public",
    tools: ["calculator", "web_search"],
    createdAt: "2026-04-15",
  },
  {
    id: "code-reviewer",
    name: "Code Reviewer",
    icon: "code",
    color: "#10b981",
    description: "Review code và gợi ý cải thiện",
    visibility: "private",
    tools: ["code_interpreter"],
    createdAt: "2026-04-18",
  },
  {
    id: "translator-bot",
    name: "Dịch thuật AI",
    icon: "globe",
    color: "#3b82f6",
    description: "Dịch đa ngôn ngữ chính xác cao",
    visibility: "public",
    tools: ["translator", "web_search"],
    createdAt: "2026-04-20",
  },
];

function ManageAgent({ onEditAgent }) {
  const { isDark } = useSelector((state) => state.theme);
  const [searchQuery, setSearchQuery] = useState("");
  const [agents, setAgents] = useState(mockAgents);

  const filteredAgents = agents.filter(
    (agent) =>
      agent.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
      agent.description.toLowerCase().includes(searchQuery.toLowerCase())
  );

  const handleDelete = (agentId, e) => {
    e.stopPropagation();
    if (window.confirm("Bạn có chắc chắn muốn xóa agent này?")) {
      setAgents((prev) => prev.filter((a) => a.id !== agentId));
    }
  };

  const toggleVisibility = (agentId, e) => {
    e.stopPropagation();
    setAgents((prev) =>
      prev.map((a) =>
        a.id === agentId
          ? { ...a, visibility: a.visibility === "public" ? "private" : "public" }
          : a
      )
    );
  };

  const handleEdit = (agent, e) => {
    e.stopPropagation();
    if (onEditAgent) {
      onEditAgent(agent);
    }
  };

  const getAgentIcon = (iconId) => {
    const IconComponent = iconMap[iconId];
    return IconComponent || PiRobot;
  };

  return (
    <div
      className="flex-1 flex flex-col min-w-0"
      style={{ background: "var(--bg-surface)" }}
    >
      {/* Header */}
      <div
        className="px-4 py-3 border-b flex-shrink-0"
        style={{
          borderColor: "var(--border-primary)",
          background: "var(--bg-surface-secondary)",
        }}
      >
        <div
          className="text-[15px] font-semibold"
          style={{ color: "var(--text-primary)" }}
        >
          Quản lý Agent
        </div>
        <div
          className="text-xs mt-0.5"
          style={{ color: "var(--text-secondary)" }}
        >
          Xem và quản lý các agent đã tạo
        </div>
      </div>

      {/* Content */}
      <div className="flex-1 overflow-y-auto p-6">
        <div className="max-w-2xl mx-auto space-y-4">
          {/* Search */}
          <div className="relative">
            <FiSearch
              size={16}
              className="absolute left-3 top-1/2 -translate-y-1/2"
              style={{ color: "var(--text-muted)" }}
            />
            <input
              type="text"
              value={searchQuery}
              onChange={(e) => setSearchQuery(e.target.value)}
              placeholder="Tìm kiếm agent..."
              className="w-full pl-9 pr-3 py-2 rounded-md text-sm border outline-none"
              style={{
                background: "var(--input-bg)",
                borderColor: "var(--input-border)",
                color: "var(--input-text)",
              }}
              onFocus={(e) =>
                (e.currentTarget.style.borderColor = "var(--primary)")
              }
              onBlur={(e) =>
                (e.currentTarget.style.borderColor = "var(--input-border)")
              }
            />
          </div>

          {/* Agent count */}
          <div
            className="text-xs font-medium"
            style={{ color: "var(--text-secondary)" }}
          >
            {filteredAgents.length} agent
          </div>

          {/* Agent list */}
          <div className="space-y-3">
            {filteredAgents.map((agent) => {
              const AgentIcon = getAgentIcon(agent.icon);
              return (
                <div
                  key={agent.id}
                  className="p-4 rounded-lg cursor-pointer group"
                  style={{ background: "var(--card-bg-secondary)" }}
                  onClick={(e) => handleEdit(agent, e)}
                  onMouseEnter={(e) => {
                    e.currentTarget.style.background = "var(--hover-primary)";
                  }}
                  onMouseLeave={(e) => {
                    e.currentTarget.style.background = "var(--card-bg-secondary)";
                  }}
                >
                  <div className="flex items-start gap-3">
                    {/* Icon */}
                    <div
                      className="w-10 h-10 rounded-lg flex items-center justify-center flex-shrink-0"
                      style={{ background: agent.color }}
                    >
                      <AgentIcon size={22} color="#fff" />
                    </div>

                    {/* Info */}
                    <div className="flex-1 min-w-0">
                      <div className="flex items-center gap-2">
                        <div
                          className="text-sm font-semibold"
                          style={{ color: "var(--text-primary)" }}
                        >
                          {agent.name}
                        </div>
                        {agent.visibility === "public" ? (
                          <span
                            className="text-xs px-1.5 py-0.5 rounded flex items-center gap-1"
                            style={{
                              background: "var(--primary-active)",
                              color: "var(--primary)",
                            }}
                          >
                            <FiGlobeIcon size={10} />
                            Công khai
                          </span>
                        ) : (
                          <span
                            className="text-xs px-1.5 py-0.5 rounded flex items-center gap-1"
                            style={{
                              background: "var(--hover-primary)",
                              color: "var(--text-secondary)",
                            }}
                          >
                            <FiLock size={10} />
                            Riêng tư
                          </span>
                        )}
                      </div>
                      <div
                        className="text-xs mt-1"
                        style={{ color: "var(--text-secondary)" }}
                      >
                        {agent.description}
                      </div>
                      <div
                        className="text-xs mt-2 flex items-center gap-3"
                        style={{ color: "var(--text-muted)" }}
                      >
                        <span>{agent.tools.length} công cụ</span>
                        <span></span>
                        <span>Tạo ngày {agent.createdAt}</span>
                      </div>
                    </div>

                    {/* Actions */}
                    <div className="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
                      <button
                        onClick={(e) => handleEdit(agent, e)}
                        className="p-1.5 rounded hover:opacity-70 transition-opacity"
                        style={{ color: "var(--text-secondary)" }}
                        title="Chỉnh sửa"
                      >
                        <FiEdit2 size={16} />
                      </button>
                      <button
                        onClick={(e) => toggleVisibility(agent.id, e)}
                        className="p-1.5 rounded hover:opacity-70 transition-opacity"
                        style={{ color: "var(--text-secondary)" }}
                        title={
                          agent.visibility === "public"
                            ? "Đổi thành riêng tư"
                            : "Đổi thành công khai"
                        }
                      >
                        {agent.visibility === "public" ? (
                          <FiLock size={16} />
                        ) : (
                          <FiGlobeIcon size={16} />
                        )}
                      </button>
                      <button
                        onClick={(e) => handleDelete(agent.id, e)}
                        className="p-1.5 rounded hover:opacity-70 transition-opacity"
                        style={{ color: "var(--danger)" }}
                        title="Xóa"
                      >
                        <FiTrash2 size={16} />
                      </button>
                    </div>
                  </div>
                </div>
              );
            })}

            {filteredAgents.length === 0 && (
              <div
                className="text-center py-12 rounded-lg"
                style={{ background: "var(--card-bg-secondary)" }}
              >
                <div
                  className="text-sm"
                  style={{ color: "var(--text-secondary)" }}
                >
                  Không tìm thấy agent nào
                </div>
                <div
                  className="text-xs mt-1"
                  style={{ color: "var(--text-muted)" }}
                >
                  Thử tìm kiếm với từ khóa khác
                </div>
              </div>
            )}
          </div>
        </div>
      </div>
    </div>
  );
}

export default ManageAgent;