<?php
function luzuk_create_home_page_on_activation() {
    $page_title = 'Home';
    $home_page_id = 0;

    $existing_page = new WP_Query( array(
        'post_type'      => 'page',
        'title'          => $page_title,
        'posts_per_page' => 1,
        'post_status'    => 'any',
    ) );

    if ( $existing_page->have_posts() ) {
        $existing_page->the_post();
        $home_page_id = get_the_ID();
    } else {
        $home_page_id = wp_insert_post( array(
            'post_title'    => $page_title,
            'post_status'   => 'publish',
            'post_type'     => 'page',
            'post_content'  => '',
        ) );
    }

    wp_reset_postdata();

    if ( $home_page_id ) {
        update_post_meta( $home_page_id, '_wp_page_template', 'page-template/custom-home-page.php' );
        update_option( 'show_on_front', 'page' );
        update_option( 'page_on_front', $home_page_id );
    }
}
add_action( 'after_switch_theme', 'luzuk_create_home_page_on_activation' );

function luzuk_create_home_page_alternative() {
    if ( get_option( 'luzuk_home_page_created' ) ) {
        return;
    }

    $page_title = 'Home';
    $home_page_id = 0;
    $existing_page = get_page_by_title( $page_title );
    if ( $existing_page ) {
        $home_page_id = $existing_page->ID;
    } else {
        $home_page_id = wp_insert_post( array(
            'post_title'    => $page_title,
            'post_status'   => 'publish',
            'post_type'     => 'page',
            'post_content'  => '',
        ) );
    }
    if ( $home_page_id ) {
        update_post_meta( $home_page_id, '_wp_page_template', 'page-template/custom-home-page.php' );
        update_option( 'show_on_front', 'page' );
        update_option( 'page_on_front', $home_page_id );
        update_option( 'luzuk_home_page_created', true );
    }
}

function luzuk_theme_setup_notice() {
    ?>
    <style>
        .luzuk-notice {
            display: flex;
            align-items: center;
            gap: 20px;
            padding: 20px;
            background: linear-gradient(135deg, #f0fff4, #d1fae5);
            border-left: 6px solid #ff0000;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        }
        .luzuk-notice img {
            width: 200px;
            height: auto;
            border-radius: 6px;
            border: 1px solid #ccc;
        }
        .luzuk-notice-content h2 {
            margin: 0 0 8px;
            font-size: 20px;
            color: #065f46;
        }
        .luzuk-notice-content p {
            margin: 0 0 12px;
            color: #047857;
            font-size: 14px;
            line-height: 1.5;
        }
        .luzuk-notice .button-primary {
            background-color: #065f46;
            border-color: #ff0000;
            box-shadow: none;
            text-decoration: none;
            padding: 10px 20px;
            font-size: 14px;
            border-radius: 25px;
            transition: all 0.3s ease;
        }
        .luzuk-notice .button-primary:hover {
            background-color: #059669;
            border-color: #047857;
            transform: translateY(-2px);
        }
    </style>
    <div class="notice notice-success luzuk-notice">
        <img src="<?php echo esc_url( get_template_directory_uri() . '/screenshot.png' ); ?>" alt="Theme Screenshot">
        <div class="luzuk-notice-content">
            <h2>🎉 Thank You for Installing <strong>Luzuk Theme</strong>!</h2>
            <p>We’re thrilled to have you on board. Kickstart your journey by customizing your theme for the perfect look and feel.</p>
            <a href="<?php echo esc_url( admin_url( 'customize.php' ) ); ?>" target="_blank" class="button button-primary">
                🚀 Setup Your Theme Now
            </a>
        </div>
    </div>
    <?php
}
add_action( 'admin_notices', 'luzuk_theme_setup_notice' );
