def main():
    global MAX_PINGS, MAX_WORKERS
    
    app = QApplication(sys.argv)
    tab_widget = QTabWidget()
    
    # Main widget and layout setup
    main_widget = QWidget()
    main_layout = QVBoxLayout(main_widget)

    # Top-right layout for host label
    top_right_layout = QHBoxLayout()
    host_label = QLabel()
    host_label.setAlignment(Qt.AlignRight | Qt.AlignTop)
    host_label.setStyleSheet("font-size: 12pt; color: black; padding-right: 10px;")
    top_right_layout.addStretch()
    top_right_layout.addWidget(host_label)
    
    # Bottom-right layout for clock label
    bottom_right_layout = QHBoxLayout()
    clock_label = QLabel()
    clock_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
    clock_label.setStyleSheet("font-size: 12pt;")
    bottom_right_layout.addStretch()
    bottom_right_layout.addWidget(clock_label)
    
    # Layout for the center widget
    center_layout = QVBoxLayout()
    center_layout.addWidget(tab_widget)
    
    # Create a duplicate overlay layout
    overlay_layout = QHBoxLayout()  # or QHBoxLayout() depending on your needs
    overlay_layout.addLayout(center_layout)
    overlay_layout.addLayout(top_right_layout)

    # Add the overlay layout to the main layout
    main_layout.addLayout(overlay_layout)
    main_layout.addLayout(bottom_right_layout)
    
    main_widget.setLayout(main_layout)
    main_widget.setWindowTitle("Server Monitor - Alert")
    main_widget.setGeometry(300, 300, 1100, 600)
    
    # Function to update labels
    def update_labels():
        current_time = QTime.currentTime().toString("hh:mm:ss")
        current_date = QDate.currentDate().toString("dd MMM yyyy")
        
        total_hosts = len(host_info_dict)
        offline_hosts = len(offline_dict)
        online_hosts = total_hosts - offline_hosts
        
        host_label.setText(f"Total: {total_hosts}   Offline: {offline_hosts}   Online: {online_hosts}")
        clock_label.setText(f"{current_date} - {current_time}")
    
    timer = QTimer()
    timer.timeout.connect(update_labels)
    timer.start(1000)  # Update every 1000ms (1 second)

    # Create tabs
    main_window = OfflineHostMonitor(None, None, None, None)
    tab_widget.addTab(main_window, "Monitor")
    return_online_widget = ReturnOnlineWidget()
    tab_widget.addTab(return_online_widget, "Return Online")
    settings_widget = SettingsWidget(None, None, None, None, None, tab_widget, main_window)
    tab_widget.addTab(settings_widget, "Settings")
    main_window.settings_widget = settings_widget
    
    # Show main widget
    main_widget.show()
    
    # File handling and threading setup
    file_path = 'hostname.txt'
    offline_state_file = 'offline_state.json'
    if not os.path.exists(file_path):
        QMessageBox.critical(None, "File Not Found", "The file 'hostname.txt' was not found. Exiting the application.")
        sys.exit()
    host_info_list, hostname_count = read_host_list(file_path)
    print(f"Number of hostnames in file: {hostname_count}")
    if not host_info_list:
        sys.exit()
    offline_dict = load_offline_state(offline_state_file)
    host_info_dict = {hostname.upper(): (hostname, store_name, telephone, wan_a, wan_b) for hostname, store_name, telephone, wan_a, wan_b in host_info_list}
    offline_dict = {hostname: details for hostname, details in offline_dict.items() if hostname in host_info_dict}
    
    queue = Queue()
    stop_event = threading.Event()
    cpu_count = psutil.cpu_count(logical=True)
    memory = psutil.virtual_memory()
    available_memory_gb = memory.available / (1024 ** 2)
    max_pings_based_on_memory = int(available_memory_gb / 0.1)
    MAX_PINGS = min(MAX_PINGS, max_pings_based_on_memory)
    semaphore = threading.Semaphore(MAX_PINGS)
    
    main_window.queue = queue
    main_window.offline_dict = offline_dict
    main_window.stop_event = stop_event
    main_window.semaphore = semaphore
    settings_widget.queue = queue
    settings_widget.offline_dict = offline_dict
    settings_widget.stop_event = stop_event
    settings_widget.semaphore = semaphore
    settings_widget.host_info_list = host_info_list
    return_online_signal = return_online_widget.dataUpdated
    
    for hostname, (host, store_name, telephone, wan_a, wan_b) in host_info_dict.items():
        threading.Thread(
            target=monitor_host,
            args=((host, store_name, telephone, wan_a, wan_b), queue, offline_dict, stop_event, semaphore, settings_widget.main_window),
            daemon=True
        ).start()
    
    threading.Thread(
        target=update_offline_list,
        args=(queue, offline_dict, stop_event, return_online_signal, settings_widget),
        daemon=True
    ).start()
    
    app.aboutToQuit.connect(lambda: save_offline_state(offline_state_file, offline_dict))
    app.aboutToQuit.connect(main_window.stop_all_threads)
    
    sys.exit(app.exec_())

duplicate overlay host_lable and tab label