1import { computed } from "vue";
2import { defineStore } from "pinia";
3import { createListResource } from "frappe-ui";
4
5export const useAgentStore = defineStore("agent", () => {
6 const agents = createListResource({
7 doctype: "OD Agent",
8 fields: ["name", "agent_name", "user", "user.user_image"],
9 filters: { is_active: 1 },
10 pageLength: 99999,
11 });
12
13 const dropdown = computed(() =>
14 agents.data?.map((o) => ({
15 label: o.agent_name,
16 value: o.name,
17 image: o.user_image,
18 }))
19 );
20
21 function searchAgents(query: string) {
22 return agents.data.filter((a) =>
23 a.user?.toLowerCase().includes(query.toLowerCase())
24 );
25 }
26
27 return {
28 dropdown,
29 agents,
30 searchAgents,
31 };
32});
33