# Tripfusion JavaScript SDK

## Installation

Add the following script to the `<head>` section on all pages where the widget will be used. Replace `<client>` and `<propertyId>` with the appropriate values.

```html
<script
    id="tripfusion-sdk"
    src="https://cdn.jsdelivr.net/npm/@vacayou/tripfusion-js-sdk@latest?client=<client>&propertyId=<propertyId>"
></script>
```

## Usage

The booking widget can be controlled both via JavaScript function calls and via html-links.

**Using the widget with JS functions**  
To display the widget, you need to add the `book` function as an event handler, for example:

```html
<button onClick="book({...config})">Book Now</button>
```

The widget configuration is done using the optional [parameters](#configuration-options).
To hide the widget, you need to call the `closeWidget()` function.

**Using the widget with HTML links**  
To trigger the booking widget, simply add the following parameters to any HTML link on the page:

```
https://<link>/?tripfusion=true[&options=...]
```

The widget configuration is done by passing additional [parameters](#configuration-options) in the link (parameter names are the same as those used when calling the JS `book()` function, all parameters should be separated by `&` symbol), for example:

-   Standard booking:

```
https://website.com/?tripfusion=true
```

-   Booking with an offer:

```
https://website.com/?tripfusion=true&offerId=<offer-id>
```

-   Experience booking mode with predefined check-in and check-out dates, number of adult guests, and children (children's ages separated by commas):

```
https://website.com/?tripfusion=true&checkin=2022-10-10&checkout=2022-10-12&adults=2&children=5,7
```

## Configuration options

| Parameter  | Required             | Description                                                                                                                                                                                                                                                                                                                     |
| ---------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| client     | yes (in script tag)  | You can override the default client ID that normally should be set in `<script>` tag.                                                                                                                                                                                                                                           |
| propertyId | yes (in script tag)  | You can override the default property ID that normally should be set in `<script>` tag.                                                                                                                                                                                                                                         |
| mode       | no                   | Booking mode: `normal` or `append` (for adding items to an existing booking).                                                                                                                                                                                                                                                   |
| bookingId  | yes (in append mode) | Existing booking ID to add items to. <br> This parameter is used only when `mode` is `append`.                                                                                                                                                                                                                                  |
| offerId    | no                   | Triggers the booking widget with the settings of the specified offer.                                                                                                                                                                                                                                                           |
| checkIn    | no                   | Check-in date. Format: `YYYY-MM-DD` <br> This parameter is used only when the property is configured for experience-only mode.                                                                                                                                                                                                  |
| checkOut   | no                   | Check-out date. Format: `YYYY-MM-DD` <br> This parameter is used only when the property is configured for experience-only mode.                                                                                                                                                                                                 |
| adults     | no                   | Adult guests count. <br> This parameter is used only when the property is configured for experience-only mode.                                                                                                                                                                                                                  |
| children   | no                   | Children's ages. <br> This parameter is used only when the property is configured for experience-only mode. <br> When using the JS function, children's ages should be passed as an array, for example: `children: [5,7]`. <br> When using an HTML link, children's ages are separated by commas, for example: `&children=5,7`. |
