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-11-30 17:26:17 +08:00
|
|
|
import {ProductCartItem} from "./ProductCartItem.jsx";
|
|
|
|
import {FakePlaceholder} from "./FakePlaceholder.jsx";
|
|
|
|
import {FillExtData} from "./options/utils";
|
2023-12-11 17:05:35 +08:00
|
|
|
import {CountResources, crate_type_to_hp, hp_to_slots, resource_counters} from "./count_resources";
|
|
|
|
import {useShopStore} from "./shop_store";
|
|
|
|
import {TriggerCardWarnings} from "./warnings";
|
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}) {
|
|
|
|
// isMobile, isTouch, crate, onToggleOverlayRemove, onClickRemoveItem, onCardUpdate, onClickItem
|
|
|
|
const {crate} = useShopStore(state => ({
|
|
|
|
crate: state.crates[crate_index]
|
|
|
|
}));
|
|
|
|
|
2023-12-11 17:47:16 +08:00
|
|
|
console.log(resource_counters, crate)
|
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
const nbrOccupied = hp_to_slots(resource_counters.hp(crate.items, -1));
|
|
|
|
const nbrSlots = hp_to_slots(crate_type_to_hp(crate.crate_mode));
|
2023-12-08 16:39:28 +08:00
|
|
|
console.log(nbrOccupied, nbrSlots);
|
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);
|
|
|
|
const resources = CountResources(crate.items, index);
|
|
|
|
const warnings = TriggerCardWarnings(crate.items, index, resources);
|
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}
|
|
|
|
resources={resources}
|
|
|
|
warnings={warnings}
|
|
|
|
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
|
|
|
}
|