# SDK Functions

## onOpenApp(appId, cb)

* **appId (string):** this will be the app unique name
* **cb (function):** this function will be executed when the app is oppened

```javascript
SDK.onOpenApp('customApp', () => {
    console.log('Open APP Event Triggered')
})
```

## onCloseApp(appId, cb)

* **appId (string):** this will be the app unique name
* **cb (function):** this function will be executed when the app is closed

```javascript
SDK.onCloseApp('customApp', () => {
  console.log('Close APP Event Triggered')
})
```

## setContextMenu(buttons)

* **buttons (**<mark style="color:red;">**array**</mark>**):** array of objects that contain the buttons information
  * **title (**<mark style="color:purple;">**string**</mark>**):** the label of the button
  * **color (**<mark style="color:purple;">**string**</mark>**):** the button text color

```javascript
SDK.setContextMenu([
  {
    title: 'Click ME',
    color: 'white',
    cb: () => {
      console.log('Button clicked')
    }
  },
])
```

## setPopUp(info)

* **info (**<mark style="color:orange;">**object**</mark>**):** element that contains all the information of the popup that will be created
  * **title (**<mark style="color:purple;">**string**</mark>**):** this is the title of the popup
  * **description (**<mark style="color:purple;">**string-**</mark><mark style="color:blue;">**optional**</mark>**):** this is the description of the popup
  * **input (**<mark style="color:orange;">**object-**</mark><mark style="color:blue;">**optional**</mark>**):** these are the input html attributes
  * **media (**<mark style="color:purple;">**string-**</mark><mark style="color:blue;">**optional**</mark>**):** this is an image or video URL
  * **code (**<mark style="color:purple;">**string-**</mark><mark style="color:blue;">**optional**</mark>**):** this is a big text code
  * **buttons (**<mark style="color:red;">**array**</mark>**):** these are the buttons of the popup
    * **title (**<mark style="color:purple;">**string**</mark>**):** the label of the button
    * **color (**<mark style="color:purple;">**string**</mark>**):** the color of the button text
    * **cb (**<mark style="color:yellow;">**function**</mark>**):** when a button is clicked, this will be triggered
      * **inputContent (**<mark style="color:purple;">**string**</mark>**):** this is an attribute that cb returns with the input value

<pre class="language-javascript"><code class="lang-javascript"><strong>SDK.setPopUp({
</strong>  title: 'This is the title',
  description: 'This is the description',
  code: '958',
  media: 'https://r2.fivemanage.com/pub/zdlyvumu5gkj.png',
  input: {
    type: 'text',
    placeholder: 'Place your text here',
    maxlength: 16
  },
  buttons: [
    {
      title: 'Cancel',
      color: "#FF3A45",
      cb: () => {}
    },
    {
      title: 'Save',
      color: "#0A84FF",
      cb: (inputContent) => {
        console.log(inputContent)
      }
    }
  ]
})
</code></pre>

## fetchNui(fetchName, data, cb, scriptName)

* **fetchName (**<mark style="color:purple;">**string**</mark>**):** this is the name of the nui event
* **data (**<mark style="color:orange;">**object**</mark>**):** this is the object that is sent to the nui handler
* **cb (**<mark style="color:yellow;">**function**</mark>**):** this will return the nui data
* **scriptName (**<mark style="color:purple;">**string**</mark>**):** this is the script name that you want the nui event

```javascript
SDK.fetchNui('getCoords', {}, (returnedData) => {
  console.log(returnedData)
}, 'my-resource-name')
```

## getSettings(cb)

* **cb (**<mark style="color:yellow;">**function**</mark>**):** this will return the entire phone settings

<pre class="language-javascript"><code class="lang-javascript"><strong>SDK.getSettings((settings) => {
</strong>  console.log(settings)
})
</code></pre>

## getLocale(locale, cb)

* **locale (**<mark style="color:purple;">**string**</mark>**):** this is the name of the locale that you will get
* **cb (**<mark style="color:yellow;">**function**</mark>**):** this will return the text in the user's language

<pre class="language-javascript"><code class="lang-javascript"><strong>SDK.getLocale('camera-label', (label) => {
</strong>  console.log(label)
})
</code></pre>

## selectGallery(info)

* **info (**<mark style="color:orange;">**object**</mark>**):** this is the object containing the information of the gallery created
  * **includeImages (**<mark style="color:green;">**boolean**</mark>**):** this will include or exclude images
  * **includeVideos (**<mark style="color:green;">**boolean**</mark>**):** this will include or exclude videos
  * **limit (**<mark style="color:blue;">**number**</mark>**):** this is the limit of selections that the user can do
  * **cb (**<mark style="color:yellow;">**function**</mark>**):** this is will return the images selected by the user

<pre class="language-javascript"><code class="lang-javascript"><strong>SDK.selectGallery({
</strong>  includeImages: true,
  includeVideos: false,
  limit: 3,
  cb: (images) => {
    console.log(images)
  }
})
</code></pre>

## useCamera(info)

* **info (**<mark style="color:orange;">**object**</mark>**):** this will be an object containing all the info regarding to the camera control
  * **defaultConfig (**<mark style="color:orange;">**object**</mark>**):** this will be the starting settings of the camera
    * type (<mark style="color:purple;">string</mark>): this is the type of media that the phone will take by default
    * flash (<mark style="color:green;">boolean</mark>): this is the default status of the flash
    * camera (<mark style="color:purple;">string</mark>): this is the default starting camera
  * **permissions (**<mark style="color:orange;">**object**</mark>**):** this will be the posibilities of the player inside the camera
    * **toggleFlash (**<mark style="color:green;">**boolean**</mark>**):** player can toggle flash
    * **flipCamera (**<mark style="color:green;">**boolean**</mark>**):** player can flip the camera
    * **takePhoto (**<mark style="color:green;">**boolean**</mark>**):** player can take photos
    * **takeVideo (**<mark style="color:green;">**boolean**</mark>**):** player can take videos
  * **cb (**<mark style="color:purple;">**string**</mark>**):** this will return the media URL

```javascript
SDK.useCamera({
  defaultConfig: {
    type: 'photo', // photo, video
    flash: true,
    camera: 'rear', // rear, front
  },
  permissions: {
    toggleFlash: true,
    flipCamera: false,
    takePhoto: false,
    takeVideo: true
  },
  cb: (url) => {
    console.log(url)
  }
})
```

## onSettingsChange(cb)

* **cb (**<mark style="color:yellow;">**function**</mark>**):** this will return the entire phone settings

```javascript
SDK.onSettingsChange((settings) => {
  console.log(settings)
})
```

## isAppInstalled(appId)

* **appId (**<mark style="color:purple;">**string**</mark>**):** this is your app unique identifier

```javascript
const hasAPP = SDK.isAppInstalled('my-app-name')
```
