-- VDS_LayoutConfig_Default
-- ============================================================================
-- Default-view widgets. Every child of a multi-child container must declare
-- `order = N` (PANEL_LAYOUT_REFERENCE #4; Layout errors loud if missing).

VDS = VDS or {}
VDS.LayoutConfig.sections = VDS.LayoutConfig.sections or {}

local LC = VDS.LayoutConfig

-- ===== TITLE ROW =====

LC.sections["title.row"] = {
    ["in"]  = "titlePanel",
    order   = 10,
    layout  = "horizontal",
    -- right=32 clears the manually-anchored closeBtn (22px wide at TOPRIGHT -6,-6).
    padding = { left = 8, top = 4, right = 32, bottom = 0 },
    gap     = 4,
}

LC.widgets["title.text"] = {
    kind   = "rainbowTitle",
    ["in"] = "title.row",
    order  = 10,
    text   = "Vamoose's Dye Studio",
    width  = "fill",
    height = 26,
    tooltip = false,
}

-- Config cog: toggles the config sidebar. Hidden in canvas/live (those use their own right column).
LC.widgets["title.configBtn"] = {
    kind    = "iconButton",
    ["in"]  = "title.row",
    order   = 40,
    visible = "config.canShow",
    atlasStates = {
        default = "decor-controls-settings-default",
        active  = "decor-controls-settings-active",
        pressed = "decor-controls-settings-pressed",
    },
    width   = 22,
    height  = 22,
    tooltip = { recipe = "Config" },
    action  = "TOGGLE_CONFIG",
}

LC.widgets["title.helpBtn"] = {
    kind    = "iconButton",
    ["in"]  = "title.row",
    order   = 50,
    atlas   = "QuestLegendaryTurnin",
    width   = 22,
    height  = 22,
    tooltip = { recipe = "Help" },
    action  = "SHOW_HELP",
}

-- ===== CONFIG SIDEBAR (configPanel; defaultWithConfig view only) =====

LC.sections["config.stack"] = {
    ["in"]  = "configPanel",
    order   = 10,
    layout  = "vertical",
    padding = { left = 10, top = 10, right = 10, bottom = 10 },
    gap     = 6,
}

LC.widgets["config.discordRow"] = {
    kind        = "linkRow",
    ["in"]      = "config.stack",
    order       = 1,
    atlas       = "UI-ChatIcon-Discord",
    text        = "https://discord.gg/RWZaxJaHFP",
    borderColor = { r = 0.35, g = 0.40, b = 0.98, a = 0.6 },  -- Discord blurple
    width       = "fill",
    height      = 26,
    tooltip = false,
}

LC.widgets["config.coffeeRow"] = {
    kind        = "linkRow",
    ["in"]      = "config.stack",
    order       = 2,
    atlas       = "auctionhouse-icon-coin-gold",
    text        = "https://buymeacoffee.com/vamoose",
    borderColor = { r = 1.00, g = 0.82, b = 0.20, a = 0.6 },  -- gold
    width       = "fill",
    height      = 26,
    tooltip = false,
}

LC.widgets["config.discordCoffeeSpacer"] = {
    kind   = "spacer",
    ["in"] = "config.stack",
    order  = 3,
    height = 8,
    tooltip = false,
}

LC.widgets["config.title"] = {
    kind     = "label",
    ["in"]   = "config.stack",
    order    = 5,
    text     = "Config",
    font     = "subheading",
    height   = 22,
    justifyH = "LEFT",
    tooltip = false,
}

LC.widgets["config.editingHeader"] = {
    kind   = "label",
    ["in"] = "config.stack",
    order  = 10,
    text   = "|cffffcc55Editing|r",
    font   = "subheading",
    height = 20,
    tooltip = false,
}

LC.widgets["config.autoSaveCheck"] = {
    kind    = "checkbox",
    ["in"]  = "config.stack",
    order   = 30,
    binding = "live.autosave",
    label   = "Auto-save dye combos on Apply",
    width   = "fill",
    height  = 22,
    tooltip = { recipe = "AutoSave" },
    action  = "SET_LIVE_AUTOSAVE",
}

LC.widgets["config.replaceCheck"] = {
    kind    = "checkbox",
    ["in"]  = "config.stack",
    order   = 40,
    binding = "config.replaceBlizzard",
    label   = "Replace Blizzard's dye picker",
    width   = "fill",
    height  = 22,
    tooltip = { recipe = "ReplaceBlizzardPicker" },
    action  = "SET_REPLACE_BLIZZARD",
}

LC.widgets["config.spacer1"] = {
    kind   = "spacer",
    ["in"] = "config.stack",
    order  = 45,
    height = 8,
    tooltip = false,
}

LC.widgets["config.miscHeader"] = {
    kind   = "label",
    ["in"] = "config.stack",
    order  = 46,
    text   = "|cffffcc55Misc|r",
    font   = "subheading",
    height = 20,
    tooltip = false,
}

LC.widgets["config.minimapCheck"] = {
    kind    = "checkbox",
    ["in"]  = "config.stack",
    order   = 47,
    binding = "config.minimapShown",
    label   = "Show minimap icon",
    width   = "fill",
    height  = 22,
    tooltip = { recipe = "MinimapToggle" },
    action  = "TOGGLE_MINIMAP",
}

LC.widgets["config.debugCheck"] = {
    kind    = "checkbox",
    ["in"]  = "config.stack",
    order   = 48,
    binding = "config.debug",
    label   = "Print debug log to chat",
    width   = "fill",
    height  = 22,
    tooltip = { recipe = "DebugToggle" },
    action  = "TOGGLE_DEBUG",
}

LC.widgets["config.openLogBtn"] = {
    kind    = "button",
    ["in"]  = "config.stack",
    order   = 49,
    font    = "body",
    text    = "Open Debug Log",
    width   = "fill",
    height  = 22,
    tooltip = { recipe = "OpenDebugLog" },
    action  = "OPEN_DEBUG_LOG",
}

LC.widgets["config.spacer"] = {
    kind   = "spacer",
    ["in"] = "config.stack",
    order  = 50,
    height = 8,
    tooltip = false,
}

LC.widgets["config.slashHeader"] = {
    kind   = "label",
    ["in"] = "config.stack",
    order  = 60,
    text   = "|cffffcc55Slash Commands|r",
    font   = "subheading",
    height = 20,
    tooltip = false,
}

LC.widgets["config.slashList"] = {
    kind    = "label",
    ["in"]  = "config.stack",
    order   = 70,
    text    = "|cffaad5ff/vds|r |cff888888or|r |cffaad5ff/dyes|r\n"
           .. "|cff7a7a7a   toggle the window|r\n"
           .. "|cffaad5ff/vds debug|r\n"
           .. "|cff7a7a7a   toggle debug logging|r\n"
           .. "|cffaad5ff/vds hardreset|r\n"
           .. "|cff7a7a7a   reset all VDS data (requires /reload)|r",
    font    = "small",
    height  = 110,
    tooltip = false,
}

-- ===== SEARCH ROW =====

LC.sections["search.row"] = {
    ["in"]  = "searchPanel",
    order   = 10,
    layout  = "horizontal",
    padding = { left = 6, top = 4, right = 6, bottom = 0 },
    gap     = 6,
}

LC.widgets["search.input"] = {
    kind    = "searchBox",
    ["in"]  = "search.row",
    order   = 10,
    binding = "ui.searchText",
    width   = 180,
    tooltip = { recipe = "SearchDyesHerbs" },
}

LC.widgets["search.counter"] = {
    kind     = "label",
    ["in"]   = "search.row",
    order    = 15,
    binding  = "progress.collection.label",
    font     = "small",
    width    = "auto",
    height   = 18,
    justifyH = "RIGHT",
    tooltip = false,
}

LC.widgets["search.progress"] = {
    kind    = "colorsProgressBar",
    ["in"]  = "search.row",
    order   = 20,
    binding = "progress.collection",
    width   = "fill",
    height  = 18,
    tooltip = false,
}

-- ===== TABS ROW =====

LC.sections["tabs.row"] = {
    ["in"]  = "tabsPanel",
    order   = 10,
    layout  = "horizontal",
    padding = { left = 4, top = 0, right = 4, bottom = 0 },
}

LC.widgets["tabs.bar"] = {
    kind    = "tabBar",
    ["in"]  = "tabs.row",
    order   = 10,
    binding = "browse.tabs.chips",
    width   = "fill",
    tooltip = false,
}

-- ===== SUBFILTER ROW =====

LC.sections["subfilter.row"] = {
    ["in"]  = "subfilterPanel",
    order   = 10,
    layout  = "horizontal",
    padding = { left = 4, top = 2, right = 4, bottom = 0 },
}

LC.widgets["subfilter.chips"] = {
    kind    = "chipStrip",
    ["in"]  = "subfilter.row",
    order   = 10,
    binding = "browse.subfilter.chips",
    width   = "fill",
    tooltip = false,
}

-- ===== BROWSE BODY =====

LC.sections["browse.body"] = {
    ["in"]  = "browsePanel",
    order   = 10,
    layout  = "vertical",
    padding = { left = 6, top = 4, right = 6, bottom = 4 },
}

-- Two sibling scrollBoxes; separate pools eliminate the prior dye<->herb cross-kind hide pattern.
LC.widgets["browse.dyes.list"] = {
    kind     = "scrollBoxList",
    ["in"]   = "browse.body",
    order    = 10,
    binding  = "browse.dyes.rows",
    visible  = "browse.dyes.shown",
    width    = "fill",
    height   = "fill",
    extent   = 38,  -- DYE_ROW_HEIGHT(36) + DYE_ROW_GAP(2)
    rowKinds = { dye = "dyeRow", header = "dyeRow" },
    tooltip = false,
}

LC.widgets["browse.herbs.list"] = {
    kind     = "scrollBoxList",
    ["in"]   = "browse.body",
    order    = 11,
    binding  = "browse.herbs.rows",
    visible  = "browse.herbs.shown",
    width    = "fill",
    height   = "fill",
    extent   = 38,
    rowKinds = { herb = "herbRow", herbHeader = "herbRow" },
    -- Declarative async-name kick: rows where data.name is nil get
    -- Request'd via ItemNameResolver. Replaces the if-not-data.name-Request
    -- boilerplate that used to live in VDS_Rows_Herb. Middleware handles
    -- per-id dedup + debounced batch dispatch.
    resolveAsync = {
        { idField = "herbID", valueField = "name", resolver = VDS.ItemNameResolver },
    },
    tooltip = false,
}

-- ===== DETAIL ROW =====
-- swatch | info (fillWidth) | actions. info absorbs slack; hidden buttons skip from flow.

LC.sections["detail.row"] = {
    ["in"]  = "detailPanel",
    order   = 10,
    layout  = "horizontal",
    padding = { left = 4, top = 6, right = 4, bottom = 6 },
    gap     = 4,
}

LC.widgets["detail.swatch"] = {
    kind    = "gradientSwatch",
    ["in"]  = "detail.row",
    order   = 10,
    binding = { dye = "detail.dye" },
    visible = "detail.has.dye",
    width   = 44,
    height  = 44,
    align   = "top",  -- detail.row is horizontal; opt out of center-vertical
    tooltip = false,
}

LC.sections["detail.info"] = {
    ["in"]   = "detail.row",
    order    = 20,
    layout   = "vertical",
    gap      = 2,
    width    = 240,  -- fixed left cluster; leaves room for right-hand action column
    visible  = "detail.showMeta",  -- hidden in Colors view; the harmony band replaces it (the slim)
}

-- Palette summary: visible in custom mode when a palette is selected/editing.
LC.widgets["detail.paletteSummary"] = {
    kind    = "label",
    ["in"]  = "detail.row",
    order   = 25,
    binding = "detail.palette.summary",
    visible = "detail.has.palette",
    font    = "body",
    width   = "fill",
    height  = 22,
    tooltip = false,
}

LC.widgets["detail.nameLabel"] = {
    kind     = "label",
    ["in"]   = "detail.info",
    order    = 10,
    binding  = "detail.dye.label",
    font     = "subheading",
    height   = 20,
    justifyH = "LEFT",
    width    = "fill",
    tooltip = false,
}

LC.widgets["detail.metaLine1"] = {
    kind    = "metaLine",
    ["in"]  = "detail.info",
    order   = 20,
    binding = "detail.line1.parts",
    font    = "small",
    height  = 14,
    tooltip = false,
}

LC.widgets["detail.metaLine2"] = {
    kind    = "metaLine",
    ["in"]  = "detail.info",
    order   = 30,
    binding = "detail.line2.parts",
    font    = "small",
    height  = 14,
    tooltip = false,
}

-- ===== HERB DETAIL CLUSTER (visible when herb selected) =====

LC.sections["detail.herbInfo"] = {
    ["in"]   = "detail.row",
    order    = 22,
    layout   = "vertical",
    gap      = 2,
    width    = "fill",
    visible  = "detail.has.herb",
    align    = "top",
}

LC.widgets["detail.herb.line1"] = {
    kind     = "label",
    ["in"]   = "detail.herbInfo",
    order    = 10,
    binding  = "detail.herb.line1",
    font     = "body",   -- was "subheading"; 3-piece name+expac+color string overflows at subheading
    height   = 18,
    justifyH = "LEFT",
    width    = "fill",
    tooltip = false,
}

LC.widgets["detail.herb.line2"] = {
    kind     = "label",
    ["in"]   = "detail.herbInfo",
    order    = 20,
    binding  = "detail.herb.line2",
    font     = "small",
    height   = 14,
    justifyH = "LEFT",
    width    = "fill",
    tooltip = false,
}

LC.widgets["detail.herb.line3"] = {
    kind     = "label",
    ["in"]   = "detail.herbInfo",
    order    = 30,
    binding  = "detail.herb.line3",
    font     = "small",
    height   = 14,
    justifyH = "LEFT",
    width    = "fill",
    tooltip = false,
}

-- Harmony band: shown only in Colors view with a dye selected. Two-row grid
-- (Triad permanent, no toggle); the slim hides the name/meta cluster here so the
-- band is the panel. Height fits two rows of 28px chips + labels.
LC.widgets["detail.harmonyBand"] = {
    kind    = "harmonyBand",
    ["in"]  = "detail.row",
    order   = 24,
    binding = "harmony.band.data",
    visible = "harmony.visible",
    width   = "fill",
    height  = 94,
    tooltip = false,
}

-- Spacer: pushes action cluster right. Hidden in custom (paletteSummary fills)
-- and herbs (herbInfo fills) to avoid two fill widgets splitting slack.
LC.widgets["detail.spacer"] = {
    kind    = "spacer",
    ["in"]  = "detail.row",
    order   = 28,
    width   = "fill",
    height  = 22,
    visible = "detail.spacerShown",
    tooltip = false,
}

-- Herb sort button: Stock tab is sole cart workflow; multiplier + Cart buttons removed.
LC.sections["detail.herbControls"] = {
    ["in"]   = "detail.row",
    order    = 26,
    layout   = "vertical",
    gap      = 2,
    width    = 76,
    visible  = "detail.has.herb",
    align    = "top",
}

LC.widgets["detail.sortBtn"] = {
    kind    = "button",
    ["in"]  = "detail.herbControls",
    order   = 10,
    font    = "body",
    binding = "detail.herbSort.mode",
    width   = "fill",
    height  = 22,
    tooltip = { recipe = "HerbSort" },
}

-- ===== CUSTOM PANEL (customPanel; defaultWithCustom view only) =====
-- Palette action buttons (Rename/Delete/Export/Done) wired here; Controller_Detail handlers
-- fire by widget id without rebinding.

LC.sections["custom.stack"] = {
    ["in"]  = "customPanel",
    order   = 10,
    layout  = "vertical",
    padding = { left = 8, top = 10, right = 8, bottom = 10 },
    gap     = 4,
}

LC.widgets["custom.title"] = {
    kind     = "label",
    ["in"]   = "custom.stack",
    order    = 5,
    text     = "Palettes",
    font     = "subheading",
    height   = 22,
    justifyH = "LEFT",
    tooltip = false,
}

LC.widgets["custom.newBtn"] = {
    kind    = "button",
    ["in"]  = "custom.stack",
    order   = 10,
    font    = "body",
    text    = "+ New",
    width   = "fill",
    height  = 22,
    tooltip = { recipe = "PaletteNew" },
}

LC.widgets["custom.importBtn"] = {
    kind    = "button",
    ["in"]  = "custom.stack",
    order   = 20,
    font    = "body",
    text    = "Import",
    width   = "fill",
    height  = 22,
    tooltip = { recipe = "PaletteImport" },
}

LC.widgets["custom.scrollbox"] = {
    kind     = "scrollBoxList",
    ["in"]   = "custom.stack",
    order    = 30,
    binding  = "custom.palette.rows",
    width    = "fill",
    height   = "fill",
    extent   = 36,
    rowKinds = { palette = "customPaletteRow" },
    tooltip = false,
}

-- 2x2 action grid: 200px sidebar fits 2 per row (4-across over-spec'd at 188 vs 184 available).
LC.sections["custom.actions"] = {
    ["in"]   = "custom.stack",
    order    = 40,
    layout   = "vertical",
    gap      = 4,
    visible  = "palette.editing",
    height   = 48,
}

LC.sections["custom.actions.rowA"] = {
    ["in"]  = "custom.actions",
    order   = 10,
    layout  = "horizontal",
    gap     = 4,
    height  = 22,
}

LC.widgets["detail.renameBtn"] = {
    kind   = "button",
    ["in"] = "custom.actions.rowA",
    order  = 10,
    font   = "body",
    text   = "Rename",
    width  = "fill",
    height = 22,
    tooltip = { recipe = "PaletteRename" },
}

LC.widgets["detail.deleteBtn"] = {
    kind   = "button",
    ["in"] = "custom.actions.rowA",
    order  = 20,
    font   = "body",
    text   = "Delete",
    width  = "fill",
    height = 22,
    tooltip = { recipe = "PaletteDelete" },
}

LC.sections["custom.actions.rowB"] = {
    ["in"]  = "custom.actions",
    order   = 20,
    layout  = "horizontal",
    gap     = 4,
    height  = 22,
}

LC.widgets["detail.exportBtn"] = {
    kind   = "button",
    ["in"] = "custom.actions.rowB",
    order  = 10,
    font   = "body",
    text   = "Export",
    width  = "fill",
    height = 22,
    tooltip = { recipe = "PaletteExport" },
}

LC.widgets["detail.doneBtn"] = {
    kind    = "button",
    ["in"]  = "custom.actions.rowB",
    order   = 20,
    font    = "body",
    binding = "detail.editToggle.text",
    width   = "fill",
    height  = 22,
    tooltip = { recipe = "PaletteDone" },
}
