import { useTranslation } from "react-i18next"; import { SendouSelect, SendouSelectItem, SendouSelectItemSection, } from "~/components/elements/Select"; import { Image } from "~/components/Image"; import type { GearType } from "~/db/tables"; import { brandIds } from "~/modules/in-game-lists/brand-ids"; import { clothesGearBrandGrouped, headGearBrandGrouped, shoesGearBrandGrouped, } from "~/modules/in-game-lists/gear-ids"; import { brandImageUrl, gearImageUrl } from "~/utils/urls"; import styles from "./WeaponSelect.module.css"; interface GearSelectProps { label?: string; value?: number | (Clearable extends true ? null : never); initialValue?: number; onChange?: ( weaponId: number | (Clearable extends true ? null : never), ) => void; clearable?: Clearable; type: GearType; } export function GearSelect({ label, value, initialValue, onChange, clearable, type, }: GearSelectProps) { const { t } = useTranslation(["common"]); const items = useGearItems(type); return ( onChange?.(value as any)} clearable={clearable} data-testid={`${type}-gear-select`} > {({ key, items: gear, brandId, idx }) => ( {gear.map(({ id, name }) => (
{name}
))}
)}
); } function useGearItems(type: GearType) { const { t } = useTranslation(["gear", "game-misc"]); const translationPrefix = type === "HEAD" ? "H" : type === "CLOTHES" ? "C" : "S"; const groupedGear = type === "HEAD" ? headGearBrandGrouped : type === "CLOTHES" ? clothesGearBrandGrouped : shoesGearBrandGrouped; const items = brandIds.map((brandId, idx) => { const items = groupedGear[brandId] || []; return { brandId, key: brandId, idx, items: items.map((gearId) => ({ id: gearId, name: t(`${translationPrefix}_${gearId}` as any), })), }; }); return items; }