Files
comparador-notas/src/ui/screens/layouts.rs
T
2026-03-04 12:25:08 -03:00

98 lines
3.1 KiB
Rust

use crate::domain::entities::layout::{Layout, TipoArquivo};
use crate::ui::app::App;
use crate::ui::message::Message;
use crate::ui::theme as t;
use iced::widget::{button, column, container, horizontal_space, row, scrollable, text};
use iced::{Alignment, Element, Length};
/// Tela de gerenciamento de layouts.
pub fn view(app: &App) -> Element<'_, Message> {
let cabecalho = row![
button("Voltar")
.on_press(Message::IrParaImportacao)
.style(t::btn_secondary),
horizontal_space(),
button("Importar JSON")
.on_press(Message::ImportarLayoutJson)
.style(t::btn_ghost),
]
.spacing(8)
.align_y(Alignment::Center)
.width(Length::Fill);
let titulo = text("Gerenciar Layouts").size(22).color(t::TEXT);
let secao_csv = view_secao_layouts("Layouts CSV", &app.layouts_salvos, TipoArquivo::Csv);
let secao_xlsx = view_secao_layouts("Layouts XLSX", &app.layouts_salvos, TipoArquivo::Xlsx);
let content = column![titulo, cabecalho, secao_csv, secao_xlsx,]
.spacing(16)
.padding(20)
.width(Length::Fill);
container(scrollable(content))
.width(Length::Fill)
.height(Length::Fill)
.style(t::fundo)
.into()
}
fn view_secao_layouts<'a>(
titulo: &'a str,
layouts: &'a [Layout],
tipo: TipoArquivo,
) -> Element<'a, Message> {
let titulo_widget = text(titulo).size(16).color(t::TEXT_SECONDARY);
let filtrados: Vec<&Layout> = layouts.iter().filter(|l| l.tipo() == tipo).collect();
let mut col = column![titulo_widget].spacing(4);
if filtrados.is_empty() {
col = col.push(text("(nenhum layout salvo)").size(13).color(t::TEXT_MUTED));
return container(col)
.padding([12, 16])
.width(Length::Fill)
.style(t::card)
.into();
}
for layout in filtrados {
if let Some(id) = layout.id() {
let linha = container(
row![
text(layout.nome())
.size(14)
.color(t::TEXT)
.width(Length::Fill),
horizontal_space(),
button("Carregar")
.on_press(Message::LayoutSelecionado(id))
.style(t::btn_primary),
button("Exportar JSON")
.on_press(Message::ExportarLayoutJson(id))
.style(t::btn_ghost),
button("Excluir")
.on_press(Message::ExcluirLayout(id))
.style(t::btn_danger),
]
.spacing(8)
.align_y(Alignment::Center)
.padding([10, 0]),
)
.width(Length::Fill);
col = col.push(linha);
// Separador entre linhas
col = col.push(container(iced::widget::horizontal_rule(1)).width(Length::Fill));
}
}
container(col)
.padding([12, 16])
.width(Length::Fill)
.style(t::card)
.into()
}