/*
 * Copyright 2025 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 { Collapsible } from "@base-ui/react/collapsible";
import { CaretDown } from "@blueprintjs/icons";
import classNames from "classnames";
import React, { memo } from "react";
import styles from "./FormSection.module.css.js";
export const FormSection = /*#__PURE__*/memo(function ({
  definition,
  errorCount,
  children
}) {
  const {
    title,
    description,
    collapsedByDefault = false,
    showTitleBar = true,
    columnCount = 1,
    style = "box"
  } = definition;
  if (style === "minimal") {
    return /*#__PURE__*/React.createElement(MinimalSection, {
      title: title,
      description: description
    }, children);
  }
  const contentClassName = classNames(columnCount === 2 ? styles.osdkFormSectionGrid : styles.osdkFormSectionContent, styles.osdkFormSectionDivider);
  if (!showTitleBar) {
    return /*#__PURE__*/React.createElement("div", {
      className: styles.osdkFormSectionBox
    }, /*#__PURE__*/React.createElement("div", {
      className: contentClassName
    }, children));
  }
  return /*#__PURE__*/React.createElement(Collapsible.Root, {
    // Inverted: Base UI uses "open" semantics, our API uses "collapsed" semantics
    defaultOpen: !collapsedByDefault,
    className: styles.osdkFormSectionBox
  }, /*#__PURE__*/React.createElement("div", {
    className: styles.osdkFormSectionHeader
  }, /*#__PURE__*/React.createElement("div", {
    className: styles.osdkFormSectionTitleArea
  }, /*#__PURE__*/React.createElement("span", {
    className: styles.osdkFormSectionTitle
  }, title), description != null && /*#__PURE__*/React.createElement("span", {
    className: styles.osdkFormSectionDescription
  }, description)), /*#__PURE__*/React.createElement(Collapsible.Trigger, {
    className: styles.osdkFormSectionTrigger,
    "aria-label": title
  }, errorCount > 0 && /*#__PURE__*/React.createElement("span", {
    className: styles.osdkFormSectionErrorBadge,
    role: "status"
  }, errorCount === 1 ? "1 error" : `${errorCount} errors`), /*#__PURE__*/React.createElement("span", {
    className: styles.osdkFormSectionChevron
  }, /*#__PURE__*/React.createElement(CaretDown, {
    size: 16
  })))), /*#__PURE__*/React.createElement(Collapsible.Panel, {
    keepMounted: true
  }, /*#__PURE__*/React.createElement("div", {
    className: contentClassName
  }, children)));
});
const MinimalSection = /*#__PURE__*/memo(function ({
  title,
  description,
  children
}) {
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    className: styles.osdkFormSectionMinimalHeader
  }, /*#__PURE__*/React.createElement("div", {
    className: styles.osdkFormSectionMinimalTitle
  }, title), description != null && /*#__PURE__*/React.createElement("div", {
    className: styles.osdkFormSectionMinimalDescription
  }, description)), /*#__PURE__*/React.createElement("div", {
    className: styles.osdkFormSectionMinimalContent
  }, children));
});
//# sourceMappingURL=FormSection.js.map