var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/eftpos/const.ts
var const_exports = {};
__export(const_exports, {
  DeviceEnum: () => DeviceEnum,
  Eftpos: () => Eftpos,
  getCommByFields: () => getCommByFields,
  getDefaultValue: () => getDefaultValue
});
module.exports = __toCommonJS(const_exports);
var import_form = require("./form");
var Eftpos = /* @__PURE__ */ ((Eftpos2) => {
  Eftpos2["Payo"] = "payo";
  Eftpos2["Tyro"] = "tyro";
  Eftpos2["Windcave"] = "windcave";
  Eftpos2["Stripe"] = "stripe";
  return Eftpos2;
})(Eftpos || {});
var DeviceEnum = /* @__PURE__ */ ((DeviceEnum2) => {
  DeviceEnum2["Add"] = "add";
  DeviceEnum2["Edit"] = "edit";
  DeviceEnum2["Repair"] = "repair";
  return DeviceEnum2;
})(DeviceEnum || {});
var getDefaultValue = (list) => {
  return list.reduce((target, item) => {
    if (Array.isArray(item.children) && item.children.length) {
      return {
        ...target,
        [item.__sourceName]: getDefaultValue(item.children)
      };
    }
    if (!item.Component) {
      return target;
    }
    const ComponentName = item.Component;
    if (import_form.helpMapping[ComponentName]) {
      return {
        ...target,
        ...import_form.helpMapping[ComponentName].getCommDefaultVal(item)
      };
    }
    return {
      ...target,
      [item.__sourceName]: item.input.defaultValue
    };
  }, {});
};
async function getCommByFields({
  field,
  value,
  name = [],
  getComm
}) {
  const result = await Promise.all(
    field.map(async (item) => {
      if (typeof item === "string") {
        const commConfig = await getComm(
          value ? { field: item, value: value[item] } : { field: item },
          value
        );
        if (!commConfig) {
          return void 0;
        }
        if (Array.isArray(commConfig)) {
          return commConfig.map((item2) => {
            const ComponentName2 = item2.Component;
            const helpFn2 = import_form.helpMapping[ComponentName2];
            if (helpFn2) {
              return helpFn2.getCommName(item2, name);
            }
            item2.__sourceName = item2.name;
            item2.name = name.length > 0 ? [...name, item2.name] : item2.name;
            return item2;
          });
        }
        const ComponentName = commConfig.Component;
        const helpFn = import_form.helpMapping[ComponentName];
        if (helpFn) {
          return helpFn.getCommName(commConfig, name);
        }
        commConfig.__sourceName = commConfig.name;
        commConfig.name = name.length > 0 ? [...name, commConfig.name] : commConfig.name;
        return commConfig;
      }
      const children = await getCommByFields({
        field: item.children,
        value,
        name: [...name || [], item.name],
        getComm
      });
      return {
        name: name.length > 0 ? [...name, item.name] : item.name,
        __sourceName: item.name,
        children
      };
    })
  );
  return result.flat().filter(Boolean);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DeviceEnum,
  Eftpos,
  getCommByFields,
  getDefaultValue
});
