use crate::io::config::interaction::NodeGraphInteractionConfig;
use crate::io::tuning::NodeGraphRuntimeTuning;

use super::NodeGraphInteractionState;

impl NodeGraphInteractionState {
    pub fn from_parts(
        config: &NodeGraphInteractionConfig,
        runtime_tuning: &NodeGraphRuntimeTuning,
    ) -> Self {
        Self {
            elements_selectable: config.elements_selectable,
            nodes_draggable: config.nodes_draggable,
            nodes_connectable: config.nodes_connectable,
            nodes_deletable: config.nodes_deletable,
            nodes_focusable: config.nodes_focusable,
            edges_selectable: config.edges_selectable,
            edges_deletable: config.edges_deletable,
            edges_focusable: config.edges_focusable,
            edges_reconnectable: config.edges_reconnectable,
            connection_mode: config.connection_mode,
            connection_radius: config.connection_radius,
            reconnect_radius: config.reconnect_radius,
            reconnect_on_drop_empty: config.reconnect_on_drop_empty,
            edge_interaction_width: config.edge_interaction_width,
            bezier_hit_test_steps: config.bezier_hit_test_steps,
            spatial_index: runtime_tuning.spatial_index,
            only_render_visible_elements: runtime_tuning.only_render_visible_elements,
            elevate_nodes_on_select: config.elevate_nodes_on_select,
            elevate_edges_on_select: config.elevate_edges_on_select,
            paint_cache_prune: runtime_tuning.paint_cache_prune,
            snap_to_grid: config.snap_to_grid,
            snap_grid: config.snap_grid,
            snaplines: config.snaplines,
            snaplines_threshold: config.snaplines_threshold,
            pan_on_scroll: config.pan_on_scroll,
            pan_on_drag: config.pan_on_drag,
            selection_on_drag: config.selection_on_drag,
            select_nodes_on_drag: config.select_nodes_on_drag,
            selection_mode: config.selection_mode,
            box_select_edges: config.box_select_edges,
            selection_key: config.selection_key,
            multi_selection_key: config.multi_selection_key,
            delete_key: config.delete_key,
            nudge_step_mode: config.nudge_step_mode,
            nudge_step_px: config.nudge_step_px,
            nudge_fast_step_px: config.nudge_fast_step_px,
            disable_keyboard_a11y: config.disable_keyboard_a11y,
            pane_click_distance: config.pane_click_distance,
            pan_activation_key_code: config.pan_activation_key_code,
            space_to_pan: config.space_to_pan,
            pan_on_scroll_speed: config.pan_on_scroll_speed,
            pan_on_scroll_mode: config.pan_on_scroll_mode,
            pan_inertia: config.pan_inertia.clone(),
            zoom_on_scroll: config.zoom_on_scroll,
            zoom_on_scroll_speed: config.zoom_on_scroll_speed,
            zoom_on_pinch: config.zoom_on_pinch,
            zoom_on_pinch_speed: config.zoom_on_pinch_speed,
            zoom_on_double_click: config.zoom_on_double_click,
            frame_view_duration_ms: config.frame_view_duration_ms,
            frame_view_ease: config.frame_view_ease,
            frame_view_padding: config.frame_view_padding,
            reroute_on_edge_double_click: config.reroute_on_edge_double_click,
            edge_insert_on_alt_drag: config.edge_insert_on_alt_drag,
            zoom_activation_key: config.zoom_activation_key,
            node_drag_threshold: config.node_drag_threshold,
            node_drag_handle_mode: config.node_drag_handle_mode,
            node_click_distance: config.node_click_distance,
            connection_drag_threshold: config.connection_drag_threshold,
            connect_on_click: config.connect_on_click,
            auto_pan: config.auto_pan.clone(),
            translate_extent: config.translate_extent,
            node_extent: config.node_extent,
            node_origin: config.node_origin,
        }
    }

    pub fn config(&self) -> NodeGraphInteractionConfig {
        NodeGraphInteractionConfig {
            elements_selectable: self.elements_selectable,
            nodes_draggable: self.nodes_draggable,
            nodes_connectable: self.nodes_connectable,
            nodes_deletable: self.nodes_deletable,
            nodes_focusable: self.nodes_focusable,
            edges_selectable: self.edges_selectable,
            edges_deletable: self.edges_deletable,
            edges_focusable: self.edges_focusable,
            edges_reconnectable: self.edges_reconnectable,
            connection_mode: self.connection_mode,
            connection_radius: self.connection_radius,
            reconnect_radius: self.reconnect_radius,
            reconnect_on_drop_empty: self.reconnect_on_drop_empty,
            edge_interaction_width: self.edge_interaction_width,
            bezier_hit_test_steps: self.bezier_hit_test_steps,
            elevate_nodes_on_select: self.elevate_nodes_on_select,
            elevate_edges_on_select: self.elevate_edges_on_select,
            snap_to_grid: self.snap_to_grid,
            snap_grid: self.snap_grid,
            snaplines: self.snaplines,
            snaplines_threshold: self.snaplines_threshold,
            pan_on_scroll: self.pan_on_scroll,
            pan_on_drag: self.pan_on_drag,
            selection_on_drag: self.selection_on_drag,
            select_nodes_on_drag: self.select_nodes_on_drag,
            selection_mode: self.selection_mode,
            box_select_edges: self.box_select_edges,
            selection_key: self.selection_key,
            multi_selection_key: self.multi_selection_key,
            delete_key: self.delete_key,
            nudge_step_mode: self.nudge_step_mode,
            nudge_step_px: self.nudge_step_px,
            nudge_fast_step_px: self.nudge_fast_step_px,
            disable_keyboard_a11y: self.disable_keyboard_a11y,
            pane_click_distance: self.pane_click_distance,
            pan_activation_key_code: self.pan_activation_key_code,
            space_to_pan: self.space_to_pan,
            pan_on_scroll_speed: self.pan_on_scroll_speed,
            pan_on_scroll_mode: self.pan_on_scroll_mode,
            pan_inertia: self.pan_inertia.clone(),
            zoom_on_scroll: self.zoom_on_scroll,
            zoom_on_scroll_speed: self.zoom_on_scroll_speed,
            zoom_on_pinch: self.zoom_on_pinch,
            zoom_on_pinch_speed: self.zoom_on_pinch_speed,
            zoom_on_double_click: self.zoom_on_double_click,
            frame_view_duration_ms: self.frame_view_duration_ms,
            frame_view_ease: self.frame_view_ease,
            frame_view_padding: self.frame_view_padding,
            reroute_on_edge_double_click: self.reroute_on_edge_double_click,
            edge_insert_on_alt_drag: self.edge_insert_on_alt_drag,
            zoom_activation_key: self.zoom_activation_key,
            node_drag_threshold: self.node_drag_threshold,
            node_drag_handle_mode: self.node_drag_handle_mode,
            node_click_distance: self.node_click_distance,
            connection_drag_threshold: self.connection_drag_threshold,
            connect_on_click: self.connect_on_click,
            auto_pan: self.auto_pan.clone(),
            translate_extent: self.translate_extent,
            node_extent: self.node_extent,
            node_origin: self.node_origin,
        }
    }

    pub fn runtime_tuning(&self) -> NodeGraphRuntimeTuning {
        NodeGraphRuntimeTuning {
            spatial_index: self.spatial_index,
            only_render_visible_elements: self.only_render_visible_elements,
            paint_cache_prune: self.paint_cache_prune,
        }
    }

    pub fn split(&self) -> (NodeGraphInteractionConfig, NodeGraphRuntimeTuning) {
        (self.config(), self.runtime_tuning())
    }
}
