/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { __toESM } from "../../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../../node_modules/classnames/index.js";
import { pkg } from "../../../settings.js";
import React, { isValidElement } from "react";
//#region src/components/Datagrid/Datagrid/DatagridExpandedRow.tsx
/**
* Copyright IBM Corp. 2020, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--datagrid`;
const DatagridExpandedRow = (ExpandedRowContentComponent) => (datagridState) => {
	const { row } = datagridState;
	const { expandedContentHeight } = row;
	const toggleParentHoverClass = (event, eventType = "") => {
		/* istanbul ignore else */
		if (event?.target?.closest("tr").previousElementSibling) {
			const parentNode = event?.target?.closest("tr").previousElementSibling;
			if (eventType === "enter") parentNode.classList.add(`${blockClass}__expandable-row--hover`);
			else parentNode.classList.remove(`${blockClass}__expandable-row--hover`);
		}
	};
	const { key, ..._state } = datagridState;
	return /* @__PURE__ */ React.createElement("tr", {
		className: (0, import_classnames.default)(`${blockClass}__expanded-row`, {
			[`${blockClass}__slug--row`]: isValidElement(row?.original?.slug),
			[`${blockClass}__ai-label--row`]: isValidElement(row?.original?.aiLabel)
		}),
		onMouseEnter: (event) => toggleParentHoverClass(event, "enter"),
		onMouseLeave: (event) => toggleParentHoverClass(event)
	}, /* @__PURE__ */ React.createElement("td", { className: `${blockClass}__expanded-row-cell-wrapper` }, /* @__PURE__ */ React.createElement("div", {
		className: `${blockClass}__expanded-row-content`,
		ref: (el) => {
			if (el && el.style && expandedContentHeight) el.style.height = `${expandedContentHeight}px`;
		}
	}, /* @__PURE__ */ React.createElement(ExpandedRowContentComponent, {
		key,
		..._state
	}))));
};
//#endregion
export { DatagridExpandedRow as default };
