import { Component, QueryLanguage } from "@contember/binding";
import { AutoCell } from "./AutoCell.js";
import { jsxDEV } from "react/jsx-dev-runtime";
import { GenericCell } from "../bindingFacade/collections/DataGrid/cells/GenericCell.js";
import { DataGrid } from "../bindingFacade/collections/DataGrid/grid/DataGrid.js";
import { LinkButton } from "../../routing/binding/LinkButton.js";
import { DeleteEntityButton } from "../bindingFacade/collections/helpers/DeleteEntityButton.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/Auto/AutoGrid.tsx";
const AutoGrid = Component((props, env) => {
  const schema = env.getSchema();
  const entities = QueryLanguage.desugarQualifiedEntityList({
    entities: props.entities
  }, env);
  const {
    createViewLinkTarget,
    createEditLinkTarget,
    ...dataGridProps
  } = props;
  const columns = createDataGridColumns(schema, entities.entityName, createViewLinkTarget, createEditLinkTarget);
  return /* @__PURE__ */ jsxDEV(DataGrid, {
    ...dataGridProps,
    children: columns
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 21,
    columnNumber: 10
  }, void 0);
});
const createDataGridColumns = (schema, entityName, createViewLinkTarget, createEditLinkTarget) => {
  const entitySchema = schema.getEntity(entityName);
  const fieldColumns = Array.from(entitySchema.fields.values()).map((it) => /* @__PURE__ */ jsxDEV(AutoCell, {
    schema,
    entityName,
    fieldName: it.name,
    createEntityLink: createViewLinkTarget
  }, it.name, false, {
    fileName: _jsxFileName,
    lineNumber: 34,
    columnNumber: 3
  }, void 0));
  const actionColumn = /* @__PURE__ */ jsxDEV(GenericCell, {
    shrunk: true,
    children: [createEditLinkTarget && /* @__PURE__ */ jsxDEV(LinkButton, {
      to: createEditLinkTarget(entityName),
      distinction: "seamless",
      children: "edit"
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 40,
      columnNumber: 5
    }, void 0), /* @__PURE__ */ jsxDEV(DeleteEntityButton, {}, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 44,
      columnNumber: 4
    }, void 0)]
  }, "action", true, {
    fileName: _jsxFileName,
    lineNumber: 38,
    columnNumber: 3
  }, void 0);
  return [...fieldColumns, actionColumn];
};
export {
  AutoGrid
};
//# sourceMappingURL=AutoGrid.js.map
