import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import React, { useState } from "react";
import { Upload } from "antd";
import ImgCrop from "antd-img-crop";
//#region src/components/cropPhoto/index.tsx
const CropPhoto = (props) => {
	const { cropShape } = props;
	const [fileList, setFileList] = useState([]);
	const onChange = ({ fileList: newFileList }) => {
		setFileList(newFileList);
	};
	const onPreview = function() {
		var _ref = _asyncToGenerator(function* (file) {
			let src = file.url;
			if (!src) src = yield new Promise((resolve) => {
				const reader = new FileReader();
				reader.readAsDataURL(file.originFileObj);
				reader.onload = () => resolve(reader.result);
			});
			const image = new Image();
			image.src = src;
			const imgWindow = window.open(src);
			imgWindow === null || imgWindow === void 0 || imgWindow.document.write(image.outerHTML);
		});
		return function onPreview(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ React.createElement(ImgCrop, {
		rotationSlider: true,
		aspectSlider: true,
		cropShape
	}, /* @__PURE__ */ React.createElement(Upload, {
		action: "https://660d2bd96ddfa2943b33731c.mockapi.io/api/upload",
		listType: "picture-card",
		fileList,
		onChange,
		onPreview
	}, fileList.length < 5 && "+ Upload"));
};
//#endregion
export { CropPhoto as default };
