use super::{ConfigState, RELOAD_HINT, form_ui, status};
use crate::config_edit::form::{self, CADENCE_SCHEMA};
use status::{describe_saved, reload_status, status_line};
pub(super) fn render(ui: &mut egui::Ui, config: &mut ConfigState) {
ui.heading("yog clock");
ui.monospace(config.cadence_editor.path().display().to_string());
ui.weak(
"the watcher-cycle cadence — worker sweeps, debounce, and every rhythm \
derived from them; delete the file to restore the defaults",
);
let groups = form::read(&CADENCE_SCHEMA, config.cadence_editor.draft(), &[]);
if let Some((row, value)) = form_ui::render(ui, "cadence", &groups, &[]) {
match form::write(&CADENCE_SCHEMA, config.cadence_editor.draft(), &row, &value) {
Ok(text) => {
config.cadence_editor.set_draft(text);
config.cadence_status =
format!("{}.{} drafted — Apply to write", row.entry, row.field);
}
Err(e) => config.cadence_status = e.to_string(),
}
}
egui::CollapsingHeader::new("raw text")
.id_salt("raw-cadence")
.show(ui, |ui| {
form_ui::raw_editor(ui, config.cadence_editor.draft_mut());
})
.header_response
.on_hover_text(
"Open the file's raw text — everything it carries beyond the settings \
above. Edits here change nothing until Apply. No key of its own: Tab \
reaches it, Space presses it.",
);
ui.horizontal(|ui| {
if ui
.button("Apply")
.on_hover_text(
"Write cadence.yaml to disk. The worker adopts the new rhythms on \
its next sweep — no restart needed. Typed, it is \
`/config cadence <text…>`.",
)
.clicked()
{
config.cadence_status = describe_saved(config.cadence_editor.apply(&config.io));
}
if ui.button("Reload").on_hover_text(RELOAD_HINT).clicked() {
config.cadence_status = reload_status(config.cadence_editor.reload(&config.io));
}
});
status_line(ui, &config.cadence_status);
}