package com.drawing.drawsketch.main

import android.content.Context
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.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.drawing.drawsketch.App
import com.drawing.drawsketch.ItemSpace
import com.drawing.drawsketch.R
import com.drawing.drawsketch.all.CategoryListActivity
import com.drawing.drawsketch.collection.CollectionActivity
import com.drawing.drawsketch.upload.UploadActivity

class MainActivity : AppCompatActivity() {

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

        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@MainActivity, UploadActivity::class.java).apply {

            })
        }
        layoutFavorite.setOnClickListener {
            startActivity(Intent(this@MainActivity, CollectionActivity::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
        }

        recycler.run {
            adapter = InitMainList().apply {
                updateData(App.assetFolders)
            }
            layoutManager = LinearLayoutManager(this@MainActivity)
            addItemDecoration(ItemSpace(7,7,0))
        }
    }

    private fun InitMainList(): MainAdapter {
        val mainAdapter = MainAdapter(this@MainActivity){ name->
            startActivity(Intent(this@MainActivity, CategoryListActivity::class.java).apply {
                putExtra(CategoryListActivity.IntentKey_Title,name)
            })
        }

        return mainAdapter
    }


}