package kz.arta.synergy.workflow.mobile.android.forms.mobile.components;

import android.content.Context;
import android.widget.LinearLayout;

import kz.arta.synergy.workflow.mobile.android.common.components.ATitle;
import kz.arta.synergy.workflow.mobile.android.common.utils.Wrapper;
import kz.arta.synergy.workflow.mobile.android.forms.mobile.FormConstants;

/**
 * Created by neox on 30.06.15.
 * Компонент "Неизменяемый текст"
 */
public class FormLabel extends LinearLayout implements IMobileComponents {

    /**
     * Текущий заголовок
     */
    private ATitle title;

    /**
     * Идентификатор компонента
     */
    private String id;

    /**
     * Тип компонента
     */
    private String type;

    public FormLabel(Context context) {
        super(context);
        init();
    }

    private void init() {
        setOrientation(LinearLayout.VERTICAL);
        setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        LayoutParams titleParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        titleParams.setMargins(FormConstants.MARGINS, FormConstants.MARGINS, FormConstants.MARGINS, FormConstants.MARGINS);
        title = new ATitle(getContext());
        title.setLayoutParams(titleParams);
        addView(title);
    }

    @Override
    public String getValue() {
        return title.getText().toString();
    }

    @Override
    public void setValue(String value) {
    }

    @Override
    public String getID() {
        return id;
    }

    @Override
    public String getJson() {
        return "{" +
                Wrapper.getItem("type", getType()) + "," +
                Wrapper.getItem("id", getID()) + "," +
                Wrapper.getItem("value", getValue())
                + "}";
    }

    @Override
    public void enabled(boolean enabled) {
        setEnabled(enabled);
    }

    @Override
    public void setRequired(String required) {

    }

    @Override
    public void setLabel(String label) {
        title.setText(label);
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String getType() {
        return type;
    }

    @Override
    public void setType(String type) {
        this.type = type;
    }
}
