<?php
// FILE: templates/embedded-order-received.php  (YENİ)
// Minimal "thank you" görünümü; tema header/footer yok; yükseklik & durum sinyali gönderir.
if ( ! defined('ABSPATH') ) exit;
if ( ! function_exists('wc_get_order') ) { wp_die( esc_html__('WooCommerce is required.', 'executive-vip-transfer-service') ); }

global $wp;
$order_id  = isset($wp->query_vars['order-received']) ? absint($wp->query_vars['order-received']) : 0;
$order_key = isset($_GET['key']) ? wc_clean( wp_unslash($_GET['key']) ) : '';
$order     = $order_id ? wc_get_order($order_id) : false;
if ( ! $order || ! $order->key_is_valid($order_key) ) { wp_die( esc_html__('Invalid order.', 'executive-vip-transfer-service') ); }

// Basit, temiz iskelet
?><!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title><?php echo esc_html( sprintf( __( 'Order #%s received', 'executive-vip-transfer-service' ), $order->get_order_number() ) ); ?></title>
<style>
  html,body{margin:0;background:#fff;font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;color:#111;}
  .wrap{max-width:860px;margin:16px auto;padding:0 12px}
  #wpadminbar{display:none!important}
</style>
<style>
  /* Başlık/Paragraflar */
  #execvitr-embed-ty h2, #execvitr-embed-ty h3{
    margin:8px 0 10px; font-weight:700; font-size:18px;
  }
  #execvitr-embed-ty p{ margin:6px 0; color:#111; }
  #execvitr-embed-ty ul{ margin:8px 0 12px 18px }

  /* Woo tablolarını sadeleştir */
  #execvitr-embed-ty table.shop_table{
    width:100%; border-collapse:collapse; margin:10px 0 14px;
    border:1px solid #eee; background:#fff; border-radius:10px; overflow:hidden;
  }
  #execvitr-embed-ty table.shop_table th,
  #execvitr-embed-ty table.shop_table td{
    border:1px solid #eee; padding:8px 10px; vertical-align:top;
  }
  #execvitr-embed-ty table.shop_table th{
    background:#f8fafc; font-weight:600;
  }

  /* Küçük metinler */
  #execvitr-embed-ty small, #execvitr-embed-ty .small{
    color:#6b7280;
  }

  /* Linkler */
  #execvitr-embed-ty a{ color:#2563eb; text-decoration:none }
  #execvitr-embed-ty a:hover{ text-decoration:underline }

  /* Spacing */
  #execvitr-embed-ty .woocommerce-order{ margin:0 }
</style>
<?php wp_head(); ?>
</head>
<body>
<div class="wrap" id="execvitr-embed-ty">
  <?php
  // WooCommerce default thankyou içeriği
  wc_get_template( 'checkout/thankyou.php', [ 'order' => $order ] );
  ?>
</div>
<script>
// iFrame ebeveyne: yükseklik + tamamlandı sinyali
(function(){
  function post(type,p){ try{ parent.postMessage(Object.assign({type:type}, p||{}), '*'); }catch(e){} }
  function sendHeight(){
    var h = Math.max(
      document.body.scrollHeight, document.documentElement.scrollHeight,
      document.body.offsetHeight, document.documentElement.offsetHeight
    );
    post('wc-iframe-height', {height:h});
  }
  document.addEventListener('DOMContentLoaded', function(){
    sendHeight();
    post('wc-pay-finished', {status:'received'});
    setInterval(sendHeight, 600);
  });
})();
</script>
<?php wp_footer(); ?>
</body>
</html>
