//! The main pane allows the user to view the definition of a
//! [`Relation`] or the data [`Field`]s within a Relation.

use ratatui::widgets::{Table, TableState};
use tui_dialog::Dialog;

use crate::{fields::Field, relations::Relation};

pub struct MainPane<'mt> {
    pub mode: Mode,
    pub data: Vec<Vec<Field>>,     // Actual data
    pub table: Option<Table<'mt>>, // Data as table
    pub table_state: TableState,
    pub page: usize,
    pub count: usize,
    pub num_pages: usize,
    pub horizontal_scroll: u16,
    pub horizontal_max: u16,
    pub vertical_scroll: u16,
    pub vertical_max: u16,
    pub sort: Sort,
    pub delete_dialog: Dialog,
    pub filter_dialog: Dialog,
}

/// Variations of the main pane.
#[derive(PartialEq)]
pub enum Mode {
    DataDefinition,
    Data,
}

#[derive(Default)]
pub struct Sort {
    pub relation: Option<Relation>,
    pub field: Option<String>,
    pub order: SortOrder,
}

#[derive(Debug, Default)]
pub enum SortOrder {
    #[default]
    Ascending,
    Descending,
}
