package controller.note;

import controller.Controller;
import org.sig.fw.db.corrida.model.Note;
import org.sig.fw.layout.pane.SOptionPane;
import view.note.Note_View;

public class Note_Controller extends Controller {
	
	private Notes_Controller ctrl_notes = null;
	private Note_View vw_note = null;
	private Note note = null;
	private boolean isLast = false;
	
	public Note_Controller(Notes_Controller ctrl_notes, Note note, boolean isLast) {
		super(ctrl_notes.getApplicationController());
		this.ctrl_notes = ctrl_notes;
		this.note = note;
		this.isLast = isLast;
		this.vw_note = new Note_View(this);
	}
	
	public String getText() {
		String text = this.note.getNote();
		text = text.replace("<br data-mce-bogus=\"1\">", "<br>");
		text = text.replace("<br>", "\n");
		text = text.replace("</p><p>", "\n");
		text = text.replace("<p>", "");
		text = text.replace("</p>", "");
		return text;
	}
	
	public Note getModel() {
		return this.note;
	}
	
	public Note_View getView() {
		return this.vw_note;
	}
	
	public boolean isLast() {
		return this.isLast;
	}
	
	public void clickUpdateNote() {
		this.ctrl_notes.setUpdateNote(this.note);
	}
	
	public void clickDeleteNote() {
		if(SOptionPane.YES_OPTION == SOptionPane.showYesNoCancelWarning("Note", "Voulez-vous vraiment supprimer cette note ?")) {
			this.ctrl_notes.deleteNote(this.note);
		}
	}
	
}
