// generated by bun run generate from the SwiftUI SDK and codegen/catalog.ts.
// edit the generator or catalog, then regenerate.
#import "OneNativeConfirmationDialogComponentView.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 OneNativeConfirmationDialogComponentView { OneNativeConfirmationDialogView *_nativeView; BOOL _actionsDirty; }
+ (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<OneNativeConfirmationDialogComponentDescriptor>(); }
- (NSObject *)accessibilityElement { return _nativeView; }
- (instancetype)initWithFrame:(CGRect)frame {
  if (self = [super initWithFrame:frame]) {
    _props = std::make_shared<const OneNativeConfirmationDialogProps>();
    _actionsDirty = YES;
    _nativeView = [OneNativeConfirmationDialogView new]; self.contentView = _nativeView;
    __weak OneNativeConfirmationDialogComponentView *weakSelf = self;
    _nativeView.onSDKEvent = ^(NSString *name, NSString *value) {
      OneNativeConfirmationDialogComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeConfirmationDialogEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeSDKEvent({.name = std::string(name.UTF8String), .value = std::string(value.UTF8String)});
    };
    _nativeView.onChange = ^(BOOL value, NSInteger eventCount, NSInteger revision) {
      OneNativeConfirmationDialogComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeConfirmationDialogEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeConfirmationDialogValueChange({.value = (bool)value, .eventCount = (int)eventCount, .revision = (int)revision});
    };
    _nativeView.onAction = ^(NSString *id, NSString *presenting, NSInteger eventCount) {
      OneNativeConfirmationDialogComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeConfirmationDialogEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeConfirmationDialogAction({.id = std::string(id.UTF8String), .presenting = std::string(presenting.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 OneNativeConfirmationDialogProps>(props);
  const auto &previous = *std::static_pointer_cast<const OneNativeConfirmationDialogProps>(_props);
  bool actionsChanged = _actionsDirty || previous.actions.size() != next.actions.size();
  if (!actionsChanged) for (size_t i = 0; i < next.actions.size(); i++) {
    if (previous.actions[i].id != next.actions[i].id || previous.actions[i].label != next.actions[i].label || previous.actions[i].role != next.actions[i].role) { actionsChanged = true; break; }
  }
  if (actionsChanged) {
    NSMutableArray *actions = [NSMutableArray new];
    for (const auto &item : next.actions) [actions addObject:@{@"id": RCTNSStringFromString(item.id), @"label": RCTNSStringFromString(item.label), @"role": RCTNSStringFromString(item.role)}];
    [_nativeView setActions:actions];
    _actionsDirty = 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:next.value
    acknowledgedEvent:next.acknowledgedEvent revision:next.revision title:RCTNSStringFromString(next.title) message:RCTNSStringFromString(next.message) presenting:RCTNSStringFromString(next.presenting) hasPresenting:next.hasPresenting titleVisibility:RCTNSStringFromString(next.titleVisibility)];

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