"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDeviceValue = useDeviceValue;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const constants_1 = require("../../constants.js");
const models_1 = require("../../models/index.js");
const utils_1 = require("../../utils/index.js");
const windowWidthContext_1 = require("../context/windowWidthContext/index.js");
const getDeviceBreakpoints = (inclusive) => {
    const shift = inclusive ? 0 : -1;
    return [constants_1.BREAKPOINTS.md + shift, constants_1.BREAKPOINTS.sm + shift];
};
function useDeviceValue(value, inclusive) {
    const windowWidth = (0, windowWidthContext_1.useWindowWidth)();
    const [tablet, mobile] = React.useMemo(() => getDeviceBreakpoints(inclusive), [inclusive]);
    const isMobile = windowWidth <= mobile;
    const isTablet = windowWidth <= tablet;
    return React.useMemo(() => {
        if (!(0, utils_1.isDeviceValue)(value)) {
            return value;
        }
        switch (true) {
            case isMobile:
                return value[models_1.Device.Mobile];
            case isTablet:
                return value[models_1.Device.Tablet] ?? value[models_1.Device.Mobile];
            default:
                return value[models_1.Device.Desktop];
        }
    }, [isMobile, isTablet, value]);
}
//# sourceMappingURL=useDeviceValue.js.map
