import { Button, Dialog, DialogActions, DialogContent, DialogTitle, FormControl, MenuItem, Select, Typography } from '@mui/material';
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
import PropTypes from 'prop-types';
import { baseLanguages } from '@blocklet/constant';
import { getLanguageLabel } from './constants';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export default function AddLanguageDialog({
  open,
  onClose,
  existingLanguages,
  selectedLanguage,
  onLanguageChange,
  onAdd
}) {
  const {
    t
  } = useLocaleContext();
  const availableLanguages = baseLanguages.filter(lang => !existingLanguages.includes(lang.code));
  return /*#__PURE__*/_jsxs(Dialog, {
    open: open,
    onClose: onClose,
    maxWidth: "xs",
    fullWidth: true,
    children: [/*#__PURE__*/_jsx(DialogTitle, {
      children: t('authentication.didConnect.addLanguage')
    }), /*#__PURE__*/_jsx(DialogContent, {
      children: /*#__PURE__*/_jsx(FormControl, {
        fullWidth: true,
        sx: {
          mt: 1
        },
        children: /*#__PURE__*/_jsx(Select, {
          value: selectedLanguage,
          onChange: e => onLanguageChange(e.target.value),
          displayEmpty: true,
          size: "small",
          renderValue: value => value ? getLanguageLabel(value) : /*#__PURE__*/_jsx(Typography, {
            color: "text.secondary",
            children: t('authentication.didConnect.selectLanguage')
          }),
          children: availableLanguages.map(lang => /*#__PURE__*/_jsx(MenuItem, {
            value: lang.code,
            children: lang.name
          }, lang.code))
        })
      })
    }), /*#__PURE__*/_jsxs(DialogActions, {
      children: [/*#__PURE__*/_jsx(Button, {
        onClick: onClose,
        children: t('common.cancel')
      }), /*#__PURE__*/_jsx(Button, {
        onClick: onAdd,
        variant: "contained",
        disabled: !selectedLanguage,
        children: t('common.add')
      })]
    })]
  });
}
AddLanguageDialog.propTypes = {
  open: PropTypes.bool.isRequired,
  onClose: PropTypes.func.isRequired,
  existingLanguages: PropTypes.array.isRequired,
  selectedLanguage: PropTypes.string.isRequired,
  onLanguageChange: PropTypes.func.isRequired,
  onAdd: PropTypes.func.isRequired
};