--------------------------------------------------------
-- Namespaces## Version: 2.6.0 ## Author: Discord: Cam#7332
--------------------------------------------------------
local MCLL = {}
if GetLocale() == "zhCN" then
    MCLL["Addons"] = "|cff69ccf0[藏品]|r坐骑收集"
    MCLL["lnuizuoqi"] = "收集者的悬赏"
    MCLL["Achievement"] = "成就"
    MCLL["Adventures"] = "冒险"
    MCLL["Ahead of the Curve"] = "引领潮流"
    MCLL["Alchemy"] = "炼金术"
    MCLL["Alliance"] = "联盟"
    MCLL["Allied Races"] = "同盟种族"
    MCLL["Archeology"] = "考古学"
    MCLL["Arena Mounts"] = "角斗士坐骑"
    MCLL["Argent Tournament"] = "银色锦标赛"
    MCLL["Assault: Uldum"] = "突袭：奥丹姆"
    MCLL["Assault: Vale of Eternal Blossoms"] = "突袭: 锦绣谷"
    MCLL["Azeroth Choppers"] = "艾泽拉斯机车"
    MCLL["BFA"] = "争霸艾泽拉斯"
    MCLL["BMAH"] = "黑市拍卖行"
    MCLL["Battle for Azeroth"] = "争霸艾泽拉斯"
    MCLL["Blacksmith"] = "锻造"
    MCLL["Blizzard Store"] = "游戏商城"
    MCLL["Blood Elf"] = "血精灵"
    MCLL["Brawler's Guild"] = "搏击俱乐部"
    MCLL["BrewFest"] = "美酒节"
    MCLL["Brewfest"] = "美酒节"
    MCLL["CATA"] = "大地的裂变"
    MCLL["Cataclysm"] = "大地的裂变"
    MCLL["Cenarion Expedition"] = "塞纳里奥远征队"
    MCLL["Challenge Mode"] = "黄金挑战"
    MCLL["Class"] = "职业"
    MCLL["Classic"] = "经典旧世"
    MCLL["Collector's Edition"] = "典藏版"
    MCLL["Covenant Feature"] = "盟约特色"
    MCLL["Daily Activities"] = "日常活动"
    MCLL["Dark Iron Dwarf"] = "黑铁矮人"
    MCLL["Darkmoon Faire"] = "暗月马戏团"
    MCLL["Delves"] = "安德麦财阀"
    MCLL["Demon Hunter"] = "恶魔猎手"
    MCLL["Diablo IV"] = "暗黑破坏神IV"
    MCLL["Dracthyr"] = "龙希尔"
    MCLL["Draenei"] = "德莱尼"
    MCLL["Dragon Riding"] = "驭龙术"
    MCLL["Dragonflight"] = "巨龙时代"
    MCLL["Dubloons"] = "达布隆币"
    MCLL["Dungeon"] = "地下城"
    MCLL["Dungeon Drop"] = "地下城掉落"
    MCLL["Dwarf"] = "矮人"
    MCLL["Engineering"] = "工程学"
    MCLL["Exalted Reputations"] = "声望崇拜"
    MCLL["Fishing"] = "钓鱼"
    MCLL["Fishing Shack"] = "要塞渔夫小屋"
    MCLL["Garrison"] = "要塞"
    MCLL["Gladiator"] = "角斗士"
    MCLL["Gnome"] = "侏儒"
    MCLL["Goblin"] = "地精"
    MCLL["Golden Lotus"] = "金莲教"
    MCLL["Guild Vendor"] = "公会商人"
    MCLL["Halaa"] = "哈兰"
    MCLL["Hallow's End"] = "万圣节"
    MCLL["Hearthstone"] = "炉石传说"
    MCLL["Heirlooms"] = "传家宝"
    MCLL["Honor"] = "荣誉"
    MCLL["Horde"] = "部落"
    MCLL["Human"] = "人类"
    MCLL["Island Expedition"] = "海岛探险"
    MCLL["Jewelcrafting"] = "珠宝加工"
    MCLL["Kun-Lai Vendor"] = "昆莱山商人"
    MCLL["Kurenai/The Mag'har"] = "库雷尼/玛格汉"
    MCLL["Kyrian"] = "格里恩"
    MCLL["LEGION"] = "军团再临"
    MCLL["Leatherworking"] = "制皮"
    MCLL["Legion"] = "军团再临"
    MCLL["Love is in the Air"] = "情人节"
    MCLL["Lunar Festival"] = "春节"
    MCLL["MOP"] = "熊猫人之谜"
    MCLL["Mark of Honor"] = "荣耀印记"
    MCLL["Maw Assaults"] = "噬渊突袭"
    MCLL["Medals"] = "服役勋章"
    MCLL["Missions"] = "任务"
    MCLL["Mists of Pandaria"] = "熊猫人之谜"
    MCLL["Mount Collection"] = "坐骑收藏"
    MCLL["Mythic +"] = "史诗钥石+"
    MCLL["Necrolords"] = "通灵领主"
    MCLL["Netherwing"] = "灵翼之龙"
    MCLL["Night Elf"] = "暗夜精灵"
    MCLL["Night Fae"] = "法夜"
    MCLL["Noblegarden"] = "复活节"
    MCLL["Old Anniversary Mounts"] = "旧版庆典坐骑"
    MCLL["Old Promotion Mounts"] = "旧版促销坐骑"
    MCLL["Oozing Necroray Egg"] = "渗出粘液的通灵鳐之卵"
    MCLL["Orc"] = "兽人"
    MCLL["Order of the Cloud Serpent"] = "云端翔龙骑士团"
    MCLL["Original Epic Mounts"] = "旧版史诗坐骑"
    MCLL["Other"] = "其他"
    MCLL["Overview"] = "概览"
    MCLL["PVP"] = "PVP"
    MCLL["Paladin"] = "圣骑士"
    MCLL["Pandaren"] = "熊猫人"
    MCLL["Paragon Reputation"] = "巅峰声望"
    MCLL["Pinned"] = "标记"
    MCLL["Plunderstorm"] = "霸业风暴"
    MCLL["Pre-Launch Event"] = "前夕事件"
    MCLL["Primal Eggs"] = "原始恐龙蛋"
    MCLL["Product Promotion"] = "产品推广"
    MCLL["Profession"] = "专业技能"
    MCLL["Professions"] = "专业技能"
    MCLL["Promotion"] = "促销"
    MCLL["Protoform Synthesis"] = "原生体合成"
    MCLL["Quest"] = "任务"
    MCLL["Raid"] = "团队副本"
    MCLL["Raid Drop"] = "团队副本掉落"
    MCLL["Rare Drops"] = "稀有掉落"
    MCLL["Rare Spawn"] = "稀有掉落"
    MCLL["Recruit-A-Friend"] = "战友招募"
    MCLL["Remix MOP"] = "幻境新生: 潘达利亚"
    MCLL["Renown"] = "名望"
    MCLL["Reputation"] = "声望"
    MCLL["Riddle"] = "解密"
    MCLL["Riddles"] = "解密"
    MCLL["SL"] = "暗影国度"
    MCLL["Scroll of Resurrection"] = "复活卷轴"
    MCLL["Secret"] = "解密"
    MCLL["Sha'tari Skyguard"] = "沙塔尔天空卫队"
    MCLL["Shado-Pan"] = "影踪派"
    MCLL["Shadowlands"] = "暗影国度"
    MCLL["Siren Island"] = "海妖岛"
    MCLL["Stables"] = "要塞兽栏"
    MCLL["TBC"] = "燃烧的远征"
    MCLL["Tailoring"] = "裁缝"
    MCLL["Talon's Vengeance"] = "复仇之爪"
    MCLL["Tauren"] = "牛头人"
    MCLL["The Burning Crusade"] = "燃烧的远征"
    MCLL["The Tillers"] = "阡陌客"
    MCLL["The War Within"] = "地心之战"
    MCLL["Timeless Isle"] = "永恒岛"
    MCLL["Timewalking"] = "时空漫游"
    MCLL["Timewalking Alterac Valley"] = "时空漫游: 奥特兰克山谷"
    MCLL["Tinkering"] = "制作"
    MCLL["Torghast"] = "托加斯特"
    MCLL["Tormentors"] = "折磨者"
    MCLL["Toy"] = "玩具"
    MCLL["Trading Card Game"] = "集换卡牌游戏"
    MCLL["Trading Post"] = "商栈"
    MCLL["Treasures"] = "宝藏"
    MCLL["Troll"] = "巨魔"
    MCLL["Undead"] = "亡灵"
    MCLL["Undermine"] = "安德麦"
    MCLL["Unobtainable"] = "绝版"
    MCLL["Unobtainable Raid Mounts"] = "绝版团本坐骑"
    MCLL["Vanilla"] = "经典旧世"
    MCLL["Vendor"] = "商人"
    MCLL["Venthyr"] = "温西尔"
    MCLL["Vicious Saddle"] = "邪气鞍座"
    MCLL["Visions"] = "惊魂幻象"
    MCLL["WOD"] = "德拉诺之王"
    MCLL["WOTLK"] = "巫妖王之怒"
    MCLL["Warcraft III Reforged"] = "魔兽争霸III：重制版"
    MCLL["Warfront: Arathi"] = "战争前线: 阿拉希"
    MCLL["Warfront: Darkshore"] = "战争前线：黑海岸"
    MCLL["Warlock"] = "术士"
    MCLL["Warlords of Draenor"] = "德拉诺之王"
    MCLL["Winter Veil"] = "冬幕节"
    MCLL["WoW Anniversary Mounts"] = "魔兽世界周年庆"
    MCLL["WoW Classic"] = "魔兽世界: 经典怀旧服"
    MCLL["Worgen"] = "狼人"
    MCLL["World Boss"] = "世界首领"
    MCLL["World Events"] = "世界事件"
    MCLL["WorldEvents"] = "世界事件"
    MCLL["Wrath of the Lich King"] = "巫妖王之怒"
    MCLL["Zone"] = "区域"
    MCLL["Incursion"] = "突袭"
    MCLL["Horrific Visions"] = "恐怖幻象"
    MCLL["Ashran"] = "阿什兰"
    
    ------ setting panel ------
    MCLL["Ctrl + Right Click to pin uncollected mounts"] = "Ctrl + 右键 标记未收集的坐骑"
    MCLL["Mount Collection Log Settings"] = "Mount Collection Log 设置"
    MCLL["Main Window Options"] = "主界面选项"
    MCLL["Main Window Opacity"] = "主界面透明度"
    MCLL["Changes the opacity of the main window"] = "更改主界面透明度"
    MCLL["Reset Opacity"] = "重置透明度"
    MCLL["Reset to default opacity"] = "重置为默认透明度"
    MCLL["Progress Bar Settings"] = "进度条设置"
    MCLL["Statusbar Texture"] = "进度条材质"
    MCLL["Set the statusbar texture."] = "设置进度条材质."
    MCLL["Reset Texture"] = "重置材质"
    MCLL["Reset to default texture"] = "重置为默认材质"
    MCLL["Progress Bar (<33%)"] = "进度条 (<33%)"
    MCLL["Set the progress bar colors to be shown when the percentage collected is below 33%"] = "设置进度条颜色 (收集进度<33%)"
    MCLL["Progress Bar (<66%)"] = "进度条 (<66%)"
    MCLL["Set the progress bar colors to be shown when the percentage collected is below 66%"] = "设置进度条颜色 (收集进度<66%)"
    MCLL["Progress Bar (<100%)"] = "进度条 (<100%)"
    MCLL["Set the progress bar colors to be shown when the percentage collected is below 100%"] = "设置进度条颜色 (收集进度<100%)"
    MCLL["Progress Bar (100%)"] = "进度条 (=100%)"
    MCLL["Set the progress bar colors to be shown when all mounts are collected"] = "设置进度条颜色 (收集所有坐骑)"
    MCLL["Reset Colors"] = "重置颜色"
    MCLL["Reset to default colors"] = "重置为默认颜色"
    MCLL["Unobtainable Settings"] = "绝版设置"
    MCLL["Hide Unobtainable from overview"] = "隐藏绝版"
    MCLL["Hide Unobtainable mounts from the overview."] = "在总览中隐藏绝版坐骑"
    MCLL["Show Minimap Icon"] = "显示小地图按钮"
    MCLL["Toggle the display of the Minimap Icon."] = "切换显示小地图按钮"
    MCLL["Reset Settings"] = "重置设置"
    MCLL["Reset to default settings"] = "重置为默认设置"
    MCLL["Hide Collected Mounts"] = "隐藏已收集的坐骑"
    MCLL["If enabled, collected mounts will not be shown in the list at all. Requires UI reload."] = "启用后，已收集的坐骑将不会显示在列表中。需要重载界面。"
    MCLL["Changing this setting requires a UI reload. Reload now?"] = "更改此设置需要重载界面。现在重载吗？"
    MCLL["YES"] = "是"
    MCLL["NO"] = "否"
    MCLL["Layout Settings"] = "布局设置"
    MCLL["Mounts Per Row"] = "每行坐骑数"
    MCLL["Set the number of mounts to display per row in the mount grid. Requires UI reload."] = "设置坐骑网格中每行显示的坐骑数量。需要重载界面。"
    MCLL["Use Blizzard Theme"] = "使用暴雪主题"
    MCLL["If enabled, the addon will use Blizzard's default UI theme. Requires UI reload."] = "启用后，插件将使用暴雪默认的界面主题。需要重载界面。"
    MCLL["Search Results"] = "搜索结果"
    MCLL["Search mounts..."] = "搜索坐骑..."
    MCLL["Mount Collection Log"] = "坐骑收集日志"
    MCLL["Clear Search"] = "清除搜索"
    MCLL["Sections"] = "分类"
elseif GetLocale() == "zhTW" then
    MCLL["Addons"] = "|cff69ccf0[藏品]|r坐骑收集"
    MCLL["Achievement"] = "成就"
    MCLL["Adventures"] = "冒險"
    MCLL["Ahead of the Curve"] = "領先群雄"
    MCLL["Alchemy"] = "鍊金術"
    MCLL["Alliance"] = "聯盟"
    MCLL["Allied Races"] = "同盟種族"
    MCLL["Archeology"] = "考古學"
    MCLL["Arena Mounts"] = "競技場坐騎"
    MCLL["Argent Tournament"] = "銀白聯賽"
    MCLL["Assault: Uldum"] = "突襲：奧丹姆"
    MCLL["Assault: Vale of Eternal Blossoms"] = "突襲：恆春谷"
    MCLL["Azeroth Choppers"] = "艾澤拉斯重機"
    MCLL["BFA"] = "決戰艾澤拉斯"
    MCLL["BMAH"] = "黑市拍賣場"
    MCLL["Battle for Azeroth"] = "決戰艾澤拉斯"
    MCLL["Blacksmith"] = "鍛造"
    MCLL["Blizzard Store"] = "暴雪商店"
    MCLL["Blood Elf"] = "血精靈"
    MCLL["Brawler's Guild"] = "鬥陣俱樂部"
    MCLL["BrewFest"] = "啤酒節"
    MCLL["Brewfest"] = "啤酒節"
    MCLL["CATA"] = "大地的裂變"
    MCLL["Cataclysm"] = "大地的裂變"
    MCLL["Cenarion Expedition"] = "塞納里奧遠征隊"
    MCLL["Challenge Mode"] = "挑戰模式"
    MCLL["Class"] = "職業"
    MCLL["Classic"] = "經典舊世"
    MCLL["Collector's Edition"] = "典藏版"
    MCLL["Covenant Feature"] = "誓盟特色"
    MCLL["Daily Activities"] = "日常活動"
    MCLL["Dark Iron Dwarf"] = "黑鐵矮人"
    MCLL["Darkmoon Faire"] = "暗月馬戲團"
    MCLL["Delves"] = "地心探險"
    MCLL["Demon Hunter"] = "惡魔獵人"
    MCLL["Diablo IV"] = "暗黑破壞神IV"
    MCLL["Dracthyr"] = "半龍人"
    MCLL["Draenei"] = "德萊尼"
    MCLL["Dragon Riding"] = "飛龍騎術"
    MCLL["Dragonflight"] = "巨龍崛起"
    MCLL["Dubloons"] = "海員古幣"
    MCLL["Dungeon"] = "地城"
    MCLL["Dungeon Drop"] = "地城掉落"
    MCLL["Dwarf"] = "矮人"
    MCLL["Engineering"] = "工程學"
    MCLL["Exalted Reputations"] = "崇拜聲望"
    MCLL["Fishing"] = "釣魚"
    MCLL["Fishing Shack"] = "釣魚小屋"
    MCLL["Garrison"] = "要塞"
    MCLL["Gladiator"] = "角鬥士"
    MCLL["Gnome"] = "侏儒"
    MCLL["Goblin"] = "哥布林"
    MCLL["Golden Lotus"] = "金蓮會"
    MCLL["Guild Vendor"] = "公會商人"
    MCLL["Halaa"] = "哈剌"
    MCLL["Hallow's End"] = "萬鬼節"
    MCLL["Hearthstone"] = "爐石戰記"
    MCLL["Heirlooms"] = "傳家寶"
    MCLL["Honor"] = "榮譽"
    MCLL["Horde"] = "部落"
    MCLL["Human"] = "人類"
    MCLL["Island Expedition"] = "海嶼遠征"
    MCLL["Jewelcrafting"] = "珠寶設計"
    MCLL["Kun-Lai Vendor"] = "崑萊峰商人"
    MCLL["Kurenai/The Mag'har"] = "卡爾奈/瑪格哈"
    MCLL["Kyrian"] = "琪瑞安"
    MCLL["LEGION"] = "軍臨天下"
    MCLL["Leatherworking"] = "製皮"
    MCLL["Legion"] = "軍臨天下"
    MCLL["Love is in the Air"] = "愛就在身邊"
    MCLL["Lunar Festival"] = "農曆新年"
    MCLL["MOP"] = "潘達利亞之謎"
    MCLL["Mark of Honor"] = "榮譽印記"
    MCLL["Maw Assaults"] = "淵喉突襲"
    MCLL["Medals"] = "服役勳章"
    MCLL["Missions"] = "任務"
    MCLL["Mists of Pandaria"] = "潘達利亞之謎"
    MCLL["Mount Collection"] = "坐騎收藏"
    MCLL["Mythic +"] = "傳奇+"
    MCLL["Necrolords"] = "死靈領主"
    MCLL["Netherwing"] = "虛空之翼"
    MCLL["Night Elf"] = "夜精靈"
    MCLL["Night Fae"] = "暗夜妖精"
    MCLL["Noblegarden"] = "貴族花園"
    MCLL["Old Anniversary Mounts"] = "舊版周年坐騎"
    MCLL["Old Promotion Mounts"] = "舊版促銷坐騎"
    MCLL["Oozing Necroray Egg"] = "黏黏的死靈魟魚卵"
    MCLL["Orc"] = "獸人"
    MCLL["Order of the Cloud Serpent"] = "雲蛟衛"
    MCLL["Original Epic Mounts"] = "舊版史詩坐騎"
    MCLL["Other"] = "其他"
    MCLL["Overview"] = "總覽"
    MCLL["PVP"] = "PvP"
    MCLL["Paladin"] = "聖騎士"
    MCLL["Pandaren"] = "熊貓人"
    MCLL["Paragon Reputation"] = "巔峰聲望"
    MCLL["Pinned"] = "標記"
    MCLL["Plunderstorm"] = "掠鴉行動"
    MCLL["Pre-Launch Event"] = "前夕事件"
    MCLL["Primal Eggs"] = "原始蛋"
    MCLL["Product Promotion"] = "產品推廣"
    MCLL["Profession"] = "專業技能"
    MCLL["Professions"] = "專業技能"
    MCLL["Promotion"] = "促銷"
    MCLL["Protoform Synthesis"] = "原型合成"
    MCLL["Quest"] = "任務"
    MCLL["Raid"] = "團隊副本"
    MCLL["Raid Drop"] = "團隊副本掉落"
    MCLL["Rare Drops"] = "稀有掉落"
    MCLL["Rare Spawn"] = "稀有怪"
    MCLL["Recruit-A-Friend"] = "招募好友"
    MCLL["Remix MOP"] = "潘達利亞：幻境新生"
    MCLL["Renown"] = "名望"
    MCLL["Reputation"] = "聲望"
    MCLL["Riddle"] = "謎題"
    MCLL["Riddles"] = "謎題"
    MCLL["SL"] = "暗影之境"
    MCLL["Scroll of Resurrection"] = "復活卷軸"
    MCLL["Secret"] = "祕密"
    MCLL["Sha'tari Skyguard"] = "薩塔禦天者"
    MCLL["Shado-Pan"] = "影踪派"
    MCLL["Shadowlands"] = "暗影之境"
    MCLL["Siren Island"] = "海妖島"
    MCLL["Stables"] = "獸欄"
    MCLL["TBC"] = "燃燒的遠征"
    MCLL["Tailoring"] = "裁縫"
    MCLL["Talon's Vengeance"] = "復仇之爪"
    MCLL["Tauren"] = "牛頭人"
    MCLL["The Burning Crusade"] = "燃燒的遠征"
    MCLL["The Tillers"] = "耕者工會"
    MCLL["The War Within"] = "地心之戰"
    MCLL["Timeless Isle"] = "永恆島"
    MCLL["Timewalking"] = "時光漫遊"
    MCLL["Timewalking Alterac Valley"] = "時光漫遊：奧特蘭克山谷"
    MCLL["Tinkering"] = "廢料場工程"
    MCLL["Torghast"] = "托迦司"
    MCLL["Tormentors"] = "折磨者"
    MCLL["Toy"] = "玩具"
    MCLL["Trading Card Game"] = "集換式卡牌遊戲"
    MCLL["Trading Post"] = "商棧"
    MCLL["Treasures"] = "寶藏"
    MCLL["Troll"] = "食人妖"
    MCLL["Undead"] = "不死族"
    MCLL["Undermine"] = "幽坑城"
    MCLL["Unobtainable"] = "絕版"
    MCLL["Unobtainable Raid Mounts"] = "絕版團隊副本坐騎"
    MCLL["Vanilla"] = "經典舊世"
    MCLL["Vendor"] = "商人"
    MCLL["Venthyr"] = "汎希爾"
    MCLL["Vicious Saddle"] = "邪惡戰騎"
    MCLL["Visions"] = "恐怖幻象"
    MCLL["WOD"] = "德拉諾之霸"
    MCLL["WOTLK"] = "巫妖王之怒"
    MCLL["Warcraft III Reforged"] = "魔獸爭霸III：重製版"
    MCLL["Warfront: Arathi"] = "戰爭前線：阿拉希"
    MCLL["Warfront: Darkshore"] = "戰爭前線：黑海岸"
    MCLL["Warlock"] = "術士"
    MCLL["Warlords of Draenor"] = "德拉諾之霸"
    MCLL["Winter Veil"] = "冬幕節"
    MCLL["WoW Anniversary Mounts"] = "魔獸世界周年慶"
    MCLL["WoW Classic"] = "魔獸世界：經典版"
    MCLL["Worgen"] = "狼人"
    MCLL["World Boss"] = "世界首領"
    MCLL["World Events"] = "世界事件"
    MCLL["WorldEvents"] = "世界事件"
    MCLL["Wrath of the Lich King"] = "巫妖王之怒"
    MCLL["Zone"] = "區域"
    MCLL["Incursion"] = "突襲"
    MCLL["Horrific Visions"] = "恐怖幻象"
    MCLL["Ashran"] = "阿斯蘭"

    ------ setting panel ------
    MCLL["Ctrl + Right Click to pin uncollected mounts"] = "Ctrl + 右鍵 標記未收藏的坐騎"
    MCLL["Mount Collection Log Settings"] = "坐騎收集日誌設定"
    MCLL["Main Window Options"] = "主視窗選項"
    MCLL["Main Window Opacity"] = "主視窗透明度"
    MCLL["Changes the opacity of the main window"] = "更改主視窗透明度"
    MCLL["Reset Opacity"] = "重設透明度"
    MCLL["Reset to default opacity"] = "重設為預設透明度"
    MCLL["Progress Bar Settings"] = "進度條設定"
    MCLL["Statusbar Texture"] = "進度條材質"
    MCLL["Set the statusbar texture."] = "設定進度條材質。"
    MCLL["Reset Texture"] = "重設材質"
    MCLL["Reset to default texture"] = "重設為預設材質"
    MCLL["Progress Bar (<33%)"] = "進度條 (<33%)"
    MCLL["Set the progress bar colors to be shown when the percentage collected is below 33%"] = "設定進度條顏色（收集進度<33%）"
    MCLL["Progress Bar (<66%)"] = "進度條 (<66%)"
    MCLL["Set the progress bar colors to be shown when the percentage collected is below 66%"] = "設定進度條顏色（收集進度<66%）"
    MCLL["Progress Bar (<100%)"] = "進度條 (<100%)"
    MCLL["Set the progress bar colors to be shown when the percentage collected is below 100%"] = "設定進度條顏色（收集進度<100%）"
    MCLL["Progress Bar (100%)"] = "進度條 (=100%)"
    MCLL["Set the progress bar colors to be shown when all mounts are collected"] = "設定進度條顏色（收集所有坐騎）"
    MCLL["Reset Colors"] = "重設顏色"
    MCLL["Reset to default colors"] = "重設為預設顏色"
    MCLL["Unobtainable Settings"] = "絕版設定"
    MCLL["Hide Unobtainable from overview"] = "總覽中隱藏絕版"
    MCLL["Hide Unobtainable mounts from the overview."] = "在總覽中隱藏絕版坐騎"
    MCLL["Show Minimap Icon"] = "顯示小地圖按鈕"
    MCLL["Toggle the display of the Minimap Icon."] = "切換顯示小地圖按鈕"
    MCLL["Reset Settings"] = "重設設定"
    MCLL["Reset to default settings"] = "重設為預設設定"
    MCLL["Hide Collected Mounts"] = "隱藏已收集的坐騎"
    MCLL["If enabled, collected mounts will not be shown in the list at all. Requires UI reload."] = "啟用後，已收集的坐騎將不會顯示在列表中。需要重新載入介面。"
    MCLL["Changing this setting requires a UI reload. Reload now?"] = "更改此設定需要重新載入介面。現在重新載入嗎？"
    MCLL["YES"] = "是"
    MCLL["NO"] = "否"
    MCLL["Layout Settings"] = "佈局設定"
    MCLL["Mounts Per Row"] = "每行坐騎數"
    MCLL["Set the number of mounts to display per row in the mount grid. Requires UI reload."] = "設定坐騎網格中每行顯示的坐騎數量。需要重新載入介面。"
    MCLL["Use Blizzard Theme"] = "使用暴雪主題"
    MCLL["If enabled, the addon will use Blizzard's default UI theme. Requires UI reload."] = "啟用後，插件將使用暴雪預設的介面主題。需要重新載入介面。"
    MCLL["Search Results"] = "搜尋結果"
    MCLL["Search mounts..."] = "搜尋坐騎..."
    MCLL["Mount Collection Log"] = "坐騎收集日誌"
    MCLL["Clear Search"] = "清除搜尋"
    MCLL["Use Blizzard Theme"] = "使用暴雪主題"
    MCLL["If enabled, the addon will use Blizzard's default UI theme. Requires UI reload."] = "啟用後，附加元件將使用暴雪的預設UI主題。需要重新載入介面。"
    MCLL["Sections"] = "分類"
    MCLL["MCL | Mount Collection Log"] = "MCL | 坐騎收集日誌"
    MCLL["|cff00CCFFMount Collection Log Commands:\n|cffFF0000Show:|cffFFFFFF Shows your mount collection log\n|cffFF0000Icon:|cffFFFFFF Toggles the minimap icon\n|cffFF0000Config:|cffFFFFFF Opens the settings\n|cffFF0000Help:|cffFFFFFF Shows commands"] = "|cff00CCFF坐騎收集日誌指令:\n|cffFF0000Show:|cffFFFFFF 顯示你的坐騎收集日誌\n|cffFF0000Icon:|cffFFFFFF 切換小地圖按鈕\n|cffFF0000Config:|cffFFFFFF 開啟設定選項\n|cffFF0000Help:|cffFFFFFF 顯示指令"
