import { getText } from "../../../../locales/index.js";
import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _asyncToGenerator } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import icon_default from "../../../icon/index.js";
import Input$1 from "../../../input/index.js";
import React, { useRef } from "react";
import { copyToClipboard } from "@pisell/utils";
import { Button, Space, message } from "antd";
//#region src/components/pisellInput/components/Copy/index.tsx
const Copy = (props) => {
	var _props$disabled;
	const { buttonProps } = props;
	const inputRef = useRef(null);
	const handleCopyClick = function() {
		var _ref = _asyncToGenerator(function* (e) {
			var _buttonProps$onClick, _inputRef$current;
			buttonProps === null || buttonProps === void 0 || (_buttonProps$onClick = buttonProps.onClick) === null || _buttonProps$onClick === void 0 || _buttonProps$onClick.call(buttonProps, e);
			yield copyToClipboard(((_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || (_inputRef$current = _inputRef$current.input) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.value) || "");
			message.success(getText("pisell-input-copy-success"));
		});
		return function handleCopyClick(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ React.createElement(Space.Compact, { block: true }, /* @__PURE__ */ React.createElement(Input$1, _objectSpread2(_objectSpread2({}, props), {}, {
		ref: inputRef,
		disabled: (_props$disabled = props.disabled) !== null && _props$disabled !== void 0 ? _props$disabled : true,
		size: "large"
	})), /* @__PURE__ */ React.createElement(Button, _objectSpread2(_objectSpread2({
		size: "large",
		icon: /* @__PURE__ */ React.createElement(icon_default, { type: "pisell2-copy-03" })
	}, buttonProps), {}, {
		onClick: handleCopyClick,
		children: (buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.children) || getText("pisell-input-copy")
	})));
};
//#endregion
export { Copy as default };
