package com.sketch.ar.artdrawing.main

import android.content.Intent
import android.os.Bundle
import android.widget.LinearLayout
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ad.toponlibrary.AdManager
import com.sketch.ar.artdrawing.MyApp
import com.sketch.ar.artdrawing.utils.ItemDec
import com.sketch.ar.artdrawing.allImageList.AllImageListActivity
import com.sketch.ar.artdrawing.like.LikeActivity
import com.sketch.ar.artdrawing.importImage.ImportImageActivity
import com.sketch.ar.artdrawing.R

class MainCategoryActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main_category)

        val layoutUpImage = findViewById<LinearLayout>(R.id.up_image)
        val layoutFavorite = findViewById<LinearLayout>(R.id.layout_favorite)
        val recycler = findViewById<RecyclerView>(R.id.recyclerview)

        layoutUpImage.setOnClickListener {
            startActivity(Intent(this@MainCategoryActivity, ImportImageActivity::class.java).apply {

            })
        }
        layoutFavorite.setOnClickListener {
            startActivity(Intent(this@MainCategoryActivity, LikeActivity::class.java).apply {

            })
        }
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        AdManager.loadAllAd()
        recycler.run {
            adapter = InitMainList().apply {
                updateData(MyApp.Companion.assetFolders)
            }
            layoutManager = GridLayoutManager(this@MainCategoryActivity,2)
            addItemDecoration(ItemDec(15, 15, 0))
        }
    }

    private fun InitMainList(): MainCategoryAdapter {
        val mainCategoryAdapter = MainCategoryAdapter(this@MainCategoryActivity){ name->
            startActivity(Intent(this@MainCategoryActivity, AllImageListActivity::class.java).apply {
                putExtra(AllImageListActivity.Companion.IntentKey_Title,name)
            })
        }

        return mainCategoryAdapter
    }


}