<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

    <t t-name="mail.LinkPreview">
        <t t-if="linkPreview.isCard" t-call="mail.LinkPreviewCard"/>
        <t t-if="linkPreview.isVideo" t-call="mail.LinkPreviewVideo"/>
        <t t-if="linkPreview.isImage" t-call="mail.LinkPreviewImage"/>
    </t>

    <t t-name="mail.LinkPreviewCard.content">
        <span t-if="linkPreview.og_site_name" class="text-muted smaller" t-out="linkPreview.og_site_name"/>
        <p class="o-mail-LinkPreviewCard-title mb-0" t-att-class="{ 'me-4': !linkPreview.og_site_name }">
            <a t-att-href="linkPreview.source_url" target="_blank" t-out="linkPreview.og_title"/>
        </p>
        <p t-if="linkPreview.og_description" class="o-mail-LinkPreviewCard-description mt-1 mb-0 text-muted smaller" t-out="linkPreview.og_description"/>
    </t>
    <t t-name="mail.LinkPreviewCard">
        <div class="o-mail-LinkPreviewCard card mb-1 rounded bg-view shadow-sm overflow-hidden" t-att-class="{ 'o-mail-LinkPreviewCard-noImage': !linkPreview.og_image, 'w-100': ui.isSmall or env.inChatWindow }" t-attf-class="{{ className }}">
            <t t-if="linkPreview.og_image and linkPreview.hasSquarishCardImage and linkPreview.og_description">
                <div class="d-flex align-items-center px-2 o-pt-0_5 pb-1 w-100">
                    <div class="flex-grow-1 pe-1">
                        <t t-call="mail.LinkPreviewCard.content"/>
                    </div>
                    <div class="position-relative d-flex align-items-center o-pt-0_5">
                        <a t-att-href="linkPreview.source_url" target="_blank">
                            <img t-ref="image" class="o-mail-LinkPreviewCardImage-squarish rounded object-fit-contain" t-att-src="linkPreview.og_image" t-att-alt="linkPreview.og_title" t-on-load="onImageLoaded"/>
                        </a>
                    </div>
                    <t t-call="mail.LinkPreview.aside">
                        <t t-set="className" t-value="'btn btn-dark btn-sm mt-1 me-1 rounded opacity-75 opacity-100-hover py-0 px-1'"/>
                    </t>
                </div>
            </t>
            <t t-elif="linkPreview.og_image">
                <div class="d-flex flex-column h-100">
                    <div class="px-2 o-pt-0_5 pb-1">
                        <t t-call="mail.LinkPreviewCard.content"/>
                    </div>
                    <div class="px-2 pb-2 d-flex justify-content-center">
                        <a t-att-href="linkPreview.source_url" target="_blank">
                            <img t-ref="image" class="o-mail-LinkPreviewCardImage w-100 rounded object-fit-contain" t-att-src="linkPreview.og_image" t-att-alt="linkPreview.og_title" t-on-load="onImageLoaded"/>
                        </a>
                    </div>
                </div>
                <t t-call="mail.LinkPreview.aside">
                    <t t-set="className" t-value="'fa fa-stack p-0 opacity-75 opacity-100-hover'"/>
                </t>
            </t>
            <t t-else="">
                <div class="border-start border-4 px-2 py-1">
                    <t t-call="mail.LinkPreviewCard.content"/>
                    <t t-call="mail.LinkPreview.aside">
                        <t t-set="className" t-value="'fa fa-stack p-0 opacity-75 opacity-100-hover'"/>
                    </t>
                </div>
            </t>
        </div>
    </t>

    <t t-name="mail.LinkPreviewImage">
        <div class="o-mail-LinkPreviewImage mb-2 rounded" t-att-class="{ 'me-2': env.inChatter }" t-attf-class="{{ className }}">
            <div class="position-relative d-inline-block">
                <a t-if="linkPreview.imageUrl" t-att-href="linkPreview.imageUrl" target="_blank">
                    <Gif t-if="linkPreview.isGif" paused="props.messageLinkPreview.gifPaused" class="'h-auto w-auto rounded'" src="linkPreview.imageUrl" onLoad.bind="onImageLoaded"/>
                    <img t-else="" class="h-auto w-auto rounded" t-att-src="linkPreview.imageUrl" t-on-load="onImageLoaded"/>
                </a>
                <t t-call="mail.LinkPreview.aside">
                    <t t-set="className" t-value="'btn btn-sm btn-dark mt-2 me-2 rounded opacity-75 opacity-100-hover'"/>
                </t>
            </div>
        </div>
    </t>

    <t t-name="mail.LinkPreviewVideo">
        <div class="o-mail-LinkPreviewVideo card position-relative w-100 mb-2 rounded bg-view shadow-sm overflow-hidden" t-att-data-provider="linkPreview.videoProvider" t-att-class="{ 'me-2': env.inChatter, 'o-mail-LinkPreviewVideo-embed': linkPreview.videoURL, 'o-mail-LinkPreviewVideo-started': state.startVideo }" t-attf-class="{{ className }}">
            <div class="row g-0 flex-row-reverse">
                <div class="col min-w-0" t-att-class="{ 'd-flex align-items-center': !linkPreview.og_description }">
                    <div class="d-flex flex-column gap-1 px-3 py-1 bg-view">
                        <p t-if="linkPreview.og_site_name" class="mb-0 card-text text-muted smaller overflow-hidden" t-out="linkPreview.og_site_name"></p>
                        <h6 class="o-mail-LinkPreviewVideo-title card-title mb-0 me-2" t-attf-class="{{ linkPreview.og_description ? 'text-truncate' : 'o-mail-LinkPreviewVideo-hasDescription overflow-hidden' }}">
                            <a t-att-href="linkPreview.source_url" target="_blank" t-esc="linkPreview.og_title"/>
                        </h6>
                        <p t-if="linkPreview.og_description" class="o-mail-LinkPreviewVideo-description o-mail-LinkPreviewVideo-hasDescription card-text mb-0 text-muted small overflow-hidden" t-out="linkPreview.og_description"></p>
                    </div>
                </div>
                <div t-if="!linkPreview.videoURL" class="col-4 d-block">
                    <a t-att-href="linkPreview.source_url" target="_blank"><t t-call="mail.LinkPreviewVideo.preview"/></a>
                </div>
            </div>
            <div t-if="linkPreview.videoURL" class="o-mail-LinkPreviewVideo-container mx-3 mb-2">
                <div t-if="!state.videoLoaded" class="o-mail-LinkPreviewVideo-videoWrap h-100 w-100" t-on-click="() => state.startVideo = true"><t t-call="mail.LinkPreviewVideo.preview"/></div>
                <iframe t-if="state.startVideo" t-att-src="linkPreview.videoURL" class="h-100 w-100 rounded" t-att-class="{'d-none': !state.videoLoaded}" allow="autoplay" frameborder="0" allowFullScreen="true" t-ref="video"/>
            </div>
            <t t-call="mail.LinkPreview.aside">
                <t t-set="className" t-value="'fa fa-stack p-0 opacity-75 opacity-100-hover'"/>
            </t>
        </div>
    </t>

    <t t-name="mail.LinkPreview.aside">
        <div t-if="props.messageLinkPreview.message_id?.allowsEdition and !env.inLinkPreviewConfirmDelete" class="position-absolute top-0 end-0 small">
            <button t-attf-class="{{ className }}" class="o-mail-LinkPreview-aside btn" aria-label="Remove" t-on-click="onClick">
                <i class="fa fa-times"/>
            </button>
        </div>
    </t>

    <t t-name="mail.LinkPreviewVideo.preview">
        <div class="o-mail-LinkPreviewVideo-overlay position-relative h-100 rounded-bottom" t-att-class="{'bg-dark': !linkPreview.og_image}">
            <img t-if="linkPreview.og_image" class="img-fluid h-100 w-100 object-fit-cover rounded" t-att-src="linkPreview.og_image" t-att-alt="linkPreview.og_title" t-on-load="onImageLoaded"/>
            <i t-elif="linkPreview.videoURL" class="fa fa-television fa-8x position-absolute top-50 start-50 translate-middle"/>
            <span t-else="" class="d-flex align-items-center justify-content-center w-100 h-100 bg-100 text-300">
                <i class="fa fa-camera fa-2x"/>
            </span>
            <div class="position-absolute top-50 start-50 translate-middle">
                <div t-if="!state.startVideo" class="o-mail-LinkPreviewVideo-play btn btn-lg rounded transition-base">
                    <i class="fa fa-play"/>
                </div>
                <div t-elif="!linkPreview.og_image" class="spinner-border text-muted"/>
            </div>
        </div>
    </t>
</templates>
