{"version":3,"file":"timeFormat.mjs","sources":["../../../admin/src/utils/timeFormat.ts"],"sourcesContent":["type TimeChangeHandler = (params: {\n  target: { name: string; value: string | undefined; type: string };\n}) => void;\n\ntype TimeChangeParams = {\n  value?: string;\n  onChange: TimeChangeHandler;\n  name: string;\n  type: string;\n};\n\n// The backend sends a value which has the following format: '00:45:00.000'\n// but the time picker only supports hours & minutes so we need to mutate the value\nconst removeSeconds = (time: string): string => {\n  const [hours, minutes] = time.split(':');\n  return `${hours}:${minutes}`;\n};\n\n// we need to send back the value with the same '00:45:00.000' format\nconst addSecondsAndMilliseconds = (time: string): string => {\n  return time.split(':').length === 2 ? `${time}:00.000` : time;\n};\n\nconst formatTimeForInput = (value?: string): string | undefined => {\n  if (!value) return;\n  return value.split(':').length > 2 ? removeSeconds(value) : value;\n};\n\nconst formatTimeForOutput = (value?: string): string | undefined => {\n  if (!value) return undefined;\n  return addSecondsAndMilliseconds(value);\n};\n\nexport const handleTimeChange = ({ value }: TimeChangeParams): string | undefined => {\n  const formattedInputTime = formatTimeForInput(value);\n\n  return formattedInputTime;\n};\n\nexport const handleTimeChangeEvent = (\n  onChange: TimeChangeHandler,\n  name: string,\n  type: string,\n  time?: string\n): void => {\n  const formattedOutputTime = formatTimeForOutput(time);\n\n  onChange({\n    target: {\n      name,\n      value: formattedOutputTime,\n      type,\n    },\n  });\n};\n"],"names":["removeSeconds","time","hours","minutes","split","addSecondsAndMilliseconds","length","formatTimeForInput","value","formatTimeForOutput","undefined","handleTimeChange","formattedInputTime","handleTimeChangeEvent","onChange","name","type","formattedOutputTime","target"],"mappings":"AAWA;AACA;AACA,MAAMA,gBAAgB,CAACC,IAAAA,GAAAA;AACrB,IAAA,MAAM,CAACC,KAAAA,EAAOC,OAAAA,CAAQ,GAAGF,IAAAA,CAAKG,KAAK,CAAC,GAAA,CAAA;AACpC,IAAA,OAAO,CAAA,EAAGF,KAAAA,CAAM,CAAC,EAAEC,OAAAA,CAAAA,CAAS;AAC9B,CAAA;A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