(()=>{"use strict";const e=window.wp.hooks;function t(){const e=document.querySelectorAll(".srfm-datepicker-block");if(!e.length)return;const t={weekday:"long",year:"numeric",month:"long",day:"numeric"},r=navigator.language||"en-US";let n;"undefined"!=typeof Intl&&Intl.DateTimeFormat&&(n=new Intl.DateTimeFormat(r,t)),e.forEach((a=>{const i=a.querySelector(".srfm-input-datepicker");if(!i)return;const o=i.getAttribute("max"),s=i.getAttribute("min"),d=i.getAttribute("data-date-format"),l=function(e){let t=[];const r=e.getAttribute("data-days-enabled");if(r)try{const e=JSON.parse(r);Array.isArray(e)&&e.length&&(t=[0,1,2,3,4,5,6].filter((t=>!e.includes(t))))}catch(e){console.error("Invalid JSON format for data-days-enabled:",e)}return t}(i),u="true"===i.getAttribute("data-disable-past"),m=window?.innerWidth<768;let c=s;if(u){const e=new Date;e.setHours(0,0,0,0),c=s&&new Date(s).getTime()>e.getTime()?s:e}const y='<svg aria-hidden="true" viewBox="0 0 6 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5 9L1 5L5 1" stroke-width="0.833333" stroke-linecap="round" stroke-linejoin="round"/></svg>',f='<svg aria-hidden="true" viewBox="0 0 6 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 9L5 5L1 1" stroke-width="0.833333" stroke-linecap="round" stroke-linejoin="round"/></svg>',p=new Datepicker(i,{format:d,autohide:!0,prevArrow:srfm_submit.is_rtl?f:y,nextArrow:srfm_submit.is_rtl?y:f,...c&&{minDate:c},...o&&{maxDate:o},daysOfWeekDisabled:l,shortcutKeys:{show:{key:" "},hide:{key:"Escape"},toggle:{key:null}}}),w={clearIncomplete:!0,showMaskOnHover:!1,showMaskOnFocus:!1};switch(d){case"dd/mm/yyyy":w.alias="datetime",w.inputFormat="dd/mm/yyyy";break;case"mm/dd/yyyy":w.alias="datetime",w.inputFormat="mm/dd/yyyy"}new Inputmask(w).mask(p.element);const g=document.createElement("input");g.required="true",g.style.display="none",p.element.addEventListener("show",(()=>{m&&i.setAttribute("readonly","true"),i.parentElement.append(g),p.picker.element.getAttribute("aria-hidden")||p.picker.element.setAttribute("aria-hidden","true")})),p.element.addEventListener("keydown",(e=>{if("ArrowLeft"===e.key||"ArrowRight"===e.key||"ArrowUp"===e.key||"ArrowDown"===e.key){const e=p.getFocusedDate();if(e){let a="";a=n?n.format(e):e.toLocaleDateString(r,t),wp.a11y.speak(a,"polite")}}})),p.element.addEventListener("hide",(()=>{m&&i.removeAttribute("readonly");const e=new Event("input",{bubbles:!1,cancelable:!0});i.dispatchEvent(e),setTimeout((()=>{g.remove()}),1)})),i.oninput=function(t){const r=t.target.value.replaceAll("/","-");i.setAttribute("value",r),e.forEach((e=>{window?.srfm?.toggleErrorState(e,!1)}))},p.element.addEventListener("focusout",(()=>{p?.hide()}))}))}window.srfmInitializeDatePicker=t,document.addEventListener("srfm_form_before_submission",(e=>{const r=e.detail?.form.querySelectorAll(".srfm-input-datepicker");r&&setTimeout((()=>{t()}),100)})),(0,e.addFilter)("srfm.modifyFieldValidationResult","sureforms-pro/datepicker-past-date-validation",((e,t,r)=>{if(!t.classList.contains("srfm-datepicker-block"))return e;const n=t.querySelector(".srfm-input-datepicker");if("true"!==n?.getAttribute("data-disable-past"))return e;const a=n?.value?.trim();if(!a)return e;const i={"mm/dd/yyyy":{year:2,month:0,day:1},"dd/mm/yyyy":{year:2,month:1,day:0}}[n.getAttribute("data-date-format")];if(!i)return e;const o=function(e,t,r,n){if(3!==e.length)return null;const a=parseInt(e[t],10),i=parseInt(e[r],10),o=parseInt(e[n],10),s=new Date(a,i-1,o);return s.getFullYear()!==a||s.getMonth()!==i-1||s.getDate()!==o?null:s}(a.split(/[\/\-]/),i.year,i.month,i.day);if(o&&!isNaN(o.getTime())){o.setHours(0,0,0,0);const e=new Date;if(e.setHours(0,0,0,0),o<e){n&&window?.srfm?.toggleErrorState(n.closest(".srfm-block"),!0);const e=t.querySelector(".srfm-error-message");return e&&(e.textContent=window?.srfm_submit?.messages?.date_picker_past_dates_not_allowed),r(n,t),!0}}return e}))})();