package analyse;

import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.Scanner;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Match;
import org.sikuli.script.Screen;

import gui.Produkteingabe;

public class Analyse {

    private final String ORDNER = "bilder/";
    private Screen s;

    @SuppressWarnings("resource")
    public void zeigeDetails(String dateiname) {
        System.out.println("suche: " + dateiname);
        try {
            Iterator<Match> it = s.findAll(dateiname);
            while (it.hasNext()) {
                Match m = it.next();
                System.out.println(dateiname + " mit " + m.getScore());
                m.highlight(4);
            }
            System.out.println("<Return> zum nächsten Bild");
            new Scanner(System.in).nextLine();
        } catch (FindFailed e) {
            System.out.println(dateiname + " nicht gefunden.");
        }
    }

    public void alle() {
//      App app = App.open("javaw -jar tarifrechner.jar");
        main.Main.main(null); // neu
        s = new Screen();
        Path dir = Paths.get(ORDNER);
        try (DirectoryStream<Path> stream = Files
                .newDirectoryStream(dir, "*.*")) {
            for (Path entry : stream) {
                zeigeDetails(entry.toString());
            }
        } catch (Exception e) {
            System.out.println(e);
        }
//        app.close();
        System.exit(0); // neu
    }

    public void eines(String name) {
        zeigeDetails(ORDNER + name + ".png");
    }

    public static void main(String[] args) {
      new Produkteingabe();
      new Analyse().alle();
    }
}
