import { getIdentiferName } from "./util.js";
export function isComputedNode(node) {
    // Check if it's a NodePath
    if ("isCallExpression" in node &&
        typeof node.isCallExpression === "function") {
        // It's a NodePath
        if (!node.isCallExpression()) {
            return false;
        }
        const callee = node.get("callee");
        return callee.isIdentifier() && callee.node.name === "computed";
    }
    else {
        // It's a direct Node
        if (node.type !== "CallExpression") {
            return false;
        }
        const callee = node.callee;
        return callee.type === "Identifier" && callee.name === "computed";
    }
}
export function isSbTemplateNode(node) {
    if (isComputedNode(node)) {
        const argument = node.get("arguments.0");
        if (argument.isArrowFunctionExpression()) {
            return argument.get("body").isTemplateLiteral();
        }
        if (argument.isFunctionExpression() &&
            argument.node.body.body.length === 1) {
            const returnStatement = argument.get("body.body.0");
            const expression = returnStatement.get("argument");
            return expression?.isTemplateLiteral();
        }
        return false;
    }
    return node.isTemplateLiteral();
}
export function isEventFlowNode(node) {
    if (!node.isCallExpression()) {
        return false;
    }
    const callee = node.get("callee");
    return (callee.isMemberExpression() &&
        getIdentiferName(callee.get("object").node) === "EventFlow");
}
export function isDimNode(node) {
    if ("isCallExpression" in node &&
        typeof node.isCallExpression === "function") {
        if (!node.isCallExpression()) {
            return false;
        }
        const callee = node.get("callee");
        return (callee.isMemberExpression() &&
            getIdentiferName(callee.get("object").node) === "Dim");
    }
    else {
        if (node.type !== "CallExpression") {
            return false;
        }
        const callee = node.callee;
        return (callee.type === "MemberExpression" &&
            getIdentiferName(callee.object) === "Dim");
    }
}
export function isFunctionNode(node) {
    return node.isArrowFunctionExpression() || node.isFunctionExpression();
}
export function isSBBindingTemplateNode(node) {
    if (!node.isTaggedTemplateExpression()) {
        return false;
    }
    const tag = node.get("tag");
    return tag.isIdentifier() && getIdentiferName(tag.node) === "SB";
}
//# sourceMappingURL=jsx-utils.js.map