# -*- coding: utf-8 -*-
import configparser

# Form implementation generated from reading ui file 'gui/designer/data.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets

from stark import parse_args, read_configs, run


def create_default_configs():
    configs = {}
    # mandatory parameters
    configs['input'] = 'data/sl_ssj-ud_v2.4.conllu'
    configs['input_path'] = 'data/sl_ssj-ud_v2.4.conllu'
    configs['output'] = 'results/out_official.tsv'
    configs['tree_size'] = '2-4'
    configs['node_type'] = 'upos'

    # mandatory parameters with default value
    configs['internal_saves'] = './internal_saves'
    configs['cpu_cores'] = 12
    configs['complete_tree_type'] = True
    configs['dependency_type'] = True
    configs['node_order'] = True
    configs['association_measures'] = False

    configs['label_whitelist'] = []
    configs['root_whitelist'] = []

    configs['query'] = None

    configs['compare'] = None

    configs['frequency_threshold'] = 0
    configs['lines_threshold'] = None

    configs['continuation_processing'] = False

    configs['nodes_number'] = True
    configs['print_root'] = True

    if configs['compare'] is not None:
        configs['other_input_path'] = configs['compare']
    return configs


class Ui_STARK(object):
    def setupUi(self, STARK):
        self.fixed = True

        STARK.setObjectName("STARK")
        STARK.resize(800, 600)
        self.buttonBox = QtWidgets.QDialogButtonBox(STARK)
        self.buttonBox.setGeometry(QtCore.QRect(430, 540, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.formLayoutWidget = QtWidgets.QWidget(STARK)
        self.formLayoutWidget.setGeometry(QtCore.QRect(30, 30, 741, 481))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
        self.formLayout.setContentsMargins(0, 0, 0, 0)
        self.formLayout.setObjectName("formLayout")
        self.label = QtWidgets.QLabel(self.formLayoutWidget)
        self.label.setObjectName("label")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label)
        self.textEdit = QtWidgets.QTextEdit(self.formLayoutWidget)
        self.textEdit.setObjectName("textEdit")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.textEdit)
        self.label_2 = QtWidgets.QLabel(self.formLayoutWidget)
        self.label_2.setObjectName("label_2")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_2)
        self.textEdit_2 = QtWidgets.QTextEdit(self.formLayoutWidget)
        self.textEdit_2.setObjectName("textEdit_2")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.textEdit_2)
        self.label_3 = QtWidgets.QLabel(self.formLayoutWidget)
        self.label_3.setObjectName("label_3")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_3)
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.radioButton = QtWidgets.QRadioButton(self.formLayoutWidget)
        self.radioButton.setObjectName("radioButton")
        self.radioButton.setChecked(True)
        self.radioButton.clicked.connect(self.fixed_click_on)
        self.verticalLayout.addWidget(self.radioButton)
        self.radioButton_2 = QtWidgets.QRadioButton(self.formLayoutWidget)
        self.radioButton_2.setObjectName("radioButton_2")
        self.radioButton_2.clicked.connect(self.fixed_click_off)
        self.verticalLayout.addWidget(self.radioButton_2)
        self.formLayout.setLayout(2, QtWidgets.QFormLayout.FieldRole, self.verticalLayout)
        self.label_4 = QtWidgets.QLabel(self.formLayoutWidget)
        self.label_4.setObjectName("label_4")
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_4)

        self.retranslateUi(STARK)
        self.buttonBox.accepted.connect(self.process)
        #self.buttonBox.rejected.connect(self.process)
        self.buttonBox.rejected.connect(STARK.reject)
        QtCore.QMetaObject.connectSlotsByName(STARK)

    def fixed_click_on(self):
        self.fixed = True

    def fixed_click_off(self):
        self.fixed = False

    def retranslateUi(self, STARK):
        _translate = QtCore.QCoreApplication.translate
        STARK.setWindowTitle(_translate("STARK", "Dialog"))
        self.label.setText(_translate("STARK", "Input"))
        self.label_2.setText(_translate("STARK", "Output"))
        self.label_3.setText(_translate("STARK", "Fixed"))
        self.radioButton.setText(_translate("STARK", "Yes"))
        self.radioButton_2.setText(_translate("STARK", "No"))

    def process(self):
        config = configparser.ConfigParser()
        config.read('config.ini')

        #configs = read_configs(config, args)
        configs = create_default_configs()

        input_path = self.textEdit.toPlainText()
        output_path = self.textEdit_2.toPlainText()

        fixed = self.fixed

        configs['input'] = configs['input'] if not input_path else input_path
        configs['input_path'] = configs['input_path'] if not input_path else input_path
        configs['output'] = configs['output'] if not output_path else output_path
        configs['node_order'] = configs['node_order'] if not fixed else fixed

        run(configs)
        print('DONE!')


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    STARK = QtWidgets.QDialog()
    ui = Ui_STARK()
    ui.setupUi(STARK)
    STARK.show()
    sys.exit(app.exec_())