using Newtonsoft.Json.Linq;
using PTMedicalInsurance.FormSetter;
using PTMedicalInsurance.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PTMedicalInsurance.Forms
{
    public partial class PreAndInProcessAnalysisForm : Form
    {
        private DataTable dtVolaItems;
        private DataTable dtVolaDetail;

        private GridViewSetter grdSetter = new GridViewSetter();
        private JArray jaVolaItems;
        public PreAndInProcessAnalysisForm()
        {
            InitializeComponent();
        }

        public PreAndInProcessAnalysisForm(JObject jo)
        {
            InitializeComponent();
            jaVolaItems = JArray.Parse(JsonHelper.getDestValue(jo, "output.result"));
            dtVolaItems = (DataTable)jo["output"]["result"].ToObject(typeof(DataTable));
            dgvVolaItems.DataSource = dtVolaItems;
            grdSetter.SetHeaderTextOfPAIPAVolaItem(dgvVolaItems);
            //tbJrID.Text = JsonHelper.getDestValue(jo, "output.result[0].jr_id");
            //tbRuleID.Text = JsonHelper.getDestValue(jo, "output.result[0].rule_id");
            //tbPatID.Text = JsonHelper.getDestValue(jo, "output.result[0].patn_id");
            //tbMdtrdID.Text = JsonHelper.getDestValue(jo, "output.result[0].mdtrt_id");
            //tbVolaAmt.Text = JsonHelper.getDestValue(jo, "output.result[0].vola_amt");
            //tbVolaAmtStas.Text = JsonHelper.getDestValue(jo, "output.result[0].vola_amt_stas");
            //tbSevDeg.Text = JsonHelper.getDestValue(jo, "output.result[0].sev_deg");
            //tbVolaBhvrType.Text = JsonHelper.getDestValue(jo, "output.result[0].vola_bhvr_type");
            //tbVolaEvid.Text = JsonHelper.getDestValue(jo, "output.result[0].vola_evid");
            //tbRuleName.Text = JsonHelper.getDestValue(jo, "output.result[0].rule_name");
            //rbtVolaContent.Text = JsonHelper.getDestValue(jo, "output.result[0].vola_cont");
        }

        private void showVolaItemContent(JObject jo)
        {
            tbJrID.Text = JsonHelper.getDestValue(jo, "jr_id");
            tbRuleID.Text = JsonHelper.getDestValue(jo, "rule_id");
            tbPatID.Text = JsonHelper.getDestValue(jo, "patn_id");
            tbMdtrdID.Text = JsonHelper.getDestValue(jo, "mdtrt_id");
            tbVolaAmt.Text = JsonHelper.getDestValue(jo, "vola_amt");
            tbVolaAmtStas.Text = JsonHelper.getDestValue(jo, "vola_amt_stas");
            tbSevDeg.Text = JsonHelper.getDestValue(jo, "sev_deg");
            tbVolaBhvrType.Text = JsonHelper.getDestValue(jo, "vola_bhvr_type");
            tbVolaEvid.Text = JsonHelper.getDestValue(jo, "vola_evid");
            tbRuleName.Text = JsonHelper.getDestValue(jo, "rule_name");
            rbtVolaContent.Text = JsonHelper.getDestValue(jo, "vola_cont");
            dtVolaDetail = (DataTable)jo["judge_result_detail_dtos"].ToObject(typeof(DataTable));
            dgvVolaDetailDtos.DataSource = dtVolaDetail;
            grdSetter.SetHeaderTextOfPAIPAVolaDetailDtos(dgvVolaDetailDtos);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void dgvVolaItems_SelectionChanged(object sender, EventArgs e)
        {
            int i = dgvVolaItems.CurrentRow.Index;
            showVolaItemContent((JObject)jaVolaItems[i]);
        }

        private void dgvVolaItems_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void uiRichTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void uiDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
