2023-12-14 17:45:54 +08:00
|
|
|
import {formatMoney} from "./utils";
|
|
|
|
import React from "react";
|
|
|
|
import {useShopStore} from "./shop_store";
|
|
|
|
|
|
|
|
// #!render_count
|
|
|
|
import {useRenderCount} from "@uidotdev/usehooks";
|
2024-01-15 13:01:27 +08:00
|
|
|
import {CrateMode} from "./CrateMode";
|
2023-12-14 17:45:54 +08:00
|
|
|
|
|
|
|
export function SummaryCrateHeader({crate_index}) {
|
|
|
|
// #!render_count
|
|
|
|
const renderCount = useRenderCount();
|
|
|
|
|
|
|
|
const currency = useShopStore((state) => state.currency);
|
|
|
|
const crateParams = useShopStore((state) => state.crateParams);
|
|
|
|
const clearCrate = useShopStore((state) => state.clearCrate);
|
|
|
|
const delCrate = useShopStore((state) => state.delCrate);
|
|
|
|
|
|
|
|
const crate_mode = useShopStore((state) => state.crates[crate_index].crate_mode);
|
|
|
|
const crate_id = useShopStore((state) => state.crates[crate_index].id);
|
2024-01-15 13:01:27 +08:00
|
|
|
const crate_name = useShopStore((state) => state.crates[crate_index].name);
|
|
|
|
const modes_order = useShopStore((state) => state.modes_order);
|
2024-01-23 11:36:56 +08:00
|
|
|
const crate_mode_displayed = modes_order.includes(crate_mode);
|
2024-01-15 13:01:27 +08:00
|
|
|
|
2023-12-14 17:45:54 +08:00
|
|
|
|
|
|
|
// #!render_count
|
|
|
|
console.log("SummaryCrateHeader renders: ", renderCount)
|
|
|
|
|
|
|
|
let crate_type = crateParams(crate_mode);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<tr key={"summary_crate_" + crate_id}>
|
2024-01-15 13:01:27 +08:00
|
|
|
<td className="item-card-name">{!!crate_name ? crate_name : crate_type.name + " #" + crate_index}</td>
|
2023-12-14 17:45:54 +08:00
|
|
|
<td className="price">
|
|
|
|
<div className="d-inline-flex">
|
2024-01-23 11:36:56 +08:00
|
|
|
|
|
|
|
{crate_mode_displayed && `${currency} ${formatMoney(crate_type.price)}`}
|
2023-12-14 17:45:54 +08:00
|
|
|
|
|
|
|
<button onClick={() => clearCrate(crate_id)}>
|
|
|
|
<img src="/images/shop/icon-clear.svg" alt="empty crate"/>
|
|
|
|
</button>
|
|
|
|
|
2024-01-15 13:01:27 +08:00
|
|
|
{
|
2024-01-23 11:36:56 +08:00
|
|
|
crate_mode_displayed ? (
|
2024-01-15 13:01:27 +08:00
|
|
|
<button onClick={() => delCrate(crate_id)}>
|
|
|
|
<img src="/images/shop/icon-remove.svg" alt="remove crate"/>
|
|
|
|
</button>
|
2024-01-23 11:36:56 +08:00
|
|
|
) : <span className="span-with-margin"></span>
|
2024-01-15 13:01:27 +08:00
|
|
|
}
|
|
|
|
|
2023-12-14 17:45:54 +08:00
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
)
|
|
|
|
}
|