{
  "version": 3,
  "sources": ["../../../../../src/functions/reference/indirect/indirect.ts"],
  "sourcesContent": [
    "import {\n  FormulaError,\n  type FunctionDefinition,\n  type FunctionEvaluationResult\n} from \"../../../core/types.mjs\";\nimport { parseFormula } from \"../../../parser/parser.mjs\";\n\n/**\n * INDIRECT function - Returns the reference specified by a text string\n * \n * Usage: INDIRECT(ref_text, [a1])\n * \n * ref_text: A reference to a cell that contains an A1-style reference, an R1C1-style reference,\n *           a name defined as a reference, or a reference to a cell as a text string\n * a1: (optional) A logical value that specifies what type of reference is in ref_text\n *     TRUE or omitted = A1-style reference\n *     FALSE = R1C1-style reference\n * \n * Examples:\n * - INDIRECT(\"A1\") returns the value in cell A1\n * - INDIRECT(\"B\" & ROW()) returns the value in column B of the current row\n * - INDIRECT(\"Sheet2!A1\") returns the value in cell A1 of Sheet2\n * \n * Note: This function is volatile - it recalculates whenever the worksheet recalculates\n */\nexport const INDIRECT: FunctionDefinition = {\n  name: \"INDIRECT\",\n  evaluate: function (node, context): FunctionEvaluationResult {\n    if (node.args.length === 0 || node.args.length > 2) {\n      return {\n        type: \"error\",\n        err: FormulaError.VALUE,\n        message: \"INDIRECT function requires 1 or 2 arguments\",\n        errAddress: context.dependencyNode,\n      };\n    }\n\n    // Evaluate ref_text\n    const refTextResult = this.evaluateNode(node.args[0]!, context);\n    if (\n      refTextResult.type === \"error\" ||\n      refTextResult.type === \"awaiting-evaluation\"\n    ) {\n      return refTextResult;\n    }\n\n    if (refTextResult.type !== \"value\" || refTextResult.result.type !== \"string\") {\n      return {\n        type: \"error\",\n        err: FormulaError.VALUE,\n        message: \"INDIRECT function ref_text must be a string\",\n        errAddress: context.dependencyNode,\n      };\n    }\n\n    const refText = refTextResult.result.value.trim();\n\n    // Optional a1 parameter\n    let a1Style = true;\n    if (node.args.length === 2) {\n      const a1Result = this.evaluateNode(node.args[1]!, context);\n      if (\n        a1Result.type === \"error\" ||\n        a1Result.type === \"awaiting-evaluation\"\n      ) {\n        return a1Result;\n      }\n\n      if (a1Result.type === \"value\" && a1Result.result.type === \"boolean\") {\n        a1Style = a1Result.result.value;\n      }\n    }\n\n    // R1C1 style not yet supported\n    if (!a1Style) {\n      return {\n        type: \"error\",\n        err: FormulaError.VALUE,\n        message: \"INDIRECT function does not yet support R1C1 style references\",\n        errAddress: context.dependencyNode,\n      };\n    }\n\n    // Parse the reference string as a formula (without the = sign)\n    try {\n      const ast = parseFormula(refText);\n      \n      // The parsed result should be a reference, range, or named expression\n      if (ast.type !== \"reference\" && ast.type !== \"range\" && ast.type !== \"named-expression\") {\n        return {\n          type: \"error\",\n          err: FormulaError.REF,\n          message: `INDIRECT requires a valid cell or range reference, got: ${refText}`,\n          errAddress: context.dependencyNode,\n        };\n      }\n      \n      // Evaluate the parsed reference\n      const result = this.evaluateNode(ast, context);\n      return result;\n      \n    } catch (error) {\n      return {\n        type: \"error\",\n        err: FormulaError.REF,\n        message: `INDIRECT could not parse reference: ${refText}`,\n        errAddress: context.dependencyNode,\n      };\n    }\n  },\n};\n"
  ],
  "mappings": ";AAAA;AAAA;AAAA;AAKA;AAoBO,IAAM,WAA+B;AAAA,EAC1C,MAAM;AAAA,EACN,UAAU,QAAS,CAAC,MAAM,SAAmC;AAAA,IAC3D,IAAI,KAAK,KAAK,WAAW,KAAK,KAAK,KAAK,SAAS,GAAG;AAAA,MAClD,OAAO;AAAA,QACL,MAAM;AAAA,QACN,KAAK,aAAa;AAAA,QAClB,SAAS;AAAA,QACT,YAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAAA,IAGA,MAAM,gBAAgB,KAAK,aAAa,KAAK,KAAK,IAAK,OAAO;AAAA,IAC9D,IACE,cAAc,SAAS,WACvB,cAAc,SAAS,uBACvB;AAAA,MACA,OAAO;AAAA,IACT;AAAA,IAEA,IAAI,cAAc,SAAS,WAAW,cAAc,OAAO,SAAS,UAAU;AAAA,MAC5E,OAAO;AAAA,QACL,MAAM;AAAA,QACN,KAAK,aAAa;AAAA,QAClB,SAAS;AAAA,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