# Towers

> The component that draws a whole towers response.

`<Towers />` takes the API response and draws every tower in it: one section per risk, the risk's towers side by side, and a key underneath.

```tsx
import { Towers } from '@vinsa/towers';
import '@vinsa/towers/styles.css';

<Towers data={response} />;
```

When the response has more than one risk, each gets a heading: the insured's name, or failing that the policy reference or risk id.

## Props

| Prop | Type | Default | |
| --- | --- | --- | --- |
| `data` | `TowersResponse` | required | The API response, unchanged. |
| `riskId` | `string` | every risk | Draw only this risk. |
| `selectedKey` | `string \| null` | own state | The highlighted layer. Pass it to control selection yourself. |
| `onSelect` | `(key, risk) => void` | | Called when a layer is clicked. `key` is `null` when the selection is cleared. |
| `loss` | `number \| null` | `null` | Draws a loss of this amount up every tower. |
| `scale` | `'amount' \| 'even'` | `'amount'` | Heights to scale, or every band the same height. |
| `height` | `number` | `420` | Plot height of each tower, in pixels. |
| `legend` | `boolean` | `true` | Show the key under each risk, including an Other reinsurers entry when that block is present. |
| `className` | `string` | | Added to the outer element. |

## One risk at a time

Pass `riskId` to draw a single risk, for a page with a risk picker of its own.

```tsx
<Towers data={response} riskId="R-1001" />
```

## Selection

Clicking a layer highlights it and dims the rest. Clicking it again, or the empty plot, clears the selection.

Left alone, the component remembers the selection itself. To react to it, pass `onSelect`. The `key` is the layer's `layerRef`, or its `layerName` when it has no reference.

```tsx
<Towers
  data={response}
  onSelect={(key, risk) => {
    if (key) openLayerPanel(risk.riskId, key);
  }}
/>
```

To own the selection, for example to keep it in the URL, pass `selectedKey` as well:

```tsx
const [selected, setSelected] = useState<string | null>(null);

<Towers data={response} riskId={riskId} selectedKey={selected} onSelect={setSelected} />;
```

A controlled `selectedKey` applies to every risk on show, so pair it with `riskId`.

## Scale

`scale="amount"` draws heights in proportion to amounts, which is truthful but can squash a small layer under a large one. `scale="even"` gives every band the same height so each layer is readable.

## Loss

`loss` washes the tower up to that amount and flags the level. See [Test a loss](https://towers.vinsa.dev/docs/guides/loss.md).
