// generated by bun run generate from the SwiftUI SDK and codegen/catalog.ts.
// edit the generator or catalog, then regenerate.
#import "OneNativeFileImporterComponentView.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 OneNativeFileImporterComponentView { OneNativeFileImporterView *_nativeView; BOOL _allowedContentTypesDirty; }
+ (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<OneNativeFileImporterComponentDescriptor>(); }
- (NSObject *)accessibilityElement { return _nativeView; }
- (instancetype)initWithFrame:(CGRect)frame {
  if (self = [super initWithFrame:frame]) {
    _props = std::make_shared<const OneNativeFileImporterProps>();
    _allowedContentTypesDirty = YES;
    _nativeView = [OneNativeFileImporterView new]; self.contentView = _nativeView;
    __weak OneNativeFileImporterComponentView *weakSelf = self;
    _nativeView.onSDKEvent = ^(NSString *name, NSString *value) {
      OneNativeFileImporterComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeFileImporterEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeSDKEvent({.name = std::string(name.UTF8String), .value = std::string(value.UTF8String)});
    };
    _nativeView.onChange = ^(BOOL value, NSInteger eventCount, NSInteger revision) {
      OneNativeFileImporterComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeFileImporterEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeFileImporterValueChange({.value = (bool)value, .eventCount = (int)eventCount, .revision = (int)revision});
    };
    _nativeView.onCompletion = ^(NSString *type, NSString *url, double index, double count, NSString *message, NSInteger eventCount) {
      OneNativeFileImporterComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeFileImporterEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeFileImporterCompletion({.type = std::string(type.UTF8String), .url = std::string(url.UTF8String), .index = (double)index, .count = (double)count, .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 OneNativeFileImporterProps>(props);
  const auto &previous = *std::static_pointer_cast<const OneNativeFileImporterProps>(_props);
  bool allowedContentTypesChanged = _allowedContentTypesDirty || previous.allowedContentTypes.size() != next.allowedContentTypes.size();
  if (!allowedContentTypesChanged) for (size_t i = 0; i < next.allowedContentTypes.size(); i++) {
    if (previous.allowedContentTypes[i] != next.allowedContentTypes[i]) { allowedContentTypesChanged = true; break; }
  }
  if (allowedContentTypesChanged) {
    NSMutableArray *allowedContentTypes = [NSMutableArray new];
    for (const auto &item : next.allowedContentTypes) [allowedContentTypes addObject:RCTNSStringFromString(item)];
    [_nativeView setAllowedContentTypes:allowedContentTypes];
    _allowedContentTypesDirty = 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 allowsMultipleSelection:next.allowsMultipleSelection];

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