Imports System.Configuration
Imports System.IO
Imports ColorCode

Namespace SelectPdf.Samples
	Public Partial Class Samples
		Inherits System.Web.UI.MasterPage

        ' True on the home page (Default.aspx) — drives the card-grid (is-home)
        ' layout and hides the side rail + the code panel.
        Protected Property IsHome As Boolean

        ' Set by converter-target pages (the convert-current-page capture and the
        ' view-http-* echo pages) BEFORE render. When true the master emits an
        ' inline PDF-reset <style> that flattens the screen-only sticky nav and
        ' the viewport-tall scrollable rail to natural top-to-bottom flow, so the
        ' SelectPdf engine paginates the page cleanly. Not @media print — the
        ' Chromium engine renders with screen media.
        Public Property FlattenForPdf As Boolean

        ' Public marketing site the chrome (nav menu, logo, footer) links at.
        ' Env-specific via the "MarketingBaseUrl" appSetting in Web.config —
        ' classic .NET Framework has no IsStaging(), so the staging deploy sets
        ' this to https://selectpdf.net; the default (dev + production) is
        ' https://selectpdf.com. No trailing slash.
        Protected ReadOnly Property MarketingBaseUrl As String
            Get
                Dim v As String = ConfigurationManager.AppSettings("MarketingBaseUrl")
                If String.IsNullOrEmpty(v) Then v = "https://selectpdf.com"
                Return v.TrimEnd("/"c)
            End Get
        End Property

        ' Scheme-less host form for the footer's visible label.
        Protected ReadOnly Property MarketingHost As String
            Get
                Return MarketingBaseUrl.Replace("https://", String.Empty) _
                                       .Replace("http://", String.Empty).TrimEnd("/"c)
            End Get
        End Property

        Protected Sub Page_Load(sender As Object, e As EventArgs)
            ' Robust home detection: the content page's app-relative path, NOT the
            ' request URL — works at the site root and under an IIS sub-application.
            IsHome = If(Page.AppRelativeVirtualPath, String.Empty).ToLowerInvariant().EndsWith("default.aspx")

            ' Home = card grid: no rail, no code panel.
            RailArea.Visible = Not IsHome
            If IsHome Then
                LitCode.Visible = False
                Return
            End If

            ' Inner page: the "Sample code · VB.NET" panel with this page's own
            ' .aspx.vb source, ColorCode-highlighted. Hides cleanly when absent.
            Try
                Dim srcPath As String = Server.MapPath(Page.AppRelativeVirtualPath) & ".vb"
                Dim code As String = File.ReadAllText(srcPath)
                Dim colorized As String = New CodeColorizer().Colorize(code, Languages.VbDotNet)
                LitCode.Text = "<div class=""spdf-code spdf-code-block"">" &
                    "<div class=""spdf-code-head"">" &
                    "<span class=""spdf-code-dots""><span class=""spdf-code-dot-red""></span>" &
                    "<span class=""spdf-code-dot-yellow""></span><span class=""spdf-code-dot-green""></span></span>" &
                    "<span>Sample code &#183; VB.NET</span>" &
                    "</div>" &
                    "<div class=""spdf-code-pre"">" & colorized & "</div>" &
                    "</div>"
            Catch
                LitCode.Visible = False
            End Try
        End Sub
	End Class
End Namespace
