package com.ycgis.macall.personalcenter.v.adapter;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.rs.macall.androidx.basemodel.base.BaseRecyclerAdapter;
import com.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.m.adapterbean.BluetoothOV;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * created by:   Macall
 * create time:  2025/5/29 16:38
 * copyright:    @ruansee.com
 * Describe:
 */
public class BluetoothListAdapter extends BaseRecyclerAdapter<BluetoothDevice ,BaseRecyclerAdapter.ViewHolder> {

    public BluetoothListAdapter(Context context, List<BluetoothDevice> dataList) {
        super(context, dataList);
    }

    @NonNull
    @NotNull
    @Override
    public BaseRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_bluetooth_list, parent, false);
        return new SimpleViewHolder(inflate).findViewById(R.id.bluetooth_name).findViewById(R.id.bluetooth_mac).findViewById(R.id.bluetooth_status);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull @NotNull BaseRecyclerAdapter.ViewHolder viewHolder, int position) {
        BluetoothDevice dataItem = getDataItem(position);
        if (viewHolder instanceof BaseRecyclerAdapter.SimpleViewHolder){
            SimpleViewHolder holder =(SimpleViewHolder)viewHolder;
            TextView name = holder.getView(R.id.bluetooth_name, TextView.class);
            TextView address = holder.getView(R.id.bluetooth_mac, TextView.class);
            TextView status = holder.getView(R.id.bluetooth_status, TextView.class);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                name.setText(dataItem.getAlias());
            } else {
                name.setText(dataItem.getName());
            }
            address.setText(dataItem.getAddress());
            status.setText(getStatusStr(dataItem.getBondState())+"  "+ getTypeStr(dataItem.getType()) );
        }
    }


    public String getStatusStr(int status) {
        if (status == 11) {
            return "正在配对";
        }
        if (status == 12) {
            return "已配对";
        }
        return "未配对";
    }

    public String getTypeStr(int type) {
        switch (type) {
            case 1:

                return "BR/EDR";
            case 2:

                return "LE-only";
            case 3:

                return "BR/EDR/LE";
            case 0:
            default:

                return "未知";
        }
    }
}
