import React, { useEffect, useState } from "react";
import { Radio } from "antd";
import { VirtualKeyboard } from "@pisell/materials";
import classNames from "classnames";
import "./index.less";
//#region src/pro/pisellPriceRadio/index.tsx
const PisellPriceRadio = ({ checked = false, onSelect, value = "", onChange, title = "", currencySymbol = "$", theme = "purple", showMinus = false, disabled = false, placeholder = "Amount" }) => {
	const [showKeyboard, setShowKeyboard] = useState(false);
	useEffect(() => {
		if (checked) setShowKeyboard(true);
		else setShowKeyboard(false);
	}, [checked]);
	const handleInputClick = () => {
		if (!disabled) {
			onSelect === null || onSelect === void 0 || onSelect();
			setShowKeyboard(true);
		}
	};
	const handleRadioClick = () => {
		if (!disabled) onSelect === null || onSelect === void 0 || onSelect();
	};
	const handlePriceChange = (newValue) => {
		onChange === null || onChange === void 0 || onChange(newValue);
	};
	const renderInput = (props) => {
		const displayValue = showMinus && value ? `-${value}` : value;
		return /* @__PURE__ */ React.createElement("button", {
			type: "button",
			className: classNames("pisell-price-radio-input-container", {
				[`pisell-price-radio-input-container-${theme}`]: checked,
				"pisell-price-radio-input-container-disabled": disabled
			}),
			onClick: handleInputClick,
			disabled
		}, /* @__PURE__ */ React.createElement("span", { className: "pisell-price-radio-currency" }, currencySymbol), /* @__PURE__ */ React.createElement("div", { className: "pisell-price-radio-input-content" }, displayValue || /* @__PURE__ */ React.createElement("span", { className: "pisell-price-radio-placeholder" }, showMinus ? "-" : "", placeholder)));
	};
	return /* @__PURE__ */ React.createElement("div", { className: classNames("pisell-price-radio", {
		[`pisell-price-radio-${theme}`]: checked,
		"pisell-price-radio-checked": checked,
		"pisell-price-radio-disabled": disabled
	}) }, /* @__PURE__ */ React.createElement("div", { className: "pisell-price-radio-header" }, /* @__PURE__ */ React.createElement(Radio, {
		checked,
		onChange: handleRadioClick,
		disabled,
		className: classNames("pisell-price-radio-button", { [`pisell-price-radio-button-${theme}`]: checked })
	}), /* @__PURE__ */ React.createElement("span", { className: "pisell-price-radio-title" }, title)), /* @__PURE__ */ React.createElement(VirtualKeyboard, {
		value,
		onChange: (e) => handlePriceChange(e.target.value),
		renderInput,
		showDelete: false,
		onValueSelect: (selected) => {
			if (selected && !checked) onSelect === null || onSelect === void 0 || onSelect();
		},
		defaultSelect: checked && showKeyboard,
		placeholder,
		disabled
	}));
};
//#endregion
export { PisellPriceRadio as default };
