import t from"../../text/components/TextInline.js";import{getDynamicSourceLocales as e}from"../../helpers.js";import{createClass as a}from"@gem-sdk/system";import{getStyleEstimateDate as r}from"./styles.js";let getEstimateValue=t=>t?"number"==typeof t?t:Number(t.split("days")[0]):0,getDayEst=t=>{let e=new Date(Date.now()),a=getEstimateValue(t?.estimateTime),r=getEstimateValue(t?.minEstimate),u=getEstimateValue(t?.maxEstimate),l=t?.typeFormat==="Custom"?t?.customFormat:t?.typeFormat;if(!l)return"";if(t?.typeEstimate===ESTIMATE_DAYS.SPECIFIC){let t=`${getDayFormat(getFutureDay(a),l)}`;return t}getDayFormat(e);let s=`${getDayFormat(getFutureDay(r),l)} - ${getDayFormat(getFutureDay(u),l)}`;return s},EstimateDateLevel=t=>{switch(t?.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:t,styles:e,setting:a,builderProps:r,pageContext:u})=>{let l="React"===t,s=getTextContent({type:t,styles:e,setting:a,builderProps:r,pageContext:u});return{text:s,htmlTag:EstimateDateLevel(a),globalSize:a?.globalSize,background:a?.background,...!l&&{translate:a?.translate,isForceValue:!0}}},getTextContent=({type:u,styles:l,setting:s,builderProps:n,pageContext:m})=>{let o="React"===u,i=a({"estimate-date-main":!0}),y=o||m?.isPreviewing?s?.customText:e({val:s?.customText,uid:n?.uid,settingId:s?.translate||"",pageContext:m,isCapitalize:l?.typo?.attrs?.transform==="capitalize",translate:s?.translate}).toString(),g={pageContext:m,setting:s,isReact:o,builderProps:n,textWithTranslate:y};return`${s?.enableCustomText===!1?"":t({styles:r(l,"typoCustom"),setting:{text:y},elementAttrs:{debugText:JSON.stringify(g).replaceAll("'","&#039;")}})} ${t({styles:r(l,"typoDate"),setting:{text:getDayEst(s)},className:i})}`},OUT_OF_STOCK={SHOW:"show",HIDE:"hide"},ESTIMATE_DAYS={SPECIFIC:"specific",RANGE:"range"},getDayFormat=(t,e="%B %d, %Y")=>{let a=t.getMonth()+1,r=t.getDate(),u=t.getFullYear();function l(t){let e=Math.floor(t/10)%10,a=t%10;return 1===a&&1!==e?"st":2===a&&1!==e?"nd":3===a&&1!==e?"rd":"th"}let s=[{type:"%a",value:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()]},{type:"%A",value:["Sunday","Monday","Tueday","Wednesday","Thursday","Friday","Saturday"][t.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:u.toString().slice(-2)},{type:"%Y",value:u},{type:"%sf",value:l(r)}];return s.forEach(t=>{e=e.replaceAll(t?.type,t?.value?.toString()||"")}),e},getFutureDay=t=>{let e=new Date,a=new Date(e);return a.setDate(e.getDate()+Number(t)),a},listFormatDate=()=>{let t=new Date(Date.now());return{FORMAT_1:{Label:getDayFormat(t,"%b %d"),value:"%b %d"},FORMAT_2:{Label:getDayFormat(t,"%b %d, %Y"),value:"%b %d, %Y"},FORMAT_3:{Label:getDayFormat(t,"%a, %b %d"),value:"%a, %b %d"},FORMAT_4:{Label:getDayFormat(t,"%d/%m/%Y"),value:"%d/%m/%Y"},FORMAT_5:{Label:getDayFormat(t,"%Y/%m/%d"),value:"%Y/%m/%d"},FORMAT_6:{Label:"Custom"}}};export{ESTIMATE_DAYS,OUT_OF_STOCK,getDayFormat,getFutureDay,getNewSetting,listFormatDate};
