import{tablesome_format,tablesome_formatDistance,tablesome_formatRelative,tablesome_isValid}from"./wrapper/date-fns";class utils{getKeyPressed(e){e.keyCode;const t=13==e.keyCode&&!e.shiftKey,a=9==e.keyCode&&!e.shiftKey,r=!(!e.shiftKey||9!=e.keyCode),o=!!(17==e.keyCode||65==e.keyCode&&e.ctrlKey);return a?"TAB_KEY_EVENT":r?"SHIFT_TAB_KEY_EVENT":t?"ENTER_KEY_EVENT":o?"CONTROL_KEY_EVENT":"OTHER_KEY_EVENT"}htmlDecode(e){return(new DOMParser).parseFromString(e,"text/html").documentElement.textContent}getCell(e){let t=jQuery(e.target);return"TD"!=jQuery(e.target).prop("tagName")&&(t=jQuery(e.target).closest("td")),t}getCellLocation(e,t){let a=e.parent().attr("data-state-record-id"),r=t.rowStore.rows.findIndex((e=>e.stateRecordID==a));return{rowIndex:parseInt(r),cellIndex:e.index()}}getCellLocationByStateRecordId(e,t){let a=t.rowStore.rows.findIndex((t=>t.stateRecordID==e));return{rowIndex:parseInt(a),cellIndex:0}}updateCell(e,t){t.doAction({type:"UPDATE_CELL_DATA",payload:{data:e}})}getFiltersOfTypeForSelectField(e,t){let a=t[e],r=[];return a.forEach((e=>{r.push({value:e,label:e})})),r}clickOutside(e){const t=t=>{!e||e.contains(t.target)||t.defaultPrevented||e.dispatchEvent(new CustomEvent("click_outside",e))};return document.addEventListener("click",t,!0),{destroy(){document.removeEventListener("click",t,!0)}}}getDomainName(e){try{return new URL(e).hostname}catch(e){return null}}fixLink(e){const t="number"==typeof e.value?e.value.toString():e&&"value"in e?e.value:"";let a=e.linkText;a=a||t.replace(/^(?:https?:\/\/)?(?:www\.)?/i,""),a=a.length>=40?a.substring(0,40)+"...":a;let r=1==t.startsWith("http")?t:"//"+t;const o=/\.[a-zA-Z]{2,}$/.test(r),n=t.includes("www")||t.includes("http");if(!o&&!n){r=window.location.origin+(r.startsWith("/")?r:"/"+r)}return r=decodeURI(r),r=r.replace("&amp;","&"),window.decodeURI,{link:r,linkText:a}}fixMediaLink(e=""){let t=e.startsWith("http"),a=""===e.trim();return e=a||1==t?e:"http://"+e}ValidateEmail(e){return/^(([^<>()[\]\\.,;:\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,}))$/.test(String(e).toLowerCase())}getBool(e){var t=+e;return isNaN(t)?!!String(e).toLowerCase().replace(!1,""):!!t}getDate(e,t=!1,a=null){const r=(e="string"==typeof e?e.trim():e)&&new Date(e).valueOf(),o=6e4*(new Date).getTimezoneOffset();if(!r)return e;if(t)return new Date(new Date(e)-o).toISOString().slice(0,10);if("filter"==a){let t=new Date(new Date(e)-o);return t=t.getDate()+""+t.getMonth()+t.getFullYear(),parseFloat(t)}return new Date(new Date(e)-o).getTime()}getFormatedDate(e,t,a,r){let o=e,n=new Date;if(e=t.date_format&&"wp_default"!==t.date_format?"distance"===t.date_format?tablesome_formatDistance(e,n,{addSuffix:!0,includeSeconds:!0}):"relative"===t.date_format?tablesome_formatRelative(e,n):tablesome_format(e,t.date_format,a,r):tablesome_format(e,tablesome_settings.date_format,a,r),t.show_time&&"distance"!==t.date_format&&"relative"!==t.date_format){let n=this._getTimeFormat(t);e+=" "+tablesome_format(o,n,a,r)}return e}getDateHTML(e,t,a){let r="";if(!e||""==e||0==e)return r;if(tablesome_isValid(parseInt(e))){let o=parseInt(e);r=this.getFormatedDate(o,t,{},a)}return r}_getTimeFormat(e){return"twenty_four_hour"===e.time_format?e.show_seconds?"kk:mm:ss":"kk:mm":e.show_seconds?"hh:mm:ss aa":"hh:mm aa"}}export default new utils;