// SPDX-FileCopyrightText: 2026 Brent Daignault
// SPDX-License-Identifier: GPL-3.0-or-later

import CoreGraphics
import Foundation

enum RenderMode {
    case booklet
    case portrait
}

/// Per-output page and label-column geometry.  CGFloat throughout — every
/// one of these values eventually feeds a CGPoint, CGRect, or a Core
/// Graphics / Core Text API parameter, none of which accept Double directly.
struct Layout {
    var pageW: CGFloat
    var pageH: CGFloat
    var mx: CGFloat      // horizontal margin
    var my: CGFloat       // vertical margin
    var colW: CGFloat     // label column width
    var nCols: Int
    var rows: Int          // label rows per column per page
}

/// Shared label geometry — identical for booklet and portrait.
enum Metrics {
    static let fsz: CGFloat = 8.0        // body font size
    static let nsz: CGFloat = 8.5        // name font size
    static let lead: CGFloat = 11.5      // line leading
    static let cgap: CGFloat = 10.0      // inter-column gap
    static let padT: CGFloat = 5.0       // padding above first text line
    static let padB: CGFloat = 3.0       // padding below last text line
    static let padAL: CGFloat = 14.0     // gap: section rule → first label top
    static let padBS: CGFloat = 10.0     // gap: section title → rule
    static let labelGap: CGFloat = 4.0   // vertical gap between label boxes

    // 6 text lines: name, address, city/pcode, phones, email1, email2
    static let labelH: CGFloat = padT + nsz + 5.0 * lead + padB   // 74 pt

    static let bpw: CGFloat = 396.0   // booklet logical page: 5.5 in
    static let bph: CGFloat = 612.0   // booklet logical page: 8.5 in
    static let ppw: CGFloat = 612.0   // portrait page: 8.5 in
    static let pph: CGFloat = 792.0   // portrait page: 11.0 in
}

extension Layout {
    static let booklet = Layout(
        pageW: Metrics.bpw, pageH: Metrics.bph,
        mx: 22.0, my: 28.0,
        colW: (Metrics.bpw - 2.0 * 22.0 - Metrics.cgap) / 2.0,
        nCols: 2, rows: 7
    )

    static let portrait = Layout(
        pageW: Metrics.ppw, pageH: Metrics.pph,
        mx: 28.0, my: 36.0,
        colW: (Metrics.ppw - 2.0 * 28.0 - 2.0 * Metrics.cgap) / 3.0,
        nCols: 3, rows: 8
    )
}
