import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import Box from '@material-ui/core/Box';
import DialogContentText from '@material-ui/core/DialogContentText';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/core/styles';
import groupBy from 'lodash/groupBy';
import sortBy from 'lodash/sortBy';
import { EntityRefLink } from '../../EntityRefLink/EntityRefLink.esm.js';
import { stringifyEntityRef } from '@backstage/catalog-model';
import 'react';
import 'lodash/get';
import { Container, ListItemText, ListSubheader, HelpIcon, KeyValueListItem } from './common.esm.js';
import { CopyTextButton } from '@backstage/core-components';
import { catalogReactTranslationRef } from '../../../translation.esm.js';
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';

const useStyles = makeStyles({
  root: {
    display: "flex",
    flexDirection: "column"
  }
});
function OverviewPage(props) {
  const classes = useStyles();
  const {
    apiVersion,
    kind,
    metadata,
    spec,
    relations = [],
    status = {}
  } = props.entity;
  const groupedRelations = groupBy(
    sortBy(relations, (r) => r.targetRef),
    "type"
  );
  const { t } = useTranslationRef(catalogReactTranslationRef);
  const entityRef = stringifyEntityRef(props.entity);
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(DialogContentText, { variant: "h2", children: t("inspectEntityDialog.overviewPage.title") }),
    /* @__PURE__ */ jsxs("div", { className: classes.root, children: [
      /* @__PURE__ */ jsx(Container, { title: "Identity", children: /* @__PURE__ */ jsxs(List, { dense: true, children: [
        /* @__PURE__ */ jsx(ListItem, { children: /* @__PURE__ */ jsx(ListItemText, { primary: "apiVersion", secondary: apiVersion }) }),
        /* @__PURE__ */ jsx(ListItem, { children: /* @__PURE__ */ jsx(ListItemText, { primary: "kind", secondary: kind }) }),
        spec?.type && /* @__PURE__ */ jsx(ListItem, { children: /* @__PURE__ */ jsx(
          ListItemText,
          {
            primary: "spec.type",
            secondary: spec.type?.toString()
          }
        ) }),
        metadata.uid && /* @__PURE__ */ jsxs(ListItem, { children: [
          /* @__PURE__ */ jsx(ListItemText, { primary: "uid", secondary: metadata.uid }),
          /* @__PURE__ */ jsx(ListItemSecondaryAction, { children: /* @__PURE__ */ jsx(CopyTextButton, { text: metadata.uid }) })
        ] }),
        metadata.etag && /* @__PURE__ */ jsxs(ListItem, { children: [
          /* @__PURE__ */ jsx(ListItemText, { primary: "etag", secondary: metadata.etag }),
          /* @__PURE__ */ jsx(ListItemSecondaryAction, { children: /* @__PURE__ */ jsx(CopyTextButton, { text: metadata.etag }) })
        ] }),
        /* @__PURE__ */ jsxs(ListItem, { children: [
          /* @__PURE__ */ jsx(ListItemText, { primary: "entityRef", secondary: entityRef }),
          /* @__PURE__ */ jsx(ListItemSecondaryAction, { children: /* @__PURE__ */ jsx(CopyTextButton, { text: entityRef }) })
        ] })
      ] }) }),
      /* @__PURE__ */ jsxs(Container, { title: "Metadata", children: [
        !!Object.keys(metadata.annotations || {}).length && /* @__PURE__ */ jsx(
          List,
          {
            dense: true,
            subheader: /* @__PURE__ */ jsxs(ListSubheader, { children: [
              "Annotations",
              /* @__PURE__ */ jsx(HelpIcon, { to: "https://backstage.io/docs/features/software-catalog/well-known-annotations" })
            ] }),
            children: Object.entries(metadata.annotations).map((entry) => /* @__PURE__ */ jsx(KeyValueListItem, { indent: true, entry }, entry[0]))
          }
        ),
        !!Object.keys(metadata.labels || {}).length && /* @__PURE__ */ jsx(List, { dense: true, subheader: /* @__PURE__ */ jsx(ListSubheader, { children: "Labels" }), children: Object.entries(metadata.labels).map((entry) => /* @__PURE__ */ jsx(KeyValueListItem, { indent: true, entry }, entry[0])) }),
        !!metadata.tags?.length && /* @__PURE__ */ jsx(List, { dense: true, subheader: /* @__PURE__ */ jsx(ListSubheader, { children: "Tags" }), children: metadata.tags.map((tag, index) => /* @__PURE__ */ jsxs(ListItem, { children: [
          /* @__PURE__ */ jsx(ListItemIcon, {}),
          /* @__PURE__ */ jsx(ListItemText, { primary: tag })
        ] }, `${tag}-${index}`)) })
      ] }),
      !!relations.length && /* @__PURE__ */ jsx(
        Container,
        {
          title: "Relations",
          helpLink: "https://backstage.io/docs/features/software-catalog/well-known-relations",
          children: Object.entries(groupedRelations).map(
            ([type, groupRelations], index) => /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(List, { dense: true, subheader: /* @__PURE__ */ jsx(ListSubheader, { children: type }), children: groupRelations.map((group) => /* @__PURE__ */ jsx(ListItem, { children: /* @__PURE__ */ jsx(
              ListItemText,
              {
                primary: /* @__PURE__ */ jsx(EntityRefLink, { entityRef: group.targetRef })
              }
            ) }, group.targetRef)) }) }, index)
          )
        }
      ),
      !!status.items?.length && /* @__PURE__ */ jsx(
        Container,
        {
          title: "Status",
          helpLink: "https://backstage.io/docs/features/software-catalog/well-known-statuses",
          children: status.items.map((item, index) => /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsxs(Typography, { children: [
              item.level,
              ": ",
              item.type
            ] }),
            /* @__PURE__ */ jsx(Box, { ml: 2, children: item.message })
          ] }, index))
        }
      )
    ] })
  ] });
}

export { OverviewPage };
//# sourceMappingURL=OverviewPage.esm.js.map
