package MpmasStataLabelsK;

use strict;
use warnings;
use Exporter;
use Storable qw(dclone);
use Data::Dumper;
use MpmasInputfile;
use MpmasInputBlock;
our @ISA = qw(MpmasInputfile);

sub filename {
	return "StataLabelsK";
}

sub write {
	my $self = shift;
	print "\e[K \r";
	print "Writing STATA Constraint label file...\r";
	open(my $klabout, ">",  $self->outdir.$self->mname."_k_labels.do") or die "Can't open ". $self->outdir.$self->mname."_k_labels.do $!";
	print $klabout <<HD_KLABEL;
label var v1 "typ_str"
label var v2 "aID"
label var v3 "catchID"
label var v4 "secID"
label var v5 "fstID"
label var v6 "popID"
label var v7 "clustID"
label var v8 "nwID"
label var v9 "segID"
label var v10 "expectID"
label var v11 "colorID"
label var v12 "xcoord"
label var v13 "ycoord"
label var v14 "numplots"
HD_KLABEL
	for my $i ($self->sorted_constraints) {
		my $k = $self->constraint($i);
		my $col = $k->lp_row + 15;
		my $name = $k->get_attribute("name");
		$name =~s/"//g;
		print $klabout "label var v". $col . " \"".$name."\"\n" if (not (lc($k->attr("type")) eq "maszero" or lc($k->attr("type")) eq "masforget"));
	}
	close $klabout;

}

1;
