<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php $s = ROS_DB::get_all_settings(); ?>
<div class="ros-admin-wrap">
  <div class="ros-admin-header">
    <h1>⚙️ Instellingen</h1>
  </div>
  <?php if ( isset( $_GET['saved'] ) ): ?>
    <div class="notice notice-success"><p>✅ Opgeslagen!</p></div>
  <?php endif; ?>

  <form method="post" action="<?php echo admin_url( 'admin-post.php' ); ?>" class="ros-form">
    <?php wp_nonce_field( 'ros_settings' ); ?>
    <input type="hidden" name="action" value="ros_save_settings">

    <div class="ros-form-card">
      <h2>Restaurant Info</h2>
      <div class="ros-field"><label>Naam</label>
        <input type="text" name="restaurant_name" value="<?php echo esc_attr( $s['restaurant_name'] ?? '' ); ?>" required></div>
      <div class="ros-field"><label>Adres</label>
        <input type="text" name="restaurant_address" value="<?php echo esc_attr( $s['restaurant_address'] ?? '' ); ?>"></div>
      <div class="ros-field"><label>Telefoon</label>
        <input type="text" name="restaurant_phone" value="<?php echo esc_attr( $s['restaurant_phone'] ?? '' ); ?>"></div>
      <div class="ros-field"><label>Valuta Symbool</label>
        <input type="text" name="currency_symbol" value="<?php echo esc_attr( $s['currency_symbol'] ?? '$' ); ?>" style="max-width:80px"></div>
    </div>

    <div class="ros-form-card">
      <h2>Logo</h2>
      <div class="ros-field">
        <label>Logo URL</label>
        <div style="display:flex;gap:10px;align-items:center">
          <input type="text" name="logo_url" id="ros_logo_url" value="<?php echo esc_attr( $s['logo_url'] ?? '' ); ?>" style="flex:1">
          <button type="button" class="button" id="ros-upload-logo">Upload Logo</button>
        </div>
        <?php if ( ! empty( $s['logo_url'] ) ): ?>
          <img src="<?php echo esc_url( $s['logo_url'] ); ?>" style="max-height:80px;margin-top:10px;border-radius:8px">
        <?php endif; ?>
      </div>
    </div>

    <div class="ros-form-card">
      <h2>💳 Stripe Betalingen</h2>
      <p style="color:#666;font-size:0.88rem;margin-bottom:16px">
        Voer hier uw Stripe API keys in. De klant kan dan direct met creditcard/debitcard betalen.
        <strong>Vind uw keys op: <a href="https://dashboard.stripe.com/apikeys" target="_blank">dashboard.stripe.com/apikeys</a></strong>
      </p>
      <div class="ros-field">
        <label>Stripe Publishable Key <span style="color:#888;font-weight:400">(begint met pk_live_ of pk_test_)</span></label>
        <input type="text" name="stripe_pk" value="<?php echo esc_attr( $s['stripe_pk'] ?? '' ); ?>" placeholder="pk_live_...">
      </div>
      <div class="ros-field">
        <label>Stripe Secret Key <span style="color:#888;font-weight:400">(begint met sk_live_ of sk_test_)</span></label>
        <input type="password" name="stripe_sk" value="<?php echo esc_attr( $s['stripe_sk'] ?? '' ); ?>" placeholder="sk_live_...">
        <small style="color:#888">Wordt versleuteld opgeslagen. Nooit zichtbaar na opslaan.</small>
      </div>
      <div class="ros-field">
        <label>
          <input type="checkbox" name="stripe_enabled" value="1" <?php checked( $s['stripe_enabled'] ?? '0', '1' ); ?>>
          Stripe kaartbetalingen inschakelen voor klanten
        </label>
      </div>
    </div>

    <button type="submit" class="ros-btn ros-btn-primary">Opslaan</button>
  </form>
</div>

<script>
jQuery(function($){
  $('#ros-upload-logo').click(function(){
    var frame = wp.media({ title:'Select Logo', multiple:false });
    frame.on('select', function(){
      var att = frame.state().get('selection').first().toJSON();
      $('#ros_logo_url').val(att.url);
    });
    frame.open();
  });
});
</script>
