import t from"../../text/components/TextInline.js";import{getDynamicSourceLocales as e,createSettingId as a}from"../../helpers.js";import{createClass as r}from"@gem-sdk/system";import{getStyleEstimateDate as u}from"./styles.js";import{EstimateDate as l}from"../settings/configs/translate.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&&{isForceValue:!0}}},getTextContent=({type:s,styles:o,setting:m,builderProps:n,pageContext:i})=>{let g="React"===s,y=r({"estimate-date-main":!0}),D=g||i?.isPreviewing?m?.customText:e({val:m?.customText,uid:n?.uid,settingId:a({id:l?.customText?.id}),pageContext:i??{},isCapitalize:o?.typo?.attrs?.transform==="capitalize"}).toString(),d={pageContext:i,setting:m,isReact:g,builderProps:n,textWithTranslate:D};return`${m?.enableCustomText===!1?"":t({styles:u(o,"typoCustom"),setting:{text:D},elementAttrs:{debugText:JSON.stringify(d).replaceAll("'","&#039;")}})} ${t({styles:u(o,"typoDate"),setting:{text:getDayEst(m)},className:y})}`},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};
