import { jsxDEV } from "react/jsx-dev-runtime";
import { Component, QueryLanguage } from "@contember/binding";
import { AutoCell } from "./AutoCell.js";
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";
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: "/__w/interface/interface/packages/admin/src/components/Auto/AutoGrid.tsx",
      lineNumber: 24,
      columnNumber: 10
    }, globalThis);
  }
);
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: "/__w/interface/interface/packages/admin/src/components/Auto/AutoGrid.tsx",
    lineNumber: 37,
    columnNumber: 3
  }, globalThis));
  const actionColumn = /* @__PURE__ */ jsxDEV(GenericCell, { shrunk: true, children: [
    createEditLinkTarget && /* @__PURE__ */ jsxDEV(LinkButton, { to: createEditLinkTarget(entityName), distinction: "seamless", children: "edit" }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/Auto/AutoGrid.tsx",
      lineNumber: 43,
      columnNumber: 5
    }, globalThis),
    /* @__PURE__ */ jsxDEV(DeleteEntityButton, {}, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/Auto/AutoGrid.tsx",
      lineNumber: 47,
      columnNumber: 4
    }, globalThis)
  ] }, "action", true, {
    fileName: "/__w/interface/interface/packages/admin/src/components/Auto/AutoGrid.tsx",
    lineNumber: 41,
    columnNumber: 3
  }, globalThis);
  return [...fieldColumns, actionColumn];
};
export {
  AutoGrid
};
//# sourceMappingURL=AutoGrid.js.map
