(()=>{"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:o}=JetFormBuilderAbstract,{isEmpty:r}=JetFormBuilderFunctions;function a(){o.call(this),this.sanitize((function(n){return r(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(o.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(o.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 o=n[1].diff(n[0],"days");return o=Number(o),i("per_nights")||o++,o};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,o]=this.input.nodes,{current:r}=this.input.value;if(r?.toString?.()!==n?.toString?.()){if(!r.length)return i.value="",o.value="",void this.updateCalendar();i.value=moment(r[0],t).format(e()),o.value=moment(r[1]??r[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;const n=t.match(/ADVANCED_PRICE::([\w\-]+)/);if(!n?.length||!e?.input)return t;const[,i]=n,o=e.input.root.getInput(i);return o?(e.cachedFields=e.cachedFields||[],e.cachedFields.includes(o.name)||(e.cachedFields.push(o.name),o.watch((()=>e.setResult()))),t):0})),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()}))})();