<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }

class KNSDD_Checkout_Notices_Controller {
    /**
     * Aynı request içinde checkout uyarılarının birden fazla kez gösterilmesini engellemek için guard.
     */
    private $shown = false;

    /**
     * Primary: WooCommerce native notification ile gösterim.
     */
    public function show_primary( $messages, $wc_notice_presenter = null, $message_renderer = null ) {
        if ( $this->shown || empty( $messages ) ) { return; }
        if ( $wc_notice_presenter && $message_renderer ) {
            $wc_notice_presenter->present_checkout_notices( $messages, $message_renderer );
        } else if ( $message_renderer ) {
            $message_renderer->render_wc_notices( $messages );
        }
        $this->shown = true;
    }

    /**
     * Fallback 1: Custom checkout notices kutusu ile gösterim.
     */
    public function show_fallback1( $messages, $wc_notice_presenter = null, $message_renderer = null ) {
        if ( $this->shown || empty( $messages ) ) { return; }
        if ( $wc_notice_presenter && $message_renderer ) {
            $wc_notice_presenter->present_checkout_notices_fallback1( $messages, $message_renderer );
        } else if ( $message_renderer ) {
            $message_renderer->render_custom_checkout_notices( $messages );
        }
        $this->shown = true;
    }

    /**
     * Fallback 2: Inline checkout notices gösterim.
     */
    public function show_fallback2( $messages, $wc_notice_presenter = null, $message_renderer = null ) {
        if ( $this->shown || empty( $messages ) ) { return; }
        if ( $wc_notice_presenter && $message_renderer ) {
            $wc_notice_presenter->present_checkout_notices_fallback2( $messages, $message_renderer );
        } else if ( $message_renderer ) {
            $message_renderer->render_inline_checkout_notices( $messages );
        }
        $this->shown = true;
    }

    /**
     * Fallback 3: Minimal tablo satırı ile gösterim.
     */
    public function show_table_fallback( $messages, $wc_notice_presenter = null, $message_renderer = null ) {
        if ( $this->shown || empty( $messages ) ) { return; }
        if ( $wc_notice_presenter && $message_renderer ) {
            $wc_notice_presenter->present_checkout_notices_table_fallback( $messages, $message_renderer );
        } else if ( $message_renderer ) {
            $message_renderer->render_clean_table_notices( $messages );
        }
        $this->shown = true;
    }
}
