> ## Documentation Index
> Fetch the complete documentation index at: https://docs.skyvexsoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# useFlightManager

> Manage the full flight lifecycle.

`useFlightManager` provides direct control over the flight lifecycle: starting, pausing, resuming, ending, and commenting on flights. It hydrates state from `GET /api/flight-manager/state` and subscribes to `flight:manager` Socket.io events for real-time updates.

For most plugins, [`useTrackingSession`](/sdk/hooks/use-tracking-session) is the better starting point — it wraps `useFlightManager` with derived state (isTracking, isPaused, elapsedTime, phase) and recovery handling. Use `useFlightManager` when you need lower-level control or want to avoid the extra derived state computation.

## Import

```ts theme={null}
import { useFlightManager } from "@skyvexsoftware/stratos-sdk";
```

## Signature

```ts theme={null}
function useFlightManager(): UseFlightManagerReturn

type UseFlightManagerReturn = {
  currentFlight: CurrentFlight | null;
  startFlight: (plan: FlightPlan) => Promise<StartFlightResult>;
  pauseFlight: () => Promise<boolean>;
  resumeFlight: () => Promise<boolean>;
  endFlight: (
    status?: "completed" | "diverted" | "crashed" | "cancelled"
  ) => Promise<boolean>;
  addComment: (message: string) => Promise<boolean>;
  runPreflightChecks: (plan: FlightPlan) => Promise<PreflightCheckResult | null>;
};
```

## Return value

| Field                | Type                                                          | Description                                                  |
| -------------------- | ------------------------------------------------------------- | ------------------------------------------------------------ |
| `currentFlight`      | `CurrentFlight \| null`                                       | Active flight state, or `null` when no flight is in progress |
| `startFlight`        | `(plan: FlightPlan) => Promise<StartFlightResult>`            | Begin a new flight with the given flight plan                |
| `pauseFlight`        | `() => Promise<boolean>`                                      | Pause the active flight                                      |
| `resumeFlight`       | `() => Promise<boolean>`                                      | Resume a paused flight                                       |
| `endFlight`          | `(status?) => Promise<boolean>`                               | End the active flight with an optional terminal status       |
| `addComment`         | `(message: string) => Promise<boolean>`                       | Attach a pilot comment to the active flight                  |
| `runPreflightChecks` | `(plan: FlightPlan) => Promise<PreflightCheckResult \| null>` | Validate a flight plan before starting                       |

## Types

### `FlightPlan`

See [`FlightPlan`](/sdk/type-reference#flightplan) for the full shape.

### `StartFlightResult`

See [`StartFlightResult`](/sdk/type-reference#startflightresult) for the full shape.

### `PreflightCheckResult`

See [`PreflightCheckResult`](/sdk/type-reference#preflightcheckresult) for the full shape (includes the nested [`PreflightCheck`](/sdk/type-reference#preflightcheck) per-check entries).

### `CurrentFlight`

See [`CurrentFlight`](/sdk/type-reference#currentflight) for the full shape.

## Usage

### Start a flight

```tsx theme={null}
import { useFlightManager } from "@skyvexsoftware/stratos-sdk";

export function StartFlightButton() {
  const { startFlight, currentFlight } = useFlightManager();

  const handleStart = async () => {
    const result = await startFlight({
      source: "manual",
      callsign: "SWR123",
      departureIcao: "YSSY",
      arrivalIcao: "YMML",
      route: ["SY", "ML"],
      aircraftIcao: "B738",
    });

    if (!result.success) {
      console.error("Failed to start flight:", result.error);
    }
  };

  return (
    <button onClick={handleStart} disabled={currentFlight !== null}>
      Start Flight
    </button>
  );
}
```

### Run preflight checks first

```tsx theme={null}
const { runPreflightChecks, startFlight } = useFlightManager();

const plan: FlightPlan = { /* ... */ };

const checks = await runPreflightChecks(plan);
if (checks && !checks.passed) {
  const errors = checks.checks.filter((c) => c.severity === "error");
  console.error("Preflight failed:", errors);
  return;
}

await startFlight(plan);
```

### End a flight

```tsx theme={null}
const { endFlight } = useFlightManager();

// End with a specific status
await endFlight("completed");

// Without a status — defaults to "completed" on the server
await endFlight();
```

## Notes

* All action methods (`startFlight`, `pauseFlight`, etc.) call REST endpoints on the local shell server. They return a boolean or result object indicating success.
* State updates arrive via `flight:manager` Socket.io events — the `currentFlight` value updates reactively without polling.
* `runPreflightChecks` returns `null` if the server is unreachable.
