import PropTypes from 'prop-types';
import MenuItem from '@mui/material/MenuItem';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
import DeleteIcon from '@mui/icons-material/Delete';
import Tooltip from '@mui/material/Tooltip';
import Actions from '../../actions';
import DeleteDomainAlias from './action/delete-domain-alias';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export default function DomainActions({
  site,
  domain,
  blocklet,
  onDelete = () => {}
}) {
  const {
    t
  } = useLocaleContext();
  const isCurrentDomain = domain.value === window.location.hostname;
  return /*#__PURE__*/_jsx(Actions, {
    "data-cy": "domain-actions",
    size: "large",
    actions: [
    // eslint-disable-next-line react/no-unstable-nested-components
    ({
      close
    }) => /*#__PURE__*/_jsx(DeleteDomainAlias, {
      id: site.id,
      domain: domain.value,
      teamDid: blocklet?.meta?.did,
      onDelete: onDelete,
      children: ({
        open
      }) => /*#__PURE__*/_jsx(Tooltip, {
        title: isCurrentDomain ? t('blocklet.router.currentDomainTip') : '',
        children: /*#__PURE__*/_jsx("span", {
          children: /*#__PURE__*/_jsxs(MenuItem, {
            disabled: domain.isProtected || isCurrentDomain,
            dense: true,
            onClick: e => {
              close();
              open(e);
            },
            "data-cy": "action-toggle-block",
            children: [/*#__PURE__*/_jsx(ListItemIcon, {
              style: {
                minWidth: 24,
                marginRight: 8
              },
              children: /*#__PURE__*/_jsx(DeleteIcon, {})
            }), /*#__PURE__*/_jsx(ListItemText, {
              primary: t('common.delete')
            })]
          }, "remove")
        })
      })
    })]
  });
}
DomainActions.propTypes = {
  site: PropTypes.object.isRequired,
  domain: PropTypes.object.isRequired,
  blocklet: PropTypes.object.isRequired,
  onDelete: PropTypes.func
};