-- VDS_LayoutConfig
-- ============================================================================
-- Declarative window-layout root. Views, panels, sections, and widgets.
-- Widgets + sections declared in VDS_LayoutConfig_Default / _Canvas / etc.
--
-- Grammar summary:
--   window.views[name] -> { width, height, columns, rows, cells? }
--   panel.cell.<view>  -> "<cellName>"
--   panel.visible      -> "<selector>"  (track-collapses when panel hides)

VDS = VDS or {}
VDS.LayoutConfig = VDS.LayoutConfig or {
    window   = { views = {} },
    panels   = {},
    sections = {},
    widgets  = {},
}

local LC = VDS.LayoutConfig

LC.window.defaultView = "default"
LC.window.padding     = 4
LC.window.gap         = 2

LC.window.views.default = {
    width   = "auto",
    height  = 520,
    columns = { 420 },
    rows = {
        { name = "title",     height = 28 },
        { name = "search",    height = 28 },
        { name = "tabs",      height = 26 },
        { name = "subfilter", height = 24 },
        { name = "body",      height = "fill" },
        { name = "footer",    height = 106 },
    },
}

-- Config sidebar open: adds right column for configPanel (rowSpan="fill").
-- Selector flips here when configShown=true AND not canvas mode.
LC.window.views.defaultWithConfig = {
    width   = "auto",
    height  = 520,
    columns = { 420, 240 },
    rows = {
        { name = "title",     height = 28 },
        { name = "search",    height = 28 },
        { name = "tabs",      height = 26 },
        { name = "subfilter", height = 24 },
        { name = "body",      height = "fill" },
        { name = "footer",    height = 106 },
    },
    cells = {
        title         = { col = 1, row = "title" },
        search        = { col = 1, row = "search" },
        tabs          = { col = 1, row = "tabs" },
        subfilter     = { col = 1, row = "subfilter" },
        body          = { col = 1, row = "body" },
        footer        = { col = 1, row = "footer" },
        configPanel   = { col = 2, row = 1, rowSpan = "fill" },
    },
}

-- Custom view: palette sidebar on LEFT (col 1); standard browse chain in col 2.
LC.window.views.defaultWithCustom = {
    width   = "auto",
    height  = 520,
    columns = { 200, 420 },
    rows = {
        { name = "title",     height = 28 },
        { name = "search",    height = 28 },
        { name = "tabs",      height = 26 },
        { name = "subfilter", height = 24 },
        { name = "body",      height = "fill" },
        { name = "footer",    height = 106 },
    },
    cells = {
        title         = { col = 2, row = "title" },
        search        = { col = 2, row = "search" },
        tabs          = { col = 2, row = "tabs" },
        subfilter     = { col = 2, row = "subfilter" },
        body          = { col = 2, row = "body" },
        footer        = { col = 2, row = "footer" },
        customPanel   = { col = 1, row = 1, rowSpan = "fill" },
    },
}

-- Canvas view: 3 columns. Header chain in col 2; picker (col 1) + preview (col 3) span full height.
-- Canvas reuses the `subfilter` row for the scope picker (color-chip subfilter
-- is empty in canvas mode, so reclaim the slot). Row bumped to 30 to fit
-- WowStyle1DropdownTemplate's native 24h + padding.
LC.window.views.canvas = {
    width   = "auto",
    height  = 520,
    columns = { 280, 420, 380 },
    rows = {
        { name = "title",     height = 28 },
        { name = "search",    height = 28 },
        { name = "tabs",      height = 26 },
        { name = "subfilter", height = 30 },
        { name = "body",      height = "fill" },
    },
    cells = {
        title         = { col = 2, row = "title" },
        search        = { col = 2, row = "search" },
        tabs          = { col = 2, row = "tabs" },
        subfilter     = { col = 2, row = "subfilter" },
        body          = { col = 2, row = "body" },
        canvasPicker  = { col = 1, row = 1, rowSpan = "fill" },
        canvasPreview = { col = 3, row = 1, rowSpan = "fill" },
    },
}

-- Live view: single column. dynamicRows/dynamicHeight resize as slots appear.
LC.window.views.live = {
    width       = "auto",
    height      = 520,
    columns     = { 420 },
    rows = {
        { name = "title",     height = 28 },
        { name = "search",    height = 28 },
        { name = "tabs",      height = 26 },
        { name = "subfilter", height = 24 },
        { name = "body",      height = "fill" },
        { name = "liveEdit",  height = 60 },   -- baseline; runtime grows with slots
    },
    dynamicRows   = "view.live.rows",
    dynamicHeight = "view.live.height",
    cells = {
        title     = { col = 1, row = "title" },
        search    = { col = 1, row = "search" },
        tabs      = { col = 1, row = "tabs" },
        subfilter = { col = 1, row = "subfilter" },
        body      = { col = 1, row = "body" },
        liveEdit  = { col = 1, row = "liveEdit" },
    },
}

