2023-12-07 17:08:22 +08:00
|
|
|
import React from 'react'
|
2023-12-01 11:52:37 +08:00
|
|
|
import {Droppable} from "@hello-pangea/dnd";
|
2023-12-07 17:50:33 +08:00
|
|
|
import {cartStyle} from "./utils";
|
2023-12-12 18:21:09 +08:00
|
|
|
import {ProductCartItem} from "./ProductCartItem";
|
|
|
|
import {FakePlaceholder} from "./FakePlaceholder";
|
2023-11-30 17:26:17 +08:00
|
|
|
import {FillExtData} from "./options/utils";
|
2023-12-13 15:17:14 +08:00
|
|
|
import {hp_to_slots} from "./count_resources";
|
2023-12-11 17:05:35 +08:00
|
|
|
import {useShopStore} from "./shop_store";
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that displays a list of <ProductCartItem>
|
|
|
|
*/
|
2023-12-11 17:05:35 +08:00
|
|
|
export function Cart({crate_index}) {
|
2023-12-12 16:09:29 +08:00
|
|
|
const {crate, crateParams} = useShopStore(state => ({
|
|
|
|
crate: state.crates[crate_index],
|
|
|
|
crateParams: state.crateParams
|
2023-12-11 17:05:35 +08:00
|
|
|
}));
|
|
|
|
|
2023-12-12 16:09:29 +08:00
|
|
|
const nbrOccupied = hp_to_slots(crate.occupiedHP);
|
|
|
|
const nbrSlots = hp_to_slots(crateParams(crate.crate_mode).hp);
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
const products = crate.items.map((item, index) => {
|
|
|
|
const ext_data = FillExtData(crate.items, index);
|
2023-11-30 17:26:17 +08:00
|
|
|
return (
|
2023-12-07 17:08:22 +08:00
|
|
|
<ProductCartItem
|
2023-12-11 17:05:35 +08:00
|
|
|
card_index={index}
|
|
|
|
crate_index={crate_index}
|
2023-12-07 17:08:22 +08:00
|
|
|
ext_data={ext_data}
|
2023-12-11 17:05:35 +08:00
|
|
|
first={index === 0}
|
|
|
|
last={index === crate.items.length - 1 && nbrOccupied >= nbrSlots}
|
|
|
|
key={item.id}/>
|
2023-12-07 17:08:22 +08:00
|
|
|
);
|
|
|
|
});
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-07 17:08:22 +08:00
|
|
|
return (
|
2023-12-11 17:05:35 +08:00
|
|
|
<Droppable droppableId={crate.id} direction="horizontal">
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-07 17:08:22 +08:00
|
|
|
{(provided, snapshot) => (
|
|
|
|
<div
|
|
|
|
ref={provided.innerRef}
|
|
|
|
{...provided.droppableProps}
|
|
|
|
style={cartStyle(
|
|
|
|
provided.droppableProps.style,
|
|
|
|
snapshot,
|
|
|
|
)}
|
|
|
|
className="items-cart-list">
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-07 17:08:22 +08:00
|
|
|
{products}
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-07 17:08:22 +08:00
|
|
|
{provided.placeholder && (
|
|
|
|
<div style={{display: 'none'}}>
|
|
|
|
{provided.placeholder}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-07 17:08:22 +08:00
|
|
|
<FakePlaceholder
|
2023-12-08 16:39:28 +08:00
|
|
|
nToDraw={nbrSlots - nbrOccupied}
|
2023-12-07 17:08:22 +08:00
|
|
|
isDraggingOver={snapshot.isDraggingOver}/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
</Droppable>
|
|
|
|
);
|
2023-11-30 17:26:17 +08:00
|
|
|
}
|