2023-12-15 13:49:54 +08:00
|
|
|
import {DialogPopup} from "./options/DialogPopup";
|
|
|
|
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 {SummaryPopup} from "./options/SummaryPopup";
|
|
|
|
|
2024-10-31 16:01:55 +08:00
|
|
|
export function OptionsDialogWrapper({crate_index, card_index, horizontal}) {
|
2024-11-01 17:32:20 +08:00
|
|
|
const whichH = whichItems(horizontal);
|
2023-12-15 13:49:54 +08:00
|
|
|
const crate_id = useShopStore((state) => state.crates[crate_index].id);
|
2024-07-12 17:17:07 +08:00
|
|
|
const use_options = useShopStore((state) => state.crateParams(state.crates[crate_index].crate_mode).options);
|
2024-11-01 17:32:20 +08:00
|
|
|
const options = useShopStore((state) => state.crates[crate_index][whichH][card_index][use_options]);
|
|
|
|
const options_data = useShopStore((state) => state.crates[crate_index][whichH][card_index].options_data);
|
|
|
|
const card_id = useShopStore((state) => state.crates[crate_index][whichH][card_index].id);
|
|
|
|
const options_class = useShopStore((state) => state.crates[crate_index][whichH][card_index].options_class);
|
2024-01-15 15:51:04 +08:00
|
|
|
const sideMenuIsOpen = useShopStore((state) => state.sideMenuIsOpen);
|
2024-03-18 14:48:16 +08:00
|
|
|
const _notificationTimer = useShopStore((state) => state.notificationTimer);
|
|
|
|
const hideNotification = useShopStore((state) => state.hideNotification);
|
|
|
|
const displayNotification = useShopStore((state) =>
|
|
|
|
state.notificationCrateId === crate_id &&
|
2024-11-01 17:32:20 +08:00
|
|
|
(state.notificationCardIndex === card_index || (state.crates[crate_index][whichH].length + (state.notificationCardIndex || -1)) === card_index));
|
2023-12-15 13:49:54 +08:00
|
|
|
|
|
|
|
const onOptionsUpdate = useShopStore((state) => state.updateOptions);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DialogPopup
|
|
|
|
options={options}
|
|
|
|
data={options_data}
|
|
|
|
options_class={options_class}
|
2024-01-15 15:51:04 +08:00
|
|
|
key={"popover" + crate_id +card_id}
|
|
|
|
id={"popover"+ crate_id + card_id}
|
|
|
|
sideMenuIsOpen={sideMenuIsOpen}
|
2024-03-18 14:48:16 +08:00
|
|
|
onHideNotification={hideNotification}
|
|
|
|
displayNotification={displayNotification}
|
2024-10-31 16:01:55 +08:00
|
|
|
horizontal={horizontal}
|
2023-12-15 13:49:54 +08:00
|
|
|
target={{
|
|
|
|
construct: ((outvar, value) => {
|
2024-01-02 17:13:50 +08:00
|
|
|
// #!options_log
|
|
|
|
console.log("construct", outvar, value, options_data);
|
|
|
|
|
2023-12-15 13:49:54 +08:00
|
|
|
options_data[outvar] = value;
|
|
|
|
}),
|
|
|
|
update: ((outvar, value) => {
|
2024-01-02 17:13:50 +08:00
|
|
|
// #!options_log
|
|
|
|
console.log("update", outvar, value, options_data);
|
|
|
|
|
2023-12-15 13:49:54 +08:00
|
|
|
if (outvar in options_data) options_data[outvar] = value;
|
2024-11-01 17:32:20 +08:00
|
|
|
onOptionsUpdate(crate_id, card_index, {[outvar]: value}, horizontal);
|
2023-12-15 13:49:54 +08:00
|
|
|
})
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-11-01 17:32:20 +08:00
|
|
|
export function OptionsSummaryWrapper({crate_index, card_index, horizontal}) {
|
|
|
|
const whichH = whichItems(horizontal);
|
|
|
|
const card_id = useShopStore((state) => state.crates[crate_index][whichH][card_index].id);
|
2024-07-12 17:17:07 +08:00
|
|
|
const use_options = useShopStore((state) => state.crateParams(state.crates[crate_index].crate_mode).options);
|
2024-11-01 17:32:20 +08:00
|
|
|
const options = useShopStore((state) => state.crates[crate_index][whichH][card_index][use_options]);
|
|
|
|
const options_data = useShopStore((state) => state.crates[crate_index][whichH][card_index].options_data);
|
2023-12-15 13:49:54 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SummaryPopup id={card_id + "options"} options={options}
|
|
|
|
data={options_data}/>
|
|
|
|
)
|
|
|
|
}
|