# Exports

This document describes **all available exports** provided by the `nm1_notification` resource, including **client-side** and **server-side** usage, parameters, defaults, and examples.

The system is **framework-agnostic** and works with ESX, QBCore, QBox, or standalone setups.

***

### Client Exports

#### `exports['nm1_notification']:Notify(data)`

Displays a notification **on the local client**.

This is the **primary and recommended client export** for showing notifications.

***

#### Parameters

`data` *(table)*

| Field      | Type   | Required | Default             | Description              |
| ---------- | ------ | -------- | ------------------- | ------------------------ |
| `title`    | string | No       | `"Notification"`    | Notification title       |
| `message`  | string | No       | `""`                | Notification body text   |
| `type`     | string | No       | `"info"`            | Notification type        |
| `duration` | number | No       | `5000`              | Duration in milliseconds |
| `position` | string | No       | Saved / `top-right` | Screen position          |
| `theme`    | string | No       | `"dark"`            | UI theme                 |

***

#### Supported Types

* `success`
* `error`
* `info`
* `warning`

***

#### Supported Positions

* `top`
* `top-right`
* `top-left`
* `bottom`
* `bottom-right`
* `bottom-left`
* `center-right`
* `center-left`

***

#### Example (Client)

```lua
exports['nm1_notification']:Notify({
    title = 'Success',
    message = 'Data saved successfully.',
    type = 'success',
    duration = 4000
})
```

***

#### Example (With Custom Position & Theme)

```lua
exports['nm1_notification']:Notify({
    title = 'Warning',
    message = 'Low fuel level.',
    type = 'warning',
    position = 'bottom-left',
    theme = 'light' -- or dark
})
```

***

### Server Exports

Server exports allow you to trigger notifications **from server-side code** to one or all players.

***

#### `exports['nm1_notification']:NotifyPlayer(src, data)`

Sends a notification to a **specific player**.

***

**Parameters**

| Field  | Type   | Required | Description                        |
| ------ | ------ | -------- | ---------------------------------- |
| `src`  | number | Yes      | Player server ID                   |
| `data` | table  | Yes      | Notification data (same as client) |

***

**Example (Server)**

```lua
exports['nm1_notification']:NotifyPlayer(source, {
    title = 'Server',
    message = 'You received a server notification.',
    type = 'info'
})
```

***

#### `exports['nm1_notification']:NotifyAll(data)`

Broadcasts a notification to **all connected players**.

***

**Parameters**

| Field  | Type  | Required | Description       |
| ------ | ----- | -------- | ----------------- |
| `data` | table | Yes      | Notification data |

***

**Example (Server)**

```lua
exports['nm1_notification']:NotifyAll({
    title = 'Announcement',
    message = 'Server restart in 5 minutes.',
    type = 'warning',
    duration = 6000
})
```

***

### Notes & Behavior

* All server exports internally trigger the client event\
  `nm1_notification:client:show`
* Saved notification position is persisted using **Resource KVP**
* Position is automatically applied:
  * On resource start
  * On player spawn
* If `position` is passed in `data`, it **overrides the saved position for that notification only**
* Theme defaults to `"dark"` if not provided

***

### Recommended Usage

| Scenario                | Recommended Export |
| ----------------------- | ------------------ |
| Client-only UI feedback | `Notify`           |
| Server → single player  | `NotifyPlayer`     |
| Server → all players    | `NotifyAll`        |

***
