package com.backendsys.modules.cms.views;

import cn.hutool.core.convert.Convert;
import com.backendsys.modules.common.aspect.Pages;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Locale;

@Controller
public class IndexViewController {

    @Autowired
    private MessageSource messageSource;

    @Pages
    @GetMapping({"/"})
    public String index(Model model, HttpServletRequest request) {

        String lang = Convert.toStr(model.getAttribute("lang"));

        model.addAttribute("title","首页");

//        model.addAttribute("bannerList", cmsBannerService.queryBannerPublic());
//
//        CmsArticleDTO cmsArticleDTO = new CmsArticleDTO();
//        cmsArticleDTO.setLang((String) model.getAttribute("lang"));
//
//        // 分类1
//        cmsArticleDTO.setCategory_id(1L);
//        Map<String, Object> list1 = cmsArticleService.queryArticle(1, 4, cmsArticleDTO);
//        model.addAttribute("articleList1", list1);
//
//        // 分类2
//        cmsArticleDTO.setCategory_id(2L);
//        Map<String, Object> list2 = cmsArticleService.queryArticle(1, 4, cmsArticleDTO);
//        model.addAttribute("articleList2", list2);

        // -- Layout ---------------------------------------------
        String titleTranslate = messageSource.getMessage("index.title", null, new Locale(lang));
        model.addAttribute("title", titleTranslate);

        model.addAttribute("layout", "index");
        return "layout/layout";
    }

}
