===== view.generated.mbt =====
// Generated by selene-xaml@0.37.3. DO NOT EDIT.
// input user fixtures/layout.xaml sha256=5075174f21bd648849e01037fc66e7b0295fab4bb3b916a20f444db226615dce
// input moon-info fixtures/layout.mbti sha256=85c67f6bba024f60b7895175644f2df66b31ca7a898cb862c9d9cc3f8c4c73b7

///|
type LayoutState = @model.LayoutState

///|
pub(all) enum LayoutViewAction {} derive(Eq, Debug)

///|
#warnings("-unused_value")
fn generated_rect_component(
  value : String,
  index : Int,
  path : String,
  image_region : Bool,
  corner_radius : Bool,
  non_negative : Bool,
) -> Double raise {
  @xaml_view.generated_view_rect_component(
    value,
    index,
    path,
    image_region,
    corner_radius~,
    non_negative~,
  )
}

///|
#warnings("-unused_value")
fn generated_image_drop_shadow(
  value : String,
  path : String,
) -> @xaml_view.ImageDropShadow? raise {
  @xaml_view.generated_view_image_drop_shadow(value, path)
}

///|
#warnings("-struct_never_constructed")
pub struct LayoutView {}

///|
let generated_runtime : @xaml_view.GeneratedViewRuntime[
  LayoutState,
  LayoutViewAction,
] = @xaml_view.GeneratedViewRuntime::new(generated_handle_event)

///|
/// World-isolated typed actions emitted by this view.
pub let action_event_bus : @event.Events[
  @xaml_view.GeneratedViewAction[LayoutViewAction],
] = generated_runtime.action_events()

///|
#warnings("-unused_error_type")
fn generated_specs(state : LayoutState) -> Array[@xaml_view.NodeSpec] raise {
  let nodes : Array[@xaml_view.NodeSpec] = []
  nodes.push({
    key: "root",
    parent: None,
    kind: @xaml_view.NodeKind::Flex,
    text: "",
    spans: [],
    source: "",
    path_geometry: None,
    active: true,
    enabled: true,
    focusable: false,
    tab_index: 0,
    focus_scope: false,
    auto_focus: false,
    navigation_up: "",
    navigation_down: "",
    navigation_left: "",
    navigation_right: "",
    automation_name: "",
    style: {
      ..@xaml_view.NodeStyle::default(),
      absolute: true,
      left: @xaml_view.LayoutValue::Px(12),
      right: @xaml_view.LayoutValue::Percent(0.05),
      width: @xaml_view.LayoutValue::Percent(1),
      height: @xaml_view.LayoutValue::Auto,
      min_width: @xaml_view.LayoutValue::Px(320),
      max_width: @xaml_view.LayoutValue::Percent(0.8),
      flex_wrap: @xaml_view.FlexWrap::WrapReverse,
      justify_content: @xaml_view.JustifyContent::SpaceEvenly,
      align_items: @xaml_view.AlignItems::Center,
      align_content: @xaml_view.AlignContent::SpaceBetween,
      horizontal_alignment: Some(@xaml_view.AlignItems::Center),
      vertical_alignment: Some(@xaml_view.AlignItems::End),
      flex_basis: @xaml_view.LayoutValue::Percent(0.25),
      flex_grow: 1,
      flex_shrink: 0,
    },
    visual_state_groups: [],
  })
  nodes.push({
    key: "label",
    parent: Some("root"),
    kind: @xaml_view.NodeKind::Text,
    text: "Layout",
    spans: [],
    source: "",
    path_geometry: None,
    active: true,
    enabled: true,
    focusable: false,
    tab_index: 0,
    focus_scope: false,
    auto_focus: false,
    navigation_up: "",
    navigation_down: "",
    navigation_left: "",
    navigation_right: "",
    automation_name: "",
    style: {
      ..@xaml_view.NodeStyle::default(),
      width: @xaml_view.LayoutValue::Px(state.label_width),
      height: @xaml_view.LayoutValue::Px(24),
      align_self: Some(@xaml_view.AlignItems::End),
    },
    visual_state_groups: [],
  })
  nodes
}

///|
/// Patches the consumed root ViewModel field label_width.
pub fn LayoutView::set_label_width(
  root : @entity.Entity,
  value : Double,
) -> Unit raise {
  let patches : Array[@xaml_view.GeneratedNodePatch[LayoutState]] = [
    {
      key: "label",
      update: fn(state, spec) {
        {
          ..spec,
          style: {
            ..spec.style,
            width: @xaml_view.LayoutValue::Px(state.label_width),
          },
        }
      },
    },
  ]
  generated_runtime.patch_nodes(
    root,
    fn(store) { store.val = { ..store.val, label_width: value } },
    patches,
  )
}

///|
/// Mounts this view on an alive root entity in the current world.
/// Destroying the root ends the view lifetime.
pub fn LayoutView::mount(
  entity : @entity.Entity,
  view_model : LayoutState,
) -> Unit raise {
  let desired = generated_specs(view_model)
  generated_runtime.mount(entity, view_model, desired)
}

///|
/// Releases this View while leaving its caller-owned root entity alive.
pub fn LayoutView::unmount(entity : @entity.Entity) -> Unit raise {
  generated_runtime.unmount(entity)
}

///|
/// Reconciles this mounted View with a new ViewModel.
pub fn LayoutView::replace(
  entity : @entity.Entity,
  view_model : LayoutState,
) -> Unit raise {
  let desired = generated_specs(view_model)
  generated_runtime.replace(entity, view_model, desired)
}

///|
#warnings("-unused_value")
fn generated_handle_event(
  view_model : LayoutState,
  event : @xaml_view.UiEvent,
) -> LayoutViewAction? {
  None
}

///|
/// Installs this View below a root generated View that owns the shared host.
pub fn component_plugin(app : @app.App) -> @app.App {
  generated_runtime.install_component(app, "selene_xaml_LayoutView_events")
}

///|
/// Installs the shared host and this View package component tree.
pub fn plugin(app : @app.App) -> @app.App {
  app.add_plugin(@xaml_view.plugin).add_plugin(component_plugin)
}

