const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_useEngineContext = require("../../../../../hooks/useEngineContext.js");
const require_types = require("../../types.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
//#region src/plus/saasDevice/deviceProfile/components/ProfileSetting/BasicForm.tsx
const getText = _pisell_utils.locales.getText;
const EMPTY_I18N = {
	original: "",
	"zh-CN": "",
	"zh-HK": "",
	en: "",
	pt: "",
	ja: ""
};
const BasicForm = (0, react.forwardRef)(({ mode, deviceType, deviceModels, initialValue, onDirty, open = true }, ref) => {
	var _context$appHelper;
	const context = require_useEngineContext.default();
	const [form] = antd.Form.useForm();
	const { translation } = (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils;
	const initialValues = (0, react.useMemo)(() => {
		if (mode === "edit" && initialValue) {
			var _initialValue$_raw$de, _initialValue$_raw;
			return {
				name: typeof (initialValue === null || initialValue === void 0 ? void 0 : initialValue.name) === "string" ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, EMPTY_I18N), {}, { original: initialValue === null || initialValue === void 0 ? void 0 : initialValue.name }) : initialValue === null || initialValue === void 0 ? void 0 : initialValue.name,
				type_code: (deviceType === null || deviceType === void 0 ? void 0 : deviceType.code) || "",
				model_code: (initialValue === null || initialValue === void 0 ? void 0 : initialValue.modelCode) || (initialValue === null || initialValue === void 0 ? void 0 : initialValue.model_code),
				description: (_initialValue$_raw$de = initialValue === null || initialValue === void 0 || (_initialValue$_raw = initialValue._raw) === null || _initialValue$_raw === void 0 ? void 0 : _initialValue$_raw.description) !== null && _initialValue$_raw$de !== void 0 ? _initialValue$_raw$de : require_objectSpread2._objectSpread2({}, EMPTY_I18N),
				status: initialValue === null || initialValue === void 0 ? void 0 : initialValue.status
			};
		}
		return {
			name: require_objectSpread2._objectSpread2({}, EMPTY_I18N),
			type_code: (deviceType === null || deviceType === void 0 ? void 0 : deviceType.code) || "",
			model_code: "",
			description: require_objectSpread2._objectSpread2({}, EMPTY_I18N),
			status: "active"
		};
	}, [
		mode,
		initialValue,
		deviceType === null || deviceType === void 0 ? void 0 : deviceType.code
	]);
	(0, react.useEffect)(() => {
		if (!open) return;
		form.resetFields();
		form.setFieldsValue(initialValues);
	}, [
		open,
		initialValues,
		form
	]);
	(0, react.useImperativeHandle)(ref, () => ({
		getValues: () => form.validateFields(),
		resetDirty: () => {}
	}), [form]);
	const typeOptions = (0, react.useMemo)(() => [{
		label: translation((deviceType === null || deviceType === void 0 ? void 0 : deviceType.name) || "") || (deviceType === null || deviceType === void 0 ? void 0 : deviceType.code) || "",
		value: (deviceType === null || deviceType === void 0 ? void 0 : deviceType.code) || ""
	}], [deviceType === null || deviceType === void 0 ? void 0 : deviceType.code, deviceType === null || deviceType === void 0 ? void 0 : deviceType.name]);
	const modelOptions = (0, react.useMemo)(() => deviceModels === null || deviceModels === void 0 ? void 0 : deviceModels.map((m) => ({
		label: translation(m.name) || m.code,
		value: m.code
	})), [deviceModels]);
	const statusOptions = (0, react.useMemo)(() => require_types.DEVICE_STATUSES.map((s) => ({
		label: getText(s.labelKey),
		value: s.value
	})), []);
	return /* @__PURE__ */ react.default.createElement(antd.Form, {
		form,
		layout: "vertical",
		onValuesChange: () => onDirty === null || onDirty === void 0 ? void 0 : onDirty(),
		preserve: false,
		initialValues
	}, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "name",
		label: getText("pisell2.saas.device-profile.setting.field.name"),
		required: true,
		rules: [{ validator: require_types.validateI18nRequired(getText("pisell2.saas.device-profile.setting.field.nameRequired")) }]
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.BaseTranslation, {
		renderMode: "edit",
		placeholder: getText("pisell2.saas.device-profile.setting.field.namePlaceholder")
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "type_code",
		label: getText("pisell2.saas.device-profile.setting.field.deviceType"),
		required: true
	}, /* @__PURE__ */ react.default.createElement(antd.Select, {
		disabled: true,
		options: typeOptions
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "model_code",
		label: getText("pisell2.saas.device-profile.setting.field.model"),
		required: true,
		rules: [{
			required: true,
			message: getText("pisell2.saas.device-profile.setting.field.modelRequired")
		}]
	}, /* @__PURE__ */ react.default.createElement(antd.Select, {
		disabled: mode === "edit",
		placeholder: getText("pisell2.saas.device-profile.setting.field.modelPlaceholder"),
		options: modelOptions
	})), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "status",
		label: getText("pisell2.saas.device-profile.setting.field.status"),
		required: true
	}, /* @__PURE__ */ react.default.createElement(antd.Select, { options: statusOptions })), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		name: "description",
		label: getText("pisell2.saas.device-profile.setting.field.description")
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.BaseTranslation, {
		renderMode: "edit",
		type: "textarea",
		placeholder: getText("pisell2.saas.device-profile.setting.field.descriptionPlaceholder")
	})));
});
BasicForm.displayName = "BasicForm";
//#endregion
exports.default = BasicForm;
