package MpmasStataLabelsU;

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

sub filename {
	return "StataLabelsU";
}

sub write {
	my $self = shift;
	print "\e[K \r";
	print "Writing STATA Activity label file...\r";
	open(my $alabout, ">",  $self->outdir.$self->mname."_u_labels.do") or die "Can't open ".$self->outdir.$self->mname."_u_labels.do: $!";
	print $alabout <<HD_ALABEL;
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_ALABEL
			
			print $alabout "\n";
			for my $i ($self->sorted_activities) {
				my $k = $self->activity($i);
				my $col = $k->lp_column + 15;
				my $name = $k->get_attribute("name");
				$name =~ s/"//g;
				print $alabout "label var v". $col . " \"".$name."\"\n" if (not (lc($k->attr("type")) eq "maszero" or lc($k->attr("type")) eq "masfuture" or lc($k->attr("type")) eq "masxc_inc_trans"));
			}
			close $alabout;
}
1;