else
    MCLL["Addons"] = "Mount Collection log"
    MCLL["Achievement"] = "Achievement"
    MCLL["Adventures"] = "Adventures"
    MCLL["Ahead of the Curve"] = "Ahead of the Curve"
    MCLL["Alchemy"] = "Alchemy"
    MCLL["Alliance"] = "Alliance"
    MCLL["Allied Races"] = "Allied Races"
    MCLL["Archeology"] = "Archeology"
    MCLL["Arena Mounts"] = "Arena Mounts"
    MCLL["Argent Tournament"] = "Argent Tournament"
    MCLL["Assault: Uldum"] = "Assault: Uldum"
    MCLL["Assault: Vale of Eternal Blossoms"] = "Assault: Vale of Eternal Blossoms"
    MCLL["Azeroth Choppers"] = "Azeroth Choppers"
    MCLL["BFA"] = "BFA"
    MCLL["BMAH"] = "BMAH"
    MCLL["Battle for Azeroth"] = "Battle for Azeroth"
    MCLL["Blacksmith"] = "Blacksmith"
    MCLL["Blizzard Store"] = "Blizzard Store"
    MCLL["Blood Elf"] = "Blood Elf"
    MCLL["Brawler's Guild"] = "Brawler's Guild"
    MCLL["BrewFest"] = "BrewFest"
    MCLL["Brewfest"] = "Brewfest"
    MCLL["CATA"] = "CATA"
    MCLL["Cataclysm"] = "Cataclysm"
    MCLL["Cenarion Expedition"] = "Cenarion Expedition"
    MCLL["Challenge Mode"] = "Challenge Mode"
    MCLL["Class"] = "Class"
    MCLL["Classic"] = "Classic"
    MCLL["Collector's Edition"] = "Collector's Edition"
    MCLL["Covenant Feature"] = "Covenant Feature"
    MCLL["Daily Activities"] = "Daily Activities"
    MCLL["Dark Iron Dwarf"] = "Dark Iron Dwarf"
    MCLL["Darkmoon Faire"] = "Darkmoon Faire"
    MCLL["Delves"] = "Delves"
    MCLL["Demon Hunter"] = "Demon Hunter"
    MCLL["Diablo IV"] = "Diablo IV"
    MCLL["Dracthyr"] = "Dracthyr"
    MCLL["Draenei"] = "Draenei"
    MCLL["Dragon Riding"] = "Dragon Riding"
    MCLL["Dragonflight"] = "Dragonflight"
    MCLL["Dubloons"] = "Dubloons"
    MCLL["Dungeon"] = "Dungeon"
    MCLL["Dungeon Drop"] = "Dungeon Drop"
    MCLL["Dwarf"] = "Dwarf"
    MCLL["Engineering"] = "Engineering"
    MCLL["Exalted Reputations"] = "Exalted Reputations"
    MCLL["Fishing"] = "Fishing"
    MCLL["Fishing Shack"] = "Fishing Shack"
    MCLL["Garrison"] = "Garrison"
    MCLL["Gladiator"] = "Gladiator"
    MCLL["Gnome"] = "Gnome"
    MCLL["Goblin"] = "Goblin"
    MCLL["Golden Lotus"] = "Golden Lotus"
    MCLL["Guild Vendor"] = "Guild Vendor"
    MCLL["Halaa"] = "Halaa"
    MCLL["Hallow's End"] = "Hallow's End"
    MCLL["Hearthstone"] = "Hearthstone"
    MCLL["Heirlooms"] = "Heirlooms"
    MCLL["Honor"] = "Honor"
    MCLL["Horde"] = "Horde"
    MCLL["Human"] = "Human"
    MCLL["Island Expedition"] = "Island Expedition"
    MCLL["Jewelcrafting"] = "Jewelcrafting"
    MCLL["Kun-Lai Vendor"] = "Kun-Lai Vendor"
    MCLL["Kurenai/The Mag'har"] = "Kurenai/The Mag'har"
    MCLL["Kyrian"] = "Kyrian"
    MCLL["LEGION"] = "LEGION"
    MCLL["Leatherworking"] = "Leatherworking"
    MCLL["Legion"] = "Legion"
    MCLL["Love is in the Air"] = "Love is in the Air"
    MCLL["Lunar Festival"] = "Lunar Festival"
    MCLL["MOP"] = "MOP"
    MCLL["Mark of Honor"] = "Mark of Honor"
    MCLL["Maw Assaults"] = "Maw Assaults"
    MCLL["Medals"] = "Medals"
    MCLL["Missions"] = "Missions"
    MCLL["Mists of Pandaria"] = "Mists of Pandaria"
    MCLL["Mount Collection"] = "Mount Collection"
    MCLL["Mythic +"] = "Mythic +"
    MCLL["Necrolords"] = "Necrolords"
    MCLL["Netherwing"] = "Netherwing"
    MCLL["Night Elf"] = "Night Elf"
    MCLL["Night Fae"] = "Night Fae"
    MCLL["Noblegarden"] = "Noblegarden"
    MCLL["Old Anniversary Mounts"] = "Old Anniversary Mounts"
    MCLL["Old Promotion Mounts"] = "Old Promotion Mounts"
    MCLL["Oozing Necroray Egg"] = "Oozing Necroray Egg"
    MCLL["Orc"] = "Orc"
    MCLL["Order of the Cloud Serpent"] = "Order of the Cloud Serpent"
    MCLL["Original Epic Mounts"] = "Original Epic Mounts"
    MCLL["Other"] = "Other"
    MCLL["Overview"] = "Overview"
    MCLL["PVP"] = "PVP"
    MCLL["Paladin"] = "Paladin"
    MCLL["Pandaren"] = "Pandaren"
    MCLL["Paragon Reputation"] = "Paragon Reputation"
    MCLL["Pinned"] = "Pinned"
    MCLL["Plunderstorm"] = "Plunderstorm"
    MCLL["Pre-Launch Event"] = "Pre-Launch Event"
    MCLL["Primal Eggs"] = "Primal Eggs"
    MCLL["Product Promotion"] = "Product Promotion"
    MCLL["Profession"] = "Profession"
    MCLL["Professions"] = "Professions"
    MCLL["Promotion"] = "Promotion"
    MCLL["Protoform Synthesis"] = "Protoform Synthesis"
    MCLL["Quest"] = "Quest"
    MCLL["Raid"] = "Raid"
    MCLL["Raid Drop"] = "Raid Drop"
    MCLL["Rare Drops"] = "Rare Drops"
    MCLL["Rare Spawn"] = "Rare Spawn"
    MCLL["Recruit-A-Friend"] = "Recruit-A-Friend"
    MCLL["Remix MOP"] = "Remix MOP"
    MCLL["Renown"] = "Renown"
    MCLL["Reputation"] = "Reputation"
    MCLL["Riddle"] = "Riddle"
    MCLL["Riddles"] = "Riddles"
    MCLL["SL"] = "SL"
    MCLL["Scroll of Resurrection"] = "Scroll of Resurrection"
    MCLL["Secret"] = "Secret"
    MCLL["Sha'tari Skyguard"] = "Sha'tari Skyguard"
    MCLL["Shado-Pan"] = "Shado-Pan"
    MCLL["Shadowlands"] = "Shadowlands"
    MCLL["Siren Island"] = "Siren Island"
    MCLL["Stables"] = "Stables"
    MCLL["TBC"] = "TBC"
    MCLL["Tailoring"] = "Tailoring"
    MCLL["Talon's Vengeance"] = "Talon's Vengeance"
    MCLL["Tauren"] = "Tauren"
    MCLL["The Burning Crusade"] = "The Burning Crusade"
    MCLL["The Tillers"] = "The Tillers"
    MCLL["The War Within"] = "The War Within"
    MCLL["Timeless Isle"] = "Timeless Isle"
    MCLL["Timewalking"] = "Timewalking"
    MCLL["Timewalking Alterac Valley"] = "Timewalking Alterac Valley"
    MCLL["Tinkering"] = "Tinkering"
    MCLL["Torghast"] = "Torghast"
    MCLL["Tormentors"] = "Tormentors"
    MCLL["Toy"] = "Toy"
    MCLL["Trading Card Game"] = "Trading Card Game"
    MCLL["Trading Post"] = "Trading Post"
    MCLL["Treasures"] = "Treasures"
    MCLL["Troll"] = "Troll"
    MCLL["Undead"] = "Undead"
    MCLL["Undermine"] = "Undermine"
    MCLL["Unobtainable"] = "Unobtainable"
    MCLL["Unobtainable Raid Mounts"] = "Unobtainable Raid Mounts"
    MCLL["Vanilla"] = "Vanilla"
    MCLL["Vendor"] = "Vendor"
    MCLL["Venthyr"] = "Venthyr"
    MCLL["Vicious Saddle"] = "Vicious Saddle"
    MCLL["Visions"] = "Visions"
    MCLL["WOD"] = "WOD"
    MCLL["WOTLK"] = "WOTLK"
    MCLL["Warcraft III Reforged"] = "Warcraft III Reforged"
    MCLL["Warfront: Arathi"] = "Warfront: Arathi"
    MCLL["Warfront: Darkshore"] = "Warfront: Darkshore"
    MCLL["Warlock"] = "Warlock"
    MCLL["Warlords of Draenor"] = "Warlords of Draenor"
    MCLL["Winter Veil"] = "Winter Veil"
    MCLL["WoW Anniversary Mounts"] = "WoW Anniversary Mounts"
    MCLL["WoW Classic"] = "WoW Classic"
    MCLL["Worgen"] = "Worgen"
    MCLL["World Boss"] = "World Boss"
    MCLL["World Events"] = "World Events"
    MCLL["WorldEvents"] = "WorldEvents"
    MCLL["Wrath of the Lich King"] = "Wrath of the Lich King"
    MCLL["Zone"] = "Zone"
    MCLL["Incursion"] = "Incursion"
    MCLL["Horrific Visions"] = "Horrific Visions"
    MCLL["Ashran"] = "Ashran"

    ------ setting panel ------
    MCLL["Ctrl + Right Click to pin uncollected mounts"] = "Ctrl + Right Click to pin uncollected mounts"
    MCLL["Mount Collection Log Settings"] = "Mount Collection Log Settings"
    MCLL["Main Window Options"] = "Main Window Options"
    MCLL["Main Window Opacity"] = "Main Window Opacity"
    MCLL["Changes the opacity of the main window"] = "Changes the opacity of the main window"
    MCLL["Reset Opacity"] = "Reset Opacity"
    MCLL["Reset to default opacity"] = "Reset to default opacity"
    MCLL["Progress Bar Settings"] = "Progress Bar Settings"
    MCLL["Statusbar Texture"] = "Statusbar Texture"
    MCLL["Set the statusbar texture."] = "Set the statusbar texture."
    MCLL["Reset Texture"] = "Reset Texture"
    MCLL["Reset to default texture"] = "Reset to default texture"
    MCLL["Progress Bar (<33%)"] = "Progress Bar (<33%)"
    MCLL["Set the progress bar colors to be shown when the percentage collected is below 33%"] = "Set the progress bar colors to be shown when the percentage collected is below 33%"
    MCLL["Progress Bar (<66%)"] = "Progress Bar (<66%)"
    MCLL["Set the progress bar colors to be shown when the percentage collected is below 66%"] = "Set the progress bar colors to be shown when the percentage collected is below 66%"
    MCLL["Progress Bar (<100%)"] = "Progress Bar (<100%)"
    MCLL["Set the progress bar colors to be shown when the percentage collected is below 100%"] = "Set the progress bar colors to be shown when the percentage collected is below 100%"
    MCLL["Progress Bar (100%)"] = "Progress Bar (100%)"
    MCLL["Set the progress bar colors to be shown when all mounts are collected"] = "Set the progress bar colors to be shown when all mounts are collected"
    MCLL["Reset Colors"] = "Reset Colors"
    MCLL["Reset to default colors"] = "Reset to default colors"
    MCLL["Layout Settings"] = "Layout Settings"
    MCLL["Mounts Per Row"] = "Mounts Per Row"
    MCLL["Set the number of mounts to display per row in the mount grid. Requires UI reload."] = "Set the number of mounts to display per row in the mount grid. Requires UI reload."
    MCLL["Unobtainable Settings"] = "Unobtainable Settings"
    MCLL["Hide Unobtainable from overview"] = "Hide Unobtainable from overview"
    MCLL["Hide Unobtainable mounts from the overview."] = "Hide Unobtainable mounts from the overview."
    MCLL["Show Minimap Icon"] = "Show Minimap Icon"
    MCLL["Toggle the display of the Minimap Icon."] = "Toggle the display of the Minimap Icon."
    MCLL["Reset Settings"] = "Reset Settings"
    MCLL["Reset to default settings"] = "Reset to default settings"
    MCLL["Hide Collected Mounts"] = "Hide Collected Mounts"
    MCLL["If enabled, collected mounts will not be shown in the list at all. Requires UI reload."] = "If enabled, collected mounts will not be shown in the list at all. Requires UI reload."
    MCLL["Changing this setting requires a UI reload. Reload now?"] = "Changing this setting requires a UI reload. Reload now?"
    MCLL["YES"] = "Yes"
    MCLL["NO"] = "No"
    MCLL["Use Blizzard Theme"] = "Use Blizzard Theme"
    MCLL["If enabled, the addon will use Blizzard's default UI theme. Requires UI reload."] = "If enabled, the addon will use Blizzard's default UI theme. Requires UI reload."
    MCLL["Search Results"] = "Search Results"
    MCLL["Search mounts..."] = "Search mounts..."
    MCLL["Mount Collection Log"] = "Mount Collection Log"
    MCLL["Clear Search"] = "Clear Search"
    MCLL["Sections"] = "Sections"
    MCLL["MCL | Mount Collection Log"] = "MCL | Mount Collection Log"
    MCLL["|cff00CCFFMount Collection Log Commands:\n|cffFF0000Show:|cffFFFFFF Shows your mount collection log\n|cffFF0000Icon:|cffFFFFFF Toggles the minimap icon\n|cffFF0000Config:|cffFFFFFF Opens the settings\n|cffFF0000Help:|cffFFFFFF Shows commands"] = "|cff00CCFFMount Collection Log Commands:\n|cffFF0000Show:|cffFFFFFF Shows your mount collection log\n|cffFF0000Icon:|cffFFFFFF Toggles the minimap icon\n|cffFF0000Config:|cffFFFFFF Opens the settings\n|cffFF0000Help:|cffFFFFFF Shows commands"
end

local MCLcore = {}

MCLcore.sectionNames = {}
MCLcore.mountList = {}

