import{getContext as e,getElement as t,store as i}from"@wordpress/interactivity";var r={d:(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},s={};r.r(s);var o={};r.r(o),r.d(o,{getCommentContent:()=>O,getCommentDate:()=>B});var l={};r.r(l),r.d(l,{getLike:()=>G,likeBackgroundColor:()=>N,unLikeBackgroundColor:()=>z});var n={};r.r(n),r.d(n,{getDeleteModalDisplay:()=>Y});var a={};r.r(a),r.d(a,{fileDragEnter:()=>H,fileDragLeave:()=>U,fileDrop:()=>Z,onChangeFile:()=>W,removeFile:()=>ee});const{addQueryArgs:d}=wp.url;class c{getReviews(e){return u({path:d("directorist-advanced-review/reviews",{post_id:e.post_id,rating:e.filters.rating,sort:e.filters.sort,page:e.page,criteria_ids:f(e)})})}create(e){return u({path:"directorist-advanced-review/reviews",method:"POST",data:e})}createReply(e){return u({path:"directorist-advanced-review/replies",method:"POST",data:e})}updateReply(e){return u({path:"directorist-advanced-review/replies",method:"PATCH",data:e})}getReplies(e,t){return u({path:d("directorist-advanced-review/replies",{comment_id:e,post_id:t})})}reaction(e,t){return u({path:"directorist-advanced-review/reviews/reaction",method:"POST",data:{comment_ID:parseInt(e),reaction:t}})}submitReport(e,t){return u({path:"directorist-advanced-review/report",method:"POST",data:{comment_ID:parseInt(e),content:t}})}delete(e){return u({path:d(`directorist-advanced-review/reviews/${e}`),method:"DELETE"})}}function u(e){return wp.apiFetch(e)}function h(){"function"==typeof window.refreshFsLightbox&&window.refreshFsLightbox()}async function m(e){const t=new c;e.is_review_loading=!0;const i=await t.getReviews(e);e.reviews=i.reviews,e.total=i.total,e.average=i.average,e.is_user_reviewed=i.is_user_reviewed,e.has_review=i.has_review,e.is_review_loading=!1;const r=f(e),s=i.criterias.map(e=>({...e,checked:r.includes(e.id)}));e.criterias=s,requestAnimationFrame(()=>{h()})}function f(e){return e.criterias.filter(e=>e.hasOwnProperty("checked")&&!0===e.checked).map(e=>e.id)}function g(e){let t=[],i=Math.floor(e),r=e%1>=.1&&e%1<=.9;for(let e=0;e<i;e++)t.push({is_full:!0,is_half:!1,is_empty:!1});for(r&&t.push({is_full:!1,is_half:!0,is_empty:!1});t.length<5;)t.push({is_full:!1,is_half:!1,is_empty:!0});return t}function p(e,t){if(e.length<=t)return e;let i=e.substring(0,t);return i.substring(0,i.lastIndexOf(" "))+"..."}function v(e){try{const t=atob(e),i=Uint8Array.from(t,e=>e.charCodeAt(0));return new TextDecoder("utf-8").decode(i)}catch(t){return atob(e)}}function b(e){e.preventDefault(),e.stopPropagation()}function y(e){e.commentForm.type="",e.commentForm.comment_ID=0}function w(e,t,i){e.onSuccess(async e=>{e.preventDefault();const r=new FormData(e.target);let s=Object.fromEntries(r.entries());s.post_id=t.post_id,s.comment_ID=parseInt(t[t.loopKey].comment_ID);const o=new c;try{await o.createReply(s);const e=await o.getReplies(t[t.loopKey].comment_ID,t.post_id);t[t.loopKey].comments=e.items,t[t.loopKey].total_children=e.total_children,t[t.loopKey].show_replies=!0,y(t),i.ref.reset()}catch(e){console.log("Errors",e)}})}function F(e){return 0!==e.user_ID}function _(e,t,i){document.querySelectorAll(e).forEach(e=>{e.querySelectorAll(t).forEach(t=>{const r=parseInt(t.getAttribute("maxlength"),10),s=e.querySelector(i);if(!r||!s)return;const o=()=>{const e=t.value.length;s.textContent=`${e}/${r} max characters`,s.style.color=e>=r?"red":"inherit"};o(),t.addEventListener("input",o);const l=t.closest("form");l&&l.addEventListener("reset",()=>{setTimeout(o,0)})})})}function C(){const e=document.getElementById("directorist-reviews");e&&e.scrollIntoView({block:"start"})}var k=Object.defineProperty,E=(e,t,i)=>(((e,t,i)=>{t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);const S=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,L=/^-?[0-9]\d*$/,I=/^(?=.*[A-Za-z])(?=.*\d).{8,}$/,D=/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,x=e=>"string"!=typeof e||""===e;var M=(e=>(e.Required="required",e.Email="email",e.MinLength="minLength",e.MaxLength="maxLength",e.Password="password",e.Number="number",e.Integer="integer",e.MaxNumber="maxNumber",e.MinNumber="minNumber",e.StrongPassword="strongPassword",e.CustomRegexp="customRegexp",e.MinFilesCount="minFilesCount",e.MaxFilesCount="maxFilesCount",e.Files="files",e))(M||{}),R=(e=>(e.Required="required",e))(R||{}),T=(e=>(e.Label="label",e.LabelArrow="labelArrow",e))(T||{});const V=[{key:M.Required,dict:{en:"The field is required"}},{key:M.Email,dict:{en:"Email has invalid format"}},{key:M.MaxLength,dict:{en:"The field must contain a maximum of :value characters"}},{key:M.MinLength,dict:{en:"The field must contain a minimum of :value characters"}},{key:M.Password,dict:{en:"Password must contain minimum eight characters, at least one letter and one number"}},{key:M.StrongPassword,dict:{en:"Password should contain minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character"}},{key:M.Number,dict:{en:"Value should be a number"}},{key:M.MaxNumber,dict:{en:"Number should be less or equal than :value"}},{key:M.MinNumber,dict:{en:"Number should be more or equal than :value"}},{key:M.MinFilesCount,dict:{en:"Files count should be more or equal than :value"}},{key:M.MaxFilesCount,dict:{en:"Files count should be less or equal than :value"}},{key:M.Files,dict:{en:"Uploaded files have one or several invalid properties (extension/size/type etc)."}}],j=e=>"object"==typeof e&&null!==e&&"then"in e&&"function"==typeof e.then,P=e=>Array.isArray(e)?e.filter(e=>e.length>0):"string"==typeof e&&e.trim()?[...e.split(" ").filter(e=>e.length>0)]:[],A=e=>e instanceof Element||e instanceof HTMLDocument,$={errorFieldStyle:{color:"#b81111",border:"1px solid #B81111"},errorFieldCssClass:"just-validate-error-field",successFieldCssClass:"just-validate-success-field",errorLabelStyle:{color:"#b81111"},errorLabelCssClass:"just-validate-error-label",successLabelCssClass:"just-validate-success-label",focusInvalidField:!0,lockForm:!0,testingMode:!1,validateBeforeSubmitting:!1,submitFormAutomatically:!1};class K{constructor(e,t,i){E(this,"form",null),E(this,"fields",{}),E(this,"groupFields",{}),E(this,"errors",{}),E(this,"isValid",!1),E(this,"isSubmitted",!1),E(this,"globalConfig",$),E(this,"errorLabels",{}),E(this,"successLabels",{}),E(this,"eventListeners",[]),E(this,"dictLocale",V),E(this,"currentLocale","en"),E(this,"customStyleTags",{}),E(this,"onSuccessCallback"),E(this,"onFailCallback"),E(this,"onValidateCallback"),E(this,"tooltips",[]),E(this,"lastScrollPosition"),E(this,"isScrollTick"),E(this,"fieldIds",new Map),E(this,"getKeyByFieldSelector",e=>this.fieldIds.get(e)),E(this,"getFieldSelectorByKey",e=>{for(const[t,i]of this.fieldIds)if(e===i)return t}),E(this,"getCompatibleFields",()=>{const e={};return Object.keys(this.fields).forEach(t=>{let i=t;const r=this.getFieldSelectorByKey(t);"string"==typeof r&&(i=r),e[i]={...this.fields[t]}}),e}),E(this,"setKeyByFieldSelector",e=>{if(this.fieldIds.has(e))return this.fieldIds.get(e);const t=String(this.fieldIds.size+1);return this.fieldIds.set(e,t),t}),E(this,"refreshAllTooltips",()=>{this.tooltips.forEach(e=>{e.refresh()})}),E(this,"handleDocumentScroll",()=>{this.lastScrollPosition=window.scrollY,this.isScrollTick||(window.requestAnimationFrame(()=>{this.refreshAllTooltips(),this.isScrollTick=!1}),this.isScrollTick=!0)}),E(this,"formSubmitHandler",e=>{e.preventDefault(),this.isSubmitted=!0,this.validateHandler(e)}),E(this,"handleFieldChange",e=>{let t;for(const i in this.fields)if(this.fields[i].elem===e){t=i;break}t&&(this.fields[t].touched=!0,this.validateField(t,!0))}),E(this,"handleGroupChange",e=>{let t;for(const i in this.groupFields)if(this.groupFields[i].elems.find(t=>t===e)){t=i;break}t&&(this.groupFields[t].touched=!0,this.validateGroup(t,!0))}),E(this,"handlerChange",e=>{e.target&&(this.handleFieldChange(e.target),this.handleGroupChange(e.target),this.renderErrors())}),this.initialize(e,t,i)}initialize(e,t,i){if(this.form=null,this.errors={},this.isValid=!1,this.isSubmitted=!1,this.globalConfig=$,this.errorLabels={},this.successLabels={},this.eventListeners=[],this.customStyleTags={},this.tooltips=[],this.currentLocale="en","string"==typeof e){const t=document.querySelector(e);if(!t)throw Error(`Form with ${e} selector not found! Please check the form selector`);this.setForm(t)}else{if(!(e instanceof HTMLFormElement))throw Error("Form selector is not valid. Please specify a string selector or a DOM element.");this.setForm(e)}if(this.globalConfig={...$,...t},i&&(this.dictLocale=[...i,...V]),this.isTooltip()){const e=document.createElement("style");e.textContent=".just-validate-error-label[data-tooltip=true]{position:fixed;padding:4px 8px;background:#423f3f;color:#fff;white-space:nowrap;z-index:10;border-radius:4px;transform:translateY(-5px)}.just-validate-error-label[data-tooltip=true]:before{content:'';width:0;height:0;border-left:solid 5px transparent;border-right:solid 5px transparent;border-bottom:solid 5px #423f3f;position:absolute;z-index:3;display:block;bottom:-5px;transform:rotate(180deg);left:calc(50% - 5px)}.just-validate-error-label[data-tooltip=true][data-direction=left]{transform:translateX(-5px)}.just-validate-error-label[data-tooltip=true][data-direction=left]:before{right:-7px;bottom:auto;left:auto;top:calc(50% - 2px);transform:rotate(90deg)}.just-validate-error-label[data-tooltip=true][data-direction=right]{transform:translateX(5px)}.just-validate-error-label[data-tooltip=true][data-direction=right]:before{right:auto;bottom:auto;left:-7px;top:calc(50% - 2px);transform:rotate(-90deg)}.just-validate-error-label[data-tooltip=true][data-direction=bottom]{transform:translateY(5px)}.just-validate-error-label[data-tooltip=true][data-direction=bottom]:before{right:auto;bottom:auto;left:calc(50% - 5px);top:-5px;transform:rotate(0)}",this.customStyleTags[T.Label]=document.head.appendChild(e),this.addListener("scroll",document,this.handleDocumentScroll)}}getLocalisedString(e,t,i){var r;const s=null!=i?i:e;let o=null==(r=this.dictLocale.find(e=>e.key===s))?void 0:r.dict[this.currentLocale];if(o||i&&(o=i),o&&void 0!==t)switch(e){case M.MaxLength:case M.MinLength:case M.MaxNumber:case M.MinNumber:case M.MinFilesCount:case M.MaxFilesCount:o=o.replace(":value",String(t))}return o||i||"Value is incorrect"}getFieldErrorMessage(e,t){const i="function"==typeof e.errorMessage?e.errorMessage(this.getElemValue(t),this.fields):e.errorMessage;return this.getLocalisedString(e.rule,e.value,i)}getFieldSuccessMessage(e,t){const i="function"==typeof e?e(this.getElemValue(t),this.fields):e;return this.getLocalisedString(void 0,void 0,i)}getGroupErrorMessage(e){return this.getLocalisedString(e.rule,void 0,e.errorMessage)}getGroupSuccessMessage(e){if(e.successMessage)return this.getLocalisedString(void 0,void 0,e.successMessage)}setFieldInvalid(e,t){this.fields[e].isValid=!1,this.fields[e].errorMessage=this.getFieldErrorMessage(t,this.fields[e].elem)}setFieldValid(e,t){this.fields[e].isValid=!0,void 0!==t&&(this.fields[e].successMessage=this.getFieldSuccessMessage(t,this.fields[e].elem))}setGroupInvalid(e,t){this.groupFields[e].isValid=!1,this.groupFields[e].errorMessage=this.getGroupErrorMessage(t)}setGroupValid(e,t){this.groupFields[e].isValid=!0,this.groupFields[e].successMessage=this.getGroupSuccessMessage(t)}getElemValue(e){switch(e.type){case"checkbox":return e.checked;case"file":return e.files;default:return e.value}}validateGroupRule(e,t,i){i.rule===R.Required&&(t.every(e=>!e.checked)?this.setGroupInvalid(e,i):this.setGroupValid(e,i))}validateFieldRule(e,t,i,r=!1){const s=i.value,o=this.getElemValue(t);var l;if(i.plugin)i.plugin(o,this.getCompatibleFields())||this.setFieldInvalid(e,i);else switch(i.rule){case M.Required:(e=>{let t=e;return"string"==typeof e&&(t=e.trim()),!t})(o)&&this.setFieldInvalid(e,i);break;case M.Email:if(x(o))break;l=o,S.test(l)||this.setFieldInvalid(e,i);break;case M.MaxLength:if(void 0===s){console.error(`Value for ${i.rule} rule for [${e}] field is not defined. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if("number"!=typeof s){console.error(`Value for ${i.rule} rule for [${e}] should be a number. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if(x(o))break;((e,t)=>e.length>t)(o,s)&&this.setFieldInvalid(e,i);break;case M.MinLength:if(void 0===s){console.error(`Value for ${i.rule} rule for [${e}] field is not defined. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if("number"!=typeof s){console.error(`Value for ${i.rule} rule for [${e}] should be a number. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if(x(o))break;((e,t)=>e.length<t)(o,s)&&this.setFieldInvalid(e,i);break;case M.Password:if(x(o))break;(e=>I.test(e))(o)||this.setFieldInvalid(e,i);break;case M.StrongPassword:if(x(o))break;(e=>D.test(e))(o)||this.setFieldInvalid(e,i);break;case M.Number:if(x(o))break;(e=>"string"==typeof e&&!isNaN(+e)&&!isNaN(parseFloat(e)))(o)||this.setFieldInvalid(e,i);break;case M.Integer:if(x(o))break;(e=>L.test(e))(o)||this.setFieldInvalid(e,i);break;case M.MaxNumber:{if(void 0===s){console.error(`Value for ${i.rule} rule for [${e}] field is not defined. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if("number"!=typeof s){console.error(`Value for ${i.rule} rule for [${e}] field should be a number. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if(x(o))break;const t=+o;(Number.isNaN(t)||((e,t)=>e>t)(t,s))&&this.setFieldInvalid(e,i);break}case M.MinNumber:{if(void 0===s){console.error(`Value for ${i.rule} rule for [${e}] field is not defined. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if("number"!=typeof s){console.error(`Value for ${i.rule} rule for [${e}] field should be a number. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if(x(o))break;const t=+o;(Number.isNaN(t)||((e,t)=>e<t)(t,s))&&this.setFieldInvalid(e,i);break}case M.CustomRegexp:{if(void 0===s)return console.error(`Value for ${i.rule} rule for [${e}] field is not defined. This field will be always invalid.`),void this.setFieldInvalid(e,i);let t;try{t=new RegExp(s)}catch(t){console.error(`Value for ${i.rule} rule for [${e}] should be a valid regexp. This field will be always invalid.`),this.setFieldInvalid(e,i);break}const r=String(o);""===r||t.test(r)||this.setFieldInvalid(e,i);break}case M.MinFilesCount:if(void 0===s){console.error(`Value for ${i.rule} rule for [${e}] field is not defined. This field will be always invalid.`),this.setFieldInvalid(e,i);break}if("number"!=typeof s){console.error(`Value for ${i.rule} rule for [${e}] field should be a number. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if(Number.isFinite(null==o?void 0:o.length)&&o.length<s){this.setFieldInvalid(e,i);break}break;case M.MaxFilesCount:if(void 0===s){console.error(`Value for ${i.rule} rule for [${e}] field is not defined. This field will be always invalid.`),this.setFieldInvalid(e,i);break}if("number"!=typeof s){console.error(`Value for ${i.rule} rule for [${e}] field should be a number. The field will be always invalid.`),this.setFieldInvalid(e,i);break}if(Number.isFinite(null==o?void 0:o.length)&&o.length>s){this.setFieldInvalid(e,i);break}break;case M.Files:{if(void 0===s)return console.error(`Value for ${i.rule} rule for [${e}] field is not defined. This field will be always invalid.`),void this.setFieldInvalid(e,i);if("object"!=typeof s)return console.error(`Value for ${i.rule} rule for [${e}] field should be an object. This field will be always invalid.`),void this.setFieldInvalid(e,i);const t=s.files;if("object"!=typeof t)return console.error(`Value for ${i.rule} rule for [${e}] field should be an object with files array. This field will be always invalid.`),void this.setFieldInvalid(e,i);const r=(e,t)=>{const i=Number.isFinite(t.minSize)&&e.size<t.minSize,r=Number.isFinite(t.maxSize)&&e.size>t.maxSize,s=Array.isArray(t.names)&&!t.names.includes(e.name),o=Array.isArray(t.extensions)&&!t.extensions.includes(e.name.split(".")[e.name.split(".").length-1]),l=Array.isArray(t.types)&&!t.types.includes(e.type);return i||r||s||o||l};if("object"==typeof o&&null!==o)for(let s=0,l=o.length;s<l;++s){const l=o.item(s);if(!l){this.setFieldInvalid(e,i);break}if(r(l,t)){this.setFieldInvalid(e,i);break}}break}default:{if("function"!=typeof i.validator)return console.error(`Validator for custom rule for [${e}] field should be a function. This field will be always invalid.`),void this.setFieldInvalid(e,i);const t=i.validator(o,this.getCompatibleFields());if("boolean"!=typeof t&&"function"!=typeof t&&console.error(`Validator return value for [${e}] field should be boolean or function. It will be cast to boolean.`),"function"==typeof t){if(!r){this.fields[e].asyncCheckPending=!1;const r=t();return j(r)?r.then(t=>{t||this.setFieldInvalid(e,i)}).catch(()=>{this.setFieldInvalid(e,i)}):(console.error(`Validator function for custom rule for [${e}] field should return a Promise. This field will be always invalid.`),void this.setFieldInvalid(e,i))}this.fields[e].asyncCheckPending=!0}t||this.setFieldInvalid(e,i)}}}isFormValid(){let e=!0;for(let t=0,i=Object.values(this.fields).length;t<i;++t){const i=Object.values(this.fields)[t];if(void 0===i.isValid){e=void 0;break}if(!1===i.isValid){e=!1;break}}for(let t=0,i=Object.values(this.groupFields).length;t<i;++t){const i=Object.values(this.groupFields)[t];if(void 0===i.isValid){e=void 0;break}if(!1===i.isValid){e=!1;break}}return e}validateField(e,t=!1){var i;const r=this.fields[e];r.isValid=!0;const s=[];return[...r.rules].reverse().forEach(i=>{const o=this.validateFieldRule(e,r.elem,i,t);j(o)&&s.push(o)}),r.isValid&&this.setFieldValid(e,null==(i=r.config)?void 0:i.successMessage),Promise.allSettled(s).finally(()=>{var e;t&&(null==(e=this.onValidateCallback)||e.call(this,{isValid:this.isFormValid(),isSubmitted:this.isSubmitted,fields:this.getCompatibleFields(),groups:{...this.groupFields}}))})}revalidateField(e){if("string"!=typeof e&&!A(e))throw Error("Field selector is not valid. Please specify a string selector or a valid DOM element.");const t=this.getKeyByFieldSelector(e);return t&&this.fields[t]?new Promise(e=>{this.validateField(t,!0).finally(()=>{this.clearFieldStyle(t),this.clearFieldLabel(t),this.renderFieldError(t,!0),e(!!this.fields[t].isValid)})}):(console.error("Field not found. Check the field selector."),Promise.reject())}revalidateGroup(e){if("string"!=typeof e&&!A(e))throw Error("Group selector is not valid. Please specify a string selector or a valid DOM element.");const t=this.getKeyByFieldSelector(e);return t&&this.groupFields[t]?new Promise(e=>{this.validateGroup(t).finally(()=>{this.clearFieldLabel(t),this.renderGroupError(t,!0),e(!!this.groupFields[t].isValid)})}):(console.error("Group not found. Check the group selector."),Promise.reject())}validateGroup(e,t=!1){const i=this.groupFields[e],r=[];return[...i.rules].reverse().forEach(t=>{const s=this.validateGroupRule(e,i.elems,t);j(s)&&r.push(s)}),Promise.allSettled(r).finally(()=>{var e;t&&(null==(e=this.onValidateCallback)||e.call(this,{isValid:this.isFormValid(),isSubmitted:this.isSubmitted,fields:this.getCompatibleFields(),groups:{...this.groupFields}}))})}focusInvalidField(){for(const e in this.fields){const t=this.fields[e];if(!t.isValid){setTimeout(()=>t.elem.focus(),0);break}}}afterSubmitValidation(e=!1){this.renderErrors(e),this.globalConfig.focusInvalidField&&this.focusInvalidField()}validate(e=!1){return new Promise(t=>{const i=[];Object.keys(this.fields).forEach(e=>{const t=this.validateField(e);j(t)&&i.push(t)}),Object.keys(this.groupFields).forEach(e=>{const t=this.validateGroup(e);j(t)&&i.push(t)}),Promise.allSettled(i).then(()=>{var r;this.afterSubmitValidation(e),null==(r=this.onValidateCallback)||r.call(this,{isValid:this.isFormValid(),isSubmitted:this.isSubmitted,fields:this.getCompatibleFields(),groups:{...this.groupFields}}),t(!!i.length)})})}revalidate(){return new Promise(e=>{this.validateHandler(void 0,!0).finally(()=>{this.globalConfig.focusInvalidField&&this.focusInvalidField(),e(this.isValid)})})}validateHandler(e,t=!1){return this.globalConfig.lockForm&&this.lockForm(),this.validate(t).finally(()=>{var t,i,r;this.globalConfig.lockForm&&this.unlockForm(),this.isValid?(null==(t=this.onSuccessCallback)||t.call(this,e),this.globalConfig.submitFormAutomatically&&(null==(i=null==e?void 0:e.currentTarget)||i.submit())):null==(r=this.onFailCallback)||r.call(this,this.getCompatibleFields(),this.groupFields)})}setForm(e){this.form=e,this.form.setAttribute("novalidate","novalidate"),this.removeListener("submit",this.form,this.formSubmitHandler),this.addListener("submit",this.form,this.formSubmitHandler)}addListener(e,t,i){t.addEventListener(e,i),this.eventListeners.push({type:e,elem:t,func:i})}removeListener(e,t,i){t.removeEventListener(e,i),this.eventListeners=this.eventListeners.filter(i=>i.type!==e||i.elem!==t)}addField(e,t,i){if("string"!=typeof e&&!A(e))throw Error("Field selector is not valid. Please specify a string selector or a valid DOM element.");let r;if(r="string"==typeof e?this.form.querySelector(e):e,!r)throw Error("Field doesn't exist in the DOM! Please check the field selector.");if(!Array.isArray(t)||!t.length)throw Error("Rules argument should be an array and should contain at least 1 element.");t.forEach(e=>{if(!("rule"in e||"validator"in e||"plugin"in e))throw Error("Rules argument must contain at least one rule or validator property.");if(!(e.validator||e.plugin||e.rule&&Object.values(M).includes(e.rule)))throw Error(`Rule should be one of these types: ${Object.values(M).join(", ")}. Provided value: ${e.rule}`)});const s=this.setKeyByFieldSelector(e);return this.fields[s]={elem:r,rules:t,isValid:void 0,touched:!1,config:i},this.setListeners(r),(this.isSubmitted||this.globalConfig.validateBeforeSubmitting)&&this.validateField(s),this}removeField(e){if("string"!=typeof e&&!A(e))throw Error("Field selector is not valid. Please specify a string selector or a valid DOM element.");const t=this.getKeyByFieldSelector(e);if(!t||!this.fields[t])return console.error("Field not found. Check the field selector."),this;const i=this.getListenerType(this.fields[t].elem.type);return this.removeListener(i,this.fields[t].elem,this.handlerChange),this.clearErrors(),delete this.fields[t],this}removeGroup(e){if("string"!=typeof e)throw Error("Group selector is not valid. Please specify a string selector.");const t=this.getKeyByFieldSelector(e);return t&&this.groupFields[t]?(this.groupFields[t].elems.forEach(e=>{const t=this.getListenerType(e.type);this.removeListener(t,e,this.handlerChange)}),this.clearErrors(),delete this.groupFields[t],this):(console.error("Group not found. Check the group selector."),this)}addRequiredGroup(e,t,i,r){if("string"!=typeof e&&!A(e))throw Error("Group selector is not valid. Please specify a string selector or a valid DOM element.");let s;if(s="string"==typeof e?this.form.querySelector(e):e,!s)throw Error("Group selector not found! Please check the group selector.");const o=s.querySelectorAll("input"),l=Array.from(o).filter(e=>{const t=((e,t)=>{const i=[...t].reverse();for(let t=0,r=i.length;t<r;++t){const r=i[t];for(const t in e){const i=e[t];if(i.groupElem===r)return[t,i]}}return null})(this.groupFields,(e=>{let t=e;const i=[];for(;t;)i.unshift(t),t=t.parentNode;return i})(e));return!t||t[1].elems.find(t=>t!==e)}),n=this.setKeyByFieldSelector(e);return this.groupFields[n]={rules:[{rule:R.Required,errorMessage:t,successMessage:r}],groupElem:s,elems:l,touched:!1,isValid:void 0,config:i},o.forEach(e=>{this.setListeners(e)}),this}getListenerType(e){switch(e){case"checkbox":case"select-one":case"file":case"radio":return"change";default:return"input"}}setListeners(e){const t=this.getListenerType(e.type);this.removeListener(t,e,this.handlerChange),this.addListener(t,e,this.handlerChange)}clearFieldLabel(e){var t,i;null==(t=this.errorLabels[e])||t.remove(),null==(i=this.successLabels[e])||i.remove()}clearFieldStyle(e){var t,i,r,s;const o=this.fields[e],l=(null==(t=o.config)?void 0:t.errorFieldStyle)||this.globalConfig.errorFieldStyle;Object.keys(l).forEach(e=>{o.elem.style[e]=""});const n=(null==(i=o.config)?void 0:i.successFieldStyle)||this.globalConfig.successFieldStyle||{};Object.keys(n).forEach(e=>{o.elem.style[e]=""}),o.elem.classList.remove(...P((null==(r=o.config)?void 0:r.errorFieldCssClass)||this.globalConfig.errorFieldCssClass),...P((null==(s=o.config)?void 0:s.successFieldCssClass)||this.globalConfig.successFieldCssClass))}clearErrors(){var e,t;Object.keys(this.errorLabels).forEach(e=>this.errorLabels[e].remove()),Object.keys(this.successLabels).forEach(e=>this.successLabels[e].remove());for(const e in this.fields)this.clearFieldStyle(e);for(const i in this.groupFields){const r=this.groupFields[i],s=(null==(e=r.config)?void 0:e.errorFieldStyle)||this.globalConfig.errorFieldStyle;Object.keys(s).forEach(e=>{r.elems.forEach(t=>{var i;t.style[e]="",t.classList.remove(...P((null==(i=r.config)?void 0:i.errorFieldCssClass)||this.globalConfig.errorFieldCssClass))})});const o=(null==(t=r.config)?void 0:t.successFieldStyle)||this.globalConfig.successFieldStyle||{};Object.keys(o).forEach(e=>{r.elems.forEach(t=>{var i;t.style[e]="",t.classList.remove(...P((null==(i=r.config)?void 0:i.successFieldCssClass)||this.globalConfig.successFieldCssClass))})})}this.tooltips=[]}isTooltip(){return!!this.globalConfig.tooltip}lockForm(){const e=this.form.querySelectorAll("input, textarea, button, select");for(let t=0,i=e.length;t<i;++t)e[t].setAttribute("data-just-validate-fallback-disabled",e[t].disabled?"true":"false"),e[t].setAttribute("disabled","disabled"),e[t].style.pointerEvents="none",e[t].style.webkitFilter="grayscale(100%)",e[t].style.filter="grayscale(100%)"}unlockForm(){const e=this.form.querySelectorAll("input, textarea, button, select");for(let t=0,i=e.length;t<i;++t)"true"!==e[t].getAttribute("data-just-validate-fallback-disabled")&&e[t].removeAttribute("disabled"),e[t].style.pointerEvents="",e[t].style.webkitFilter="",e[t].style.filter=""}renderTooltip(e,t,i){var r;const{top:s,left:o,width:l,height:n}=e.getBoundingClientRect(),a=t.getBoundingClientRect(),d=i||(null==(r=this.globalConfig.tooltip)?void 0:r.position);switch(d){case"left":t.style.top=s+n/2-a.height/2+"px",t.style.left=o-a.width-5+"px";break;case"top":t.style.top=s-a.height-5+"px",t.style.left=o+l/2-a.width/2+"px";break;case"right":t.style.top=s+n/2-a.height/2+"px",t.style.left=`${o+l+5}px`;break;case"bottom":t.style.top=`${s+n+5}px`,t.style.left=o+l/2-a.width/2+"px"}return t.dataset.direction=d,{refresh:()=>{this.renderTooltip(e,t,i)}}}createErrorLabelElem(e,t,i){const r=document.createElement("div");r.innerHTML=t;const s=this.isTooltip()?null==i?void 0:i.errorLabelStyle:(null==i?void 0:i.errorLabelStyle)||this.globalConfig.errorLabelStyle;return Object.assign(r.style,s),r.classList.add(...P((null==i?void 0:i.errorLabelCssClass)||this.globalConfig.errorLabelCssClass),"just-validate-error-label"),this.isTooltip()&&(r.dataset.tooltip="true"),this.globalConfig.testingMode&&(r.dataset.testId=`error-label-${e}`),this.errorLabels[e]=r,r}createSuccessLabelElem(e,t,i){if(void 0===t)return null;const r=document.createElement("div");r.innerHTML=t;const s=(null==i?void 0:i.successLabelStyle)||this.globalConfig.successLabelStyle;return Object.assign(r.style,s),r.classList.add(...P((null==i?void 0:i.successLabelCssClass)||this.globalConfig.successLabelCssClass),"just-validate-success-label"),this.globalConfig.testingMode&&(r.dataset.testId=`success-label-${e}`),this.successLabels[e]=r,r}renderErrorsContainer(e,t){const i=t||this.globalConfig.errorsContainer;if("string"==typeof i){const t=this.form.querySelector(i);if(t)return t.appendChild(e),!0;console.error(`Error container with ${i} selector not found. Errors will be rendered as usual`)}return i instanceof Element?(i.appendChild(e),!0):(void 0!==i&&console.error("Error container not found. It should be a string or existing Element. Errors will be rendered as usual"),!1)}renderGroupLabel(e,t,i,r){!r&&this.renderErrorsContainer(t,i)||e.appendChild(t)}renderFieldLabel(e,t,i,r){var s,o,l,n,a,d,c;if(r||!this.renderErrorsContainer(t,i))if("checkbox"===e.type||"radio"===e.type){const i=document.querySelector(`label[for="${e.getAttribute("id")}"]`);"label"===(null==(o=null==(s=e.parentElement)?void 0:s.tagName)?void 0:o.toLowerCase())?null==(n=null==(l=e.parentElement)?void 0:l.parentElement)||n.appendChild(t):i?null==(a=i.parentElement)||a.appendChild(t):null==(d=e.parentElement)||d.appendChild(t)}else null==(c=e.parentElement)||c.appendChild(t)}showLabels(e,t){Object.keys(e).forEach((i,r)=>{const s=e[i],o=this.getKeyByFieldSelector(i);if(!o||!this.fields[o])return void console.error("Field not found. Check the field selector.");const l=this.fields[o];l.isValid=!t,this.clearFieldStyle(o),this.clearFieldLabel(o),this.renderFieldError(o,!1,s),0===r&&this.globalConfig.focusInvalidField&&setTimeout(()=>l.elem.focus(),0)})}showErrors(e){if("object"!=typeof e)throw Error("[showErrors]: Errors should be an object with key: value format");this.showLabels(e,!0)}showSuccessLabels(e){if("object"!=typeof e)throw Error("[showSuccessLabels]: Labels should be an object with key: value format");this.showLabels(e,!1)}renderFieldError(e,t=!1,i){var r,s,o,l,n,a;const d=this.fields[e];if(!1===d.isValid&&(this.isValid=!1),void 0===d.isValid||!t&&!this.isSubmitted&&!d.touched&&void 0===i)return;if(d.isValid){if(!d.asyncCheckPending){const t=this.createSuccessLabelElem(e,void 0!==i?i:d.successMessage,d.config);t&&this.renderFieldLabel(d.elem,t,null==(r=d.config)?void 0:r.errorsContainer,!0),d.elem.classList.add(...P((null==(s=d.config)?void 0:s.successFieldCssClass)||this.globalConfig.successFieldCssClass))}return}d.elem.classList.add(...P((null==(o=d.config)?void 0:o.errorFieldCssClass)||this.globalConfig.errorFieldCssClass));const c=this.createErrorLabelElem(e,void 0!==i?i:d.errorMessage,d.config);this.renderFieldLabel(d.elem,c,null==(l=d.config)?void 0:l.errorsContainer),this.isTooltip()&&this.tooltips.push(this.renderTooltip(d.elem,c,null==(a=null==(n=d.config)?void 0:n.tooltip)?void 0:a.position))}renderGroupError(e,t=!0){var i,r,s,o;const l=this.groupFields[e];if(!1===l.isValid&&(this.isValid=!1),void 0===l.isValid||!t&&!this.isSubmitted&&!l.touched)return;if(l.isValid){l.elems.forEach(e=>{var t,i;Object.assign(e.style,(null==(t=l.config)?void 0:t.successFieldStyle)||this.globalConfig.successFieldStyle),e.classList.add(...P((null==(i=l.config)?void 0:i.successFieldCssClass)||this.globalConfig.successFieldCssClass))});const t=this.createSuccessLabelElem(e,l.successMessage,l.config);return void(t&&this.renderGroupLabel(l.groupElem,t,null==(i=l.config)?void 0:i.errorsContainer,!0))}this.isValid=!1,l.elems.forEach(e=>{var t,i;Object.assign(e.style,(null==(t=l.config)?void 0:t.errorFieldStyle)||this.globalConfig.errorFieldStyle),e.classList.add(...P((null==(i=l.config)?void 0:i.errorFieldCssClass)||this.globalConfig.errorFieldCssClass))});const n=this.createErrorLabelElem(e,l.errorMessage,l.config);this.renderGroupLabel(l.groupElem,n,null==(r=l.config)?void 0:r.errorsContainer),this.isTooltip()&&this.tooltips.push(this.renderTooltip(l.groupElem,n,null==(o=null==(s=l.config)?void 0:s.tooltip)?void 0:o.position))}renderErrors(e=!1){if(this.isSubmitted||e||this.globalConfig.validateBeforeSubmitting){this.clearErrors(),this.isValid=!0;for(const e in this.groupFields)this.renderGroupError(e);for(const e in this.fields)this.renderFieldError(e)}}destroy(){this.eventListeners.forEach(e=>{this.removeListener(e.type,e.elem,e.func)}),Object.keys(this.customStyleTags).forEach(e=>{this.customStyleTags[e].remove()}),this.clearErrors(),this.globalConfig.lockForm&&this.unlockForm()}refresh(){this.destroy(),this.form?(this.initialize(this.form,this.globalConfig),Object.keys(this.fields).forEach(e=>{const t=this.getFieldSelectorByKey(e);t&&this.addField(t,[...this.fields[e].rules],this.fields[e].config)})):console.error("Cannot initialize the library! Form is not defined")}setCurrentLocale(e){"string"==typeof e||void 0===e?(this.currentLocale=e,this.isSubmitted&&this.validate()):console.error("Current locale should be a string")}onSuccess(e){return this.onSuccessCallback=e,this}onFail(e){return this.onFailCallback=e,this}onValidate(e){return this.onValidateCallback=e,this}}window.moment;const q=window.moment;function O(){const t=e(),i=v(t.comment.comment_content);return t.comment.show_full_content?i:p(i,250)}function B(){const t=e();return q(t.comment.comment_date,"YYYY-MM-DD HH:mm:ss").format("D MMM, YYYY")}function G(){const t=e();return t[t.loopKey].like}function N(){const t=e();if(1===t[t.loopKey].user_reaction)return"#D2D6DB"}function z(){const t=e();if(0===t[t.loopKey].user_reaction)return"#D2D6DB"}function Y(){const t=e();return parseInt(t[t.loopKey].comment_ID)===parseInt(t.commentDelete.comment_ID)?"inherit":"none"}function H(t){b(t),e().highlightFileUpload=!0}function U(t){b(t),e().highlightFileUpload=!1}function Z(e){b(e),U(e),W(e.dataTransfer.files),X()}function Q(e){const{createReview:t}=e,i=t.files.some(e=>e.uploading);t.disable_submission=i}function X(){const e=document.querySelector("#file-input.adr-upload__input");e&&(e.value="")}function W(e){const t=e.target?e.target.files:e;for(let e of t)J(e);e.target&&X()}function J(t){const i=e(),{createReview:r}=i;if(i.max_allowed<=r.files.length)return;const s=URL.createObjectURL(t);r.files.push({id:Math.floor(1e4*Math.random()),src:s,progress:"0%",uploaded:!1,uploading:!0,xhrRequest:null}),Q(i);const o=r.files[r.files.length-1],l=new FormData;l.append("file",t);const n=window.jQuery.ajax({url:`${i.rest_url}/reviews/upload`,type:"POST",data:l,processData:!1,contentType:!1,headers:{"X-WP-Nonce":i.nonce},xhr:function(){const e=new XMLHttpRequest;return e.upload.onprogress=e=>{e.lengthComputable&&(o.progress=`${Math.round(100*e.loaded/e.total)}%`)},e},success:e=>{o.attachment_id=e.data.attachment_id,o.uploaded=!0,o.uploading=!1,o.xhrRequest=null,Q(i)},error:(e,t,s)=>{o.uploading=!1,Q(i),"abort"!==t&&(console.error("Error uploading file:",s),r.files=r.files.filter(e=>e.id!==o.id),alert("Failed to upload file. Please try again."))},dataType:"json",accepts:{json:"application/json"}});o.xhrRequest=n}function ee(){const t=e(),{createReview:i,item:r}=t;r.xhrRequest&&(r.xhrRequest.abort(),r.xhrRequest=null),i.files=i.files.filter(e=>e.id!==r.id),Q(t),r.attachment_id&&u({url:`${t.rest_url}/reviews/upload`,method:"DELETE",data:{attachment_id:r.attachment_id}}).catch(()=>{})}const te=window.moment,{state:ie}=i("directorist-advanced-review",{state:{hasFiles:()=>0!==e().createReview.files.length,getGalleryId:()=>"gallery-"+e().item.comment_ID,hasReviews:()=>e().has_review,headerTotalText:()=>{const t=e();return t.total>1?`Based on ${t.total} Reviews`:`Based on ${t.total} Review`},getCommentText:()=>e().item.total_children>1?"Comments":"Comment",getReplyText:()=>e().reply.total_children>1?"Replies":"Reply",reviewExists:()=>0!==e().reviews.length,isOwnComment:()=>{const t=e();return parseInt(t[t.loopKey].author_ID)&&t.user_ID},isListingOwner:()=>{const t=e();return t[t.loopKey].is_listing_owner},showReviewCreateForm:()=>{const t=e();return t.show_review_form&&!t.is_user_reviewed},showCommentCreateForm:()=>{const t=e();return t.commentForm.comment_ID===parseInt(t[t.loopKey].comment_ID)&&"create"===t.commentForm.type},showFileUploadArea:()=>{const t=e();return t.max_allowed>t.createReview.files.length},showCommentEditForm:()=>{const t=e(),i=parseInt(t[t.loopKey].comment_ID);return t.commentForm.comment_ID===i&&"edit"===t.commentForm.type},showReviewAction:()=>{const t=e();return parseInt(t[t.loopKey].comment_ID)===t.commentAction.comment_ID?"flex":"none"},hasShowMore:()=>{const t=e();return t[t.loopKey].comment_content.length>250},commentContent:()=>{const t=e(),i=t[t.loopKey].comment_content;return t[t.loopKey].show_full_content?i:p(i,250)},hasComment:()=>{const t=e();return 0!==t[t.loopKey].comment_content.length},createFormRatings:()=>{const t=e();let i=[];for(let e=1;e<6;e++)e<=t.createReview.rating?i.push({rating:e,is_full:!0,is_empty:!1}):i.push({rating:e,is_full:!1,is_empty:!0});return i},createFormCategoryRatings:()=>{var t;const i=e();let r=i.item.id,s=null!==(t=i.createReview.ratings[r])&&void 0!==t?t:1,o=[];for(let e=1;e<6;e++)e<=s?o.push({rating:e,is_full:!0,is_empty:!1}):o.push({rating:e,is_full:!1,is_empty:!0});return o},getReviewDate:()=>{const t=e();return te(t[t.loopKey].comment_date,"YYYY-MM-DD HH:mm:ss").format("D MMM, YYYY")},isSortOptionSelected:()=>{const t=e();return t.item.value===t.filters.sort},isRatingOptionSelected:()=>{const t=e();return parseInt(t.item.value)===t.filters.rating},getCriteriaBarWidth:()=>{let t=e().item.average;return t<0&&(t=0),t>5&&(t=5),t/5*100+"%"},getReviewRatings:()=>g(e().item.rating),getAverageRatingStars:()=>g(e().average),getPagination:()=>{const t=e();return function(e,t,i=5){let r=[];if(t<=i+2){for(let e=1;e<=t;e++)r.push({page:e});return r}r.push({page:1}),e>i&&r.push({page:"::",isBreak:!0});let s=Math.max(2,e-Math.floor(i/2)),o=Math.min(t-1,s+i-1);o===t-1&&(s=Math.max(2,t-i));for(let e=s;e<=o;e++)r.push({page:e});return o<t-1&&r.push({page:"::",isBreak:!0}),r.push({page:t}),r}(t.page,ie.getTotalPage(),t.per_page)},isPageActive:()=>{const t=e();return t.page===t.item.page},getTotalPage:()=>{const t=e();return Math.ceil(t.total/t.per_page)},isPaginationExist:()=>ie.getTotalPage()>1,isFirstPageActive:()=>1===e().page,isLastPageActive:()=>{const t=e();return ie.getTotalPage()===t.page},getReviewCriteriaProgressWidth:()=>e().criteria.rating/5*100+"%",commentEditContent:()=>{const t=e();return t[t.loopKey].commentEditContent},createReview:{is_loading:!1},...s,...o,...l,...n,displayLoginAlert:()=>e().unauthorized_reaction_modal.show},callbacks:{init:function(){const t=e(),i=jQuery;i("#adr-filters__sort").select2({minimumResultsForSearch:1/0,allowClear:!0,dropdownCssClass:"adr-filters__dropdown",dropdownParent:i("body")}).on("change",function(){t.filters.sort=i(this).val(),m(t)}),i("#adr-filters__rating").select2({minimumResultsForSearch:1/0,allowClear:!0,dropdownCssClass:"adr-filters__dropdown",dropdownParent:i("body")}).on("change",function(){t.filters.rating=parseInt(i(this).val(),10),m(t)}),i(".adr-filters__wrapper").each(function(){i(document).on("select2:open",function(e){const t=i(e.target).closest(".adr-filters__wrapper"),r=i(e.target).closest(".adr-filters__sort-container, .adr-filters__rating-container");t.find(".adr-filters__icon-right").removeClass("active"),r.find(".adr-filters__icon-right").addClass("active")}).on("select2:close",function(e){i(e.target).closest(".adr-filters__sort-container, .adr-filters__rating-container").find(".adr-filters__icon-right").removeClass("active")})}),h(),i(document).on("keydown",function(e){"Escape"===e.key&&(t.unauthorized_reaction_modal.show=!1)}),i(document).on("click",function(e){e.target.classList.contains("adr-modal")&&(t.unauthorized_reaction_modal.show=!1)})},initReviewForm:function(){const i=t(),r=e(),s=new K(`#${i.ref.id}`,{validateBeforeSubmitting:!0});s.addField("#adr-review-form__review-title",[{rule:"required",errorMessage:"The review title field is required"},{rule:"maxLength",value:120}],{errorsContainer:".adr-form-status__review-title .adr-form-status__warning"}),r.is_gdpr_enabled&&s.addField("#adr-review-form__gdpr-consent",[{rule:"required",errorMessage:"Gdpr consent is required."}]),r.is_cookies_enabled&&s.addField("#adr-review-form__cookie-consent",[{rule:"required",errorMessage:"Cookie consent is required."}]),r.is_guest&&s.addField("#adr-review-form__review-email",[{rule:"required",errorMessage:"The email field is required"},{rule:"email"},{rule:"maxLength",value:120}],{errorsContainer:".adr-form-status__review-email .adr-form-status__warning"}).addField("#adr-review-form__review-name",[{rule:"required",errorMessage:"The name field is required"},{rule:"maxLength",value:120}],{errorsContainer:".adr-form-status__review-name .adr-form-status__warning"}),s.addField("#adr-review-form__review-feedback",[{rule:"required",errorMessage:"The feedback field is required"},{rule:"maxLength",value:1e3}]),s.onSuccess(async e=>{e.preventDefault(),r.createReview.is_loading=!0;const t=new FormData(e.target);let s=Object.fromEntries(t.entries());const o=r.createReview.files.map(e=>e.attachment_id);s.rating=parseInt(t.get("rating")),s.post_id=r.post_id,s.rating=r.createReview.rating,s.ratings={...r.createReview.ratings},s.attachment_ids=o;const l=new c;try{await l.create(s),m(r),i.ref.reset(),r.createReview.files=[],r.createReview.duplicate_email_error=!1,r.show_review_form=!r.show_review_form,r.show_review_form||C()}catch(e){console.log("Errors",e),400===e.data.status&&(r.createReview.duplicate_email_error=!0)}finally{r.createReview.is_loading=!1}}),_(".adr-review-form__group-item--title","#adr-review-form__review-title",".adr-review-form__word-limit"),_(".adr-review-form__group-item--feedback","#adr-review-form__review-feedback",".adr-review-form__word-limit")},initReplyForm:function(){const i=t(),r=e(),s=new K(i.ref,{validateBeforeSubmitting:!0});s.addField(".adr-review-reply__form-control",[{rule:"required"}]),w(s,r,i)},initReportForm:function(){const i=t(),r=e(),s=new K(`#${i.ref.id}`,{validateBeforeSubmitting:!0,errorsContainer:".adr-form-status__warning"});s.addField("#adrMoreInfo",[{rule:"required",errorMessage:"Don’t leave this blank"}]),s.onSuccess(async e=>{e.preventDefault();const t=new FormData(e.target);let s=Object.fromEntries(t.entries());const o=new c;try{await o.submitReport(parseInt(r.report_modal.comment_ID),s.content),r.report_modal.show=!1,i.ref.reset()}catch(e){console.log("Errors",e)}}),_(".adr-report-form",".adr-report-form__form-control",".adr-report-form__word-limit")},initCommentForm:function(){jQuery;const i=t(),r=e(),s=new K(i.ref,{validateBeforeSubmitting:!0,errorsContainer:".adr-form-status__warning"});s.addField("textarea",[{rule:"required"}]),w(s,r,i),function(e,t="input"){document.querySelectorAll(e).forEach(function(e){e.addEventListener(t,function(){this.style.height="auto",this.style.height=this.scrollHeight+"px"})})}(".adr-reply-child-comment__form-control")},initEditCommentForm:function(){const i=t(),r=e(),s=new K(i.ref,{validateBeforeSubmitting:!0});s.addField("textarea",[{rule:"required"}]),function(e,t){e.onSuccess(async e=>{e.preventDefault();const i=new FormData(e.target);let r=Object.fromEntries(i.entries());r.post_id=t.post_id,r.comment_ID=parseInt(t[t.loopKey].comment_ID);const s=new c;try{await s.updateReply(r),t[t.loopKey].comment_content=r.comment,y(t)}catch(e){console.log("Errors",e)}})}(s,r)},initComment:()=>{const t=e();t[t.loopKey].comment_content=v(t[t.loopKey].comment_content)},onClickReadMore:()=>{const t=e();t.item.show_full_content=!t.item.show_full_content},onClickPage:()=>{const t=e();t.item.isBreak||(t.page=t.item.page,m(t),C())},onClickPrevPage:()=>{if(ie.isFirstPageActive())return;const t=e();t.page=t.page-1,m(t),C()},onClickNextPage:()=>{if(ie.isLastPageActive())return;const t=e();t.page=t.page+1,m(t),C()}},actions:{onClickReviewActions:()=>{const t=e(),i=t.commentAction.comment_ID,r=parseInt(t[t.loopKey].comment_ID);t.commentAction.comment_ID=i===r?0:r},onClickOutside:t=>{const i=e();t.target.closest(".adr-review__dropdown")||(i.commentAction.comment_ID=0)},onClickReviewAction:()=>{const t=e();t.report_modal.show=!t.report_modal.show,t.report_modal.comment_ID=t.item.comment_ID,t.commentAction.comment_ID=0},onClickCommentEditAction:()=>{const t=e();let i=t[t.loopKey];const r=parseInt(i.comment_ID);t.commentForm.type=t.commentForm.comment_ID===r?"":"edit",t.commentForm.comment_ID=t.commentForm.comment_ID===r?0:r,"edit"===t.commentForm.type&&(t.commentAction.comment_ID=0),t[t.loopKey].commentEditContent=i.comment_content},onCloseReportModal:()=>{e().report_modal.show=!1},onClickCreateFormRating:()=>{const t=e();t.createReview.rating=t.rating.rating},onClickCreateFormCategoryRating:()=>{const t=e();let i=t.item.id;t.createReview.ratings[i]=t.rating.rating},onClickLikeButton:async()=>{const t=e();if(!F(t))return void(t.unauthorized_reaction_modal.show=!0);const i=new c,r=1===t[t.loopKey].user_reaction?null:1,s=await i.reaction(t[t.loopKey].comment_ID,r);t[t.loopKey].user_reaction=r,t[t.loopKey].like=s.data.like},onClickUnLikeButton:async()=>{const t=e();if(!F(t))return void(t.unauthorized_reaction_modal.show=!0);const i=new c,r=0===t[t.loopKey].user_reaction?null:0,s=await i.reaction(t[t.loopKey].comment_ID,r);t[t.loopKey].user_reaction=r,t[t.loopKey].like=s.data.like},onCloseLoginAlert:()=>{const t=e();t.unauthorized_reaction_modal.show=!t.unauthorized_reaction_modal.show},toggleCriteria:()=>{const t=e();t.item.checked=!t.item.checked,m(t)},toggleReviewForm:()=>{const t=e();if(t.show_review_form=!t.show_review_form,t.show_review_form){const e=document.getElementById("adr-create-review");e&&e.scrollIntoView({behavior:"smooth",block:"start"})}},onClickReplyButton:()=>{const t=e(),i=parseInt(t[t.loopKey].comment_ID);t.commentForm.type=t.commentForm.comment_ID===i?"":"create",t.commentForm.comment_ID=t.commentForm.comment_ID===i?0:i},onClickReplyEditButton:()=>{const t=e(),i=parseInt(t[t.loopKey].comment_ID);t.commentForm.type="edit",t.commentForm.comment_ID=i,t.commentAction.comment_ID=0},onCloseReplyForm:()=>{y(e())},onClickCommentButton:async()=>{const t=e();if(0===t[t.loopKey].total_children)return;t[t.loopKey].show_replies=!t[t.loopKey].show_replies;const i=new c,r=await i.getReplies(t[t.loopKey].comment_ID,t.post_id);t[t.loopKey].comments=r.items},onClickDeleteCommentAction:()=>{const t=e();t.commentDelete.comment_ID=t[t.loopKey].comment_ID,t.commentDelete.parentLoopKey=t.parentLoopKey},onClickDeleteCancel:()=>{e().commentDelete.comment_ID=0},onClickDeleteButton:async()=>{const i=e();t().ref.disabled=!0;const{commentDelete:r}=i,{comment_ID:s,parentLoopKey:o}=r;if(!s)return;await(new c).delete(s);const l=i[o];l?.comments&&(l.comments=l.comments.filter(e=>e.comment_ID!==s),l.total_children=Math.max(0,(l.total_children||0)-1)),r.comment_ID=0},...a}});