import { useDict, type UseDict } from '@/core/dictionary/use';
import type { MaybeDictValue } from '@/core/dictionary/index';
import type { Reactive, SlotsType } from 'vue';

export default /*#__PURE__*/ defineComponent({
  name: 'UseDict',
  props: {
    sign: { type: String as PropType<string>, required: true },
    raw: String as PropType<MaybeDictValue>,
  },
  slots: Object as SlotsType<{
    default: Reactive<UseDict>;
  }>,
  setup(props, { slots, attrs }) {
    const data = reactive(useDict(props.sign, toRef(props, 'raw'), attrs));

    return () => {
      if (slots.default) return slots.default(data);
    };
  },
});
