/**
* @file Règle les Expéditions depuis Administration › Guilde › Expéditions : en-tête (ouverture, suivi du
* jour, expéditions en route), puis les réglages rangés en onglets thématiques, avec un seul brouillon
* et une barre d'application commune.
*/
import { useState } from "react";
import { Tabs } from "../../../components/Tabs.jsx";
import { ConfirmModal } from "../../../components/ToolboxModals.jsx";
import { cancelExpedition, updateExpeditionSettings } from "../cardsApi.js";
import { DATE_FORMATTER } from "./adminFormat.js";
import { EXPEDITION_OPEN_PATH, EXPEDITION_SETTING_GROUPS, EXPEDITION_SETTING_THEMES, expeditionSettingLabel, formatSettingValue } from "./expeditionSettingFields.js";
import { GuildQuestHeader } from "./GuildQuestHeader.jsx";
import { guildQuest, questFigures, questStatus } from "./guildQuests.js";
import { ApplyBar, DefaultHint, NumberInput, SettingsGroup, SettingsSection } from "./SettingFields.jsx";
import { readPath, same, toDraft, useSettingsDraft, writePath } from "./settingsDraft.js";
const DESTINATION_WEIGHT = { min: 0, max: 100 };
// Tous les réglages modifiables ici : ceux des groupes rangés dans un onglet (bornes du schéma) et ceux de chaque destination.
// L'ouverture (bandeau d'état) et le prix d'un Éclat (Boutique) se règlent ailleurs.
function editableFields(schema, destinations) {
const fromGroups = EXPEDITION_SETTING_GROUPS.filter((group) => PANEL_THEME.has(group.id)).flatMap((group) => group.fields
.map((field) => ({ ...field, ...schema.find((item) => item.path === field.path), panel: group.id })));
const fromDestinations = destinations.flatMap((destination) => [
{ path: `destinations.${destination.id}.active`, kind: "bool", panel: "destinations" },
{ path: `destinations.${destination.id}.weight`, kind: "int", ...DESTINATION_WEIGHT, panel: "destinations" }
]);
return [...fromGroups, ...fromDestinations];
}
const PANEL_THEME = new Map(EXPEDITION_SETTING_THEMES.flatMap((theme) => theme.panels.map((panel) => [panel, theme.id])));
// Destinations : proposées ou non, et poids dans le tirage du jour, une ligne alignée par destination. Leurs textes vivent dans le
// fichier du serveur.
function DestinationSettings({ destinations, draft, settings, defaults, busy }) {
return {destinations.map((destination) => {
const activePath = `destinations.${destination.id}.active`;
const weightField = { path: `destinations.${destination.id}.weight`, ...DESTINATION_WEIGHT };
const active = draft.raw(activePath);
const weight = draft.raw(weightField.path);
const changed = !same(draft.value(activePath), readPath(settings, activePath)) || !same(draft.value(weightField.path), readPath(settings, weightField.path));
return