MCLcore.mountList[1] = {
	name = "SL",
	categories = {
		Achievement = {
			name = "Achievement",
			mounts = {186654, 186637, 184183, 182596, 186653, 184166, 186655, 187673, "m1549", "m1576"},
			mountID = {"m15491", "m1549", "m1576"}
		},
		Vendor = {
			name = "Vendor",
			mounts = {180748},
			mountID = {}
		},
		Treasures = {
			name = "Treasures",
			mounts = {180731, 180772, 190766},
			mountID = {}
		},
		Adventures = {
			name = "Adventures",
			mounts = {183052, 183617, 183615, 183618},
			mountID = {}
		},
		Riddles = {
			name = "Riddles",
			mounts = {184168,186713},
			mountID = {}
		},
		Tormentors = {
			name = "Tormentors",
			mounts = {185973},
			mountID = {}
		},
		MawAssaults = {
			name = "Maw Assaults",
			mounts = {185996, 186000, 186103},
			mountID = {}
		},
		Reputation = {
			name = "Reputation",
			mounts = {180729, 182082, 183518, 183740, 186647, 186648, 187629, 187640},
			mountID = {}
		},
		ParagonReputation = {
			name = "Paragon Reputation",
			mounts = {182081, 183800, 186649, 186644, 186657, 186641},
			mountID = {}
		},
		DungeonDrop = {
			name = "Dungeon Drop",
			mounts = {181819, 186638, "m1445"},
			mountID = {1445}
		},
		RaidDrop = {
			name = "Raid Drop",
			mounts = {186656, 186642, 190768},
			mountID = {}
		},
		Zone = {
			name = "Zone",
			mounts = {181818},
			mountID = {}
		},
		DailyActivities = {
			name = "Daily Activities",
			mounts = {182614, 182589, 186643, 186651, 186646, 188808},
			mountID = {}
		},
		RareSpawn = {
			name = "Rare Spawn",
			mounts = {180728, 180727, 180725, 182650, 180773, 182085, 184062, 182084, 182079, 180582, 183741, 184167, 187183, 186652 ,186645, 186659, 187676, 190765},
			mountID = {}
		},
		OozingNecrorayEgg = {
			name = "Oozing Necroray Egg",
			mounts = {184160, 184161, 184162},
			mountID = {}
		},
		CovenantFeature = {
			name = "Covenant Feature",
			mounts = {180726, 181316, 181300, 181317},
			mountID = {}
		},
		NightFae = {
			name = "Night Fae",
			mounts = {180263, 180721, 183053, 180722, 180413, 180415, 180414, 180723, 183801, 180724, 180730, 186493, 186494, 186495, 186492},
			mountID = {}
		},
		Kyrian = {
			name = "Kyrian",
			mounts = {180761, 180762, 180763, 180764, 180765, 180766, 180767, 180768, 186482, 186485, 186480, 186483},
			mountID = {}
		},
		Necrolords = {
			name = "Necrolords",
			mounts = {182078, 182077, 181822, 182076, 182075, 181821, 181815, 182074, 181820, 182080, 186487, 186488, 186490, 186489},
			mountID = {}
		},
		Venthyr = {
			name = "Venthyr",
			mounts = {182954, 180581, 180948, 183715, 180945, 182209, 182332, 183798, 180461, 186476, 186478, 186477, 186479},
			mountID = {}				
		},
		ProtoformSynthesis = {
			name = "Protoform Synthesis",
			mounts = {187632, 187670, 187663, 187665, 187630, 187631, 187638, 187664, 187677, 187683, 190580, 187679, 187667, 187639, 188809, 187668, 188810, 187672, 187669, 187641, 187678, 187671, 187660, 187666},
			mountID = {}
		},
		Torghast = {
			name = "Torghast",
			mounts = {188700, 188696, 188736},
			mountID = {}
		}
	}
}
MCLcore.mountList[2] = {
	name = "BFA",
	categories = {
		Achievement = {
			name = "Achievement",
			mounts = {168056, 168055, 169162, 163577, 169194, 168329, 161215, 163216, 166539, 167171, 174861, 174654, 235515},
			mountID = {}
		},
		Vendor = {
			name = "Vendor",
			mounts = {163183, 166442, 166443, 163589, 169203, 169202, 174770},
			mountID = {}
		},
		Quest = {
			name = "Quest",
			mounts = {159146, 168827, 168408, 169199, 174859, 174771, 169200, 170069},
			mountID = {}
		},
		Medals = {
			name = "Medals",
			mounts = {166464, 166436, 166469, 166465, 166463},
			mountID = {}
		},
		AlliedRaces = {
			name = "Allied Races",
			mounts = {155662, 156487, 161330, 157870, 174066, 156486, 155656, 161331, 164762, 174067, 223572},
			mountID = {}
		},
		Reputation = {
			name = "Reputation",
			mounts = {161773, 161774, 161665, 161666, 161667, 161664, 167167, 167170, 168829, 174754, 161911, 161912, 161910, 161879, 161909, 161908},
			mountID = {}
		},
		Riddle = {
			name = "Riddle",
			mounts = {156798},
			mountID = {}
		},
		Tinkering = {
			name = "Tinkering",
			mounts = {167751},
			mountID = {}
		},
		Zone = {
			name = "Zone",
			mounts = {163576, 163574, 163575, 163573},
			mountID = {}
		},
		RareSpawn = {
			name = "Rare Spawn",
			mounts = {161479, 166433, 169201, 168370, 168823, 169163, 174860},
			mountID = {}
		},
		WorldBoss = {
			name = "World Boss",
			mounts = {174842},
			mountID = {}
		},
		WarfrontArathi = {
			name = "Warfront: Arathi",
			mounts = {163579, 163578, 163644, 163645, 163706, 163646},
			mountID = {}
		},
		WarfrontDarkshore = {
			name = "Warfront: Darkshore",
			mounts = {166438, 166434, 166435, 166432},
			mountID = {}
		},
		AssaultVale = {
			name = "Assault: Vale of Eternal Blossoms",
			mounts = {173887, 174752, 174841, 174840, 174649},
			mountID = {}
		},
		AssaultUldum = {
			name = "Assault: Uldum",
			mounts = {174769, 174641, 174753},
			mountID = {}
		},
		DungeonDrop = {
			name = "Dungeon Drop",
			mounts = {159921, 160829, 159842, 168826, 168830},
			mountID = {}
		},	
		RaidDrop = {
			name = "Raid Drop",
			mounts = {166518, 166705, 174872},
			mountID = {}
		},	
		IslandExpedition = {
			name = "Island Expedition",
			mounts = {163584, 163585, 163583, 163586, 163582, 166470, 166468, 166467, 166466},
			mountID = {}
		},	
		Dubloons = {
			name = "Dubloons",
			mounts = {166471, 166745},
			mountID = {}
		},
		Visions = {
			name = "Visions",
			mounts = {174653},
			mountID = {}
		},
		ParagonReputation = {
			name = "Paragon Reputation",
			mounts = {169198},
			mountID = {}
		}
	}
}
MCLcore.mountList[3] = {
	name = "LEGION",
	categories = {
		Achievement = {
			name = "Achievement",
			mounts = {141216, 138387, 141217, 143864, 152815, 153041, 129280},
			mountID = {}
		},
		Vendor = {
			name = "Vendor",
			mounts = {138811, 141713, 137570},
			mountID = {}
		},
		Quest = {
			name = "Quest",
			mounts = {137573, 142436, 137577, 137578, 137579, 137580},
			mountID = {}
		},
		Riddle = {
			name = "Riddle",
			mounts = {138201, 147835, 151623},
			mountID = {}
		},
		RareSpawn = {
			name = "Rare Spawn",
			mounts = {138258, 152814, 152844, 152842, 152840, 152841, 152843, 152904, 152905, 152903, 152790},
			mountID = {}
		},
		DungeonDrop = {
			name = "Dungeon Drop",
			mounts = {142236, 142552},
			mountID = {}
		},
		RaidDrop = {
			name = "Raid Drop",
			mounts = {137574, 143643, 152816, 137575, 152789},
			mountID = {}
		},
		Class = {
			name = "Class",
			mounts = {142231, 143502, 143503, 143505, 143504, 143493, 143492, 143490, 143491, 142225, 142232, 143489, 142227, 142228, 142226, 142233, 143637, "m868", "m860", "m861", "m898"},
			mountID = {868, 860, 861, 898}
		},
		ParagonReputation = {
			name = "Paragon Reputation",
			mounts = {147806, 147804, 147807, 147805, 143764, 153042, 153044, 153043},
			mountID = {}
		},
		Reputation = {
			name = "Reputation",
			mounts = {152788, 152797, 152793, 152795, 152794, 152796, 152791},
			mountID = {}
		}
	}																										
}
MCLcore.mountList[4] = {
	name = "WOD",
	categories = {
		Achievement = {
			name = "Achievement",
			mounts = {116670, 116383, 127140, 128706},
			mountID = {}
		},
		Vendor = {
			name = "Vendor",
			mounts = {116664, 116785, 116772, 116672, 116768, 116671, 128480, 128526, 123974, 116667, 116655},
			mountID = {}
		},
		Garrison = {
			name = "Garrison",
			mounts = {116779, 116673, 116786, 116663},
			mountID = {}
		},
		Missions = {
			name = "Missions",
			mounts = {116769, 128311},
			mountID = {}
		},
		Stables = {
			name = "Stables",
			mounts = {116784, 116662, 116676, 116675, 116774, 116656, 116668, 116781},
			mountID = {}
		},
		TradingPost = {
			name = "Trading Post",
			mounts = {116782, 116665},
			mountID = {}
		},
		RareSpawn = {
			name = "Rare Spawn",
			mounts = {116674, 116659, 116661, 116792, 116767, 116773, 116794, 121815, 116780, 116669, 116658},
			mountID = {}
		},
		WorldBoss = {
			name = "World Boss",
			mounts = {116771},
			mountID = {}
		},
		RaidDrop = {
			name = "Raid Drop",
			mounts = {116660, 123890},
			mountID = {}
		},
		FishingShack = {
			name = "Fishing Shack",
			mounts = {87791},
			mountID = {}
		}		
	}		
}
MCLcore.mountList[5] = {
	name = "MOP",
	categories = {
		Achievement = {
			name = "Achievement",
			mounts = {87769, 87773, 81559, 93662, 104208, 89785},
			mountID = {}
		},
		GoldenLotus = {
			name = "Golden Lotus",
			mounts = {87781, 87782, 87783},
			mountID = {}
		},
		CloudSerpent = {
			name = "Order of the Cloud Serpent",
			mounts = {85430, 85429, 79802},
			mountID = {}
		},
		ShadoPan = {
			name = "Shado-Pan",
			mounts = {89305, 89306, 89307},
			mountID = {}
		},
		KunLai = {
			name = "Kun-Lai Vendor",
			mounts = {87788, 87789, 84101},
			mountID = {}
		},
		TheTillers = {
			name = "The Tillers",
			mounts = {89362, 89390, 89391},
			mountID = {}
		},
		PrimalEggs = {
			name = "Primal Eggs",
			mounts = {94291, 94292, 94293},
			mountID = {}
		},
		Quest = {
			name = "Quest",
			mounts = {93386, 87768, 94290, 93385},
			mountID = {}
		},
		RaidDrop = {
			name = "Raid Drop",
			mounts = {87777, 93666, 95059, 104253},
			mountID = {}
		},
		RareSpawn = {
			name = "Rare Spawn",
			mounts = {90655, 94229, 94230, 94231, 104269},
			mountID = {}
		},
		WorldBoss = {
			name = "World Boss",
			mounts = {94228, 87771, 89783, 95057},
			mountID = {}
		},
		Reputation = {
			name = "Reputation",
			mounts = {93169, 95565, 81354, 89304, 85262, 89363, 87774, 93168, 95564},
			mountID = {}
		}
	}																																
}
MCLcore.mountList[6] = {
	name = "CATA",
	categories = {
		Achievement = {
			name = "Achievement",
			mounts = {62900, 62901, 69213, 69230, 77068},
			mountID = {}
		},
		Quest = {
			name = "Quest",
			mounts = {54465},
			mountID = {}
		},
		Vendor = {
			name = "Vendor",
			mounts = {65356, 64999, 63044, 63045, 64998},
			mountID = {}
		},
		DungeonDrop = {
			name = "Dungeon Drop",
			mounts = {69747, 63040, 63043, 68823, 68824},
			mountID = {}
		},
		RaidDrop = {
			name = "Raid Drop",
			mounts = {77067, 77069, 78919, 63041, 69224, 71665},
			mountID = {}
		},
		RareSpawn = {
			name = "Rare Spawn",
			mounts = {67151, 63042, 63046},
			mountID = {}
		}		
	}										
}
MCLcore.mountList[7] = {
	name = "WOTLK",
	categories = {
		Achievement = {
			name = "Achievement",
			mounts = {44160, 45801, 45802, 51954, 51955},
			mountID = {}
		},
		Quest = {
			name = "Quest",
			mounts = {43962, 52200},
			mountID = {}
		},
		Vendor = {
			name = "Vendor",
			mounts = {44690, 44231, 44234, 44226, 44689, 44230, 44235, 44225},
			mountID = {}
		},
		ArgentTournament = {
			name = "Argent Tournament",
			mounts = {46814, 45592, 45593, 45595, 45596, 45597, 46743, 46746, 46749, 46750, 46751, 46816, 47180, 45725, 45125, 45586, 45589, 45590, 45591, 46744, 46745, 46747, 46748, 46752, 46815, 46813},
			mountID = {}
		},
		Reputation = {
			name = "Reputation",
			mounts = {44080, 44086, 43955, 44707, 43958, 43961},
			mountID = {}
		},
		DungeonDrop = {
			name = "Dungeon Drop",
			mounts = {43951, 44151},
			mountID = {}
		},
		RaidDrop = {
			name = "Raid Drop",
			mounts = {43952, 43953, 43954, 43986, 49636, 43959, 45693, 50818, 44083,206585},
			mountID = {}
		},
		RareSpawn = {
			name = "Rare Spawn",
			mounts = {44168},
			mountID = {}
		}			
	}																		
}
MCLcore.mountList[8] = {
	name = "TBC",
	categories = {
		CenarionExpedition = {
			name = "Cenarion Expedition",
			mounts = {33999},
			mountID = {}
		},
		Kurenai = {
			name = "Kurenai/The Mag'har",
			mounts = {29227, 29231, 29229, 29230, 31830, 31832, 31834, 31836},
			mountID = {}
		},
		Netherwing = {
			name = "Netherwing",
			mounts = {32858, 32859, 32857, 32860, 32861, 32862},
			mountID = {}
		},
		Shatari = {
			name = "Sha'tari Skyguard",
			mounts = {32319, 32314, 32316, 32317, 32318},
			mountID = {}
		},
		Vendor = {
			name = "Vendor",
			mounts = {25473, 25527, 25528, 25529, 25470, 25471, 25472, 25477, 25531, 25532, 25533, 25474, 25475, 25476},
			mountID = {}
		},
		DungeonDrop = {
			name = "Dungeon Drop",
			mounts = {32768, 35513},
			mountID = {}
		},
		RaidDrop = {
			name = "Raid Drop",
			mounts = {32458, 30480},
			mountID = {}
		}
	}
}
MCLcore.mountList[9] = {
	name = "Classic",
	categories = {	
		Reputation = {
			name = "Reputation",
			mounts = {13086, 46102},
			mountID = {}
		},
		DungeonDrop = {
			name = "Dungeon Drop",
			mounts = {13335},
			mountID = {}
		},
		RaidDrop = {
			name = "Raid Drop",
			mounts = {21218, 21321, 21323, 21324},
			mountID = {}
		}
	}						
}
MCLcore.mountList[10] = {
	name = "Alliance",
	categories = {	
		Human = {
			name = "Human",
			mounts = {18776, 18777, 18778, 5655, 2411, 2414, 5656},
			mountID = {}
		},
		NightElf = {
			name = "Night Elf",
			mounts = {18766, 18767, 18902, 8629, 8631, 8632, 47100},
			mountID = {}
		},
		Dwarf = {
			name = "Dwarf",
			mounts = {18785, 18786, 18787, 5864, 5872, 5873},
			mountID = {}
		},
		DarkIronDwarf = {
			name = "Dark Iron Dwarf",
			mounts = {191123},
			mountID = {}
		},
		Gnome = {
			name = "Gnome",
			mounts = {18772, 18773, 18774, 8563, 8595, 13322, 13321},
			mountID = {}
		},
		Draenei = {
			name = "Draenei",
			mounts = {29745, 29746, 29747, 28481, 29743, 29744},
			mountID = {}
		},
		Worgen = {
			name = "Worgen",
			mounts = {73839, 73838},
			mountID = {}
		},
		Pandaren = {
			name = "Pandaren",
			mounts = {91010, 91012, 91011, 91013, 91014, 91015, 91004, 91008, 91009, 91005, 91006, 91007},
			mountID = {}
		},
		Dracthyr = {
			name = "Dracthyr",
			mounts = {201720, 201702, 201719, 201704, 198809, 198811, 198810, 198808},
			mountID = {},
		}		
	}				
}
MCLcore.mountList[11] = {
	name = "Horde",
	categories = {	
		Orc = {
			name = "Orc",
			mounts = {18796, 18798, 18797, 46099, 5668, 5665, 1132},
			mountID = {}
		},
		Undead = {
			name = "Undead",
			mounts = {13334, 18791, 13331, 13332, 13333, 46308, 47101},
			mountID = {}
		},
		Tauren = {
			name = "Tauren",
			mounts = {18793, 18794, 18795, 15277, 15290, 46100},
			mountID = {}
		},
		Troll = {
			name = "Troll",
			mounts = {18788, 18789, 18790, 8588, 8591, 8592},
			mountID = {}
		},
		Bloodelf = {
			name = "Blood Elf",
			mounts = {28936, 29223, 29224, 28927, 29220, 29221, 29222, 191566},
			mountID = {}
		},
		Goblin = {
			name = "Goblin",
			mounts = {62462, 62461},
			mountID = {}
		},			
		Pandaren = {
			name = "Pandaren",
			mounts = {91010, 91012, 91011, 91013, 91014, 91015, 91004, 91008, 91009, 91005, 91006, 91007},
			mountID = {}
		},
		Dracthyr = {
			name = "Dracthyr",
			mounts = {201720, 201702, 201719, 201704, 198809, 198811, 198810, 198808},
			mountID = {},
		}
	}
}
MCLcore.mountList[12] = {
	name = "Professions",
	categories = {	
		Alchemy = {
			name = "Alchemy",
			mounts = {65891},
			mountID = {}
		},
		Archeology = {
			name = "Archeology",
			mounts = {60954, 64883, 131734},
			mountID = {}
		},
		Engineering = {
			name = "Engineering",
			mounts = {34060, 41508, 34061, 44413, 87250, 87251, 95416, 161134, 153594},
			mountID = {}
		},
		Fishing = {
			name = "Fishing",
			mounts = {46109, 23720, 152912, 163131},
			mountID = {}
		},
		Jewelcrafting = {
			name = "Jewelcrafting",
			mounts = {83088, 83087, 83090, 83089, 82453},
			mountID = {}
		},
		Tailoring = {
			name = "Tailoring",
			mounts = {44554, 54797, 44558, 115363},
			mountID = {}
		},
		Leatherworking = {
			name = "Leatherworking",
			mounts = {108883, 129962},
			mountID = {}
		},
		Blacksmith = {
			name = "Blacksmith",
			mounts = {137686},
			mountID = {}
		}
	}
}
MCLcore.mountList[13] = {
	name = "PVP",
	categories = {	
		Achievement = {
			name = "Achievement",
			mounts = {44223, 44224},
			mountID = {}
		},
		MarkHonor = {
			name = "Mark of Honor",
			mounts = {19030, 29465, 29467, 29468, 29471, 35906, 43956, 29466, 29469, 29470, 29472, 19029, 34129, 44077},
			mountID = {}
		},
		Honor = {
			name = "Honor",
			mounts = {140228, 140233, 140408, 140232, 140230, 140407, 164250},
			mountID = {}
		},
		ViciousSaddle = {
			name = "Vicious Saddle",
			mounts = {102533, 70910, 116778, 124540, 140348, 140354, 143649, 142235, 142437, 152869, 163124, 165020, 163121, 173713, 184013,184014, 186179, 70909, 102514, 116777, 124089, 140353, 140350, 143648, 142234, 142237, 152870, 163123, 163122, 173714, 186178, 187681, 187680, 187642, 187644, 201788, 201789, 205245, 205246, 210070, 210069, 213439, 213440,223511,221813,229989,229988},
			mountID = {}
		},
		Gladiator = {
			name = "Gladiator",
			mounts = {229987},
			mountID = {}
		},
		Halaa = {
			name = "Halaa",
			mounts = {28915, 29228},
			mountID = {}
		},
		Ashran = {
			name = "Ashran",
			mounts = {116776, 116775}
		},
		TimelessIsle = {
			name = "Timeless Isle",
			mounts = {103638},
			mountID = {}
		},
		TalonsVengeance = {
			name = "Talon's Vengeance",
			mounts = {142369},
			mountID = {}
		}
	}
}
MCLcore.mountList[14] = {
	name = "WorldEvents",
	categories = {	
		Achievement = {
			name = "Achievement",
			mounts = {44177},
			mountID = {}
		},
		Brewfest = {
			name = "Brewfest",
			mounts = {33977, 37828},
			mountID = {}
		},
		HallowsEnd = {
			name = "Hallow's End",
			mounts = {37012},
			mountID = {}
		},
		LoveAir = {
			name = "Love is in the Air",
			mounts = {72146, 50250, 210973, 232926},
			mountID = {}
		},
		NobleGarden = {
			name = "Noblegarden",
			mounts = {72145, 212599},
			mountID = {}
		},
		WinterVeil = {
			name = "Winter Veil",
			mounts = {128671},
			mountID = {}
		},
		DarkmoonFaire = {
			name = "Darkmoon Faire",
			mounts = {72140, 73766, 142398, 153485},
			mountID = {}
		},
		TimeWalking = {
			name = "Timewalking",
			mounts = {129923, 129922, 87775, 167894, 167895, 133543, 188674, 187595, 231374, 224398, 224399,234730,232624,205208,234721,234716,234740},
			mountID = {}
		},
		Lunar = {
			name = "Lunar Festival",
			mounts = {232901},
			mountID = {}
		},
		lnuizuoqi = {
			name = "lnuizuoqi",
			mounts = {13335, 32768, 35513, 30480, 32458, 44151, 43952, 43953, 44083, 45693, 49636, 50818, 63040, 63043, 68823, 68824, 63041, 69224, 71665, 77067, 77069, 78919, 87777, 93666, 95059, 104253, 116660, 123890, 142236, 137575, 137574, 143643, 152789, 152816, 159842, 159921, 160829, 168826, 166518,166705, 174872, 181819, 186638, 186642, 186656, 190768},
			mountID = {}
		}
	}
}
MCLcore.mountList[15] = {
	name = "Promotion",
	categories = {	
		BlizzardStore = {
			name = "Blizzard Store",
			mounts = {54811, 69846, 78924, 97989, 107951, 112326, 122469, 147901, 156564, 160589, 166775, 166774, 166776, "m1266", "m1267", "m1290", "m1346", "m1291", "m1456", "m1330", "m1531", "m1581", "m1312", "m1662", "m1594", "m1583", "m1797", 203727, "m1795", "m1692", 212229, 228751, 229128, 219450, 224574, "m2237", 229418, 230184, 230200, 230201, 230185, 227362, 235344, 231297, 233285, 233284, 233282, 233283, 233286, 238943,238994},
			mountID = {1266, 1267, 1290, 1346, 1291, 1456, 1330, 1531, 1581}
		},
		CollectorsEdition = {
			name = "Collector's Edition",
			mounts = {85870, 109013, 128425, 153539, 153540, "m1289", "m1556", "m1792"},
			mountID = {1289, 1556}
		},
		WowClassic = {
			name = "WoW Classic",
			mounts = {"m1444", "m1602", "m1812"},
			mountID = {1444, 1602}
		},
		anniversary = {
			name = "WoW Anniversary Mounts",
			mounts = {172022, 172023, 186469, 208572, 228760, 229348},
			mountID = {}
		},
		Hearthstone = {
			name = "Hearthstone",
			mounts = {98618, "m1513", 163186, 212522},
			mountID = {1513}
		},
		WarcraftIII = {
			name = "Warcraft III Reforged",
			mounts = {164571},
			mountID = {}
		},
		DiabloIV = {
			name = "Diablo IV",
			mounts = {"m1596", 246264},
			mountID = {}
		},		
		RAF = {
			name = "Recruit-A-Friend",
			mounts = {173297, 173299, 204091},
			mountID = {}
		},
		AzerothChoppers = {
			name = "Azeroth Choppers",
			mounts = {116789},
			mountID = {}
		},
		TCG = {
			name = "Trading Card Game",
			mounts = {49283, 49284, 49285, 49286, 49282, 49290, 54069, 54068, 68008, 69228, 68825, 71718, 72582, 72575, 79771, 93671},
			mountID = {}
		},
		AV = {
			name = "Timewalking Alterac Valley",
			mounts = {172023, 172022},
			mountID = {}
		},
		PlunderStorm = {
			name="Plunderstorm",
			mounts = {233241,233240,233243,233242},
		},
		ProductPromotion = {
			name="Product Promotion",
			mounts = {"m1947", "m1946"}
		}
	}	
}
MCLcore.mountList[16] = {
	name = "Other",
	categories = {	
		GuildVendor = {
			name = "Guild Vendor",
			mounts = {63125, 62298, 67107, 85666, 116666},
			mountID = {}
		},
		BMAH = {
			name = "BMAH",
			mounts = {19872, 19902, 44175, 163042},
			mountID = {}
		},
		MountCollection = {
			name = "Mount Collection",
			mounts = {44178, 44843, 44842, 98104, 91802, 98259, 69226, 87776, 137614, 163981, 118676, 198654},
			mountID = {}
		},
		ExaltedReputations = {
			name = "Exalted Reputations",
			mounts = {163982},
			mountID = {}
		},
		Toy = {
			name = "Toy",
			mounts = {140500},
			mountID = {}
		},
		Heirlooms = {
			name = "Heirlooms",
			mounts = {120968, 122703},
			mountID = {}
		},
		Paladin = {
			name="Paladin",
			mounts = {47179, "m2233", "m41", "m84", "m149", "m150", "m350", "m351", "m367", "m368", "m1046", "m1047", "m1568"},
			mountID = {}
		},
		Warlock = {
			name="Warlock",
			mounts = {"m17", "m83"},
			mountID = {17, 83},
		},
		DemonHunter = {
			name="Demon Hunter",
			mounts = {"m780"},
		},
		TradingPost = {
			name = "Trading Post",
			mounts = {190231, 190168, 190539, 190767, 190613, 206156, 137576, 208598, 211074, 210919, 212227, 212630, 212920, 192766, 226041, 226040, 226044, 226042, 226506, 223449, 223469, 187674, 233019,233020,233023,233354,212631, 223285, 221814, 207821, 190169, 189978, 206976, 206027, "m1595", 235646, 235650, 235555, 235556, 235554, 235657, 235557, 235658, 235659, 235662,238967,238897,238941,236415,238902,238901,238968,238900, 243593, 243597, 243594, 243590, 243572, 243591, 243592, 245936, 243596},
		},		
	}
}
MCLcore.mountList[17] = {
	name = "Unobtainable",
	categories = {	
		MythicPlus = {
			name = "Mythic +",
			mounts = {182717, 187525, 174836, 187682, 192557, 199412, 204798, 209060, 213438, 226357},
			mountID = {}
		},
		ScrollOfResurrection = {
			name = "Scroll of Resurrection",
			mounts = {76902, 76889},
			mountID = {}
		},
		ChallengeMode = {
			name = "Challenge Mode",
			mounts = {89154, 90710, 90711, 90712, 116791},
			mountID = {}
		},
		RAF = {
			name = "Recruit-A-Friend",
			mounts = {83086, 106246, 118515, 37719, "m382"},
			mountID = {}
		},
		AOTC = {
			name = "Ahead of the Curve",
			mounts = {104246, 128422, 152901, 174862, 190771},
			mountID = {}
		},
		Brawl = {
			name = "Brawler's Guild",
			mounts = {142403, 98405, 166724},
			mountID = {}
		},
		Arena = {
			name = "Arena Mounts",
			mounts = {30609, 34092, 37676, 43516, 46708, 46171, 47840, 50435, 71339, 71954, 85785, 95041, 104325, 104326, 104327, 128277, 128281, 128282, 141843, 141844, 141845, 141846, 141847, 141848, 153493, 156879, 156880, 156881, 156884, 183937, 186177, 189507, 191290, 202086, 205233, 210345, "m1822", 223586},
			mountID = {}
		},
		DCAzerothChopper = {
			name = "Azeroth Choppers",
			mounts = {116788},
			mountID = {}
		},
		OriginalEpic = {
			name = "Original Epic Mounts",
			mounts = {13328, 13329, 13327, 13326, 12354, 12353, 12302, 12303, 12351, 12330, 15292, 15293, 13317, 8586},
			mountID = {}
		},
		Promotion = {
			name = "Old Promotion Mounts",
			mounts = {76755, 95341, 112327, 92724, 143631, 163127, 43599, 151618, "m1458"},
			mountID = {}
		},	
		RaidMounts = {
			name = "Unobtainable Raid Mounts",
			mounts = {49098, 49096, 49046, 49044, 44164, 33809, 21176, "m937"},
			mountID = {937}
		},
		BrewFest = {
			name = "BrewFest",
			mounts = {33976},
			mountID = {}
		},
		Anniversary = {
			name="Old Anniversary Mounts",
			mounts = {172012, 115484, "m1424"},
			mountID = {}
		},
		PreLaunchEvent = {
			name = "Pre-Launch Event",
			mounts = {163127, 163128, 217987, 217985},
			mountID = {}
		},
		RemixMOP = {
			name="Remix MOP",
			mounts = {220766,220768,213582,213576,213584,213595,87784,213602,213603,213605,213606,213607,213604,213608,213609,213628,213627,87786,87787,84753,213626,213624,213625,213623,213622,213621,218111,213600,213601,213598,213597,213596},	
		}
	}
}
MCLcore.mountList[18] = {
	name = "Dragonflight",
	categories = {
		DragonRiding = {
			name = "Dragon Riding",
			mounts = {194034, 194705, 194521, 194549, 204361, 210412}
		},
		Achievement = {
			name = "Achievement",
			mounts = {192806, 192791, 192784, 205205, 208152, 210060, 192774, 210142, "m1614", 198822, 192792, 192788, 211862, 192765, "m1733", 217340},
		},
		Treasures = {
			name = "Treasures",
			mounts = {201440, 198825, 192777, 192779,205204, 210059},
		},
		Quest = {
			name = "Quest",
			mounts = {192799, 198870, 206567, 206566, "m1545", 210774, 211873},
		},
		Reputation = {		
			name = "Renown",
			mounts = {192762, 198872, 192761, 192764, 200118, 201426, 201425, 205155, 205209, 205207, 210969, 210833, 210831, 210946, 210948, 210945, 209951, 209949},
		},
		Zone = {
			name = "Zone",
			mounts = {192601, 198873, 198871, 192775, 201454, 192800, 204382, 192785, 192790, 192772, 191838, 205203, 205197,210775, 210769, 210058, 210057, 209947, 209950, 212645, "m1638", 192807, 198824},
		},
		Secret = {
			name = "Secret",
			mounts = {192786}
		},
		Vendor = {
			name = "Vendor",
			mounts = {206673, 206680, 206676, 206678, 206674, 206679, 206675, 211084}
		},
		Raid = {
			name = "Raid",
			mounts = {"m1818"}
		},
	}
}
MCLcore.mountList[19] = {
	name = "The War Within",
	categories = {
		RareDrops = {
			name = "Rare Drops",
			mounts = {223315,223270,223501},
		},
		Raid = {
			name = "Raid",
			mounts = {224147,224151, 236960, 235626, 229945, 229924, 229940},
		},
		Dungeon = {
			name = "Dungeon",
			mounts = {221765,225548},
		},
		Achievement = {
			name = "Achievement",
			mounts = {223266,224415,223267,223286,223158, "m2190", 231173, 235549, 237141},
		},
		Quest = {
			name = "Quest",
			mounts = {219391,224150, 246237},
		},
		Reputation = {
			name = "Reputation",
			mounts = {223571,221753,223505,222989,223317,223314,223274,223264,223276,223278,223279,238829},
		},
		Profession = {
			name = "Profession",
			mounts = {221967, 235712},
		},
		Vendor = {
			name = "Vendor",
			mounts = {223153},
		},
		Zone = {
			name = "Zone",
			mounts = {223269, 223318},
		},
		SirenIsland = {
			name = "Siren Island",
			mounts = {232639, 233058, 233489, 232991}
		},
		UnderMine = {
			name = "Undermine",
			mounts = {229974, 229953, 229955,  229954, 229941, 229952, 229949, 229947, 233064, "m2281", "m2295", "m2289", "m2274"}
		},
		Incursion = {
			name = "Incursion",
			mounts = {239563, 239020}
		},
		HorrificVisions = {
			name = "Horrific Visions",
			mounts = {235711,235709,235705,235700,235706,235707,211089}
		},
		Delves = {
			name = "Delves",
			mounts = {229944,229956,229948,229935,229946,229936,229950}
		}	
	}
}
MCLcore.sectionNames[11] = {
	name = "Vanilla",
	mounts = MCLcore.mountList[9],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\classic.blp",
	isExpansion = true,
}
MCLcore.sectionNames[10] = {
	name = "The Burning Crusade",
	mounts = MCLcore.mountList[8],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\bc.blp",
	isExpansion = true,
}
MCLcore.sectionNames[9] = {
	name = "Wrath of the Lich King",
	mounts = MCLcore.mountList[7],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\wrath.blp",
	isExpansion = true,
}
MCLcore.sectionNames[8] = {
	name = "Cataclysm",
	mounts = MCLcore.mountList[6],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\cata.blp",
	isExpansion = true,
}
MCLcore.sectionNames[7] = {
	name = "Mists of Pandaria",
	mounts = MCLcore.mountList[5],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\mists.blp",
	isExpansion = true,
}
MCLcore.sectionNames[6] = {
	name = "Warlords of Draenor",
	mounts = MCLcore.mountList[4],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\wod.blp",
	isExpansion = true,
}
MCLcore.sectionNames[5] = {
	name = "Legion",
	mounts = MCLcore.mountList[3],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\legion.blp",
	isExpansion = true,
}
MCLcore.sectionNames[4] = {
	name = "Battle for Azeroth",
	mounts = MCLcore.mountList[2],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\bfa.blp",
	isExpansion = true,
}
MCLcore.sectionNames[3] = {
	name = "Shadowlands",
	mounts = MCLcore.mountList[1],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\sl.blp",
	isExpansion = true,
}
MCLcore.sectionNames[2] = {
	name = "Dragonflight",
	mounts = MCLcore.mountList[18],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\df.blp",
	isExpansion = true,
}
MCLcore.sectionNames[1] = {
	name = "The War Within",
	mounts = MCLcore.mountList[19],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\tww.blp",
	isExpansion = true,
}
MCLcore.sectionNames[12] = {
	name = "Horde",
	mounts = MCLcore.mountList[11],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\horde.blp",
	isExpansion = false,
}
MCLcore.sectionNames[13] = {
	name = "Alliance",
	mounts = MCLcore.mountList[10],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\alliance.blp",
	isExpansion = false,
}
MCLcore.sectionNames[14] = {
	name = "Professions",
	mounts = MCLcore.mountList[12],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\professions.blp",
	isExpansion = false,
}
MCLcore.sectionNames[15] = {
	name = "PVP",
	mounts = MCLcore.mountList[13],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\pvp.blp",
	isExpansion = false,
}
MCLcore.sectionNames[16] = {
	name = "World Events",
	mounts = MCLcore.mountList[14],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\holiday.blp",
	isExpansion = false,
}
MCLcore.sectionNames[17] = {
	name = "Promotion",
	mounts = MCLcore.mountList[15],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\promotion.blp",
	isExpansion = false,
}
MCLcore.sectionNames[18] = {
	name = "Other",
	mounts = MCLcore.mountList[16],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\other.blp",
	isExpansion = false,
}
MCLcore.sectionNames[19] = {
	name = "Unobtainable",
	mounts = MCLcore.mountList[17],
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\unobtainable.blp",
	isExpansion = false,
}
MCLcore.sectionNames[20] = {
	name = "Pinned",
	mounts = {MCL_PINNED},
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\pin.blp",
	isExpansion = false,
}
MCLcore.sectionNames[21] = {
	name = "Overview",
	mounts = {},
	icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\mcl.blp",
	isExpansion = false,
}

MCLcore.regionalFilter = {
	['CN'] = {210077},
}

MCLcore.Function = {};
local MCL_functions = MCLcore.Function;

MCLcore.mounts = {}
MCLcore.stats= {}
MCLcore.overviewStats = {}
MCLcore.overviewFrames = {}
MCLcore.mountFrames = {}
MCLcore.mountCheck = {}
MCLcore.addon_name = MCLL["Addons"]


function MCL_functions:getFaction()
    -- * --------------------------------
    -- * Get's player faction
    -- * --------------------------------
	if UnitFactionGroup("player") == "Alliance" then
		return "Horde" -- Inverse
	else
		return "Alliance" -- Inverse
	end
end

-- local function IsMountFactionSpecific(id)
--     if string.sub(id, 1, 1) == "m" then
--         mount_Id = string.sub(id, 2, -1)
--         local mountName, spellID, icon, _, _, _, _, isFactionSpecific, faction, _, isCollected, mountID, _ = C_MountJournal.GetMountInfoByID(mount_Id)
--         return faction, isFactionSpecific
--     else
--         mount_Id = C_MountJournal.GetMountFromItem(id)
--         local mountName, spellID, icon, _, _, _, _, isFactionSpecific, faction, _, isCollected, mountID, _ = C_MountJournal.GetMountInfoByID(mount_Id)
--         return faction, isFactionSpecific
--     end
-- end

local function GetMountInfoByIDChecked(mount_Id)
    local mountName, spellID, icon, _, _, _, _, isFactionSpecific, faction, _, isCollected, mountID, _ = C_MountJournal.GetMountInfoByID(mount_Id)
    return faction, isFactionSpecific
end

local function IsMountFactionSpecific(id)
    local mount_Id, ok, faction, isFactionSpecific

    if string.sub(id, 1, 1) == "m" then
        mount_Id = string.sub(id, 2, -1)
    else
        mount_Id = C_MountJournal.GetMountFromItem(id)
    end

    -- Use pcall to execute GetMountInfoByIDChecked and capture any error
    ok, faction, isFactionSpecific = pcall(GetMountInfoByIDChecked, mount_Id)

    -- If an error occurred, print the error message along with the id that caused the error
    if not ok then
        return nil, nil
    else
        return faction, isFactionSpecific
    end
end

MCLcore.Function.IsMountFactionSpecific = IsMountFactionSpecific

function MCL_functions:resetToDefault(setting)
    if setting == nil then
        MCL_SETTINGS = {}        
        MCL_SETTINGS.unobtainable = false
        MCL_SETTINGS.hideCollectedMounts = false
    end
    if setting == "Opacity" or setting == nil then
        MCL_SETTINGS.opacity = 0.95
    end
    if setting == "Texture" or setting == nil then
        MCL_SETTINGS.statusBarTexture = nil
    end
    if setting == "Colors" or setting == nil then
        MCL_SETTINGS.progressColors = {
            low = {
                ["a"] = 1,
                ["r"] = 0.929,
                ["g"] = 0.007,
                ["b"] = 0.019,
            },
            high = {
                ["a"] = 1,
                ["r"] = 0.1,
                ["g"] = 0.9,
                ["b"] = 0.1,
            },
            medium = {
                ["a"] = 1,
                ["r"] = 0.941,
                ["g"] = 0.658,
                ["b"] = 0.019,
            },
            complete = {
                ["a"] = 1,
                ["r"] = 0,
                ["g"] = 0.5,
                ["b"] = 0.9,
            },
        }
    end
    if setting == "HideCollectedMounts" or setting == nil then
        MCL_SETTINGS.hideCollectedMounts = false
    end
    if setting == "BlizzardTheme" or setting == nil then
        MCL_SETTINGS.useBlizzardTheme = false
    end
    if setting == "MountsPerRow" or setting == nil then
        MCL_SETTINGS.mountsPerRow = 12
    end
end

if MCL_SETTINGS == nil then
    MCLcore.Function:resetToDefault()
end

-- Ensure mountsPerRow setting exists for existing users
if MCL_SETTINGS.mountsPerRow == nil then
    MCL_SETTINGS.mountsPerRow = 12
end

-- Tables Mounts into Global List
function MCL_functions:TableMounts(id, frame, section, category)
    local mount = {
        id = id,
        frame = frame,
        section =  section,
        category = category,
    }
    table.insert(MCLcore.mounts, mount)
end

function MCL_functions:simplearmoryLink()
    local region = GetCVar("portal")

    local realmName = GetRealmName()

    local playerName = UnitName("player")

    local string = "https://simplearmory.com/#/"..region.."/"..realmName.."/"..playerName

    KethoEditBox_Show(string)

end

function MCL_functions:dfaLink()
    local region = GetCVar("portal")

    local realmName = GetRealmName()

    local playerName = UnitName("player")

    local string = "https://www.dataforazeroth.com/characters/"..region.."/"..realmName.."/"..playerName

    KethoEditBox_Show(string)

end

function MCL_functions:compareLink()
    local region = GetCVar("portal")

    local realmName = GetRealmName()

    local playerName = UnitName("player")
    local targetName, targetRealm
    if UnitIsPlayer("target") then
        targetName, targetRealm = UnitName("target")
        if targetRealm == nil then
            targetRealm = realmName
        end
    else
        KethoEditBox_Show("挂载需要目标")
        return
    end
    
    local string = "https://wow-mcl.herokuapp.com/?realma="..region.."."..realmName.."&charactera="..playerName.."&realmb="..region.."."..targetRealm.."&characterb="..targetName
    
    KethoEditBox_Show(string)
end


function KethoEditBox_Show(text)
    if not KethoEditBox then
        local f = CreateFrame("Frame", "KethoEditBox", UIParent, "DialogBoxFrame")
        f:SetPoint("CENTER")
        f:SetSize(700, 100)
        
        f:SetBackdrop({
            bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
            edgeFile = "Interface\\PVPFrame\\UI-Character-PVP-Highlight", -- this one is neat
            edgeSize = 16,
            insets = { left = 8, right = 6, top = 8, bottom = 8 },
        })
        f:SetBackdropBorderColor(0, .44, .87, 0.5) -- darkblue
        
        -- Movable
        f:SetMovable(true)
        f:SetClampedToScreen(true)
        f:SetScript("OnMouseDown", function(self, button)
            if button == "LeftButton" then
                self:StartMoving()
            end
        end)
        f:SetScript("OnMouseUp", f.StopMovingOrSizing)
        
        -- ScrollFrame
        local sf = CreateFrame("ScrollFrame", "KethoEditBoxScrollFrame", KethoEditBox, "UIPanelScrollFrameTemplate")
        sf:SetPoint("LEFT", 16, 0)
        sf:SetPoint("RIGHT", -32, 0)
        sf:SetPoint("TOP", 0, -16)
        sf:SetPoint("BOTTOM", KethoEditBoxButton, "TOP", 0, 0)
        
        -- EditBox
        local eb = CreateFrame("EditBox", "KethoEditBoxEditBox", KethoEditBoxScrollFrame)
        eb:SetSize(sf:GetSize())
        eb:SetMultiLine(true)
        eb:SetAutoFocus(false) -- dont automatically focus
        eb:SetFontObject("ChatFontNormal")
        eb:SetScript("OnEscapePressed", function() f:Hide() end)
        sf:SetScrollChild(eb)
        
        -- Resizable
        f:SetResizable(true)
        f:SetFrameStrata("HIGH")
        
        f:Show()
    end
    
    if text then
        KethoEditBoxEditBox:SetText(text)
    end
    KethoEditBox:Show()
    MCLcore.MCL_MF:Hide()
end

