{if isset($RSThemes['pages'][$templatefile]) && file_exists($RSThemes['pages'][$templatefile]['fullPath'])}
    {include file=$RSThemes['pages'][$templatefile]['fullPath']}
{else}  
    {if $invalidTicketId}
        {include file="$template/includes/alert.tpl" type="danger" title=$LANG.thereisaproblem msg=$LANG.supportticketinvalid}
    {else}
        {if $closedticket}
            {include file="$template/includes/alert.tpl" type="info" msg=$LANG.supportticketclosedmsg}
        {/if}
        {if $errormessage}
            {include file="$template/includes/alert.tpl" type="error" additionalClasses="alert-primary" errorshtml=$errormessage}
        {/if}
    {/if}
    {if !$invalidTicketId}
        <section class="section section-sm">
            <div class="section-header">
                <div class="section-title">{$rslang->trans('support.ticket_settings')}</div>
            </div>
            <div class="section-body">
                <div class="panel panel-default panel-ticket-reply hidden-print" {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } id="accordion"{/if}>
                    <ul class="panel-tabs nav nav-tabs {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } nav-tabs-collapse{/if}">
                        <li {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-toggle="collapse" data-target="#reply" class="collapsed"{/if}>
                            <a tabindex="0" class="{if !(isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1") } active {/if}" href="#reply" data-toggle="tab" aria-expanded="false" tabindex="0">
                                {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" }
                                    {include file="$template/assets/img/closed-collapse-icon.svg"}
                                {/if}
                                <span>{$LANG.supportticketsreply}</span>
                            </a>
                        </li>
                        {if isset($sensitiveDataEnabled) && $sensitiveDataEnabled && (isset($sensitiveDataOptions) && $sensitiveDataOptions == "new") && $loggedin && (is_array($sensitiveDataSupportDepartmentsEnabled) && $sensitiveDataSupportDepartmentsEnabled[$departmentid] == 1)}
                        <li {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-toggle="collapse" data-target="#sensitive-data" class="collapsed"{/if}>
                                <a tabindex="0" tabindex="0" class="" href="#sensitive-data" data-toggle="tab" aria-expanded="false">
                                    {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" }
                                        {include file="$template/assets/img/closed-collapse-icon.svg"}
                                    {/if}
                                    <span class="">{$sensitiveDataTranslations->getClientTranslation("open_ticket.tab_name")|unescape:'html'}</span>
                                    {if isset($sensitiveData) && $sensitiveData != ""}
                                        <span class="badge badge-primary-faded">1</span>
                                    {else}
                                        <span class="badge badge-default">0</span>
                                    {/if}
                                </a>
                            </li>
                        {/if}
                        <li {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-toggle="collapse" data-target="#recipients" class="collapsed"{/if}>
                            <a tabindex="0" tabindex="0" class="" href="#recipients" data-toggle="tab" aria-expanded="false">
                                {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" }
                                    {include file="$template/assets/img/closed-collapse-icon.svg"}
                                {/if}
                                <span class="">{$LANG.support.ccRecipients}</span>
                                <span class="badge {if  is_array($ticketRecipietns) && $ticketRecipietns|@count > 0}badge-primary-faded{else}badge-default{/if}">{if  is_array($ticketRecipietns)}{$ticketRecipietns|@count}{/if}</span>
                            </a>
                        </li>
                        <li {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-toggle="collapse" data-target="#attachements" class="collapsed"{/if}>
                            <a tabindex="0" tabindex="0" class="" href="#attachements" data-toggle="tab" aria-expanded="false"> 
                                {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" }
                                    {include file="$template/assets/img/closed-collapse-icon.svg"}
                                {/if}
                                <span class="">{$LANG.supportticketsticketattachments}</span>
                                <span class="badge {if is_array($ticketAttachments) && $ticketAttachments|@count > 0}badge-primary-faded{else}badge-default{/if}">{$ticketAttachmentsCount}</span>
                            </a>
                        </li>
                        {if is_array($customfields)}
                            {assign var="customfield_count" value=0}
                            {foreach item=customfield from=$customfields}
                                {if $customfield.rawvalue}
                                    {assign var="customfield_count" value=$customfield_count+1}
                                {/if}
                            {/foreach}
                            {if $customfield_count != 0}
                                <li {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-toggle="collapse" data-target="#additional-information" tabindex="0" class="collapsed"{/if}>
                                    <a tabindex="0" class="" href="#additional-information" data-toggle="tab" aria-expanded="false">
                                        {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" }
                                            {include file="$template/assets/img/closed-collapse-icon.svg"}
                                        {/if}
                                        <span class="">{$LANG.additionalInfo}</span>
                                        <span class="badge badge-primary-faded">{$customfield_count}</span>
                                    </a>
                                </li>
                            {/if}
                        {/if}
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane tab-reply active{if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } collapse{/if}" id="reply" {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-parent="#accordion"{/if}>
                            {include file="$template/includes/view-ticket/reply-tab-content.tpl"}
                        </div>
                        {if isset($sensitiveDataEnabled) && $sensitiveDataEnabled && (isset($sensitiveDataOptions) && $sensitiveDataOptions == "new") && $loggedin && (is_array($sensitiveDataSupportDepartmentsEnabled) && $sensitiveDataSupportDepartmentsEnabled[$departmentid] == 1)}
                            <div class="tab-pane tab-sensitive {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } collapse{/if}" id="sensitive-data" {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-parent="#accordion"{/if}>
                                {include file="$template/core/extensions/SensitiveDataManager/views/view-ticket.tpl" translations=$sensitiveDataTranslations}
                            </div>
                        {/if}
                        <div class="tab-pane tab-recipients {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } collapse{/if}" id="recipients" {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-parent="#accordion"{/if}>
                            {include file="$template/includes/view-ticket/recipients-tab-content.tpl"}
                        </div>
                        <div class="tab-pane tab-attachements {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } collapse{/if}" id="attachements" {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-parent="#accordion"{/if}>
                            {include file="$template/includes/view-ticket/attachements-tab-content.tpl"}
                        </div>
                        {if is_array($customfields) && $customfields|@count > 0}
                            <div class="tab-pane tab-additional-information {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } collapse{/if}" id="additional-information" {if isset($RSThemes['pages'][$templatefile]['config']['collapsedTabs']) && $RSThemes['pages'][$templatefile]['config']['collapsedTabs'] == "1" } data-parent="#accordion"{/if}>
                                {include file="$template/includes/view-ticket/custom-field-tab-content.tpl"}
                            </div>
                        {/if}
                    </div>
                </div>
            </div>
        </section>
        <section class="section section-sm">
                <div class="section-header">
                    <div class="section-title">{$rslang->trans('support.ticket_messages')}</div>
                </div>
                <div class="section-body">
                    {foreach from=$descreplies key=num item=reply}
                        <div class="ticket-reply{if $reply.admin} staff{/if}">
                            <div class="ticket-reply-top">
                                {if $RSThemes.addonSettings.show_gravatar_image == 'displayed'}
                                    <div class="client-avatar client-avatar-md">
                                        <img src="https://www.gravatar.com/avatar/{$reply.email|md5}{if $RSThemes.addonSettings.gravatar_placeholder && $RSThemes.addonSettings.gravatar_placeholder != "default"}?d={$RSThemes.addonSettings.gravatar_placeholder}{/if}" alt="Avatar">

                                        {* TODO: Sprawdzać które logo ma być wyświetlane na jakim tle? *}
                                        {if $reply.admin && $RSThemes.logoSquareInverse}
                                            <div class="staff-reply">
                                                <a tabindex="0" href="{if $lagom_logo_url}{$lagom_logo_url}{else}{$WEB_ROOT}/index.php{/if}" class="logo"><img src="{$WEB_ROOT}{$RSThemes.logoSquareInverse}" alt="{$companyname}"/></a>
                                            </div>
                                        {/if}
                                    </div>
                                {/if}
                                <div class="user">
                                    <div class="user-info">
                                        <span class="name">
                                            {if $RSThemes.addonSettings.show_gravatar_image == 'hidden'}
                                                <i class="ls ls-user"></i>
                                            {/if}
                                            {$reply.name}
                                        </span>
                                        <div class="date">{$reply.date}</div>
                                    </div>
                                    <div class="user-label">
                                        <span class="label label-xs {if !$reply.admin}label-inner-border{/if} requestor-type-{$reply.requestor.type_normalised} label-rounded">{lang key='support.requestor.'|cat:$reply.requestor.type_normalised}</span>
                                        {if $reply.id && $reply.admin && $ratingenabled}
                                            {if $reply.rating}
                                                <div class="rating-done">
                                                    {for $rating=1 to 5}
                                                        <span class="star{if (5 - $reply.rating) < $rating} active{/if}"></span>
                                                    {/for}
                                                </div>
                                            {else}
                                                <div class="rating" ticketid="{$tid}" ticketkey="{$c}" ticketreplyid="{$reply.id}">
                                                    <span class="star" rate="5"></span>
                                                    <span class="star" rate="4"></span>
                                                    <span class="star" rate="3"></span>
                                                    <span class="star" rate="2"></span>
                                                    <span class="star" rate="1"></span>
                                                </div>
                                            {/if}
                                        {/if}
                                    </div>
                                </div>
                            </div>            
                            <div class="ticket-reply-message markdown-content">
                                {$reply.message}
                                {if $reply.ipaddress}
                                    <p class="ip-address">{lang key='support.ipAddress'}: {$reply.ipaddress}</p>
                                {/if}
                            </div>
                            {if $reply.attachments}
                                <div class="ticket-reply-attachments">
                                    <strong>{$LANG.supportticketsticketattachments} ({$reply.attachments|count})</strong>
                                    {if $reply.attachments_removed}({lang key='support.attachmentsRemoved'}){/if}
                                    <ul>
                                        {foreach from=$reply.attachments key=num item=attachment}
                                            {if $reply.attachments_removed}
                                                <li>
                                                    <i class="ls ls-minus"></i>
                                                    {$attachment}
                                                </li>
                                            {else}
                                                {$attachmentArray = "."|explode:$attachment}
                                                {$attachmentExtension = '.'|cat:{$attachmentArray|@end}}
                                                {$attachmentName = $attachment|replace:".{$attachmentExtension}":""}
                                                <li>
                                                    <a tabindex="0" href="dl.php?type={if $reply.id}ar&id={$reply.id}{else}a&id={$id}{/if}&i={$num}">
                                                        <i class="lm lm-document"></i>
                                                        <div class="attachment-container">
                                                            <span class="attachment-name">{$attachmentName}</span>
                                                            <span class="attachment-extension">{$attachmentExtension}</span>
                                                        </div>
                                                    </a>
                                                </li>
                                            {/if}
                                        {/foreach}
                                    </ul>
                                </div>
                            {/if}
                        </div>
                    {/foreach}
                </div>
        </section>
        <div class="panel panel-info visible-print-block">
            <div class="panel-heading">
                <h3 class="panel-title">
                    {$LANG.ticketinfo}
                </h3>
            </div>
            <div class="panel-body container-fluid">
                <div class="row">
                    <div class="col-md-2 col-xs-6">
                        <b>{$LANG.supportticketsticketid}</b><br />{$tid}
                    </div>
                    <div class="col-md-4 col-xs-6">
                        <b>{$LANG.supportticketsticketsubject}</b><br />{$subject}
                    </div>
                    <div class="col-md-2 col-xs-6">
                        <b>{$LANG.supportticketspriority}</b><br />{$urgency}
                    </div>
                    <div class="col-md-4 col-xs-6">
                        <b>{$LANG.supportticketsdepartment}</b><br />{$department}
                    </div>
                </div>
            </div>
        </div>
        {include file="$template/includes/view-ticket/modals/close-ticket.tpl"}
    {/if}
{/if}