<%--
/**
 * 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" %>

<%
SearchContainer<Country> countrySearchContainer = CountrySearchContainerFactory.create(liferayPortletRequest, liferayPortletResponse);
%>

<clay:management-toolbar
	managementToolbarDisplayContext="<%= new CountriesManagementAdminManagementToolbarDisplayContext(request, liferayPortletRequest, liferayPortletResponse, countrySearchContainer) %>"
	propsTransformer="js/CountriesManagementToolbarPropsTransformer"
/>

<clay:container-fluid>
	<aui:form method="post" name="fm">
		<aui:input name="redirect" type="hidden" value="<%= currentURL %>" />
		<aui:input name="countryIds" type="hidden" />

		<liferay-ui:search-container
			searchContainer="<%= countrySearchContainer %>"
		>
			<liferay-ui:search-container-row
				className="com.liferay.portal.kernel.model.Country"
				keyProperty="countryId"
				modelVar="country"
			>

				<%
				List<String> availableActions = new ArrayList<>();

				availableActions.add("deleteCountries");

				if (country.getActive()) {
					availableActions.add("deactivateCountries");
				}
				else {
					availableActions.add("activateCountries");
				}

				row.setData(
					HashMapBuilder.<String, Object>put(
						"actions", StringUtil.merge(availableActions)
					).build());
				%>

				<portlet:renderURL var="rowURL">
					<portlet:param name="mvcRenderCommandName" value="/address/edit_country" />
					<portlet:param name="countryId" value="<%= String.valueOf(country.getCountryId()) %>" />
				</portlet:renderURL>

				<%
				if (!PortalPermissionUtil.contains(permissionChecker, ActionKeys.MANAGE_COUNTRIES)) {
					rowURL = null;
				}
				%>

				<liferay-ui:search-container-column-text
					cssClass="font-weight-bold important table-cell-expand-smallest"
					href="<%= rowURL %>"
					name="name"
					value="<%= HtmlUtil.escape(country.getTitle(locale)) %>"
				/>

				<liferay-ui:search-container-column-text
					name="billing-allowed"
				>
					<liferay-ui:icon
						cssClass='<%= country.isBillingAllowed() ? "text-success" : "text-danger" %>'
						icon='<%= country.isBillingAllowed() ? "check" : "times" %>'
						markupView="lexicon"
					/>
				</liferay-ui:search-container-column-text>

				<liferay-ui:search-container-column-text
					name="shipping-allowed"
				>
					<liferay-ui:icon
						cssClass='<%= country.isShippingAllowed() ? "text-success" : "text-danger" %>'
						icon='<%= country.isShippingAllowed() ? "check" : "times" %>'
						markupView="lexicon"
					/>
				</liferay-ui:search-container-column-text>

				<liferay-ui:search-container-column-text
					name="two-letter-iso-code"
					property="a2"
				/>

				<liferay-ui:search-container-column-text
					name="active"
				>
					<liferay-ui:icon
						cssClass='<%= country.isActive() ? "text-success" : "text-danger" %>'
						icon='<%= country.isActive() ? "check" : "times" %>'
						markupView="lexicon"
					/>
				</liferay-ui:search-container-column-text>

				<liferay-ui:search-container-column-text
					name="priority"
					property="position"
				/>

				<liferay-ui:search-container-column-jsp
					cssClass="table-column-text-end"
					path="/country_action.jsp"
				/>
			</liferay-ui:search-container-row>

			<liferay-ui:search-iterator
				markupView="lexicon"
			/>
		</liferay-ui:search-container>
	</aui:form>
</clay:container-fluid>