# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QAction, QLineEdit
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl


class Browser(QMainWindow):

    def __init__(self):
        super().__init__()

        self.browser = QWebEngineView()
        self.browser.setUrl(QUrl("https://www.google.com"))
        self.setCentralWidget(self.browser)

        navbar = QToolBar()
        self.addToolBar(navbar)

        back_btn = QAction("Voltar", self)
        back_btn.triggered.connect(self.browser.back)
        back_btn.setObjectName("back_btn")
        navbar.addAction(back_btn)

        forward_btn = QAction("Avançar", self)
        forward_btn.triggered.connect(self.browser.forward)
        forward_btn.setObjectName("forward_btn")
        navbar.addAction(forward_btn)

        reload_btn = QAction("Recarregar", self)
        reload_btn.triggered.connect(self.browser.reload)
        reload_btn.setObjectName("reload_btn")
        navbar.addAction(reload_btn)

        home_btn = QAction("Home", self)
        home_btn.triggered.connect(self.go_home)
        home_btn.setObjectName("home_btn")
        navbar.addAction(home_btn)

        self.url_bar = QLineEdit()
        self.url_bar.returnPressed.connect(self.navigate_to_url)
        navbar.addWidget(self.url_bar)

        self.browser.urlChanged.connect(self.update_url)

        self.show()

    def go_home(self):
        self.browser.setUrl(QUrl("https://www.google.com"))

    def navigate_to_url(self):
        url = self.url_bar.text()
        self.browser.setUrl(QUrl(url))

    def update_url(self, q):
        self.url_bar.setText(q.toString())


app = QApplication(sys.argv)
QApplication.setApplicationName("Netscape Navigator")

# Tema Netscape embutido diretamente no código
tema_netscape = """
/* Tema Netscape Navigator - Estilo Vintage */

QMainWindow {
    background-color: #C0C0C0;
    border: 2px solid #808080;
}

/* Toolbar estilo Netscape */
QToolBar {
    background-color: #D4D0C8;
    border: 2px solid;
    border-top-color: #FFFFFF;
    border-left-color: #FFFFFF;
    border-right-color: #808080;
    border-bottom-color: #808080;
    padding: 3px;
    spacing: 3px;
}

QToolBar::separator {
    width: 6px;
    background-color: #808080;
    margin: 2px 1px;
}

/* Botões estilo Windows 95/Netscape */
QToolButton {
    background-color: #D4D0C8;
    border: 2px solid;
    border-top-color: #FFFFFF;
    border-left-color: #FFFFFF;
    border-right-color: #808080;
    border-bottom-color: #808080;
    padding: 3px 8px;
    color: #000000;
    font-family: "MS Sans Serif", "Arial", sans-serif;
    font-size: 11px;
    font-weight: bold;
    min-width: 60px;
}

QToolButton:hover {
    background-color: #E0E0E0;
    border-top-color: #FFFFFF;
    border-left-color: #FFFFFF;
    border-right-color: #404040;
    border-bottom-color: #404040;
}

QToolButton:pressed {
    border-top-color: #808080;
    border-left-color: #808080;
    border-right-color: #FFFFFF;
    border-bottom-color: #FFFFFF;
    background-color: #C0C0C0;
}

/* Barra de URL estilo Netscape */
QLineEdit {
    background-color: #FFFFFF;
    border: 2px solid;
    border-top-color: #808080;
    border-left-color: #808080;
    border-right-color: #FFFFFF;
    border-bottom-color: #FFFFFF;
    padding: 3px 5px;
    font-family: "Courier New", monospace;
    font-size: 12px;
    min-height: 20px;
    min-width: 300px;
}

QLineEdit:focus {
    background-color: #FFFFE0;
    border-top-color: #000000;
    border-left-color: #000000;
}

/* Área do navegador - borda vintage */
QWebEngineView {
    border: 3px solid;
    border-top-color: #808080;
    border-left-color: #808080;
    border-right-color: #FFFFFF;
    border-bottom-color: #FFFFFF;
    background-color: #FFFFFF;
}

/* Scrollbars estilo vintage */
QScrollBar:vertical {
    border: 2px solid;
    border-top-color: #FFFFFF;
    border-left-color: #FFFFFF;
    border-right-color: #808080;
    border-bottom-color: #808080;
    background: #D4D0C8;
    width: 16px;
    margin: 0px;
}

QScrollBar::handle:vertical {
    background: #C0C0C0;
    border: 2px solid;
    border-top-color: #FFFFFF;
    border-left-color: #FFFFFF;
    border-right-color: #808080;
    border-bottom-color: #808080;
    min-height: 20px;
}

QScrollBar::handle:vertical:hover {
    background: #A0A0A0;
}

QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {
    border: 2px solid;
    border-top-color: #FFFFFF;
    border-left-color: #FFFFFF;
    border-right-color: #808080;
    border-bottom-color: #808080;
    background: #C0C0C0;
    height: 16px;
}

/* Ícones de placeholder para os botões (usando texto) */
QToolButton#back_btn {
    qproperty-text: "◀";
    font-size: 14px;
}

QToolButton#forward_btn {
    qproperty-text: "▶";
    font-size: 14px;
}

QToolButton#reload_btn {
    qproperty-text: "↻";
    font-size: 14px;
}

QToolButton#home_btn {
    qproperty-text: "⌂";
    font-size: 14px;
}
"""

# Aplicar o tema
app.setStyleSheet(tema_netscape)

window = Browser()
app.exec_()