function MCL_functions:initSections()
    -- * --------------------------------
    -- * Create variables and assign strings to each section.
    -- * --------------------------------

    local faction = MCL_functions:getFaction()
    MCLcore.sections = {}

    for i, v in ipairs(MCLcore.sectionNames) do
        -- Skip opposite faction section
        if v.name ~= faction then
            table.insert(MCLcore.sections, v)
        end
    end

    MCLcore.MCL_MF_Nav = MCLcore.Frames:createNavFrame(MCLcore.MCL_MF, MCLL["Sections"])

    -- Create the overview parent frame before SetTabs
    if not MCLcore.overview or not MCLcore.overview:IsObjectType("Frame") then
        -- Use the same width calculations from frames.lua for consistency
        local main_frame_width = 1250  -- Match the width from frames.lua
        MCLcore.overview = CreateFrame("Frame", nil, MCL_mainFrame.ScrollChild, "BackdropTemplate")
        MCLcore.overview:SetSize(main_frame_width - 60, 550)  -- Use consistent width calculation
        MCLcore.overview:SetPoint("TOPLEFT", MCL_mainFrame.ScrollChild, "TOPLEFT", 30, 0)  -- Consistent with other content frames
        MCLcore.overview:SetBackdropColor(0, 0, 0, 0)
    end
    -- Build the overview content into the overview frame
    MCLcore.Frames:createOverviewCategory(MCLcore.sections, MCLcore.overview)

    local tabFrames, numTabs = MCLcore.Frames:SetTabs() 

    MCLcore.sectionFrames = {}
    for i=1, numTabs do
        -- The section frames are already created in SetTabs, just reference them
        if tabFrames and tabFrames[i] then
            table.insert(MCLcore.sectionFrames, tabFrames[i])
        end
    end    
end


function MCL_functions:GetCollectedMounts()
    local mounts = {}
    for k,v in pairs(C_MountJournal.GetMountIDs()) do
        local mountName, spellID, icon, _, isUsable, _, _, isFactionSpecific, faction, _, isCollected, mountID = C_MountJournal.GetMountInfoByID(v)
        if isCollected then
            if faction then
                if faction == 1 then
                    faction = "Alliance"
                else
                    faction = "Horde"
                end
            end
            if (isFactionSpecific == false) or (isFactionSpecific == true and faction == UnitFactionGroup("player")) then                     
                table.insert(mounts, mountID)
            end   
        end
    end
    for k,v in pairs(mounts) do
        local exists = false
        for kk,vv in pairs(MCLcore.mountCheck) do
            if v == vv then
                exists = true
            end
        end
    end
end

function MCL_functions:CreateBorder(frame, side)
    frame.borders = frame:CreateLine(nil, "BACKGROUND", nil, 0)
    local l = frame.borders
    l:SetThickness(1)
    l:SetColorTexture(1, 1, 1, 0.4)
	l:SetStartPoint("BOTTOM"..side)
	l:SetEndPoint("TOP"..side)
    return frame
end


function MCL_functions:CreateFullBorder(self)
    if not self.borders then
        self.borders = {}
        for i=1, 4 do
            self.borders[i] = self:CreateLine(nil, "BACKGROUND", nil, 0)
            local l = self.borders[i]
            l:SetThickness(2)
            l:SetColorTexture(0, 0, 0, 0.7)
            if i==1 then
                l:SetStartPoint("TOPLEFT", 0, 1)
                l:SetEndPoint("TOPRIGHT", 0, 1)
            elseif i==2 then
                l:SetStartPoint("TOPRIGHT", 0, 1)
                l:SetEndPoint("BOTTOMRIGHT", 0, 2)
            elseif i==3 then
                l:SetStartPoint("BOTTOMRIGHT", 0, 2)
                l:SetEndPoint("BOTTOMLEFT", 0, 2)
            else
                l:SetStartPoint("BOTTOMLEFT", 0, 2)
                l:SetEndPoint("TOPLEFT", 0, 1)
            end
        end
    end
end

function MCL_functions:getTableLength(set)
    local i = 1
    for k,v in pairs(set) do
        i = i+1
    end
    return i
end

function MCL_functions:SetMouseClickFunctionalityPin(frame, mountID, mountName, itemLink, spellID, isSteadyFlight)
    frame:SetScript("OnMouseDown", function(self, button)
        if IsControlKeyDown() then
            if button == 'LeftButton' then
                DressUpMount(mountID)
            elseif button == 'RightButton' then
                if IsMountCollected(mountID) == false then
                    -- Initialize MCL_PINNED if it doesn't exist
                    if not MCL_PINNED then
                        MCL_PINNED = {}
                    end
                    
                    local pin = false
                    local pin_count = table.getn(MCL_PINNED)
                    if pin_count ~= nil then                     
                        for i=1, pin_count do                      
                            if MCL_PINNED[i].mountID == "m"..mountID then
                                pin = i
                            end
                        end
                    end
                                          
                    table.remove(MCL_PINNED, pin)
                    local index = 0
                    -- Initialize MCLcore.mountFrames[1] if it doesn't exist
                    if not MCLcore.mountFrames[1] then
                        MCLcore.mountFrames[1] = {}
                    end
                    for k,v in pairs(MCLcore.mountFrames[1]) do
                        index = index + 1
                        if tostring(v.mountID) == tostring(mountID) then
                            table.remove(MCLcore.mountFrames[1],  index)
                            for kk,vv in ipairs(MCLcore.mountFrames[1]) do
                                if kk == 1 then
                                    vv:SetParent(_G["PinnedFrame"])
                                else
                                    vv:SetParent(MCLcore.mountFrames[1][kk-1])
                                end
                            end
                            frame:Hide()
                            MCLcore.Function:UpdateCollection()
                        end
                    end
                end
            end               
        elseif button=='LeftButton' then
            if IsShiftKeyDown() then
                -- Handle shift-click to link mount in chat
                if itemLink and ChatEdit_GetActiveWindow() then
                    ChatEdit_InsertLink(itemLink)
                elseif spellID then
                    local spellLink = C_Spell.GetSpellLink(spellID)
                    if spellLink and ChatEdit_GetActiveWindow() then
                        ChatEdit_InsertLink(spellLink)
                    end
                end
            end
        end
        if button == 'RightButton' then
            CastSpellByName(mountName);
        end
    end)
end

function MCL_functions:SetMouseClickFunctionality(frame, mountID, mountName, itemLink, spellID, isSteadyFlight) -- * Mount Frames

    frame:SetScript("OnMouseDown", function(self, button)
        if IsControlKeyDown() then
            if button == 'LeftButton' then
                DressUpMount(mountID)
            elseif button == 'RightButton' then
                if IsMountCollected(mountID) == false then
                    -- Initialize MCL_PINNED if it doesn't exist
                    if not MCL_PINNED then
                        MCL_PINNED = {}
                    end
                    
                    local pin = false
                    local pin_count = table.getn(MCL_PINNED)
                    if pin_count ~= nil then                     
                        for i=1, pin_count do                      
                            if MCL_PINNED[i].mountID == "m"..mountID then
                                pin = i
                            end
                        end
                    end
                    if pin ~= false then
                        if frame.pin then
                            frame.pin:SetAlpha(0)
                        end
                        table.remove(MCL_PINNED, pin)
                        -- Update all pin icons for this mount
                        MCLcore.Function:UpdateAllPinIcons(mountID)
                        local index = 0
                        -- Initialize MCLcore.mountFrames[1] if it doesn't exist
                        if not MCLcore.mountFrames[1] then
                            MCLcore.mountFrames[1] = {}
                        end
                        for k,v in pairs(MCLcore.mountFrames[1]) do
                            index = index + 1
                            if tostring(v.mountID) == tostring(mountID) then
                                MCLcore.mountFrames[1][index]:Hide()                                
                                table.remove(MCLcore.mountFrames[1],  index)
                                for kk,vv in ipairs(MCLcore.mountFrames[1]) do
                                    if kk == 1 then
                                        vv:SetParent(_G["PinnedFrame"])
                                        vv:Show()
                                    else
                                        vv:SetParent(MCLcore.mountFrames[1][kk-1])
                                        vv:Show()
                                    end
                                end                                
                            end
                        end
                    else	                            
                        if frame.pin then
                            frame.pin:SetAlpha(1)
                        end
                        local t = {
                            mountID = "m"..mountID,
                            category = frame.category,
                            section = frame.section
                        }
                        if pin_count == nil then
                            MCL_PINNED[1] = t
                        else
                            MCL_PINNED[pin_count+1] = t
                        end
                        MCLcore.Function:CreatePinnedMount(mountID, frame.category, frame.section)
                        -- Update all pin icons for this mount
                        MCLcore.Function:UpdateAllPinIcons(mountID)

                    end
                end
            end               
        elseif button=='LeftButton' then
            if IsShiftKeyDown() then
                -- Handle shift-click to link mount in chat
                if itemLink and ChatEdit_GetActiveWindow() then
                    ChatEdit_InsertLink(itemLink)
                elseif spellID then
                    local spellLink = C_Spell.GetSpellLink(spellID)
                    if spellLink and ChatEdit_GetActiveWindow() then
                        ChatEdit_InsertLink(spellLink)
                    end
                end
            elseif isSteadyFlight then
                if frame.pop and frame.pop:IsShown() then 
                    frame.pop:Hide()
                elseif frame.pop then
                    frame.pop:Show()
                end
            else
                -- Don't add conflicting OnClick handlers here since OnMouseDown is already handling mouse events
                -- Shift-click functionality is handled in SetMouseClickFunctionality
            end
        end
        if button == 'RightButton' then
            CastSpellByName(mountName);
        end
    end)
end

function MCL_functions:LinkMountItem(id, frame, pin, dragonriding)
	--Adding a tooltip for mounts
    if string.sub(id, 1, 1) == "m" then
        id = string.sub(id, 2, -1)
        local mountName, spellID, icon, _, _, _, _, isFactionSpecific, faction, _, isCollected, mountID, isSteadyFlight = C_MountJournal.GetMountInfoByID(id)

        frame:HookScript("OnEnter", function()
            GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
            if (spellID) then
                _, description, source, _, mountTypeID, _, _, _, _ = C_MountJournal.GetMountInfoExtraByID(id) 

                GameTooltip:SetSpellByID(spellID)
                GameTooltip:AddLine(source) 
                GameTooltip:Show()
                frame:SetHyperlinksEnabled(true)
            end
        end)
        frame:HookScript("OnLeave", function()
            GameTooltip:Hide()
        end)
        if pin == true then
            MCLcore.Function:SetMouseClickFunctionalityPin(frame, mountID, mountName, itemLink, spellID, isSteadyFlight)
        else
            MCLcore.Function:SetMouseClickFunctionality(frame, mountID, mountName, itemLink, spellID, isSteadyFlight)
        end  
    else
        local item, itemLink = GetItemInfo(id);
        if dragonriding then
            frame:HookScript("OnEnter", function()
                GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
                if (id) then
                    GameTooltip:SetItemByID(id)
                    GameTooltip:AddLine(frame.source)
                    GameTooltip:Show()
                    frame:SetHyperlinksEnabled(true)
                end
            end)
            frame:HookScript("OnLeave", function()
                GameTooltip:Hide()
            end)

        else
            local mountID = C_MountJournal.GetMountFromItem(id)
            local mountName, spellID, icon, _, _, _, _, isFactionSpecific, faction, _, isCollected, mountID, isSteadyFlight = C_MountJournal.GetMountInfoByID(mountID)
        
            frame:HookScript("OnEnter", function()
                GameTooltip:SetOwner(frame, "ANCHOR_TOP")
                if (itemLink) then
                    frame:SetHyperlinksEnabled(true)
                    _, description, source, _, mountTypeID, _, _, _, _ = C_MountJournal.GetMountInfoExtraByID(mountID)                     
                    GameTooltip:SetHyperlink(itemLink)
                    GameTooltip:AddLine(source)
                    GameTooltip:Show()
                end
            end)
            frame:HookScript("OnLeave", function()
                GameTooltip:Hide()
            end)
            if pin == true then
                MCLcore.Function:SetMouseClickFunctionalityPin(frame, mountID, mountName, itemLink, _, isSteadyFlight)
            else
                MCLcore.Function:SetMouseClickFunctionality(frame, mountID, mountName, itemLink, _, isSteadyFlight)
            end
        end
    end
     
end


function MCL_functions:CompareMountJournal()
    local mounts = {}
    local i = 1
    for k,v in pairs(C_MountJournal.GetMountIDs()) do
        mounts[i] = v
        for kk,vv in pairs(MCLcore.mounts) do
            if vv.id == mounts[i] then
                mounts[i] = nil
            end
        end
    end
    for x,y in ipairs(mounts) do
        if y ~= nil then
            local mountName, spellID, icon, _, _, _, _, isFactionSpecific, faction, _, isCollected, mountID, _ = C_MountJournal.GetMountInfoByID(y)
        end
    end
end


function MCL_functions:CheckIfPinned(mountID)
    if MCL_PINNED == nil then
        MCL_PINNED = {}
    end
    for k,v in pairs(MCL_PINNED) do
        if v.mountID == mountID then
            return true, k
        end
    end
    return false, nil
end


function MCL_functions:CreateMountsForCategory(set, relativeFrame, frame_size, tab, skip_total, pin)

    local category = relativeFrame
    local previous_frame = relativeFrame
    local count = 0
    local first_frame
    local overflow = 0
    local mountFrames = {}
    local val
    local mountName, spellID, icon, _, _, sourceType, _, isFactionSpecific, faction, _, isCollected, mountID, sourceText, isSteadyFlight

    for kk,vv in pairs(set) do
        local mount_Id
        if pin then
            val = vv.mountID
        else
            val = vv
        end
        if string.sub(val, 1, 1) == "m" then
            mount_Id = string.sub(val, 2, -1)
            mountName, spellID, icon, _, _, sourceType, _, isFactionSpecific, faction, _, isCollected, mountID, isSteadyFlight = C_MountJournal.GetMountInfoByID(mount_Id)
            _,_, sourceText =  C_MountJournal.GetMountInfoExtraByID(mount_Id)
        else
            mount_Id = C_MountJournal.GetMountFromItem(val)
            mountName, spellID, icon, _, _, sourceType, _, isFactionSpecific, faction, _, isCollected, mountID, isSteadyFlight = C_MountJournal.GetMountInfoByID(mount_Id)
        end        
        local faction, faction_specific = IsMountFactionSpecific(val)
        if faction then
            if faction == 0 then
                faction = "Horde"
            elseif faction == 1 then
                faction = "Alliance"
            end
        end
        -- NEW: Hide collected mounts if setting is enabled
        if MCL_SETTINGS.hideCollectedMounts and IsMountCollected(mount_Id) then
            -- skip rendering this mount
        else
            if (faction_specific == false) or (faction_specific == true and faction == UnitFactionGroup("player")) then
                local mountsPerRow = MCL_SETTINGS.mountsPerRow or 12  -- Use setting or default to 12
                if count == mountsPerRow then
                    overflow = overflow + frame_size + 10
                end            
                local frame = CreateFrame("Button", nil, relativeFrame, "BackdropTemplate");
                frame:SetWidth(frame_size);
                frame:SetHeight(frame_size);
                frame:SetBackdrop({
                    edgeFile = [[Interface\Buttons\WHITE8x8]],
                    edgeSize = frame_size + 2,
                    bgFile = [[Interface\Buttons\WHITE8x8]],              
                })

                frame.pin = frame:CreateTexture(nil, "OVERLAY")
                frame.pin:SetWidth(16)
                frame.pin:SetHeight(16)
                frame.pin:SetTexture("Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\pin.blp")
                frame.pin:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -2, -2)
                frame.pin:SetAlpha(0)

                -- Handle category and section assignment based on context
                if pin and vv.category and vv.section then
                    -- For pinned mounts, use the data from the pinned mount entry
                    frame.category = vv.category
                    frame.section = vv.section
                elseif category and category.category and category.section then
                    -- For regular mounts, use the category data
                    frame.category = category.category
                    frame.section = category.section
                else
                    -- Fallback to prevent errors
                    frame.category = "Unknown"
                    frame.section = "Unknown"
                end

                frame.dragonRidable = isSteadyFlight


                frame:SetBackdropBorderColor(1, 0, 0, 0.03)
                frame:SetBackdropColor(0, 0, 0, MCL_SETTINGS.opacity)


                frame.tex = frame:CreateTexture()
                frame.tex:SetSize(frame_size, frame_size)
                frame.tex:SetPoint("LEFT")

                if string.sub(val, 1, 1) == "m" then
                    frame.tex:SetTexture(icon)
                else
                    frame.tex:SetTexture(GetItemIcon(val))
                end
        
                frame.tex:SetVertexColor(0.75, 0.75, 0.75, 0.3);

                frame.mountID = mount_Id
                frame.itemID = val            

                local pin_check = MCLcore.Function:CheckIfPinned("m"..frame.mountID)
                if pin_check == true then
                    frame.pin:SetAlpha(1)
                else
                    frame.pin:SetAlpha(0)
                end              

                if pin then
                    local y = 30
                    if previous_frame == category then
                        y = 0
                    end

                    frame.sectionName = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
                    frame.sectionName:SetPoint("LEFT", 650, 0)
                    frame.sectionName:SetText(vv.section)

                    frame.categoryName = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
                    frame.categoryName:SetPoint("LEFT", 850, 0)
                    frame.categoryName:SetText(vv.category)  
                    
                    frame.mountName = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
                    frame.mountName:SetPoint("LEFT", 50, 0)
                    frame.mountName:SetText(mountName)  
                    
                    frame.sourceText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
                    frame.sourceText:SetPoint("LEFT", 250, 0)
                    frame.sourceText:SetText(sourceText)  
                    
                    frame.border = frame:CreateLine(nil, "BACKGROUND", nil, 0)
                    frame.border:SetThickness(3)
                    frame.border:SetColorTexture(1, 1, 1, 0.3)
                    frame.border:SetStartPoint("BOTTOMLEFT")
                    frame.border:SetEndPoint("BOTTOMRIGHT")
                    frame:SetWidth(1000)
                    frame:SetHeight(frame.sourceText:GetStringHeight()+20)
                    
                    frame:SetBackdrop({
                        bgFile = [[Interface\Buttons\WHITE8x8]],              
                    })

                    frame:SetBackdropBorderColor(0, 0, 0, MCL_SETTINGS.opacity)
                    frame:SetBackdropColor(0, 0, 0, MCL_SETTINGS.opacity)
                    frame.tex:SetVertexColor(1, 1, 1, 1)

                    -- Pin icon is already set correctly above, don't hide it

                    frame:SetPoint("BOTTOMLEFT", previous_frame, "BOTTOMLEFT", 0, -frame.sourceText:GetStringHeight()-y);
                    
                    frame.sourceText:SetJustifyH("LEFT")              
                    
                    previous_frame = frame
                elseif count == (MCL_SETTINGS.mountsPerRow or 12) then
                    frame:SetPoint("BOTTOMLEFT", first_frame, "BOTTOMLEFT", 0, -overflow);
                    count = 0           
                elseif relativeFrame == category then
                    frame:SetPoint("BOTTOMLEFT", category, "BOTTOMLEFT", 0, -35);
                    first_frame = frame
                else
                    frame:SetPoint("RIGHT", relativeFrame, "RIGHT", frame_size+10, 0);
                end          

                MCLcore.Function:LinkMountItem(val, frame, pin)

                relativeFrame = frame
                count = count + 1
                if skip_total == true then
                else
                    if tab then
                        MCL_functions:TableMounts(mount_Id, frame, tab, category)
                    end
                end
                table.insert(mountFrames, frame)
            end  
        end   
    end
    
    return overflow, mountFrames
end


function MCL_functions:CreatePinnedMount(mount_Id, category, section)

    local frame_size = 30
    local mountFrames = {}
    
    -- Initialize MCLcore.mountFrames[1] if it doesn't exist
    if not MCLcore.mountFrames[1] then
        MCLcore.mountFrames[1] = {}
    end
    
    local total_pinned = table.getn(MCLcore.mountFrames[1])
    if total_pinned == 0 then
        -- Initialize MCL_PINNED if it doesn't exist
        if not MCL_PINNED then
            MCL_PINNED = {}
        end
        local overflow, mountFrame = MCLcore.Function:CreateMountsForCategory(MCL_PINNED, _G["PinnedFrame"], 30, _G["PinnedTab"], true, true)
        MCLcore.mountFrames[1] = mountFrame
    else
        local relativeFrame = MCLcore.mountFrames[1][total_pinned]

        local mountName, spellID, icon, _, _, sourceType, _, isFactionSpecific, faction, _, isCollected, mountID, _ = C_MountJournal.GetMountInfoByID(mount_Id)
        _,_, sourceText =  C_MountJournal.GetMountInfoExtraByID(mount_Id)

        -- Create frame parented to the Pinned section, not to the previous frame
        local frame = CreateFrame("Button", nil, _G["PinnedFrame"], "BackdropTemplate");
        frame:SetWidth(frame_size);
        frame:SetHeight(frame_size);
        frame:SetBackdrop({
            -- edgeFile = [[Interface\Buttons\WHITE8x8]],
            -- edgeSize = frame_size + 2,
            bgFile = [[Interface\Buttons\WHITE8x8]],
            tileSize = frame_size + 2,    
        })

        frame.pin = frame:CreateTexture(nil, "OVERLAY")
        frame.pin:SetWidth(16)
        frame.pin:SetHeight(16)
        frame.pin:SetTexture("Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\pin.blp")
        frame.pin:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -2, -2)
        frame.pin:SetAlpha(1)

        frame.tex = frame:CreateTexture()
        frame.tex:SetSize(frame_size, frame_size)
        frame.tex:SetPoint("LEFT")
        local mountName, spellID, icon, _, _, _, _, isFactionSpecific, faction, _, isCollected, mountID, _ = C_MountJournal.GetMountInfoByID(mount_Id)
        frame.tex:SetTexture(icon)

        frame.tex:SetVertexColor(0.75, 0.75, 0.75, 0.3);        

        frame.category = category
        frame.section = section

        frame.sectionName = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
        frame.sectionName:SetPoint("LEFT", 650, 0)
        frame.sectionName:SetText(section)

        frame.categoryName = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
        frame.categoryName:SetPoint("LEFT", 850, 0)
        frame.categoryName:SetText(category)
        
        frame.mountName = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
        frame.mountName:SetPoint("LEFT", 50, 0)
        frame.mountName:SetText(mountName)  
        
        frame.sourceText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
        frame.sourceText:SetPoint("LEFT", 250, 0)
        frame.sourceText:SetText(sourceText)          

        frame.border = frame:CreateLine(nil, "BACKGROUND", nil, 0)
        frame.border:SetThickness(1)
        frame.border:SetColorTexture(1, 1, 1, 0.8)
        frame.border:SetStartPoint("BOTTOMLEFT")
        frame.border:SetEndPoint("BOTTOMRIGHT")
        frame:SetWidth(1000)
        frame:SetHeight(frame.sourceText:GetStringHeight()+20)
        frame:SetBackdropBorderColor(0, 0, 0, MCL_SETTINGS.opacity)
        frame:SetBackdropColor(0, 0, 0, MCL_SETTINGS.opacity)
        frame.tex:SetVertexColor(1, 1, 1, 1)

        frame.pin:SetAlpha(0)

        frame:SetPoint("BOTTOMLEFT", relativeFrame, "BOTTOMLEFT", 0, -frame.sourceText:GetStringHeight()-30);

        frame.sourceText:SetJustifyH("LEFT") 

        frame.mountID = mount_Id

        MCLcore.Function:LinkMountItem("m"..tostring(mount_Id), frame, true)

        table.insert(MCLcore.mountFrames[1], frame)
  
    end
end


function MCL_functions:GetMountID(id)
    local mount_Id
    local inputType = type(id)
    local isStringWithM = (inputType == "string" and string.sub(tostring(id), 1, 1) == "m")
    local isNumber = (inputType == "number")
    
    if isStringWithM then
        mount_Id = tonumber(string.sub(tostring(id), 2, -1))
    elseif isNumber and id > 100000 then
        -- Likely an item ID (large number)
        mount_Id = C_MountJournal.GetMountFromItem(id)
    elseif isNumber and id < 10000 then
        -- Likely a mount ID (small number)
        mount_Id = id
    else
        -- Default to item lookup
        mount_Id = C_MountJournal.GetMountFromItem(id)
    end
    
    return mount_Id
end

function IsMountCollected(id)
    local mountName, spellID, icon, _, _, _, _, isFactionSpecific, faction, _, isCollected, mountID = C_MountJournal.GetMountInfoByID(id)
    return isCollected
end

function UpdateBackground(frame)
    local pinned, pin = MCLcore.Function:CheckIfPinned(frame.mountID)
    if pinned == true then
        table.remove(MCL_PINNED, pin)
    end
    frame:SetBackdropBorderColor(0, 0.45, 0, 0.4)
    frame.tex:SetVertexColor(1, 1, 1, 1);	
end


function UpdateProgressBar(frame, total, collected)
    if not frame then
        return
    end    
    
    if total == nil and collected == nil then
        return frame
    else
        if total == 0 then
            -- Handle zero total case properly
            frame:SetValue(0)
            frame.Text:SetText("0/0 (0%)")
            frame:SetStatusBarColor(0.3, 0.3, 0.3)  -- Dark gray for no data
            return frame
        end
        frame.collected = collected
        frame.total = total
        frame:SetValue((collected/total)*100)
        frame.Text:SetText(collected.."/"..total.." ("..math.floor(((collected/total)*100)).."%)")
        frame.val = (collected/total)*100
    end
    
    if frame.val == nil then
        return frame
    end
    
    if not MCL_SETTINGS or not MCL_SETTINGS.progressColors then
        -- Fallback colors
        if frame.val < 33 then
            frame:SetStatusBarColor(1, 0, 0) -- red
        elseif frame.val < 66 then
            frame:SetStatusBarColor(1, 0.65, 0) -- orange
        elseif frame.val < 100 then
            frame:SetStatusBarColor(0, 1, 0) -- green
        else
            frame:SetStatusBarColor(0, 0.5, 1) -- blue
        end
        return frame
    end
    
    if frame.val < 33 then
        frame:SetStatusBarColor(MCL_SETTINGS.progressColors.low.r, MCL_SETTINGS.progressColors.low.g, MCL_SETTINGS.progressColors.low.b) -- red
    elseif frame.val < 66 then
        frame:SetStatusBarColor(MCL_SETTINGS.progressColors.medium.r, MCL_SETTINGS.progressColors.medium.g, MCL_SETTINGS.progressColors.medium.b) -- orange
    elseif frame.val < 100 then
        frame:SetStatusBarColor(MCL_SETTINGS.progressColors.high.r, MCL_SETTINGS.progressColors.high.g, MCL_SETTINGS.progressColors.high.b) -- green
    elseif frame.val == 100 then
        frame:SetStatusBarColor(MCL_SETTINGS.progressColors.complete.r, MCL_SETTINGS.progressColors.complete.g, MCL_SETTINGS.progressColors.complete.b) -- blue
    end
    
    -- Ensure we have a good texture for coloring
    local textureToUse = "Interface\\TargetingFrame\\UI-StatusBar"  -- Default fallback
    
    -- Try to get the texture from settings first
    if MCL_SETTINGS and MCL_SETTINGS.statusBarTexture and MCLcore.media then
        local settingsTexture = MCLcore.media:Fetch("statusbar", MCL_SETTINGS.statusBarTexture)
        if settingsTexture then
            textureToUse = settingsTexture
        end
    end
    
    -- Set the texture
    frame:SetStatusBarTexture(textureToUse)
    local texture = frame:GetStatusBarTexture()
    if texture then
        texture:SetHorizTile(false)
        texture:SetVertTile(false)
    end
    
    return frame
end

function UpdateProgressBarColor(frame)
	frame:SetStatusBarColor(0, 0.5, 0.9)
end

local function clearOverviewStats()
    for k in pairs (MCLcore.overviewStats) do
        MCLcore.overviewStats[k] = nil
    end
end

local function IsMountPinned(id)
    for k,v in pairs(MCLcore.mountFrames[1]) do
        if v.mountID == id then
            return true 
        end
    end
end

local function UpdatePin(frame)
    if not frame.pin then
        return  -- Exit early if pin doesn't exist
    end
    local pinned, pin = MCLcore.Function:CheckIfPinned("m"..tostring(frame.mountID))
    if pinned == true then
        frame.pin:SetAlpha(1)
    else
        frame.pin:SetAlpha(0)
    end
end   


