// generated by bun run generate from the SwiftUI SDK and codegen/catalog.ts.
// edit the generator or catalog, then regenerate.
#import "OneNativeStoreViewComponentView.h"
#import <React/RCTView.h>
#import "One-Swift.h"
#import "OneNativeStoreViewShadowNode.h"
#import "OneNativeMeasuredHeight.h"
#import <react/renderer/components/OneNativeSpec/EventEmitters.h>
#import <React/RCTConversions.h>
#import "OneNativeStyleDictionary.h"
using namespace facebook::react;
@implementation OneNativeStoreViewComponentView { OneNativeStoreViewView *_nativeView; OneNativeMeasuredHeight *_measured; BOOL _idsDirty; }
+ (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<OneNativeStoreViewComponentDescriptor>(); }
- (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 OneNativeStoreViewProps>();
    _idsDirty = YES;
    _measured = [OneNativeMeasuredHeight new];
    _nativeView = [OneNativeStoreViewView new]; self.contentView = _nativeView;
    __weak OneNativeStoreViewComponentView *weakSelf = self;
    _nativeView.onSDKEvent = ^(NSString *name, NSString *value) {
      OneNativeStoreViewComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeStoreViewEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeSDKEvent({.name = std::string(name.UTF8String), .value = std::string(value.UTF8String)});
    };
    _nativeView.onHeight = ^(CGFloat height) {
      OneNativeStoreViewComponentView *strongSelf = weakSelf;
      if (strongSelf) [strongSelf->_measured update:height];
    };
  }
  return self;
}
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
  const auto &next = *std::static_pointer_cast<const OneNativeStoreViewProps>(props);
  const auto &previous = *std::static_pointer_cast<const OneNativeStoreViewProps>(_props);
  bool idsChanged = _idsDirty || previous.ids.size() != next.ids.size();
  if (!idsChanged) for (size_t i = 0; i < next.ids.size(); i++) {
    if (previous.ids[i] != next.ids[i]) { idsChanged = true; break; }
  }
  if (idsChanged) {
    NSMutableArray *ids = [NSMutableArray new];
    for (const auto &item : next.ids) [ids addObject:RCTNSStringFromString(item)];
    [_nativeView setIds:ids];
    _idsDirty = 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.prefersPromotionalIcon
    ];

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