import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.ScrollPane;
import java.awt.event.ActionListener;
import java.math.BigInteger;
import java.net.URL;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

public class ShopItem extends JPanel {
    private JButton buyButton;
    private JLabel Item;
    private BigInteger Cost;

    private Color Black = new Color(0, 0, 0);
    private Color Grey = new Color(105, 106, 106);
    private Color White = new Color(255, 255, 255);
    private Color OxidizedBlue = new Color(63, 63, 116);

    private Border lineBorder = BorderFactory.createLineBorder(OxidizedBlue);

    public ShopItem(URL itemImageURL, String description, ActionListener SellListener, BigInteger Cost) {
        setLayout(new FlowLayout());
        setBackground(Grey);
        setBorder(lineBorder);
        JPanel holder = new JPanel();
        holder.setLayout(new BoxLayout(holder, BoxLayout.Y_AXIS));
        ScrollPane text = new ScrollPane();
        text.setSize(192, 60);
        JLabel des = new JLabel(description);
        text.add(des);
        this.Cost = Cost;
        this.buyButton = new JButton("Buy : $" + this.Cost);
        this.buyButton.setEnabled(true);

        this.buyButton.setBorder(lineBorder);
        this.buyButton.setBackground(Grey);
        this.buyButton.setForeground(White);
        this.buyButton.addActionListener(SellListener);

        holder.add(text);
        holder.add(Box.createRigidArea(new Dimension(0, 5)));
        holder.add(this.buyButton);
        ImageIcon item = new ImageIcon(itemImageURL);
        this.Item = new JLabel(item);

        add(this.Item);
        add(holder);

    }

    public javax.swing.JButton getBuyButton() {
        return this.buyButton;
    }

    public void Sold() {

        this.buyButton.setText("Sold Out");
        this.buyButton.setEnabled(false);
        this.buyButton.setBorder(lineBorder);
        this.buyButton.setBackground(Black);
        this.buyButton.setForeground(White);

    }

    public void NoMoney() {

        this.buyButton.setText("You need $" + this.Cost);
        this.buyButton.setEnabled(false);
        this.buyButton.setBorder(lineBorder);
        this.buyButton.setBackground(Black);
        this.buyButton.setForeground(White);

    }

    public void InStock() {

        this.buyButton.setText("Buy : $" + this.Cost);
        this.buyButton.setEnabled(true);

    }

    public BigInteger getPrice() {
        return this.Cost;
    }

}
