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/components/table/Table/SelectField/index.tsx
var SelectField_exports = {};
__export(SelectField_exports, {
  default: () => SelectField_default
});
module.exports = __toCommonJS(SelectField_exports);
var import_iconfont = __toESM(require("../../../iconfont"));
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_react2 = require("react");
var import_fields = require("../fields");
var import_index = __toESM(require("./index.less"));
var SelectFieldCom = ({ value, onChange }) => {
  const [open, setOpen] = (0, import_react2.useState)(false);
  const currentField = (0, import_react2.useMemo)(() => {
    var _a;
    return (_a = (0, import_fields.getFieldByType)(value)) == null ? void 0 : _a.field;
  }, [value]);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: import_index.default["field-list"] }, open ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: import_index.default["current-field"],
      onClick: () => {
        setOpen(false);
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: import_index.default["left"] }, /* @__PURE__ */ import_react.default.createElement(
      import_iconfont.default,
      {
        className: import_index.default["icon"],
        type: currentField == null ? void 0 : currentField.field_icon
      }
    ), /* @__PURE__ */ import_react.default.createElement("span", { className: import_index.default["name"] }, currentField == null ? void 0 : currentField.field_name)),
    /* @__PURE__ */ import_react.default.createElement(
      import_iconfont.default,
      {
        type: "pi-a-Property3caret-down1",
        className: import_index.default["right"]
      }
    )
  )) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, import_fields.fieldList.map((d) => {
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(import_index.default["field-item"], {
          [import_index.default["active"]]: value === d.field_type
        }),
        key: d.field_type,
        onClick: () => {
          setOpen(true);
          onChange(d.field_type);
        }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_iconfont.default,
        {
          type: d.field_icon,
          className: import_index.default["field-icon"]
        }
      ),
      /* @__PURE__ */ import_react.default.createElement("div", { className: import_index.default["field-name"] }, d.field_name)
    );
  })));
};
var FieldEditor = ({ fieldType }) => {
  var _a;
  const Com = (_a = (0, import_fields.getFieldByType)(fieldType)) == null ? void 0 : _a.Editor;
  return Com ? /* @__PURE__ */ import_react.default.createElement(Com, null) : /* @__PURE__ */ import_react.default.createElement("div", null);
};
var SelectField = () => {
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      name: "field_type",
      rules: [
        {
          required: true,
          message: "Please select a field type"
        }
      ]
    },
    /* @__PURE__ */ import_react.default.createElement(SelectFieldCom, null)
  ), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      noStyle: true,
      shouldUpdate: (prevValues, currentValues) => prevValues.field_type !== currentValues.field_type
    },
    ({ getFieldValue }) => {
      let fieldType = getFieldValue("field_type");
      return /* @__PURE__ */ import_react.default.createElement(FieldEditor, { fieldType });
    }
  ));
};
var SelectField_default = SelectField;
