import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import Box from '@material-ui/core/Box';
import Button from '@material-ui/core/Button';
import { makeStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import { EmptyState, CodeSnippet, Link } from '@backstage/core-components';
import { useEntity } from '../../hooks/useEntity.esm.js';
import '../../hooks/useEntityListProvider.esm.js';
import 'react';
import 'react-use/esm/useAsync';
import 'lodash/isEqual';
import 'lodash/sortBy';
import '@backstage/core-plugin-api';
import '../../api.esm.js';
import '@backstage/catalog-model';
import 'react-use/esm/useObservable';
import '../../apis/EntityPresentationApi/EntityPresentationApi.esm.js';
import 'lodash/get';
import '../../apis/StarredEntitiesApi/StarredEntitiesApi.esm.js';
import 'zen-observable';

const useStyles = makeStyles(
  (theme) => ({
    code: {
      borderRadius: 6,
      margin: theme.spacing(2, 0),
      background: theme.palette.type === "dark" ? "#444" : theme.palette.common.white
    }
  }),
  { name: "BackstageMissingAnnotationEmptyState" }
);
function generateYamlExample(annotations, entity) {
  const kind = entity?.kind || "Component";
  const name = entity?.metadata.name || "example";
  const type = entity?.spec?.type || "website";
  const owner = entity?.spec?.owner || "user:default/guest";
  const yamlText = `apiVersion: backstage.io/v1alpha1
kind: ${kind}
metadata:
  name: ${name}
  annotations:${annotations.map((ann) => `
    ${ann}: value`).join("")}
spec:
  type: ${type}
  owner: ${owner}`;
  let line = 6;
  const lineNumbers = [];
  annotations.forEach(() => {
    lineNumbers.push(line);
    line++;
  });
  return {
    yamlText,
    lineNumbers
  };
}
function generateDescription(annotations, entityKind = "Component") {
  const isSingular = annotations.length <= 1;
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    "The ",
    isSingular ? "annotation" : "annotations",
    " ",
    annotations.map((ann) => /* @__PURE__ */ jsx("code", { children: ann })).reduce((prev, curr) => /* @__PURE__ */ jsxs(Fragment, { children: [
      prev,
      ", ",
      curr
    ] })),
    " ",
    isSingular ? "is" : "are",
    " missing. You need to add the",
    " ",
    isSingular ? "annotation" : "annotations",
    " to your ",
    entityKind,
    " if you want to enable this tool."
  ] });
}
function MissingAnnotationEmptyState(props) {
  let entity;
  try {
    const entityContext = useEntity();
    entity = entityContext.entity;
  } catch (err) {
  }
  const { annotation, readMoreUrl } = props;
  const annotations = Array.isArray(annotation) ? annotation : [annotation];
  const url = readMoreUrl || "https://backstage.io/docs/features/software-catalog/well-known-annotations";
  const classes = useStyles();
  const entityKind = entity?.kind || "Component";
  const { yamlText, lineNumbers } = generateYamlExample(annotations, entity);
  return /* @__PURE__ */ jsx(
    EmptyState,
    {
      missing: "field",
      title: "Missing Annotation",
      description: generateDescription(annotations, entityKind),
      action: /* @__PURE__ */ jsxs(Fragment, { children: [
        /* @__PURE__ */ jsxs(Typography, { variant: "body1", children: [
          "Add the annotation to your ",
          entityKind,
          " YAML as shown in the highlighted example below:"
        ] }),
        /* @__PURE__ */ jsx(Box, { className: classes.code, children: /* @__PURE__ */ jsx(
          CodeSnippet,
          {
            text: yamlText,
            language: "yaml",
            showLineNumbers: true,
            highlightedNumbers: lineNumbers,
            customStyle: { background: "inherit", fontSize: "115%" }
          }
        ) }),
        /* @__PURE__ */ jsx(Button, { color: "primary", component: Link, to: url, children: "Read more" })
      ] })
    }
  );
}

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