import { V as o } from "./vue.min-CtdJWvsZ.js";
import { C as r, S as n } from "./EntityList-BfLW5ykn.js";
import l from "./vue/sql-text-editor.js";
import { C as d } from "./Table-fFZBsK5T.js";
import { n as c } from "./_plugin-vue2_normalizer-5m4abzWv.js";
const m = {
  /** List of entities (tables) available for selection */
  entities: {
    type: Array,
    default: () => [{ columns: [], data: [] }]
  },
  /** Props passed to the EntityList component */
  entityListProps: {
    type: Object,
    default: () => ({})
  },
  /** Props passed to the SqlTextEditor component */
  sqlTextEditorProps: {
    type: Object,
    default: () => ({})
  },
  /** Props passed to the Table component */
  tableProps: {
    type: Object,
    default: () => ({})
  }
}, E = ["setTable"], u = o.extend({
  components: { EntityList: r, SqlTextEditor: l, TableComponent: d },
  props: m,
  data() {
    return {
      sql: "",
      data: [],
      columns: [],
      mainSplit: null,
      showInitialPlaceholder: !0
    };
  },
  watch: {},
  computed: {
    keybindings() {
      return {
        "Ctrl-Enter": this.submitQuery,
        "Cmd-Enter": this.submitQuery
      };
    }
  },
  methods: {
    setTable(i) {
      this.showInitialPlaceholder = !1, this.data = i.data, this.columns = i.columns;
    },
    submitQuery() {
      this.$emit("bks-query-submit", { query: this.sql });
    },
    handleValueChange(i) {
      this.sql = i.value;
    },
    handleEntityDblclick(i) {
      this.setTable(i.entity);
    },
    handleForeignKeyGoTo({ field: i }) {
      const t = this.entities.find(
        (e) => {
          var s;
          return e === ((s = this.columns.find((a) => a.field === i)) == null ? void 0 : s.toTable);
        }
      );
      t && this.setTable(t);
    }
  },
  mounted() {
    const i = this.$refs.main, t = this.$refs.right;
    this.mainSplit = n(i.children, {
      direction: "horizontal",
      gutterStyle: () => "",
      elementStyle: (e, s) => ({
        "flex-basis": `calc(${s}%)`
      }),
      gutter: (e, s) => {
        const a = document.createElement("div");
        return a.className = `BksDataEditor-gutter gutter gutter-${s}`, a;
      },
      expandToMin: !0
    }), this.rightSplit = n(t.children, {
      direction: "vertical",
      gutterStyle: () => "",
      elementStyle: (e, s) => ({
        "flex-basis": `calc(${s}%)`
      }),
      gutter: (e, s) => {
        const a = document.createElement("div");
        return a.className = `BksDataEditor-gutter gutter gutter-${s}`, a;
      },
      expandToMin: !0
    });
  }
});
var h = function() {
  var t = this, e = t._self._c;
  return t._self._setupProxy, e("div", { ref: "main", staticClass: "BksUiKit BksDataEditor" }, [e("entity-list", t._b({ attrs: { entities: t.entities, proxyEmit: "" }, on: { "bks-entity-dblclick": t.handleEntityDblclick } }, "entity-list", t.entityListProps, !1)), e("div", { ref: "right", staticClass: "BksDataEditor-right-container" }, [e("div", { staticClass: "BksDataEditor-sql-editor" }, [e("sql-text-editor", t._b({ attrs: { focus: "", entities: t.entities, keybindings: t.keybindings, proxyEmit: "" }, on: { "bks-value-change": t.handleValueChange } }, "sql-text-editor", t.sqlTextEditorProps, !1)), e("div", { staticClass: "BksDataEditor-run" }, [e("button", { attrs: { title: "Ctrl-Enter" }, on: { click: t.submitQuery } }, [t._v("Run")])])], 1), e("div", { staticClass: "BksDataEditor-table" }, [e("div", { directives: [{ name: "show", rawName: "v-show", value: t.showInitialPlaceholder, expression: "showInitialPlaceholder" }], staticClass: "BksDataEditor-initial-placeholder" }, [t._v(" Select a table to view data or run a query. ")]), e("table-component", t._b({ directives: [{ name: "show", rawName: "v-show", value: !t.showInitialPlaceholder, expression: "!showInitialPlaceholder" }], attrs: { columns: t.columns, data: t.data, proxyEmit: "" }, on: { "bks-foreign-key-go-to": t.handleForeignKeyGoTo } }, "table-component", t.tableProps, !1))], 1)])], 1);
}, p = [], b = /* @__PURE__ */ c(
  u,
  h,
  p
);
const k = b.exports;
export {
  k as C,
  E as e
};
//# sourceMappingURL=DataEditor-BbQNlRie.js.map
