"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProperty = exports.toArray = void 0;
exports.isString = isString;
exports.isNumber = isNumber;
exports.isBoolean = isBoolean;
exports.isNestableElement = isNestableElement;
exports.isAutoLoginFlow = isAutoLoginFlow;
exports.isNullOrUndefined = isNullOrUndefined;
exports.isDefined = isDefined;
exports.getIntegerFromString = getIntegerFromString;
exports.distinct = distinct;
function isString(value) {
    return (value && value instanceof String) || typeof value === 'string';
}
function isNumber(value) {
    return (value && value instanceof Number) || typeof value === 'number';
}
function isBoolean(value) {
    return (value && value instanceof Boolean) || typeof value === 'boolean';
}
function isNestableElement(value) {
    return (value && value instanceof Object) || value instanceof Array;
}
function isAutoLoginFlow(flow) {
    return flow?.flow_type === 'login';
}
const toArray = (args) => Array.isArray(args) ? args : args && [].concat(args, []);
exports.toArray = toArray;
const getProperty = (object, path, defaultValue = undefined) => {
    if (isNullOrUndefined(object)) {
        return defaultValue;
    }
    const pathArray = (0, exports.toArray)(path);
    let result = object;
    for (const key of pathArray) {
        if (isNullOrUndefined(result)) {
            return defaultValue;
        }
        result = result[key];
    }
    return result === undefined ? defaultValue : result;
};
exports.getProperty = getProperty;
function isNullOrUndefined(arg) {
    return arg === null || arg === undefined;
}
function isDefined(value) {
    return value !== undefined;
}
function getIntegerFromString(value) {
    if (isNullOrUndefined(value)) {
        return null;
    }
    if (isString(value) && value.length === 0) {
        return null;
    }
    const parsedValue = isNumber(value) ? value : Number(value);
    if (!Number.isInteger(parsedValue)) {
        return null;
    }
    return parsedValue;
}
function distinct(array) {
    return [...new Set(array.filter((item) => item !== undefined))];
}
