# Exports

## Notification

#### 1. `Notify`

The `Notify` function is used to display a simple notification with customizable options such as type, title, message, icon, duration, position, and style.

**Usage:**

```lua
Notify(type, title, message, icon, duration, position, style)
```

**Parameters**

* `type` (string): The type of notification. Options are:
  * `"info"` (default)
  * `"success"`
  * `"warning"`
  * `"error"`
* `title` (string)
* `message` (string)
* `icon` (string, optional) Default is `nil` (no icon).
* `duration` (number, optional) Default is `3000`.
* `position` (string, optional):
  * `"top-left"`
  * `"top-center"`
  * `"top-right"`
  * `"bottom-left"`
  * `"bottom-center"`
  * `"bottom-right"`
  * Default is `"top-center"`.
* `style` (table, optional): A table of custom CSS properties to style the notification.

### **Example: Using Export**

```lua
exports["core_notifiche"]:Notify('success', 'Successo', 'Operazione completata con successo!', nil, 3000, 'top-center')
```

### Example: Server Side Event

```lua
TriggerClientEvent("core_notifiche:Notify", source, 'error', 'Errore', 'Si è verificato un errore!', nil, 3000, 'bottom-left')
```

## Promise

The `Promise` function is used for promise-based notifications that show a loading state and then display either a success or failure message based on the outcome of an asynchronous operation.

**Usage**

```lua
exports["core_notifiche"]:Promise(loadingMessage, resultHandler, options)
```

**Parameters**

* `loadingMessage` (string): The message to display while the notification is in a loading state.
* `resultHandler` (function): A function that determines the outcome of the operation. It takes a callback function (`cb_NotificationPromise`) as a parameter, which must be called with:
  * `resultMessage` (string): The message to display upon completion.
  * `isSuccess` (boolean): Whether the operation was successful (`true`) or failed (`false`).
* `options` (table, optional): A table of custom options for the notification:
  * `icon` (string, optional): Custom icon or emoji for the notification.
  * `duration` (number, optional): Duration of the notification in milliseconds.
  * `position` (string, optional): Position of the notification on the screen (same options as `Notify`).
  * `style` (table, optional): Custom CSS properties for the notification style.

### **Example: Using Export**

```lua
exports["core_notifiche"]:Promise('Loading...', function(cb_NotificationPromise)
    ESX.TriggerServerCallback('esx:checkitem', function(hasItem)
        if hasItem then 
            cb_NotificationPromise('You have the item!', true)
        else
            cb_NotificationPromise('You miss something', false)
        end
    end, "lockpick")
end, { -- Optional custom styling
    icon = '✔️', -- Custom icon || Leave this as nil otherwise the result will have this icon too!
    duration = 5000, -- Duration in milliseconds
    position = 'bottom-right', -- Toast position
    style = { -- Custom CSS style
        background = '#4B0082',
        color = '#FFD700',
        fontSize = '18px'
    }
})
```

### Example: Server Side Event

```lua
TriggerClientEvent("core_notifiche:Promise", source, 'Caricamento in corso...', function(cb_NotificationPromise)
    CheckItem(function(hasItem)
        if hasItem then 
            cb_NotificationPromise('You have the item!', true)
        else
            cb_NotificationPromise('You miss something', false)
        end
    end, "lockpick")
end, { -- Optional custom styling
    icon = '✔️', -- Custom icon || Leave this as nil otherwise the result will have this icon too!
    duration = 5000, -- Duration in milliseconds
    position = 'bottom-right', -- Toast position
    style = { -- Custom CSS style
        background = '#4B0082',
        color = '#FFD700',
        fontSize = '18px'
    }
})
```
