// src/common/ui-utils.ts
function typeStr(task) {
  return task.subType && task.subType !== "Plan" ? `${task.type} / ${task.subType || ""}` : task.type;
}
function getKeyCommands(value) {
  const keys = Array.isArray(value) ? value : [value];
  return keys.reduce((acc, k) => {
    const includeMeta = keys.includes("Meta") || keys.includes("Control");
    if (includeMeta && (k === "a" || k === "A")) {
      return acc.concat([{ key: k, command: "SelectAll" }]);
    }
    if (includeMeta && (k === "c" || k === "C")) {
      return acc.concat([{ key: k, command: "Copy" }]);
    }
    if (includeMeta && (k === "v" || k === "V")) {
      return acc.concat([{ key: k, command: "Paste" }]);
    }
    return acc.concat([{ key: k }]);
  }, []);
}
function locateParamStr(locate) {
  if (!locate) {
    return "";
  }
  if (typeof locate === "string") {
    return locate;
  }
  return locate.prompt;
}
function scrollParamStr(scrollParam) {
  if (!scrollParam) {
    return "";
  }
  return `${scrollParam.direction || "down"}, ${scrollParam.scrollType || "once"}, ${scrollParam.distance || "distance-not-set"}`;
}
function taskTitleStr(type, prompt) {
  if (prompt) {
    return `${type} - ${prompt}`;
  }
  return type;
}
function paramStr(task) {
  let value;
  if (task.type === "Planning") {
    value = task?.param?.userInstruction;
  }
  if (task.type === "Insight") {
    value = task?.param?.prompt || task?.param?.id || task?.param?.dataDemand || task?.param?.assertion;
  }
  if (task.type === "Action") {
    const locate = task?.locate;
    const locateStr = locate ? locateParamStr(locate) : "";
    value = task.thought || "";
    if (typeof task?.param?.timeMs === "number") {
      value = `${task?.param?.timeMs}ms`;
    } else if (typeof task?.param?.scrollType === "string") {
      value = scrollParamStr(task?.param);
    } else if (typeof task?.param?.value !== "undefined") {
      value = task?.param?.value;
    }
    if (locateStr) {
      if (value) {
        value = `${locateStr} - ${value}`;
      } else {
        value = locateStr;
      }
    }
  }
  if (typeof value === "undefined")
    return "";
  return typeof value === "string" ? value : JSON.stringify(value, void 0, 2);
}
var limitOpenNewTabScript = `
if (!window.__MIDSCENE_NEW_TAB_INTERCEPTOR_INITIALIZED__) {
  window.__MIDSCENE_NEW_TAB_INTERCEPTOR_INITIALIZED__ = true;

  // Intercept the window.open method (only once)
  window.open = function(url) {
    console.log('Blocked window.open:', url);
    window.location.href = url;
    return null;
  };

  // Block all a tag clicks with target="_blank" (only once)
  document.addEventListener('click', function(e) {
    const target = e.target.closest('a');
    if (target && target.target === '_blank') {
      e.preventDefault();
      console.log('Blocked new tab:', target.href);
      window.location.href = target.href;
      target.removeAttribute('target');
    }
  }, true);
}
`;
export {
  getKeyCommands,
  limitOpenNewTabScript,
  locateParamStr,
  paramStr,
  scrollParamStr,
  taskTitleStr,
  typeStr
};

//# sourceMappingURL=ui-utils.js.map