{% set sub_url="https://"+domain+"/"+hconfigs[ConfigEnum.proxy_path]+"/"+user.uuid+"/" %}
{% set sub_encoded_url='https%3A%2F%2F'+domain+'%2F'+hconfigs[ConfigEnum.proxy_path]+'%2F'+user.uuid+'%2F' %}
{% set base_download_url='/{{hconfigs[ConfigEnum.proxy_path]}}/gh' %}
{% set base_download_url='https://github.com' %}

<div class="row1  mb-2" style="margin-top: 10px;">

    <div class="card-deck">
        <div class="card small-box bg-success bg-h-red">
            <a class="open_in_hiddify" href="{{sub_url}}">
                <div class="card-body">
                    <div class="inner">

                        <h4 style="text-wrap:balance">{{_('Click to Start Anti-Filter.')}}</h4>
                        <div class="info-box-content">
                            {{_('Unified link for all application.')}}
                        </div>
                    </div>
                    <div class="icon">
                        <i class="fa-solid fa-wifi" style="top:7px"></i>
                    </div>
                </div>
            </a>

        </div>
        <div class="card small-box bg-success bg-h-pink ">
            <a class="short-link" href="{{sub_url}}short/">
                <div class="card-body">
                    <div class="inner">
                        <h4> {{_('Temporary Short Link')}}</h4>
                        <div class="info-box-content">
                            {{_('Simplifies the process of employing the link elsewhere.')}}
                        </div>
                    </div>
                    <div class="icon">
                        <i class="fa-solid fa-file-zipper" style="top:7px"></i>
                    </div>
                </div>

            </a>

        </div>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">{{_('Open in Application')}}</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                {{_("If the application do not open automatically, please click <a class='btn btn-primary copy-link'
                    href='%(sub)s'>this universal link</a> to copy and paste it on
                your application, or:",sub=sub_url)}}
                <br><br>

                {% if ua.os.family=="Android" %}
                <h3>
                    {{_('Use HiddifyNext:')}}
                </h3>

                <table>
                    <tr>

                        <td>

                            <a href="{{base_download_url}}/hiddify/hiddify-next/releases/latest/download/hiddify-android-universal.apk"
                                class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                        </td>
                        <td>
                            <a href="https://play.google.com/store/apps/details?id=app.hiddify.com"
                                class="btn col-12 btn-primary">{{_('install from google play')}}</a>
                        </td>
                        <td><a class="btn col-12 btn-success"
                                href="hiddify://install-config/?url={{sub_encoded_url}}">{{_('Import')}}</a></td>
                    </tr>
                </table>
                <details>
                    <summary>{{_('More Applications')}}</summary>
                    <table>
                        <tr>
                            <td>HiddifyNG / V2rayNG</td>
                            <td>

                                <a href="{{base_download_url}}/Hiddify/HiddifyNG/releases/latest/download/HiddifyNG.apk"
                                    class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                                <a href="https://play.google.com/store/apps/details?id=ang.hiddify.com"
                                    class="btn col-12 btn-primary">{{_('install from google play')}}</a>
                            </td>

                            <td><a class="btn col-12 btn-success"
                                    href="hiddify://install-sub/?url={{sub_encoded_url}}">{{_('Import in')}}
                                    HiddifyNG</a></td>
                        </tr>
                        <tr>
                            <td>Clash / Meta</td>
                            <td><a href="{{base_download_url}}/hiddify/HiddifyClashAndroid/releases/download/v2.7.3-h0.24/hiddify-2.7.3-h0.24-meta-alpha-universal-release.apk"
                                    class="btn col-12 btn-primary ">{{_('Download App')}}</a></td>
                            <td><a class="btn col-12 btn-success"
                                    href="clash://install-config/?url={{sub_encoded_url}}">{{_('Import in')}} Clash</a>
                            </td>
                        </tr>
                    </table>
                </details>
                {% endif %}

                {% if ua.os.family=="Windows" %}
                <h3>
                    {{_('Use HiddifyNext:')}}
                </h3>
                <table>
                    <tr>

                        <td>
                            <a href="{{base_download_url}}/hiddify/hiddify-next/releases/latest/download/hiddify-windows-x64-setup.zip"
                                class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                        </td>
                        <td><a class="btn col-12 btn-success"
                                href="hiddify://install-config/?url={{sub_encoded_url}}">{{_('Import')}}</a></td>
                    </tr>
                </table>


                <details>
                    <summary>{{_('More Applications')}}</summary>
                    <table>
                        <tr>
                            <td>HiddifyN</td>
                            <td>
                                <a href="{{base_download_url}}/Hiddify/HiddifyN/releases/latest/download/win-x86.zip"
                                    class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                            </td>

                            <td><a class="btn col-12 btn-success"
                                    href="hiddify://install-sub/?url={{sub_encoded_url}}">{{_('Import')}}</a></td>
                        </tr>
                        <tr>
                            <td>Clash / Meta</td>
                            <td>
                                <a href="{{base_download_url}}/Hiddify/HiddifyClashDesktop/releases/latest/download/HiddifyClashDesktop_13.1.4_x64_en-US.msi"
                                    class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                            </td>
                            <td><a class="btn col-12 btn-success"
                                    href="clash://install-config/?url={{sub_encoded_url}}">{{_('Import')}}</a></td>
                        </tr>
                    </table>
                </details>
                {% endif %}

                {% if 'Linux' in self.ua_string and 'X11' in self.ua_string%}
                <h3>
                    {{_('Use HiddifyNext:')}}
                </h3>
                <table>
                    <tr>

                        <td>
                            <a href="{{base_download_url}}/hiddify/hiddify-next/releases/latest/download/hiddify-linux-x64.zip"
                                class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                        </td>
                        <td><a class="btn col-12 btn-success"
                                href="hiddify://install-config/?url={{sub_encoded_url}}">{{_('Import')}}</a></td>
                    </tr>
                </table>
                <details>
                    <summary>{{_('More Applications')}}</summary>
                    <table>
                        <!-- <tr>
                        <td>HiddifyN</td>
                        <td>
                            <a href="{{base_download_url}}/Hiddify/HiddifyN/releases/latest/download/win-x86.zip"
                                class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                        </td>

                        <td><a class="btn col-12 btn-success" href="hiddify://install-sub/?url={{sub_encoded_url}}">Import</a></td>
                    </tr> -->
                        <tr>
                            <td>Clash / ClashMeta / HiddifyClash</td>
                            <td>
                                <a href="{{base_download_url}}/Hiddify/HiddifyClashDesktop/releases/latest/download/hiddify-clash-desktop_13.1.4_amd64.AppImage"
                                    class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                            </td>
                            <td><a class="btn col-12 btn-success"
                                    href="clash://install-config/?url={{sub_encoded_url}}">{{_('Import')}}</a></td>
                        </tr>
                    </table>
                </details>
                {% endif %}

                {% if ua.os.family=='Mac OS X' %}
                <h3>
                    {{_('Use HiddifyNext:')}}
                </h3>
                <table>
                    <tr>
                        <td>
                            <a href="{{base_download_url}}/hiddify/hiddify-next/releases/latest/download/hiddify-macos-universal.zip"
                                class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                        </td>
                        <td><a class="btn col-12 btn-success"
                                href="hiddify://install-config/?url={{sub_encoded_url}}">{{_('Import')}}</a></td>
                    </tr>
                </table>
                <details>
                    <summary>{{_('More Applications')}}</summary>
                    <table>
                        <!-- <tr>
                        <td>HiddifyN</td>
                        <td>
                            <a href="{{base_download_url}}/Hiddify/HiddifyN/releases/latest/download/win-x86.zip"
                                class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                        </td>

                        <td><a class="btn col-12 btn-success" href="hiddify://install-sub/?url={{sub_encoded_url}}">Import</a></td>
                    </tr> -->
                        <tr>
                            <td>Clash / Meta </td>
                            <td>
                                <a href="{{base_download_url}}/Hiddify/HiddifyClashDesktop/releases/latest/download/HiddifyClashDesktop_13.1.4_x64.dmg"
                                    class="btn col-12 btn-primary ">{{_('Download App')}}</a>
                            </td>
                            <td><a class="btn col-12 btn-success"
                                    href="clash://install-config/?url={{sub_encoded_url}}">{{_('Import')}}</a></td>
                        </tr>
                        <tr>
                            <td>FoxRay</td>
                            <td><a href="https://apps.apple.com/us/app/foxray/id6448898396" target="_blank"
                                    class="btn btn-primary">{{_('Download App')}}</a></td>
                            <td><a class="btn btn-success"
                                    href="foxray://yiguo.dev/sub/add/?url={{base}}">{{_('Import')}}</a></td>
                        </tr>
                    </table>
                </details>
                {% endif %}


                {% if ua.os.family=="iOS" %}
                <details>
                    <summary>{{_('More Applications')}}</summary>
                    <table>
                        <tr>
                            <td>FoxRay</td>
                            <td><a href="https://apps.apple.com/us/app/foxray/id6448898396" target="_blank"
                                    class="btn btn-primary">{{_('Download App')}}</a></td>
                            <td><a class="btn btn-success"
                                    href="https://yiguo.dev/sub/add/?url={{sub_url|b64encode}}#{{profile_title}}">{{_('Import')}}</a>
                            </td>
                        </tr>
                        <tr>
                            <td>Streisand</td>
                            <td><a href="https://apps.apple.com/app/id6450534064" target="_blank"
                                    class="btn btn-primary">{{_('Download App')}}</a></td>
                            <td><a class="btn btn-success"
                                    href="streisand://import/{{sub_url}}#{{profile_title}}">{{_('Import')}}</a></td>
                        </tr>
                        <tr>
                            <td>Shadowrocket</td>
                            <td>
                                <a href="https://apps.apple.com/us/app/shadowrocket/id932747118" target="_blank"
                                    class="btn btn-primary">{{_('Download App')}}</a>
                            </td>
                            <td><a class="btn col-12 btn-success" href="sub://{{sub_url|b64encode}}">{{_('Import')}}</a>
                            </td>
                        </tr>
                        <tr>
                            <td>Stash</td>
                            <td>
                                <a href="https://apps.apple.com/us/app/stash-rule-based-proxy/id1596063349"
                                    target="_blank" class="btn btn-primary">
                                    {{_('Download App')}}
                                </a>
                            </td>
                            <td><a class="btn col-12 btn-success"
                                    href="clash://install-config/?url={{sub_encoded_url}}">
                                    {{_('Import')}}
                                </a></td>
                        </tr>
                        <tr>
                            <td>Loon</td>
                            <td>
                                <a href="https://apps.apple.com/app/id1373567447" target="_blank"
                                    class="btn btn-primary">
                                    {{_('Download App')}}
                                </a>
                            </td>
                            <td><a class="btn col-12 btn-success"
                                    href="loon://import?nodelist={{sub_encoded_url}}">{{_('Import')}}</a></td>
                        </tr>

                    </table>
                </details>
                {% endif %}

                <details>
                    <summary>{{_('QRCode')}}</summary>
                    <center>
                        <div id="qrcode-oneclick" class="mx-auto"
                            style="margin:10px;margin:10px;padding:10px;background:#fff"></div>
                    </center>
                </details>



            </div>
            <div class="modal-footer">
                <a class="btn btn-secondary" data-dismiss="modal">{{_('Close')}}</a>
                <a href="{{sub_url}}" class="btn btn-primary copy-link">{{_('Copy Link')}}</a>
            </div>

        </div>
    </div>
