export const appdelegate_header_snippet = `#import <Smartech/Smartech.h>`;

export const appdelegateSnippet = {
  fileName: 'AppDelegate.h',
  smartechHeaderSnippet: '#import <Smartech/Smartech.h>',
  hanselHeaderSnippet: '#import <SmartechNudges/Hansel.h>'

}

export const swiftImports = {
  smartechImport: 'import Smartech',
  hanselImport: 'import SmartechNudges'
}

export const smartechBaseSnippet = {
  smartechInit: `[[Smartech sharedInstance] initSDKWithDelegate:self withLaunchOptions:launchOptions];`,
  debugLevel: `[[Smartech sharedInstance] setDebugLevel:SMTLogLevelVerbose];`,
  trackAppInstallUpdateBySmartech: `[[Smartech sharedInstance] trackAppInstallUpdateBySmartech];`,
  hanselLogSnippet: `[Hansel enableDebugLogs];`,
  didfinishRegex: /\(\s*BOOL\s*\)\s*application:(UIApplication\s*)application\s*didFinishLaunchingWithOptions:\s*\(NSDictionary\s*\*\)\s*launchOptions/,
  regexPattern: /application\s*:\s*\(UIApplication\s*\*\)\s*application\s*didFinishLaunchingWithOptions\s*:\s*\(NSDictionary\s*\*\)\s*launchOptions/
  //   // didfinishRegex: /\[super application:application didFinishLaunchingWithOptions/
}

export const smartechBaseSwiftSnippet = {
  smartechInit: `Smartech.sharedInstance().initSDK(with: self, withLaunchOptions: launchOptions)`,
  debugLevel: `Smartech.sharedInstance().setDebugLevel(.verbose)`,
  trackAppInstallUpdateBySmartech: `Smartech.sharedInstance().trackAppInstallUpdateBySmartech()`,
  hanselLogSnippet: `Hansel.enableDebugLogs()`,
  // Updated regex to handle multiline method signatures and optional keywords
  didFinishLaunchingRegex: /(?:public\s+)?(?:override\s+)?func\s+application\s*\(/,
  openURLRegex: /(?:public\s+)?(?:override\s+)?func\s+application\s*\(\s*_\s+app:/
}



export const deepLinkHandlerSnippet = (delayInSeconds: number) => {

  const delayValue = typeof delayInSeconds === 'number' && delayInSeconds > 0
    ? delayInSeconds
    : 1.5;

  return [
    "#pragma mark - SmartechDelegate Method",
    "- (void)handleDeeplinkActionWithURLString:(NSString *)deeplinkURLString andNotificationPayload:(NSDictionary *_Nullable)notificationPayload {",

    `dispatch_after(dispatch_time(DISPATCH_TIME_NOW, ${delayValue} * NSEC_PER_SEC), dispatch_get_main_queue(), ^{`,
    'NSLog(@"SMTLOGGER DEEPLINK: %@",deeplinkURLString);',
    '[[NSNotificationCenter defaultCenter] postNotificationName:kSMTDeeplinkNotificationIdentifier object:nil userInfo:notificationPayload];',
    "});",
    "}",
    "\n",
  ].join("\n");
}

export const deepLinkHandlerSwiftSnippet = (delayInSeconds: number) => {

  const delayValue = typeof delayInSeconds === 'number' && delayInSeconds > 0
    ? delayInSeconds
    : 1.5;

  return [
    "    // MARK: - SmartechDelegate Method",
    "   public func handleDeeplinkAction(withURLString deeplinkURLString: String, andNotificationPayload notificationPayload: [AnyHashable : Any]?) {",
    `        DispatchQueue.main.asyncAfter(deadline: .now() + ${delayValue}) {`,
    '            print("SMTLOGGER DEEPLINK: \\(deeplinkURLString)")',
    '            NotificationCenter.default.post(name: NSNotification.Name("SmartechDeeplink"), object: nil, userInfo: notificationPayload)',
    "        }",
    "    }",
    "",
  ].join("\n");
}

