2024-04-04 18:56:51 -05:00
|
|
|
import {
|
|
|
|
|
CaretLeftIcon,
|
|
|
|
|
CaretRightIcon,
|
|
|
|
|
ShuffleIcon,
|
|
|
|
|
TrashIcon,
|
|
|
|
|
} from '@radix-ui/react-icons';
|
2024-04-05 13:40:18 -05:00
|
|
|
import { Dialog, Flex, IconButton } from '@radix-ui/themes';
|
2024-04-04 18:56:51 -05:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { TankDefinition } from '../../../../core/blitzkrieg/tankDefinitions';
|
|
|
|
|
import { tankToDuelMember } from '../../../../core/blitzkrieg/tankToDuelMember';
|
2024-04-05 13:59:30 -05:00
|
|
|
import {
|
|
|
|
|
CompareMember,
|
|
|
|
|
mutateCompareTemporary,
|
|
|
|
|
} from '../../../../stores/compare';
|
2024-04-04 18:56:51 -05:00
|
|
|
import { TankSearch } from '../../tankopedia/components/TankSearch';
|
|
|
|
|
|
|
|
|
|
interface TankControlProps {
|
|
|
|
|
index: number;
|
|
|
|
|
tank: TankDefinition;
|
|
|
|
|
members: CompareMember[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function TankControl({ index, tank, members }: TankControlProps) {
|
|
|
|
|
const [switchTankDialogOpen, setSwitchTankDialogOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
return (
|
2024-04-05 13:40:18 -05:00
|
|
|
<Flex gap="4" style={{ padding: '0 4px' }}>
|
|
|
|
|
{index !== 0 && (
|
2024-04-04 18:56:51 -05:00
|
|
|
<IconButton
|
|
|
|
|
variant="ghost"
|
|
|
|
|
onClick={() => {
|
2024-04-05 13:59:30 -05:00
|
|
|
mutateCompareTemporary((draft) => {
|
2024-04-05 13:40:18 -05:00
|
|
|
const item = draft.members[index];
|
2024-04-04 18:56:51 -05:00
|
|
|
draft.members.splice(index, 1);
|
2024-04-05 13:40:18 -05:00
|
|
|
draft.members.splice(index - 1, 0, item);
|
2024-04-04 18:56:51 -05:00
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-04-05 13:40:18 -05:00
|
|
|
<CaretLeftIcon />
|
2024-04-04 18:56:51 -05:00
|
|
|
</IconButton>
|
2024-04-05 13:40:18 -05:00
|
|
|
)}
|
|
|
|
|
<IconButton
|
|
|
|
|
variant="ghost"
|
|
|
|
|
onClick={() => {
|
2024-04-05 13:59:30 -05:00
|
|
|
mutateCompareTemporary((draft) => {
|
2024-04-05 13:40:18 -05:00
|
|
|
draft.members.splice(index, 1);
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<TrashIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Dialog.Root
|
|
|
|
|
open={switchTankDialogOpen}
|
|
|
|
|
onOpenChange={setSwitchTankDialogOpen}
|
|
|
|
|
>
|
|
|
|
|
<Dialog.Trigger>
|
|
|
|
|
<IconButton variant="ghost">
|
|
|
|
|
<ShuffleIcon />
|
2024-04-04 18:56:51 -05:00
|
|
|
</IconButton>
|
2024-04-05 13:40:18 -05:00
|
|
|
</Dialog.Trigger>
|
|
|
|
|
|
|
|
|
|
<Dialog.Content>
|
|
|
|
|
<Flex gap="4" direction="column">
|
|
|
|
|
<Flex
|
|
|
|
|
direction="column"
|
|
|
|
|
gap="4"
|
|
|
|
|
style={{ flex: 1 }}
|
|
|
|
|
justify="center"
|
|
|
|
|
>
|
|
|
|
|
<TankSearch
|
|
|
|
|
compact
|
|
|
|
|
onSelect={(tank) => {
|
2024-04-05 13:59:30 -05:00
|
|
|
mutateCompareTemporary((draft) => {
|
2024-04-05 13:40:18 -05:00
|
|
|
draft.members[index] = {
|
|
|
|
|
...tankToDuelMember(tank),
|
|
|
|
|
crewSkills: {},
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
setSwitchTankDialogOpen(false);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Dialog.Content>
|
|
|
|
|
</Dialog.Root>
|
|
|
|
|
{index !== members.length - 1 && (
|
|
|
|
|
<IconButton
|
|
|
|
|
variant="ghost"
|
|
|
|
|
onClick={() => {
|
2024-04-05 13:59:30 -05:00
|
|
|
mutateCompareTemporary((draft) => {
|
2024-04-05 13:40:18 -05:00
|
|
|
const item = draft.members[index];
|
|
|
|
|
draft.members.splice(index, 1);
|
|
|
|
|
draft.members.splice(index + 1, 0, item);
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<CaretRightIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
)}
|
|
|
|
|
</Flex>
|
2024-04-04 18:56:51 -05:00
|
|
|
);
|
|
|
|
|
}
|