"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("react");
const index$1 = require("./web/index.js");
const emotionReactJsxRuntime_browser_esm = require("../../node_modules/.pnpm/@emotion_react@11.10.4_q4mq7tnhdumujvomvw24zx33y4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const index = require("../../node_modules/.pnpm/@arco-design_web-react@2.40.1_biqbaboplfbrettd7655fr4n2y/node_modules/@arco-design/web-react/es/Form/index.js");
const FormItem = index.Item;
index.List;
const Field = (props) => {
  let {
    label,
    name,
    type,
    layout,
    col,
    required,
    rules = [],
    condition,
    defaultValue,
    normalize,
    render,
    isHidden
  } = props;
  const ControlComponent = index$1[findType(type)];
  if (!ControlComponent) {
    return null;
  }
  const component = render || /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(ControlComponent, {
    ...props
  });
  let config = {
    className: `${col && layout !== "inline" ? `col-span-${col}` : ""}  ${type === "textarea" || type === "image" || type === "images" ? "row-span-2" : ""}`,
    label,
    field: name,
    name,
    ...defaultValue ? {
      initialValue: type === "switch" ? Boolean(defaultValue) : defaultValue
    } : {},
    rules: [{
      required,
      ...type === "tel" ? {
        match: /[+\(\d]{3,4}[\(\d \)-]{4,8}[\d]{4}/g
      } : {}
    }, ...rules],
    normalize,
    formatter: (value) => {
      if (type === "time-range") {
        return typeof value !== "string" ? `${value && value[0]}-${value && value[1]}` : value;
      }
      return value;
    },
    hidden: isHidden || type === "uuid" ? true : false
  };
  if (condition) {
    return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(FormItem, {
      noStyle: true,
      shouldUpdate: true,
      children: (values) => {
        return conditionalField(values, condition) ? {
          component
        } : null;
      }
    });
  }
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(FormItem, {
    ...config,
    children: component
  });
};
const findType = (type = "title") => {
  switch (type) {
    case "uuid": {
      return "input";
    }
    case "string": {
      return "input";
    }
    case "tel": {
      return "input";
    }
    case "text": {
      return "input";
    }
    case "search": {
      return "input";
    }
    case "time-range": {
      return "time";
    }
    case "timeRange": {
      return "time";
    }
    case "rmb": {
      return "number";
    }
    case "day": {
      return "date";
    }
    case "multipleSelect": {
      return "select";
    }
    case "status": {
      return "select";
    }
    case "datetime": {
      return "date";
    }
    case "image": {
      return "upload";
    }
    case "images": {
      return "upload";
    }
    case "readOnly": {
      return "title";
    }
    default:
      return type;
  }
};
const conditionalField = (values, condition) => {
  const value = values[condition.name];
  if (!condition.name && !condition.value) {
    return false;
  }
  let operator = condition.operator || "=";
  if (operator === "=" && value === condition.value) {
    return false;
  }
  if (operator === "!=" && value !== condition.value) {
    return false;
  }
  return true;
};
exports.Field = Field;
//# sourceMappingURL=Field.js.map
