-- 更新分类图标为 emoji 格式
-- 运行此脚本修复分类图标显示问题

-- 更新一级分类图标
UPDATE public.ml_categories
SET icon_url = 
    CASE 
        WHEN slug = 'digital' THEN '📱'
        WHEN slug = 'fashion' THEN '👕'
        WHEN slug = 'home' THEN '🏠'
        WHEN slug = 'food' THEN '🍎'
        WHEN slug = 'beauty' THEN '💄'
        WHEN slug = 'sports' THEN '⚽'
        WHEN slug = 'books' THEN '📚'
        WHEN slug = 'baby' THEN '👶'
        WHEN slug = 'health' THEN '💊'
        ELSE icon_url
    END
WHERE level = 1;

-- 更新二级分类图标
UPDATE public.ml_categories
SET icon_url = 
    CASE 
        -- 数码电器二级分类
        WHEN slug = 'mobile' THEN '📱'
        WHEN slug = 'computer' THEN '💻'
        WHEN slug = 'appliance' THEN '🎥'
        WHEN slug = 'accessories' THEN '🔌'
        -- 服装鞋帽二级分类
        WHEN slug = 'mens-wear' THEN '👔'
        WHEN slug = 'womens-wear' THEN '👗'
        WHEN slug = 'mens-shoes' THEN '👞'
        WHEN slug = 'womens-shoes' THEN '👠'
        -- 家居用品二级分类
        WHEN slug = 'furniture' THEN '🛋️'
        WHEN slug = 'decoration' THEN '🖼️'
        WHEN slug = 'kitchen' THEN '🍳'
        WHEN slug = 'daily' THEN '🧹'
        -- 食品饮料二级分类
        WHEN slug = 'fruits' THEN '🍊'
        WHEN slug = 'meat' THEN '🥩'
        WHEN slug = 'snacks' THEN '🍪'
        WHEN slug = 'drinks' THEN '🍺'
        -- 美妆护肤二级分类
        WHEN slug = 'skincare' THEN '🧴'
        WHEN slug = 'makeup' THEN '💅'
        -- 运动户外二级分类
        WHEN slug = 'outdoor' THEN '🏕️'
        WHEN slug = 'fitness' THEN '🏋️'
        -- 母婴用品二级分类
        WHEN slug = 'toys' THEN '🧸'
        WHEN slug = 'feeding' THEN '🍼'
        -- 图书文娱二级分类
        WHEN slug = 'stationery' THEN '✏️'
        WHEN slug = 'audio' THEN '🎵'
        ELSE icon_url
    END
WHERE level = 2;

-- 如果有 icon_url 为 icon-xxx 格式的记录，也进行更新
UPDATE public.ml_categories
SET icon_url = 
    CASE 
        WHEN icon_url = 'icon-digital' THEN '📱'
        WHEN icon_url = 'icon-fashion' THEN '👕'
        WHEN icon_url = 'icon-home' THEN '🏠'
        WHEN icon_url = 'icon-food' THEN '🍎'
        WHEN icon_url = 'icon-beauty' THEN '💄'
        WHEN icon_url = 'icon-sports' THEN '⚽'
        WHEN icon_url = 'icon-books' THEN '📚'
        WHEN icon_url = 'icon-baby' THEN '👶'
        WHEN icon_url = 'icon-health' THEN '💊'
        ELSE icon_url
    END
WHERE icon_url LIKE 'icon-%';

-- 查看更新结果
SELECT name, slug, icon_url FROM public.ml_categories WHERE level = 1 ORDER BY sort_order;
SELECT name, slug, icon_url FROM public.ml_categories WHERE level = 2 ORDER BY sort_order;
