using System;
using FastReport.Dialog;
using static FastReport.Web.Constants;

namespace FastReport.Web
{
    public partial class Dialog
    {
        private void CheckBoxClick(CheckBoxControl cb, string data)
        {
            bool oldValue = cb.Checked;
            cb.Checked = data == "true";
            cb.FilterData();
            cb.OnClick(null);
            if (oldValue != cb.Checked)
                cb.OnCheckedChanged(EventArgs.Empty);
        }

        private string GetCheckBoxHtml(CheckBoxControl control)
        {
            string id = GetControlID(control);
            string html = $"<span style=\"{GetCheckBoxStyle(control)}\">" +
                $"<input style=\"vertical-align:middle;padding:0;margin:0 5px 0 0;\"" +
                $" type=\"checkbox\" name=\"{control.Name}\" value=\"{control.Text}\"" +
                $" onclick=\"{GetEvent(ONCLICK, control, DIALOG, $"document.getElementById('{id}').checked")}\"" +
                $" id=\"{id}\" {(control.Checked ? "checked" : "")} {(control.Enabled ? "" : "disabled")}/>" +
                $"<label style=\"{GetControlFont(control.Font)}\" for=\"{id}\">{control.Text}</label></span>";
            return html;
        }

        private string GetCheckBoxStyle(CheckBoxControl control)
        {
            return GetStandardStyle(control);
        }
    }
}
