import React, { useState, useEffect } from 'react';
import {
PageSection,
Divider,
Tabs,
Tab,
TabTitleText,
} from '@patternfly/react-core';
import { translate as __ } from 'foremanReact/common/I18n';
import PropTypes from 'prop-types';
import { networkSelected } from './ProxmoxVmUtils';
import ProxmoxComputeSelectors from './ProxmoxComputeSelectors';
import ProxmoxServerStorage from './ProxmoxServer/ProxmoxServerStorage';
import ProxmoxServerOptions from './ProxmoxServer/ProxmoxServerOptions';
import ProxmoxServerNetwork from './ProxmoxServer/ProxmoxServerNetwork';
import ProxmoxServerHardware from './ProxmoxServer/ProxmoxServerHardware';
import ProxmoxContainerNetwork from './ProxmoxContainer/ProxmoxContainerNetwork';
import ProxmoxContainerOptions from './ProxmoxContainer/ProxmoxContainerOptions';
import ProxmoxContainerStorage from './ProxmoxContainer/ProxmoxContainerStorage';
import ProxmoxContainerHardware from './ProxmoxContainer/ProxmoxContainerHardware';
import InputField from './common/FormInputs';
import GeneralTabContent from './GeneralTabContent';
const ProxmoxVmType = ({
vmAttrs,
nodes,
images,
pools,
fromProfile,
newVm,
storages,
bridges,
registerComp,
untemplatable,
}) => {
const nodesMap =
nodes.length > 0
? nodes.map(node => ({ value: node.node, label: node.node }))
: [];
const imagesMap =
images.length > 0
? [
{ value: '', label: '' },
...images.map(image => ({
value: image.uuid,
label: image.name,
})),
]
: [];
const poolsMap =
pools.length > 0
? [
{ value: '', label: '' },
...pools.map(pool => ({
value: pool.poolid,
label: pool.poolid,
})),
]
: [];
const [activeTabKey, setActiveTabKey] = useState(0);
const handleTabClick = (event, tabIndex) => {
setActiveTabKey(tabIndex);
};
const [general, setGeneral] = useState(vmAttrs);
const paramScope = fromProfile
? 'compute_attribute[vm_attrs]'
: 'host[compute_attributes]';
const [filteredBridges, setFilteredBridges] = useState([]);
useEffect(() => {
if (!registerComp && !fromProfile) {
networkSelected(general?.type?.value);
}
}, [general?.type?.value]);
useEffect(() => {
if (!registerComp) {
const filtered = bridges.filter(
bridge => bridge.node_id === general?.nodeId?.value
);
setFilteredBridges(filtered);
}
}, [general?.nodeId?.value, bridges]);
if (registerComp) {
return null;
}
const componentMap = {
qemu: {
options: