import { html, nothing, type TemplateResult } from "lit";
import { weatherEntity } from "../../../weather.ts";
import { isSymcon } from "../../../entities/symcon-values.ts";
import { renderSymconWeather } from "../symcon-fields.ts";
import type { I18nKey } from "../../../i18n.ts";
import { DEFAULT_PAINT_INSIDE, DEFAULT_PAINT_OUTSIDE, DEFAULT_WEATHER_EFFECTS, WEATHER_EFFECTS, type Building, type RoofType } from "../../../model.ts";
import { entityName } from "../../../devices.ts";
import { FURNITURE_ROLES, STOCK_ROLE_HEX } from "../../../furniture-colors.ts";
import { entityOptions } from "../entities.ts";
import { renderCompass } from "./compass.ts";
import { renderMapSettings } from "./map.ts";
import { checkField, colorField, entityField, hint, numberField, selectField, textField } from "../fields.ts";
import type { EditorHost } from "../host.ts";
import { clamp, withEffect } from "../ops/settings.ts";
/** What choosing the "own sections" roof needs from the editor: it proposes sections from the rooms and opens the roof tool. */
export interface SettingsActions {
useRoofSections(): void;
}
const ROOF_TYPES = ["none", "flat", "gable", "custom"] as const;
type Backdrop = NonNullable;
/** An own background behind the house: on or off, a colour, a picture and how much it is dimmed. */
function backdropFields(host: EditorHost, b: Backdrop | null, onChange: (b: Backdrop | null) => void): TemplateResult {
const t = host.t;
const on = !!b;
const patch = (p: Partial) => onChange({ color: null, image: null, dim: 0.35, ...(b ?? {}), ...p });
return html`
${t("backdrop")}
${checkField(host, t("backdrop"), on, (v) => onChange(v ? { color: "#101828", image: null, dim: 0.35 } : null))}
${on
? html`
${numberField(host, t("backdrop_dim"), Math.round((b?.dim ?? 0.35) * 100), (v) => patch({ dim: clamp(v, 0, 80) / 100 }), 5, 0)}
${textField(host, t("backdrop_image"), b?.image ?? "", (v) => patch({ image: v || null }), { wide: true, placeholder: "/local/hintergrund.jpg" })}
${hint(t("backdrop_hint"), "nf-wide")}`
: nothing}`;
}
/** Wall thickness, grid, north, roof shape, the weather source and its effects. */
/** The plan's own sensors at the top of the 3D view: the chosen ones as chips to remove, and a picker to add one. */
function statusFields(host: EditorHost, ids: string[], set: (ids: string[]) => void): TemplateResult {
const t = host.t;
const options = entityOptions(host.hass, (id) => !ids.includes(id) && /^(sensor|binary_sensor|alarm_control_panel|weather|input_|counter|lock|climate|person|sun)\b/.test(id));
return html`