// generated by bun run generate from the SwiftUI SDK and codegen/catalog.ts.
// edit the generator or catalog, then regenerate.
#import "OneNativeTextFieldComponentView.h"
#import <React/RCTView.h>
#import "One-Swift.h"
#import "OneNativeSyncBridge.h"
#import "OneNativeTextFieldShadowNode.h"
#import "OneNativeMeasuredHeight.h"
#import <react/renderer/components/OneNativeSpec/EventEmitters.h>
#import <React/RCTConversions.h>
#import "OneNativeStyleDictionary.h"
using namespace facebook::react;
@implementation OneNativeTextFieldComponentView { OneNativeTextFieldView *_nativeView; OneNativeMeasuredHeight *_measured; int32_t _syncStateId; }
+ (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<OneNativeTextFieldComponentDescriptor>(); }
- (NSObject *)accessibilityElement { return _nativeView; }
- (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState { [_measured adopt:state]; }
- (instancetype)initWithFrame:(CGRect)frame {
  if (self = [super initWithFrame:frame]) {
    _props = std::make_shared<const OneNativeTextFieldProps>();
    _measured = [OneNativeMeasuredHeight new];
    _nativeView = [OneNativeTextFieldView new]; self.contentView = _nativeView;
    __weak OneNativeTextFieldComponentView *weakSelf = self;
    _nativeView.onSDKEvent = ^(NSString *name, NSString *value) {
      OneNativeTextFieldComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeTextFieldEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeSDKEvent({.name = std::string(name.UTF8String), .value = std::string(value.UTF8String)});
    };
    _nativeView.onHeight = ^(CGFloat height) {
      OneNativeTextFieldComponentView *strongSelf = weakSelf;
      if (strongSelf) [strongSelf->_measured update:height];
    };
    _nativeView.onChange = ^(NSString *value, NSInteger eventCount, NSInteger revision) {
      OneNativeTextFieldComponentView *strongSelf = weakSelf;
      if (strongSelf && strongSelf->_syncStateId != 0) { OneNativeSyncDidSetExternally(strongSelf->_syncStateId); }
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeTextFieldEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeTextFieldValueChange({.value = std::string(value.UTF8String), .eventCount = (int)eventCount, .revision = (int)revision});
    };
    _nativeView.onFocusChange = ^(BOOL value, NSInteger eventCount, NSInteger revision) {
      OneNativeTextFieldComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeTextFieldEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeTextFieldFocusChange({.value = (bool)value, .eventCount = (int)eventCount, .revision = (int)revision});
    };
    _nativeView.onSubmit = ^(NSInteger eventCount) {
      OneNativeTextFieldComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeTextFieldEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeTextFieldSubmit({.eventCount = (int)eventCount});
    };
  }
  return self;
}
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
  const auto &next = *std::static_pointer_cast<const OneNativeTextFieldProps>(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)];
  _syncStateId = next.syncStateId;
  [_nativeView configure:RCTNSStringFromString(next.value)
    acknowledgedEvent:next.acknowledgedEvent revision:next.revision syncStateId:next.syncStateId focused:next.focused acknowledgedFocusEvent:next.acknowledgedFocusEvent focusRevision:next.focusRevision label:RCTNSStringFromString(next.label) disabled:next.disabled prompt:RCTNSStringFromString(next.prompt) textFieldStyle:RCTNSStringFromString(next.textFieldStyle) submitLabel:RCTNSStringFromString(next.submitLabel) textInputAutocapitalization:RCTNSStringFromString(next.textInputAutocapitalization) autocorrectionDisabled:next.autocorrectionDisabled keyboardType:RCTNSStringFromString(next.keyboardType) textContentType:RCTNSStringFromString(next.textContentType) axis:RCTNSStringFromString(next.axis)];

  [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]; [_measured reset]; }
@end
