package com.example.punyaria;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.NonNull;

public class GenderDialog extends Dialog {

    private Context context;
    private GenderDialogListener listener;

    public GenderDialog(@NonNull Context context, GenderDialogListener listener) {
        super(context);
        this.context = context;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_gender);

        ListView genderListView = findViewById(R.id.genderListView);
        String[] genders = {"Laki-laki", "Perempuan"};
        ArrayAdapter<String> adapter = new ArrayAdapter<>(context, R.layout.list_item_gender, genders);
        genderListView.setAdapter(adapter);

        genderListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // Ketika item di ListView dipilih, ambil nilai jenis kelamin dan kirimkan ke listener
                String selectedGender = genders[position];
                listener.onGenderSelected(selectedGender);
                dismiss(); // Tutup dialog setelah memilih
            }
        });
    }

    // Interface untuk menangani pemilihan jenis kelamin
    public interface GenderDialogListener {
        void onGenderSelected(String gender);
    }
}
