// generated by bun run generate from the SwiftUI SDK and codegen/catalog.ts.
// edit the generator or catalog, then regenerate.
#import "OneNativeSignInWithAppleButtonComponentView.h"
#import <React/RCTView.h>
#import "One-Swift.h"
#import "OneNativeSignInWithAppleButtonShadowNode.h"
#import "OneNativeMeasuredHeight.h"
#import <react/renderer/components/OneNativeSpec/EventEmitters.h>
#import <React/RCTConversions.h>
#import "OneNativeStyleDictionary.h"
using namespace facebook::react;
@implementation OneNativeSignInWithAppleButtonComponentView { OneNativeSignInWithAppleButtonView *_nativeView; OneNativeMeasuredHeight *_measured; BOOL _requestedScopesDirty; }
+ (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<OneNativeSignInWithAppleButtonComponentDescriptor>(); }
- (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 OneNativeSignInWithAppleButtonProps>();
    _requestedScopesDirty = YES;
    _measured = [OneNativeMeasuredHeight new];
    _nativeView = [OneNativeSignInWithAppleButtonView new]; self.contentView = _nativeView;
    __weak OneNativeSignInWithAppleButtonComponentView *weakSelf = self;
    _nativeView.onSDKEvent = ^(NSString *name, NSString *value) {
      OneNativeSignInWithAppleButtonComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeSignInWithAppleButtonEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeSDKEvent({.name = std::string(name.UTF8String), .value = std::string(value.UTF8String)});
    };
    _nativeView.onHeight = ^(CGFloat height) {
      OneNativeSignInWithAppleButtonComponentView *strongSelf = weakSelf;
      if (strongSelf) [strongSelf->_measured update:height];
    };
    _nativeView.onCompletion = ^(NSString *type, NSString *user, NSString *email, NSString *givenName, NSString *familyName, NSString *identityToken, NSString *authorizationCode, NSString *message, NSInteger eventCount) {
      OneNativeSignInWithAppleButtonComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeSignInWithAppleButtonEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeSignInWithAppleButtonCompletion({.type = std::string(type.UTF8String), .user = std::string(user.UTF8String), .email = std::string(email.UTF8String), .givenName = std::string(givenName.UTF8String), .familyName = std::string(familyName.UTF8String), .identityToken = std::string(identityToken.UTF8String), .authorizationCode = std::string(authorizationCode.UTF8String), .message = std::string(message.UTF8String), .eventCount = (int)eventCount});
    };
  }
  return self;
}
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
  const auto &next = *std::static_pointer_cast<const OneNativeSignInWithAppleButtonProps>(props);
  const auto &previous = *std::static_pointer_cast<const OneNativeSignInWithAppleButtonProps>(_props);
  bool requestedScopesChanged = _requestedScopesDirty || previous.requestedScopes.size() != next.requestedScopes.size();
  if (!requestedScopesChanged) for (size_t i = 0; i < next.requestedScopes.size(); i++) {
    if (previous.requestedScopes[i] != next.requestedScopes[i]) { requestedScopesChanged = true; break; }
  }
  if (requestedScopesChanged) {
    NSMutableArray *requestedScopes = [NSMutableArray new];
    for (const auto &item : next.requestedScopes) [requestedScopes addObject:RCTNSStringFromString(item)];
    [_nativeView setRequestedScopes:requestedScopes];
    _requestedScopesDirty = NO;
  }

  [_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.nonce)
    label:RCTNSStringFromString(next.label)];

  [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]; _requestedScopesDirty = YES; }
@end
