package kr.co.hanwha.hifive.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.data.model.ProjectCounterMeasuresInfo;

/**
 * Created by sanghoonkwon on 2018. 2. 23..
 */

public class HFProjectIssueView extends LinearLayout {
    private TextView mTextViewName;
    private TextView mTextViewIssue;
    private String mText = "";

    public HFProjectIssueView(Context context) {
        super(context);
        initialize(context, null);
    }

    public HFProjectIssueView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initialize(context, attrs);
    }

    public HFProjectIssueView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initialize(context, attrs);
    }

    private void initialize(Context context, @Nullable AttributeSet attrs) {
        if (isInEditMode()) return;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_hf_project_issue, this, true);

        mTextViewName = (TextView) findViewById(R.id.name_textView);
        mTextViewIssue = (TextView) findViewById(R.id.issue_textView);
    }

    public void setIssue(ProjectCounterMeasuresInfo info) {
        if (info == null) return;

        if (TextUtils.isEmpty(info.getName()) || info.getStatus() == 5400) {
            mTextViewName.setVisibility(View.GONE);
            mTextViewName.setText("");
        } else {
            mTextViewName.setVisibility(View.VISIBLE);
            mTextViewName.setText("[" + info.getName() + "]");
        }


        mTextViewIssue.setText(TextUtils.isEmpty(info.getIssue()) ? "" : info.getIssue());
    }

    public void setMessage(String message) {
        if (TextUtils.isEmpty(message)) return;

        mTextViewName.setVisibility(View.GONE);
        mTextViewIssue.setText(message);
    }
}
