#import "CSMaskedView.h"

#ifdef RCT_NEW_ARCH_ENABLED
#import <react/renderer/components/ContentsquareBridge/ComponentDescriptors.h>
#import <react/renderer/components/ContentsquareBridge/RCTComponentViewHelpers.h>

#import <React/RCTFabricComponentsPlugins.h>

using namespace facebook::react;

@interface CSMaskedView () <RCTCSMaskedViewViewProtocol>
#else
@interface CSMaskedView ()
#endif

@end

@implementation CSMaskedView {
  UIView *_view;
}

#if !RCT_NEW_ARCH_ENABLED

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
  // Try to hit subviews first
  for (UIView *subview in [self.subviews reverseObjectEnumerator]) {
    CGPoint convertedPoint = [subview convertPoint:point fromView:self];
    UIView *hitSubview = [subview hitTest:convertedPoint withEvent:event];
    if (hitSubview != nil) {
      return hitSubview;
    }
  }

  return nil;
}
#endif

#ifdef RCT_NEW_ARCH_ENABLED
+ (ComponentDescriptorProvider)componentDescriptorProvider {
  return concreteComponentDescriptorProvider<CSMaskedViewComponentDescriptor>();
}

Class<RCTComponentViewProtocol> CSMaskedViewCls(void) {
  return CSMaskedView.class;
}
#endif

@end
