<% use ui::cmn; my ($prj,$outdir,$type,$cfgref) = @_;  
my $props_prefix = $type eq 'installer' ?  "createexe_" : 'create_copier_exe_';
my $is_copier = $type ne 'installer';

if (!length($prj->{outdir_cooked}))
{
    $prj->{outdir_cooked} = $outdir;
    my $tmp = substr($outdir,-1);
    $prj->{outdir_cooked} .= '/' if(! ($tmp eq '/' || $tmp eq '\\')); #append path separator
    $prj->{outdir_cooked} .= '..';

}
sub exe_get_prop
{
    my($prj,$props_prefix,$key,$label,$defval,$widthclass) = @_;
    my $fullkey = $props_prefix . $key;
    my $prevval = $prj->{opts}->{$fullkey};
#    print "<tr><td>$label $tip{$fullkey} </td><td><input name=$fullkey required value=\"" .
#	(length($prevval) ? $prevval : $defval)
#	. "\"></td>\n";
%>
    	    <div class="<%= $widthclass %> wide field required">
		<label><i class="ui NOicon file outline"></i>
		    <%$ $label . tooltip($fullkey)  %></label>
		<div class="ui input">
		    <input required name="<%= $fullkey %>"   value="<%= (length($prevval) ? $prevval : $defval) %>" 
		     type="text">
		</div>
	    </div>
<%
}

sub quoteslashes
{
    my($s) = @_;
    $s =~ s,\\,\\\\,g;
    $s;
}

my $title = $is_copier ? __('Creating utility to install product to hard disk') :  __('Creating Windows Installer');
%>


<% $forge->include('wgt-load-semanticui') %>
<% $forge->include('wgt-init-filesysbrowser',$cfgref) %>
<% $forge->include('wgt-page-prjoptions-pickdirjs') %>

<div class="main ui container">
 <div class="ui segment">
    <% $forge->include('wgt-semui-header', $title ) %>
    <form class="ui form"   id=mainform>
	<input type=hidden name=havevals value=1>
	<input type=hidden name=indir value="<%= $prj->{indir} %>" id=indir>


	<% $forge->include('wgt-browseoutfn-semui', $prj, $props_prefix, 
		($is_copier ? 'copy to hard disk.exe' : 'installer.exe'), qw(width_of_fn six   width_of_dir five)) %>
    	    <div class="five wide field">
		<label><%$ __('Text file with text of license, if needed') . tooltip('makeexe_license_file')  %></label>
		<div class="ui input">
		    <input NOTrequired name="<%= $props_prefix %>licensefilename"  
			id=filename1
			value="<%= $prj->{opts}->{ $props_prefix  . "licensefilename"} %>"
			placeholder="license.txt" type="text">
		    <!-- <% # user will have to type in filename %>
		    <button class="ui icon button" id="filename1_btn" dataset-id="filename1">
			<i class="file icon"></i>
		      </button>
		    -->
		</div>
	    </div>
	</div> <!-- of .fields started by wgt-browseoutfn-semui -->

	<h4 class="ui Xdividing header"><%= __('Branding') %></h4>

	<div class="fields">
<% 

exe_get_prop($prj,$props_prefix,'exe_prodname',__('Product name'),'Our Product','six');
exe_get_prop($prj,$props_prefix,'exe_companyname',__('Company name'),'Our Company','five');
exe_get_prop($prj,$props_prefix,'exe_version',__('Product version'),'1.0','five');
%>	

	</div>


	<h4 class="ui Xdividing header"><%= __('File and directory names to use') %></h4>
	<div class="fields">
<%

exe_get_prop($prj,$props_prefix,'exe_dirname',__('Folder name in c:\\Program Files\\ where product will be installed to'),
    'Our Product by Our Company', 'eleven');
exe_get_prop($prj,$props_prefix,'exe_shortcutfilename',__('Shortcut file name'),'Run Our Product','five');
%>
	</div>


	<h4 class="ui header">&nbsp;</h4>
	<div class="fields">
<% 

my @nsispaths = grep { -r $_ }  (#possible paths to makensis follow
    '/usr/bin/makensis', '/usr/local/bin/makensis',
    $ENV{ProgramFiles} . '\\NSIS\\makensis.exe',
    $ENV{"ProgramFiles(x86)"} . '\\NSIS\\makensis.exe'
    );

$nsispaths[0] = $^O !~ /Win/ ? ($ENV{ProgramFiles} . '\\NSIS\\makensis.exe') : '/usr/local/bin/makensis'
    if (!@nsispaths);

exe_get_prop($prj,$props_prefix,'exe_nsis',__('Where NSIS is installed (see below of where to get it)'),
    $nsispaths[0], 'eleven');


%>
    	    <div class="five wide field">
		<label>&nbsp;</label>
                <button class="ui fluid primary wide button"><i class="ui icon windows"></i>
                 <%=   __('Create')  %>  </button>
    	    </div>
	</div>


<div>&nbsp;</div>
<div class="setting-hint">
<i class="icon idea"></i>
<%$ 
    !$is_copier ?
    __('It\'s recommended to produce the prototype just for Windows before creating installer. Also it\'s recommended to do <a href=pack.optimize class=noul>Optimize &amp; Pack Prototype&rArr;Optimize directory structure</a> first before generating installer.') 
    : __('You do not have to regenerate utility each time you update the Prototype, because utility does not contain any of your files inside it. Generate utility only once, regerenate it if you accidently removed it or wish to change product name or version.')
%>
</div>

    </form>
 </div>
</div>





<div class="ui accordion container">

    <div class="title"><i class="dropdown icon"></i><%= __('Why use this?') %></div>
    <div class="content">
	<%$    tooltip_data(	$is_copier ? "menu.pack.create-exe-copier" : "menu.pack.create-exe" )  %>
    </div>

    <div class="title"><i class="dropdown icon"></i><%= __('Where to get NSIS?') %></div>
    <div class="content">
	<%$ __('You will need to install a free tool called NSIS to be able to create installers. It can be downloaded from <a href=http://nsis.sourceforge.net/Download>here</a>, version 3.x is recommended, but version 2.x will most probably work fine too. There are some builds of NSIS for Mac and Linux, so you can generate installers even on Mac and Linux.')  %>
    </div>

</div>



