package org.bdware.sc.contractGen;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;

import javax.swing.*;
import java.util.HashMap;
import java.util.Map;

public class MainFrame extends JPanel {
    final RSyntaxTextArea textfield;
    JLabel sdk_label;
    JLabel datalen_label;

    JPanel p1;
    JPanel p2;
    JButton generate;
    JButton reset;

    public MainFrame() {
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

        p1 = new JPanel();//面板OnBlock
        p2 = new JPanel();//面板OnBlock

        generate = new JButton("生成合约");
        reset = new JButton("重置内容");
        p2.add(generate);
        p2.add(reset);

        this.textfield = new RSyntaxTextArea(30, 80);//height,width
        textfield.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
        textfield.setCodeFoldingEnabled(true);

        JScrollPane scroll = new JScrollPane(textfield);
        scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

        p1.add(scroll);
        this.add(p1);
        this.add(p2);

        reset.addActionListener(arg0 -> {
            // TODO Auto-generated method stub
            textfield.setText("");
        });
        generate.addActionListener(e -> {
            // TODO Auto-generated method stub
            // use new file to generate yjs
            Map<String, String> map = new HashMap<>();
            map.put("indexData", "./RocksDB");
            String res = ContractGenerator.generateAPIContract(map);
        });
    }
}
