label('Capture snapshot') ->requiresConfirmation() ->modalHeading('Capture snapshot now') ->modalSubheading('This will fetch the latest configuration from Microsoft Graph and store a new policy version.') ->form([ Forms\Components\Checkbox::make('include_assignments') ->label('Include assignments') ->default(true) ->helperText('Captures assignment include/exclude targeting and filters.'), Forms\Components\Checkbox::make('include_scope_tags') ->label('Include scope tags') ->default(true) ->helperText('Captures policy scope tag IDs.'), ]) ->action(function (array $data) { $policy = $this->record; try { $tenant = $policy->tenant; if (! $tenant) { Notification::make() ->title('Policy has no tenant associated.') ->danger() ->send(); return; } app(VersionService::class)->captureFromGraph( tenant: $tenant, policy: $policy, createdBy: auth()->user()?->email ?? null, includeAssignments: $data['include_assignments'] ?? false, includeScopeTags: $data['include_scope_tags'] ?? false, ); Notification::make() ->title('Snapshot captured successfully.') ->success() ->send(); $this->redirect($this->getResource()::getUrl('view', ['record' => $policy->getKey()])); } catch (\Throwable $e) { Notification::make() ->title('Failed to capture snapshot: '.$e->getMessage()) ->danger() ->send(); } }) ->color('primary'), ]; } }