import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import React, { useCallback, useState } from "react";
import classNames from "classnames";
import "./PisellBaseCard.less";
//#region src/components/pisellBaseCard/PisellBaseCard.tsx
/**
* 合并默认样式与状态样式
*/
function mergeStateStyle(base, hover, active, disabled, isHover, isActive, isDisabled) {
	let s = _objectSpread2({}, base);
	if (isDisabled && disabled) {
		Object.assign(s, disabled);
		return s;
	}
	if (isActive && active) Object.assign(s, active);
	if (isHover && hover) Object.assign(s, hover);
	return s;
}
/**
* PisellBaseCard 基础卡片容器
* 提供可定制的容器用于承载子内容，支持默认/悬停/按下/禁用四态样式，可点击时支持焦点与键盘触发
*/
function PisellBaseCard({ children, className, style, hoverStyle, activeStyle, disabledStyle, clickable = true, disabled = false, onClick }) {
	const [isHover, setIsHover] = useState(false);
	const [isActive, setIsActive] = useState(false);
	const mergedStyle = mergeStateStyle(style, hoverStyle, activeStyle, disabledStyle, isHover, isActive, disabled);
	const handleClick = useCallback((e) => {
		if (!clickable || disabled) return;
		onClick === null || onClick === void 0 || onClick(e);
	}, [
		clickable,
		disabled,
		onClick
	]);
	const handleKeyDown = useCallback((e) => {
		if (!clickable || disabled) return;
		if (e.key === "Enter" || e.key === " ") {
			e.preventDefault();
			e.target.click();
		}
	}, [clickable, disabled]);
	const handlePointerEnter = useCallback(() => {
		if (!disabled) setIsHover(true);
	}, [disabled]);
	const handlePointerLeave = useCallback(() => {
		setIsHover(false);
		setIsActive(false);
	}, []);
	const handlePointerDown = useCallback(() => {
		if (clickable && !disabled) setIsActive(true);
	}, [clickable, disabled]);
	const handlePointerUp = useCallback(() => {
		setIsActive(false);
	}, []);
	const canInteract = clickable && !disabled;
	return /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-base-card-root", className),
		style: mergedStyle,
		"data-clickable": clickable,
		"data-disabled": disabled,
		role: canInteract ? "button" : void 0,
		"aria-disabled": disabled ? true : void 0,
		tabIndex: canInteract ? 0 : void 0,
		onClick: handleClick,
		onKeyDown: handleKeyDown,
		onPointerEnter: handlePointerEnter,
		onPointerLeave: handlePointerLeave,
		onPointerDown: handlePointerDown,
		onPointerUp: handlePointerUp
	}, children);
}
//#endregion
export { PisellBaseCard };
