package _VisualDVM.GlobalData.User.UI;
import Common.Utils.Utils_;
import Common.Visual.Menus.TextEditorMenu;
import Common.Visual.TextField.StyledPasswordField;
import Common.Visual.TextField.StyledTextField;
import Common.Visual.Windows.Dialog.DialogFields;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class UserFields implements DialogFields {
    public JPanel content;
    public JTextField tfLogin;
    public JTabbedPane AuthenticationTabs;
    public JPanel PasswordTab;
    public JPasswordField tfPassword;
    public JTextField tfWorkspace;
    public JTextField tfRoot;
    public JButton bBrowse;
    char mask;
    char unmask = (char) 0;
    boolean password_visible = false;
    private JButton bPasswordVisibility;
    public UserFields() {
        mask = tfPassword.getEchoChar();
        bPasswordVisibility.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                password_visible = !password_visible;
                tfPassword.setEchoChar(password_visible ? unmask : mask);
                bPasswordVisibility.setIcon(Utils_.getIcon("/icons/" + (password_visible ? "Show" : "Hide") + "Password.png"));
            }
        });
        /*
        bBrowse.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String dst;
                if (Global.mainModule.getPass(PassCode.SelectRemoteFile).Do(true)) {
                    String root= Global.mainModule.getRemoteFile().full_name;
                    tfRoot.setText(root);
                    if (!tfWorkspace.getText().isEmpty()){
                        RemoteFile workspace=new RemoteFile(tfWorkspace.getText(), true);
                        tfWorkspace.setText(root+"/"+workspace.name);
                    }
                }
            }
        });
         */
    }
    @Override
    public Component getContent() {
        return content;
    }
    private void createUIComponents() {
        // TODO: place custom component creation code here
        tfLogin = new StyledTextField();
        tfPassword = new StyledPasswordField();
        tfPassword.setComponentPopupMenu(new TextEditorMenu(tfPassword));
        tfWorkspace = new StyledTextField();
    }
}
