{"version":3,"file":"get-business-hours-mod.cjs","names":[],"sources":["../../../src/utils/get-business-hours-mod/get-business-hours-mod.ts"],"sourcesContent":["import { DayOfWeek } from '../../types';\n\n/** Business hours range in `HH:mm:ss` format */\nexport type BusinessHoursRange = [string, string];\n\n/** Per-day business hours map keyed by day of the week (0 – Sunday, 6 – Saturday). `null` marks a day as fully outside business hours. */\nexport type BusinessHoursPerDay = Partial<Record<DayOfWeek, BusinessHoursRange | null>>;\n\n/** Business hours value – tuple applies to every day, record configures business hours per day */\nexport type BusinessHoursValue = BusinessHoursRange | BusinessHoursPerDay;\n\nexport interface GetBusinessHoursModInput {\n  time: string;\n  businessHours?: BusinessHoursValue;\n  highlightBusinessHours?: boolean;\n  dayOfWeek?: DayOfWeek;\n}\n\nexport interface BusinessHoursMod {\n  'business-hours': boolean;\n  'non-business-hours': boolean;\n}\n\nfunction isBusinessHoursRange(value: BusinessHoursValue): value is BusinessHoursRange {\n  return (\n    Array.isArray(value) &&\n    value.length === 2 &&\n    typeof value[0] === 'string' &&\n    typeof value[1] === 'string'\n  );\n}\n\n/**\n * Determines if a given time is within business hours and returns modifier object\n * @param time - Time string in HH:mm:ss format\n * @param businessHours - Tuple of [start, end] times in HH:mm:ss format, or per-day record keyed by day of the week\n * @param highlightBusinessHours - Whether to highlight business hours\n * @param dayOfWeek - Day of the week (0 – Sunday, 6 – Saturday), used to resolve per-day business hours\n * @returns Modifier object for styling business/non-business hours\n */\nexport function getBusinessHoursMod({\n  time,\n  businessHours,\n  highlightBusinessHours,\n  dayOfWeek,\n}: GetBusinessHoursModInput): BusinessHoursMod {\n  if (!highlightBusinessHours || !businessHours) {\n    return {\n      'business-hours': false,\n      'non-business-hours': false,\n    };\n  }\n\n  let range: [string, string] | null;\n  if (isBusinessHoursRange(businessHours)) {\n    range = businessHours;\n  } else {\n    if (dayOfWeek === undefined) {\n      return {\n        'business-hours': false,\n        'non-business-hours': false,\n      };\n    }\n    range = businessHours[dayOfWeek] ?? null;\n  }\n\n  if (!range) {\n    return {\n      'business-hours': false,\n      'non-business-hours': true,\n    };\n  }\n\n  const [start, end] = range;\n  const isInBusinessHours = time >= start && time < end;\n\n  return {\n    'business-hours': isInBusinessHours,\n    'non-business-hours': !isInBusinessHours,\n  };\n}\n"],"mappings":";;AAuBA,SAAS,qBAAqB,OAAwD;CACpF,OACE,MAAM,QAAQ,KAAK,KACnB,MAAM,WAAW,KACjB,OAAO,MAAM,OAAO,YACpB,OAAO,MAAM,OAAO;AAExB;;;;;;;;;AAUA,SAAgB,oBAAoB,EAClC,MACA,eACA,wBACA,aAC6C;CAC7C,IAAI,CAAC,0BAA0B,CAAC,eAC9B,OAAO;EACL,kBAAkB;EAClB,sBAAsB;CACxB;CAGF,IAAI;CACJ,IAAI,qBAAqB,aAAa,GACpC,QAAQ;MACH;EACL,IAAI,cAAc,KAAA,GAChB,OAAO;GACL,kBAAkB;GAClB,sBAAsB;EACxB;EAEF,QAAQ,cAAc,cAAc;CACtC;CAEA,IAAI,CAAC,OACH,OAAO;EACL,kBAAkB;EAClB,sBAAsB;CACxB;CAGF,MAAM,CAAC,OAAO,OAAO;CACrB,MAAM,oBAAoB,QAAQ,SAAS,OAAO;CAElD,OAAO;EACL,kBAAkB;EAClB,sBAAsB,CAAC;CACzB;AACF"}