package com.example.myapplication.ui.shop.search

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import com.example.myapplication.R

class SearchResultFragment : Fragment() {

    private lateinit var etInput: EditText

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_search_result, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        // 返回按钮
        view.findViewById<FrameLayout>(R.id.iv_close).setOnClickListener {
            parentFragmentManager.popBackStack()
        }

        etInput = view.findViewById(R.id.et_input)

        // ⭐ 接收从上一个页面传来的搜索词
        val keyword = arguments?.getString("search_keyword") ?: ""
        etInput.setText(keyword)
        // etInput.setSelection(keyword.length) // 光标移动到最后
    }
}
