{
  "version": 3,
  "sources": ["../../../../../src/functions/lookup/count/count-utils.ts"],
  "sourcesContent": [
    "import {\n  type CellAddress,\n  type FunctionEvaluationResult,\n  type SingleEvaluationResult,\n} from \"../../../core/types.mjs\";\nimport type { ParsedCriteria } from \"../../criteria-parser.mjs\";\n\n/**\n * Performs counting of numeric values from an iterable of SingleEvaluationResult values\n * Handles numbers and infinities according to Excel's COUNT behavior\n * - Propagates errors immediately\n * - Only counts numeric values (numbers and infinities)\n * - Ignores non-numeric values (strings, booleans, empty cells)\n *\n * @param results - Iterable of SingleEvaluationResult to count\n * @returns FunctionEvaluationResult with the count\n */\nexport function performCount(\n  results: Iterable<SingleEvaluationResult>\n): FunctionEvaluationResult {\n  let count = 0;\n\n  for (const result of results) {\n    if (result.type === \"error\" || result.type === \"awaiting-evaluation\") {\n      // Propagate errors immediately\n      return result;\n    }\n\n    if (result.type === \"value\") {\n      if (\n        result.result.type === \"number\" ||\n        result.result.type === \"infinity\"\n      ) {\n        count++;\n      }\n      // Non-numeric values (strings, booleans) are ignored\n    }\n  }\n\n  return {\n    type: \"value\",\n    result: { type: \"number\", value: count },\n  };\n}\n\nexport function countEmptyCells(\n  criteriaRangeResult: FunctionEvaluationResult,\n  parsedCriteria: ParsedCriteria,\n  currentCell: CellAddress\n): FunctionEvaluationResult | undefined {\n  // Special case: counting empty cells over infinite ranges\n  if (\n    criteriaRangeResult.type === \"spilled-values\" &&\n    parsedCriteria.type === \"exact\" &&\n    parsedCriteria.value.type === \"string\" &&\n    parsedCriteria.value.value === \"\"\n  ) {\n    const spillArea = criteriaRangeResult.spillArea(currentCell);\n\n    // Check if this is an infinite range\n    if (\n      spillArea.end.col.type === \"infinity\" ||\n      spillArea.end.row.type === \"infinity\"\n    ) {\n      // Return infinity for infinite empty cell count\n      return {\n        type: \"value\",\n        result: { type: \"infinity\", sign: \"positive\" },\n      };\n    }\n  }\n}\n"
  ],
  "mappings": ";AAiBO,SAAS,YAAY,CAC1B,SAC0B;AAAA,EAC1B,IAAI,QAAQ;AAAA,EAEZ,WAAW,UAAU,SAAS;AAAA,IAC5B,IAAI,OAAO,SAAS,WAAW,OAAO,SAAS,uBAAuB;AAAA,MAEpE,OAAO;AAAA,IACT;AAAA,IAEA,IAAI,OAAO,SAAS,SAAS;AAAA,MAC3B,IACE,OAAO,OAAO,SAAS,YACvB,OAAO,OAAO,SAAS,YACvB;AAAA,QACA;AAAA,MACF;AAAA,IAEF;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,MAAM,UAAU,OAAO,MAAM;AAAA,EACzC;AAAA;AAGK,SAAS,eAAe,CAC7B,qBACA,gBACA,aACsC;AAAA,EAEtC,IACE,oBAAoB,SAAS,oBAC7B,eAAe,SAAS,WACxB,eAAe,MAAM,SAAS,YAC9B,eAAe,MAAM,UAAU,IAC/B;AAAA,IACA,MAAM,YAAY,oBAAoB,UAAU,WAAW;AAAA,IAG3D,IACE,UAAU,IAAI,IAAI,SAAS,cAC3B,UAAU,IAAI,IAAI,SAAS,YAC3B;AAAA,MAEA,OAAO;AAAA,QACL,MAAM;AAAA,QACN,QAAQ,EAAE,MAAM,YAAY,MAAM,WAAW;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AAAA;",
  "debugId": "27BAB068756EB60864756E2164756E21",
  "names": []
}