function MCL_functions:UpdateCollection()
    clearOverviewStats()
    if MCLcore.MCL_MF.Bg then
        MCLcore.MCL_MF.Bg:SetVertexColor(0, 0, 0, MCL_SETTINGS.opacity)
    end
    MCLcore.total = 0
    MCLcore.collected = 0

    -- Count mounts from MCLcore.mounts
    for k, v in pairs(MCLcore.mounts) do
        local mountID = v.id
        MCLcore.total = MCLcore.total + 1
        if IsMountCollected(mountID) then
            table.insert(MCLcore.mountCheck, mountID)
            UpdateBackground(v.frame)
            MCLcore.collected = MCLcore.collected + 1
            local pin_count = table.getn(MCL_PINNED) or 0
            for i = 1, pin_count do
                if MCL_PINNED[i].mountID == "m"..v.frame.mountID then
                    table.remove(MCL_PINNED, i)
                    break
                end
            end
            UpdatePin(v.frame)
            local index = 0
            for kk, vv in pairs(MCLcore.mountFrames[1] or {}) do
                index = index + 1
                if tostring(vv.mountID) == tostring(v.frame.mountID) then
                    local f = MCLcore.mountFrames[1][index]
                    table.remove(MCLcore.mountFrames[1], index)
                    for kkk, vvv in ipairs(MCLcore.mountFrames[1]) do
                        if kkk == 1 then
                            vvv:SetParent(_G["PinnedFrame"])
                        else
                            vvv:SetParent(MCLcore.mountFrames[1][kkk-1])
                        end
                    end
                    f:Hide()
                    break
                end
            end
        else
            UpdatePin(v.frame)
        end
    end

    -- Update section stats with validation
    for k, v in pairs(MCLcore.stats) do
        local section_total = 0
        local section_collected = 0
        local section_name
        for kk, vv in pairs(v) do
            local collected = 0
            local total = 0
            if type(vv) == "table" then
                if vv["mounts"] then
                    for kkk, vvv in pairs(vv.mounts) do
                        local faction, faction_specific = IsMountFactionSpecific(vvv)
                        if faction then
                            if faction == 1 then faction = "Alliance" else faction = "Horde" end
                        end
                        if (faction_specific == false) or (faction_specific == true and faction == UnitFactionGroup("player")) then
                            local mountID
                            if string.sub(vvv, 1, 1) == "m" then
                                mountID = tonumber(string.sub(vvv, 2, -1))
                            else
                                mountID = C_MountJournal.GetMountFromItem(vvv)
                            end
                            if mountID then
                                local isCollected = IsMountCollected(mountID)
                                if isCollected == nil then
                                    C_Item.RequestLoadItemDataByID(vvv) -- Force load if item-based
                                end
                                total = total + 1
                                if isCollected then
                                    collected = collected + 1
                                end
                            end
                        end
                    end
                    if vv.pBar then
                        vv.pBar = UpdateProgressBar(vv.pBar, total, collected)
                    end
                    section_total = section_total + total
                    section_collected = section_collected + collected
                else
                    if vv.pBar then
                        vv.pBar = UpdateProgressBar(vv.pBar, section_total, section_collected)
                    end
                end
                if vv["rel"] then
                    for q, e in pairs(MCLcore.overviewFrames) do
                        if e.name == vv.rel.name and e.frame then
                            e.frame = UpdateProgressBar(e.frame, section_total, section_collected)
                            section_name = e.name
                        end
                    end
                end
            end
        end
        if section_name == MCLL["Unobtainable"] then
            MCLcore.total = MCLcore.total + section_collected - section_total
        end
    end

    -- Validate and update overall progress
    if MCLcore.total < 0 then
        MCLcore.total = 0
    end
    
    -- Only update overview progress bar if it exists
    if MCLcore.overview and MCLcore.overview.pBar then
        MCLcore.overview.pBar = UpdateProgressBar(MCLcore.overview.pBar, MCLcore.total, MCLcore.collected)
    end
    
    -- Initialize pinned section if it doesn't exist yet
    if _G["PinnedFrame"] and (not MCLcore.mountFrames[1] or #MCLcore.mountFrames[1] == 0) then
        -- Initialize MCL_PINNED if it doesn't exist
        if not MCL_PINNED then
            MCL_PINNED = {}
        end
        -- Initialize mountFrames[1] if it doesn't exist
        if not MCLcore.mountFrames[1] then
            MCLcore.mountFrames[1] = {}
        end
        -- Create the pinned section content even if empty
        local overflow, mountFrame = MCLcore.Function:CreateMountsForCategory(MCL_PINNED, _G["PinnedFrame"], 30, _G["PinnedTab"], true, true)
        MCLcore.mountFrames[1] = mountFrame
    end
end


function MCL_functions:updateFromSettings(setting, val)
    for k,v in pairs(MCLcore.statusBarFrames) do
        if setting == "texture" then
            v:SetStatusBarTexture(MCLcore.media:Fetch("statusbar", MCL_SETTINGS.statusBarTexture))
        elseif setting == "progressColor" then
            -- Call UpdateProgressBar with proper parameters to refresh colors
            if v.total and v.collected then
                v = UpdateProgressBar(v, v.total, v.collected)
            end
        end
    end
    if setting == "opacity" then
        MCLcore.MCL_MF.Bg:SetVertexColor(0,0,0,MCL_SETTINGS.opacity)
    elseif setting:lower() == "unobtainable" then
        for k,v in pairs(MCLcore.overviewFrames) do
            if v.name:lower() == setting:lower() then
                if val == true then
                    v.frame:GetParent():Hide()
                    v.frame.unobtainable = true
                else 
                    v.frame.unobtainable = false
                    v.frame:GetParent():Show()
                end
            end
        end
    end
end

--------------------------------------------------
-- Minimap Icon
--------------------------------------------------

function MCL_functions:test()
end


local MCL_MM = LibStub("AceAddon-3.0"):NewAddon("MCL_MM", "AceConsole-3.0")
local MCL_LDB = LibStub("LibDataBroker-1.1"):NewDataObject("MCL!", {
type = "data source",
text = "MCL!",
icon = "Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\mcl-logo-32",
--[[OnTooltipShow = function(tooltip)
    tooltip:SetText("MCL")
    tooltip:AddLine(MCLL["Mount Collection Log"], 1, 1, 1)
    tooltip:Show()
end,]]
OnClick = function(_, button) 
	MCLcore.Main:Toggle() 
end,
})
local icon = LibStub("LibDBIcon-1.0")

function MCL_MM:OnInitialize() -- Obviously you'll need a ## SavedVariables: BunniesDB line in your TOC, duh!
	self.db = LibStub("AceDB-3.0"):New("MCL_DB", { profile = { minimap = { hide = false, }, }, }) icon:Register("MCL!", MCL_LDB, self.db.profile.minimap) self:RegisterChatCommand("mcl", "UpdateMinimapButton")
end

function MCL_MM:MCL_MM()
	self.db.profile.minimap.hide = not self.db.profile.minimap.hide
	if self.db.profile.minimap.hide then
		icon:Hide("MCL!")
	else
		icon:Show("MCL!")
	end
end

function MCL_functions:MCL_MM()
	MCL_MM:MCL_MM()
end


function MCL_functions:updateFromDefaults(setting)
    MCLcore.Function:resetToDefault(setting)
    MCLcore.Function:updateFromSettings("opacity")
    MCLcore.Function:updateFromSettings("texture")
    MCLcore.Function:updateFromSettings("progressColor")
    MCLcore.Function:updateFromSettings("unobtainable", false)
end

function MCL_functions:AddonSettings()
    local AceConfig = LibStub("AceConfig-3.0");
    local media = LibStub("LibSharedMedia-3.0")
    MCLcore.media = media
    local options = {
        type = "group",
        name = MCLL["Mount Collection Log Settings"],
        order = 1,
        args = {
            headerone = {             
                order = 1,
                name = MCLL["Main Window Options"],
                type = "header",
                width = "full",
            },            
            mainWindow = {             
                order = 2,
                name = MCLL["Main Window Opacity"],
                desc = MCLL["Changes the opacity of the main window"],
                type = "range",
                width = "normal",
                min = 0,
                max = 1,
                softMin = 0,
                softMax = 1,
                bigStep = 0.05,
                isPercent = false,
                set = function(info, val) MCL_SETTINGS.opacity = val; MCLcore.Function:updateFromSettings("opacity"); end,
                get = function(info) return MCL_SETTINGS.opacity; end,
            },
            spacer1 = {
                order = 2.5,
                cmdHidden = true,
                name = "",
                type = "description",
                width = "half",
            },
            defaultOpacity = {
                order = 3,
                name = MCLL["Reset Opacity"],
                desc = MCLL["Reset to default opacity"],
                width = "normal",
                type = "execute",
                func = function()
                    MCLcore.Function:updateFromDefaults("Opacity")
                end
            },              
            headertwo = {             
                order = 4,
                name = MCLL["Progress Bar Settings"],
                type = "header",
                width = "normal",
            },             
            texture = {              
                order = 5,
                type = "select",
                name = MCLL["Statusbar Texture"],
                width = "normal",
                desc = MCLL["Set the statusbar texture."],
                values = media:HashTable("statusbar"),
                -- Removed dialogControl = "LSM30_Statusbar",
                set = function(info, val) MCL_SETTINGS.statusBarTexture = val; MCLcore.Function:updateFromSettings("texture"); end,
                get = function(info) return MCL_SETTINGS.statusBarTexture; end,
                style = "dropdown", -- This ensures it uses a dropdown menu for selection
            },
            spacer2 = {
                order = 5.5,
                cmdHidden = true,
                name = "",
                type = "description",
                width = "half",
            },            
            defaultTexture = {
                order = 6,
                name = MCLL["Reset Texture"],
                desc = MCLL["Reset to default texture"],
                width = "normal",
                type = "execute",
                func = function()
                    MCLcore.Function:updateFromDefaults("Texture")
                end
            },
            spacer3 = {
                order = 6.5,
                cmdHidden = true,
                name = "",
                type = "description",
                width = "full",
            },
            spacer3large = {
                order = 6.6,
                cmdHidden = true,
                name = "",
                type = "description",
                width = "full",
            },                                  
            progressColorLow = {
                order = 7,
                type = "color",
                name = MCLL["Progress Bar (<33%)"],
                width = "normal",
                desc = MCLL["Set the progress bar colors to be shown when the percentage collected is below 33%"],
                set = function(info, r, g, b) MCL_SETTINGS.progressColors.low.r = r; MCL_SETTINGS.progressColors.low.g = g; MCL_SETTINGS.progressColors.low.b = b; MCLcore.Function:updateFromSettings("progressColor"); end,
                get = function(info) return MCL_SETTINGS.progressColors.low.r, MCL_SETTINGS.progressColors.low.g, MCL_SETTINGS.progressColors.low.b; end,                
            },
            spacer4 = {
                order = 7.5,
                cmdHidden = true,
                name = "",
                type = "description",
                width = "half",
            },            
            progressColorMedium = {
                order = 8,
                type = "color",
                name = MCLL["Progress Bar (<66%)"],
                width = "normal",
                desc = MCLL["Set the progress bar colors to be shown when the percentage collected is below 66%"],
                set = function(info, r, g, b) MCL_SETTINGS.progressColors.medium.r = r; MCL_SETTINGS.progressColors.medium.g = g; MCL_SETTINGS.progressColors.medium.b = b; MCLcore.Function:updateFromSettings("progressColor"); end,
                get = function(info) return MCL_SETTINGS.progressColors.medium.r, MCL_SETTINGS.progressColors.medium.g, MCL_SETTINGS.progressColors.medium.b; end,                
            },
            spacer5 = {
                order = 8.5,
                cmdHidden = true,
                name = "",
                type = "description",
                width = "half",
            },             
            progressColorHigh = {
                order = 9,
                type = "color",
                name = MCLL["Progress Bar (<100%)"],
                width = "normal",
                desc = MCLL["Set the progress bar colors to be shown when the percentage collected is below 100%"],
                set = function(info, r, g, b) MCL_SETTINGS.progressColors.high.r = r; MCL_SETTINGS.progressColors.high.g = g; MCL_SETTINGS.progressColors.high.b = b; MCLcore.Function:updateFromSettings("progressColor"); end,
                get = function(info) return MCL_SETTINGS.progressColors.high.r, MCL_SETTINGS.progressColors.high.g, MCL_SETTINGS.progressColors.high.b; end,                
            },
            spacer6 = {
                order = 9.5,
                cmdHidden = true,
                name = "",
                type = "description",
                width = "half",
            },             
            progressColorComplete = {
                order = 10,
                type = "color",
                name = MCLL["Progress Bar (100%)"],
                width = "normal",
                desc = MCLL["Set the progress bar colors to be shown when all mounts are collected"],
                set = function(info, r, g, b) MCL_SETTINGS.progressColors.complete.r = r; MCL_SETTINGS.progressColors.complete.g = g; MCL_SETTINGS.progressColors.complete.b = b; MCLcore.Function:updateFromSettings("progressColor"); end,
                get = function(info) return MCL_SETTINGS.progressColors.complete.r, MCL_SETTINGS.progressColors.complete.g, MCL_SETTINGS.progressColors.complete.b; end,                
            },
            defaultColor = {
                order = 11,
                name = MCLL["Reset Colors"],
                desc = MCLL["Reset to default colors"],
                width = "normal",
                type = "execute",
                func = function()
                    MCLcore.Function:updateFromDefaults("Colors")
                end
            },              
            headerthree = {             
                order = 12,
                name = MCLL["Layout Settings"],
                type = "header",
                width = "full",
            },
            mountsPerRow = {
                order = 12.5,
                name = MCLL["Mounts Per Row"],
                desc = MCLL["Set the number of mounts to display per row in the mount grid. Requires UI reload."],
                type = "range",
                width = "normal",
                min = 6,
                max = 24,
                softMin = 6,
                softMax = 24,
                step = 1,
                bigStep = 1,
                set = function(info, val)
                    if MCL_SETTINGS.mountsPerRow ~= val then
                        -- Save the setting first
                        MCL_SETTINGS.mountsPerRow = val;
                        
                        -- Then ask if they want to reload
                        StaticPopupDialogs["MCL_MOUNTS_PER_ROW_RELOAD"] = {
                            text = MCLL["Changing this setting requires a UI reload. Reload now?"],
                            button1 = MCLL["YES"],
                            button2 = MCLL["NO"],
                            OnAccept = function()
                                ReloadUI();
                            end,
                            OnCancel = function()
                                -- Setting is already saved, so just do nothing
                            end,
                            timeout = 0,
                            whileDead = true,
                            hideOnEscape = true,
                            preferredIndex = 3,
                        }
                        StaticPopup_Show("MCL_MOUNTS_PER_ROW_RELOAD")
                    end
                end,
                get = function(info) return MCL_SETTINGS.mountsPerRow; end,
            },
            headerfour = {             
                order = 13,
                name = MCLL["Unobtainable Settings"],
                type = "header",
                width = "full",
            },            
            unobtainable = {             
                order = 14,
                name = MCLL["Hide Unobtainable from overview"],
                desc = MCLL["Hide Unobtainable mounts from the overview."],
                type = "toggle",
                width = "full",
                set = function(info, val) MCL_SETTINGS.unobtainable = val; MCLcore.Function:updateFromSettings("unobtainable", val); end,
                get = function(info) return MCL_SETTINGS.unobtainable; end,
            },
            hideCollectedMounts = {
                order = 14.5,
                name = MCLL["Hide Collected Mounts"],
                desc = MCLL["If enabled, collected mounts will not be shown in the list at all. Requires UI reload."],
                type = "toggle",
                width = "full",
                set = function(info, val)
                    if MCL_SETTINGS.hideCollectedMounts ~= val then
                        StaticPopupDialogs["MCL_RELOAD_CONFIRM"] = {
                            text = MCLL["Changing this setting requires a UI reload. Reload now?"],
                            button1 = MCLL["YES"],
                            button2 = MCLL["NO"],
                            OnAccept = function()
                                MCL_SETTINGS.hideCollectedMounts = val;
                                ReloadUI();
                            end,
                            OnCancel = function()
                                -- Do nothing
                            end,
                            timeout = 0,
                            whileDead = true,
                            hideOnEscape = true,
                            preferredIndex = 3,
                        }
                        StaticPopup_Show("MCL_RELOAD_CONFIRM")
                    end
                end,
                get = function(info) return MCL_SETTINGS.hideCollectedMounts; end,
            },
            useBlizzardTheme = {
                order = 14.6,
                name = MCLL["Use Blizzard Theme"],
                desc = MCLL["If enabled, the addon will use Blizzard's default UI theme. Requires UI reload."],
                type = "toggle",
                width = "full",
                set = function(info, val)
                    if MCL_SETTINGS.useBlizzardTheme ~= val then
                        StaticPopupDialogs["MCL_RELOADUI"] = {
                            text = MCLL["Changing this setting requires a UI reload. Reload now?"],
                            button1 = MCLL["YES"],
                            button2 = MCLL["NO"],
                            OnAccept = function() MCL_SETTINGS.useBlizzardTheme = val; ReloadUI(); end,
                            timeout = 0,
                            hideOnEscape = true,
                        }
                        StaticPopup_Show("MCL_RELOADUI")
                    end
                end,
                get = function(info) return MCL_SETTINGS.useBlizzardTheme; end,
            },
            minimapIconToggle = {
                order = 14.7,
                name = MCLL["Show Minimap Icon"],
                desc = MCLL["Toggle the display of the Minimap Icon."],
                type = "toggle",
                width = "full",
                set = function(info, val)
                    MCL_MM.db.profile.minimap.hide = not val
                    if val then
                        icon:Show("MCL!")
                    else
                        icon:Hide("MCL!")
                    end
                end,
                get = function(info)
                    return not MCL_MM.db.profile.minimap.hide
                end,
            },
            headerfive = {             
                order = 15,
                name = MCLL["Reset Settings"],
                type = "header",
                width = "full",
            },             
            defaults = {
                order = 16,
                name = MCLL["Reset Settings"],
                desc = MCLL["Reset to default settings"],
                width = "normal",
                type = "execute",
                func = function()
                    MCLcore.Function:updateFromDefaults()
                end
            }                                                                                                       
        }
    }                                                        


    AceConfig:RegisterOptionsTable(MCLcore.addon_name, options, {});
    MCLcore.AceConfigDialog = LibStub("AceConfigDialog-3.0");
    MCLcore.AceConfigDialog:AddToBlizOptions(MCLcore.addon_name, MCLcore.addon_name, nil);
end

function MCL_functions:CalculateSectionStats()
    MCLcore.stats = {}
    
    for _, section in ipairs(MCLcore.sections or {}) do
        local sectionTotal = 0
        local sectionCollected = 0
        
        if section.mounts and section.mounts.categories then
            for categoryName, categoryData in pairs(section.mounts.categories) do
                -- Combine both mounts and mountID arrays
                local mountList = {}
                if categoryData.mounts then
                    for _, mount in ipairs(categoryData.mounts) do
                        table.insert(mountList, mount)
                    end
                end
                if categoryData.mountID then
                    for _, mount in ipairs(categoryData.mountID) do
                        table.insert(mountList, mount)
                    end
                end
                
                for _, mountId in ipairs(mountList) do
                    sectionTotal = sectionTotal + 1
                    local mount_Id = MCLcore.Function:GetMountID(mountId)
                    if mount_Id and IsMountCollected(mount_Id) then
                        sectionCollected = sectionCollected + 1
                    end
                end
            end
        end
        
        MCLcore.stats[section.name] = {
            total = sectionTotal,
            collected = sectionCollected
        }
    end
end

function MCL_functions:UpdateAllPinIcons(mountID)
    -- Update pin icons for mounts with the given mountID across all frames
    local mountIDString = "m" .. mountID
    local isPinned = MCLcore.Function:CheckIfPinned(mountIDString)
    
    -- Update pin icons in regular mount frames (CreateMountsForCategory)
    for k, v in pairs(MCLcore.mounts or {}) do
        if v.frame and v.frame.mountID and tostring(v.frame.mountID) == tostring(mountID) then
            if v.frame.pin then
                if isPinned then
                    v.frame.pin:SetAlpha(1)
                else
                    v.frame.pin:SetAlpha(0)
                end
            end
        end
    end
    
    -- Update pin icons in section page mount frames
    -- We need to search through all frames in the UI to find matching mount frames
    local function UpdateFrameRecursively(frame)
        if frame and frame.mountID and tostring(frame.mountID) == tostring(mountID) and frame.pin then
            if isPinned then
                frame.pin:SetAlpha(1)
            else
                frame.pin:SetAlpha(0)
            end
        end
        
        -- Check children
        if frame.GetChildren then
            for _, child in ipairs({frame:GetChildren()}) do
                UpdateFrameRecursively(child)
            end
        end
    end
    
    -- Start from the main frame and search all children
    if MCLcore.MCL_MF then
        UpdateFrameRecursively(MCLcore.MCL_MF)
    end
end



local MCL_Load = MCLcore.Main;

MCLcore.Frames = {};
local MCL_frames = MCLcore.Frames;

MCLcore.TabTable = {}
MCLcore.statusBarFrames  = {}

MCLcore.nav_width = 180
local nav_width = MCLcore.nav_width
local main_frame_width = 900
local main_frame_height = 500

local r,g,b,a
-- Helper function to style navigation buttons for both themes
local function StyleNavButton(button, isExpansionIcon)
    if not button then return end
    
    if MCL_SETTINGS.useBlizzardTheme then
        -- Blizzard theme styling with authentic textures
        if isExpansionIcon then
            -- Expansion icons get a Blizzard-style button frame
            button:SetBackdrop({
                bgFile = "Interface\\Buttons\\UI-Panel-Button-Up", 
                edgeFile = "Interface\\Buttons\\UI-Panel-Button-Border", 
                edgeSize = 8,
                insets = {left = 2, right = 2, top = 2, bottom = 2}
            })
            button:SetBackdropColor(0.9, 0.9, 1, 0.4)  -- Light blue-white background
            button:SetBackdropBorderColor(0.7, 0.7, 0.9, 1)  -- Blue border
        else
            -- Regular navigation buttons get Blizzard panel styling
            button:SetBackdrop({
                bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", 
                edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", 
                edgeSize = 16,
                insets = {left = 4, right = 4, top = 4, bottom = 4}
            })
            button:SetBackdropColor(0.05, 0.05, 0.2, 0.9)  -- Dark blue background
            button:SetBackdropBorderColor(0.6, 0.6, 0.8, 1)  -- Blue-gray border
        end
        
        -- Blizzard-style text color
        if button.text then
            button.text:SetTextColor(1, 0.82, 0, 1)  -- Gold text
        end
    else
        -- Default theme styling (current)
        button:SetBackdrop({bgFile = "Interface\\Buttons\\WHITE8x8", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 8})
        button:SetBackdropColor(0.1, 0.1, 0.1, 0.95)
        button:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
        
        if button.text then
            button.text:SetTextColor(1, 1, 1, 1)  -- White text
        end
    end
end


local function ScrollFrame_OnMouseWheel(self, delta)
	local newValue = self:GetVerticalScroll() - (delta * 50);
	
	if (newValue < 0) then
		newValue = 0;
	elseif (newValue > self:GetVerticalScrollRange()) then
		newValue = self:GetVerticalScrollRange();
	end
	
	self:SetVerticalScroll(newValue);
end


function MCL_frames:openSettings()
	Settings.OpenToCategory(MCLcore.addon_name)
	local panel = SettingsPanel or InterfaceOptionsFrame or _G["SettingsPanel"]
	if not panel then return end

	-- Remove old checkboxes if they exist
	if MCLcore.hideCollectedIconCheckbox then
		MCLcore.hideCollectedIconCheckbox:Hide()
		MCLcore.hideCollectedIconCheckbox = nil
	end
	if MCLcore.useBlizzardThemeCheckbox then
		MCLcore.useBlizzardThemeCheckbox:Hide()
		MCLcore.useBlizzardThemeCheckbox = nil
	end

	-- Find the last checkbox in the Unobtainable Settings section to anchor below
	local lastCheckbox = nil
	if MCLcore.hideUnobtainableCheckbox then
		lastCheckbox = MCLcore.hideUnobtainableCheckbox
	elseif MCLcore.hideCollectedMountsCheckbox then
		lastCheckbox = MCLcore.hideCollectedMountsCheckbox
	elseif MCLcore.showMinimapIconCheckbox then
		lastCheckbox = MCLcore.showMinimapIconCheckbox
	end
end

function MCL_frames:CreateMainFrame()
    local frameTemplate = MCL_SETTINGS.useBlizzardTheme and "MCLBlizzardFrameTemplate" or "MCLFrameTemplateWithInset"
    MCL_mainFrame = CreateFrame("Frame", "MCLFrame", UIParent, frameTemplate);
    if MCL_SETTINGS.useBlizzardTheme then
        if MCL_mainFrame.NineSlice then MCL_mainFrame.NineSlice:Hide() end
        if MCL_mainFrame.MCLFrameTopLeft then MCL_mainFrame.MCLFrameTopLeft:Hide() end
        if MCL_mainFrame.MCLFrameTopRight then MCL_mainFrame.MCLFrameTopRight:Hide() end
        if MCL_mainFrame.MCLFrameBottomLeft then MCL_mainFrame.MCLFrameBottomLeft:Hide() end
        if MCL_mainFrame.MCLFrameBottomRight then MCL_mainFrame.MCLFrameBottomRight:Hide() end
        if MCL_mainFrame.MCLFrameTop then MCL_mainFrame.MCLFrameTop:Hide() end
        if MCL_mainFrame.MCLFrameBottom then MCL_mainFrame.MCLFrameBottom:Hide() end
        if MCL_mainFrame.MCLFrameLeft then MCL_mainFrame.MCLFrameLeft:Hide() end
        if MCL_mainFrame.MCLFrameRight then MCL_mainFrame.MCLFrameRight:Hide() end
    end
    if not MCL_SETTINGS.useBlizzardTheme then
        if MCL_mainFrame.Bg then
            MCL_mainFrame.Bg:SetVertexColor(0,0,0,MCL_SETTINGS.opacity)
        end
        if MCL_mainFrame.TitleBg then
            MCL_mainFrame.TitleBg:SetVertexColor(0.1,0.1,0.1,0.95)
        end
    end
    MCL_mainFrame:Show()
    
    -- Create the main frame title
    MCL_mainFrame.title = MCL_mainFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
    
    -- Settings button
    MCL_mainFrame.settings = CreateFrame("Button", nil, MCL_mainFrame);
    MCL_mainFrame.settings:SetSize(14, 14)
    if MCL_SETTINGS.useBlizzardTheme then
        MCL_mainFrame.settings:SetPoint("TOPRIGHT", MCL_mainFrame, "TOPRIGHT", -40, -8)
    else
        MCL_mainFrame.settings:SetPoint("TOPRIGHT", MCL_mainFrame, "TOPRIGHT", -30, 0)
    end
    MCL_mainFrame.settings.tex = MCL_mainFrame.settings:CreateTexture()
    MCL_mainFrame.settings.tex:SetAllPoints(MCL_mainFrame.settings)
    MCL_mainFrame.settings.tex:SetTexture("Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\settings.blp")
    MCL_mainFrame.settings:SetScript("OnClick", function()MCL_frames:openSettings()end)

    --[[ SA button
    MCL_mainFrame.sa = CreateFrame("Button", nil, MCL_mainFrame);
    MCL_mainFrame.sa:SetSize(60, 15)
    if MCL_SETTINGS.useBlizzardTheme then
        MCL_mainFrame.sa:SetPoint("TOPRIGHT", MCL_mainFrame, "TOPRIGHT", -60, -8)
    else
        MCL_mainFrame.sa:SetPoint("TOPRIGHT", MCL_mainFrame, "TOPRIGHT", -60, -1)
    end
    MCL_mainFrame.sa.tex = MCL_mainFrame.sa:CreateTexture()
    MCL_mainFrame.sa.tex:SetAllPoints(MCL_mainFrame.sa)
    MCL_mainFrame.sa.tex:SetTexture("Interface\\Buttons\\WHITE8x8")
    MCL_mainFrame.sa.tex:SetVertexColor(0.1,0.1,0.1,0.95, MCL_SETTINGS.opacity)
    MCL_mainFrame.sa.text = MCL_mainFrame.sa:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
    MCL_mainFrame.sa.text:SetPoint("CENTER", MCL_mainFrame.sa, "CENTER", 0, 0);
    MCL_mainFrame.sa.text:SetText("SA")
    MCL_mainFrame.sa.text:SetTextColor(0, 0.7, 0.85)	
    MCL_mainFrame.sa:SetScript("OnClick", function()MCLcore.Function:simplearmoryLink()end)	
	
    -- DFA button
    MCL_mainFrame.dfa = CreateFrame("Button", nil, MCL_mainFrame);
    MCL_mainFrame.dfa:SetSize(60, 15)
    if MCL_SETTINGS.useBlizzardTheme then
        MCL_mainFrame.dfa:SetPoint("TOPRIGHT", MCL_mainFrame, "TOPRIGHT", -125, -8)
    else
        MCL_mainFrame.dfa:SetPoint("TOPRIGHT", MCL_mainFrame, "TOPRIGHT", -125, -1)
    end
    MCL_mainFrame.dfa.tex = MCL_mainFrame.dfa:CreateTexture()
    MCL_mainFrame.dfa.tex:SetAllPoints(MCL_mainFrame.dfa)
    MCL_mainFrame.dfa.tex:SetTexture("Interface\\Buttons\\WHITE8x8")
    MCL_mainFrame.dfa.tex:SetVertexColor(0.1,0.1,0.1,0.95, MCL_SETTINGS.opacity)
    MCL_mainFrame.dfa.text = MCL_mainFrame.dfa:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
    MCL_mainFrame.dfa.text:SetPoint("CENTER", MCL_mainFrame.dfa, "CENTER", 0, 0);
    MCL_mainFrame.dfa.text:SetText("DFA")
    MCL_mainFrame.dfa.text:SetTextColor(0, 0.7, 0.85)	
    MCL_mainFrame.dfa:SetScript("OnClick", function()MCLcore.Function:dfaLink()end)]]		


	--MCL Frame settings
	MCL_mainFrame:SetSize(main_frame_width, main_frame_height); -- width, height
	MCL_mainFrame:SetPoint("CENTER", UIParent, "CENTER"); -- point, relativeFrame, relativePoint, xOffset, yOffset
	MCL_mainFrame:SetHyperlinksEnabled(true)
	MCL_mainFrame:SetScript("OnHyperlinkClick", ChatFrame_OnHyperlinkShow)
	
	-- Restore saved frame size if available
	MCL_frames:RestoreFrameSize()

	MCL_mainFrame:SetMovable(true)
	MCL_mainFrame:EnableMouse(true)
	MCL_mainFrame:RegisterForDrag("LeftButton")
	MCL_mainFrame:SetScript("OnDragStart", MCL_mainFrame.StartMoving)
	MCL_mainFrame:SetScript("OnDragStop", MCL_mainFrame.StopMovingOrSizing)
	
	-- Make frame resizable
	MCL_mainFrame:SetResizable(true)
	MCL_mainFrame:SetResizeBounds(900, 600, 1600, 1000)  -- min width, min height, max width, max height
	
	-- Create resize grip
	MCL_mainFrame.resizeGrip = CreateFrame("Button", nil, MCL_mainFrame)
	MCL_mainFrame.resizeGrip:SetSize(16, 16)
	MCL_mainFrame.resizeGrip:SetPoint("BOTTOMRIGHT", MCL_mainFrame, "BOTTOMRIGHT", -2, 2)
	MCL_mainFrame.resizeGrip:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
	MCL_mainFrame.resizeGrip:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
	MCL_mainFrame.resizeGrip:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
	MCL_mainFrame.resizeGrip:SetScript("OnMouseDown", function(self)
		MCL_mainFrame:StartSizing("BOTTOMRIGHT")
	end)
	MCL_mainFrame.resizeGrip:SetScript("OnMouseUp", function(self)
		MCL_mainFrame:StopMovingOrSizing()
		-- Save the new size and trigger layout update after resize
		MCL_frames:SaveFrameSize()
		MCL_frames:RefreshLayout()
	end)    

	-- Move title to top center
    if MCL_mainFrame.title then
        MCL_mainFrame.title:ClearAllPoints()
		-- if blizzard theme
		if MCL_SETTINGS.useBlizzardTheme then
			MCL_mainFrame.title:SetPoint("TOPLEFT", MCL_mainFrame, "TOPLEFT", 10, -8)  -- Moved down 10px from the very top
		else
			MCL_mainFrame.title:SetPoint("TOPLEFT", MCL_mainFrame, "TOPLEFT", 10, -2)  -- Moved down 5px from the very top
		end
        MCL_mainFrame.title:SetText(MCLL["Mount Collection Log"])

        MCL_mainFrame.title:SetTextColor(0.3, 0.7, 0.9, 1)  -- White text for better visibility
    end
    
    -- Scroll Frame for Main Window
	MCL_mainFrame.ScrollFrame = CreateFrame("ScrollFrame", nil, MCL_mainFrame, "MinimalScrollFrameTemplate");
	-- Anchor scroll frame to the main frame, not Bg
    MCL_mainFrame.ScrollFrame:ClearAllPoints()
    MCL_mainFrame.ScrollFrame:SetPoint("TOPLEFT", MCL_mainFrame, "TOPLEFT", 10, -40)
    MCL_mainFrame.ScrollFrame:SetPoint("BOTTOMRIGHT", MCL_mainFrame, "BOTTOMRIGHT", -10, 10)
	MCL_mainFrame.ScrollFrame:SetClipsChildren(true);
	MCL_mainFrame.ScrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel);
	MCL_mainFrame.ScrollFrame:EnableMouse(true)
    
	MCL_mainFrame.ScrollFrame.ScrollBar:ClearAllPoints();
	MCL_mainFrame.ScrollFrame.ScrollBar:SetPoint("TOPLEFT", MCL_mainFrame.ScrollFrame, "TOPRIGHT", -8, -19);
	MCL_mainFrame.ScrollFrame.ScrollBar:SetPoint("BOTTOMRIGHT", MCL_mainFrame.ScrollFrame, "BOTTOMRIGHT", -8, 17);

    -- Create and assign a dedicated scroll child frame
    if not MCL_mainFrame.ScrollChild then
        MCL_mainFrame.ScrollChild = CreateFrame("Frame", nil, MCL_mainFrame.ScrollFrame)
        MCL_mainFrame.ScrollChild:SetSize(main_frame_width, main_frame_height)
        MCL_mainFrame.ScrollFrame:SetScrollChild(MCL_mainFrame.ScrollChild)
    end

	MCL_mainFrame:SetFrameStrata("HIGH")
    if not MCL_SETTINGS.useBlizzardTheme then
        MCLcore.Function:CreateFullBorder(MCL_mainFrame)
    end

    tinsert(UISpecialFrames, "MCLFrame")
    
    -- Add OnShow handler to show navigation when main frame is shown
    MCL_mainFrame:SetScript("OnShow", function()
        if MCLcore.MCL_MF_Nav then
            MCLcore.MCL_MF_Nav:Show()
        end
    end)
    
    -- Add OnHide handler to hide navigation when main frame is closed
    MCL_mainFrame:SetScript("OnHide", function()
        if MCLcore.MCL_MF_Nav then
            MCLcore.MCL_MF_Nav:Hide()
        end
    end)
    
    return MCL_mainFrame
