(()=>{"use strict";const t="YYYY-MM-DD";function e(){return window?.JetABAFInput?.field_format??t}function n(){return window?.JetABAFInput?.layout??"single"}function i(t){return window?.JetABAFData?.[t]}const{InputData:r}=JetFormBuilderAbstract,{isEmpty:o}=JetFormBuilderFunctions;function a(){r.call(this),this.sanitize(function(n){return o(n)||!Array.isArray(n)&&"string"!=typeof n?[]:Array.isArray(n)?n:(n=n.split(" - ")).length?n.map(n=>moment(n,e()).format(t)):[]}),this.isSupported=function(t){return"checkin-checkout"===t.dataset.field},this.addListeners=function(){this.reporting.makeInvalid=()=>{},this.reporting.makeValid=()=>{};const[t]=this.nodes;jQuery(t).on("change.JetFormBuilderMain",()=>{this.value.current=this.value.isMaked?t.value:this.value.applySanitizers(t.value)});const e=t.parentElement.querySelectorAll(".jet-abaf-field__input");for(const t of e)t.addEventListener("blur",()=>this.reportOnBlur())},this.setValue=function(){this.value.current=this.value.applySanitizers(this.nodes[0].value)},this.checkIsRequired=function(){const[t]=this.nodes;return!!t.required||!!t.parentElement.querySelector(".jet-abaf-field__input[required]")},this.setNode=function(t){if(r.prototype.setNode.call(this,t),this.inputType="checkin-checkout","single"===n())return;const e=t.closest(".jet-abaf-separate-fields");this.nodes.push(...e.querySelectorAll('.jet-abaf-field__input[type="text"]'),e)}}a.prototype=Object.create(r.prototype),a.prototype.parseValueForCalculated=function(){if(!this.getValue()?.length)return 0;if(window?.JetBooking?.calcBookedDates){const n=this.getValue().map(n=>moment(n,t).format(e()));return JetBooking.calcBookedDates(n.join(" - "))}if(i("one_day_bookings"))return 1;const n=this.value.current.map(t=>moment(t));let r=n[1].diff(n[0],"days");return r=Number(r),i("per_nights")||r++,r};const u=a,{BaseSignal:s}=JetFormBuilderAbstract;function c(){s.call(this),this.isSupported=function(t,e){return e instanceof u},this.runSignal=function(t){"single"===n()?this.runSignalForSingle():this.runSignalForSeparate(t)},this.runSignalForSingle=function(){const[n]=this.input.nodes,{current:i}=this.input.value;i.length?n.value=i.map(n=>moment(n,t).format(e())).join(" - "):n.value=""},this.runSignalForSeparate=function(n){const[,i,r]=this.input.nodes,{current:o}=this.input.value;if(o?.toString?.()!==n?.toString?.()){if(!o.length)return i.value="",r.value="",void this.updateCalendar();i.value=moment(o[0],t).format(e()),r.value=moment(o[1]??o[0],t).format(e()),this.updateCalendar()}},this.updateCalendar=function(){const{current:t}=this.input.value,[,,,n]=this.input.nodes;if(!t.length)return void jQuery(n).data("dateRangePicker").clear();const i=e();jQuery(n).data("dateRangePicker").setDateRange(moment(t[0]).format(i),moment(t[1]??t[0]).format(i),!0)}}c.prototype=Object.create(s.prototype);const l=c,{addAction:d,addFilter:f}=JetPlugins.hooks;d("jet.fb.observe.before","jet-form-builder/booking-compatibility",function(t){const{rootNode:e}=t;for(const t of e.querySelectorAll(".field-type-check-in-out")){const e=t.querySelector('input[data-field="checkin-checkout"]');e&&(e.dataset.jfbSync=1)}}),f("jet.fb.inputs","jet-form-builder/booking-compatibility",function(t){return[u,...t]}),f("jet.fb.signals","jet-form-builder/booking-compatibility",function(t){return[l,...t]}),f("jet.fb.formula.node.exists","jet-form-builder/booking-compatibility",function(t,e,n){const i=e.match(/ADVANCED_PRICE::([\w\-]+)/);return i&&i?.length&&(t=n.root.rootNode[i[1]]),t}),f("jet.fb.onCalculate.part","jet-form-builder/booking-compatibility",function(t,e){if("string"!=typeof t)return t;if(!e?.input)return t;const n=t.match(/(ADVANCED_PRICE|BOOKING_TIME)::([\w\-]+)/);if(!n?.length)return t;const[,i,r]=n;if("ADVANCED_PRICE"===i){const t=e.input.root.getInput(r);if(!t)return 0;e.cachedFields=e.cachedFields||[],e.cachedFields.includes(t.name)||(e.cachedFields.push(t.name),t.watch(()=>e.setResult()))}else{const t=document.getElementById(r);if(!t)return 0;t.addEventListener("change",()=>{e.setResult()})}return t}),f("jet.fb.calculated.callback","jet-form-builder/booking-field-parser",function(t,e,n){return!1!==t||"checkin-checkout"!==e.inputType?t:e.parseValueForCalculated()})})();