var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/saasDevice/deviceProfile/components/ProfileSetting/BasicForm.tsx
var BasicForm_exports = {};
__export(BasicForm_exports, {
  default: () => BasicForm_default
});
module.exports = __toCommonJS(BasicForm_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var import_types = require("../../types");
var import_useEngineContext = __toESM(require("../../../../../hooks/useEngineContext"));
var getText = import_utils.locales.getText;
var EMPTY_I18N = {
  original: "",
  "zh-CN": "",
  "zh-HK": "",
  en: "",
  pt: "",
  ja: ""
};
var BasicForm = (0, import_react.forwardRef)(
  ({ mode, deviceType, deviceModels, initialValue, onDirty, open = true }, ref) => {
    var _a;
    const context = (0, import_useEngineContext.default)();
    const [form] = import_antd.Form.useForm();
    const { translation } = (_a = context.appHelper) == null ? void 0 : _a.utils;
    const initialValues = (0, import_react.useMemo)(() => {
      var _a2;
      if (mode === "edit" && initialValue) {
        return {
          name: typeof (initialValue == null ? void 0 : initialValue.name) === "string" ? { ...EMPTY_I18N, original: initialValue == null ? void 0 : initialValue.name } : initialValue == null ? void 0 : initialValue.name,
          type_code: (deviceType == null ? void 0 : deviceType.code) || "",
          model_code: (initialValue == null ? void 0 : initialValue.modelCode) || (initialValue == null ? void 0 : initialValue.model_code),
          description: ((_a2 = initialValue == null ? void 0 : initialValue._raw) == null ? void 0 : _a2.description) ?? { ...EMPTY_I18N },
          status: initialValue == null ? void 0 : initialValue.status
        };
      }
      return {
        name: { ...EMPTY_I18N },
        type_code: (deviceType == null ? void 0 : deviceType.code) || "",
        model_code: "",
        description: { ...EMPTY_I18N },
        status: "active"
      };
    }, [mode, initialValue, deviceType == null ? void 0 : deviceType.code]);
    (0, import_react.useEffect)(() => {
      if (!open) return;
      form.resetFields();
      form.setFieldsValue(initialValues);
    }, [open, initialValues, form]);
    (0, import_react.useImperativeHandle)(
      ref,
      () => ({
        getValues: () => form.validateFields(),
        resetDirty: () => {
        }
      }),
      [form]
    );
    const typeOptions = (0, import_react.useMemo)(
      () => [
        {
          label: translation((deviceType == null ? void 0 : deviceType.name) || "") || (deviceType == null ? void 0 : deviceType.code) || "",
          value: (deviceType == null ? void 0 : deviceType.code) || ""
        }
      ],
      [deviceType == null ? void 0 : deviceType.code, deviceType == null ? void 0 : deviceType.name]
    );
    const modelOptions = (0, import_react.useMemo)(
      () => deviceModels == null ? void 0 : deviceModels.map((m) => ({
        label: translation(m.name) || m.code,
        value: m.code
      })),
      [deviceModels]
    );
    const statusOptions = (0, import_react.useMemo)(
      () => import_types.DEVICE_STATUSES.map((s) => ({
        label: getText(s.labelKey),
        value: s.value
      })),
      []
    );
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form,
      {
        form,
        layout: "vertical",
        onValuesChange: () => onDirty == null ? void 0 : onDirty(),
        preserve: false,
        initialValues
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          name: "name",
          label: getText("pisell2.saas.device-profile.setting.field.name"),
          required: true,
          rules: [
            {
              validator: (0, import_types.validateI18nRequired)(
                getText(
                  "pisell2.saas.device-profile.setting.field.nameRequired"
                )
              )
            }
          ]
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_materials.BaseTranslation,
          {
            renderMode: "edit",
            placeholder: getText(
              "pisell2.saas.device-profile.setting.field.namePlaceholder"
            )
          }
        )
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          name: "type_code",
          label: getText(
            "pisell2.saas.device-profile.setting.field.deviceType"
          ),
          required: true
        },
        /* @__PURE__ */ import_react.default.createElement(import_antd.Select, { disabled: true, options: typeOptions })
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_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__ */ import_react.default.createElement(
          import_antd.Select,
          {
            disabled: mode === "edit",
            placeholder: getText(
              "pisell2.saas.device-profile.setting.field.modelPlaceholder"
            ),
            options: modelOptions
          }
        )
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          name: "status",
          label: getText("pisell2.saas.device-profile.setting.field.status"),
          required: true
        },
        /* @__PURE__ */ import_react.default.createElement(import_antd.Select, { options: statusOptions })
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          name: "description",
          label: getText(
            "pisell2.saas.device-profile.setting.field.description"
          )
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_materials.BaseTranslation,
          {
            renderMode: "edit",
            type: "textarea",
            placeholder: getText(
              "pisell2.saas.device-profile.setting.field.descriptionPlaceholder"
            )
          }
        )
      )
    );
  }
);
BasicForm.displayName = "BasicForm";
var BasicForm_default = BasicForm;