end


local function Tab_OnClick(self)
	PanelTemplates_SetTab(self:GetParent(), self:GetID());

	local scrollChild = MCL_mainFrame.ScrollFrame:GetScrollChild();
	if(scrollChild) then
		scrollChild:Hide();
	end

	MCL_mainFrame.ScrollFrame:SetScrollChild(self.content);
	self.content:Show();
	MCL_mainFrame.ScrollFrame:SetVerticalScroll(0);
end


-- Build a nav-ordered list of sections for consistent tab/content mapping
function MCLcore:BuildSectionsOrdered()
    local pinned, overview, expansions, others = nil, nil, {}, {}
    local playerFaction = UnitFactionGroup("player")
    for i = 1, #MCLcore.sectionNames do
        local v = MCLcore.sectionNames[i]
        if v.name == "Pinned" then
            pinned = v
        elseif v.name == "Horde" and playerFaction == "Alliance" then
            -- skip Horde for Alliance players
        elseif v.name == "Alliance" and playerFaction == "Horde" then
            -- skip Alliance for Horde players
        elseif v.name == "Overview" then
            overview = v
        elseif v.isExpansion then
            table.insert(expansions, v)
        else
            table.insert(others, v)
        end
    end
    local ordered = {}
    if overview then table.insert(ordered, overview) end
    for _, v in ipairs(expansions) do table.insert(ordered, v) end
    for _, v in ipairs(others) do table.insert(ordered, v) end
    if pinned then table.insert(ordered, pinned) end
    MCLcore.sectionsOrdered = ordered
end

function MCL_frames:SetTabs()
    -- Always update stats before building tabs/UI
    if MCLcore.Function and MCLcore.Function.UpdateCollection then
        MCLcore.Function:UpdateCollection()
    end
    if MCLcore.BuildSectionsOrdered then
        MCLcore:BuildSectionsOrdered()
    end
    if MCLcore.Function and MCLcore.Function.CalculateSectionStats then
        MCLcore.Function:CalculateSectionStats()
    end
    
    -- Refresh overview stats after calculation
    if MCLcore.overviewFrames then
        for _, overviewFrame in ipairs(MCLcore.overviewFrames) do
            local sectionName = overviewFrame.name
            local pBar = overviewFrame.frame
            local sectionStats = MCLcore.stats and MCLcore.stats[sectionName]
            
            if sectionStats and sectionStats.collected and sectionStats.total then
                UpdateProgressBar(pBar, sectionStats.total, sectionStats.collected)
            end
        end
    end

    local tabFrame
    if MCL_SETTINGS.useBlizzardTheme then
        -- Blizzard theme should ALSO use the separate navigation frame
        tabFrame = MCLcore.MCL_MF_Nav
    else
        tabFrame = MCLcore.MCL_MF_Nav
    end

    -- Store reference for overview navigation
    if not tabFrame.tabs then
        tabFrame.tabs = {}
    end

    local sections = MCLcore.sectionsOrdered or MCLcore.sections
    -- Find Overview, Pinned, expansions, and others
    local overviewSection, pinnedSection, expansionSections, otherSections = nil, nil, {}, {}
    for _, v in ipairs(sections) do
        if v.name == "Overview" then
            overviewSection = v
        elseif v.name == "Pinned" then
            pinnedSection = v
        elseif v.isExpansion then
            table.insert(expansionSections, v)
        else
            table.insert(otherSections, v)
        end
    end

    if tabFrame.tabs then
        for _, tab in ipairs(tabFrame.tabs) do
            tab:Hide()
            if tab.content then tab.content:Hide() end
        end
    end
    tabFrame.tabs = {}
    MCLcore.sectionFrames = {}

    local navYOffset = -55  -- Adjusted to account for search bar
    local tabIndex = 1
    local selectedTab = nil

    local function HideAllTabContents()
        for _, t in ipairs(tabFrame.tabs) do
            if t.content then t.content:Hide() end
        end
    end
    local function DeselectAllTabs()
        for _, t in ipairs(tabFrame.tabs) do
            t:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
        end
    end
    local function SelectTab(tab)
        DeselectAllTabs()
        HideAllTabContents()
        tab:SetBackdropBorderColor(1, 0.82, 0, 1)
        MCL_mainFrame.ScrollFrame:SetScrollChild(tab.content)
        tab.content:Show()
        MCL_mainFrame.ScrollFrame:SetVerticalScroll(0)
        -- Store the currently selected tab globally for search functionality
        MCLcore.currentlySelectedTab = tab
    end

    -- 1. Overview tab (always first)
    if overviewSection then
        local tab = CreateFrame("Button", nil, tabFrame, "BackdropTemplate")
        tab:SetSize(nav_width + 8, 32)  -- Use nav width for sidebar tabs
        tab:SetPoint("TOPLEFT", tabFrame, "TOPLEFT", 1, navYOffset)
        StyleNavButton(tab, false)  -- Use our styling function
        tab.text = tab:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
        tab.text:SetPoint("LEFT", 10, 0)
        tab.text:SetText(MCLL[overviewSection.name] or overviewSection.name)
        tab.section = overviewSection
        tab.content = MCLcore.overview
        if tab.content then tab.content:Hide() end
        tab:SetScript("OnClick", function(self)
            SelectTab(self)
        end)
        tab:EnableMouse(true)
        tab:SetFrameStrata("HIGH")
        tab:SetFrameLevel(100)
        tab:Show()
        table.insert(tabFrame.tabs, tab)
        -- Also store in navigation frame for overview navigation
        if MCLcore.MCL_MF_Nav and not MCLcore.MCL_MF_Nav.tabs then
            MCLcore.MCL_MF_Nav.tabs = {}
        end
        if MCLcore.MCL_MF_Nav then
            table.insert(MCLcore.MCL_MF_Nav.tabs, tab)
        end
        table.insert(MCLcore.sectionFrames, tab.content)
        tabIndex = tabIndex + 1
        navYOffset = navYOffset - 36
        selectedTab = tab
        -- Store globally for search functionality
        MCLcore.currentlySelectedTab = tab
    end
    -- 2. Expansion grid (icon-only, 3 per row)
    local gridCols, iconSize, iconPad = 3, 36, 8
    local gridStartY = navYOffset
    
    -- Calculate centering for expansion icons within the nav sidebar
    local totalGridWidth = gridCols * iconSize + (gridCols - 1) * iconPad
    local navFrameWidth = nav_width + 10  -- Use the nav frame width
    local gridStartX = (navFrameWidth - totalGridWidth) / 2  -- Center within nav frame
    
    for i, v in ipairs(expansionSections) do
        local col = ((i-1) % gridCols)
        local row = math.floor((i-1) / gridCols)
        local btn = CreateFrame("Button", nil, tabFrame, "BackdropTemplate")
        btn:SetSize(iconSize, iconSize)
        btn:SetPoint("TOPLEFT", tabFrame, "TOPLEFT", gridStartX + col * (iconSize + iconPad), gridStartY - row * (iconSize + iconPad))
        StyleNavButton(btn, true)  -- Use our styling function for expansion icons
        btn.icon = btn:CreateTexture(nil, "ARTWORK")
        btn.icon:SetAllPoints(btn)
        btn.icon:SetTexture(v.icon)
        btn.section = v
        btn.content = MCLcore.Frames:createContentFrame(MCL_mainFrame.ScrollChild, v.name)
        -- Populate expansion tab content
        if v.mounts then
            if v.mounts.categories then
                MCLcore.Frames:createCategoryFrame(v.mounts.categories, btn.content, v.name)
            else
                -- For some sections, mounts might be directly in v.mounts
                MCLcore.Frames:createCategoryFrame(v.mounts, btn.content, v.name)
            end
        end
        btn.content:Hide()
        btn:SetScript("OnClick", function(self)
            SelectTab(self)
        end)
        btn:EnableMouse(true)
        btn:SetFrameStrata("HIGH")
        btn:SetFrameLevel(100)
        btn:Show()
        table.insert(tabFrame.tabs, btn)
        -- Also store in navigation frame for overview navigation
        if MCLcore.MCL_MF_Nav then
            table.insert(MCLcore.MCL_MF_Nav.tabs, btn)
        end
        table.insert(MCLcore.sectionFrames, btn.content)
        tabIndex = tabIndex + 1
    end
    navYOffset = gridStartY - math.ceil(#expansionSections / gridCols) * (iconSize + iconPad) - 10
    -- 3. Remaining full-width tabs
    for _, v in ipairs(otherSections) do
        local tab = CreateFrame("Button", nil, tabFrame, "BackdropTemplate")
        tab:SetSize(nav_width + 8, 32)  -- Use nav width for sidebar tabs
        tab:SetPoint("TOPLEFT", tabFrame, "TOPLEFT", 1, navYOffset)
        StyleNavButton(tab, false)  -- Use our styling function
        tab.text = tab:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
        tab.text:SetPoint("LEFT", 10, 0)
        tab.text:SetText(MCLL[v.name] or v.name)
        tab.section = v
        tab.content = MCLcore.Frames:createContentFrame(MCL_mainFrame.ScrollChild, v.name)
        -- Populate other tab content if available
        if v.mounts then
            if v.mounts.categories then
                MCLcore.Frames:createCategoryFrame(v.mounts.categories, tab.content, v.name)
            else
                MCLcore.Frames:createCategoryFrame(v.mounts, tab.content, v.name)
            end
        end
        tab.content:Hide()
        tab:SetScript("OnClick", function(self)
            SelectTab(self)
        end)
        tab:EnableMouse(true)
        tab:SetFrameStrata("HIGH")
        tab:SetFrameLevel(100)
        tab:Show()
        table.insert(tabFrame.tabs, tab)
        -- Also store in navigation frame for overview navigation (other sections)
        if MCLcore.MCL_MF_Nav then
            table.insert(MCLcore.MCL_MF_Nav.tabs, tab)
        end
        table.insert(MCLcore.sectionFrames, tab.content)
        tabIndex = tabIndex + 1
        navYOffset = navYOffset - 28
    end
    -- 4. Pinned tab (always last)
    if pinnedSection then
        local tab = CreateFrame("Button", nil, tabFrame, "BackdropTemplate")
        tab:SetSize(nav_width + 8, 32)  -- Use nav width for sidebar tabs
        tab:SetPoint("TOPLEFT", tabFrame, "TOPLEFT", 1, navYOffset)
        StyleNavButton(tab, false)  -- Use our styling function
        tab.text = tab:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
        tab.text:SetPoint("LEFT", 10, 0)
        tab.text:SetText(MCLL[pinnedSection.name] or pinnedSection.name)
        tab.section = pinnedSection
        tab.content = MCLcore.Frames:createContentFrame(MCL_mainFrame.ScrollChild, pinnedSection.name)
        -- Set global reference for pinned content frame (used by functions.lua)
        _G["PinnedFrame"] = tab.content
        _G["PinnedTab"] = tab
        -- Optionally, populate pinned tab content if you have a function for it
        tab.content:Hide()
        tab:SetScript("OnClick", function(self)
            SelectTab(self)
        end)
        tab:EnableMouse(true)
        tab:SetFrameStrata("HIGH")
        tab:SetFrameLevel(100)
        tab:Show()
        table.insert(tabFrame.tabs, tab)
        -- Also store in navigation frame for overview navigation (pinned)
        if MCLcore.MCL_MF_Nav then
            table.insert(MCLcore.MCL_MF_Nav.tabs, tab)
        end
        table.insert(MCLcore.sectionFrames, tab.content)
        tabIndex = tabIndex + 1
        navYOffset = navYOffset - 28
    end
    -- Select Overview by default
    if selectedTab then
        SelectTab(selectedTab)
    elseif tabFrame.tabs[1] then
        SelectTab(tabFrame.tabs[1])
    end
    return MCLcore.sectionFrames, #tabFrame.tabs
end


function MCL_frames:createNavFrame(relativeFrame, title)
    -- Nav frame is parented to the main frame so it opens/closes together
    -- Don't use insetFrameTemplate for default theme as it has its own styling that conflicts
    local frameTemplate = MCL_SETTINGS.useBlizzardTheme and "MCLBlizzardNavTemplate" or "BackdropTemplate"
    local frame = CreateFrame("Frame", "Nav", relativeFrame, frameTemplate);
    frame:SetWidth(nav_width + 10)  -- Keep original nav width as sidebar
    
    -- Set height to match current main frame height
    local _, currentHeight = MCL_frames:GetCurrentFrameDimensions()
    frame:SetHeight(currentHeight+1)
    
    frame:ClearAllPoints()
    
    -- Consistent positioning for both themes - account for any frame insets
    local xOffset = -1
    local yOffset = 2


    if MCL_SETTINGS.useBlizzardTheme then
        -- Blizzard theme has a different inset, adjust accordingly
        xOffset = 3  -- Adjusted for Blizzard theme
        yOffset = -5
        frame:SetHeight(currentHeight-9)
    end

    
    -- Get the actual frame dimensions and adjust for any template differences
    if MCL_SETTINGS.useBlizzardTheme then
        -- UIPanelDialogTemplate frames have different insets, get actual boundaries
        local left, bottom, width, height = relativeFrame:GetRect()
        if left then
            -- Position relative to the actual frame boundaries
            frame:SetPoint("TOPRIGHT", relativeFrame, "TOPLEFT", xOffset, yOffset)
        else
            -- Fallback positioning
            frame:SetPoint("TOPRIGHT", relativeFrame, "TOPLEFT", xOffset, yOffset)
        end
    else
        -- Default theme - standard positioning
        frame:SetPoint("TOPRIGHT", relativeFrame, "TOPLEFT", xOffset, yOffset)
    end
    
    -- Apply styling after frame creation to ensure it sticks
    if MCL_SETTINGS.useBlizzardTheme then
        -- Blizzard-style backdrop with proper textures
        if frame.SetBackdrop then
            frame:SetBackdrop({
                bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background-Dark", 
                edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", 
                edgeSize = 16,
                insets = {left = 4, right = 4, top = 4, bottom = 4}
            })
            frame:SetBackdropColor(0.05, 0.05, 0.15, 0.95)  -- Dark blue tint with higher opacity
            frame:SetBackdropBorderColor(0.4, 0.4, 0.6, 1)  -- Blue-gray border
        end
    else
        -- Default theme - dark background with proper opacity
        if frame.SetBackdrop then
            frame:SetBackdrop({bgFile = "Interface\\Buttons\\WHITE8x8", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 8})
            frame:SetBackdropColor(0.08, 0.08, 0.08, 0.95)  -- Increased opacity to ensure visibility
            frame:SetBackdropBorderColor(0.2, 0.2, 0.2, 1)
        end
    end
    
    frame.title = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
    frame.title:SetPoint("TOP", frame, "TOP", 0, -8)
    frame.title:SetText(title or "")
    
    -- Style the title text for Blizzard theme
    if MCL_SETTINGS.useBlizzardTheme then
        frame.title:SetTextColor(1, 0.82, 0, 1)  -- Gold color like Blizzard UI
    else
        frame.title:SetTextColor(1, 1, 1, 1)  -- White for default theme
    end
    
    -- Create search bar
    frame.searchContainer = CreateFrame("Frame", nil, frame, "BackdropTemplate")
    frame.searchContainer:SetSize(nav_width - 10, 25)
    frame.searchContainer:SetPoint("TOP", frame.title, "BOTTOM", 0, -5)
    frame.searchContainer:SetBackdrop({
        bgFile = "Interface\\Buttons\\WHITE8x8",
        edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
        edgeSize = 2
    })
    frame.searchContainer:SetBackdropColor(0.1, 0.1, 0.1, 0.9)
    frame.searchContainer:SetBackdropBorderColor(0.4, 0.4, 0.4, 1)
    
    -- Create search editbox
    frame.searchBox = CreateFrame("EditBox", nil, frame.searchContainer)
    frame.searchBox:SetSize(nav_width - 20, 20)
    frame.searchBox:SetPoint("CENTER", frame.searchContainer, "CENTER", 0, 0)
    frame.searchBox:SetFontObject("GameFontHighlightSmall")
    frame.searchBox:SetTextColor(1, 1, 1, 1)
    frame.searchBox:SetAutoFocus(false)
    frame.searchBox:SetMaxLetters(50)
    frame.searchBox:EnableMouse(true)
    frame.searchBox:SetScript("OnEnterPressed", function(self)
        self:ClearFocus()
        MCLcore.Search:PerformSearch(self:GetText())
    end)
    frame.searchBox:SetScript("OnEscapePressed", function(self)
        self:ClearFocus()
        self:SetText("")
        MCLcore.Search:ClearSearchAndGoToOverview()
    end)
    frame.searchBox:SetScript("OnTextChanged", function(self, userInput)
        if userInput then
            local text = self:GetText()
            if text == "" then
                MCLcore.Search:ClearSearchAndGoToOverview()
            end
        end
    end)
    
    -- Create search placeholder text
    frame.searchPlaceholder = frame.searchContainer:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
    frame.searchPlaceholder:SetPoint("LEFT", frame.searchBox, "LEFT", 5, 0)
    frame.searchPlaceholder:SetText(MCLL["Search mounts..."])
    frame.searchPlaceholder:SetTextColor(0.6, 0.6, 0.6, 1)
    
    -- Show/hide placeholder based on editbox focus and content
    frame.searchBox:SetScript("OnEditFocusGained", function(self)
        frame.searchPlaceholder:Hide()
    end)
    frame.searchBox:SetScript("OnEditFocusLost", function(self)
        if self:GetText() == "" then
            frame.searchPlaceholder:Show()
        end
    end)
    
    -- Create clear search button
    frame.clearButton = CreateFrame("Button", nil, frame.searchContainer)
    frame.clearButton:SetSize(16, 16)
    frame.clearButton:SetPoint("RIGHT", frame.searchContainer, "RIGHT", -3, 0)
    frame.clearButton:SetNormalTexture("Interface\\FriendsFrame\\ClearBroadcastIcon")
    frame.clearButton:SetScript("OnClick", function()
        frame.searchBox:SetText("")
        frame.searchBox:ClearFocus()
        MCLcore.Search:ClearSearchAndGoToOverview()
        frame.searchPlaceholder:Show()
    end)
    frame.clearButton:SetScript("OnEnter", function(self)
        GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
        GameTooltip:SetText(MCLL["Clear Search"], 1, 1, 1)
        GameTooltip:Show()
    end)
    frame.clearButton:SetScript("OnLeave", function()
        GameTooltip:Hide()
    end)
    
    -- Ensure the frame is visible and at the correct strata
    frame:SetFrameStrata("HIGH")
    frame:Show()
    
    return frame;
end

-- IMPORTANT: Ensure SetTabs is called before any code that uses MCLcore.overview

function MCL_frames:progressBar(relativeFrame, top)
    MyStatusBar = CreateFrame("StatusBar", nil, relativeFrame, "BackdropTemplate")
    MyStatusBar:SetStatusBarTexture(MCLcore.media:Fetch("statusbar", MCL_SETTINGS.statusBarTexture))
    MyStatusBar:GetStatusBarTexture():SetHorizTile(false)
    MyStatusBar:SetMinMaxValues(0, 100)
    MyStatusBar:SetValue(0)
    MyStatusBar:SetWidth(150)
    MyStatusBar:SetHeight(15)
    if top then
        MyStatusBar:SetPoint("BOTTOMLEFT", relativeFrame, "BOTTOMLEFT", 0, 10)
    else
        MyStatusBar:SetPoint("BOTTOMLEFT", relativeFrame, "BOTTOMLEFT", 0, 10)
    end

    MyStatusBar:SetStatusBarColor(0.1, 0.9, 0.1)

    MyStatusBar.bg = MyStatusBar:CreateTexture(nil, "BACKGROUND")
    MyStatusBar.bg:SetTexture("Interface\\TARGETINGFRAME\\UI-Status-Bar")
    MyStatusBar.bg:SetAllPoints(true)
    MyStatusBar.bg:SetVertexColor(0.843, 0.874, 0.898, 0.5)
    MyStatusBar.Text = MyStatusBar:CreateFontString()
    MyStatusBar.Text:SetFontObject(GameFontWhite)
    MyStatusBar.Text:SetPoint("CENTER")
    MyStatusBar.Text:SetJustifyH("CENTER")
    MyStatusBar.Text:SetText()

    table.insert(MCLcore.statusBarFrames, MyStatusBar)

    return MyStatusBar
end

function MCL_frames:createContentFrame(relativeFrame, title)
    -- Calculate dynamic width based on current main frame width
    local currentWidth, _ = MCL_frames:GetCurrentFrameDimensions()
    local availableWidth = currentWidth - 60  -- 60px for padding
    
    local frame = CreateFrame("Frame", nil, relativeFrame, "BackdropTemplate")
    frame:SetWidth(availableWidth)  -- Use current available width
    frame:SetHeight(50)  -- Increased height to accommodate title padding
    frame:SetPoint("TOPLEFT", relativeFrame, "TOPLEFT", 30, 0)  -- Remove nav_width since nav is outside
    frame:SetBackdropColor(0, 0, 0, 0)  -- Transparent background
    frame.title = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
    frame.title:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -15)  -- Added padding: 15px from left and top
    frame.title:SetText(MCLL[title]) -- Localized for display
    frame.name = title -- Store non-localized name

    if title ~= "Pinned" then
        frame.pBar = MCLcore.Frames:progressBar(frame)
        frame.pBar:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, -15)  -- Aligned with title padding
        frame.pBar:SetWidth(availableWidth - 30)  -- Account for padding on both sides
        frame.pBar:SetHeight(20)
    end

    return frame
end


