/*
 * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { Chat } from "@blueprintjs/icons";
import { getUIMessageText } from "@osdk/aip-core";
import classNames from "classnames";
import * as React from "react";
import { useChatAutoScroll } from "../hooks/useChatAutoScroll.js";
import { AipAgentChatLoader } from "./AipAgentChatLoader.js";
import { AipAgentChatMessage } from "./AipAgentChatMessage.js";
import styles from "../AipAgentChat.module.css";
const DEFAULT_EMPTY_STATE = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Chat, {
  className: styles.emptyIcon,
  size: 64
}), /*#__PURE__*/React.createElement("div", {
  className: styles.emptyTitle
}, "Start a conversation"), /*#__PURE__*/React.createElement("div", null, "Type a message below to chat with the assistant."));
export function AipAgentChatMessageList({
  messages,
  isStreaming,
  enableAutoScroll,
  className,
  renderEmptyState,
  renderMessage
}) {
  const lastMessage = messages.at(-1);
  const lastMessageTextLength = lastMessage != null ? getUIMessageText(lastMessage).length : 0;
  const scrollSignal = `${messages.length}:${lastMessageTextLength}`;
  const setContainerRef = useChatAutoScroll(scrollSignal, enableAutoScroll);
  const isEmpty = messages.length === 0 && !isStreaming;
  const showLoader = isStreaming && lastMessage?.role !== "assistant";
  return /*#__PURE__*/React.createElement("div", {
    "aria-live": isEmpty ? undefined : "polite",
    className: classNames(styles.messageList, isEmpty && styles.empty, className),
    ref: setContainerRef,
    role: isEmpty ? undefined : "log"
  }, isEmpty ? renderEmptyState != null ? renderEmptyState() : DEFAULT_EMPTY_STATE : /*#__PURE__*/React.createElement(React.Fragment, null, messages.map(message => /*#__PURE__*/React.createElement(React.Fragment, {
    key: message.id
  }, renderMessage != null ? renderMessage(message) : /*#__PURE__*/React.createElement(AipAgentChatMessage, {
    message: message
  }))), showLoader && /*#__PURE__*/React.createElement("div", {
    className: classNames(styles.message, styles.assistantMessage)
  }, /*#__PURE__*/React.createElement("div", {
    className: classNames(styles.bubble, styles.assistantBubble)
  }, /*#__PURE__*/React.createElement(AipAgentChatLoader, null)))));
}
//# sourceMappingURL=AipAgentChatMessageList.js.map