package view;

import javax.swing.*;
import java.awt.*;

public class ChangePasswordView extends JDialog {
    private final JPasswordField oldPasswordField = new JPasswordField(20);
    private final JPasswordField newPasswordField = new JPasswordField(20);
    private final JPasswordField confirmPasswordField = new JPasswordField(20);
    private final JButton confirmButton = new JButton("确认修改");
    private final JButton cancelButton = new JButton("取消");

    public ChangePasswordView(Frame owner) {
        super(owner, "修改密码", true);
        setSize(450, 300);
        setLocationRelativeTo(owner);
        setLayout(new BorderLayout(10, 10));

        JPanel fieldsPanel = new JPanel(new GridBagLayout());
        fieldsPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 5, 5);
        gbc.fill = GridBagConstraints.HORIZONTAL;

        JLabel hintLabel = new JLabel("新密码要求: 6-10位，且必须包含大小写字母和数字。");
        hintLabel.setForeground(Color.GRAY);
        gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 2; fieldsPanel.add(hintLabel, gbc);

        gbc.gridwidth = 1;
        gbc.gridx = 0; gbc.gridy = 1; fieldsPanel.add(new JLabel("原密码:"), gbc);
        gbc.gridx = 1; gbc.gridy = 1; fieldsPanel.add(oldPasswordField, gbc);
        gbc.gridx = 0; gbc.gridy = 2; fieldsPanel.add(new JLabel("新密码:"), gbc);
        gbc.gridx = 1; gbc.gridy = 2; fieldsPanel.add(newPasswordField, gbc);
        gbc.gridx = 0; gbc.gridy = 3; fieldsPanel.add(new JLabel("确认新密码:"), gbc);
        gbc.gridx = 1; gbc.gridy = 3; fieldsPanel.add(confirmPasswordField, gbc);

        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 0));
        buttonPanel.add(confirmButton);
        buttonPanel.add(cancelButton);

        add(fieldsPanel, BorderLayout.CENTER);
        add(buttonPanel, BorderLayout.SOUTH);
    }

    public String getOldPassword() { return new String(oldPasswordField.getPassword()); }
    public String getNewPassword() { return new String(newPasswordField.getPassword()); }
    public String getConfirmPassword() { return new String(confirmPasswordField.getPassword()); }
    public JButton getConfirmButton() { return confirmButton; }
    public JButton getCancelButton() { return cancelButton; }
}