// generated by bun run generate from the SwiftUI SDK and codegen/catalog.ts.
// edit the generator or catalog, then regenerate.
#import "OneNativeMeshGradientComponentView.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 OneNativeMeshGradientComponentView { OneNativeMeshGradientView *_nativeView; BOOL _colorsDirty; }
+ (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<OneNativeMeshGradientComponentDescriptor>(); }
- (NSObject *)accessibilityElement { return _nativeView; }
- (instancetype)initWithFrame:(CGRect)frame {
  if (self = [super initWithFrame:frame]) {
    _props = std::make_shared<const OneNativeMeshGradientProps>();
    _colorsDirty = YES;
    _nativeView = [OneNativeMeshGradientView new]; self.contentView = _nativeView;
    __weak OneNativeMeshGradientComponentView *weakSelf = self;
    _nativeView.onSDKEvent = ^(NSString *name, NSString *value) {
      OneNativeMeshGradientComponentView *strongSelf = weakSelf;
      if (!strongSelf || !strongSelf->_eventEmitter) return;
      auto emitter = std::static_pointer_cast<const OneNativeMeshGradientEventEmitter>(strongSelf->_eventEmitter);
      emitter->onNativeSDKEvent({.name = std::string(name.UTF8String), .value = std::string(value.UTF8String)});
    };
  }
  return self;
}
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
  const auto &next = *std::static_pointer_cast<const OneNativeMeshGradientProps>(props);
  const auto &previous = *std::static_pointer_cast<const OneNativeMeshGradientProps>(_props);
  bool colorsChanged = _colorsDirty || previous.colors.size() != next.colors.size();
  if (!colorsChanged) for (size_t i = 0; i < next.colors.size(); i++) {
    if (previous.colors[i] != next.colors[i]) { colorsChanged = true; break; }
  }
  if (colorsChanged) {
    NSMutableArray *colors = [NSMutableArray new];
    for (const auto &item : next.colors) [colors addObject:RCTNSStringFromString(item)];
    [_nativeView setColors:colors];
    _colorsDirty = 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.meshWidth
    meshHeight:next.meshHeight points:RCTNSStringFromString(next.points) background:RCTNSStringFromString(next.background) smoothsColors:next.smoothsColors colorSpace:RCTNSStringFromString(next.colorSpace)];

  [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 = next.accessibilityLabel.empty() && !next.testId.empty() ? RCTNSStringFromString(next.testId) : nil;
}
- (void)prepareForRecycle { [super prepareForRecycle]; [_nativeView reset]; _colorsDirty = YES; }
@end
