#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/blib/lib", "$FindBin::Bin/blib/arch";
use Chandra;

print "Opening Chandra...\n";

Chandra->new(
    title  => 'Perl Chandra Demo',
    url    => 'data:text/html,<!DOCTYPE html>
<html>
<head>
    <style>
        body { 
            font-family: -apple-system, BlinkMacSystemFont, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background: linear-gradient(135deg, %23667eea 0%25, %23764ba2 100%25);
            color: white;
        }
        h1 { margin-bottom: 20px; color: black; }
        button {
            padding: 15px 30px;
            font-size: 18px;
            border: none;
            border-radius: 8px;
            background: white;
            color: %23667eea;
            cursor: pointer;
            transition: transform 0.2s;
        }
        button:hover { transform: scale(1.05); }
        #counter { color: black; font-size: 64px; margin: 20px; }
    </style>
</head>
<body>
   <script>
        let count = 0;
        function increment() {
            count++;
            document.getElementById("counter").textContent = count;
            window.external.invoke("count:" + count);
        }
    </script>
    <h1>Hello from Perl + Chandra!</h1>
    <div id="counter">0</div>
    <button onclick="increment()">Click me!</button>
 
</body>
</html>',
    width    => 500,
    height   => 400,
    debug    => 1,
    callback => sub {
        my ($msg) = @_;
        print "JS says: $msg\n";
    },
)->run;

print "WebView closed.\n";
