package edu.school.hairdressing;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.BevelBorder;
import java.awt.Color;
import javax.swing.JRadioButton;
import java.awt.SystemColor;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ButtonGroup;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import javax.swing.SwingConstants;
	/**
	 * Информатика, 8 клас, издателство Просвета, 2017
	 * Автори: Светла Бойчева, Николина Николова, Елиза Стефанова, Антон Денев
	 * 3.3.2. Условен оператор
	 * Урок: Условен оператор – упражнение
	 * Задача: RxC001 помага във фризьорски салон, но има затруднение при пресмятане
	 * стойността на услугата. Направете приложение HairDressingSalon, което по зададени
	 * желания на клиента, пресмята стойността на услугата, ако има следните опции:
	 *  • дамско/мъжко подстригване;
	 *  • боядисване на коса;
	 *  • измиване на косата с шампоан и балсам;
	 *  • подсушаване на косата със сешоар;
	 * При пресмятане на крайната цена, допълнително се взема предвид и разхода на
	 * консумативи според дължината на косата.
	 *  
	 * Вариант 1.
	 */
public class HairDressingFrame extends JFrame {

	
	private JPanel contentPane;
	private JLabel lblPrice;
	private JButton btnCalc;
	private JCheckBox chkHairColoring;
	private JCheckBox chkHairWash;
	private JCheckBox chkHairDrying;
	private JRadioButton rbWomanHaircut;
	private JRadioButton rbManHaircut;
	private JRadioButton rbLongHair;
	private JRadioButton rbShortHair;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private final ButtonGroup buttonGroup_1 = new ButtonGroup();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					HairDressingFrame frame = new HairDressingFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public HairDressingFrame() {
		setTitle("\u0424\u0440\u0438\u0437\u044C\u043E\u0440\u0441\u043A\u0438 \u0441\u0430\u043B\u043E\u043D");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 254);
		contentPane = new JPanel();
		contentPane.setForeground(new Color(0, 0, 0));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JPanel panelHaircut = new JPanel();
		panelHaircut.setBackground(SystemColor.controlHighlight);
		panelHaircut.setForeground(Color.BLACK);
		panelHaircut.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u041F\u043E\u0434\u0441\u0442\u0440\u0438\u0433\u0432\u0430\u043D\u0435", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		panelHaircut.setToolTipText("");
		panelHaircut.setBounds(10, 17, 270, 56);
		contentPane.add(panelHaircut);

		rbManHaircut = new JRadioButton("\u041C\u044A\u0436\u043A\u043E");
		buttonGroup.add(rbManHaircut);
		rbManHaircut.setFont(new Font("Tahoma", Font.PLAIN, 14));
		rbManHaircut.setBackground(SystemColor.controlHighlight);
		panelHaircut.add(rbManHaircut);
		
				rbWomanHaircut = new JRadioButton("\u0414\u0430\u043C\u0441\u043A\u043E");
				rbWomanHaircut.setSelected(true);
				buttonGroup.add(rbWomanHaircut);
				rbWomanHaircut.setFont(new Font("Tahoma", Font.PLAIN, 14));
				rbWomanHaircut.setBackground(SystemColor.controlHighlight);
				panelHaircut.add(rbWomanHaircut);

		JPanel panelLength = new JPanel();
		panelLength.setToolTipText("");
		panelLength.setForeground(Color.BLACK);
		panelLength.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u0414\u044A\u043B\u0436\u0438\u043D\u0430 \u043D\u0430 \u043A\u043E\u0441\u0430\u0442\u0430", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		panelLength.setBackground(SystemColor.controlHighlight);
		panelLength.setBounds(10, 84, 270, 56);
		contentPane.add(panelLength);

		rbLongHair = new JRadioButton("\u0414\u044A\u043B\u0433\u0430");
		buttonGroup_1.add(rbLongHair);
		rbLongHair.setFont(new Font("Tahoma", Font.PLAIN, 14));
		rbLongHair.setBackground(SystemColor.controlHighlight);
		panelLength.add(rbLongHair);

		rbShortHair = new JRadioButton("\u041A\u044A\u0441\u0430");
		rbShortHair.setSelected(true);
		buttonGroup_1.add(rbShortHair);
		rbShortHair.setFont(new Font("Tahoma", Font.PLAIN, 14));
		rbShortHair.setBackground(SystemColor.controlHighlight);
		panelLength.add(rbShortHair);

		chkHairWash = new JCheckBox("\u0418\u0437\u043C\u0438\u0432\u0430\u043D\u0435");
		chkHairWash.setFont(new Font("Tahoma", Font.PLAIN, 14));
		chkHairWash.setBounds(306, 67, 124, 23);
		contentPane.add(chkHairWash);

		chkHairColoring = new JCheckBox("\u0411\u043E\u044F\u0434\u0438\u0441\u0432\u0430\u043D\u0435");
		chkHairColoring.setFont(new Font("Tahoma", Font.PLAIN, 14));
		chkHairColoring.setBounds(306, 17, 124, 23);
		contentPane.add(chkHairColoring);

		chkHairDrying = new JCheckBox("\u0421\u0443\u0448\u0435\u043D\u0435");
		chkHairDrying.setFont(new Font("Tahoma", Font.PLAIN, 14));
		chkHairDrying.setBounds(306, 117, 124, 23);
		contentPane.add(chkHairDrying);

		btnCalc = new JButton("\u041F\u0440\u0435\u0441\u043C\u0435\u0442\u043D\u0438");
		btnCalc.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				//константи от реален тип за единичните цени 
				// за всяка услуга, която предлага фризьорския салон
				final double MAN_HAIRCUT = 5.50;
				final double WOMEN_HAIRCUT = 7.20;
				final double HAIR_COLORING = 7.00;
				final double HAIR_WASH = 2.30;
				final double HAIR_DRYING = 1.75;

				// инициализация на цената на услугата
				double price = 0.0;
				
				// обработка на полетата за отметка
				// за боядисване, измиване и сушене
				if (chkHairWash.isSelected())
					price += HAIR_WASH;
				
				if (chkHairColoring.isSelected())
					price += HAIR_COLORING;
				
				if (chkHairDrying.isSelected())
					price += HAIR_DRYING;
				
				
				// обработка на радио-бутоните 
				// за дължина на косата и тип подстригване (мъжко-дамско)
				if (rbLongHair.isSelected())
				{
					price *=2;
				}
				
				if (rbManHaircut.isSelected()) {
					price += MAN_HAIRCUT;
				} else {
					price += WOMEN_HAIRCUT;
				}
				
				// форматиране и извеждане на цената на услугата
				String result = 
					 String.format("Цена: %.2f лв.", price);
		    	lblPrice.setText(result);
			}
		});
		btnCalc.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnCalc.setBounds(306, 164, 124, 40);
		contentPane.add(btnCalc);

		lblPrice = new JLabel("\u0426\u0435\u043D\u0430:");
		lblPrice.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblPrice.setBounds(10, 164, 270, 40);
		contentPane.add(lblPrice);
	}
}
