import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
import { Button, Tooltip, Typography } from '@mui/material';
import PropTypes from 'prop-types';
import semver from 'semver';
import { jsx as _jsx } from "react/jsx-runtime";
const isSatisfiedVersion = (serverVersion, requirementVersion) => {
  if (!requirementVersion || !serverVersion) return true;
  const isServerVersionSatisfied = semver.satisfies(semver.coerce(serverVersion), requirementVersion);
  return isServerVersionSatisfied;
};
export default function CheckVersionButton({
  children,
  serverVersion = '',
  requirementVersion = '',
  ...props
}) {
  const {
    t
  } = useLocaleContext();
  const isSatisfied = isSatisfiedVersion(serverVersion, requirementVersion);
  if (isSatisfied) {
    return children;
  }
  return /*#__PURE__*/_jsx(Tooltip, {
    title: t('store.tooltip.upgradeServer', {
      serverVersion,
      version: requirementVersion
    }),
    arrow: true,
    children: /*#__PURE__*/_jsx(Typography, {
      children: /*#__PURE__*/_jsx(Button, {
        disabled: true,
        variant: "outlined",
        ...props,
        children: t('common.upgradeServer')
      })
    })
  });
}
CheckVersionButton.propTypes = {
  children: PropTypes.node.isRequired,
  serverVersion: PropTypes.string,
  requirementVersion: PropTypes.string
};