// generated by bun run generate from the SwiftUI SDK and codegen/catalog.ts.
// edit the generator or catalog, then regenerate.
#import "OneNativeWebViewComponentView.h"
#import <React/RCTView.h>
#import "One-Swift.h"
#import <react/renderer/components/OneNativeSpec/ComponentDescriptors.h>
#import <react/renderer/components/OneNativeSpec/EventEmitters.h>
#import <React/RCTConversions.h>
#import "OneNativeStyleDictionary.h"
using namespace facebook::react;
@implementation OneNativeWebViewComponentView { OneNativeWebViewView *_nativeView; }
+ (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<OneNativeWebViewComponentDescriptor>(); }
- (NSObject *)accessibilityElement { return _nativeView; }
- (instancetype)initWithFrame:(CGRect)frame {
  if (self = [super initWithFrame:frame]) {
    _props = std::make_shared<const OneNativeWebViewProps>();
    _nativeView = [OneNativeWebViewView new]; self.contentView = _nativeView;
    __weak OneNativeWebViewComponentView *weakSelf = self;
    _nativeView.onSDKEvent = ^(NSString *name, NSString *value) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeSDKEvent({.name = std::string(name.UTF8String), .value = std::string(value.UTF8String)});
    };
    _nativeView.onNavigate = ^(NSString *url, NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewNavigate({.url = std::string(url.UTF8String), .eventCount = (int)eventCount});
    };
    _nativeView.onTitleChange = ^(NSString *title, NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewTitleChange({.title = std::string(title.UTF8String), .eventCount = (int)eventCount});
    };
    _nativeView.onLoadingChange = ^(BOOL loading, double progress, NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewLoadingChange({.loading = (bool)loading, .progress = (double)progress, .eventCount = (int)eventCount});
    };
    _nativeView.onLoadStart = ^(NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewLoadStart({.eventCount = (int)eventCount});
    };
    _nativeView.onLoadEnd = ^(NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewLoadEnd({.eventCount = (int)eventCount});
    };
    _nativeView.onError = ^(NSString *message, NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewError({.message = std::string(message.UTF8String), .eventCount = (int)eventCount});
    };
    _nativeView.onHttpError = ^(double statusCode, NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewHttpError({.statusCode = (double)statusCode, .eventCount = (int)eventCount});
    };
    _nativeView.onMessage = ^(NSString *data, NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewMessage({.data = std::string(data.UTF8String), .eventCount = (int)eventCount});
    };
    _nativeView.onHistoryChange = ^(BOOL canGoBack, BOOL canGoForward, NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewHistoryChange({.canGoBack = (bool)canGoBack, .canGoForward = (bool)canGoForward, .eventCount = (int)eventCount});
    };
    _nativeView.onProcessTerminate = ^(NSInteger eventCount) {
      OneNativeWebViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeWebViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeWebViewProcessTerminate({.eventCount = (int)eventCount});
    };
  }
  return self;
}
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
  const auto &next = *std::static_pointer_cast<const OneNativeWebViewProps>(props);


  [_nativeView configureAccessibility:RCTNSStringFromString(next.accessibilityLabel)
    hint:RCTNSStringFromString(next.accessibilityHint)
    value:RCTNSStringFromString(next.accessibilityValue.text.value_or(""))
    identifier:RCTNSStringFromString(next.testId)];
  [_nativeView configureStyle:OneNativeStyleDictionary(next.swiftStyle)];
  [_nativeView configure:RCTNSStringFromString(next.url)
    html:RCTNSStringFromString(next.html) script:RCTNSStringFromString(next.script) command:RCTNSStringFromString(next.command) commandRevision:next.commandRevision commandValue:RCTNSStringFromString(next.commandValue) limitsNavigationsToAppBoundDomains:next.limitsNavigationsToAppBoundDomains inlineMedia:next.inlineMedia inspectable:next.inspectable bounces:next.bounces backForwardNavigationGestures:RCTNSStringFromString(next.backForwardNavigationGestures) magnificationGestures:RCTNSStringFromString(next.magnificationGestures) linkPreviews:RCTNSStringFromString(next.linkPreviews) elementFullscreen:RCTNSStringFromString(next.elementFullscreen) contentBackground:RCTNSStringFromString(next.contentBackground)];

  [super updateProps:props oldProps:oldProps];
  // the swiftui element that is the control carries testID (OneNativeAccessibility), so a test
  // taps the control and not the centre of its wider host. the host keeps it only while
  // that element is hidden.
  self.accessibilityIdentifier = nil;
  _nativeView.accessibilityIdentifier = nil;
}
- (void)prepareForRecycle { [super prepareForRecycle]; [_nativeView reset]; }
@end
