Select::make('checklist_template_id')
->label('Checklist Template')
->live()
->visible(fn (Get $get) => $get('model_id') !== null)
->relationship('checklistTemplate', 'name'),
CheckboxList::make('results')
->live()
->options(function (Get $get): array {
$checklistTemplateId = $get('checklist_template_id');
$checklistTemplate = ChecklistTemplate::find($checklistTemplateId);
if (! $checklistTemplate) {
return [];
}
if ($checklistTemplate->checklist_class) {
$checklistClass = ChecklistManager::getChecklistClass($checklistTemplate->checklist_class);
$checklistObject = new $checklistClass(Order::find($get('model_id')));
return $checklistObject->getKeys();
}
return $checklistTemplate->checklist_keys;
})
->default(function (Get $get) {
ray('checklist-default-called');
$checklistTemplateId = $get('checklist_template_id');
$checklistTemplate = ChecklistTemplate::find($checklistTemplateId);
if (! $checklistTemplate) {
return [];
}
if ($checklistTemplate->checklist_class) {
$checklistClass = ChecklistManager::getChecklistClass($checklistTemplate->checklist_class);
$checklistObject = new $checklistClass(Order::find($get('model_id')));
$result = $checklistObject->getKeysThatAreTrueFromAutoChecks();
return $result;
}
return [];
})
->visible(fn (Get $get): bool => $get('checklist_template_id') !== null)
->bulkToggleable(),