import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import React, { useEffect, useMemo, useState } from "react";
import classNames from "classnames";
import "./index.less";
//#region src/pro/Selector/components/Indicator/index.tsx
const sizeMap = {
	small: 20,
	middle: 24,
	large: 28
};
const Indicator = (props) => {
	const { mode = "single", variant = "outlined", disabled = false, className, styles = {}, children, size = "middle", onChange, defaultChecked, checked: checkedProp } = props;
	const [internalChecked, setInternalChecked] = useState(defaultChecked || false);
	useEffect(() => {
		if (checkedProp !== void 0) setInternalChecked(checkedProp);
	}, [checkedProp]);
	const isControlled = checkedProp !== void 0;
	const checked = isControlled ? checkedProp : internalChecked;
	const prefixCls = "pisell-pro-indicator";
	const classes = classNames(prefixCls, `${prefixCls}-${mode}`, `${prefixCls}-${variant}`, {
		[`${prefixCls}-checked`]: checked,
		[`${prefixCls}-disabled`]: disabled
	}, className);
	const indicatorStyle = useMemo(() => {
		const sizeValue = sizeMap[size] || Number(size);
		return _objectSpread2({
			width: sizeValue,
			height: sizeValue
		}, styles.indicator);
	}, [size, styles.indicator]);
	const handleInputChange = (e) => {
		if (disabled) return;
		if (!isControlled) setInternalChecked(e.target.checked);
		onChange === null || onChange === void 0 || onChange(e);
	};
	const renderCheckIcon = () => {
		const iconSize = (sizeMap[size] || Number(size)) * .6;
		const strokeWidth = iconSize * .15;
		return /* @__PURE__ */ React.createElement("svg", {
			className: `${prefixCls}-check-icon`,
			width: iconSize,
			height: iconSize * .76,
			viewBox: "0 0 17 13",
			fill: "none",
			xmlns: "http://www.w3.org/2000/svg"
		}, /* @__PURE__ */ React.createElement("path", {
			d: "M14.8814 1.44043L5.64141 10.6804L1.44141 6.48043",
			stroke: "currentColor",
			strokeWidth,
			strokeLinecap: "round",
			strokeLinejoin: "round"
		}));
	};
	return /* @__PURE__ */ React.createElement("label", {
		className: classes,
		style: styles === null || styles === void 0 ? void 0 : styles.container
	}, /* @__PURE__ */ React.createElement("input", {
		type: mode === "single" ? "radio" : "checkbox",
		className: `${prefixCls}-input`,
		checked: !!checked,
		disabled,
		onChange: handleInputChange
	}), /* @__PURE__ */ React.createElement("div", {
		className: `${prefixCls}-inner`,
		style: indicatorStyle
	}, checked && /* @__PURE__ */ React.createElement(React.Fragment, null, mode === "single" && variant === "outlined" ? /* @__PURE__ */ React.createElement("div", { className: `${prefixCls}-dot` }) : renderCheckIcon())), children && /* @__PURE__ */ React.createElement("span", {
		className: `${prefixCls}-content`,
		style: styles === null || styles === void 0 ? void 0 : styles.content
	}, children));
};
//#endregion
export { Indicator as default };
