import React, { useMemo } from 'react';
import { Box, Stack } from '@mui/material';
import Alert from '@mui/material/Alert';
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
import { isAccessible } from '@blocklet/meta/lib/util';
import DomainListWithPermission from './component/domain-list';
import DomainActionCard from './component/domain-action-card';
import { isServerless } from './util';
import { useBlockletContext } from '../contexts/blocklet';
import { useNodeContext } from '../contexts/node';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export default function BlockletDomains() {
  const {
    blocklet,
    actions: {
      updateBlockletDomainAliases
    }
  } = useBlockletContext();
  const {
    inService
  } = useNodeContext();
  const {
    t
  } = useLocaleContext();
  const hasMutatePermission = useMemo(() => {
    let res = true;
    if (isServerless(blocklet)) {
      res = res && inService;
    }
    return res;
  }, [inService, blocklet]);
  return /*#__PURE__*/_jsxs(Box, {
    component: Stack,
    sx: {
      gap: 3,
      maxWidth: 820
    },
    children: [/*#__PURE__*/_jsxs(_Fragment, {
      children: [isAccessible(blocklet.status) === false && /*#__PURE__*/_jsx(Alert, {
        severity: "warning",
        children: t('blocklet.router.noRunning')
      }), hasMutatePermission && /*#__PURE__*/_jsx(DomainActionCard, {
        blocklet: blocklet,
        updateBlockletDomainAliases: updateBlockletDomainAliases,
        connectDomainProps: {
          shouldCheckDomain: true
        }
      })]
    }), /*#__PURE__*/_jsx(DomainListWithPermission, {
      showAllDomains: true,
      updateBlockletDomainAliases: updateBlockletDomainAliases
    })]
  });
}