function MCL_frames:createOverviewCategory(set, relativeFrame)
    if not set or not relativeFrame then
        return
    end

    -- Use the same layout calculations as createCategoryFrame for consistency
    local currentWidth, _ = MCL_frames:GetCurrentFrameDimensions()
    local availableWidth = currentWidth - 60  -- Total content width
    local columnSpacing = 25  -- Spacing between columns
    local numColumns = 2
    local columnWidth = math.floor((availableWidth - columnSpacing * (numColumns - 1)) / numColumns)
    
    local leftColumnX = 15  -- Start with padding from left edge
    local rightColumnX = leftColumnX + columnWidth + columnSpacing
    
    local leftColumnY = -30  -- Reduced from -60 for tighter spacing
    local rightColumnY = -30
    local sectionIndex = 0

    -- Create sections similar to how categories are created in other tabs
    for k, v in pairs(set) do
        if (v.name ~= "Overview") and (v.name ~= "Pinned") then
            sectionIndex = sectionIndex + 1
            
            -- Determine which column to use (alternate left/right)
            local isLeftColumn = (sectionIndex % 2 == 1)
            local xPos = isLeftColumn and leftColumnX or rightColumnX
            local yPos = isLeftColumn and leftColumnY or rightColumnY
            
            -- Get actual stats for this section
            local sectionStats = MCLcore.stats and MCLcore.stats[v.name]
            local totalMounts = (sectionStats and sectionStats.total) or 0
            local collectedMounts = (sectionStats and sectionStats.collected) or 0
            
            -- Create section frame without background
            local sectionFrame = CreateFrame("Frame", nil, relativeFrame)
            sectionFrame:SetWidth(columnWidth)  -- Use calculated column width
            sectionFrame:SetHeight(50)  -- Reduced from 65 to 50 for even tighter spacing
            sectionFrame:SetPoint("TOPLEFT", relativeFrame, "TOPLEFT", xPos, yPos)
            
            -- Section title with smaller font
            sectionFrame.title = sectionFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
            sectionFrame.title:SetPoint("TOPLEFT", sectionFrame, "TOPLEFT", 5, -2)  -- Reduced padding
            sectionFrame.title:SetText(MCLL[v.name] or v.name)
            sectionFrame.title:SetTextColor(1, 1, 1, 1)
            
            -- Create progress bar container with dynamic width based on column width
            local progressContainer = CreateFrame("Frame", nil, sectionFrame)
            progressContainer:SetWidth(columnWidth - 10)  -- Use column width with padding
            progressContainer:SetHeight(16)  -- Smaller height
            progressContainer:SetPoint("TOPLEFT", sectionFrame.title, "BOTTOMLEFT", 0, -5)  -- Reduced spacing
            
            -- Create progress bar with background
            local pBar = CreateFrame("StatusBar", nil, progressContainer, "BackdropTemplate")
            
            -- Add dark background to the progress bar
            pBar:SetBackdrop({
                bgFile = "Interface\\Buttons\\WHITE8x8",
                edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
                edgeSize = 1
            })
            pBar:SetBackdropColor(0.1, 0.1, 0.1, 0.8)  -- Dark background
            pBar:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)  -- Subtle border
            
            -- Use settings texture if available, otherwise fallback to TargetingFrame
            local textureToUse = "Interface\\TargetingFrame\\UI-StatusBar"  -- Good default that colors well
            if MCL_SETTINGS and MCL_SETTINGS.statusBarTexture and MCLcore.media then
                local settingsTexture = MCLcore.media:Fetch("statusbar", MCL_SETTINGS.statusBarTexture)
                if settingsTexture then
                    textureToUse = settingsTexture
                end
            end
            
            pBar:SetStatusBarTexture(textureToUse)
            pBar:GetStatusBarTexture():SetHorizTile(false)
            pBar:GetStatusBarTexture():SetVertTile(false)
            pBar:SetMinMaxValues(0, 100)
            pBar:SetValue(0)
            pBar:SetAllPoints(progressContainer)
            
            -- Text for progress bar
            pBar.Text = pBar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
            pBar.Text:SetPoint("CENTER", pBar, "CENTER", 0, 0)
            pBar.Text:SetJustifyH("CENTER")
            pBar.Text:SetTextColor(1, 1, 1, 1)
            
            -- Update progress bar with actual data
            if totalMounts > 0 then
                local percentage = (collectedMounts / totalMounts) * 100
                pBar:SetValue(percentage)
                pBar.Text:SetText(string.format("%d/%d (%d%%)", collectedMounts, totalMounts, math.floor(percentage)))
                
                -- Use the same color logic as other progress bars
                pBar.val = percentage
                UpdateProgressBar(pBar, totalMounts, collectedMounts)
            else
                pBar:SetValue(0)
                pBar.Text:SetText("0/0 (0%)")
                pBar:SetStatusBarColor(0.5, 0.5, 0.5)  -- Gray for no data
            end
            
            -- Store this in the same way other progress bars are stored
            -- Check if this progress bar is already in the table to prevent duplicates
            local alreadyExists = false
            if MCLcore.statusBarFrames then
                for _, existingBar in ipairs(MCLcore.statusBarFrames) do
                    if existingBar == pBar then
                        alreadyExists = true
                        break
                    end
                end
            end
            if not alreadyExists then
                table.insert(MCLcore.statusBarFrames, pBar)
            end
            
            -- Add hover effects like other sections
            pBar:HookScript("OnEnter", function()
                -- Store the current color before changing to hover color
                local r, g, b, a = pBar:GetStatusBarColor()
                pBar.originalR = r
                pBar.originalG = g
                pBar.originalB = b
                pBar:SetStatusBarColor(0.8, 0.5, 0.9, 1)  -- Purple hover color
            end)
            pBar:HookScript("OnLeave", function()
                -- Restore the stored original color
                if pBar.originalR and pBar.originalG and pBar.originalB then
                    pBar:SetStatusBarColor(pBar.originalR, pBar.originalG, pBar.originalB)
                else
                    -- Fallback: recalculate the color if we don't have stored values
                    if totalMounts > 0 then
                        local percentage = (collectedMounts / totalMounts) * 100
                        if percentage < 33 then
                            pBar:SetStatusBarColor(MCL_SETTINGS.progressColors.low.r, MCL_SETTINGS.progressColors.low.g, MCL_SETTINGS.progressColors.low.b)
                        elseif percentage < 66 then
                            pBar:SetStatusBarColor(MCL_SETTINGS.progressColors.medium.r, MCL_SETTINGS.progressColors.medium.g, MCL_SETTINGS.progressColors.medium.b)
                        elseif percentage < 100 then
                            pBar:SetStatusBarColor(MCL_SETTINGS.progressColors.high.r, MCL_SETTINGS.progressColors.high.g, MCL_SETTINGS.progressColors.high.b)
                        else
                            pBar:SetStatusBarColor(MCL_SETTINGS.progressColors.complete.r, MCL_SETTINGS.progressColors.complete.g, MCL_SETTINGS.progressColors.complete.b)
                        end
                    else
                        pBar:SetStatusBarColor(0.5, 0.5, 0.5)  -- Gray for no data
                    end
                end
            end)
            
            -- Handle unobtainable sections
            if v.name == "Unobtainable" then
                pBar.unobtainable = MCL_SETTINGS.unobtainable
                if MCL_SETTINGS.unobtainable == true then
                    sectionFrame:Hide()
                end
            end

            -- Add click functionality to navigate to the section
            pBar:SetScript("OnMouseDown", function(self, button)
                if button == 'LeftButton' then
                    -- Find the corresponding tab and select it
                    local navFrame = MCLcore.MCL_MF_Nav
                    if navFrame and navFrame.tabs then
                        for _, tab in ipairs(navFrame.tabs) do
                            if tab.section and tab.section.name == v.name then
                                -- Use the same selection logic as in SetTabs
                                for _, t in ipairs(navFrame.tabs) do
                                    if t.content then t.content:Hide() end
                                    if t.SetBackdropBorderColor then
                                        t:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
                                    end
                                end
                                if tab.SetBackdropBorderColor then
                                    tab:SetBackdropBorderColor(1, 0.82, 0, 1)
                                end
                                if MCL_mainFrame and MCL_mainFrame.ScrollFrame then
                                    MCL_mainFrame.ScrollFrame:SetScrollChild(tab.content)
                                    if tab.content then
                                        tab.content:Show()
                                    end
                                    MCL_mainFrame.ScrollFrame:SetVerticalScroll(0)
                                end
                                break
                            end
                        end
                    end
                end
            end)
            
            -- Store frame reference for updates
            local t = {
                name = v.name, -- Use non-localized name for identification
                frame = pBar
            }
            
            -- Initialize overviewFrames if it doesn't exist
            if not MCLcore.overviewFrames then
                MCLcore.overviewFrames = {}
            end
            
            -- Check for duplicates before adding
            local alreadyExists = false
            for _, existingFrame in ipairs(MCLcore.overviewFrames) do
                if existingFrame.name == v.name then
                    alreadyExists = true
                    break
                end
            end
            
            if not alreadyExists then
                table.insert(MCLcore.overviewFrames, t)
            end
            
            -- Update column positions for next section
            if isLeftColumn then
                leftColumnY = leftColumnY - 55  -- Reduced from 75 to 55 (section height 50 + 5 spacing)
            else
                rightColumnY = rightColumnY - 55
            end
        end
    end
    
    -- Adjust parent frame height to accommodate all sections with proper padding
    local maxY = math.min(leftColumnY, rightColumnY)
    local requiredHeight = math.abs(maxY) + 40  -- Add more padding for better spacing
    relativeFrame:SetHeight(requiredHeight)
end


----------------------------------------------------------------
-- Creating a placeholder for each category, this is where we attach each mount to.
----------------------------------------------------------------

function MCL_frames:createCategoryFrame(set, relativeFrame, sectionName)
    if not set then
        return
    end

    -- Check if set has any data
    local hasData = false
    for k, v in pairs(set) do
        hasData = true
        break
    end
    
    if not hasData then
        return
    end

    -- Dynamic layout calculation based on current frame width
    local currentWidth, _ = MCL_frames:GetCurrentFrameDimensions()
    local availableWidth = currentWidth - 60  -- Total content width
    local columnSpacing = 25  -- Reduced spacing between columns to use more space
    local numColumns = 2
    local columnWidth = math.floor((availableWidth - columnSpacing * (numColumns - 1)) / numColumns)
    
    local leftColumnX = 0
    local rightColumnX = leftColumnX + columnWidth + columnSpacing
    
    local leftColumnY = -50
    local rightColumnY = -50
    local categoryIndex = 0

    -- Get sorted category names
local sortedCategoryNames = {}
for k, v in pairs(set) do
    if type(v) == "table" then
        table.insert(sortedCategoryNames, k)
    end
end
table.sort(sortedCategoryNames)

local leftColumnY = -50
local rightColumnY = -50
local categoryIndex = 0

for _, categoryName in ipairs(sortedCategoryNames) do
    local categoryData = set[categoryName]
    -- Calculate mount stats for this category first (needed for dynamic height)
    local totalMounts = 0
    local collectedMounts = 0
    local displayedMounts = 0  -- Track mounts that will actually be displayed
    
    -- Combine both mounts and mountID arrays
    local mountList = {}
    if categoryData.mounts then
        for _, mount in ipairs(categoryData.mounts) do
            table.insert(mountList, mount)
        end
    end
    if categoryData.mountID then
        for _, mount in ipairs(categoryData.mountID) do
            table.insert(mountList, mount)
        end
    end
    
    for _, mountId in ipairs(mountList) do
        local mount_Id = MCLcore.Function:GetMountID(mountId)
        if mount_Id then
            -- Faction check: Only count mounts that are not faction-specific or match the player's faction
            local faction, faction_specific = MCLcore.Function.IsMountFactionSpecific(mountId)
            local playerFaction = UnitFactionGroup("player")
            local allowed = false
            if faction_specific == false then
                allowed = true
            elseif faction_specific == true then
                if faction == 0 then faction = "Horde" elseif faction == 1 then faction = "Alliance" end
                allowed = (faction == playerFaction)
            end
            if allowed then
                local isCollected = IsMountCollected(mount_Id)
                totalMounts = totalMounts + 1
                if isCollected then
                    collectedMounts = collectedMounts + 1
                end
                if not (MCL_SETTINGS.hideCollectedMounts and isCollected) then
                    displayedMounts = displayedMounts + 1
                end
            end
        end
    end

    -- Only increment categoryIndex if the category is actually displayed (e.g., displayedMounts > 0)
    if displayedMounts > 0 then
        categoryIndex = categoryIndex + 1
        -- Determine which column to use (alternate left/right)
        local isLeftColumn = (categoryIndex % 2 == 1)
        local xPos = isLeftColumn and leftColumnX or rightColumnX
        local yPos = isLeftColumn and leftColumnY or rightColumnY
        
        -- Calculate optimal mounts per row based on column width (same calculation as later)
        local categoryPadding = 20  -- Total padding (10px on each side)
        local availableMountWidth = columnWidth - categoryPadding
        
        -- Start with user's preferred mounts per row
        local mountsPerRow = MCL_SETTINGS.mountsPerRow or 12  -- Use setting or default to 12
        -- Ensure it's within bounds
        mountsPerRow = math.max(6, math.min(mountsPerRow, 24))
        
        -- Calculate mount size to fit exactly within available width
        local desiredSpacing = 4  -- Fixed spacing between mounts
        local minMountSize = 16  -- Absolute minimum mount size (reduced from 24)
        local maxMountSize = 48  -- Maximum mount size
        
        -- Try the preferred mounts per row first
        local totalSpacingWidth = desiredSpacing * (mountsPerRow - 1)
        local availableForMounts = availableMountWidth - totalSpacingWidth
        local mountSize = math.floor(availableForMounts / mountsPerRow)
        
        -- If mount size is too small, reduce mounts per row until we get acceptable size
        while mountSize < minMountSize and mountsPerRow > 6 do
            mountsPerRow = mountsPerRow - 1
            totalSpacingWidth = desiredSpacing * (mountsPerRow - 1)
            availableForMounts = availableMountWidth - totalSpacingWidth
            mountSize = math.floor(availableForMounts / mountsPerRow)
        end
        
        -- Ensure mount size is within bounds
        mountSize = math.max(minMountSize, math.min(mountSize, maxMountSize))
        
        -- Recalculate actual spacing to center the grid
        local actualMountWidth = mountSize * mountsPerRow
        local actualSpacing = mountsPerRow > 1 and math.floor((availableMountWidth - actualMountWidth) / (mountsPerRow - 1)) or 0
        actualSpacing = math.max(1, actualSpacing)  -- Minimum 1px spacing (reduced from 2)
        
        -- Calculate dynamic height based on actual mount layout
        local numRows = math.ceil(displayedMounts / mountsPerRow)
        local baseHeight = 80  -- Base height (title + progress bar + padding)
        local rowSpacing = 4  -- Minimal Y-axis spacing between rows (reduced)
        local rowHeight = mountSize + rowSpacing  -- Actual row height based on calculated mount size
        local categoryHeight = baseHeight + (numRows * rowHeight) + 10  -- Reduced bottom padding
        
        -- Create category frame with dynamic height
        local categoryFrame = CreateFrame("Frame", nil, relativeFrame, "BackdropTemplate")

        categoryFrame:SetWidth(columnWidth)
        categoryFrame:SetHeight(categoryHeight)  -- Dynamic height
        categoryFrame:SetPoint("TOPLEFT", relativeFrame, "TOPLEFT", xPos, yPos)
        categoryFrame:SetBackdrop({
            bgFile = "Interface\\Buttons\\WHITE8x8",
            edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
            edgeSize = 8
        })
        categoryFrame:SetBackdropColor(0.05, 0.05, 0.05, 0.9)
        categoryFrame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
        categoryFrame:SetPoint("TOPLEFT", relativeFrame, "TOPLEFT", xPos, yPos)
        categoryFrame:SetBackdrop({
            bgFile = "Interface\\Buttons\\WHITE8x8",
            edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
            edgeSize = 8
        })
        categoryFrame:SetBackdropColor(0.05, 0.05, 0.05, 0.9)
        categoryFrame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)

        -- Category title
        categoryFrame.title = categoryFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
        categoryFrame.title:SetPoint("TOPLEFT", categoryFrame, "TOPLEFT", 10, -8)
        categoryFrame.title:SetText(MCLL[categoryData.name] or MCLL[categoryName] or categoryData.name or categoryName)
        categoryFrame.title:SetTextColor(1, 1, 1, 1)
        
        -- Create progress bar container
        local progressContainer = CreateFrame("Frame", nil, categoryFrame)
        progressContainer:SetWidth(columnWidth - 20)  -- Now 500px wide
        progressContainer:SetHeight(18)
        progressContainer:SetPoint("TOPLEFT", categoryFrame.title, "BOTTOMLEFT", 0, -5)
        
        -- Create progress bar using proper texture fallback
        local pBar = CreateFrame("StatusBar", nil, progressContainer, "BackdropTemplate")
        
        -- Use settings texture if available, otherwise fallback to TargetingFrame
        local textureToUse = "Interface\\TargetingFrame\\UI-StatusBar"  -- Good default that colors well
        if MCL_SETTINGS and MCL_SETTINGS.statusBarTexture and MCLcore.media then
            local settingsTexture = MCLcore.media:Fetch("statusbar", MCL_SETTINGS.statusBarTexture)
            if settingsTexture then
                textureToUse = settingsTexture
            end
        end
        
        pBar:SetStatusBarTexture(textureToUse)
        pBar:GetStatusBarTexture():SetHorizTile(false)
        pBar:GetStatusBarTexture():SetVertTile(false)
        pBar:SetMinMaxValues(0, 100)
        pBar:SetValue(0)
        pBar:SetAllPoints(progressContainer)
        
        -- Background for progress bar
        pBar:SetBackdrop({
            bgFile = "Interface\\Buttons\\WHITE8x8",
            edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
            edgeSize = 1
        })
        pBar:SetBackdropColor(0.1, 0.1, 0.1, 0.8)
        pBar:SetBackdropBorderColor(0.4, 0.4, 0.4, 1)
        
        -- Text for progress bar
        pBar.Text = pBar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
        pBar.Text:SetPoint("CENTER", pBar, "CENTER", 0, 0)
        pBar.Text:SetTextColor(1, 1, 1, 1)
        
        -- Update progress bar
        local percentage = totalMounts > 0 and (collectedMounts / totalMounts) * 100 or 0
        pBar:SetValue(percentage)
        pBar.Text:SetText(string.format("%d/%d (%d%%)", collectedMounts, totalMounts, percentage))
        
        -- Use the UpdateProgressBar function for consistent coloring
        pBar.val = percentage
        UpdateProgressBar(pBar, totalMounts, collectedMounts)
        
        -- Store this progress bar in the statusBarFrames table for settings updates
        table.insert(MCLcore.statusBarFrames, pBar)
        
        -- Mount grid within category - positioned below progress bar
        local mountStartY = -60  -- More padding below progress bar
        
        -- Use the same calculations as in height calculation for consistency
        local categoryPadding = 20  -- Total padding (10px on each side)
        local availableMountWidth = columnWidth - categoryPadding
        
        -- Start with user's preferred mounts per row
        local mountsPerRow = MCL_SETTINGS.mountsPerRow or 12  -- Use setting or default to 12
        -- Ensure it's within bounds
        mountsPerRow = math.max(6, math.min(mountsPerRow, 24))
        
        -- Calculate mount size to fit exactly within available width
        local desiredSpacing = 4  -- Fixed spacing between mounts
        local minMountSize = 16  -- Absolute minimum mount size (reduced from 24)
        local maxMountSize = 48  -- Maximum mount size
        
        -- Try the preferred mounts per row first
        local totalSpacingWidth = desiredSpacing * (mountsPerRow - 1)
        local availableForMounts = availableMountWidth - totalSpacingWidth
        local mountSize = math.floor(availableForMounts / mountsPerRow)
        
        -- If mount size is too small, reduce mounts per row until we get acceptable size
        while mountSize < minMountSize and mountsPerRow > 6 do
            mountsPerRow = mountsPerRow - 1
            totalSpacingWidth = desiredSpacing * (mountsPerRow - 1)
            availableForMounts = availableMountWidth - totalSpacingWidth
            mountSize = math.floor(availableForMounts / mountsPerRow)
        end
        
        -- Ensure mount size is within bounds
        mountSize = math.max(minMountSize, math.min(mountSize, maxMountSize))
        
        -- Recalculate actual spacing to center the grid
        local actualMountWidth = mountSize * mountsPerRow
        local actualSpacing = mountsPerRow > 1 and math.floor((availableMountWidth - actualMountWidth) / (mountsPerRow - 1)) or 0
        actualSpacing = math.max(1, actualSpacing)  -- Minimum 1px spacing (reduced from 2)
        
        -- Y-axis spacing (only affected by height changes)
        local rowSpacing = 4  -- Minimal Y-axis spacing between rows
        
        local maxDisplayMounts = displayedMounts  -- Show all displayed mounts instead of limiting to 24
        local mountStartX = 10
        local displayedIndex = 0  -- Track the actual displayed position
        
        for i, mountId in ipairs(mountList) do
            -- Check if we should skip this mount due to hide collected mounts setting
            local mount_Id = MCLcore.Function:GetMountID(mountId)
            -- Faction check: Only display mounts that are not faction-specific or match the player's faction
            local faction, faction_specific = MCLcore.Function.IsMountFactionSpecific(mountId)
            local playerFaction = UnitFactionGroup("player")
            local allowed = false
            if faction_specific == false then
                allowed = true
            elseif faction_specific == true then
                if faction == 0 then faction = "Horde" elseif faction == 1 then faction = "Alliance" end
                allowed = (faction == playerFaction)
            end
            if allowed and not (mount_Id and MCL_SETTINGS.hideCollectedMounts and IsMountCollected(mount_Id)) then
                displayedIndex = displayedIndex + 1
                if displayedIndex <= maxDisplayMounts then
                local col = ((displayedIndex-1) % mountsPerRow)
                local row = math.floor((displayedIndex-1) / mountsPerRow)
                
                -- Calculate exact position for this icon
                local iconX = mountStartX + col * (mountSize + actualSpacing)
                local iconY = mountStartY - row * (mountSize + rowSpacing)  -- Use rowSpacing for Y
                
                -- Create backdrop frame first (smaller than spacing to create visual gaps)
                local backdropSize = mountSize + 2  -- Only 1px overhang on each side for visual separation
                local backdropFrame = CreateFrame("Frame", nil, categoryFrame, "BackdropTemplate")
                backdropFrame:SetSize(backdropSize, backdropSize)
                backdropFrame:SetPoint("TOPLEFT", categoryFrame, "TOPLEFT", 
                    iconX - 1, -- Minimal offset for overhang
                    iconY + 1) -- Minimal offset for overhang
                
                -- Store the mount ID for search functionality
                backdropFrame.mountID = mountId
                
                -- Create mount frame (for icon) centered in backdrop
                local mountFrame = CreateFrame("Button", nil, backdropFrame)
                mountFrame:SetSize(mountSize, mountSize)
                mountFrame:SetPoint("CENTER", backdropFrame, "CENTER", 0, 0)                            -- Store the mount ID for search functionality
                            mountFrame.mountID = mountId
                            
                            -- Set category and section for pinning functionality
                            mountFrame.category = categoryData.name or categoryName
                            mountFrame.section = sectionName or "Unknown"
                            
                            -- Get mount info and set icon
                            if mount_Id and type(mount_Id) == "number" and mount_Id > 0 then
                                local mountName, spellID, icon = C_MountJournal.GetMountInfoByID(mount_Id)
                                if icon then
                            -- Create the icon texture
                            mountFrame.tex = mountFrame:CreateTexture(nil, "ARTWORK")
                            mountFrame.tex:SetAllPoints(mountFrame)
                            mountFrame.tex:SetTexture(icon)
                            
                            -- Create pin icon for this mount frame
                            mountFrame.pin = mountFrame:CreateTexture(nil, "OVERLAY")
                            mountFrame.pin:SetWidth(16)
                            mountFrame.pin:SetHeight(16)
                            mountFrame.pin:SetTexture("Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\pin.blp")
                            mountFrame.pin:SetPoint("TOPRIGHT", mountFrame, "TOPRIGHT", 6, 6)
                            
                            -- Check if this mount is pinned and set pin visibility
                            local pin_check = MCLcore.Function:CheckIfPinned("m"..mount_Id)
                            if pin_check == true then
                                mountFrame.pin:SetAlpha(1)
                            else
                                mountFrame.pin:SetAlpha(0)
                            end
                            
                            -- Check if mount is collected and style backdrop accordingly
                            if IsMountCollected(mount_Id) then
                                -- Collected mount styling - green background with thick border
                                mountFrame.tex:SetVertexColor(1, 1, 1, 1)
                                backdropFrame:SetBackdrop({
                                    bgFile = "Interface\\Buttons\\WHITE8x8",
                                    edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
                                    edgeSize = 3  -- Thicker border
                                })
                                backdropFrame:SetBackdropColor(0, 0.8, 0, 0.6)  -- Brighter green background
                                backdropFrame:SetBackdropBorderColor(0, 1, 0, 1)  -- Bright green border
                            else
                                -- Uncollected mount styling - red/dark background
                                mountFrame.tex:SetVertexColor(0.4, 0.4, 0.4, 0.7)
                                backdropFrame:SetBackdrop({
                                    bgFile = "Interface\\Buttons\\WHITE8x8",
                                    edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
                                    edgeSize = 2  -- Slightly thinner border for uncollected
                                })
                                backdropFrame:SetBackdropColor(0.3, 0.1, 0.1, 0.4)  -- Reddish background
                                backdropFrame:SetBackdropBorderColor(0.6, 0.2, 0.2, 0.8)  -- Red border
                            end
                            
                            -- Add mount interaction to the mount frame
                            if MCLcore.Function and MCLcore.Function.LinkMountItem then
                                MCLcore.Function:LinkMountItem(mountId, mountFrame, false, false)
                            end
                        end
                    end
                    end
                end  -- Close the if block for non-hidden mounts
            end
            
            -- Update column positions for next category
            if isLeftColumn then
                leftColumnY = leftColumnY - (categoryHeight + 8)  -- Reduced spacing between categories
            else
                rightColumnY = rightColumnY - (categoryHeight + 8)  -- Reduced spacing between categories
            end
            
        end
    end
    
    -- Adjust parent frame height to accommodate all categories with proper padding
    local maxY = math.min(leftColumnY, rightColumnY)
    local requiredHeight = math.abs(maxY) + 20  -- Reduced padding for tighter layout
    relativeFrame:SetHeight(requiredHeight)
end

-- Helper function to get current frame dimensions
function MCL_frames:GetCurrentFrameDimensions()
    if MCL_mainFrame then
        local width = MCL_mainFrame:GetWidth()
        local height = MCL_mainFrame:GetHeight()
        return width, height
    end
    return main_frame_width, main_frame_height  -- Fallback to defaults
end

-- Function to refresh layout after resize
function MCL_frames:RefreshLayout()
    if not MCL_mainFrame then return end
    
    -- Remember which tab was selected before refresh
    local selectedTabName = nil
    local navFrame = MCLcore.MCL_MF_Nav
    if navFrame and navFrame.tabs then
        for _, tab in ipairs(navFrame.tabs) do
            if tab.content and tab.content:IsShown() then
                selectedTabName = tab.section and tab.section.name
                break
            end
        end
    end
    
    -- Update scroll frame size
    MCL_mainFrame.ScrollFrame:ClearAllPoints()
    MCL_mainFrame.ScrollFrame:SetPoint("TOPLEFT", MCL_mainFrame, "TOPLEFT", 10, -40)
    MCL_mainFrame.ScrollFrame:SetPoint("BOTTOMRIGHT", MCL_mainFrame, "BOTTOMRIGHT", -10, 10)
    
    -- Update scroll child size
    if MCL_mainFrame.ScrollChild then
        local currentWidth, currentHeight = MCL_frames:GetCurrentFrameDimensions()
        MCL_mainFrame.ScrollChild:SetSize(currentWidth, currentHeight)
    end
    
    -- Update navigation frame height to match main frame
    if MCLcore.MCL_MF_Nav then
        local _, currentHeight = MCL_frames:GetCurrentFrameDimensions()
        MCLcore.MCL_MF_Nav:SetHeight(currentHeight)
    end
    
    -- Recreate tabs with new dimensions
    if MCL_frames.SetTabs then
        MCL_frames:SetTabs()
        
        -- If we're on the overview page, we need to refresh it since it has dynamic content
        if selectedTabName == "Overview" and MCLcore.overview then
            -- Clear existing overview content more thoroughly
            local children = {MCLcore.overview:GetChildren()}
            for i = 1, #children do
                local child = children[i]
                if child then
                    child:Hide()
                    child:ClearAllPoints()
                    child:SetParent(nil)
                end
            end
            
            -- Clear the overview frames array to prevent duplicates
            if MCLcore.overviewFrames then
                MCLcore.overviewFrames = {}
            end
            
            -- Recreate overview content with new dimensions
            if MCLcore.sections and MCL_frames.createOverviewCategory then
                MCL_frames:createOverviewCategory(MCLcore.sections, MCLcore.overview)
            end
        end
        
        -- Restore the previously selected tab
        if selectedTabName and navFrame and navFrame.tabs then
            for _, tab in ipairs(navFrame.tabs) do
                if tab.section and tab.section.name == selectedTabName then
                    -- Use the same selection logic as in SetTabs
                    for _, t in ipairs(navFrame.tabs) do
                        if t.content then t.content:Hide() end
                        if t.SetBackdropBorderColor then
                            t:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
                        end
                    end
                    if tab.SetBackdropBorderColor then
                        tab:SetBackdropBorderColor(1, 0.82, 0, 1)
                    end
                    if MCL_mainFrame and MCL_mainFrame.ScrollFrame then
                        MCL_mainFrame.ScrollFrame:SetScrollChild(tab.content)
                        if tab.content then
                            tab.content:Show()
                        end
                        MCL_mainFrame.ScrollFrame:SetVerticalScroll(0)
                    end
                    break
                end
            end
        end
    end
end

-- Function to save frame size to settings
function MCL_frames:SaveFrameSize()
    if MCL_mainFrame and MCL_SETTINGS then
        MCL_SETTINGS.frameWidth = MCL_mainFrame:GetWidth()
        MCL_SETTINGS.frameHeight = MCL_mainFrame:GetHeight()
    end
end

-- Function to restore frame size from settings
function MCL_frames:RestoreFrameSize()
    if MCL_mainFrame and MCL_SETTINGS then
        local width = MCL_SETTINGS.frameWidth or main_frame_width
        local height = MCL_SETTINGS.frameHeight or main_frame_height
        MCL_mainFrame:SetSize(width, height)
    end
end

