// generated by bun run generate from the SwiftUI SDK and codegen/catalog.ts.
// edit the generator or catalog, then regenerate.
import SwiftUI

struct OneNativePopoverRoot: View {
  @ObservedObject var model: OneNativePopoverModel
  @ObservedObject var children: OneNativeChildren
  // composed, the parent lays the trigger out and measures it; only a standalone
  // popover answers to Yoga.
  let standalone: Bool
  var body: some View {
    VStack(alignment: .leading, spacing: 0) {
      ForEach(children.items) { child in child.content }
    }
    .popover(
      isPresented: Binding(
        get: { model.controlled.value && model.content != nil },
        set: { value in model.change(value) }
      ),
      arrowEdge: OneNativeGenerated.edge(model.arrowEdge)
    ) {
      if let content = model.content {
        // SwiftUI sizes a popover from its content and a React Native subtree has no
        // ideal size, so the box is explicit.
        OneNativeSlot(content: content, mode: .presented, onLayout: { frame in
          if model.active && model.controlled.value { model.onLayout?(frame) }
        })
        .frame(width: model.contentWidth, height: model.contentHeight)
        .oneNativePresentationCompactAdaptation(model.presentationCompactAdaptation)
      }
    }
    // the popover anchors to the trigger's own bounds, so the stack hugs it and this
    // outer frame is what puts the trigger at the leading edge, as a host does.
    .frame(maxWidth: .infinity, alignment: .leading)
    .oneNativeMeasured(standalone, model.onHeight)
  }
}
