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 { EMPTY_I18N, toLangDict, validateI18nRequired } from "../../types.js";
import React, { useEffect } from "react";
import { Form } from "antd";
import { BaseTranslation, PisellModal } from "@pisell/materials";
//#region src/plus/saasDevice/devicePlanning/components/WorkAreaModal/index.tsx
const WorkAreaModal = ({ open, mode, record, submitting, getText, onCancel, onSubmit }) => {
	const [form] = Form.useForm();
	useEffect(() => {
		if (!open) return;
		form.setFieldsValue({
			name: mode === "edit" ? toLangDict(record === null || record === void 0 ? void 0 : record.name) : _objectSpread2({}, EMPTY_I18N),
			description: mode === "edit" ? toLangDict(record === null || record === void 0 ? void 0 : record.description) : _objectSpread2({}, EMPTY_I18N)
		});
	}, [
		form,
		mode,
		open,
		record
	]);
	const handleOk = function() {
		var _ref = _asyncToGenerator(function* () {
			onSubmit(yield form.validateFields());
		});
		return function handleOk() {
			return _ref.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ React.createElement(PisellModal, {
		open,
		title: getText(mode === "create" ? "pisell2.saas.device-planning.modal.create-title" : "pisell2.saas.device-planning.modal.edit-title"),
		headerDivider: false,
		onCancel,
		okText: getText(mode === "create" ? "pisell2.saas.device-planning.modal.create" : "pisell2.saas.device-planning.modal.save"),
		cancelText: getText("pisell2.saas.device-planning.modal.cancel"),
		okButtonProps: {
			loading: submitting,
			onClick: handleOk
		},
		cancelButtonProps: { disabled: submitting },
		destroyOnClose: true,
		maskClosable: false,
		width: 520,
		className: "saas-device-planning-workarea-modal"
	}, /* @__PURE__ */ React.createElement(Form, {
		form,
		layout: "vertical",
		preserve: false
	}, /* @__PURE__ */ React.createElement(Form.Item, {
		name: "name",
		label: getText("pisell2.saas.device-planning.modal.name"),
		required: true,
		rules: [{ validator: validateI18nRequired(getText("pisell2.saas.device-planning.modal.name-required")) }]
	}, /* @__PURE__ */ React.createElement(BaseTranslation, { renderMode: "edit" })), /* @__PURE__ */ React.createElement(Form.Item, {
		name: "description",
		label: getText("pisell2.saas.device-planning.modal.description")
	}, /* @__PURE__ */ React.createElement(BaseTranslation, {
		renderMode: "edit",
		type: "textarea"
	}))));
};
//#endregion
export { WorkAreaModal as default };