-- Function to calculate minimum height based on navigation content
function MCL_frames:CalculateMinHeight()
    local baseHeight = 100  -- Base height for frame borders, title, etc.
    local navStartY = -20   -- Starting Y position for nav items
    local currentY = navStartY
    
    -- Calculate sections like in SetTabs
    local sections = MCLcore.sectionsOrdered or MCLcore.sections
    if not sections then
        return baseHeight + 200  -- Fallback minimum
    end
    
    local overviewSection, pinnedSection, expansionSections, otherSections = nil, nil, {}, {}
    for _, v in ipairs(sections) do
        if v.name == "Overview" then
            overviewSection = v
        elseif v.name == "Pinned" then
            pinnedSection = v
        elseif v.isExpansion then
            table.insert(expansionSections, v)
        else
            table.insert(otherSections, v)
        end
    end
    
    -- 1. Overview section (32px height + 4px spacing)
    if overviewSection then
        currentY = currentY - 36
    end
    
    -- 2. Expansion grid (calculate rows needed)
    if #expansionSections > 0 then
        local gridCols = 3
        local iconSize = 36
        local iconPad = 8
        local gridRows = math.ceil(#expansionSections / gridCols)
        local gridHeight = gridRows * (iconSize + iconPad)
        currentY = currentY - gridHeight - 10  -- 10px spacing after grid
    end
    
    -- 3. Other sections (28px each)
    for _, v in ipairs(otherSections) do
        currentY = currentY - 28
    end
    
    -- 4. Pinned section (28px)
    if pinnedSection then
        currentY = currentY - 28
    end
    
    -- Convert negative Y offset to positive height requirement
    local requiredNavHeight = math.abs(currentY) + 40  -- 40px bottom padding
    local totalMinHeight = baseHeight + requiredNavHeight
    
    return math.max(totalMinHeight, 300)  -- Ensure at least 300px minimum
end

-- * ------------------------------------------------------
-- * Variables
-- * ------------------------------------------------------
MCLcore.Main = {};
local MCL_Load = MCLcore.Main;
local init_load = true
local load_check = 0
local region = GetCVar('portal')


-- * -------------------------------------------------
-- * Initialise Database
-- * Cycles through data.lua, checks if in game mount journal has an entry for mount. Restarts function if mount does is not loaded yet.
-- * Function is designed to check if the ingame mount journal has loaded correctly before loading our own database.
-- * -----------------------------------------------

function IsRegionalFiltered(id)
    if MCLcore.regionalFilter[region] ~= nil then
        for k, v in pairs(MCLcore.regionalFilter[region]) do
            if v == id then
                return true
            end
        end
    end
    return false
end

function CountMounts()
    MCLcore.mountList = MCLcore.mountList or {}
    local count = 0
    for b, n in pairs(MCLcore.mountList) do
        if type(n) == "table" then
            for h, j in pairs(n) do
                if type(j) == "table" then
                    for k, v in pairs(j) do
                        -- Ensure v.mounts is a table before attempting to iterate over it
                        if type(v.mounts) == "table" then
                            for kk, vv in pairs(v.mounts) do
                                count = count + 1
                            end
                        end
                    end
                end
            end
        end
    end
    return count
end

-- Global for Addon Compartment
--MCL_OnAddonCompartmentClick = function()
    --MCL_Load:Toggle()
--end

-- Save total mount count
local totalMountCount = CountMounts()

local function InitMounts()
    load_check = 0
    totalMountCount = 0
    for b,n in pairs(MCLcore.mountList) do
        for h,j in pairs(n) do
            if (type(j) == "table") then
                for k,v in pairs(j) do
                    for kk,vv in pairs(v.mounts) do
                        if not IsRegionalFiltered(vv) then
                            if not string.match(vv, "^m") then
                                totalMountCount = totalMountCount + 1
                                C_Item.RequestLoadItemDataByID(vv)
                                local mountName = C_MountJournal.GetMountFromItem(vv)
                                if mountName ~= nil then
                                    load_check = load_check + 1
                                end                            
                            end
                        end                                     
                    end
                end
            end
        end
    end
end


-- * -----------------------------------------------------
-- * Toggle the main window
-- * -----------------------------------------------------


MCLcore.dataLoaded = false

function MCL_Load:PreLoad()      
    if load_check >= totalMountCount then
        MCLcore.dataLoaded = true
        return true
    else   
        InitMounts()         
        return false
    end
end

-- Set a maximum number of initialization retries
local MAX_INIT_RETRIES = 3

-- Initialization function
function MCL_Load:Init(force)
    local function repeatCheck()
        local retries = 0
        if MCL_Load:PreLoad() then
            -- Initialization steps
            if MCLcore.MCL_MF == nil then
                -- Ensure Frames module is available
                if not MCLcore.Frames then
                    return false
                end
                MCLcore.MCL_MF = MCLcore.Frames:CreateMainFrame()
                MCLcore.MCL_MF:SetShown(false)
                MCLcore.Function:initSections()
            end
            MCLcore.Function:UpdateCollection()
            init_load = false -- Ensure that the initialization does not repeat unnecessarily.
        else
            retries = retries + 1
            if retries < MAX_INIT_RETRIES then
                -- Retry the initialization process after a delay
                C_Timer.After(1, repeatCheck)
            end
        end
    end

    -- Force reinitialization if specifically requested
    if force then
        load_check = 0
        MCLcore.dataLoaded = false
    end

    -- Check if we need to attempt initialization
    if not MCLcore.dataLoaded then
        init_load = true
        repeatCheck()
    end
end

-- Toggle function
function MCL_Load:Toggle()
    -- Check preload status and if false, prevent execution.
    if MCLcore.dataLoaded == false then
        MCL_Load:Init()
        return
    end 
    if MCLcore.MCL_MF == nil then
        return -- Immune to function calls before the initialization process is complete, as the frame doesn't exist yet.
    else
        MCLcore.MCL_MF:SetShown(not MCLcore.MCL_MF:IsShown()) -- The addon's frame exists and can be toggled.
    end
    MCLcore.Function:UpdateCollection()
end

local f = CreateFrame("Frame")
local login = true



-- * -------------------------------------------------
-- * Loads addon once Blizzard_Collections has loaded in.
-- * -------------------------------------------------


local function onevent(self, event, arg1, ...)
    if(login and ((event == "ADDON_LOADED" and name == "OrzUI") or (event == "PLAYER_LOGIN"))) then
        login = nil
        f:UnregisterEvent("ADDON_LOADED")
        f:UnregisterEvent("PLAYER_LOGIN")
	    if not C_AddOns.IsAddOnLoaded("Blizzard_Collections") then
	        C_AddOns.LoadAddOn("Blizzard_Collections")
	    end
        
        -- Ensure Function module is available before calling AddonSettings
        if MCLcore.Function and MCLcore.Function.AddonSettings then
            MCLcore.Function:AddonSettings()
        end
        
        -- Initiate the addon when the required addon is loaded
        MCL_Load:Init()
        
        -- Initialize search functionality
        if MCLcore.InitializeSearch then
            MCLcore.InitializeSearch()
        end
    end
end


-- function addon:MCL_MM() self.db.profile.minimap.hide = not self.db.profile.minimap.hide if self.db.profile.minimap.hide then icon:Hide("MCL-icon") else icon:Show("MCL-icon") end end
f:RegisterEvent("ADDON_LOADED")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", onevent)
-- Initialize search functionality when the addon loads
local function InitializeSearch()
    if not MCLcore.Search then
        -- Search functionality namespace
        MCLcore.Search = {}

        -- Search state
        MCLcore.Search.searchResults = {}
        MCLcore.Search.currentSearchTerm = ""
        MCLcore.Search.isSearchActive = false

        -- Search functionality
        function MCLcore.Search:PerformSearch(searchTerm)
            if not searchTerm or searchTerm == "" then
                self:ClearSearch()
                return
            end
            
            -- Remove leading and trailing whitespace
            searchTerm = searchTerm:gsub("^%s*(.-)%s*$", "%1")
            if searchTerm == "" then
                self:ClearSearch()
                return
            end
            
            self.currentSearchTerm = searchTerm:lower()
            self.isSearchActive = true
            self.searchResults = {}
            
            -- Search through all mounts in all sections
            for sectionIndex, section in ipairs(MCLcore.sectionNames) do
                if section.mounts then
                    -- Handle different mount data structures
                    local categories = section.mounts.categories or section.mounts
                    if categories then
                        for categoryName, categoryData in pairs(categories) do
                            if type(categoryData) == "table" then
                                -- Combine both mounts and mountID arrays for search
                                local mountList = {}
                                if categoryData.mounts then
                                    for _, mount in ipairs(categoryData.mounts) do
                                        table.insert(mountList, mount)
                                    end
                                end
                                if categoryData.mountID then
                                    for _, mount in ipairs(categoryData.mountID) do
                                        table.insert(mountList, mount)
                                    end
                                end
                                
                                for _, mountId in ipairs(mountList) do
                                    local mount_Id = MCLcore.Function:GetMountID(mountId)
                                    if mount_Id then
                                        local mountName, spellID, icon = C_MountJournal.GetMountInfoByID(mount_Id)
                                        local isCollected = IsMountCollected(mount_Id)
                                        
                                        -- Skip collected mounts if the setting is enabled
                                        if MCL_SETTINGS.hideCollectedMounts and isCollected then
                                            -- Skip this mount entirely
                                        elseif mountName and mountName:lower():find(self.currentSearchTerm, 1, true) then
                                            table.insert(self.searchResults, {
                                                mountId = mountId,
                                                mountName = mountName,
                                                icon = icon,
                                                spellID = spellID,
                                                section = section.name,
                                                category = categoryData.name or categoryName,
                                                isCollected = isCollected
                                            })
                                        end
                                    end
                                end
                            end
                        end
                    end
                end
            end
            
            -- Display search results
            self:DisplaySearchResults()
        end        function MCLcore.Search:ClearSearch()
            self.currentSearchTerm = ""
            self.isSearchActive = false
            self.searchResults = {}
            
            -- Clear any highlighting
            self:ClearHighlighting()
            
            -- Hide search results if they exist
            if MCLcore.searchResultsContent then
                MCLcore.searchResultsContent:Hide()
            end
            
            -- Restore the previously selected tab using the proper SelectTab function
            if self.previouslySelectedTab then
                -- We need to call the SelectTab function from frames.lua
                -- Since it's local, we'll replicate its logic here
                if MCLcore.MCL_MF_Nav and MCLcore.MCL_MF_Nav.tabs then
                    -- Deselect all tabs first
                    for _, t in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                        if t.SetBackdropBorderColor then
                            t:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
                        end
                    end
                    -- Hide all tab contents
                    for _, t in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                        if t.content then
                            t.content:Hide()
                        end
                    end
                    -- Restore the selected tab
                    if self.previouslySelectedTab.SetBackdropBorderColor then
                        self.previouslySelectedTab:SetBackdropBorderColor(1, 0.82, 0, 1)
                    end
                    if self.previouslySelectedTab.content and MCL_mainFrame.ScrollFrame then
                        MCL_mainFrame.ScrollFrame:SetScrollChild(self.previouslySelectedTab.content)
                        self.previouslySelectedTab.content:Show()
                        MCL_mainFrame.ScrollFrame:SetVerticalScroll(0)
                    end
                    -- Update global reference
                    MCLcore.currentlySelectedTab = self.previouslySelectedTab
                end
                self.previouslySelectedTab = nil
            end
        end

        function MCLcore.Search:ClearSearchAndGoToOverview()
            self.currentSearchTerm = ""
            self.isSearchActive = false
            self.searchResults = {}
            
            -- Clear any highlighting
            self:ClearHighlighting()
            
            -- Hide search results if they exist
            if MCLcore.searchResultsContent then
                MCLcore.searchResultsContent:Hide()
            end
            
            -- Always go to Overview tab regardless of previous selection
            if MCLcore.MCL_MF_Nav and MCLcore.MCL_MF_Nav.tabs then
                -- Find the Overview tab (should be the first one)
                local overviewTab = nil
                for _, tab in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                    if tab.section and tab.section.name == "Overview" then
                        overviewTab = tab
                        break
                    end
                end
                
                if overviewTab then
                    -- Deselect all tabs first
                    for _, t in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                        if t.SetBackdropBorderColor then
                            t:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
                        end
                    end
                    -- Hide all tab contents
                    for _, t in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                        if t.content then
                            t.content:Hide()
                        end
                    end
                    -- Select the Overview tab
                    if overviewTab.SetBackdropBorderColor then
                        overviewTab:SetBackdropBorderColor(1, 0.82, 0, 1)
                    end
                    if overviewTab.content and MCL_mainFrame.ScrollFrame then
                        MCL_mainFrame.ScrollFrame:SetScrollChild(overviewTab.content)
                        overviewTab.content:Show()
                        MCL_mainFrame.ScrollFrame:SetVerticalScroll(0)
                    end
                    -- Update global reference
                    MCLcore.currentlySelectedTab = overviewTab
                end
            end
            
            -- Clear the previously selected tab since we're defaulting to Overview
            self.previouslySelectedTab = nil
        end
        function MCLcore.Search:DisplaySearchResults()
            if not MCL_mainFrame then return end
            
            -- Store the currently selected tab so we can restore it later
            if MCLcore.currentlySelectedTab and not self.previouslySelectedTab then
                self.previouslySelectedTab = MCLcore.currentlySelectedTab
            end
            
            -- Hide all tab contents first
            if MCLcore.MCL_MF_Nav and MCLcore.MCL_MF_Nav.tabs then
                for _, t in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                    if t.content then
                        t.content:Hide()
                    end
                end
                -- Deselect all tabs visually
                for _, t in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                    if t.SetBackdropBorderColor then
                        t:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
                    end
                end
            end
            
            -- Create or get search results content frame
            if not MCLcore.searchResultsContent then
                MCLcore.searchResultsContent = MCLcore.Frames:createContentFrame(MCL_mainFrame.ScrollChild, "Search Results")
            end
            
            -- Update search results content
            self:UpdateSearchResultsContent()
            
            -- Show search results in main frame
            if MCL_mainFrame.ScrollFrame then
                MCL_mainFrame.ScrollFrame:SetScrollChild(MCLcore.searchResultsContent)
                MCLcore.searchResultsContent:Show()
                MCL_mainFrame.ScrollFrame:SetVerticalScroll(0)
            end
        end        function MCLcore.Search:UpdateSearchResultsContent()
            if not MCLcore.searchResultsContent then return end
            
            local content = MCLcore.searchResultsContent
            
            -- Clear existing content more thoroughly
            -- First hide and remove all children except the title
            for i = content:GetNumChildren(), 1, -1 do
                local child = select(i, content:GetChildren())
                if child and child ~= content.title then
                    child:Hide()
                    child:SetParent(nil)
                end
            end
            
            -- Also clear any FontStrings that were created directly on the content frame
            -- We need to track and clear these separately since they're not children
            if content.searchFontStrings then
                for _, fontString in ipairs(content.searchFontStrings) do
                    if fontString then
                        fontString:Hide()
                        fontString:SetParent(nil)
                    end
                end
            end
            content.searchFontStrings = {}
            
            -- Update title
            content.title:SetText(string.format("Search Results: '%s' (%d found)", self.currentSearchTerm, #self.searchResults))
            
            if #self.searchResults == 0 then
                -- Show no results message
                if not content.noResultsText then
                    content.noResultsText = content:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
                    content.noResultsText:SetPoint("TOP", content.title, "BOTTOM", 0, -20)
                    content.noResultsText:SetTextColor(0.7, 0.7, 0.7, 1)
                    table.insert(content.searchFontStrings, content.noResultsText)
                end
                content.noResultsText:SetText("No mounts found matching your search.")
                content.noResultsText:Show()
                return
            else
                if content.noResultsText then
                    content.noResultsText:Hide()
                end
            end
            
            -- Group results by section, then by category
            local groupedResults = {}
            for _, result in ipairs(self.searchResults) do
                if not groupedResults[result.section] then
                    groupedResults[result.section] = {}
                end
                if not groupedResults[result.section][result.category] then
                    groupedResults[result.section][result.category] = {}
                end
                table.insert(groupedResults[result.section][result.category], result)
            end
            
            -- Calculate layout dimensions
            local currentWidth, _ = MCLcore.Frames:GetCurrentFrameDimensions()
            local availableWidth = currentWidth - 60
            
            -- Start with user's preferred mounts per row
            local mountsPerRow = MCL_SETTINGS.mountsPerRow or 12  -- Use setting or default to 12
            -- Ensure it's within bounds
            mountsPerRow = math.max(6, math.min(mountsPerRow, 24))
            
            -- Calculate mount size to fit exactly within available width
            local desiredSpacing = 4  -- Fixed spacing between mounts
            local minMountSize = 16  -- Absolute minimum mount size
            local maxMountSize = 48  -- Maximum mount size
            
            -- Try the preferred mounts per row first
            local totalSpacingWidth = desiredSpacing * (mountsPerRow - 1)
            local availableForMounts = availableWidth - totalSpacingWidth
            local mountSize = math.floor(availableForMounts / mountsPerRow)
            
            -- If mount size is too small, reduce mounts per row until we get acceptable size
            while mountSize < minMountSize and mountsPerRow > 6 do
                mountsPerRow = mountsPerRow - 1
                totalSpacingWidth = desiredSpacing * (mountsPerRow - 1)
                availableForMounts = availableWidth - totalSpacingWidth
                mountSize = math.floor(availableForMounts / mountsPerRow)
            end
            
            -- Ensure mount size is within bounds
            mountSize = math.max(minMountSize, math.min(mountSize, maxMountSize))
            
            -- Recalculate actual spacing to center the grid
            local actualMountWidth = mountSize * mountsPerRow
            local spacing = mountsPerRow > 1 and math.floor((availableWidth - actualMountWidth) / (mountsPerRow - 1)) or 0
            spacing = math.max(1, spacing)  -- Minimum 1px spacing
            
            local currentY = -80 -- Start below title
            local mountIndex = 0
            
            -- Display results grouped by section and category
            for sectionName, sectionData in pairs(groupedResults) do
                -- Create section header
                local sectionHeader = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
                sectionHeader:SetPoint("TOPLEFT", content, "TOPLEFT", 10, currentY)
                sectionHeader:SetText(sectionName)
                sectionHeader:SetTextColor(1, 0.82, 0, 1) -- Gold color like Blizzard UI
                table.insert(content.searchFontStrings, sectionHeader)
                currentY = currentY - 25
                
                for categoryName, categoryMounts in pairs(sectionData) do
                    -- Create category header
                    local categoryHeader = content:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
                    categoryHeader:SetPoint("TOPLEFT", content, "TOPLEFT", 20, currentY)
                    categoryHeader:SetText(categoryName .. " (" .. #categoryMounts .. ")")
                    categoryHeader:SetTextColor(0.8, 0.8, 1, 1) -- Light blue color
                    table.insert(content.searchFontStrings, categoryHeader)
                    currentY = currentY - 20
                    
                    -- Display mounts for this category
                    local categoryStartY = currentY
                    local categoryMountIndex = 0
                    
                    for _, result in ipairs(categoryMounts) do
                        local col = (categoryMountIndex % mountsPerRow)
                        local row = math.floor(categoryMountIndex / mountsPerRow)
                        
                        local x = spacing + col * (mountSize + spacing)
                        local y = categoryStartY - row * (mountSize + 10)
                          -- Create mount frame
                        local mountFrame = CreateFrame("Button", nil, content, "BackdropTemplate")
                        mountFrame:SetSize(mountSize, mountSize)
                        mountFrame:SetPoint("TOPLEFT", content, "TOPLEFT", x, y)
                        
                        -- Set mount icon
                        mountFrame.tex = mountFrame:CreateTexture(nil, "ARTWORK")
                        mountFrame.tex:SetAllPoints(mountFrame)
                        mountFrame.tex:SetTexture(result.icon)
                          -- Add pin functionality (required for pin/unpin operations)
                        mountFrame.pin = mountFrame:CreateTexture(nil, "OVERLAY")
                        mountFrame.pin:SetWidth(16)
                        mountFrame.pin:SetHeight(16)
                        mountFrame.pin:SetTexture("Interface\\AddOns\\OrzUI\\Media\\Modules\\MountCollectionLog\\pin.blp")
                        mountFrame.pin:SetPoint("TOPRIGHT", mountFrame, "TOPRIGHT", -2, -2)
                        mountFrame.pin:SetAlpha(0)
                        
                        -- Set mount properties for functionality
                        mountFrame.mountID = result.mountId
                        mountFrame.category = result.category
                        mountFrame.section = result.section
                        
                        -- Check if mount is already pinned and show pin icon if needed
                        local isPinned, pinIndex = MCLcore.Function:CheckIfPinned("m" .. result.mountId)
                        if isPinned then
                            mountFrame.pin:SetAlpha(1)
                        end                        -- Style based on collection status
                        -- Note: With hideCollectedMounts enabled, collected mounts won't be in search results
                        if result.isCollected then
                            mountFrame.tex:SetVertexColor(1, 1, 1, 1)
                            mountFrame:SetBackdrop({
                                bgFile = "Interface\\Buttons\\WHITE8x8",
                                edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
                                edgeSize = 2
                            })
                            mountFrame:SetBackdropColor(0, 0.8, 0, 0.6)
                            mountFrame:SetBackdropBorderColor(0, 1, 0, 1)
                        else
                            mountFrame.tex:SetVertexColor(0.4, 0.4, 0.4, 0.7)
                            mountFrame:SetBackdrop({
                                bgFile = "Interface\\Buttons\\WHITE8x8",
                                edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
                                edgeSize = 2
                            })
                            mountFrame:SetBackdropColor(0.8, 0, 0, 0.4)
                            mountFrame:SetBackdropBorderColor(0.8, 0.2, 0.2, 1)
                        end-- Add tooltip and click functionality
                        mountFrame:SetScript("OnEnter", function(self)
                            GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
                            GameTooltip:SetMountBySpellID(result.spellID)
                            GameTooltip:AddLine(" ")
                            GameTooltip:AddLine("Found in: " .. result.section .. " > " .. result.category, 0.7, 0.7, 1, 1)
                            GameTooltip:AddLine("Click to navigate to this mount's location", 1, 1, 0, 1)
                            GameTooltip:AddLine("Ctrl+Right-Click to pin/unpin this mount", 1, 1, 0, 1)
                            GameTooltip:Show()
                        end)
                        mountFrame:SetScript("OnLeave", function()
                            GameTooltip:Hide()
                        end)
                        
                        -- Set up proper mouse click functionality including pinning
                        MCLcore.Function:SetMouseClickFunctionality(mountFrame, result.mountId, result.mountName, nil, result.spellID, false)
                        
                        -- Add left-click navigation functionality (OnClick doesn't conflict with OnMouseDown)
                        mountFrame:SetScript("OnClick", function(self, button)
                            if button == "LeftButton" and not IsControlKeyDown() then
                                -- Navigate to the mount's location
                                MCLcore.Search:NavigateToMount(result)
                            end
                        end)
                        
                        categoryMountIndex = categoryMountIndex + 1
                    end
                    
                    -- Calculate how much Y space this category used
                    local categoryRows = math.ceil(#categoryMounts / mountsPerRow)
                    currentY = categoryStartY - categoryRows * (mountSize + 10) - 10 -- Add some spacing after category
                end
                
                -- Add extra spacing after each section
                currentY = currentY - 10
            end
        end
        function MCLcore.Search:NavigateToMount(result)
            -- Store the target section for navigation
            local targetSection = result.section
            
            -- Clear search first (this will restore the previous tab)
            self:ClearSearch()
            
            -- Now find and select the correct tab for this section
            if MCLcore.MCL_MF_Nav and MCLcore.MCL_MF_Nav.tabs then
                for _, tab in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                    if tab.section and tab.section.name == targetSection then
                        -- Use the proper tab selection logic (same as SelectTab function)
                        -- Deselect all tabs first
                        for _, t in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                            if t.SetBackdropBorderColor then
                                t:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
                            end
                        end
                        -- Hide all tab contents
                        for _, t in ipairs(MCLcore.MCL_MF_Nav.tabs) do
                            if t.content then
                                t.content:Hide()
                            end
                        end
                        -- Select the target tab
                        if tab.SetBackdropBorderColor then
                            tab:SetBackdropBorderColor(1, 0.82, 0, 1)
                        end
                        if tab.content and MCL_mainFrame.ScrollFrame then
                            MCL_mainFrame.ScrollFrame:SetScrollChild(tab.content)
                            tab.content:Show()
                            MCL_mainFrame.ScrollFrame:SetVerticalScroll(0)
                        end
                        -- Update global reference
                        MCLcore.currentlySelectedTab = tab
                        break
                    end
                end
            end
            
            -- Store the mount to highlight for later
            MCLcore.Search.highlightMountId = result.mountId
            
            -- Schedule highlighting for next frame to ensure content is loaded
            C_Timer.After(0.1, function()
                MCLcore.Search:HighlightMount(result.mountId)
            end)
            
            -- Print info for user feedback
            print("|cff00CCFFMount Collection Log:|r Found '" .. result.mountName .. "' in " .. result.section .. " > " .. result.category)
        end

        function MCLcore.Search:ClearHighlighting()
            -- Clear any existing highlighting effects
            if MCLcore.highlightedMountFrame then
                if MCLcore.highlightedMountFrame.originalBorderColor then
                    MCLcore.highlightedMountFrame:SetBackdropBorderColor(
                        MCLcore.highlightedMountFrame.originalBorderColor[1],
                        MCLcore.highlightedMountFrame.originalBorderColor[2],
                        MCLcore.highlightedMountFrame.originalBorderColor[3],
                        MCLcore.highlightedMountFrame.originalBorderColor[4]
                    )
                end
                if MCLcore.highlightedMountFrame.highlightTimer then
                    MCLcore.highlightedMountFrame.highlightTimer:Cancel()
                end
                MCLcore.highlightedMountFrame = nil
            end
        end

        function MCLcore.Search:HighlightMount(mountId)
            -- Clear any existing highlighting
            self:ClearHighlighting()
            
            -- Find the mount frame in the current content
            local currentContent = MCL_mainFrame.ScrollFrame:GetScrollChild()
            if not currentContent then return end
            
            -- Look for mount frames that match our target mount
            local function FindMountFrame(parent)
                for i = 1, parent:GetNumChildren() do
                    local child = select(i, parent:GetChildren())
                    if child and child.mountID then
                        local mount_Id = MCLcore.Function:GetMountID(child.mountID)
                        local target_Id = MCLcore.Function:GetMountID(mountId)
                        if mount_Id and target_Id and mount_Id == target_Id then
                            return child
                        end
                    end
                    -- Recursively search children
                    local found = FindMountFrame(child)
                    if found then return found end
                end
            end
            
            local mountFrame = FindMountFrame(currentContent)
            if mountFrame then
                -- Store original border color
                local r, g, b, a = mountFrame:GetBackdropBorderColor()
                mountFrame.originalBorderColor = {r, g, b, a}
                
                -- Store reference for cleanup
                MCLcore.highlightedMountFrame = mountFrame
                
                -- Create pulsing highlight effect
                local pulseTimer
                local pulseCount = 0
                local maxPulses = 6
                
                pulseTimer = C_Timer.NewTicker(0.5, function()
                    pulseCount = pulseCount + 1
                    if pulseCount > maxPulses then
                        -- Restore original color and stop
                        if mountFrame.originalBorderColor then
                            mountFrame:SetBackdropBorderColor(
                                mountFrame.originalBorderColor[1],
                                mountFrame.originalBorderColor[2],
                                mountFrame.originalBorderColor[3],
                                mountFrame.originalBorderColor[4]
                            )
                        end
                        pulseTimer:Cancel()
                        MCLcore.highlightedMountFrame = nil
                        return
                    end
                    
                    -- Pulse between yellow and original color
                    if pulseCount % 2 == 1 then
                        mountFrame:SetBackdropBorderColor(1, 1, 0, 1) -- Bright yellow
                    else
                        mountFrame:SetBackdropBorderColor(
                            mountFrame.originalBorderColor[1],
                            mountFrame.originalBorderColor[2],
                            mountFrame.originalBorderColor[3],
                            mountFrame.originalBorderColor[4]
                        )
                    end
                end)
                
                mountFrame.highlightTimer = pulseTimer
                
                -- Scroll to the mount if needed
                local frameTop = currentContent:GetTop()
                local frameBottom = currentContent:GetBottom()
                local mountTop = mountFrame:GetTop()
                local mountBottom = mountFrame:GetBottom()
                
                if frameTop and frameBottom and mountTop and mountBottom then
                    local scrollFrame = MCL_mainFrame.ScrollFrame
                    local scrollTop = scrollFrame:GetTop()
                    local scrollBottom = scrollFrame:GetBottom()
                    
                    -- Check if mount is not visible in scroll area
                    if mountTop > scrollTop or mountBottom < scrollBottom then
                        -- Calculate scroll position to center the mount
                        local scrollHeight = scrollFrame:GetVerticalScrollRange()
                        local contentHeight = frameTop - frameBottom
                        local mountCenter = (mountTop + mountBottom) / 2
                        local targetScroll = (frameTop - mountCenter) / contentHeight * scrollHeight
                        
                        -- Clamp to valid scroll range
                        targetScroll = math.max(0, math.min(targetScroll, scrollHeight))
                        scrollFrame:SetVerticalScroll(targetScroll)
                    end
                end
            end
        end
    end
end

-- Make InitializeSearch available globally so it can be called when addon loads
MCLcore = MCLcore or {}
MCLcore.InitializeSearch = InitializeSearch

-- Namespace
-------------------------------------------------------------

SLASH_MCL1 = "/mcl";

SlashCmdList["MCL"] = function(msg)
    if msg:lower() == "help" then
        print(MCLL["|cff00CCFFMount Collection Log Commands:\n|cffFF0000Show:|cffFFFFFF Shows your mount collection log\n|cffFF0000Icon:|cffFFFFFF Toggles the minimap icon\n|cffFF0000Config:|cffFFFFFF Opens the settings\n|cffFF0000Help:|cffFFFFFF Shows commands"])
    end
    if msg:lower() == "show" then
        MCLcore.Main.Toggle();
    end
    if msg:lower() == "icon" then
        MCLcore.Function.MCL_MM();
    end        
    if msg:lower() == "" then
        MCLcore.Main.Toggle();
    end
    if msg:lower() == "debug" then
        MCLcore.Function:GetCollectedMounts();
    end
    if msg:lower() == "config" or msg == "settings" then
        MCLcore.Frames:openSettings();
    end
    if msg:lower() == "refresh" then
        if MCLcore.Main and type(MCLcore.Main.Init) == "function" then
            MCLcore.Main:Init(true)  -- True to force re-initialization.
        end
    end  
 end
