<data>
	<organization>
		<name>${organizationData.name}</name>
		<address>${organizationData.mainContact.address}</address>
		<web>www.kssp.cz</web>
	</organization>
	<#if participantsData?has_content>
	    <#list participantsData as participant>
	        <@printParticipant participant />
	    </#list>
	<#else>
        <@printEmptyParticipant />
    </#if>
</data>

<#macro printParticipant participant>
    <#local contacts = participantContacts?api.get(participant.id)>
    <#local infos = participantInfos?api.get(participant.id)>
    <#local assets = participantAssets?api.get(participant.id)>
    <#if assets?has_content>
        <#if ParticipantFunctions.getAssetByFunction(assets, 'Fena')??>
            <#local fena = ParticipantFunctions.getAssetByFunction(assets, 'Fena')>
        </#if>
        <#if ParticipantFunctions.getAssetByFunction(assets, 'Krycí pes 1')??>
            <#local pes1 = ParticipantFunctions.getAssetByFunction(assets, 'Krycí pes 1')>
        </#if>
        <#if ParticipantFunctions.getAssetByFunction(assets, 'Krycí pes 2')??>
            <#local pes2 = ParticipantFunctions.getAssetByFunction(assets, 'Krycí pes 2')>
        </#if>
        <#if ParticipantFunctions.getAssetByFunction(assets, 'Krycí pes 3')??>
            <#local pes3 = ParticipantFunctions.getAssetByFunction(assets, 'Krycí pes 3')>
        </#if>
    </#if>
	<participant>
		<formNumber>${ParticipantFunctions.getInfoValue(infos, 'Č. KL')}</formNumber>
		<validity>${KSSPFunctions.getValidityRange(ParticipantFunctions.getInfoValue(infos, 'Chov. rok'))}</validity>
		<breed><#if fena??>${ParticipantFunctions.getAssetAttributeValue(fena.renderedAttributes, 'Plemeno')}</#if></breed>
		<inseminace>${ParticipantFunctions.getInfoValue(infos, 'Inseminace')}</inseminace>
		<inseminacePoznamka>${ParticipantFunctions.getInfoValue(infos, 'Poznámka inseminace')}</inseminacePoznamka>

		<female>
			<name><#if fena??>${fena.name!""}</#if></name>
			<number><#if fena??>${fena.number!""}</#if></number>
            <#if fena??>
                <#local femaleMembers = assetMembers?api.get(fena.id)![]>

                <#if ParticipantFunctions.getAssetMemberByType(femaleMembers, 'Majitel')??>
                    <#local femaleMemberByType = ParticipantFunctions.getAssetMemberByType(femaleMembers, 'Majitel')>
                    <#if femaleMemberByType?has_content>
                        <#local femaleOwnerContact = ParticipantFunctions.getContactByType(femaleMemberByType.contacts, 'Kontaktní adresa')>
                    </#if>
                </#if>
            </#if>
			<owner>
				<name><#if femaleMemberByType??>${femaleMemberByType.name!""}</#if></name>
				<address><#if femaleOwnerContact??>${femaleOwnerContact.address}</#if></address>
			</owner>
		</female>
		<male1>
			<name><#if pes1??>${pes1.name!""}</#if></name>
			<number><#if pes1??>${pes1.number!""}</#if></number>
			<recommended>${ParticipantFunctions.getInfoValue(infos, 'Dop. P1')?replace('✖ ', '')?replace('✔ ', '')}</recommended>
			<note>${ParticipantFunctions.getInfoValue(infos, 'Pozn. P1')}</note>
            <#if pes1??>
                <#local male1Members = assetMembers?api.get(pes1.id)![]>
                <#if ParticipantFunctions.getAssetMemberByType(male1Members, 'Majitel')??>
                    <#local male1MemberByType = ParticipantFunctions.getAssetMemberByType(male1Members, 'Majitel')>
                    <#if male1MemberByType?has_content>
                        <#local male1OwnerContact = ParticipantFunctions.getContactByType(male1MemberByType.contacts, 'Kontaktní adresa')>
                    </#if>
                </#if>
            </#if>
			<owner>
				<name><#if male1MemberByType??>${male1MemberByType.name!""}</#if></name>
				<address><#if male1OwnerContact??>${male1OwnerContact.address}</#if></address>
			</owner>
		</male1>
		<male2>
			<name><#if pes2??>${pes2.name!""}</#if></name>
			<number><#if pes2??>${pes2.number!""}</#if></number>
			<recommended>${ParticipantFunctions.getInfoValue(infos, 'Dop. P2')?replace('✖ ', '')?replace('✔ ', '')}</recommended>
			<note>${ParticipantFunctions.getInfoValue(infos, 'Pozn. P2')}</note>
            <#if pes2??>
                <#local male2Members = assetMembers?api.get(pes2.id)![]>
                <#if ParticipantFunctions.getAssetMemberByType(male2Members, 'Majitel')??>
                    <#local male2MemberByType = ParticipantFunctions.getAssetMemberByType(male2Members, 'Majitel')>
                    <#if male2MemberByType?has_content>
                        <#local male2OwnerContact = ParticipantFunctions.getContactByType(male2MemberByType.contacts, 'Kontaktní adresa')>
                    </#if>
                </#if>
            </#if>
			<owner>
				<name><#if male2MemberByType??>${male2MemberByType.name!""}</#if></name>
				<address><#if male2OwnerContact??>${male2OwnerContact.address}</#if></address>
			</owner>
		</male2>
		<male3>
			<name><#if pes3??>${pes3.name!""}</#if></name>
			<number><#if pes3??>${pes3.number!""}</#if></number>
			<recommended>${ParticipantFunctions.getInfoValue(infos, 'Dop. P3')?replace('✖ ', '')?replace('✔ ', '')}</recommended>
			<note>${ParticipantFunctions.getInfoValue(infos, 'Pozn. P3')}</note>
            <#if pes3??>
                <#local male3Members = assetMembers?api.get(pes3.id)![]>
                <#if ParticipantFunctions.getAssetMemberByType(male3Members, 'Majitel')??>
                    <#local male3MemberByType = ParticipantFunctions.getAssetMemberByType(male3Members, 'Majitel')>
                    <#if male3MemberByType?has_content>
                        <#local male3OwnerContact = ParticipantFunctions.getContactByType(male3MemberByType.contacts, 'Kontaktní adresa')>
                    </#if>
                </#if>
            </#if>
			<owner>
				<name><#if male3MemberByType??>${male3MemberByType.name!""}</#if></name>
				<address><#if male3OwnerContact??>${male3OwnerContact.address}</#if></address>
			</owner>
		</male3>
		<created>${ParticipantFunctions.getInfoValue(infos, 'Datum zpracování KL')}</created>
		<createdBy>${ParticipantFunctions.getInfoValue(infos, 'PCH')}</createdBy>
		<createdByAddress>${KSSPFunctions.getCreatorAddress(ParticipantFunctions.getInfoValue(infos, 'PCH'))}</createdByAddress>
	</participant>
</#macro>

<#macro printEmptyParticipant>
	<participant>
		<formNumber />
		<validity />
		<breed />
		<inseminace />
		<inseminacePoznamka />
		<female>
			<name />
			<number />
			<owner>
				<name />
				<address />
			</owner>
		</female>
		<male1>
			<name />
			<number />
			<recommended />
			<note />
			<owner>
				<name />
				<address />
			</owner>
		</male1>
		<male2>
			<name />
			<number />
			<recommended />
			<note />
			<owner>
				<name />
				<address />
			</owner>
		</male2>
		<male3>
			<name />
			<number />
			<recommended />
			<note />
			<owner>
				<name />
				<address />
			</owner>
		</male3>
		<created />
		<createdBy />
		<createdByAddress />
	</participant>
</#macro>