/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ 20
(__unused_webpack_module, exports, __webpack_require__) {

var __webpack_unused_export__;
/**
 * @license React
 * react-jsx-runtime.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var f=__webpack_require__(609),k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};
function q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=""+g);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__webpack_unused_export__=l;exports.jsx=q;__webpack_unused_export__=q;


/***/ },

/***/ 848
(module, __unused_webpack_exports, __webpack_require__) {



if (true) {
  module.exports = __webpack_require__(20);
} else // removed by dead control flow
{}


/***/ },

/***/ 609
(module) {

module.exports = window["React"];

/***/ },

/***/ 428
(module) {

module.exports = window["jQuery"];

/***/ },

/***/ 723
(module) {

module.exports = window["wp"]["i18n"];

/***/ }

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	const __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		const cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		const module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/compat get default export */
/******/ 	(() => {
/******/ 		// getDefaultExport function for compatibility with non-harmony modules
/******/ 		__webpack_require__.n = (module) => {
/******/ 			const getter = module && module.__esModule ?
/******/ 				() => (module['default']) :
/******/ 				() => (module);
/******/ 			__webpack_require__.d(getter, { a: getter });
/******/ 			return getter;
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/define property getters */
/******/ 	(() => {
/******/ 		// define getter/value functions for harmony exports
/******/ 		__webpack_require__.d = (exports, definition) => {
/******/ 			if(Array.isArray(definition)) {
/******/ 				var i = 0;
/******/ 				while(i < definition.length) {
/******/ 					var key = definition[i++];
/******/ 					var binding = definition[i++];
/******/ 					if(!__webpack_require__.o(exports, key)) {
/******/ 						if(binding === 0) {
/******/ 							Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] });
/******/ 						} else {
/******/ 							Object.defineProperty(exports, key, { enumerable: true, get: binding });
/******/ 						}
/******/ 					} else if(binding === 0) { i++; }
/******/ 				}
/******/ 			} else {
/******/ 				for(var key in definition) {
/******/ 					if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 						Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 					}
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	(() => {
/******/ 		__webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop))
/******/ 	})();
/******/ 	
/************************************************************************/
let __webpack_exports__ = {};

;// external ["wp","element"]
const external_wp_element_namespaceObject = window["wp"]["element"];
;// external ["wp","components"]
const external_wp_components_namespaceObject = window["wp"]["components"];
// EXTERNAL MODULE: external "jQuery"
var external_jQuery_ = __webpack_require__(428);
var external_jQuery_default = /*#__PURE__*/__webpack_require__.n(external_jQuery_);
// EXTERNAL MODULE: ./node_modules/react/jsx-runtime.js
var jsx_runtime = __webpack_require__(848);
;// ./src/js/writepanel.js




external_jQuery_default()(document).ready(function ($) {
  $('#bookings_availability, #bookings_pricing, .bookings_extension').on('change', '.wc_booking_availability_type select, .wc_booking_pricing_type select', function () {
    const value = $(this).val();
    const tr = $(this).closest('tr');
    const row = $(tr);

    // cleanup
    row.find('.from_date, .from_day_of_week, .from_month, .from_week, .from_time, .from').hide();
    row.find('.to_date, .to_day_of_week, .to_month, .to_week, .to_time, .to').hide();
    row.find('.repeating-label').hide();
    row.find('.bookings-datetime-select-to').removeClass('bookings-datetime-select-both');
    row.find('.bookings-datetime-select-from').removeClass('bookings-datetime-select-both');
    row.find('.bookings-to-label-row .bookings-datetimerange-second-label').hide();
    row.find('.rrule').hide();
    if (value === 'custom') {
      row.find('.from_date, .to_date').show();
    }
    if (value === 'custom:daterange') {
      row.find('.from_time, .to_time').show();
      row.find('.from_date, .to_date').show();
      row.find('.bookings-datetime-select-to').addClass('bookings-datetime-select-both');
      row.find('.bookings-datetime-select-from').addClass('bookings-datetime-select-both');
      row.find('.bookings-to-label-row .bookings-datetimerange-second-label').show();
    }
    if (value === 'months') {
      row.find('.from_month, .to_month').show();
    }
    if (value === 'weeks') {
      row.find('.from_week, .to_week').show();
    }
    if (value === 'days') {
      row.find('.from_day_of_week, .to_day_of_week').show();
    }
    if (value.match('^time')) {
      row.find('.from_time, .to_time').show();
      // Show the date range as well if "time range for custom dates" is selected
      if (value === 'time:range') {
        row.find('.from_date, .to_date').show();
        row.find('.repeating-label').show();
        row.find('.bookings-datetime-select-to').addClass('bookings-datetime-select-both');
        row.find('.bookings-datetime-select-from').addClass('bookings-datetime-select-both');
        row.find('.bookings-to-label-row .bookings-datetimerange-second-label').show();
      }
    }
    if (value === 'persons' || value === 'duration' || value === 'blocks') {
      row.find('.from, .to').show();
    }
    if (value === 'rrule') {
      row.find('.rrule').show();
    }
    $('#availability_rows tr').show();
  });

  /**
   * Sanitizes the start and end dates when datepicker value
   * is set through on onSelect.
   *
   * If date comparison fails, it sets both the start and end dates
   * to the same date.
   *
   * @param {Object} ref Reference to the input HTML DOM element.
   */
  function startEndDateSanitizer(ref) {
    const input = $(ref);
    const dateType = input.closest('div').attr('class');
    const todaysDate = new Date();
    let startDate,
      endDate = null;
    let inputComplement = null;
    switch (dateType) {
      case 'from_date':
        inputComplement = input.closest('tr').find('.to_date .date-picker');
        startDate = input.datepicker('getDate');
        endDate = inputComplement.datepicker('getDate');
        if (startDate < todaysDate) {
          input.datepicker('setDate', todaysDate);
        } else if (endDate && startDate > endDate) {
          inputComplement.datepicker('setDate', startDate);
        }
        break;
      case 'to_date':
        inputComplement = input.closest('tr').find('.from_date .date-picker');
        endDate = input.datepicker('getDate');
        startDate = inputComplement.datepicker('getDate');
        if (endDate < startDate) {
          input.datepicker('setDate', startDate);
        }
        break;
      default:
        break;
    }
  }
  $(document).ready(function () {
    // Destroy all instances of date picker under availability rows.
    $('#availability_rows .date-picker, #pricing_rows .date-picker, #rates_rows .date-picker').datepicker('destroy');
    initializeDatepickers();
  });
  $('body').on('row_added', function () {
    $('.wc_booking_availability_type select, .wc_booking_pricing_type select').trigger('change');
    initializeDatepickers();
  });

  /**
   * Initializes datepickers throughout bookings.
   */
  function initializeDatepickers() {
    $('#availability_rows .date-picker, #pricing_rows .date-picker, #rates_rows .date-picker, .booking_start_date_field').datepicker({
      dateFormat: 'yy-mm-dd',
      numberOfMonths: 1,
      showButtonPanel: true,
      showOn: 'button',
      buttonImage: wc_bookings_admin_js_params.calendar_image,
      buttonImageOnly: true,
      minDate: 0,
      firstDay: parseInt(wc_bookings_admin_js_params.start_of_week, 10),
      onSelect() {
        startEndDateSanitizer(this);
      },
      beforeShow(input, datePicker) {
        datePicker.dpDiv.addClass('wc-bookings-ui-datepicker-widget');
        if ($(input).parent().hasClass('to_date')) {
          const fromDate = $(input).closest('tr').find('.from_date .date-picker').datepicker('getDate');
          return {
            minDate: fromDate
          };
        }
        return {
          minDate: 0
        };
      },
      onClose(dateText, datePicker) {
        datePicker.dpDiv.removeClass('wc-bookings-ui-datepicker-widget');
      }
    });
  }
  $(document).on('change', '#availability_rows .date-picker, #pricing_rows .date-picker', function () {
    startEndDateSanitizer(this);
  });
  $('body').on('woocommerce-product-type-change', function (event, type) {
    if (type !== 'booking') {
      $('#_wc_booking_has_persons').prop('checked', false);
      $('#_wc_booking_has_resources').prop('checked', false);
    }
    wcBookingsTriggerChangeEvents();
  });
  function wcBookingsTriggerChangeEvents() {
    $('.wc_booking_availability_type select, .wc_booking_pricing_type select, #_wc_booking_duration_type, #_wc_booking_user_can_cancel, #_wc_booking_duration_unit, #_wc_booking_has_persons, #_wc_booking_has_resources, #_wc_booking_has_person_types, #_wc_booking_has_restricted_days').trigger('change');
  }
  $('input#_virtual').on('change', function () {
    wcBookingsTriggerChangeEvents();
  });
  $('#_wc_booking_duration_type').on('change', function () {
    if ($(this).val() === 'customer') {
      $('#min_max_duration').show();
    } else {
      $('#min_max_duration').hide();
    }
  });

  // limit hourly duration up to 24.
  $('#_wc_booking_duration, #_wc_booking_duration_unit, #_wc_booking_default_date_availability').on('change', function () {
    limitHourlyDuration($(this));
  });
  $('#_wc_booking_duration_unit').on('change', function () {
    $('.availability_time, ._wc_booking_first_block_time_field').hide();
    $('#enable-range-picker').hide();
    $('._wc_booking_apply_adjacent_buffer_field').show();
    $('._wc_booking_buffer_period').show();
    switch ($(this).val()) {
      case 'hour':
      case 'minute':
        const unitText = $(this).val() === 'hour' ? wc_bookings_admin_js_params.i18n_hours : wc_bookings_admin_js_params.i18n_minutes;
        $('._wc_booking_buffer_period_unit').text(unitText);
        $('.availability_time, ._wc_booking_first_block_time_field').show();
        break;
      case 'month':
        $('#enable-range-picker').show();
        $('._wc_booking_buffer_period').hide();
        $('._wc_booking_apply_adjacent_buffer_field').hide();
        break;
      default:
        //day
        $('#enable-range-picker').show();
        $('._wc_booking_buffer_period_unit').text(wc_bookings_admin_js_params.i18n_days);
        break;
    }
  });
  $('#_wc_booking_user_can_cancel').on('change', function () {
    if ($(this).is(':checked')) {
      $('.form-field.booking-cancel-limit').show();
    } else {
      $('.form-field.booking-cancel-limit').hide();
    }
  });
  $('#_wc_booking_has_persons').on('change', function () {
    if ($(this).is(':checked')) {
      $('#persons-options, .bookings_persons_tab').show();
    } else {
      $('#persons-options, .bookings_persons_tab').hide();
    }
    $('ul.wc-tabs li:visible').eq(0).find('a').trigger('click');
  });
  $('#_wc_booking_has_person_types').on('change', function () {
    if ($(this).is(':checked')) {
      $('#persons-types').show();
    } else {
      $('#persons-types').hide();
    }
  });
  $('#_wc_booking_has_resources').on('change', function () {
    if ($(this).is(':checked')) {
      $('.bookings_resources_tab').show();
      $('._wc_booking_qty_field').addClass('blur').attr('data-note', wc_bookings_admin_js_params.i18n_max_booking_overwridden);
    } else {
      $('.bookings_resources_tab').hide();
      $('._wc_booking_qty_field').removeClass('blur');
    }
    $('ul.wc-tabs li:visible').eq(0).find('a').trigger('click');
  });
  $('#_wc_booking_has_restricted_days').on('change', function () {
    if ($(this).is(':checked')) {
      $('.booking-day-restriction').show();
    } else {
      $('.booking-day-restriction').hide();
    }
  });
  wcBookingsTriggerChangeEvents();
  $('#availability_rows, #pricing_rows').sortable({
    items: 'tr',
    cursor: 'move',
    axis: 'y',
    handle: '.sort',
    scrollSensitivity: 40,
    forcePlaceholderSize: true,
    helper: 'clone',
    opacity: 0.65,
    placeholder: 'wc-metabox-sortable-placeholder',
    start(event, ui) {
      ui.item.css('background-color', '#f6f6f6');
    },
    stop(event, ui) {
      ui.item.removeAttr('style');
      ui.item.show();

      // loop through each of the rows
      external_jQuery_default()(event.target).find('tr').each(function (rowIndex, item) {
        // update all the form field indexes in the current moved tr
        const fields = external_jQuery_default()(item).find('[name*="wc_booking"]');
        for (let i = 0; i < fields.length; i++) {
          const field = fields[i];
          const oldName = external_jQuery_default()(field).attr('name');
          const newName = oldName.replace(/[\d+]/g, rowIndex);
          if (newName !== oldName) {
            external_jQuery_default()(field).attr('name', newName);
          }
        }
      });
    }
  });
  $('.add_row').on('click', function (e) {
    const indexField = $(e.target).closest('table').find('#pricing_rows tr:last [name*=wc_booking_pricing_type]').attr('name');
    const newRowIndex = indexField ? parseInt(indexField.replace(/[^\[]+\[(.*)\]/, '$1'), 10) + 1 : 0;
    let newRow = $(this).data('row');
    newRow = newRow.replace(/bookings_cost_js_index_replace/gi, newRowIndex.toString());
    // Clear out IDs.
    newRow = newRow.replace(/wc_booking_availability_id.+/, 'wc_booking_availability_id[]" value="" />');
    newRow = newRow.replace(/data-id=.+/, 'data-id="">');

    // Clear out title.
    newRow = newRow.replace(/wc_booking_availability_title.+/, 'wc_booking_availability_title[]" value="" style="border:1px solid #ddd;background-color:#fff;" />');

    // Clear out priority.
    newRow = newRow.replace(/wc_booking_availability_priority.+/, 'wc_booking_availability_priority[]" value="10" placeholder="10" />');
    const tableBody = $(this).closest('table').find('tbody');
    tableBody.append(newRow);
    $('body').trigger('row_added', tableBody.find('tr:last'));
    return false;
  });
  $('body').on('click', 'td.remove', function () {
    const row = $(this).parent('tr'),
      id = row.data('id');

    // Get current deleted list.
    let deleted = $('.wc-booking-availability-deleted').val();

    // Add to deleted list.
    deleted = deleted + ',' + id;
    $('.wc-booking-availability-deleted').val(deleted);
    row.remove();
  });
  $('#bookings_persons').on('change', 'input.person_name', function () {
    $(this).closest('.woocommerce_booking_person').find('span.person_name').text($(this).val());
  });

  // limit hourly duration up to 24.
  function limitHourlyDuration(_this) {
    const bookingDuration = $('#_wc_booking_duration');
    if ($('#_wc_booking_duration_unit').val() === 'hour' && bookingDuration.val() > 24 && $('#_wc_booking_default_date_availability').val() === 'non-available') {
      _this.parents('.form-field').addClass('limited-hours');
      const limitedHoursNotice = _this.parents('._wc_booking_default_date_availability_field').length !== 0 ? wc_bookings_admin_js_params.i18n_limited_hours_in_gen_tab : wc_bookings_admin_js_params.i18n_limited_hours;
      _this.parents('.form-field').addClass('limited-hours').attr('data-note', limitedHoursNotice);
      bookingDuration.val(24);
    } else {
      $('.form-field').removeClass('limited-hours');
    }
  }

  // Add a person type
  external_jQuery_default()('#bookings_persons').on('click', 'button.add_person', function () {
    external_jQuery_default()('.woocommerce_bookable_persons').block({
      message: null
    });
    const loop = external_jQuery_default()('.woocommerce_booking_person').length;
    const data = {
      action: 'woocommerce_add_bookable_person',
      post_id: wc_bookings_admin_js_params.post,
      loop,
      security: wc_bookings_admin_js_params.nonce_add_person
    };
    external_jQuery_default().post(wc_bookings_admin_js_params.ajax_url, data, function (response) {
      external_jQuery_default()('.woocommerce_bookable_persons').append(response).unblock();
      external_jQuery_default()('.woocommerce_bookable_persons #message').hide();
      $('.woocommerce_bookable_persons').sortable(personsSortableOptions);
      // Trigger change to set max attribute.
      $('#_wc_booking_max_persons_group').trigger('change');
    });
    return false;
  });

  // Remove a person type
  external_jQuery_default()('#bookings_persons').on('click', 'button.unlink_booking_person', function (e) {
    e.preventDefault();
    // eslint-disable-next-line no-alert
    const answer = window.confirm(wc_bookings_admin_js_params.i18n_remove_person);
    if (answer) {
      const el = external_jQuery_default()(this).parent().parent();
      const person = external_jQuery_default()(this).attr('rel');
      if (person > 0) {
        external_jQuery_default()(el).block({
          message: null
        });
        const data = {
          action: 'woocommerce_unlink_bookable_person',
          person_id: person,
          security: wc_bookings_admin_js_params.nonce_unlink_person
        };
        external_jQuery_default().post(wc_bookings_admin_js_params.ajax_url, data, function () {
          external_jQuery_default()(el).fadeOut('300', function () {
            external_jQuery_default()(el).remove();
          });
        });
      } else {
        external_jQuery_default()(el).fadeOut('300', function () {
          external_jQuery_default()(el).remove();
        });
      }
    }
    return false;
  });
  const personsSortableOptions = {
    items: '.woocommerce_booking_person',
    cursor: 'move',
    axis: 'y',
    handle: 'h3',
    scrollSensitivity: 40,
    forcePlaceholderSize: true,
    helper: 'clone',
    opacity: 0.65,
    placeholder: 'wc-metabox-sortable-placeholder',
    start(event, ui) {
      ui.item.css('background-color', '#f6f6f6');
    },
    stop(event, ui) {
      ui.item.removeAttr('style');
      personRowIndexes();
    }
  };
  $('.woocommerce_bookable_persons').sortable(personsSortableOptions);
  function personRowIndexes() {
    $('.woocommerce_bookable_persons .woocommerce_booking_person').each(function (index, el) {
      $('.person_menu_order', el).val(parseInt($(el).index('.woocommerce_bookable_persons .woocommerce_booking_person'), 10));
    });
  }
  $('#bookings_resources').on('change', 'input.resource_name', function () {
    $(this).closest('.woocommerce_booking_resource').find('span.resource_name').text($(this).val());
  });

  // Add a resource
  external_jQuery_default()('#bookings_resources').on('click', 'button.add_resource', function () {
    const loop = external_jQuery_default()('.woocommerce_booking_resource').length;
    const addResourceId = external_jQuery_default()('select.add_resource_id').val();
    let addResourceName = '';
    if (!addResourceId) {
      // eslint-disable-next-line no-alert
      addResourceName = window.prompt(wc_bookings_admin_js_params.i18n_new_resource_name);
      if (!addResourceName) {
        return false;
      }
    }
    external_jQuery_default()('.woocommerce_bookable_resources').block({
      message: null
    });
    const data = {
      action: 'woocommerce_add_bookable_resource',
      post_id: wc_bookings_admin_js_params.post,
      loop,
      add_resource_id: addResourceId,
      add_resource_name: addResourceName,
      security: wc_bookings_admin_js_params.nonce_add_resource
    };
    external_jQuery_default().post(wc_bookings_admin_js_params.ajax_url, data, function (response) {
      if (response.error) {
        window.alert(response.error); // eslint-disable-line no-alert
      } else {
        external_jQuery_default()('.woocommerce_bookable_resources').append(response.html).unblock();
        external_jQuery_default()('.woocommerce_bookable_resources').sortable(resourcesSortableOptions);
        if (addResourceId) {
          external_jQuery_default()('.add_resource_id').find('option[value=' + addResourceId + ']').remove();
        }
      }
    });
    return false;
  });

  // Remove a resource
  external_jQuery_default()('#bookings_resources').on('click', 'button.remove_booking_resource', function (e) {
    e.preventDefault();
    // eslint-disable-next-line no-alert
    const answer = window.confirm(wc_bookings_admin_js_params.i18n_remove_resource);
    if (answer) {
      const el = external_jQuery_default()(this).parent().parent();
      const resource = external_jQuery_default()(this).attr('rel');
      external_jQuery_default()(el).block({
        message: null,
        overlayCSS: {
          background: '#fff url(' + wc_bookings_admin_js_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
          opacity: 0.6
        }
      });
      const data = {
        action: 'woocommerce_remove_bookable_resource',
        post_id: wc_bookings_admin_js_params.post,
        resource_id: resource,
        security: wc_bookings_admin_js_params.nonce_delete_resource
      };
      external_jQuery_default().post(wc_bookings_admin_js_params.ajax_url, data, function () {
        external_jQuery_default()(el).fadeOut('300', function () {
          external_jQuery_default()(el).remove();
          const resourceId = external_jQuery_default()(el).find('input[name*=resource_id]').val();
          const resourceTitle = external_jQuery_default()(el).find('input[name*=resource_title]').val();
          external_jQuery_default()('select[name=add_resource_id]').append(external_jQuery_default()('<option>', {
            value: resourceId,
            text: resourceTitle
          }));
        });
      });
    }
    return false;
  });
  const resourcesSortableOptions = {
    items: '.woocommerce_booking_resource',
    cursor: 'move',
    axis: 'y',
    handle: 'h3',
    scrollSensitivity: 40,
    forcePlaceholderSize: true,
    helper: 'clone',
    opacity: 0.65,
    placeholder: 'wc-metabox-sortable-placeholder',
    start(event, ui) {
      ui.item.css('background-color', '#f6f6f6');
    },
    stop(event, ui) {
      ui.item.removeAttr('style');
      resourceRowIndexes();
    }
  };
  $('.woocommerce_bookable_resources').sortable(resourcesSortableOptions);
  function resourceRowIndexes() {
    $('.woocommerce_bookable_resources .woocommerce_booking_resource').each(function (index, el) {
      $('.resource_menu_order', el).val(parseInt($(el).index('.woocommerce_bookable_resources .woocommerce_booking_resource'), 10));
    });
  }

  // Set max attribute for the max persons field in person types.
  $('#bookings_persons').on('change', '#_wc_booking_max_persons_group', function () {
    const maxPersonsGroup = $(this).val();
    if (maxPersonsGroup && maxPersonsGroup > 0) {
      $('.woocommerce_bookable_persons').find('input.person_max, input.person_min').each(function () {
        $(this).attr('max', maxPersonsGroup);
      });
    } else {
      $('.woocommerce_bookable_persons').find('input.person_max, input.person_min').each(function () {
        $(this).removeAttr('max');
      });
    }
  });
  // Trigger change to set max attribute values of max for person types.
  $('#_wc_booking_max_persons_group').trigger('change');

  // Render the WordPress timepicker for the time input field inside "from_time" container.
  // This is needed for the initial load.
  // The timepicker is not rendered for the "google-event" rows.
  document.querySelectorAll(['#availability_rows tr:not(.google-event) .from_time', '#availability_rows tr:not(.google-event) .to_time', '#pricing_rows .from_time', '#pricing_rows .to_time',
  // This class must be applied to a direct parent of input[type="time"]
  // input[type="time"] must be the only child of the parent container
  '.wc-bookings-render-wp-time-picker'].join(', ')).forEach(el => {
    renderWPTimePicker(el);
  });

  // Render the WordPress timepicker for the time input field inside "from_time" container when a new row is added.
  $('body').on('row_added', function (e, jQueryRowSelector) {
    // Do not render the timepicker for the "google-event" rows.
    if (jQueryRowSelector.classList.contains('google-event')) {
      return;
    }
    if (jQueryRowSelector.closest('#availability_rows') || jQueryRowSelector.closest('#pricing_rows')) {
      jQueryRowSelector.querySelectorAll('.from_time, .to_time').forEach(el => {
        renderWPTimePicker(el);
      });
    }
  });

  /**
   * Should render the WordPress timepicker.
   *
   * @since 1.16.0
   * @param {HTMLElement} el The time input field container. div.from_time or div.to_time.
   *
   * @return {void}
   */
  function renderWPTimePicker(el) {
    const timeElement = el.querySelector('input[type="time"]');
    const timeIn24Hours = timeElement.value ? timeElement.value.split(':') // Saved time
    : ['00', '00']; // Default time.
    // Availability times are wall-clock values with no timezone. Passing a real Date
    // makes the picker shift them by the browser/site offset, so give it the full
    // date-time string it expects with a throwaway date; only the time is rendered.
    const currentTime = `2000-01-01T${timeIn24Hours[0]}:${timeIn24Hours[1]}:00`;

    // This function handles WP Timpicker change event to update the hidden input field with the time.
    let setTimeAsValueToInputField = (timeFieldContainer, time) => {
      const date = new Date(time);
      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');

      // Update the hidden input field.
      timeFieldContainer.querySelector('input:last-child').value = `${hours}:${minutes}`;
    };
    setTimeAsValueToInputField = setTimeAsValueToInputField.bind(null, el);

    // Replace time input with TimePicker.
    (0,external_wp_element_namespaceObject.render)(/*#__PURE__*/(0,jsx_runtime.jsx)(external_wp_components_namespaceObject.TimePicker, {
      currentTime: currentTime,
      is12Hour: wc_bookings_admin_js_params.time_in_12hours === '1',
      onChange: setTimeAsValueToInputField,
      __nextRemoveHelpButton: true,
      __nextRemoveResetButton: true
    }), el);

    // Add hidden input to store the time value.
    el.insertAdjacentHTML('beforeend', `<input type="hidden" name="${timeElement.name}" value="${timeElement.value}" />`);
  }

  // When the publish button is clicked, check if there are invalid fields in the person types section.
  $('#publish').on('click', function () {
    // Find all invalid fields in the person types section
    const $invalidFields = $('.woocommerce_bookable_persons input:invalid');
    if ($invalidFields.length) {
      // Open the person types tab.
      $('.bookings_persons_tab a').click();

      // For each invalid field, expand its parent section if closed.
      $invalidFields.each(function () {
        const $personSection = $(this).closest('.woocommerce_booking_person');
        if ($personSection.hasClass('closed')) {
          $personSection.find('h3').click();
        }
      });

      // Focus the first invalid field.
      const $firstInvalid = $invalidFields.first();
      $firstInvalid.focus();
    }
  });

  // Prevent entering more than allowed persons in person_max and person_min fields
  $('#bookings_persons').on('input change', 'input.person_max, input.person_min', function () {
    const max = parseInt($(this).attr('max'), 10);
    const val = parseInt($(this).val(), 10);

    // Remove any previous warning
    $(this).next('.max-persons-warning').remove();
    if (max && val > max) {
      $(this).val(max);

      // Inline warning message.
      $(this).after('<span class="max-persons-warning" style="color:red; margin-left:5px; margin-top:10px; display:inline-block;">' + wc_bookings_admin_js_params.i18n_max_persons_warning + ' ' + max + '</span>');
    }
  });
});
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(428);
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);

jquery__WEBPACK_IMPORTED_MODULE_0___default()(function ($) {
  'use strict';

  if (typeof window.wcTracks === 'undefined') {
    return;
  }
  const wcBookingsTracks = {
    record_event(eventName, properties) {
      const prefix = 'bookings_';
      const baseProperties = {
        bookings_version: wc_bookings_admin_js_params.bookings_version,
        bookings_db_version: wc_bookings_admin_js_params.bookings_db_version
      };
      properties = {
        ...properties,
        ...baseProperties
      };
      const fullEventName = prefix + eventName;
      window.wcTracks.recordEvent(fullEventName, properties);
    },
    init() {
      const doc = $(document);
      doc.on('click', '.booking-calendar-booking-title, .booking-calendar-time-range', function () {
        wcBookingsTracks.record_event('calendar_popover_clicked');
      });
      doc.on('click', '#wc-bookings-datepicker-toggle-day', function () {
        wcBookingsTracks.record_event('calendar_datepicker_clicked');
      });
      doc.on('click', '.wc-bookings-datepicker-popover .CalendarDay', function () {
        wcBookingsTracks.record_event('calendar_datepicker_date_changed');
      });
      doc.on('click', '.date-selector-popover .change-date.prev', function () {
        wcBookingsTracks.record_event('calendar_change_date_prev_clicked');
      });
      doc.on('click', '.date-selector-popover .change-date.next', function () {
        wcBookingsTracks.record_event('calendar_change_date_next_clicked');
      });
      doc.on('click', '.date-selector-popover .change-date.today', function () {
        wcBookingsTracks.record_event('calendar_change_date_today_clicked');
      });
      doc.on('click', '.wc-bookings-calendar-popover #event_detail_footer a', function () {
        wcBookingsTracks.record_event('calendar_popover_details_clicked');
      });
      doc.on('click', '#publish', function () {
        if (window.location.href.indexOf('post-new.php') > -1 && $('#product-type').val() === 'booking') {
          wcBookingsTracks.record_event('booking_product_published');
        }
      });

      // Templates.
      doc.on('wc_bookings_template_clicked', function (event, templateIndex, templateSlug) {
        wcBookingsTracks.record_event('template_click', {
          product_template: templateSlug,
          source: window.pagenow || 'unknown'
        });
      });
      doc.on('click', '.bookings-templates a.start-from-scratch-link', function () {
        wcBookingsTracks.record_event('template_click_blank');
      });
    }
  };
  wcBookingsTracks.init();
});
/* harmony import */ var admin_lazy_load_availability_rules_wordpress_i18n_WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(723);
/* harmony import */ var admin_lazy_load_availability_rules_wordpress_i18n_WEBPACK_IMPORTED_MODULE_0_default = /*#__PURE__*/__webpack_require__.n(admin_lazy_load_availability_rules_wordpress_i18n_WEBPACK_IMPORTED_MODULE_0_);
/**
 * This file has logic to handle lazy loading store availability rules.
 * Location of availability rules listing page: "Bookings -> Settings -> Store Availability".
 *
 * @since 1.15.69
 */

document.addEventListener('DOMContentLoaded', function () {
  const form = document.getElementById('bookings_settings');
  const lazyLoadAvailabilityRuleshiddenField = form ? form.querySelector('[name="can-lazy-load-availability-rules"]') : null;
  const canLazyLoadAvailabilityRules = lazyLoadAvailabilityRuleshiddenField ? parseInt(lazyLoadAvailabilityRuleshiddenField.value, 10) : 0;
  if (!canLazyLoadAvailabilityRules) {
    return;
  }

  // Data about store availability rule types.
  const availabilityRuleTypes = {
    current_list_type: new URLSearchParams(window.location.search).get('show'),
    GOOGLE_EVENT: 'google-events',
    AVAILABILITY_RULES: 'availability-rules'
  };
  const availabilityRule = {
    // Data related to remaining (lazy loaded) store availability rules.
    remaining_availability_rules: {
      button: null,
      can_fetch: true,
      next_request_data: {},
      availability_rules_html: ''
    },
    /**
     * Bootstrap process.
     *
     * @since 1.15.69
     */
    init_lazy_load: () => {
      // Add lazy load feature only on Google events rules list page.
      if (availabilityRuleTypes.GOOGLE_EVENT !== availabilityRuleTypes.current_list_type) {
        return;
      }
      const data = {
        per_page: parseInt(form.querySelector('[name="availability-rules-per-page"]').value, 10),
        step: 1,
        nonce: form.querySelector('[name="lazy_load_availability_rules_nonce"]').value,
        show: availabilityRuleTypes.current_list_type
      };
      availabilityRule.register_lazy_load_button();

      // Disable load more button till first batch of availability rules ready to render.
      availabilityRule.remaining_availability_rules.button.disabled = true;
      availabilityRule.fetch(data);
    },
    /**
     * Should insert availability rules html to table.
     *
     * @since 1.15.69
     * @param {string} html
     */
    insert_html: html => {
      const availabilityRows = document.getElementById('availability_rows');
      availabilityRows.insertAdjacentHTML('beforeend', html);
      jQuery('body').trigger('row_added', availabilityRows.querySelector('tr:last-child'));
    },
    /**
     * Should add lazy load button.
     *
     * @since 1.15.69
     */
    register_lazy_load_button: () => {
      const submitButtonContainer = form.querySelector('p.submit');
      const buttonTitle = (0,admin_lazy_load_availability_rules_wordpress_i18n_WEBPACK_IMPORTED_MODULE_0_.__)('Load more Google Calendar event rules', 'woocommerce-bookings');

      // Add load more button.
      submitButtonContainer.insertAdjacentHTML('beforeend', `<button class="button-secondary lazy-load-button" style="margin-left: 5px">${buttonTitle}</button>`);

      // Cache button element for future use.
      availabilityRule.remaining_availability_rules.button = submitButtonContainer.querySelector('.lazy-load-button');
      availabilityRule.remaining_availability_rules.button.addEventListener('click', event => {
        const {
          button,
          can_fetch: canFetch,
          next_request_data: nextRequestData,
          availability_rules_html: availabilityRulesHtml
        } = availabilityRule.remaining_availability_rules;
        button.disabled = true;
        button.textContent = (0,admin_lazy_load_availability_rules_wordpress_i18n_WEBPACK_IMPORTED_MODULE_0_.__)('Loading…', 'woocommerce-bookings');

        // Add availability HTML to dom.
        // Trigger event which attach/perform necessary actions on new table rows.
        window.setTimeout(() => {
          availabilityRule.insert_html(availabilityRulesHtml);
        }, 5);

        // Fetch next batch of availibility rules.
        if (canFetch) {
          window.setTimeout(() => availabilityRule.fetch(nextRequestData), 10);
        }
        event.preventDefault();
      });
    },
    /**
     * Should fetch availability rules html.
     *
     * @since 1.15.69
     * @param {Object} data
     */
    fetch: (data = null) => {
      const request = {
        method: 'POST'
      };
      const formData = new FormData();

      // Prepare quest data.
      data.action = 'wc_bookings_lazy_load_availability_rules';
      for (const property in data) {
        formData.append(property, data[property]);
      }
      request.body = formData;
      fetch(`${wc_bookings_admin_js_params.ajax_url}`, request).then(response => response.json()).then(response => {
        if (response.success) {
          // Remove "Load more availability rules" button if all availability rules loaded.
          const {
            button
          } = availabilityRule.remaining_availability_rules;
          if (!response.data.lazy_load_availability_rules) {
            availabilityRule.insert_html(response.data.html);
            button.remove();
            return;
          }

          // Increment step.
          ++data.step;
          availabilityRule.remaining_availability_rules.availability_rules_html = response.data.html;
          availabilityRule.remaining_availability_rules.can_fetch = response.data.lazy_load_availability_rules;
          availabilityRule.remaining_availability_rules.next_request_data = data;

          // Activate load more button to allow fetch next batch of availability rules.
          button.disabled = false;
          button.textContent = (0,admin_lazy_load_availability_rules_wordpress_i18n_WEBPACK_IMPORTED_MODULE_0_.__)('Load more Google Calendar event rules', 'woocommerce-bookings');
        }
      });
    }
  };
  availabilityRule.init_lazy_load();
});
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(723);
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(428);
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);


jquery__WEBPACK_IMPORTED_MODULE_1___default()(function ($) {
  // Create a bookable product.
  $('.wc-use-templates').on('click', function (e) {
    e.preventDefault();
    const button = $(this);

    // Return if already clicked.
    if (button.hasClass('active')) {
      return false;
    }
    const dashicon = button.find('.dashicons');
    const template = button.parents('.template-loop-item');
    const dataIndex = template.data('template-index');
    const dataSlug = template.data('template-slug');

    // Show the loader inside the button.
    button.addClass('active');
    dashicon.addClass('dashicons-update');
    dashicon.addClass('spin');
    dashicon.css('display', 'inline-block');
    $.ajax({
      type: 'POST',
      url: wc_bookings_admin_js_params.ajax_url,
      data: {
        action: 'wc_bookings_get_product_template',
        index: dataIndex,
        slug: dataSlug,
        security: wc_bookings_admin_js_params.nonce.wc_bookings_get_product_template
      },
      success(result) {
        result = JSON.parse(result);

        // Remove the loader.
        button.removeClass('active');
        dashicon.removeClass('dashicons-update');
        dashicon.css('display', 'none');

        // Check for failure.
        if (!result.success) {
          window.alert(result.data); // eslint-disable-line no-alert

          return false;
        }
        if ($('.template-item-popup-content .insertion-result').length === 0) {
          // Creating the <p> element.
          const paragraph = document.createElement('p');
          paragraph.className = 'insertion-result';
          paragraph.innerHTML = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.sprintf)(/* translators: 1: Open anchor tag html 2: Close anchor tag html */
          (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('A bookable product is created using this template. Please %1$sclick here%2$s if you are not redirected automatically.', 'woocommerce-bookings'), `<a href="${result.data}">`, '</a>');
          $('.template-item-popup-content').append(paragraph);
        }

        // Reload to the newly created bookable product's edit screen.
        window.location.href = result.data;
      },
      error(jqXHR, exception) {
        if (exception === 'abort') {
          return; // Assuming the date is changed very quickly.
        }

        // Error responses (e.g. 403) carry the message in the JSON payload.
        let data = jqXHR.responseJSON ? jqXHR.responseJSON.data : null;
        if (!data) {
          try {
            data = JSON.parse(jqXHR.responseText).data;
          } catch {
            data = null;
          }
        }
        let message = wc_bookings_admin_js_params.i18n_template_error;
        if (typeof data === 'string' && data) {
          message = data;
        } else if (data && typeof data.message === 'string' && data.message) {
          message = data.message;
        }

        // Show the error.
        window.alert(message); // eslint-disable-line no-alert

        // Remove the loader.
        button.removeClass('active');
        dashicon.removeClass('dashicons-update');
        dashicon.removeClass('spin');
        dashicon.css('display', 'none');
      },
      dataType: 'html'
    });
  });

  // Open the popup when the button is clicked.
  $('.template-loop-item').on('click', function (e) {
    e.stopPropagation();

    // Stop if the arrow or the popup-inner side is clicked.
    if ($(e.target).closest('.item-popup-arrow').length !== 0 || $(e.target).closest('.template-item-popup-inner').length !== 0) {
      return false;
    }
    const $body = $('body');

    // Add overlay only if it doesn't exist.
    if (!$('#active-template-popup-overlay').length) {
      $body.prepend('<div id="active-template-popup-overlay"></div>');
    }
    $body.addClass('noscroll');
    $('.template-item-popup').fadeOut();
    $(this).find('.template-item-popup').addClass('active').fadeIn();
    $body.trigger('wc_bookings_template_clicked', [$(this).data('template-index'), $(this).data('template-slug'), $(this)]);
  });

  // Close the popup when clicked outside or a close button.
  $('.close-template-popup').on('click', function (e) {
    e.stopPropagation();
    $('.template-item-popup').fadeOut();
    $(this).parents('.template-item-popup').removeClass('active');
    $('#active-template-popup-overlay').remove();
    $('body').removeClass('noscroll');
  });
  $(document).on('click', function (e) {
    if ($(e.target).closest('.template-item-popup-inner').length === 0) {
      $('.close-template-popup').trigger('click');
    }
  });

  // Close popup on Esc key press.
  $(document).on('keyup', function (e) {
    const activePopupEl = $('.active.template-item-popup');

    // Return if popup is not open.
    if (!activePopupEl.length) {
      return;
    }
    switch (e.key) {
      case 'ArrowLeft':
        activePopupEl.find('.item-popup-arrow.left').trigger('click');
        break;
      case 'ArrowRight':
        activePopupEl.find('.item-popup-arrow.right').trigger('click');
        break;
      case 'Escape':
        activePopupEl.find('.close-template-popup').trigger('click');
        break;
    }
  });

  // On arrow click, show next/prev popup.
  $('.item-popup-arrow').on('click', function () {
    const direction = $(this).hasClass('left') ? 'left' : 'right';
    const currentPopupCard = $(this).closest('.template-loop-item');

    // Remove active class from all popup cards.
    currentPopupCard.find('.template-item-popup').removeClass('active');
    if (direction === 'left') {
      let prevPopupCard = currentPopupCard.prev();
      prevPopupCard = prevPopupCard.length ? prevPopupCard : currentPopupCard.siblings().last();
      prevPopupCard.trigger('click');
    } else {
      let nextPopupCard = currentPopupCard.next();
      nextPopupCard = nextPopupCard.length ? nextPopupCard : currentPopupCard.siblings().first();
      nextPopupCard.trigger('click');
    }
  });
});
// extracted by mini-css-extract-plugin

// extracted by mini-css-extract-plugin

/******/ })()
;
//# sourceMappingURL=admin.js.map