{"version":3,"file":"CMSRelativeTime.Dq4NaeTY.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/v5jwhdgsiqrg4kG0DgW2/Nlc0S82ptPvosLt1FH4z/CMSRelativeTime.js"],"sourcesContent":["import{jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useEffect}from\"react\";import{addPropertyControls,ControlType}from\"framer\";import{motion}from\"framer-motion\";/**\n * @copyright ©framersnippets.com\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n * @framerDisableUnlink\n **/export default function CMSRelativeTime({date,unit,font,color,prefix,suffix,locale:initialLocale}){const[locale,setLocale]=useState(initialLocale||\"en-US\");useEffect(()=>{setLocale(initialLocale||navigator.language);},[initialLocale]);const relativeTime=formatRelativeTime(date,unit,locale);return /*#__PURE__*/_jsxs(motion.div,{style:{...font,color},children:[prefix,\" \",relativeTime,\" \",suffix]});}function formatRelativeTime(date,unit,locale){const now=new Date;const targetDate=new Date(date);const diffMs=targetDate-now;const isPast=diffMs<0;const rtf=new Intl.RelativeTimeFormat(locale,{numeric:\"auto\"});let unitValue,unitLabel;const absDiffSecs=Math.abs(Math.round(diffMs/1e3));const absDiffMins=Math.abs(Math.round(absDiffSecs/60));const absDiffHours=Math.abs(Math.round(absDiffMins/60));const absDiffDays=Math.abs(Math.round(absDiffHours/24));const absDiffWeeks=Math.abs(Math.round(absDiffDays/7));const absDiffMonths=Math.abs(Math.round(absDiffDays/30.44));const absDiffYears=Math.abs(Math.round(absDiffDays/365));if(unit===\"auto\"){if(absDiffYears>=1){unitValue=absDiffYears;unitLabel=\"year\";}else if(absDiffMonths>=1){unitValue=absDiffMonths;unitLabel=\"month\";}else if(absDiffWeeks>=1){unitValue=absDiffWeeks;unitLabel=\"week\";}else if(absDiffDays>=1){unitValue=absDiffDays;unitLabel=\"day\";}else if(absDiffHours>=1){unitValue=absDiffHours;unitLabel=\"hour\";}else if(absDiffMins>=1){unitValue=absDiffMins;unitLabel=\"minute\";}else{unitValue=absDiffSecs;unitLabel=\"second\";}}else{unitValue=({years:absDiffYears,months:absDiffMonths,weeks:absDiffWeeks,days:absDiffDays,hours:absDiffHours,minutes:absDiffMins,seconds:absDiffSecs})[unit];unitLabel=unit;}const formattedTime=rtf.format(isPast?-unitValue:unitValue,unitLabel);return isPast?`${formattedTime} `:` ${formattedTime}`;}CMSRelativeTime.defaultProps={date:new Date().toISOString(),unit:\"auto\",font:{fontFamily:\"Inter, sans-serif\",fontSize:15,fontWeight:400,lineHeight:1.2,letterSpacing:0},color:\"#000\",prefix:\"\",suffix:\"\",locale:\"\"};addPropertyControls(CMSRelativeTime,{date:{type:ControlType.Date,title:\"Date\"},font:{type:ControlType.Font,controls:\"extended\",defaultValue:CMSRelativeTime.defaultProps.font},color:{type:ControlType.Color,title:\"Color\"},unit:{type:ControlType.Enum,title:\"Unit\",defaultValue:\"auto\",options:[\"auto\",\"years\",\"months\",\"weeks\",\"days\",\"hours\",\"minutes\",\"seconds\"],optionTitles:[\"Auto\",\"Years\",\"Months\",\"Weeks\",\"Days\",\"Hours\",\"Minutes\",\"Seconds\"]},locale:{type:ControlType.String,title:\"Locale\",description:\"Auto by default\"},prefix:{type:ControlType.String,title:\"Prefix\",defaultValue:\"\",placeholder:\"Enter prefix..\"},suffix:{type:ControlType.String,title:\"Suffix\",placeholder:\"Enter suffix..\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"CMSRelativeTime\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"any\",\"framerDisableUnlink\":\"\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CMSRelativeTime.map"],"mappings":"gPAKI,SAAwB,EAAgB,CAAC,OAAK,OAAK,OAAK,QAAM,SAAO,SAAO,OAAO,GAAe,CAAC,GAAK,CAAC,EAAO,GAAWA,EAAS,GAAe,QAAQ,CAAC,MAAc,CAA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