2023-12-15 13:49:54 +08:00
|
|
|
import {compareObjectsEmptiness, formatMoney} from "./utils";
|
2023-12-14 17:45:54 +08:00
|
|
|
import {WarningIndicator} from "./CardWarnings";
|
|
|
|
import React from "react";
|
2024-11-01 17:32:20 +08:00
|
|
|
import {useShopStore, whichItems} from "./shop_store";
|
2023-12-15 13:49:54 +08:00
|
|
|
import {OptionsSummaryWrapper} from "./OptionsWrapper";
|
2023-12-14 17:45:54 +08:00
|
|
|
|
|
|
|
// #!render_count
|
|
|
|
import {useRenderCount} from "@uidotdev/usehooks";
|
|
|
|
|
2023-12-15 13:49:54 +08:00
|
|
|
|
2024-11-01 17:32:20 +08:00
|
|
|
export function SummaryCrateCard({crate_index, card_index, horizontal}) {
|
2023-12-14 17:45:54 +08:00
|
|
|
// #!render_count
|
|
|
|
const renderCount = useRenderCount();
|
|
|
|
|
2024-11-01 17:32:20 +08:00
|
|
|
const whichH = whichItems(horizontal);
|
|
|
|
|
2023-12-14 17:45:54 +08:00
|
|
|
const currency = useShopStore((state) => state.currency);
|
|
|
|
const deleteCard = useShopStore((state) => state.deleteCard);
|
|
|
|
const setHighlight = useShopStore((state) => state.highlightCard);
|
|
|
|
const resetHighlight = useShopStore((state) => state.highlightReset);
|
|
|
|
|
2024-11-01 17:32:20 +08:00
|
|
|
const highlighted = useShopStore((state) =>
|
|
|
|
state.highlighted.horizontal === horizontal &&
|
|
|
|
state.crates[crate_index].id === state.highlighted.crate &&
|
|
|
|
card_index === state.highlighted.card);
|
2023-12-14 17:45:54 +08:00
|
|
|
const crate_id = useShopStore((state) => state.crates[crate_index].id);
|
2024-11-01 17:32:20 +08:00
|
|
|
const card = useShopStore((state) =>
|
|
|
|
state.crates[crate_index][whichH][card_index],
|
2023-12-15 13:49:54 +08:00
|
|
|
(a, b) => a.id === b.id);
|
2024-11-01 17:32:20 +08:00
|
|
|
// additional hooks for updating warning and options
|
|
|
|
const card_show_warnings = useShopStore(state =>
|
|
|
|
state.crates[crate_index][whichH][card_index].show_warnings,
|
|
|
|
compareObjectsEmptiness);
|
|
|
|
const card_options_data = useShopStore(state =>
|
|
|
|
state.crates[crate_index][whichH][card_index].options_data,
|
|
|
|
compareObjectsEmptiness);
|
2024-07-12 17:17:07 +08:00
|
|
|
const warnings_disabled = useShopStore((state) => !!state.crateParams(state.crates[crate_index].crate_mode).warnings_disabled);
|
|
|
|
const use_options = useShopStore((state) => state.crateParams(state.crates[crate_index].crate_mode).options);
|
2023-12-14 17:45:54 +08:00
|
|
|
|
|
|
|
// #!render_count
|
|
|
|
console.log("SummaryCrateCard renders: ", renderCount)
|
|
|
|
|
|
|
|
|
2024-07-12 17:17:07 +08:00
|
|
|
const options = use_options && card && card[use_options] && card[use_options].length > 0;
|
|
|
|
const options_data = card_options_data && Object.keys(card_options_data).length > 0;
|
|
|
|
const warnings = !warnings_disabled && card_show_warnings && card_show_warnings.length > 0;
|
2023-12-14 17:45:54 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<tr
|
|
|
|
key={"summary_crate_" + crate_id + "_" + card_index}
|
|
|
|
className={`hoverable ${highlighted ? 'selected' : ''}`}
|
2024-11-01 17:32:20 +08:00
|
|
|
onClick={() => setHighlight(crate_id, card_index, horizontal)}
|
|
|
|
onMouseEnter={() => setHighlight(crate_id, card_index, horizontal)}
|
2023-12-14 17:45:54 +08:00
|
|
|
onMouseLeave={() => resetHighlight()}>
|
2024-02-26 17:36:15 +08:00
|
|
|
<td className="item-card-name tabbed">
|
2023-12-14 17:45:54 +08:00
|
|
|
<div>{`${card.name_number} ${card.name} ${card.name_codename}`}</div>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td className="price">
|
|
|
|
<div className="d-inline-flex align-content-center">
|
|
|
|
{`${currency} ${formatMoney(card.price)}`}
|
|
|
|
|
2024-11-01 17:32:20 +08:00
|
|
|
<button onClick={() => deleteCard(crate_id, card_index, horizontal)}>
|
2024-01-23 11:36:56 +08:00
|
|
|
<img src="/images/shop/icon-remove.svg" className="d-block"/>
|
2023-12-14 17:45:54 +08:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<div style={{'width': '45px', 'height': '20px'}}
|
|
|
|
className="d-inline-flex align-content-center align-self-center justify-content-evenly">
|
2023-12-15 13:49:54 +08:00
|
|
|
{(warnings ? (
|
|
|
|
<WarningIndicator crate_index={crate_index} card_index={card_index}/>
|
2023-12-14 17:45:54 +08:00
|
|
|
) : (
|
|
|
|
<span style={{
|
|
|
|
'display': 'inline-block',
|
2024-01-23 11:36:56 +08:00
|
|
|
'minWidth': '20px',
|
2023-12-14 17:45:54 +08:00
|
|
|
}}> </span>
|
|
|
|
))}
|
|
|
|
{((options && options_data) ? (
|
2024-11-01 17:32:20 +08:00
|
|
|
<OptionsSummaryWrapper
|
|
|
|
crate_index={crate_index}
|
|
|
|
card_index={card_index}
|
|
|
|
horizontal={horizontal}/>
|
2023-12-14 17:45:54 +08:00
|
|
|
) : (
|
|
|
|
<span style={{
|
|
|
|
'display': 'inline-block',
|
|
|
|
'width': '20px',
|
|
|
|
}}> </span>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>);
|
|
|
|
}
|