{
  "version": 3,
  "sources": ["../../../../../src/functions/text/mid/mid.ts"],
  "sourcesContent": [
    "import {\n  FormulaError,\n  type FunctionDefinition,\n  type FunctionEvaluationResult,\n} from \"../../../core/types.mjs\";\nimport { createMidSpilledResult, midOperation } from \"../text-helpers.mjs\";\n\n/**\n * MID function - Returns characters from the middle of a text string\n *\n * Usage: MID(text, start_num, num_chars)\n *\n * text: The text string to extract characters from.\n * start_num: The position of the first character to extract (1-based).\n * num_chars: The number of characters to extract.\n *\n * Example: MID(\"Hello, World!\", 8, 5) returns \"World\"\n *\n * Note:\n * - If start_num is less than 1, the function returns an error.\n * - If num_chars is less than 0, the function returns an error.\n * - If start_num is greater than the length of text, the function returns an empty string.\n * - Supports dynamic arrays (spilled values) for all arguments\n * - Strict type checking: text must be string, start_num and num_chars must be numbers\n */\nexport const MID: FunctionDefinition = {\n  name: \"MID\",\n  evaluate: function (node, context): FunctionEvaluationResult {\n    if (node.args.length !== 3) {\n      return {\n        type: \"error\",\n        err: FormulaError.VALUE,\n        message: \"MID function takes exactly 3 arguments\",\n        errAddress: context.dependencyNode,\n      };\n    }\n\n    // Evaluate the text argument\n    const textResult = this.evaluateNode(node.args[0]!, context);\n    if (\n      textResult.type === \"error\" ||\n      textResult.type === \"awaiting-evaluation\"\n    ) {\n      return textResult;\n    }\n\n    // Evaluate the start_num argument\n    const startNumResult = this.evaluateNode(node.args[1]!, context);\n    if (\n      startNumResult.type === \"error\" ||\n      startNumResult.type === \"awaiting-evaluation\"\n    ) {\n      return startNumResult;\n    }\n\n    // Evaluate the num_chars argument\n    const numCharsResult = this.evaluateNode(node.args[2]!, context);\n    if (\n      numCharsResult.type === \"error\" ||\n      numCharsResult.type === \"awaiting-evaluation\"\n    ) {\n      return numCharsResult;\n    }\n\n    // Handle spilled-values inputs\n    if (\n      textResult.type === \"spilled-values\" ||\n      startNumResult.type === \"spilled-values\" ||\n      numCharsResult.type === \"spilled-values\"\n    ) {\n      return createMidSpilledResult.call(this, {\n        textResult,\n        startNumResult,\n        numCharsResult,\n        context,\n      });\n    }\n\n    // Strict type checking - no coercion\n    if (textResult.result.type !== \"string\") {\n      return {\n        type: \"error\",\n        err: FormulaError.VALUE,\n        message: \"Text argument must be a string\",\n        errAddress: context.dependencyNode,\n      };\n    }\n\n    if (startNumResult.result.type !== \"number\") {\n      return {\n        type: \"error\",\n        err: FormulaError.VALUE,\n        message: \"Start_num argument must be a number\",\n        errAddress: context.dependencyNode,\n      };\n    }\n\n    if (numCharsResult.result.type !== \"number\") {\n      return {\n        type: \"error\",\n        err: FormulaError.VALUE,\n        message: \"Num_chars argument must be a number\",\n        errAddress: context.dependencyNode,\n      };\n    }\n\n    const result = midOperation(\n      textResult,\n      startNumResult,\n      numCharsResult,\n      context\n    );\n    if (result.type === \"error\" || result.type === \"awaiting-evaluation\") {\n      return result;\n    }\n    return {\n      type: \"value\",\n      result: result.result,\n    };\n  },\n};\n"
  ],
  "mappings": ";AAAA;AAAA;AAAA;AAKA;AAoBO,IAAM,MAA0B;AAAA,EACrC,MAAM;AAAA,EACN,UAAU,QAAS,CAAC,MAAM,SAAmC;AAAA,IAC3D,IAAI,KAAK,KAAK,WAAW,GAAG;AAAA,MAC1B,OAAO;AAAA,QACL,MAAM;AAAA,QACN,KAAK,aAAa;AAAA,QAClB,SAAS;AAAA,QACT,YAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAAA,IAGA,MAAM,aAAa,KAAK,aAAa,KAAK,KAAK,IAAK,OAAO;AAAA,IAC3D,IACE,WAAW,SAAS,WACpB,WAAW,SAAS,uBACpB;AAAA,MACA,OAAO;AAAA,IACT;AAAA,IAGA,MAAM,iBAAiB,KAAK,aAAa,KAAK,KAAK,IAAK,OAAO;AAAA,IAC/D,IACE,eAAe,SAAS,WACxB,eAAe,SAAS,uBACxB;AAAA,MACA,OAAO;AAAA,IACT;AAAA,IAGA,MAAM,iBAAiB,KAAK,aAAa,KAAK,KAAK,IAAK,OAAO;AAAA,IAC/D,IACE,eAAe,SAAS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