<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>Get the {{ object.name }} App</title>

  <!-- Bootstrap core CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>

<body>
  <div class="d-flex flex-column min-vh-100 justify-content-center align-items-center">
    <!-- <img class="mb-4" src="https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72"> -->
    <h1>{{ object.name }}</h1>

    {% if is_mobile_ios or is_tablet_ios %}
      <p>iOS Mobile/Tablet</p>
      {% if object.get_app_store_url %}
      <a class="btn btn-lg btn-primary" href="{{ object.get_app_store_url }}">Get The App</a>
      {% else %}
      <p class="alert alert-danger">iOS App Not Available</p>
      {{ object.get_ios_redirect_url }}
      {% endif %}

    {% elif is_mobile_android or is_tablet_android %}
      <p>Android Mobile/Tablet</p>
      {% if object.get_play_store_url %}
      <a class="btn btn-lg btn-primary" href="{{ object.get_play_store_url }}">Get The App</a>
      {% else %}
      <p class="alert alert-danger">Android App Not Available</p>
      {{ object.get_android_redirect_url }}
      {% endif %}

    {% elif is_pc_mac %}
      <p>Mac Desktop</p>
      {% if object.get_mac_app_store_url %}
      <a class="btn btn-lg btn-primary" href="{{ object.get_mac_app_store_url }}">Get The App</a>
      {% else %}
      <p class="alert alert-danger">Mac App Not Available</p>
      {% endif %}

    {% elif is_pc_windows %}
      <p>Windows Desktop</p>
      {% if object.get_windows_app_store_url %}
      <a class="btn btn-lg btn-primary" href="{{ object.get_windows_app_store_url }}">Get The App</a>
      {% else %}
      <p class="alert alert-danger">Windows App Not Available</p>
      {% endif %}

    {% else %}
      <p class="alert alert-danger">Unknown Platform</p>
    {% endif %}
  </div>

  <script type="text/javascript">
    function validateProtocol(url) {
      var parser = document.createElement("a");
      parser.href = url;
      var protocol = parser.protocol.toLowerCase();
      if (["javascript:", "vbscript:", "data:", "ftp:", ":", " "].indexOf(protocol) < 0) {
        return url;
      }
      return null;
    }
    {% if is_mobile_ios or is_tablet_ios %}
      console.log('iOS Mobile/Tablet');
      {% if object.get_ios_redirect_url %}
      window.onload = function () {
        console.log('Redirect to: {{ object.get_ios_redirect_url }}');
        window.top.location = validateProtocol("{{ object.get_ios_redirect_url }}");
      };
      {% else %}
      console.log('iOS App Not Available');
      {% endif %}

    {% elif is_mobile_android or is_tablet_android %}
      console.log('Android Mobile/Tablet');
      {% if object.get_android_redirect_url %}
      window.onload = function () {
        console.log('Redirect to: {{ object.get_android_redirect_url }}');
        window.top.location = validateProtocol("{{ object.get_android_redirect_url }}");
      };
      {% else %}
      console.log('Android App Not Available');
      {% endif %}

    {% elif is_pc_mac %}
      console.log('Mac Desktop');
      {% if object.get_mac_app_store_url %}
      window.onload = function () {
        console.log('Redirect to: {{ object.get_mac_app_store_url }}');
        window.top.location = validateProtocol("{{ object.get_mac_app_store_url }}");
      };
      {% else %}
      console.log('Mac App Not Available');
      {% endif %}

    {% elif is_pc_windows %}
      console.log('Windows Desktop');
      {% if object.get_windows_app_store_url %}
      window.onload = function () {
        console.log('Redirect to: {{ object.get_windows_app_store_url }}');
        window.top.location = validateProtocol("{{ object.get_windows_app_store_url }}");
      };
      {% else %}
      console.log('Windows App Not Available');
      {% endif %}

    {% else %}
    console.log('Unknown Platform');
    {% endif %}
  </script>
</body>

</html>
