"use strict";var TextInline=require("../../text/components/TextInline.js"),helpers=require("../../helpers.js"),system=require("@gem-sdk/system"),styles=require("./styles.js");const getEstimateValue=e=>e?"number"==typeof e?e:Number(e.split("days")[0]):0,getDayEst=e=>{let t=new Date(Date.now()),a=getEstimateValue(e?.estimateTime),r=getEstimateValue(e?.minEstimate),s=getEstimateValue(e?.maxEstimate),l=e?.typeFormat==="Custom"?e?.customFormat:e?.typeFormat;if(!l)return"";if(e?.typeEstimate===ESTIMATE_DAYS.SPECIFIC){let e=`${getDayFormat(getFutureDay(a),l)}`;return e}getDayFormat(t);let u=`${getDayFormat(getFutureDay(r),l)} - ${getDayFormat(getFutureDay(s),l)}`;return u},EstimateDateLevel=e=>{switch(e?.htmlTag){case 1:return"h1";case 2:return"h2";case 3:return"h3";case 4:return"h4";case 5:return"h5";case 6:return"h6";default:return"div"}},getNewSetting=({type:e,styles:t,setting:a,builderProps:r,pageContext:s})=>{let l="React"===e,u=getTextContent({type:e,styles:t,setting:a,builderProps:r,pageContext:s});return{text:u,htmlTag:EstimateDateLevel(a),globalSize:a?.globalSize,background:a?.background,...!l&&{translate:a?.translate,isForceValue:!0}}},getTextContent=({type:e,styles:t,setting:a,builderProps:r,pageContext:s})=>{let l="React"===e,u=system.createClass({"estimate-date-main":!0}),n=l||s?.isPreviewing?a?.customText:helpers.getDynamicSourceLocales({val:a?.customText,uid:r?.uid,settingId:a?.translate||"",pageContext:s,isCapitalize:t?.typo?.attrs?.transform==="capitalize",translate:a?.translate}).toString(),i={pageContext:s,setting:a,isReact:l,builderProps:r,textWithTranslate:n};return`${a?.enableCustomText===!1?"":TextInline.default({styles:styles.getStyleEstimateDate(t,"typoCustom"),setting:{text:n},elementAttrs:{debugText:JSON.stringify(i).replaceAll("'","&#039;")}})} ${TextInline.default({styles:styles.getStyleEstimateDate(t,"typoDate"),setting:{text:getDayEst(a)},className:u})}`},OUT_OF_STOCK={SHOW:"show",HIDE:"hide"},ESTIMATE_DAYS={SPECIFIC:"specific",RANGE:"range"},getDayFormat=(e,t="%B %d, %Y")=>{let a=e.getMonth()+1,r=e.getDate(),s=e.getFullYear();function l(e){let t=Math.floor(e/10)%10,a=e%10;return 1===a&&1!==t?"st":2===a&&1!==t?"nd":3===a&&1!==t?"rd":"th"}let u=[{type:"%a",value:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][e.getDay()]},{type:"%A",value:["Sunday","Monday","Tueday","Wednesday","Thursday","Friday","Saturday"][e.getDay()]},{type:"%d",value:r.toString().padStart(2,"0")},{type:"%b",value:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][a-1]},{type:"%B",value:["January","February","March","April","May","June","July","August","September","October","November","December"][a-1]},{type:"%m",value:a.toString().padStart(2,"0")},{type:"%y",value:s.toString().slice(-2)},{type:"%Y",value:s},{type:"%sf",value:l(r)}];return u.forEach(e=>{t=t.replaceAll(e?.type,e?.value?.toString()||"")}),t},getFutureDay=e=>{let t=new Date,a=new Date(t);return a.setDate(t.getDate()+Number(e)),a},listFormatDate=()=>{let e=new Date(Date.now());return{FORMAT_1:{Label:getDayFormat(e,"%b %d"),value:"%b %d"},FORMAT_2:{Label:getDayFormat(e,"%b %d, %Y"),value:"%b %d, %Y"},FORMAT_3:{Label:getDayFormat(e,"%a, %b %d"),value:"%a, %b %d"},FORMAT_4:{Label:getDayFormat(e,"%d/%m/%Y"),value:"%d/%m/%Y"},FORMAT_5:{Label:getDayFormat(e,"%Y/%m/%d"),value:"%Y/%m/%d"},FORMAT_6:{Label:"Custom"}}};exports.ESTIMATE_DAYS=ESTIMATE_DAYS,exports.OUT_OF_STOCK=OUT_OF_STOCK,exports.getDayFormat=getDayFormat,exports.getFutureDay=getFutureDay,exports.getNewSetting=getNewSetting,exports.listFormatDate=listFormatDate;
