import PropTypes from 'prop-types';
import { Icon } from '@iconify/react';
import IconButton from '@mui/material/IconButton';
import { useCallback, isValidElement } from 'react';
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
function NavigationActions({
  className = '',
  add = () => {},
  edit = () => {},
  toggle = () => {},
  del = () => {},
  data,
  section = ''
}) {
  const {
    t
  } = useLocaleContext();
  const isDisabled = ['yaml', 'team-tmpl'].includes(data.from);
  const isUninstalled = /*#__PURE__*/isValidElement(data.subtitle);
  function handleClick(e) {
    e.preventDefault();
    e.stopPropagation();
  }
  const handleClickAdd = useCallback(e => {
    handleClick(e);
    add(data);
  }, [add, data]);
  const handleClickEdit = useCallback(e => {
    handleClick(e);
    edit(data);
  }, [edit, data]);
  const handleClickToggle = useCallback(e => {
    handleClick(e);
    toggle(data);
  }, [toggle, data]);
  const handleClickDelete = useCallback(e => {
    handleClick(e);
    del(data);
  }, [del, data]);
  return /*#__PURE__*/_jsxs("div", {
    className: className,
    children: [!data.parent && ['header', 'footer', 'dashboard'].includes(section) && /*#__PURE__*/_jsx("span", {
      title: isUninstalled ? t('navigation.action.noAddSub') : t('navigation.action.addSub'),
      children: /*#__PURE__*/_jsx(IconButton, {
        size: "small",
        color: "success",
        onClick: handleClickAdd,
        disabled: isUninstalled,
        children: /*#__PURE__*/_jsx(Icon, {
          icon: "mdi:plus-box-outline"
        })
      })
    }), /*#__PURE__*/_jsx("span", {
      title: isUninstalled ? t('navigation.action.noEdit') : t('navigation.action.edit'),
      children: /*#__PURE__*/_jsx(IconButton, {
        size: "small",
        color: "primary",
        onClick: handleClickEdit,
        disabled: isUninstalled || data.from === 'team-tmpl',
        children: /*#__PURE__*/_jsx(Icon, {
          icon: "mdi:pencil-outline"
        })
      })
    }), /*#__PURE__*/_jsx("span", {
      title:
      // eslint-disable-next-line no-nested-ternary
      isUninstalled ? t('navigation.action.noEdit') : data.visible ? t('navigation.action.hide') : t('navigation.action.show'),
      children: /*#__PURE__*/_jsx(IconButton, {
        size: "small",
        color: "warning",
        onClick: handleClickToggle,
        disabled: isUninstalled,
        children: data.visible === false ? /*#__PURE__*/_jsx(Icon, {
          icon: "mdi:eye-off-outline"
        }) : /*#__PURE__*/_jsx(Icon, {
          icon: "mdi:eye-outline"
        })
      })
    }), /*#__PURE__*/_jsx("span", {
      title: isDisabled && !isUninstalled ? t('navigation.action.noDel') : t('navigation.action.del'),
      children: /*#__PURE__*/_jsx(IconButton, {
        disabled: isDisabled && !isUninstalled,
        size: "small",
        color: "error",
        onClick: handleClickDelete,
        children: /*#__PURE__*/_jsx(Icon, {
          icon: "mdi:delete"
        })
      })
    })]
  });
}
NavigationActions.propTypes = {
  data: PropTypes.object.isRequired,
  className: PropTypes.string,
  add: PropTypes.func,
  edit: PropTypes.func,
  toggle: PropTypes.func,
  del: PropTypes.func,
  section: PropTypes.string
};
export default NavigationActions;