import { AjaxSelect } from "#core:core/components/ajax-select-base"; import { registerComponent } from "#core:utils/web-components"; import type { TomOption } from "tom-select/dist/types/types"; import type { escape_html } from "tom-select/dist/types/utils"; import { type ClubSchema, clubSearchClub } from "#openapi"; @registerComponent("club-ajax-select") export class ClubAjaxSelect extends AjaxSelect { protected valueField = "id"; protected labelField = "name"; protected searchField = ["code", "name"]; protected async search(query: string): Promise { const resp = await clubSearchClub({ query: { search: query } }); if (resp.data) { return resp.data.results; } return []; } protected renderOption(item: ClubSchema, sanitize: typeof escape_html) { return `
${sanitize(item.name)}
`; } protected renderItem(item: ClubSchema, sanitize: typeof escape_html) { return `${sanitize(item.name)}`; } }