// Utilities
import { getCurrentInstance } from 'vue';
import { wrapInArray } from "./helpers.mjs";
import { consoleWarn } from "./console.mjs";
import { useVuetify } from "../framework.mjs"; // Types

export function makeProps(props) {
  for (const key in props) {
    const originalProp = props[key];
    const isOptions = !(originalProp == null || Array.isArray(originalProp) || typeof originalProp === 'function');
    const propDefinition = isOptions ? originalProp : {
      type: originalProp
    };
    const originalDefault = propDefinition.hasOwnProperty('default') ? propDefinition.default : propDefinition.type === Boolean || Array.isArray(propDefinition.type) && propDefinition.type.includes(Boolean) ? false : undefined;
    const wrappedDefault = generateDefault(key, originalDefault, propDefinition.type);
    props[key] = { ...propDefinition,
      default: wrappedDefault
    };
  }

  return props;
}

function generateDefault(propName, localDefault, type) {
  return props => {
    var _vuetify$defaults$vm$;

    const vm = getCurrentInstance();

    if (!vm) {
      consoleWarn('Unable to get current component instance when generating default prop value');
      return localDefault;
    }

    if (!vm.type.name) {
      consoleWarn('The component is missing an explicit name, unable to generate default prop value');
      return localDefault;
    }

    const vuetify = useVuetify();
    const globalDefault = vuetify.defaults.global[propName];
    const componentDefault = (_vuetify$defaults$vm$ = vuetify.defaults[vm.type.name]) == null ? void 0 : _vuetify$defaults$vm$[propName];
    const actualDefault = typeof componentDefault !== 'undefined' ? componentDefault : typeof globalDefault !== 'undefined' ? globalDefault : localDefault;
    return isFactory(actualDefault, type) ? actualDefault(props) : actualDefault;
  };
} // Would be nice to have PropOptions here


function isFactory(val, type) {
  return typeof val === 'function' && !wrapInArray(type).includes(Function);
}
//# sourceMappingURL=makeProps.mjs.map