> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: onViewChange(handler: ViewChangeEventHandler, operation: ViewChangeOperation, timeout: number)

# Method package: w

# Method menu location: w --> DatePicker --> onViewChange

# Method Link: https://dev.wix.com/docs/velo/velo-only-apis/$w/date-picker/on-view-change.md

# Method Description:

Adds an event handler that triggers when the date picker's view changes.

When a site visitor views a new month or year in the date picker, the event handler is triggered. Selecting a new day in the current month doesn't trigger the event handler, as the month in view doesn't change. 
Each time a site visitor enters the date picker, they initiate the view, triggering the event handler. You can pass an optional `operation()` function parameter. If provided, the `operation()` function is called first, and the handler function only triggers after the operation finishes. 
You can pass an optional timeout parameter to specify how long to wait for the operation to return. If the operation doesn't resolve before the timeout, an error is returned. When the `operation()` function returns, the returned object is passed to the event handler in the `options.operationResult` object. 
> **Note:** The `operation()` function is called each time the month or year changes and the onViewChange event is triggered. If the `operation()` function takes time to return, there can be more than one instance of the function running when a site visitor clicks multiple times on the next month arrow. In these cases, only the last triggered operation is returned to the event handler and the handler only runs once.
For example, if the date picker's view is in May, and a site visitor clicks the next month arrow 3 times, the operation function is called for June, July, and August. However, the handler is only called only once with the result from the operation for August.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Get the month's start and end date dates when the date picker's view changes

```javascript
$w('#myDatePicker').onViewChange((event) => {
    let startDate = event.options.startDate; // "Tue Mar 01 2022 00:00:00 GMT-5 (Eastern Standard Time)"
    let endDate = event.options.endDate; // "Thu Mar 31 2022 23:59:59 GMT-5 (Eastern Standard Time)"
  });
```

## Set the disabledDateRanges property using public Holiday dates

```javascript
const timeout = 2000;

$w.onReady(function () {
  $w('#datePicker1').onViewChange(handler, operation, timeout);
});

async function operation() {
  // get a list of public holidays from the web 
  const listOfPublicHolidays = await getInfoFromTheWeb(); 
  return listOfPublicHolidays;
}

function handler(event) {
  const holidays = [];
  let publicHoliday;
  // get a list of public holidays from the web 
  let listOfPublicHolidays = event.options.operationResult;
  listOfPublicHolidays.forEach(holiday => {
    publicHoliday = {
      startDate: holiday.startDate,
      endDate: holiday.endDate
    }
    holidays.push(publicHoliday);
  })
  $w('#datePicker1').disabledDateRanges = holidays;
}

function getInfoFromTheWeb() {
  // fetch a list of public holidays from an API on the web

  /* sample return object:
  return [
    {
      startDate: new Date('12/31/2022'),
      endDate: new Date('01/01/2023')
    },
    {
      startDate: new Date('12/25/2022'),
      endDate: new Date('12/25/2022')
    }
  ]
  */
}
```

## Set the enabledDateRanges property using available booking slot dates

```javascript
import wixBookings from 'wix-bookings';

const myBookingsServiceId = // get my booking service ID
const timeout = 2000;

$w.onReady(function () {
  $w('#myDatePicker').onViewChange(handler, operation, timeout);
});

async function operation({options}) {
  const {startDate, endDate} = options;
  const availability = await wixBookings.getServiceAvailability(myServiceId, {startDateTime: startDate, endDateTime: endDate});
  return availability;
}

function handler(event) {
  let availableDates = [];
  const slots = event.options.operationResult.slots;
  slots.forEach(slot => {
    if (slot.bookable === true) {
      const availableSlot = {
        startDate: slot.startDateTime,
        endDate: slot.startDateTime
      }
      availableDates.push(availableSlot);
    }
  })
  $w('#datePicker1').enabledDateRanges = availableDates;
}




```

---