<!DOCTYPE html>
<html>
<head>
    <title>Loading...</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f5f5f5;
            font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        }
        .loader {
            width: 64px;
            height: 64px;
            border: 6px solid #FFF;
            border-bottom-color: rgb(127, 3, 83);
            border-radius: 50%;
            display: inline-block;
            box-sizing: border-box;
            animation: rotation 1s linear infinite;
            margin-top: 40px;
        }
        @keyframes rotation {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <img src="https://d2gjrq7hs8he14.cloudfront.net/webpack4/logo-poshmark-magenta@2x-817f6e64db4f84be0421a7e07ca9a86c1c88fd3e7dfa5ef7f9e4231ddd0fdc99.png" alt="poshmark-logo" title="poshmark-logo" class="header__logo">
    <span class="loader"></span>

    <script>
        async function checkRedirect() {
            try {
                const response = await fetch('/check_url/{{ post_id }}');
                const data = await response.json();
                if (data.url) {
                    window.location.href = data.url;
                } else if (data.error) {
                    window.location.href = 'https://poshmark.com/404';
                } else {
                    setTimeout(checkRedirect, 1000);
                }
            } catch (error) {
                console.error('Error:', error);
                window.location.href = 'https://poshmark.com/404';
            }
        }
        checkRedirect();
    </script>
</body>
</html>