/*
 * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#include <QBuffer>
#include <QDebug>

#include <nostalgia/core/consts.hpp>
#include <nostalgia/core/gfx.hpp>

#include "consts.hpp"
#include "newpalettewizard.hpp"

namespace nostalgia::core {

NewPaletteWizardPage::NewPaletteWizardPage(const studio::Context *ctx) {
	m_ctx = ctx;
	addLineEdit(tr("&Palette Name:"), QString(PaletteName) + "*", "", [](QString) {
		return 0;
	});
}

int NewPaletteWizardPage::accept() {
	const auto paletteName = field(PaletteName).toString();
	const auto path = PaletteDir + paletteName + FileExt_npal;
	if (m_ctx->project->exists(path)) {
		showValidationError(tr("A palette with this name already exists."));
		return 1;
	}
	NostalgiaPalette pal;
	m_ctx->project->writeObj(path, &pal);
	return 0;
}

}
