import { useRef, useState, useMemo } from 'react'
import { useLocation } from 'react-router-dom'
import { Card, Flex, Space } from 'antd'
import { LoadingOutlined } from '@ant-design/icons'
import ActionHandler from '../../common/ActionHandler'
import AuditLogIcon from '../../../Icons/AuditLogIcon'
import DocumentPrintButton from '../../common/DocumentPrintButton'
import EditButtons from '../../common/EditButtons'
import ObjectTableNavigationButtons from '../../common/ObjectTableNavigationButtons.jsx'
import HotEndIcon from '../../../Icons/HotEndIcon'
import InfoCircleIcon from '../../../Icons/InfoCircleIcon'
import MultiMotionIcon from '../../../Icons/MultiMotionIcon'
import PictureIcon from '../../../Icons/PictureIcon'
import RulerIcon from '../../../Icons/RulerIcon'
import InfoCollapse from '../../common/InfoCollapse'
import InfoCollapsePlaceholder from '../../common/InfoCollapsePlaceholder'
import ActivityIndicator from '../../common/ActivityIndicator'
import NoteIcon from '../../../Icons/NoteIcon'
import NotesPanel from '../../common/NotesPanel'
import ObjectActions from '../../common/ObjectActions'
import { useDashboardObjectTools } from '../../context/DashboardObjectToolsContext'
import ObjectForm from '../../common/ObjectForm'
import ObjectInfo from '../../common/ObjectInfo'
import ObjectTable from '../../common/ObjectTable'
import ScrollBox from '../../common/ScrollBox'
import UserNotifierToggle from '../../common/UserNotifierToggle'
import ViewButton from '../../common/ViewButton'
import useCollapseState from '../../hooks/useCollapseState'
import ObjectProperty from '../../common/ObjectProperty'
import { getModelProperty, getModelByName } from '../../../../database/ObjectModels'
import GCodeFileIcon from '../../../Icons/GCodeFileIcon'
import SettingsIcon from '../../../Icons/SettingsIcon'
import ExclamationOctagonIcon from '../../../Icons/ExclamationOctagonIcon'
const PrinterProfileInfo = () => {
const location = useLocation()
const objectFormRef = useRef(null)
const actionHandlerRef = useRef(null)
const printerProfileId = new URLSearchParams(location.search).get(
'printerProfileId'
)
const [collapseState, updateCollapseState] = useCollapseState(
'PrinterProfileInfo',
{
info: true,
dimensions: true,
bedExcludeArea: true,
extruders: true,
motion: true,
gCodeSettings: true,
optional: true,
thumbnails: true,
notes: true,
auditLogs: false
}
)
const [objectFormState, setObjectFormState] = useState({
isEditing: false,
editLoading: false,
formValid: false,
lock: null,
loading: false,
editDisabled: false,
objectData: {}
})
const currentObjectTools = useMemo(
() => (
),
[objectFormState.loading, printerProfileId]
)
useDashboardObjectTools(currentObjectTools)
const actions = {
edit: () => {
objectFormRef.current?.startEditing?.()
return false
},
cancelEdit: () => {
objectFormRef.current?.cancelEditing?.()
return true
},
finishEdit: () => {
objectFormRef.current?.handleUpdate?.()
return true
},
delete: () => {
objectFormRef.current?.handleDelete?.()
return true
}
}
return (
actionHandlerRef.current.callAction('finishEdit')
}
cancelEditing={() =>
actionHandlerRef.current.callAction('cancelEdit')
}
startEditing={() => actionHandlerRef.current.callAction('edit')}
editLoading={objectFormState.editLoading}
formValid={objectFormState.formValid}
disabled={
objectFormState.beingEditedByOther ||
objectFormState.loading ||
objectFormState.editDisabled
}
loading={objectFormState.editLoading}
/>
setObjectFormState((current) => ({ ...current, ...state }))
}
>
{({ loading, isEditing, objectData }) => (
}
active={collapseState.info}
onToggle={(expanded) =>
updateCollapseState('info', expanded)
}
collapseKey='info'
>
}
isEditing={isEditing}
type='printerProfile'
objectData={objectData}
labelWidth='140px'
visibleProperties={{
_id: true,
name: true,
_reference: true,
printer: true,
createdAt: true,
updatedAt: true
}}
/>
}
active={collapseState.dimensions}
onToggle={(expanded) =>
updateCollapseState('dimensions', expanded)
}
collapseKey='dimensions'
>
}
isEditing={isEditing}
type='printerProfile'
objectData={objectData}
labelWidth='230px'
visibleProperties={{
printBedWidth: true,
printBedHeight: true,
originX: true,
originY: true,
printableHeight: true,
supportMultiBedTypes: true,
bestObjectPositionX: true,
bestObjectPositionY: true,
zOffset: true,
preferredOrientation: true
}}
/>
}
active={collapseState.bedExcludeArea}
onToggle={(expanded) =>
updateCollapseState('bedExcludeArea', expanded)
}
collapseKey='bedExcludeArea'
>
}
active={collapseState.extruders}
onToggle={(expanded) =>
updateCollapseState('extruders', expanded)
}
collapseKey='extruders'
>
}
active={collapseState.motion}
onToggle={(expanded) =>
updateCollapseState('motion', expanded)
}
collapseKey='motion'
>
}
isEditing={isEditing}
type='printerProfile'
objectData={objectData}
labelWidth='225px'
visibleProperties={{
machineMaxAccelerationRetracting: true,
machineMaxSpeedE: true,
machineMaxSpeedX: true,
machineMaxSpeedY: true,
machineMaxJunctionDeviation: true
}}
/>
}
active={collapseState.gCodeSettings}
onToggle={(expanded) =>
updateCollapseState('gCodeSettings', expanded)
}
collapseKey='gCodeSettings'
>
}
isEditing={isEditing}
type='printerProfile'
objectData={objectData}
labelWidth='240px'
visibleProperties={{
machinePauseGcode: true,
machineStartGcode: true,
machineEndGcode: true,
layerChangeGcode: true,
beforeLayerChangeGcode: true
}}
/>
}
active={collapseState.miscellaneous}
onToggle={(expanded) =>
updateCollapseState('miscellaneous', expanded)
}
collapseKey='miscellaneous'
>
}
isEditing={isEditing}
type='printerProfile'
objectData={objectData}
labelWidth='210px'
visibleProperties={{
printerNotes: true,
scanFirstLayer: true,
machineLoadFilamentTime: true,
machineUnloadFilamentTime: true,
auxiliaryFan: true
}}
/>
}
active={collapseState.thumbnails}
onToggle={(expanded) =>
updateCollapseState('thumbnails', expanded)
}
collapseKey='thumbnails'
>
)}
}
active={collapseState.notes}
onToggle={(expanded) => updateCollapseState('notes', expanded)}
collapseKey='notes'
>
}
active={collapseState.auditLogs}
onToggle={(expanded) => updateCollapseState('auditLogs', expanded)}
collapseKey='auditLogs'
>
{objectFormState.loading ? (
) : (
)}
)
}
export default PrinterProfileInfo