//
//  UIDevice+XXGDevice.m
//  XXGPlayKit
//
//  Created by apple on 2025/4/29.
//

#import "UIDevice+XXGDevice.h"
#import "XXGWindowManager.h"
@import UIKit;

@implementation UIDevice (XXGDevice)

static NSInteger isIPad = -1;
+ (BOOL)isIPad {
    if (isIPad < 0) {
        isIPad = [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad ? 1 : 0;
    }
    return isIPad > 0;
}

+ (BOOL)hasNotch {
    if (@available(iOS 11.0, *)) {
        // 1. 获取当前窗口的安全区域
        UIWindow *window = XXGWindowManager.shared.xxpk_currentWindow;
        
        UIEdgeInsets safeArea = window.safeAreaInsets;
        
        // 2. 仅针对 iPhone 设备判断
        BOOL isiPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone);
        
        // 3. 核心判断逻辑（横竖屏兼容）
        return isiPhone && (
            safeArea.top > 20.0 ||          // 竖屏状态下的刘海屏
            safeArea.left > 0 ||            // 横屏左侧刘海（如 iPhone X）
            safeArea.right > 0              // 横屏右侧刘海（如 iPhone 14 Pro）
        );
    }
    return NO; // iOS 11 以下无刘海屏
}

@end
