"use strict";
function createSSEParser(callback) {
  let buffer = "";
  let currentEvent = "message";
  function parse(chunk) {
    buffer += chunk;
    const messages = buffer.split("\n\n");
    buffer = messages.pop();
    messages.forEach((message) => {
      if (message.trim()) {
        currentEvent = "message";
        parseMessage(message);
      }
    });
  }
  function parseMessage(message) {
    const lines = message.split("\n");
    let event = "message";
    const dataLines = [];
    lines.forEach((line) => {
      if (line.startsWith("event:")) {
        event = line.slice(6).trim();
        currentEvent = event;
      } else if (line.startsWith("data:")) {
        dataLines.push(line.slice(5).trim());
      }
    });
    if (dataLines.length > 0) {
      dataLines.forEach((data) => {
        callback(currentEvent, data);
      });
    } else if (currentEvent !== "message") {
      callback(currentEvent, null);
    }
  }
  return {
    parse
  };
}
exports.createSSEParser = createSSEParser;
//# sourceMappingURL=../../.sourcemap/mp-alipay/utils/sseParse.js.map
