# Exports and Events

Use the public exports and events for integrations.

Prefer these over internal hooks.

### Client exports

These are the public client exports documented for Pawnshop.

#### `OpenManagementNUI(shopName, context)`

Opens the management UI for a specific shop.

Parameters:

* `shopName` - shop identifier string
* `context` - optional table with extra context data

```lua
exports['envi-pawnshop']:OpenManagementNUI('Harrison\'s Pawn Shop')
```

With context:

```lua
exports['envi-pawnshop']:OpenManagementNUI('Harrison\'s Pawn Shop', {
    tab = 'exports',
    source = 'my-resource'
})
```

#### `CloseManagementNUI()`

Closes the management UI if it is open.

```lua
exports['envi-pawnshop']:CloseManagementNUI()
```

#### `IsManagementNUIOpen()`

Returns whether the management UI is currently open.

Returns:

* `boolean`

```lua
local isOpen = exports['envi-pawnshop']:IsManagementNUIOpen()

if isOpen then
    print('Pawnshop UI is open')
end
```

#### `GetCurrentShopName()`

Returns the current shop name being managed.

Returns:

* `string|nil`

```lua
local currentShop = exports['envi-pawnshop']:GetCurrentShopName()

if currentShop then
    print('Managing shop:', currentShop)
end
```

#### `SendUINotification(message, type, duration)`

Sends a notification into the Pawnshop UI.

If the UI is closed, it falls back to the framework notification path.

Parameters:

* `message` - notification text
* `type` - `success`, `error`, `warning`, or `info`
* `duration` - optional duration in ms

```lua
exports['envi-pawnshop']:SendUINotification('Order accepted', 'success', 4000)
```

#### `PlayUISound(sound)`

Plays a UI sound effect.

Parameters:

* `sound` - sound name string

```lua
exports['envi-pawnshop']:PlayUISound('confirm')
```

#### `CleanupExportDelivery()`

Cleans up an active export delivery flow.

Use this when your integration cancels or forcibly resets a delivery.

```lua
exports['envi-pawnshop']:CleanupExportDelivery()
```

#### `CleanupSupplierMission()`

Cleans up an active supplier or collection mission.

```lua
exports['envi-pawnshop']:CleanupSupplierMission()
```

#### `IsSupplierMissionActive()`

Returns whether the local player currently has an active supplier mission.

Returns:

* `boolean`

```lua
local missionActive = exports['envi-pawnshop']:IsSupplierMissionActive()

if missionActive then
    print('Supplier mission already active')
end
```

### Example export usage

#### Open the UI only if it is not already open

```lua
if not exports['envi-pawnshop']:IsManagementNUIOpen() then
    exports['envi-pawnshop']:OpenManagementNUI('Harrison\'s Pawn Shop')
end
```

#### Send a UI notification only when the player is inside Pawnshop UI

```lua
if exports['envi-pawnshop']:IsManagementNUIOpen() then
    exports['envi-pawnshop']:SendUINotification('Hello from another resource!', 'info', 5000)
end
```

#### Get the current managed shop and branch your logic

```lua
local currentShop = exports['envi-pawnshop']:GetCurrentShopName()

if currentShop == 'Harrison\'s Pawn Shop' then
    print('Run Harrison-specific logic here')
end
```

#### Reset both mission types during a forced cleanup

```lua
exports['envi-pawnshop']:CleanupExportDelivery()
exports['envi-pawnshop']:CleanupSupplierMission()
```

### Related pages

* [Database Schema](https://envi-scripts-organization.gitbook.io/documentation/premium-scripts/envi-pawnshop/database-schema)
* [Customization Guide](https://envi-scripts-organization.gitbook.io/documentation/premium-scripts/envi-pawnshop/customization-guide)
