===== moon.pkg =====
import {
  "example/model",
  "example/generated/missing_child" @child,
  "KKKIIO/selene/app",
  "KKKIIO/selene/entity",
  "KKKIIO/selene/event",
  "KKKIIO/selene/xaml_view",
}

supported_targets = "native+js"

===== view.generated.mbt =====
// Generated by selene-xaml@0.37.3. DO NOT EDIT.
// input user ui_xaml/root.xaml sha256=175088cb4bfced9c77d4e15ddf84f47dd61d257f5c91219faaa6f0f96670c6a1
// input moon-info model/pkg.generated.mbti sha256=58977c76ae83b1993f3a5eb8467eb5fe786cdb7023cbb1942d5ccc70f8ab0975

///|
type RootViewModel = @model.RootViewModel

///|
pub(all) enum RootViewAction {} 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 RootView {}

///|
let generated_runtime : @xaml_view.GeneratedViewRuntime[
  RootViewModel,
  RootViewAction,
] = @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[RootViewAction],
] = generated_runtime.action_events()

///|
/// ViewModel components mounted by this View in the current World.
pub fn RootView::view_models() -> Map[@entity.Entity, RootViewModel] {
  generated_runtime.view_models()
}

///|
#warnings("-unused_error_type")
fn generated_specs(state : RootViewModel) -> Array[@xaml_view.NodeSpec] raise {
  let nodes : Array[@xaml_view.NodeSpec] = []
  nodes.push({
    key: "node-root-view",
    parent: None,
    kind: @xaml_view.NodeKind::View,
    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() },
    visual_state_groups: [],
  })
  nodes.push({
    key: "child",
    parent: Some("node-root-view"),
    kind: @xaml_view.NodeKind::View,
    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() },
    visual_state_groups: [],
  })
  nodes
}

///|
/// Refreshes presentation dependencies rooted at child.
pub fn RootView::refresh_child(root : @entity.Entity) -> Unit raise {
  let refreshes : Array[@xaml_view.GeneratedNodeRefresh[RootViewModel]] = []
  generated_runtime.refresh_nodes(root, refreshes)
  @child.MissingChildView::replace(
    RootView::child(root),
    generated_runtime.view_model(root).child,
  )
}

///|
/// Returns the mounted root owned by the named child View.
pub fn RootView::child(root : @entity.Entity) -> @entity.Entity raise {
  match @xaml_view.ViewHost::new().entity(root, "child") {
    Some(value) => value
    None => fail("component placeholder is missing: child")
  }
}

///|
/// Mounts this view on an alive root entity in the current world.
/// Destroying the root ends the view lifetime.
pub fn RootView::mount(
  entity : @entity.Entity,
  view_model : RootViewModel,
) -> Unit raise {
  let desired = generated_specs(view_model)
  generated_runtime.mount(entity, view_model, desired)
  let host = @xaml_view.ViewHost::new()
  let generated_component_0 = match host.entity(entity, "child") {
    Some(value) => value
    None => fail("component placeholder is missing: child")
  }
  @child.MissingChildView::mount(generated_component_0, view_model.child)
}

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

///|
/// Refreshes the complete presentation from the current ViewModel component.
pub fn RootView::refresh(entity : @entity.Entity) -> Unit raise {
  let view_model = generated_runtime.view_model(entity)
  let desired = generated_specs(view_model)
  generated_runtime.refresh(entity, desired)
  let host = @xaml_view.ViewHost::new()
  match host.entity(entity, "child") {
    Some(target) => @child.MissingChildView::replace(target, view_model.child)
    None => fail("component placeholder is missing: child")
  }
}

///|
/// Reconciles this mounted View with a new ViewModel.
pub fn RootView::replace(
  entity : @entity.Entity,
  view_model : RootViewModel,
) -> Unit raise {
  let desired = generated_specs(view_model)
  generated_runtime.replace(entity, view_model, desired)
  let host = @xaml_view.ViewHost::new()
  match host.entity(entity, "child") {
    Some(target) => @child.MissingChildView::replace(target, view_model.child)
    None => fail("component placeholder is missing: child")
  }
}

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

///|
/// Installs this View below a root generated View that owns the shared host.
pub fn component_plugin(app : @app.App) -> @app.App {
  let app = app.add_plugin(@child.component_plugin)
  generated_runtime.install_component(app, "selene_xaml_RootView_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)
}

===== view.generated.mbt.map.json =====
{
  "mappings": []
}

