use crate::AppModel;
use crate::actions::{ActionsState, close_enabled, move_enabled, unclaim_enabled, verbs};
use crate::cli_outbound::{Binary, Cli};
use crate::projects::join::{JoinRow, owner_name};
use std::io;
use std::path::Path;
pub(super) fn actions(
ui: &mut egui::Ui,
model: &mut AppModel,
actions: &mut ActionsState,
bl: &Cli,
join: Option<&JoinRow>,
) {
let Some(row) = join else {
return;
};
let state_root = model.state_root().to_path_buf();
let gate = model.toolchain().clone();
let bl_ok = model.toolchain().permits(Binary::Bl);
let owner = owner_name(row);
let targets: Vec<String> = model
.workspace_names()
.into_iter()
.filter(|n| *n != owner)
.collect();
ui.horizontal(|ui| {
ui.label(format!("ball {}", row.ball_id));
if ui
.add_enabled(
close_enabled(row.state) && bl_ok,
egui::Button::new("Close"),
)
.clicked()
{
let closed = verbs::close(
&gate,
bl,
&state_root,
&super::now_ts(),
&row.project,
&row.ball_id,
&owner,
);
after_bl(closed, model, actions, &row.project);
}
if ui
.add_enabled(
unclaim_enabled(row.state) && bl_ok,
egui::Button::new("Release"),
)
.clicked()
{
let released = verbs::unclaim(
&gate,
bl,
&state_root,
&super::now_ts(),
&row.project,
&row.ball_id,
&owner,
);
after_bl(released, model, actions, &row.project);
}
});
if move_enabled(row.state) && bl_ok && !targets.is_empty() {
ui.horizontal(|ui| {
ui.label("move to:");
for to in &targets {
if ui.button(to).clicked() {
let moved = verbs::reassign(
&gate,
bl,
(&state_root, &super::now_ts()),
&row.project,
&row.ball_id,
&owner,
to,
);
after_bl(moved, model, actions, &row.project);
}
}
});
}
}
fn after_bl(
_result: io::Result<verbs::Outcome>,
model: &mut AppModel,
actions: &mut ActionsState,
project: &Path,
) {
model.after_bl_verb(project);
actions.last_failure = model.last_failure();
}