{"version":3,"file":"use-matches.cjs","names":["useMantineTheme"],"sources":["../../../../src/core/MantineProvider/use-matches/use-matches.ts"],"sourcesContent":["import { useMediaQuery, UseMediaQueryOptions } from '@mantine/hooks';\nimport { useMantineTheme } from '../MantineThemeProvider';\nimport { MantineBreakpoint } from '../theme.types';\n\ntype UseMatchesInput<T> = Partial<Record<MantineBreakpoint, T>>;\n\nconst BREAKPOINTS = ['xs', 'sm', 'md', 'lg', 'xl'];\n\nfunction getFirstMatchingValue<T>(\n  value: UseMatchesInput<T>,\n  biggestMatch: MantineBreakpoint | undefined\n): T {\n  if (!biggestMatch) {\n    return value.base!;\n  }\n\n  let index = BREAKPOINTS.indexOf(biggestMatch);\n\n  while (index >= 0) {\n    if (BREAKPOINTS[index] in value) {\n      return value[BREAKPOINTS[index]]!;\n    }\n    index -= 1;\n  }\n\n  return value.base!;\n}\n\nfunction getFirstMatchingBreakpoint(matches: (boolean | undefined)[]) {\n  return matches.findLastIndex((v) => v);\n}\n\nexport function useMatches<T>(payload: UseMatchesInput<T>, options?: UseMediaQueryOptions) {\n  const theme = useMantineTheme();\n  const xsMatches = useMediaQuery(`(min-width: ${theme.breakpoints.xs})`, false, options);\n  const smMatches = useMediaQuery(`(min-width: ${theme.breakpoints.sm})`, false, options);\n  const mdMatches = useMediaQuery(`(min-width: ${theme.breakpoints.md})`, false, options);\n  const lgMatches = useMediaQuery(`(min-width: ${theme.breakpoints.lg})`, false, options);\n  const xlMatches = useMediaQuery(`(min-width: ${theme.breakpoints.xl})`, false, options);\n\n  const breakpoints = [xsMatches, smMatches, mdMatches, lgMatches, xlMatches];\n  const firstMatchingBreakpointIndex = getFirstMatchingBreakpoint(breakpoints);\n  return getFirstMatchingValue(payload, BREAKPOINTS[firstMatchingBreakpointIndex]);\n}\n"],"mappings":";;;;;AAMA,MAAM,cAAc;CAAC;CAAM;CAAM;CAAM;CAAM;AAAI;AAEjD,SAAS,sBACP,OACA,cACG;CACH,IAAI,CAAC,cACH,OAAO,MAAM;CAGf,IAAI,QAAQ,YAAY,QAAQ,YAAY;CAE5C,OAAO,SAAS,GAAG;EACjB,IAAI,YAAY,UAAU,OACxB,OAAO,MAAM,YAAY;EAE3B,SAAS;CACX;CAEA,OAAO,MAAM;AACf;AAEA,SAAS,2BAA2B,SAAkC;CACpE,OAAO,QAAQ,eAAe,MAAM,CAAC;AACvC;AAEA,SAAgB,WAAc,SAA6B,SAAgC;CACzF,MAAM,QAAQA,6BAAAA,gBAAgB;CAS9B,OAAO,sBAAsB,SAAS,YADD,2BAA2B;oCAPhC,eAAe,MAAM,YAAY,GAAG,IAAI,OAAO,OAMlD;oCALG,eAAe,MAAM,YAAY,GAAG,IAAI,OAAO,OAKvC;oCAJR,eAAe,MAAM,YAAY,GAAG,IAAI,OAAO,OAI5B;oCAHnB,eAAe,MAAM,YAAY,GAAG,IAAI,OAAO,OAGjB;oCAF9B,eAAe,MAAM,YAAY,GAAG,IAAI,OAAO,OAEN;CACC,CACG,EAAE;AACjF"}