import { __assign } from "tslib";
var defaultGetItemKey = function (item) {
    return item.key || item.label;
};
var defaultGetItemLeadContent = function (item) { return item.leadContent; };
var defaultGetItemDisabled = function (item) { return item.isDisabled; };
var defaultGetItemLabel = function (item) {
    return item.label;
};
var defaultGetItemOnClick = function (item) {
    return item.onClick;
};
var defaultGetItemAttributes = function (item) { return item.attributes; };
var defaultGetItemGroupId = function (item) {
    return item.groupId;
};
export function withDefaultGetters(props) {
    return __assign(__assign({}, props), { getItemKey: props.getItemKey || defaultGetItemKey, getItemLabel: props.getItemLabel ||
            defaultGetItemLabel, getItemLeadContent: props.getItemLeadContent ||
            defaultGetItemLeadContent, getItemDisabled: props.getItemDisabled ||
            defaultGetItemDisabled, getItemOnClick: props.getItemOnClick ||
            defaultGetItemOnClick, getItemGroupId: props.getItemGroupId ||
            defaultGetItemGroupId, getItemAttributes: props.getItemAttributes ||
            defaultGetItemAttributes });
}
export var DEFAULT_RECT_ELEMENT = {
    width: 0,
    height: 0,
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
    x: 0,
    y: 0,
    toJSON: function () {
        /* */
    }
};
export var calculateRectElement = function (el) {
    if (el) {
        var _a = el.getBoundingClientRect(), width = _a.width, height = _a.height, top_1 = _a.top, left = _a.left, bottom = _a.bottom, right = _a.right, x = _a.x, y = _a.y;
        return {
            width: width,
            height: height,
            top: top_1 + window.scrollY,
            left: left,
            bottom: bottom + window.scrollY,
            right: right,
            x: x,
            y: y,
            toJSON: function () {
                /* */
            }
        };
    }
    return DEFAULT_RECT_ELEMENT;
};
export var getDirection = function (_a) {
    var anchorRect = _a.anchorRect, direction = _a.direction, dropdownRect = _a.dropdownRect, offset = _a.offset;
    var viewerSize = {
        width: document.documentElement.clientWidth,
        height: document.documentElement.clientHeight
    };
    var isTop = anchorRect.y - dropdownRect.height - offset >= 0;
    var isBottom = anchorRect.y + anchorRect.height + dropdownRect.height + offset <=
        viewerSize.height;
    var isRight = anchorRect.right + anchorRect.width + dropdownRect.width + offset <=
        viewerSize.width;
    var isLeft = anchorRect.x - dropdownRect.width - offset >= 0;
    switch (direction) {
        case "left":
            if (isLeft) {
                return "left";
            }
            return "right";
        case "right":
            if (isRight) {
                return "right";
            }
            return "left";
        case "top":
            if (isTop) {
                return "top";
            }
            return "bottom";
        case "topRight":
            if (isTop) {
                return "topRight";
            }
            return "bottomRight";
        case "topLeft":
            if (isTop) {
                return "topLeft";
            }
            return "bottomLeft";
        case "bottom":
            if (isBottom) {
                return "bottom";
            }
            return "top";
        case "bottomLeft":
            if (isBottom) {
                return "bottomLeft";
            }
            return "topLeft";
        case "bottomRight":
            if (isBottom) {
                return "bottomRight";
            }
            return "topRight";
        default:
            return direction;
    }
};
