/**
 * Snippet action helpers that pair a store mutation with its user-facing
 * confirmation, so every trigger of an action behaves identically.
 *
 * `publishActiveSnippet` is the single publish-with-confirmation path: the
 * Publish button (SpecEditor) and the Cmd/Ctrl+S shortcut (EventRouter) both go
 * through it, so the success toast (spec §03D) fires no matter how the user
 * published. Without this, Cmd+S published silently while the button toasted — a
 * trigger-dependent inconsistency.
 */

import { notify } from '../stores/NotificationStore';
import { useSnippetStore } from '../stores/SnippetStore';

/**
 * Publish the active snippet's draft and confirm it. No-op (no toast) when no
 * snippet is active. The toast copy follows the council's rule (architecture 10
 * → Toast copy): the title states the action, the message adds the consequence.
 */
export function publishActiveSnippet(): void {
  if (!useSnippetStore.getState().activeSnippetId) return;
  useSnippetStore.getState().publish();
  notify({
    kind: 'success',
    title: 'Snippet published',
    message: 'Your draft is now the published version.',
  });
}
