#ifndef RCT_NEW_ARCH_ENABLED

#import "BasePaperComponent.h"

// MARK: - Flow-specific Manager

@interface RCTFlowManager : RCTBasePaperComponentManager
@end

@implementation RCTFlowManager

RCT_EXPORT_MODULE(FlowPaper);

- (instancetype)init
{
    return [super initWithComponentType:RCTCheckoutComponentTypeFlow];
}

RCT_EXPORT_VIEW_PROPERTY(config, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(onDimensionsChanged, RCTBubblingEventBlock);

RCT_EXPORT_METHOD(submit:(nonnull NSNumber *)reactTag) {
    [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTBasePaperComponent *> *viewRegistry) {
        RCTBasePaperComponent *view = viewRegistry[reactTag];
        if (view && [view isKindOfClass:[RCTBasePaperComponent class]]) {
            [view submit];
        }
    }];
}

RCT_EXPORT_METHOD(tokenize:(nonnull NSNumber *)reactTag) {
    [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTBasePaperComponent *> *viewRegistry) {
        RCTBasePaperComponent *view = viewRegistry[reactTag];
        if (view && [view isKindOfClass:[RCTBasePaperComponent class]]) {
            [view tokenize];
        }
    }];
}

RCT_EXPORT_METHOD(update:(nonnull NSNumber *)reactTag
                  amount:(NSInteger)amount
                  currency:(NSString *)currency) {
    [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTBasePaperComponent *> *viewRegistry) {
        RCTBasePaperComponent *view = viewRegistry[reactTag];
        if (view && [view isKindOfClass:[RCTBasePaperComponent class]]) {
            [view update:amount currency:currency];
        }
    }];
}

@end

#endif
