use crate::DataFormat;
use egui::{Align, Direction, Layout};
use polars::prelude::Column;
use std::sync::Arc;
pub const DEFAULT_OVERRIDE_REGEX: Option<&str> = Some("^Chave.*$");
const COL_SPECIAL: &[&str] = &["Alíq", "Aliq"]; const COL_DECIMAL: usize = 4;
pub fn get_decimal_and_layout(
column: &Column,
format: &Arc<DataFormat>,
) -> (Option<usize>, Layout) {
let column_name = column.name();
let dtype = column.dtype(); let decimal = format.decimal;
let is_special = COL_SPECIAL
.iter()
.any(|&special_name| column_name.contains(special_name));
let align = format.alignments.get(dtype).unwrap_or(&Align::LEFT);
if dtype.is_float() {
let selected_decimal = if is_special { COL_DECIMAL } else { decimal };
let layout = if is_special {
Layout::centered_and_justified(Direction::LeftToRight)
} else {
match *align {
Align::LEFT => Layout::left_to_right(Align::Center),
Align::Center => Layout::centered_and_justified(Direction::LeftToRight),
Align::RIGHT => Layout::right_to_left(Align::Center),
}
};
(Some(selected_decimal), layout)
} else if dtype.is_date() || dtype.is_bool() || dtype.is_integer() {
let layout = match *align {
Align::LEFT => Layout::left_to_right(Align::Center),
Align::Center => Layout::centered_and_justified(Direction::LeftToRight),
Align::RIGHT => Layout::right_to_left(Align::Center),
};
(None, layout)
} else {
let layout = match *align {
Align::LEFT => Layout::left_to_right(Align::Center),
Align::Center => Layout::centered_and_justified(Direction::LeftToRight),
Align::RIGHT => Layout::right_to_left(Align::Center),
};
(None, layout)
}
}