<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
        version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
        xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">

    <xsl:output method="html" indent="yes" encoding="UTF-8"/>

    <xsl:template match="/">
        <html lang="id-ID">
            <head>
                <title>
                    Sitemap | Akusewa
                    <xsl:if test="sitemap:sitemapindex">Index</xsl:if>
                </title>
                <link rel="icon" type="image/png" href="/wp-content/uploads/favicon-01.png" sizes="32x32" />
                <link rel="stylesheet" href="/wp-content/themes/akusewa-theme/assets/css/atasnalar.min.css"/>
                <script src="/wp-content/themes/akusewa-theme/assets/js/jquery.min.js"></script>
                <script src="/wp-content/themes/akusewa-theme/assets/js/table2excel.min.js"></script>
                <style type="text/css">
                    /* Scrollbar - Width */
                    ::-webkit-scrollbar {
                        width: 8px;
                        height: 8px;
                    }

                    /* Scrollbar - Track */
                    ::-webkit-scrollbar-track {
                        background: var(--gray-20);
                    }

                    /* Scrollbar - Handle */
                    ::-webkit-scrollbar-thumb {
                        background: var(--primary);
                        border-radius: 1rem;
                        -webkit-border-radius: 1rem;
                        -moz-border-radius: 1rem;
                        -ms-border-radius: 1rem;
                        -o-border-radius: 1rem;
                    }

                    /* Scrollbar - Handle on hover */
                    ::-webkit-scrollbar-thumb:hover {
                        background: var(--primary);
                    }
                    *, html, body {
                        color: var(--dark);
                    }

                    header a,
                    footer a {
                        color: var(--dark);
                    }
                    .fw-500 {
                        font-weight: 500;
                    }
                    .fw-600 {
                        font-weight: 600;
                    }
                    .content-wrap {
                        background: #fff;
                        padding: 1rem 0.875rem;
                        border-radius: 1rem;
                        -webkit-border-radius: 1rem;
                        -moz-border-radius: 1rem;
                        -ms-border-radius: 1rem;
                        -o-border-radius: 1rem;
                        -webkit-box-shadow: 0 0 16px 0 rgba(var(--dark-rgb), 15%);
                                box-shadow: 0 0 16px 0 rgba(var(--dark-rgb), 15%);
                        margin-bottom: 1rem;
                    }
                    .site-footer {
                        color: var(--dark);
                        background: var(--white);
                        padding: 0.5rem 0;
                        border-top: 1px solid var(--primary);
                        -webkit-box-shadow: 0 -0.25rem 0.5rem rgb(0 0 0 / 8%);
                        box-shadow: 0 -0.25rem 0.5rem rgb(0 0 0 / 8%);
                    }
                    .floating {
                        bottom: 2rem;
                        z-index: 1010;
                    }
                    #back-to-top {
                        color: var(--white);
                        background-color: var(--primary);
                    }
                    .bg-light-blue {
                        background-color: #F1F6FE;
                    }
                </style>
            </head>
            <body class="bg-light-blue">
                <header class="text-center">
                    <div class="container-lg">
                        <div class="row">
                            <div class="col-12">
                                <div class="p-3">
                                    <a href="/" aria-label="Logo"><img src="/wp-content/uploads/logo-01.svg" alt="Akusewa" class="an-img-256" /></a>
                                    <h4 class="mt-3">PT AKUSEWA INDONESIA SEJAHTERA</h4>
                                    <xsl:if test="sitemap:sitemapindex">
                                        <span class="badge fw-normal fs-md py-1 px-2 bg-primary rounded-2">Index</span>
                                    </xsl:if>
                                    <xsl:if test="sitemap:urlset">
                                        <span class="badge fw-normal fs-md py-1 px-2 bg-primary rounded-2">Peta Situs</span>
                                    </xsl:if>
                                    <xsl:if test="image:image">
                                        <span class="badge fw-normal fs-md py-1 px-2 bg-primary rounded-2">Gambar</span>
                                    </xsl:if>
                                    <xsl:if test="video:video">
                                        <span class="badge fw-normal fs-md py-1 px-2 bg-primary rounded-2">Video</span>
                                    </xsl:if>
                                    <xsl:if test="xhtml:link">
                                        <span class="badge fw-normal fs-md py-1 px-2 bg-primary rounded-2">Xhtml</span>
                                    </xsl:if>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="content-wrap">
                                    <h5>
                                        <xsl:choose>
                                            <xsl:when test="sitemap:sitemapindex">
                                                Indeks ini berisi
                                                <strong class="text-secondary fw-600"><xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"/></strong>
                                                Situs.
                                            </xsl:when>
                                            <xsl:otherwise>
                                                Indeks ini berisi
                                                <strong class="text-secondary fw-600"><xsl:value-of select="count(sitemap:urlset/sitemap:url)"/></strong>
                                                URL.
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </h5>
                                    <p class="m-0">
                                        Ini adalah sitemap XML, dimaksudkan untuk dikonsumsi oleh mesin pencari seperti Google, Bing atau lainnya.<br/>
                                        Anda dapat menemukan informasi lebih lanjut tentang sitemaps XML di <a href="https://sitemaps.org" class="text-dark text-hover-primary">sitemaps.org</a>.
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </header>

                <xsl:apply-templates/>

                <footer id="site-footer" class="site-footer mt-3" role="contentinfo">
                    <div class="container">
                        <div class="row">
                            <div class="text-center col">
                                <!-- Copyright -->
                                <span>
                                    Hak Cipta © 2022 oleh <a href="/">PT AKUSEWA INDONESIA SEJAHTERA</a>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="floating">
                        <!-- Begin Scroll to top -->
                        <a id="back-to-top" href="javascript:void(0)" class="btn btn-light btn-md back-to-top hover-up" role="button">↑</a>
                        <!-- END Scroll to top -->
                    </div>
                </footer>

                <div class="preloader">
                    <div class="loader-wrap" data-label="Sedang Memuat...">
                        <img src="/wp-content/uploads/favicon-01.svg" class="logo-loader" />
                    </div>
                </div>

                <script src="/wp-content/themes/akusewa-theme/assets/js/atasnalar.bundle.min.js"></script>
                <script type="text/javascript">
                    jQuery(window).on('load', function() {
                        jQuery('.preloader').delay(1500).fadeOut('slow');
                    });
                    jQuery(document).ready(function($) {
                        // Scroll to top
                        $(window).on('scroll', function () {
                            if ($(this).scrollTop() > 50) {
                                $('#back-to-top').fadeIn();
                            } else {
                                $('#back-to-top').fadeOut();
                            }
                        });

                        // scroll body to 0px on click
                        $('#back-to-top').on('click', function () {
                            $('body,html').animate({
                            scrollTop: 0
                            }, 400);
                            return false;
                        });
                        $('body').find('a').each(function () {
                            // if value is only # then replace with js void
                            if ($(this).attr('href') === '#') {
                                $(this).attr('href', 'javascript:void(0)');
                            }
                        });
                        // Table2excel
                        $('#download-sitemap').click(function() {
                            $('#sitemap').table2excel({
                                name: "Peta Situs - PT AKUSEWA INDONESIA SEJAHTERA",
                                filename: "Peta Situs - PT AKUSEWA INDONESIA SEJAHTERA",
                                fileext: ".xls",
                                exclude_img: true,
                                exclude_links: false,
                                exclude_inputs: true,
                                exclude: ".nodownload"
                            });
                        });
                        $('table').each(function() {
                            var $table = $(this);
                            var freq = $('.freq');

                            $table.find('td:nth-child(3)').each(function() {
                                var text = $(this).text();
                                if (text === 'daily') {
                                    freq.text('per Hari');
                                } else if (text === 'weekly') {
                                    freq.text('per Minggu');
                                } else if (text === 'monthly') {
                                    freq.text('per Bulan');
                                } else if (text === 'yearly') {
                                    freq.text('per Tahun');
                                }
                            });
                        });
                    });
                </script>
            </body>
        </html>
    </xsl:template>


    <xsl:template match="sitemap:sitemapindex">
        <div class="container-lg">
            <div class="row">
                <div class="col-12">
                    <div class="content-wrap p-3">
                        <div class="d-flex flex-wrap align-items-center justify-content-between mb-2">
                            <h4 class="m-0">Daftar Indeks</h4>
                            <a href="#" id="download-sitemap" class="btn btn-primary">Unduh Peta Situs</a>
                        </div>
                        <table id="sitemap" class="table table-bordered table-hover" cellspacing="0">
                            <thead class="bg-primary">
                                <tr>
                                    <th valign="middle" class="text-center" style="width:60px">#</th>
                                    <th valign="middle">URL</th>
                                    <th valign="middle" class="text-center" style="width:200px">Terakhir diperbarui</th>
                                </tr>
                            </thead>
                            <tbody>
                            <xsl:for-each select="sitemap:sitemap">
                            <xsl:sort select="sitemap:lastmod" order="descending"/>
                                <tr>
                                    <xsl:variable name="loc">
                                        <xsl:value-of select="sitemap:loc"/>
                                    </xsl:variable>
                                    <xsl:variable name="pno">
                                        <xsl:value-of select="position()"/>
                                    </xsl:variable>
                                    <td class="text-center">
                                        <xsl:value-of select="$pno"/>
                                    </td>
                                    <td class="">
                                        <a href="{$loc}" class="text-dark text-hover-primary" target="_blank">
                                            <xsl:value-of select="sitemap:loc"/>
                                        </a>
                                    </td>
                                    <xsl:if test="sitemap:lastmod">
                                    <td class="text-center">
                                        <xsl:value-of select="concat(substring(sitemap:lastmod, 0, 11), concat(' ', substring(sitemap:lastmod, 12, 5)), concat(' ', substring(sitemap:lastmod, 20, 6)))"/>
                                    </td>
                                    </xsl:if>
                                    <xsl:apply-templates/>
                                </tr>
                            </xsl:for-each>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </xsl:template>

    <xsl:template match="sitemap:urlset">
        <div class="container-lg">
            <div class="row">
                <div class="col-12">
                    <div class="content-wrap p-3">
                        <div class="d-flex flex-wrap align-items-center justify-content-between mb-2">
                            <h4 class="m-0">Daftar Indeks</h4>
                            <a href="#" id="download-sitemap" class="btn btn-primary">Unduh Peta Situs</a>
                        </div>
                        <table id="sitemap" class="table table-bordered table-hover" cellspacing="0">
                            <thead class="table-primary text-white">
                                <tr>
                                    <th valign="middle" class="text-center" style="width:60px">#</th>
                                    <th valign="middle">URL</th>
                                    <xsl:if test="sitemap:url/sitemap:changefreq">
                                    <th valign="middle" class="text-center" style="width:180px">Frekuensi <br/><small class="freq fw-normal fs-xs fst-italic"></small></th>
                                    </xsl:if>
                                    <xsl:if test="sitemap:url/sitemap:priority">
                                    <th valign="middle" class="text-center" style="width:90px">Prioritas</th>
                                    </xsl:if>
                                    <xsl:if test="sitemap:url/sitemap:lastmod">
                                    <th valign="middle" class="text-center" style="width:200px">Terakhir diperbarui</th>
                                    </xsl:if>
                                </tr>
                            </thead>
                            <tbody>
                            <xsl:for-each select="sitemap:url">
                            <xsl:sort select="sitemap:lastmod" order="descending"/>
                                <tr>
                                    <xsl:variable name="loc">
                                        <xsl:value-of select="sitemap:loc"/>
                                    </xsl:variable>
                                    <xsl:variable name="pno">
                                        <xsl:value-of select="position()"/>
                                    </xsl:variable>
                                    <td class="text-center">
                                        <xsl:value-of select="$pno"/>
                                    </td>
                                    <td>
                                        <a href="{$loc}" class="text-dark text-hover-blue" target="_blank">
                                            <xsl:value-of select="sitemap:loc"/>
                                        </a>
                                        <xsl:apply-templates select="xhtml:*"/>
                                        <xsl:apply-templates select="image:*"/>
                                        <xsl:apply-templates select="video:*"/>
                                    </td>
                                    <xsl:apply-templates select="sitemap:changefreq"/>
                                    <xsl:apply-templates select="sitemap:priority"/>
                                    <xsl:if test="sitemap:lastmod">
                                    <td class="text-center">
                                        <xsl:value-of select="concat(substring(sitemap:lastmod, 0, 11), concat(' ', substring(sitemap:lastmod, 12, 5)), concat(' ', substring(sitemap:lastmod, 20, 6)))"/>
                                    </td>
                                    </xsl:if>
                                </tr>
                            </xsl:for-each>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </xsl:template>

    <xsl:template match="sitemap:loc|sitemap:lastmod|image:loc|image:caption|video:*">
    </xsl:template>

    <xsl:template match="sitemap:changefreq|sitemap:priority">
        <td class="text-center">
            <xsl:apply-templates/>
        </td>
    </xsl:template>

    <xsl:template match="xhtml:link">
        <xsl:variable name="altloc">
            <xsl:value-of select="@href"/>
        </xsl:variable>
        <p>
            <strong>Xhtml: </strong>
            <a href="{$altloc}" class="text-dark text-hover-blue">
                <xsl:value-of select="@href"/>
            </a>

            <xsl:if test="@hreflang">
                <small class="badge fw-normal fs-md py-1 px-2 bg-primary rounded-2">
                    <xsl:value-of select="@hreflang"/>
                </small>
            </xsl:if>

            <xsl:if test="@rel">
                <small class="badge fw-normal fs-md py-1 px-2 bg-primary rounded-2">
                    <xsl:value-of select="@rel"/>
                </small>
            </xsl:if>

            <xsl:if test="@media">
                <small class="badge fw-normal fs-md py-1 px-2 bg-primary rounded-2">
                    <xsl:value-of select="@media"/>
                </small>
            </xsl:if>
        </p>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="image:image">
        <xsl:variable name="loc">
            <xsl:value-of select="image:loc"/>
        </xsl:variable>
        <p>
            <strong>Image: </strong>
            <a href="{$loc}" class="text-dark text-hover-primary">
                <xsl:value-of select="image:loc"/>
            </a>
            <xsl:if test="image:caption">
                <span class="fst-italic text-gray">
                    <xsl:value-of select="image:caption"/>
                </span>
            </xsl:if>
            <xsl:apply-templates/>
        </p>
    </xsl:template>

    <xsl:template match="video:video">
        <xsl:variable name="loc">
            <xsl:choose>
                <xsl:when test="video:player_loc != ''">
                    <xsl:value-of select="video:player_loc"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="video:content_loc"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="thumb_loc">
            <xsl:value-of select="video:thumbnail_loc"/>
        </xsl:variable>
        <p>
            <strong>Video: </strong>
            <a href="{$loc}" class="text-dark text-hover-primary">
                <xsl:choose>
                    <xsl:when test="video:player_loc != ''">
                        <xsl:value-of select="video:player_loc"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="video:content_loc"/>
                    </xsl:otherwise>
                </xsl:choose>
            </a>
            <a href="{$thumb_loc}" class="badge fw-normal fs-md py-1 px-2 bg-primary rounded-2">
                thumb
            </a>
            <xsl:if test="video:title">
                <span class="fst-italic text-gray">
                    <xsl:value-of select="video:title"/>
                </span>
            </xsl:if>
            <xsl:apply-templates/>
        </p>
    </xsl:template>

</xsl:stylesheet>