// SPDX-License-Identifier: EUPL-1.2+ // SPDX-FileCopyrightText: 2025 Johannes Süllner use super::{ BUTTON_TEXT_SIZE, Event, MARGIN_LR, MARGIN_VERTICAL, Page, TITLE_TEXT_SIZE, UpdateResult, WINDOW_WIDTH, }; use crate::{center_horizontal_in_container, destination_device::DestinationDevice}; use iced::{ Length, Task, widget::{checkbox, column, container, space, text}, }; pub struct PageConfirmation { device: DestinationDevice, install_confirmed: bool, } impl PageConfirmation { pub fn new(device: DestinationDevice) -> Self { Self { device, install_confirmed: false, } } } #[derive(Clone, Debug)] pub enum PageConfirmationEvent { Back, ConfirmCheckboxToggled(bool), StartInstallation, } impl Page for PageConfirmation { fn update(&mut self, event: Event) -> UpdateResult { if let Event::PageConfirmation(page_event) = event { match page_event { PageConfirmationEvent::Back => { return ( Some(Box::new(super::disk_selection::PageDiskSelection::new())), Task::none(), ); } PageConfirmationEvent::ConfirmCheckboxToggled(bool) => { self.install_confirmed = bool; } PageConfirmationEvent::StartInstallation => { return ( Some(Box::new(super::installation::PageInstallation::new( self.device.clone(), ))), Task::none(), ); } } } (None, Task::none()) } fn view(&self) -> iced::Element<'_, Event> { let main_content = column![ space().height(Length::Fill), center_horizontal_in_container!(text("Confirm Installation").size(TITLE_TEXT_SIZE)), space().height(MARGIN_VERTICAL), center_horizontal_in_container!(text( "Erase all data on the following device and install Spectrum?" )), space().height(MARGIN_VERTICAL), center_horizontal_in_container!( container(super::layout::disk_element(&self.device)) .width(WINDOW_WIDTH - 2.0 * MARGIN_LR) ), space().height(MARGIN_VERTICAL), center_horizontal_in_container!( checkbox(self.install_confirmed) .label(format!( "I understand all data on {} will be lost", self.device.name )) .on_toggle(|bool| Event::PageConfirmation( PageConfirmationEvent::ConfirmCheckboxToggled(bool) )) ), space().height(Length::Fill), ]; super::layout::bottom_buttons_layout( [[ ( text("Back").size(BUTTON_TEXT_SIZE).into(), Some(Event::PageConfirmation(PageConfirmationEvent::Back)), ), ( text("Start installation").size(BUTTON_TEXT_SIZE).into(), if self.install_confirmed { Some(Event::PageConfirmation( PageConfirmationEvent::StartInstallation, )) } else { None }, ), ]], main_content.into(), ) } }