</div>






<div class="modal fade" id="short-link-Modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">{{_('Temporary Short Link')}}</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <!-- AJAX content will be loaded here -->
            </div>
        </div>
    </div>
</div>

<script data-cfasync="false" type="text/javascript">

    // ONE CLICK

    var qr_code_generated = false

    //$('.open_in_hiddify').click(function (e) {
    document.querySelectorAll('.open_in_hiddify').forEach(function (element) {
        element.addEventListener('click', function (e) {
            e.preventDefault()
            let iframe = $('<iframe></iframe>').css('display', 'none');
            $('body').append(iframe);
            url = "hiddify://install-sub/?url=" + encodeURI(this.href)
            try {
                navigator.clipboard.writeText(this.href).then(function () {
                    console.log("success")
                    iframe.attr('src', url);
                }, function (err) {
                    console.log(err)
                    iframe.attr('src', url);
                });
            } catch (error) {
                console.log(error)
                iframe.attr('src', url);
            }

            // 
            $('#exampleModal').modal({ show: true })
            if (!qr_code_generated) {
                let w = Math.min(window.innerWidth, window.innerHeight) * 0.5;
                let qrcode_oneclick = new QRCode(document.getElementById("qrcode-oneclick"), {
                    width: w,
                    height: w,
                    correctLevel: 1
                });
                qrcode_oneclick.clear();
                qrcode_oneclick.makeCode(document.location.href);
                qr_code_generated = true
            }
        });
    });


    //   $('.short-link').click(function (e) {
    document.querySelectorAll('.short-link').forEach(function (element) {
        element.addEventListener('click', function (e) {
            e.preventDefault()
            $.get(this.href, function (data) {
                $("#short-link-Modal .modal-body").html(data);
                $("#short-link-Modal").modal('show');
            })

        });
    });

</script>