<%@ Page Language="VB" AutoEventWireup="false" CodeBehind="TiffViewer.aspx.vb" Inherits="TiffPageHandler.TiffViewer" %>

<!DOCTYPE html>
<html>
<head runat="server">
    <title>TIFF Viewer</title>
    <style>
        body {
            font-family: Segoe UI, Arial, sans-serif;
            background-color: #f4f6f8;
            margin: 0;
            padding: 30px;
            color: #333;
        }

        .container {
            max-width: 950px;
            margin: 0 auto;
            background: #ffffff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.08);
            padding: 25px 30px;
        }

        h2 {
            margin-top: 0;
            font-size: 20px;
            color: #222;
            border-bottom: 1px solid #e5e5e5;
            padding-bottom: 12px;
        }

        .upload-row {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 10px;
            flex-wrap: wrap;
        }

        .btn {
            background-color: #2563eb;
            color: #fff;
            border: none;
            padding: 8px 18px;
            border-radius: 5px;
            font-size: 14px;
            cursor: pointer;
        }

        .btn:hover {
            background-color: #1d4ed8;
        }

        .btn-secondary {
            background-color: #64748b;
        }

        .btn-secondary:hover {
            background-color: #475569;
        }

        .status-msg {
            font-size: 13px;
            margin-top: 5px;
            display: block;
        }

        .viewer-panel {
            margin-top: 25px;
            border-top: 1px solid #e5e5e5;
            padding-top: 20px;
        }

        .nav-row {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 15px;
            margin-bottom: 15px;
        }

        #pageLabel {
            font-size: 14px;
            font-weight: 600;
            color: #444;
            min-width: 110px;
            text-align: center;
        }

        .image-frame {
            display: flex;
            justify-content: center;
            background: #fafafa;
            border: 1px solid #ddd;
            border-radius: 6px;
            padding: 15px;
            min-height: 300px;
            align-items: center;
        }

        #imgViewer {
            max-width: 100%;
            max-height: 600px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        input[type="file"] {
            font-size: 14px;
        }
    </style>
    <script>
        var currentPage = 0;
        var totalPages = 0;
        var currentFile = "";

        function initViewer(fileName, pageCount) {
            currentFile = fileName;
            totalPages = pageCount;
            currentPage = 0;
            loadPage(0);
        }

        function loadPage(p) {
            document.getElementById("imgViewer").src =
                "TiffPageHandler.ashx?file=" + encodeURIComponent(currentFile) +
                "&page=" + p + "&t=" + new Date().getTime();
            document.getElementById("pageLabel").innerText = "Page " + (p + 1) + " of " + totalPages;
            currentPage = p;
        }

        function nextPage() { if (currentPage < totalPages - 1) loadPage(currentPage + 1); }
        function prevPage() { if (currentPage > 0) loadPage(currentPage - 1); }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="container">
            <h2>TIFF Document Viewer</h2>

            <div class="upload-row">
                <asp:FileUpload ID="FileUpload1" runat="server" />
                <asp:Button ID="btnUpload" runat="server" CssClass="btn" Text="Upload & View" OnClick="btnUpload_Click" />
            </div>
            <asp:Label ID="lblStatus" runat="server" CssClass="status-msg" ForeColor="#c0392b" />

            <asp:HiddenField ID="hdnFileName" runat="server" ClientIDMode="Static" />

            <div id="viewerPanel" runat="server" visible="false" class="viewer-panel">
                <div class="nav-row">
                    <button type="button" class="btn btn-secondary" onclick="prevPage()">&laquo; Prev</button>
                    <span id="pageLabel">Page 1</span>
                    <button type="button" class="btn btn-secondary" onclick="nextPage()">Next &raquo;</button>
                </div>
                <div class="image-frame">
                    <img id="imgViewer" src="" alt="TIFF Page" />
                </div>
            </div>
        </div>
    </form>
</body>
</html>