import { getCurrentScope, onScopeDispose } from "vue";
export const BUILT_IN_DOCUMENT_TEMPLATE_INPUT_TYPES = Object.freeze([
  { label: "Text Field", value: "VTextField" },
  { label: "Text Area", value: "VTextarea" },
  { label: "Text Date Picker", value: "FormDate" },
  { label: "Text Time Picker", value: "FormTime" },
  { label: "Text Date & Time Picker", value: "FormDateTime" },
  { label: "Select Dropdown", value: "VSelect", requiresOptions: true, optionsAsChoice: true },
  { label: "Select Combobox", value: "VCombobox", requiresOptions: true, optionsAsChoice: true },
  { label: "Autocomplete", value: "VAutocomplete", requiresOptions: true, optionsAsChoice: true },
  { label: "Autocomplete from Master", value: "MasterAutocomplete", requiresOptions: true, optionsLabel: "Group Key" },
  { label: "Radio Buttons", value: "VRadio", requiresOptions: true, optionsAsChoice: true },
  { label: "Radio Buttons Inline", value: "VRadioInline", requiresOptions: true, optionsAsChoice: true },
  { label: "Checkbox", value: "VCheckbox" },
  { label: "Checkbox Group", value: "FormCheckboxGroup", requiresOptions: true, optionsAsChoice: true },
  { label: "Switch", value: "VSwitch" },
  { label: "File Upload", value: "FormFile", needsLabel: false, showsOptions: false },
  { label: "Signature Pad", value: "FormSignPad" },
  { label: "Table", value: "FormTable", requiresOptions: true, hasSpecificOptionEditor: true },
  { label: "Table Data", value: "FormTableData", requiresOptions: true, hasSpecificOptionEditor: true },
  {
    label: "[Decoration] Header",
    value: "Header",
    needsVariableName: false,
    needsWidth: false,
    optionsLabel: "Class",
    hidesValidationRules: true,
    hidesInputAttributes: true
  },
  {
    label: "[Decoration] Separator",
    value: "Separator",
    needsVariableName: false,
    needsLabel: false,
    needsWidth: false,
    showsOptions: false,
    hidesValidationRules: true,
    hidesInputAttributes: true,
    hidesColumnAttributes: true,
    hidesAdvancedSettings: true
  },
  {
    label: "[Advanced] Hidden Field",
    value: "FormHidden",
    needsLabel: false,
    needsWidth: false,
    hasSpecificOptionEditor: true,
    hidesValidationRules: true,
    hidesColumnAttributes: true,
    hidesClassAndStyle: true
  },
  {
    label: "[Advanced] Inherit Form",
    value: "DocumentForm",
    needsVariableName: false,
    needsLabel: false,
    needsWidth: false,
    requiresOptions: true,
    optionsLabel: "Template Code",
    hidesValidationRules: true,
    hidesInputAttributes: true,
    hidesColumnAttributes: true
  },
  {
    label: "[Advanced] Custom Code",
    value: "CustomCode",
    needsVariableName: false,
    needsLabel: false,
    showsOptions: false,
    hidesValidationRules: true,
    hidesInputAttributes: true,
    hidesAdvancedSettings: true
  }
]);
export function mergeDocumentTemplateInputTypes(...lists) {
  const byValue = /* @__PURE__ */ new Map();
  for (const list of lists) {
    if (!list) continue;
    for (const entry of list) {
      if (!entry || typeof entry.value !== "string" || entry.value.length === 0) continue;
      byValue.set(entry.value, { ...byValue.get(entry.value), ...entry });
    }
  }
  return [...byValue.values()];
}
const runtimeRegistry = /* @__PURE__ */ new Map();
export function registerDocumentTemplateInputType(entry) {
  if (!entry || typeof entry.value !== "string" || entry.value.length === 0) {
    return () => {
    };
  }
  const previous = runtimeRegistry.get(entry.value);
  const merged = { ...previous, ...entry };
  runtimeRegistry.set(entry.value, merged);
  return () => {
    if (runtimeRegistry.get(entry.value) === merged) {
      runtimeRegistry.delete(entry.value);
    }
  };
}
export function unregisterDocumentTemplateInputType(value) {
  runtimeRegistry.delete(value);
}
export function useDocumentTemplateInputType(entry) {
  const unregister = registerDocumentTemplateInputType(entry);
  if (getCurrentScope()) {
    onScopeDispose(unregister);
  }
}
export function _getDocumentTemplateRuntimeRegistry() {
  return [...runtimeRegistry.values()];
}
export function _resetDocumentTemplateRuntimeRegistry() {
  runtimeRegistry.clear();
}
export function getDocumentTemplateInputTypeEntry(value) {
  if (!value) return void 0;
  const fromRuntime = runtimeRegistry.get(value);
  const builtIn = BUILT_IN_DOCUMENT_TEMPLATE_INPUT_TYPES.find((t) => t.value === value);
  if (fromRuntime) return { ...builtIn, ...fromRuntime };
  return builtIn;
}
export function useDocumentTemplateInputTypes() {
  return mergeDocumentTemplateInputTypes(
    BUILT_IN_DOCUMENT_TEMPLATE_INPUT_TYPES,
    _getDocumentTemplateRuntimeRegistry()
  );
}
