/**
* Site settings for schedules (RFC-0008 §15.1 "Site settings", §11.5–§11.6): the General section's
* "Time zone" field (`Site.timeZone`, a `Combobox` over the browser's IANA zones with the browser's
* own suggested), and the Schedules section — the scheduler's health, the site's kill switch (with
* a reason, confirmed) and the daily automation write cap with today's use. Words come from the
* lazy `scheduleSettings` namespace, loaded with the settings route.
*/
import { formatNumber } from "@cloudhal/messages/format";
import {
Badge,
Banner,
Button,
Combobox,
Input,
InputArea,
LayerDialog,
Meter,
SkeletonLine,
Switch,
Text,
} from "@cloudhal/ui";
import { ArrowClockwise, PauseCircle, WarningCircle } from "@phosphor-icons/react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useEffect, useMemo, useState } from "react";
import { useI18n } from "../i18n/index.tsx";
import { ApiRequestError, api, isNotEnabled, type ScheduleSettings } from "../lib/api.ts";
import { apiErrorText } from "../lib/api-errors.ts";
import { browserZone, formatMoment, knownZones, zoneLabel } from "../lib/schedules.ts";
import { schedulesApi } from "../lib/schedules-api.ts";
import { SettingRow, SettingsSection } from "./Settings.tsx";
import { useToast } from "./Toast.ts";
import { useGate } from "./useMe.ts";
export const SCHEDULE_SETTINGS_SECTION = "schedules";
interface ZoneOption {
value: string;
label: string;
}
/**
* "Time zone" (`Site.timeZone`): a searchable `Combobox` of the zones this browser knows, written
* "Istanbul (UTC+3)", with the browser's own zone offered first. Empty means UTC.
*/
export function TimeZoneField({
value,
onChange,
disabled,
invalid,
}: {
value: string;
onChange: (zone: string) => void;
disabled?: boolean;
/** The server refused the zone (`invalid_time_zone`). */
invalid?: boolean;
}) {
const { t } = useI18n("scheduleSettings");
const z = "scheduleSettings.timeZone" as const;
const mine = browserZone();
const options: ZoneOption[] = useMemo(() => {
const now = Date.now();
const zones = knownZones();
const ordered = [mine, ...zones.filter((zone) => zone !== mine)];
return ordered.map((zone) => ({ value: zone, label: `${zoneLabel(zone, now)} · ${zone}` }));
}, [mine]);
const selected = options.find((o) => o.value === (value || "UTC")) ?? null;
return (