/*
 * Copyright (C) 2013 Snowsun <http://wyrez.org> and contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.wyrez.shootingstars.gui;

import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f;
import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.listener.YTDownloadListener;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.text.Label;
import tonegod.gui.controls.text.TextField;
import tonegod.gui.controls.windows.Panel;
import tonegod.gui.core.Screen;

/**
 *
 * @author Snowsun
 */
public class YTDownloadGUI extends Panel implements Gui{

    private YTDownloadListener listener;
    
    public YTDownloadGUI(Screen screen, YTDownloadListener listener) {
        super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
        this.listener = listener;
        this.setIgnoreMouse(true);
        this.setIsVisible(false);
        create();
    }
    
    private void create() {
        float startPointx = 384f;//screen.getWidth() * 0.3f;
        float startPointy = 324f;//screen.getHeight() * 0.45f;
        float labelFontSize = 51.2f;//screen.getWidth() * 0.04f;
        float buttonWidth = 153f;//screen.getWidth() * 0.12f;
        float textFieldWitdh = 409f;//screen.getWidth() * 0.32f;
        float marginTextFieldLeft = 153f;
        float marginTextFieldTop = 8.64f;
        float marginYTButtonLeft = 409f;
        float marginYTButtonTop = 72f;
        
        
        Label lblYTLink = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(160, 40));
        lblYTLink.setFontSize(labelFontSize);
        lblYTLink.setText("YT Link");
        
        final TextField txtYTLink = new TextField(screen,"txtYTLink", new Vector2f(startPointx + marginTextFieldLeft, startPointy + marginTextFieldTop), new Vector2f(textFieldWitdh, 40));
        txtYTLink.setType(TextField.Type.DEFAULT);
        
        Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx + marginYTButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, 40)) {
            @Override
            public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
                listener.downloadYTVideo(txtYTLink.getText());
            }
        };
        btnYTDownload.setText("Download");
        
        this.addChild(lblYTLink);
        this.addChild(txtYTLink);
        this.addChild(btnYTDownload);
    }
    
    public void attach() {
        screen.addElement(this);
    }

    public void detach() {
        screen.removeElement(this);
    }

}
