import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
// Utilities
import { computed, defineComponent, inject, isRef } from 'vue';
import { makeProps } from "../util/makeProps.mjs";
import { propsFactory } from "../util/propsFactory.mjs"; // Types

export const VuetifyIconSymbol = Symbol.for('vuetify:icons');
export const makeIconProps = propsFactory({
  icon: {
    type: [String, Object],
    required: true
  },
  // Could not remove this and use makeTagProps, types complained because it is not required
  tag: {
    type: String,
    required: true
  }
}, 'icon');
export const VComponentIcon = defineComponent({
  name: 'VComponentIcon',
  props: makeProps(makeIconProps()),

  setup(props) {
    return () => {
      return _createVNode(props.tag, null, {
        default: () => [_createVNode(props.icon, null, null)]
      });
    };
  }

});
export const VSvgIcon = defineComponent({
  name: 'VSvgIcon',
  inheritAttrs: false,
  props: makeProps(makeIconProps()),

  setup(props, {
    attrs
  }) {
    return () => {
      return _createVNode(props.tag, _mergeProps(attrs, {
        "style": null
      }), {
        default: () => [_createVNode("svg", {
          "class": 'v-icon__svg',
          "xmlns": 'http://www.w3.org/2000/svg',
          "viewBox": '0 0 24 24',
          "role": 'img',
          "aria-hidden": "true"
        }, [_createVNode("path", {
          "d": props.icon
        }, null, 8, ["d"])])]
      }, 16);
    };
  }

});
export const VLigatureIcon = defineComponent({
  name: 'VLigatureIcon',
  props: makeProps(makeIconProps()),

  setup(props) {
    return () => {
      return _createVNode(props.tag, null, {
        default: () => [props.icon]
      });
    };
  }

});
export const VClassIcon = defineComponent({
  name: 'VClassIcon',
  props: makeProps(makeIconProps()),

  setup(props) {
    return () => {
      return _createVNode(props.tag, {
        "class": props.icon
      }, null, 8, ["class"]);
    };
  }

});
export const defaultSets = {
  svg: {
    component: VSvgIcon
  },
  class: {
    component: VClassIcon
  }
}; // Composables

export const useIcon = props => {
  const icons = inject(VuetifyIconSymbol);
  if (!icons) throw new Error('Missing Vuetify Icons provide!');
  const iconData = computed(() => {
    const iconAlias = isRef(props) ? props.value : props.icon;
    if (!iconAlias) throw new Error('Icon value is undefined or null');
    let icon = iconAlias;

    if (typeof iconAlias === 'string' && iconAlias.includes('$')) {
      var _icons$aliases;

      icon = (_icons$aliases = icons.aliases) == null ? void 0 : _icons$aliases[iconAlias.slice(iconAlias.indexOf('$') + 1)];
    }

    if (!icon) throw new Error("Could not find aliased icon \"".concat(iconAlias, "\""));

    if (typeof icon !== 'string') {
      return {
        component: VComponentIcon,
        icon
      };
    }

    const hasSet = icon.includes(':');
    const setName = hasSet ? icon.split(':')[0] : icons.defaultSet;
    const iconName = hasSet ? icon.split(':')[1] : icon;
    const set = icons.sets[setName != null ? setName : icons.defaultSet];

    if (!set) {
      throw new Error("Could not find icon set \"".concat(setName, "\""));
    }

    return {
      component: set.component,
      icon: iconName
    };
  });
  return {
    iconData
  };
};
//# sourceMappingURL=icons.mjs.map