{"version":3,"sources":["../src/getResponsiveValue.ts"],"names":[],"mappings":";;;;;AAMO,SAAS,mBACf,iBACA,mBACgB;AAChB,MACC,OAAO,oBAAoB,YAC1B,mBACA,OAAO,oBAAoB,YAC3B,CAAC,OAAO,KAAK,eAAe,EAAE;AAAA,IAC7B,CAAC,kBAAkB,YAAY;AAC9B,UAAI,YAAY,SAAS,OAAc;AAAG,eAAO;AACjD,aAAO;AAAA,IACR;AAAA,IACA;AAAA,EACD;AAED,WAAO;AAER,MAAI;AACJ,WAAS,cAAc,aAAa;AACnC,UAAM,qBAAqB,YAAY,QAAQ,UAAU;AACzD,UAAM,4BACL,YAAY,QAAQ,iBAAiB;AACtC,QAAI,sBAAsB,2BAA2B;AACpD,YAAO,gBAAwC,UAAU,KAAK;AAAA,IAC/D;AAAA,EACD;AAEA,SAAO;AACR","sourcesContent":["import { Breakpoint, breakpoints } from \"./useBreakpoint\";\n\ntype ResponsiveObject<T> = { [key in Breakpoint]?: T };\n\nexport type ResponsiveValue<T> = T | ResponsiveObject<T>;\n\nexport function getResponsiveValue<T>(\n\tresponsiveValue: ResponsiveValue<T>,\n\tcurrentBreakpoint: Breakpoint\n): T | undefined {\n\tif (\n\t\ttypeof responsiveValue !== \"object\" ||\n\t\t(responsiveValue &&\n\t\t\ttypeof responsiveValue === \"object\" &&\n\t\t\t!Object.keys(responsiveValue).reduce(\n\t\t\t\t(hasBreakpointKey, current) => {\n\t\t\t\t\tif (breakpoints.includes(current as any)) return true;\n\t\t\t\t\treturn hasBreakpointKey;\n\t\t\t\t},\n\t\t\t\tfalse\n\t\t\t))\n\t)\n\t\treturn responsiveValue as T;\n\n\tlet res: T | undefined;\n\tfor (let breakpoint of breakpoints) {\n\t\tconst indexInBreakpoints = breakpoints.indexOf(breakpoint);\n\t\tconst indexInBreakpointsCurrent =\n\t\t\tbreakpoints.indexOf(currentBreakpoint);\n\t\tif (indexInBreakpoints <= indexInBreakpointsCurrent) {\n\t\t\tres = (responsiveValue as ResponsiveObject<T>)[breakpoint] || res;\n\t\t}\n\t}\n\n\treturn res;\n}\n"]}