"use client";
import { AccordionChevron } from "../Accordion/AccordionChevron.mjs";
import { Combobox } from "../Combobox/Combobox.mjs";
import { CheckIcon } from "../Checkbox/CheckIcon.mjs";
import { CheckboxIndicator } from "../Checkbox/CheckboxIndicator/CheckboxIndicator.mjs";
import TreeSelect_module_default from "./TreeSelect.module.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
//#region packages/@mantine/core/src/components/TreeSelect/TreeSelectOption.tsx
const LEVEL_OFFSET = 20;
const BASE_PADDING = 8;
const LINE_CONTENT_GAP = 5;
const OPTION_GAP = 6;
function TreeSelectOption({ node, level, expanded, hasChildren, selected, checked, indeterminate, showCheckbox, isLastChild, lineGuides, withLines, onToggleExpand, renderNode, chevronAriaLabels }) {
	const indentPx = (level - 1) * LEVEL_OFFSET;
	const handleExpandClick = (event) => {
		event.stopPropagation();
		event.preventDefault();
		onToggleExpand(node.value);
	};
	const handleExpandMouseDown = (event) => {
		event.preventDefault();
	};
	const customContent = renderNode ? renderNode({
		node,
		level,
		expanded,
		hasChildren,
		selected,
		checked,
		indeterminate
	}) : null;
	const lineElements = withLines && level > 1 ? /* @__PURE__ */ jsxs(Fragment, { children: [
		lineGuides.map((show, g) => show ? /* @__PURE__ */ jsx("span", {
			className: TreeSelect_module_default.guideLine,
			style: { insetInlineStart: BASE_PADDING + (g + 1) * LEVEL_OFFSET - LEVEL_OFFSET / 2 }
		}, `g${g}`) : null),
		/* @__PURE__ */ jsx("span", {
			className: TreeSelect_module_default.branchVertical,
			"data-last": isLastChild || void 0,
			style: { insetInlineStart: BASE_PADDING + (level - 1) * LEVEL_OFFSET - LEVEL_OFFSET / 2 }
		}),
		/* @__PURE__ */ jsx("span", {
			className: TreeSelect_module_default.branchHorizontal,
			style: {
				insetInlineStart: BASE_PADDING + (level - 1) * LEVEL_OFFSET - LEVEL_OFFSET / 2,
				width: LEVEL_OFFSET / 2
			}
		})
	] }) : null;
	const isActive = selected || checked;
	const showCheckMark = !showCheckbox && isActive;
	const ariaChecked = showCheckbox ? indeterminate && !checked ? "mixed" : checked : void 0;
	return /* @__PURE__ */ jsxs(Combobox.Option, {
		value: node.value,
		disabled: node.nodeProps?.disabled,
		active: isActive,
		className: TreeSelect_module_default.option,
		style: { paddingInlineStart: BASE_PADDING + indentPx + (withLines && level > 1 ? LINE_CONTENT_GAP : 0) + (!hasChildren ? OPTION_GAP : 0) },
		"aria-selected": isActive,
		"aria-level": level,
		"aria-expanded": hasChildren ? expanded : void 0,
		"aria-checked": ariaChecked,
		children: [lineElements, customContent || /* @__PURE__ */ jsxs(Fragment, { children: [
			hasChildren && /* @__PURE__ */ jsx("span", {
				className: TreeSelect_module_default.expandIcon,
				"data-expanded": expanded || void 0,
				onClick: handleExpandClick,
				onKeyDown: (e) => {
					if (e.key === "Enter") handleExpandClick(e);
				},
				onMouseDown: handleExpandMouseDown,
				role: "button",
				tabIndex: -1,
				"aria-label": expanded ? chevronAriaLabels?.collapse ?? "Collapse" : chevronAriaLabels?.expand ?? "Expand",
				children: /* @__PURE__ */ jsx(AccordionChevron, { size: "80%" })
			}),
			showCheckbox && /* @__PURE__ */ jsx(CheckboxIndicator, {
				checked: checked || indeterminate,
				indeterminate: !checked && indeterminate,
				size: "18px"
			}),
			/* @__PURE__ */ jsx("span", {
				className: TreeSelect_module_default.label,
				children: node.label
			}),
			showCheckMark && /* @__PURE__ */ jsx(CheckIcon, { className: TreeSelect_module_default.checkIcon })
		] })]
	});
}
TreeSelectOption.displayName = "@mantine/core/TreeSelectOption";
//#endregion
export { TreeSelectOption };

//# sourceMappingURL=TreeSelectOption.mjs.map