/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.ctecinf;

import br.com.ctecinf.nfe.SEFAZConnection;
import br.com.ctecinf.swing.Image;
import br.com.ctecinf.swing.OptionPane;
import br.com.ctecinf.swing.TabbedPane;
import br.com.ctecinf.theme.OlivaTheme;
import br.com.ctecinf.view.MenuBar;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author cassio
 */
public class Main {

    public static final String TITLE = "CTecInf Sistemas Gerenciais - ctecinf.com.br (PENDRIVE)";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

//        new Daruma();
        new OlivaTheme();

        Empresa.setBairro("NAVEGANTES");
        Empresa.setCep("95555000");
        Empresa.setCnpj("94166261000120");
        Empresa.setComplemento("LJ. 01");
        Empresa.setContadorCNPJ("");
        Empresa.setFone("5136654120");
        Empresa.setFreteId(9l);
        Empresa.setAliquota(35.49);
        Empresa.setCfopId(5102l);
        Empresa.setContadorEmail("asc.contabilidade@gmail.com");
        Empresa.setSerie(1);
        Empresa.setCscTokenHomo("8E40EAFA-A200-4853-9A8F-633AE9600FC2");
        Empresa.setCscTokenProd("B32C1BDE-94EE-4480-8E0F-EB8450E84CC7");
        Empresa.setIcmsId(102l);
        Empresa.setIcmsOrigemId(0l);
        Empresa.setInscEstadual("2340022791");
        Empresa.setLogradouro("AV. PARAGUASSU");
        Empresa.setMunicipio("CAPAO DA CANOA");
        Empresa.setMunicipioIBGE(4304630l);
        Empresa.setNatOperacao("VENDA DE MERCADORIA");
        Empresa.setNomeFantasia("OPTICA PERFORMANCE");
        Empresa.setNumero(2950);
        Empresa.setRazaoSocial("OPTICA PERFORMANCE LTDA");
        Empresa.setSenhaCertificado("1234");
        Empresa.setSlogan("A SERVICO DA BOA VISAO - DESDE 1991");
        Empresa.setUf("RS");
        Empresa.setUfIBGE(43);
        Empresa.setMensagem("");

        System.setProperty("nfe_tp_amb", "1");
        Config.set("nfe.amb", "1");
        Config.set("user.cnpj", Empresa.getCnpj().trim());
        
        new Thread(() -> {
            try {
                //new Server().addContext(new JSON()).addContext(new Save()).addContext(new XML()).start();
                SEFAZConnection.registrarConexao(true);
            } catch (Exception ex) {
                OptionPane.error(ex);
            }
        }).start();
        TabbedPane pane = new TabbedPane();

        JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
        p.add(new JLabel(Utils.getMyIP(), Image.parse(Image.DB, 16), JLabel.HORIZONTAL));

        JFrame frame = new JFrame(TITLE);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.setLayout(new BorderLayout());
        frame.add(new MenuBar(pane), BorderLayout.NORTH);
        frame.add(pane, BorderLayout.CENTER);
        frame.add(p, BorderLayout.SOUTH);

        frame.setSize(1024, 728);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

//        new Login() {
//
//            @Override
//            public void success() {
//
//                new Thread(() -> {
//                    try {
//                        new Server().addContext(new JSON()).addContext(new Save()).addContext(new XML()).start();
//                        SEFAZConnection.registrarConexao(true);
//                    } catch (Exception ex) {
//                        OptionPane.error(ex);
//                    }
//                }).start();
//                TabbedPane pane = new TabbedPane();
//
//                JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
//                p.add(new JLabel(Utils.getMyIP(), Image.parse(Image.DB, 16), JLabel.HORIZONTAL));
//
//                JFrame frame = new JFrame(TITLE);
//                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//
//                frame.setLayout(new BorderLayout());
//                frame.add(new MenuBar(pane), BorderLayout.NORTH);
//                frame.add(pane, BorderLayout.CENTER);
//                frame.add(p, BorderLayout.SOUTH);
//
//                frame.setSize(1024, 728);
//                frame.setLocationRelativeTo(null);
//                frame.setVisible(true);
//            }
//        }.init();
    }
}
