{"version":3,"file":"RelativeDateLabel.-cAlCW9u.mjs","names":["useState","date","_Fragment"],"sources":["https:/framerusercontent.com/modules/t8Qr6L6FYBKrlEUWDdZt/FZWC9nUSzGqTV910KYCC/RelativeDateLabel.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useState,useEffect}from\"react\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight auto\n */export default function RelativeDateLabel(props){const{date,locale,format,textCase,transform}=props;const[isPast,setIsPast]=useState(true);const[relativeTitle,setRelativeTitle]=useState(\"\");useEffect(()=>{if(!date){return;}const compareDate=new Date(date);const now=new Date;now.setHours(0,0,0,0)// Reset time to 12 AM\n;setIsPast(now>compareDate);const formatter=new Intl.RelativeTimeFormat(locale.length>0?locale:undefined,{numeric:format.numeric,style:format.showLabel?format.style:\"narrow\"});const DIVISIONS=[{amount:60,name:\"seconds\"},{amount:60,name:\"minutes\"},{amount:24,name:\"hours\"},{amount:7,name:\"days\"},{amount:4.34524,name:\"weeks\"},{amount:12,name:\"months\"},{amount:Number.POSITIVE_INFINITY,name:\"years\"}];function formatTimeAgo(date){let duration=(date-now)/1e3;const autoUnit=props.unit==\"auto\";let unit=\"\";for(let i=0;i<DIVISIONS.length;i++){const division=DIVISIONS[i];if(autoUnit?Math.abs(duration)<division.amount:division.name==props.unit){unit=division.name;break;}duration/=division.amount;}let result=formatter.format(Math.round(duration),unit).replace(/^in\\s+/,\"\").replace(/\\s+ago$/,\"\");if(!format.showLabel){result=result.replace(/[a-zA-Z]/g,\"\");}if(!format.commas){result=result.replace(/,/g,\"\");}return result;}setRelativeTitle(formatTimeAgo(compareDate));},[date,format,props.unit,format.commas]);return /*#__PURE__*/_jsx(\"p\",{style:{color:props.fontColor,userSelect:props.textSelect?\"auto\":\"none\",whiteSpace:\"pre\",margin:0,...props.font},children:date?/*#__PURE__*/_jsxs(_Fragment,{children:[isPast?transform.pastPrefix:transform.futurePrefix,/*#__PURE__*/_jsx(\"span\",{style:{textTransform:textCase},children:relativeTitle}),isPast?transform.pastSuffix:transform.futureSuffix]}):\"Set a date value.\"});}RelativeDateLabel.displayName=\"Relative Date Label\";addPropertyControls(RelativeDateLabel,{date:{type:ControlType.Date},unit:{type:ControlType.Enum,defaultValue:\"auto\",options:[\"auto\",\"years\",\"months\",\"weeks\",\"days\",\"hours\",\"minutes\",\"seconds\"],optionTitles:[\"Auto\",\"Years\",\"Months\",\"Weeks\",\"Days\",\"Hours\",\"Minutes\",\"Seconds\"]},locale:{type:ControlType.String,placeholder:`Auto (${typeof navigator!==\"undefined\"?navigator.language:\"\"})`},format:{type:ControlType.Object,buttonTitle:\"Options\",controls:{numeric:{type:ControlType.Enum,defaultValue:\"always\",options:[\"always\",\"auto\"],optionTitles:[\"Always\",\"Auto\"],displaySegmentedControl:true,description:\"When set to *Auto*, some values are converted:\\n\\n1 day ago → yesterday\\nin 0 days → today\\n in 1 day → tomorrow\"},showLabel:{type:ControlType.Boolean,defaultValue:true},style:{type:ControlType.Enum,defaultValue:\"long\",options:[\"long\",\"short\",\"narrow\"],optionTitles:[\"Long\",\"Short\",\"Narrow\"],displaySegmentedControl:true,segmentedControlDirection:\"vertical\",hidden:props=>!props.showLabel},commas:{type:ControlType.Boolean,defaultValue:true}}},transform:{type:ControlType.Object,buttonTitle:\"Prefix & Suffix\",controls:{pastPrefix:{type:ControlType.String,defaultValue:\"\"},pastSuffix:{type:ControlType.String,defaultValue:\" ago\"},futurePrefix:{type:ControlType.String,defaultValue:\"\"},futureSuffix:{type:ControlType.String,defaultValue:\" from now\"}}},fontColor:{type:ControlType.Color,defaultValue:\"#000\"},font:{type:\"font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:16,lineHeight:1}},textCase:{type:ControlType.Enum,defaultValue:\"lowercase\",options:[\"capitalize\",\"uppercase\",\"lowercase\"],optionTitles:[\"Capitalized\",\"UPPERCASE\",\"lowercase\"]},textSelect:{type:ControlType.Boolean,defaultValue:true}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"RelativeDateLabel\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\",\"framerSupportedLayoutWidth\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./RelativeDateLabel.map"],"mappings":"8MAGG,SAAwB,EAAkB,EAAM,CAAC,GAAK,CAAC,OAAK,SAAO,SAAO,WAAS,aAAW,EAAW,CAAC,EAAO,GAAWA,EAAS,GAAK,CAAM,CAAC,EAAc,GAAkBA,EAAS,GAAG,CAC6yB,OAD5yB,MAAc,CAAC,GAAG,CAAC,EAAM,OAAQ,IAAM,EAAY,IAAI,KAAK,EAAK,CAAO,EAAI,IAAI,KAAK,EAAI,SAAS,EAAE,EAAE,EAAE,EAAE,CAC1S,EAAU,EAAI,EAAY,CAAC,IAAM,EAAU,IAAI,KAAK,mBAAmB,EAAO,OAAO,EAAE,EAAO,IAAA,GAAU,CAAC,QAAQ,EAAO,QAAQ,MAAM,EAAO,UAAU,EAAO,MAAM,SAAS,CAAC,CAAO,EAAU,CAAC,CAAC,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,OAAO,IAAyB,KAAK,QAAQ,CAAC,CAAC,SAAS,EAAc,EAAK,CAAC,IAAI,GAAUC,EAAK,GAAK,IAAU,EAAS,EAAM,MAAM,OAAW,EAAK,GAAG,IAAI,IAAI,EAAE,EAAE,EAAE,EAAU,OAAO,IAAI,CAAC,IAAM,EAAS,EAAU,GAAG,GAAG,EAAS,KAAK,IAAI,EAAS,CAA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