import { defineComponent as _defineComponent, getCurrentInstance, shallowReactive, toRaw, watchEffect } from "vue";
import { toKebabCase } from "@veno-ui/utils";
import { useDefaults } from "../composables/defaults";
import { consoleWarn } from "./console";
function propIsDefined(vnode, prop) {
  return vnode.props?.hasOwnProperty(prop) || vnode.props?.hasOwnProperty(toKebabCase(prop));
}
const defineComponent = function defineComponent2(options) {
  options._setup = options._setup ?? options.setup;
  if (!options.name) {
    consoleWarn("The component is missing an explicit name, unable to generate default prop value");
    return options;
  }
  if (options._setup) {
    options.setup = function setup(props, ctx) {
      const vm = getCurrentInstance();
      const defaults = useDefaults();
      const _props = shallowReactive({
        ...toRaw(props)
      });
      watchEffect(() => {
        const globalDefaults = defaults.value.global;
        const componentDefaults = defaults.value[options.name];
        for (const prop of Object.keys(props)) {
          let newVal;
          if (propIsDefined(vm.vnode, prop)) {
            newVal = props[prop];
          } else {
            newVal = componentDefaults?.[prop] ?? globalDefaults?.[prop] ?? props[prop];
          }
          if (_props[prop] !== newVal) {
            _props[prop] = newVal;
          }
        }
      });
      return options._setup(_props, ctx);
    };
  }
  return options;
};
function genericComponent(exposeDefaults = true) {
  return (options) => (exposeDefaults ? defineComponent : _defineComponent)(options);
}
export {
  defineComponent,
  genericComponent,
  propIsDefined
};
//# sourceMappingURL=define-component.mjs.map
