import "../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                       */
/* empty css                                                               */
/* empty css                                                            */
/* empty css                                                         */
/* empty css                                                            */
/* empty css                                                                  */
/* empty css                                                            */
/* empty css                                                            */
import { computed, ref, createElementBlock, openBlock, Fragment, createVNode, unref, isRef, withCtx, renderList, createBlock, createTextVNode } from "vue";
import { Plus as plus_default } from "../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
import { getEditConfigDataSources } from "../packages/utils/common.mjs";
import { useDataSourceDialog } from "../packages/dataSource/useDataSourceDialog.mjs";
import { ElSelect, ElOption } from "../../../node_modules/element-plus/es/components/select/index.mjs";
import { ElButton } from "../../../node_modules/element-plus/es/components/button/index.mjs";
const _sfc_main = {
  __name: "DataSourceSelect",
  props: {
    modelValue: {
      type: [String, Number],
      default: ""
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const modelValue = computed({
      get: () => props.modelValue,
      set: (val) => emit("update:modelValue", val)
    });
    const { dataSourceDialogVisible, openDataSourceDialog, DataSourceDialog } = useDataSourceDialog();
    const dataSources = computed(() => {
      return getEditConfigDataSources();
    });
    const selectRef = ref(null);
    const handleAddDataSource = () => {
      var _a;
      (_a = selectRef.value) == null ? void 0 : _a.blur();
      openDataSourceDialog();
    };
    return (_ctx, _cache) => {
      const _component_el_option = ElOption;
      const _component_el_button = ElButton;
      const _component_el_select = ElSelect;
      return openBlock(), createElementBlock(Fragment, null, [
        createVNode(_component_el_select, {
          ref_key: "selectRef",
          ref: selectRef,
          modelValue: unref(modelValue),
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(modelValue) ? modelValue.value = $event : null),
          placeholder: "请选择数据源",
          filterable: "",
          style: { "width": "100%" },
          teleported: false
        }, {
          footer: withCtx(() => [
            createVNode(_component_el_button, {
              type: "primary",
              size: "small",
              icon: unref(plus_default),
              link: "",
              onClick: handleAddDataSource
            }, {
              default: withCtx(() => _cache[2] || (_cache[2] = [
                createTextVNode(" 新增数据源 ")
              ])),
              _: 1
            }, 8, ["icon"])
          ]),
          default: withCtx(() => [
            (openBlock(true), createElementBlock(Fragment, null, renderList(unref(dataSources), (dataSource) => {
              return openBlock(), createBlock(_component_el_option, {
                key: dataSource.id,
                label: dataSource.name,
                value: dataSource.id
              }, null, 8, ["label", "value"]);
            }), 128))
          ]),
          _: 1
        }, 8, ["modelValue"]),
        createVNode(unref(DataSourceDialog), {
          modelValue: unref(dataSourceDialogVisible),
          "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(dataSourceDialogVisible) ? dataSourceDialogVisible.value = $event : null)
        }, null, 8, ["modelValue"])
      ], 64);
    };
  }
};
export {
  _sfc_main as default
};
