use super::{Owes, Seat};
use crate::AppModel;
use crate::boundary::Action;
use crate::shell::ShellState;
use crate::start::Prepared;
use std::path::Path;
pub(in crate::shell) fn fan(
model: &mut AppModel,
state: &mut ShellState,
ws: &Path,
prepared: &Prepared,
n: usize,
) {
let ctx = model.line_context();
let (Some(project), Some(crate::start::BallSpec::Existing { id, .. })) =
(ctx.project, ctx.ball)
else {
state.slash = Some(
"nothing to fan over — a fan spends the focused ball's delivery obligation, \
and this workspace holds none"
.to_owned(),
);
return;
};
let action = Action::Fan(crate::fan::Verb::Spread {
prepared: prepared.clone(),
obligation: crate::fan::Obligation {
project,
ball: Some(id),
},
n,
});
super::hold(
model,
state,
ws,
&action,
Seat::Quiet,
Owes::Fanned {
goal: prepared.goal.clone(),
},
);
}
pub(super) fn fanned(
model: &mut AppModel,
state: &mut ShellState,
ws: &Path,
candidates: &[Prepared],
goal: &str,
) -> bool {
state.start.fan_n = 1;
let Some((last, rest)) = candidates.split_last() else {
return false;
};
for prepared in rest {
model.post_act(&Action::Prompt {
prepared: prepared.clone(),
goal: goal.to_owned(),
seed: None,
});
}
super::start::prompt(model, state, ws, last, goal);
true
}