<%--
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */
--%>

<%@ include file="/init.jsp" %>

<%
EditDDMTemplateDisplayContext editDDMTemplateDisplayContext = (EditDDMTemplateDisplayContext)request.getAttribute(WebKeys.PORTLET_DISPLAY_CONTEXT);

DDMTemplate ddmTemplate = editDDMTemplateDisplayContext.getDDMTemplate();
%>

<aui:model-context bean="<%= ddmTemplate %>" model="<%= DDMTemplate.class %>" />

<div class="form-group-sm template-properties">
	<c:if test="<%= (ddmTemplate == null) && !editDDMTemplateDisplayContext.autogenerateTemplateKey() %>">
		<aui:input name="templateKey" />
	</c:if>

	<c:if test="<%= ddmTemplate != null %>">
		<aui:input helpMessage="template-key-help" name="templateKey" type="resource" value="<%= ddmTemplate.getTemplateKey() %>" />

		<portlet:resourceURL id="/template/get_ddm_template" var="getTemplateURL">
			<portlet:param name="ddmTemplateId" value="<%= String.valueOf(ddmTemplate.getTemplateId()) %>" />
		</portlet:resourceURL>

		<aui:input name="url" type="resource" value="<%= getTemplateURL %>" />

		<c:if test="<%= Validator.isNotNull(editDDMTemplateDisplayContext.getRefererWebDAVToken()) %>">
			<aui:input name="webDavURL" type="resource" value="<%= ddmTemplate.getWebDavURL(themeDisplay, editDDMTemplateDisplayContext.getRefererWebDAVToken()) %>" />
		</c:if>
	</c:if>

	<aui:input name="description" />

	<%
	String smallImageSource = editDDMTemplateDisplayContext.getSmallImageSource();
	%>

	<aui:select label="" name="smallImageSource" value="<%= smallImageSource %>" wrapperCssClass="mb-3">
		<aui:option label="no-image" value="none" />
		<aui:option label="from-url" value="url" />
		<aui:option label="from-your-computer" value="file" />
	</aui:select>

	<div class="<%= Objects.equals(smallImageSource, "url") ? "" : "hide" %>" id="<portlet:namespace />smallImageURLContainer">
		<aui:input label="" name="smallImageURL" title="small-image-url" wrapperCssClass="mb-3" />

		<c:if test="<%= editDDMTemplateDisplayContext.isSmallImage() && (ddmTemplate != null) && Validator.isNotNull(ddmTemplate.getSmallImageURL()) %>">
			<p class="control-label font-weight-semi-bold">
				<liferay-ui:message key="preview" />
			</p>

			<div class="aspect-ratio aspect-ratio-16-to-9">
				<img alt="<liferay-ui:message escapeAttribute="<%= true %>" key="preview" />" class="aspect-ratio-item-fluid" src="<%= HtmlUtil.escapeAttribute(ddmTemplate.getTemplateImageURL(themeDisplay)) %>" />
			</div>
		</c:if>
	</div>

	<div class="<%= Objects.equals(smallImageSource, "file") ? "" : "hide" %>" id="<portlet:namespace />smallImageFileContainer">
		<aui:input label="" name="smallImageFile" type="file" wrapperCssClass="mb-3" />

		<c:if test="<%= editDDMTemplateDisplayContext.isSmallImage() && (ddmTemplate != null) && (ddmTemplate.getSmallImageId() > 0) %>">
			<p>
				<strong><liferay-ui:message key="preview" /></strong>
			</p>

			<div class="aspect-ratio aspect-ratio-16-to-9">
				<img alt="<liferay-ui:message escapeAttribute="<%= true %>" key="preview" />" class="aspect-ratio-item-fluid" src="<%= HtmlUtil.escapeAttribute(ddmTemplate.getTemplateImageURL(themeDisplay)) %>" />
			</div>
		</c:if>
	</div>

	<aui:script>
		Liferay.Util.toggleSelectBox(
			'<portlet:namespace />smallImageSource',
			'url',
			'<portlet:namespace />smallImageURLContainer'
		);
		Liferay.Util.toggleSelectBox(
			'<portlet:namespace />smallImageSource',
			'file',
			'<portlet:namespace />smallImageFileContainer'
		);
	</aui:script>
</div>