#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/**
* Native (template/Express) UIComponent middle layer (refer to AppLovinMAXAdViewUIComponent design).
 *
* **Not responsible for loading** - loading is triggered by `ATNative.makeAdRequest()` on the JS side (by using Bridge.loadNativeAd
* → ATNativeManager.loadNativeWith), offer has been cached internally in the SDK.
 *
* UIComponent is only responsible for "consuming loaded ads":
* 1. attachIfNeeded calls [ATAdManager getNativeAdOfferWithplacementID:] to get the cache offer
* 2. Construct ATNativeADView rendering (only template Express; self-rendering pending viewTag binding)
* 3. addSubview to hostView
 *
* Why not loadAd here?
* - If ComponentView also calls loadAd, it will conflict with the loading process of ATNative on the JS side (two sets of delegate,
* SDK loading twice), resulting in duplicate/out of order ad rendering.
* - The JS side process `await native.getNativeAd()` has ensured that there is offer in the cache when mounting ComponentView.
 *
* The timing is right:
* - When updateProps calls attachIfNeeded for the first time, hostView may not be layout (bounds=0) yet, skipping;
* - layoutSubviews triggers attachIfNeeded again (the attached guard is guaranteed to be idempotent).
 */
@interface ATNativeUIComponent : NSObject

- (instancetype)initWithHostView:(UIView *)hostView
                     placementID:(NSString *)placementID;

/// Idempotent: Try to get the ad offer from the SDK cache and render it to hostView.
/// Safely skip if hostView.bounds is zero or offer is not ready.
- (void)attachIfNeeded;

/// In the self-rendering scenario, the SDK will internally reset selfRenderView.frame back to 0×0 in rendererWithConfiguration:.
/// Called by ATRNNativeAdView.layoutSubviews, each time layout arranges selfRenderView and the child view frame.
- (void)syncLayout;

- (void)destroy;

/// The user point is destroyed after closing/dislike, and prevents layoutSubviews from attaching again.
- (void)destroyFromUserClose;

@end

NS_ASSUME_NONNULL_END
