package com.philisense.rdgo.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.philisense.rdgo.R;
import com.unnamed.b.atv.model.TreeNode;

/**
 * Created by shaop on 2017/12/18.
 */

public class OrderBoxViewHolder extends TreeNode.BaseNodeViewHolder<OrderBoxViewHolder.OrderBox> {

    private OrderBox data;
    private DeleteListenner listenner;

    public void setListenner(DeleteListenner listenner) {
        this.listenner = listenner;
    }

    public OrderBoxViewHolder(Context context) {
        super(context);
    }

    @Override
    public View createNodeView(TreeNode node, OrderBox value) {
        data = value;
        final LayoutInflater inflater = LayoutInflater.from(context);
        final View view = inflater.inflate(R.layout.item_put_in_order_oil, null, false);

        TextView IdTextView = view.findViewById(R.id.put_in_order_box_title);
        TextView InfoTextView = view.findViewById(R.id.put_in_order_box_subtitle);
        ImageButton deleteButton = view.findViewById(R.id.put_in_order_box_delete_button);

        // 如果是虚拟箱码，就显示删除按钮
        if (value.getBoxId().length() > 2) {
            if ("xn".equals(value.getBoxId().substring(0,2))) {
                deleteButton.setVisibility(View.VISIBLE);
            }else {
                deleteButton.setVisibility(View.GONE);
            }
        }

        deleteButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listenner.deleteAction(data.boxId);
            }
        });

        IdTextView.setText("编号："+value.getBoxId());
        InfoTextView.setText("产线："+value.getBoxInfo());

        return view;
    }

    public OrderBox getData() {
        return data;
    }

    public interface DeleteListenner {
        public void deleteAction(String boxId);
    }

    public static class OrderBox {
        private String boxId;
        private String outPutBoxId;
        private String pileId;
        private String boxInfo;

        public OrderBox(String boxId, String pileId, String boxInfo, String outPutBoxId) {
            this.boxId = boxId;
            this.pileId = pileId;
            this.boxInfo = boxInfo;
            this.outPutBoxId = outPutBoxId;
        }

        public String getOutPutBoxId() {
            return outPutBoxId;
        }

        public void setOutPutBoxId(String outPutBoxId) {
            this.outPutBoxId = outPutBoxId;
        }

        public String getPileId() {
            return pileId;
        }

        public void setPileId(String pileId) {
            this.pileId = pileId;
        }

        public String getBoxId() {
            return boxId;
        }

        public void setBoxId(String boxId) {
            this.boxId = boxId;
        }

        public String getBoxInfo() {
            return boxInfo;
        }

        public void setBoxInfo(String boxInfo) {
            this.boxInfo = boxInfo;
        }
    }
}
