{"version":3,"file":"useDateStringColumnDef.mjs","names":["DateTime","IANAZone","useMemo","getDateFromString","GridExcelStyleEnums","useAuthedUser","useGetLocalizedDateString","useGetLocalizedDateTimeString","useDateStringColumnDef","t0","t1","t2","$","_c","includeTime","undefined","timeZone","includeTimeZoneOffset","user","tz","additionalProperties","t3","isValidZone","validTimeZone","zone","getLocalizedDateTimeString","getLocalizedDateString","t4","valueFormatter","params","value","cellClass","DateTimeShortWithSeconds","DateShort","filter","filterParams","comparator","filterLocalDateAtMidnight","cellValue","cellDate","filterDateTimeMidnight","fromJSDate","setZone","keepLocalTime","cellDateTimeMidnight","set","hour","minute","second","millisecond","buttons","closeOnApply","suppressAndOrCondition","filterOptions","columnDef"],"sources":["../../../src/udp/utilities/useDateStringColumnDef.js"],"sourcesContent":["import { DateTime, IANAZone } from 'luxon';\nimport { useMemo } from 'react';\nimport { getDateFromString } from '../../UI/widgets/utils/dateUtils';\nimport { GridExcelStyleEnums } from '../../enums/unitySystemEnums';\nimport { useAuthedUser } from '../../utilities/auth/useAuthedUser'\nimport { useGetLocalizedDateString, useGetLocalizedDateTimeString } from './dateLocalizationHooks';\n\n\nexport const useDateStringColumnDef = (\n  includeTime = false,\n  timeZone = null,\n  includeTimeZoneOffset = false,\n) => {\n  const user = useAuthedUser();\n\n  const zone = useMemo(() => {\n    const tz = timeZone ?? user?.additionalProperties?.timeZone ?? 'local';\n    const validTimeZone =\n      tz !== 'local' &&\n      (tz === user?.additionalProperties?.timeZone || IANAZone.isValidZone(tz))\n        ? tz\n        : 'local'; // IANAZone.isValidZone is very slow, skip it if known valid timeZone passed\n    return validTimeZone;\n  }, [timeZone, user]);\n\n  const getLocalizedDateTimeString = useGetLocalizedDateTimeString(zone, includeTimeZoneOffset);\n  const getLocalizedDateString = useGetLocalizedDateString(zone);\n\n  const columnDef = useMemo(() => {\n    return !user\n      ? {}\n      : ({\n          valueFormatter: (params) => {\n            if (!params) {\n              return '';\n            }\n            if (includeTime) {\n              return getLocalizedDateTimeString(params.value);\n            } else {\n              return getLocalizedDateString(params.value);\n            }\n          },\n          cellClass: includeTime\n            ? GridExcelStyleEnums.DateTimeShortWithSeconds\n            : GridExcelStyleEnums.DateShort,\n          filter: 'agDateColumnFilter',\n          filterParams: {\n            comparator: function (filterLocalDateAtMidnight, cellValue) {\n              const cellDate = getDateFromString(cellValue);\n              if (!cellDate) {\n                return null;\n              }\n\n              // Assume date picker is in the same time zone that we're displaying dates in so that the results make sense to the user\n              const filterDateTimeMidnight = DateTime.fromJSDate(filterLocalDateAtMidnight).setZone(\n                zone,\n                { keepLocalTime: true },\n              );\n              const cellDateTimeMidnight = DateTime.fromJSDate(cellDate, { zone: zone }).set({\n                hour: 0,\n                minute: 0,\n                second: 0,\n                millisecond: 0,\n              });\n\n              if (cellDateTimeMidnight < filterDateTimeMidnight) {\n                return -1;\n              } else if (cellDateTimeMidnight > filterDateTimeMidnight) {\n                return 1;\n              } else {\n                return 0;\n              }\n            },\n            buttons: ['apply', 'reset'],\n            closeOnApply: true,\n            suppressAndOrCondition: true,\n            filterOptions: ['equals', 'lessThan', 'greaterThan', 'inRange'],\n          },\n        });\n  }, [includeTime, getLocalizedDateString, getLocalizedDateTimeString, user, zone]);\n\n  return columnDef;\n};\n"],"mappings":";;;;;;;;AAQA,MAAaQ,0BAAyBC,IAAAC,IAAAC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CACpC,MAAAC,cAAAL,OAAAM,KAAAA,IAAA,QAAAN;CACA,MAAAO,WAAAN,OAAAK,KAAAA,IAAA,OAAAL;CACA,MAAAO,wBAAAN,OAAAI,KAAAA,IAAA,QAAAJ;CAEA,MAAAO,OAAab,eAAe;CAG1B,MAAAc,KAAWH,YAAYE,MAAIE,sBAAgCJ,YAAhD;CAA4D,IAAAK;AAAA,KAAAT,EAAA,OAAAO,MAAAP,EAAA,OAAAM,MAAAE,sBAAAJ,UAAA;AAErEK,OAAAF,OAAO,YACNA,OAAOD,MAAIE,sBAAgCJ,YAAIf,SA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