-- Stock view: herbs panel in col 2 (Craft mode only). Without its own column,
-- colSpan=2 on chrome rows bleeds tab chips into the herbs area.
LC.window.views.stock = {
    width   = "auto",
    height  = 560,
    -- Static fallback. dynamicColumns: Buy={420}, Craft={420,240}.
    columns = { 420, 240 },
    dynamicColumns = "view.stock.columns",
    -- No subfilter row: omitted entirely (track-collapse can't fire with herbs panel pinning col 2).
    rows = {
        { name = "title",     height = 28 },
        { name = "search",    height = 28 },
        { name = "tabs",      height = 26 },
        { name = "modeBar",   height = 26 },
        { name = "body",      height = "fill" },
        { name = "footer",    height = 40 },
    },
    cells = {
        title     = { col = 1, row = "title" },
        search    = { col = 1, row = "search" },
        tabs      = { col = 1, row = "tabs" },
        modeBar   = { col = 1, row = "modeBar" },
        body      = { col = 1, row = "body" },
        footer    = { col = 1, row = "footer" },
        herbs     = { col = 2, row = 1, rowSpan = "fill" },  -- full-height; visible in Craft mode only
    },
}

LC.window.views.liveWithGallery = {
    width       = "auto",
    height      = 520,
    columns     = { 420, 146 },
    rows = {
        { name = "title",     height = 28 },
        { name = "search",    height = 28 },
        { name = "tabs",      height = 26 },
        { name = "subfilter", height = 24 },
        { name = "body",      height = "fill" },
        { name = "liveEdit",  height = 60 },
    },
    dynamicRows   = "view.live.rows",
    dynamicHeight = "view.live.height",
    cells = {
        title     = { col = 1, row = "title" },
        search    = { col = 1, row = "search" },
        tabs      = { col = 1, row = "tabs" },
        subfilter = { col = 1, row = "subfilter" },
        body      = { col = 1, row = "body" },
        liveEdit  = { col = 1, row = "liveEdit" },
        gallery   = { col = 2, row = 1, rowSpan = "fill" },
    },
}

LC.panels.titlePanel = {
    kind = "frame",
    cell = { default = "title", defaultWithConfig = "title", defaultWithCustom = "title",
             canvas = "title", live = "title", liveWithGallery = "title", stock = "title" },
}

LC.panels.searchPanel = {
    kind = "frame",
    cell = { default = "search", defaultWithConfig = "search", defaultWithCustom = "search",
             canvas = "search", live = "search", liveWithGallery = "search", stock = "search" },
}

LC.panels.tabsPanel = {
    kind = "frame",
    cell = { default = "tabs", defaultWithConfig = "tabs", defaultWithCustom = "tabs",
             canvas = "tabs", live = "tabs", liveWithGallery = "tabs", stock = "tabs" },
}

LC.panels.subfilterPanel = {
    kind    = "frame",
    visible = "subfilter.shown",
    -- Canvas + stock omitted: canvas uses the cell for canvasScopePanel;
    -- stock view drops the subfilter row entirely.
    cell    = { default = "subfilter", defaultWithConfig = "subfilter", defaultWithCustom = "subfilter",
                live = "subfilter", liveWithGallery = "subfilter" },
}

-- Canvas scope picker (theme / custom palette + reset). Sits in the subfilter
-- row -- color chips are empty in canvas mode, so the slot is repurposed.
LC.panels.canvasScopePanel = {
    kind = "frame",
    cell = { canvas = "subfilter" },
}

LC.panels.browsePanel = {
    kind = "frame",
    cell = { default = "body", defaultWithConfig = "body", defaultWithCustom = "body",
             canvas = "body", live = "body", liveWithGallery = "body" },
}

LC.panels.detailPanel = {
    kind = "frame",
    cell = { default = "footer", defaultWithConfig = "footer", defaultWithCustom = "footer" },
}

LC.panels.configPanel = {
    kind = "frame",
    cell = { defaultWithConfig = "configPanel" },
}

LC.panels.customPanel = {
    kind = "frame",
    cell = { defaultWithCustom = "customPanel" },
}

LC.panels.canvasPickerPanel = {
    kind = "frame",
    cell = { canvas = "canvasPicker" },
}

LC.panels.canvasPreviewPanel = {
    kind = "frame",
    cell = { canvas = "canvasPreview" },
}

LC.panels.liveEditPanel = {
    kind = "frame",
    cell = { live = "liveEdit", liveWithGallery = "liveEdit" },
}

LC.panels.galleryPanel = {
    kind = "frame",
    cell = { liveWithGallery = "gallery" },
}

LC.panels.stockModeBarPanel = {
    kind = "frame",
    cell = { stock = "modeBar" },
}

LC.panels.stockControlsPanel = {
    kind = "frame",
    cell = { stock = "footer" },
}

LC.panels.stockBodyPanel = {
    kind = "frame",
    cell = { stock = "body" },
}

LC.panels.stockHerbsPanel = {
    kind    = "frame",
    visible = "stock.craftMode",
    cell    = { stock = "herbs" },
}
