/* eslint-disable react/no-unstable-nested-components */
import PropTypes from 'prop-types';
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
import DeleteIcon from '@mui/icons-material/Delete';
import LaunchIcon from '@mui/icons-material/Launch';
import IconButton from '@mui/material/IconButton';
import SettingsOutlinedIcon from '@mui/icons-material/SettingsOutlined';
import Box from '@mui/material/Box';
import { useBlockletContext } from '../../contexts/blocklet';
import DeleteRule from './action/delete-rule';
import UpdateRule from './action/update-rule';
import { getBlockletUrlParams, getAccessUrl } from '../../util';

// eslint-disable-next-line react/prop-types
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export default function RuleActions({
  from,
  isProtected = false,
  ...rest
}) {
  const {
    locale
  } = useLocaleContext();
  const {
    blocklet,
    recommendedDomain: domain
  } = useBlockletContext();

  // eslint-disable-next-line react/prop-types
  const href = getAccessUrl(domain, from.pathPrefix, getBlockletUrlParams(blocklet, locale));
  return /*#__PURE__*/_jsxs(Box, {
    sx: {
      display: 'flex',
      alignItems: 'center'
    },
    children: [/*#__PURE__*/_jsx(Box, {
      component: "a",
      sx: {
        display: {
          xs: 'flex',
          md: 'none'
        }
      },
      target: "_blank",
      href: href,
      rel: "noopener noreferrer",
      title: href,
      children: /*#__PURE__*/_jsx(IconButton, {
        size: "small",
        children: /*#__PURE__*/_jsx(LaunchIcon, {})
      })
    }), /*#__PURE__*/_jsx(UpdateRule, {
      ...rest,
      isProtected: isProtected,
      from: from,
      children: ({
        open: o
      }) => /*#__PURE__*/_jsx(IconButton, {
        size: "small",
        onClick: o,
        disabled: isProtected,
        "data-cy": "action-update-rule",
        children: /*#__PURE__*/_jsx(SettingsOutlinedIcon, {})
      })
    }), /*#__PURE__*/_jsx(DeleteRule, {
      ...rest,
      isProtected: isProtected,
      from: from,
      children: ({
        open
      }) => /*#__PURE__*/_jsx(IconButton, {
        size: "small",
        onClick: open,
        disabled: isProtected,
        "data-cy": "action-delete-rule",
        children: /*#__PURE__*/_jsx(DeleteIcon, {})
      })
    })]
  });
}
RuleActions.propTypes = {
  isProtected: PropTypes.bool
};