<?php
if (!current_user_can('manage_options')) { echo '<p>No access.</p>'; return; }
$rules = wp_kses_post(get_option(WPGC_VideoChat_Licensed::OPTION_RULES, ''));
$default_room = sanitize_title(get_option(WPGC_VideoChat_Licensed::OPTION_DEFAULT_ROOM, 'main'));
$turn_urls = esc_attr(get_option(WPGC_VideoChat_Licensed::OPTION_TURN_URLS, ''));
$turn_username = esc_attr(get_option(WPGC_VideoChat_Licensed::OPTION_TURN_USERNAME, ''));
$turn_credential = esc_attr(get_option(WPGC_VideoChat_Licensed::OPTION_TURN_CREDENTIAL, ''));
$license_key = esc_attr(get_option(WPGC_VideoChat_Licensed::OPTION_LICENSE_KEY, ''));
$license_status = esc_html(get_option(WPGC_VideoChat_Licensed::OPTION_LICENSE_STATUS, 'invalid'));
$license_expires = esc_html(get_option(WPGC_VideoChat_Licensed::OPTION_LICENSE_EXPIRES, ''));
$license_api_base = esc_attr(get_option(WPGC_VideoChat_Licensed::OPTION_LICENSE_API_BASE, 'https://sincotechs.com'));
?>
<div class="wrap">
  <h1>VideoChat Settings</h1>

  <div class="wpgc-card" style="max-width:900px;">
    <h2>License</h2>
    <p>Status: <strong><?php echo $license_status; ?></strong><?php if ($license_expires) { echo ' (expires: ' . $license_expires . ')'; } ?></p>
    <form id="wpgc-license-form">
      <label>License Key<br>
        <input type="text" id="wpgc_license_key" value="<?php echo $license_key; ?>" style="width:100%" placeholder="SINC-XXXX-XXXX-XXXX">
      </label>
      <p><button class="button button-primary">Activate License</button></p>
    </form>
  </div>

  <div class="wpgc-card" style="max-width:900px;">
    <h2>General</h2>
    <form id="wpgc-settings-form">
      <p><label>Default room slug
        <input type="text" id="wpgc_default_room" value="<?php echo esc_attr($default_room); ?>">
      </label></p>
      <p><label>Rules<br>
        <textarea id="wpgc_rules" rows="6" style="width:100%;"><?php echo esc_textarea($rules); ?></textarea>
      </label></p>
      <hr>
      <h2>TURN (optional)</h2>
      <p><small>Comma-separated: <code>turn:turn.example.com:3478, turns:turn.example.com:5349</code></small></p>
      <p><label>TURN URLs<br><input type="text" id="wpgc_turn_urls" style="width:100%" value="<?php echo $turn_urls; ?>"></label></p>
      <p><label>TURN Username<br><input type="text" id="wpgc_turn_username" style="width:100%" value="<?php echo $turn_username; ?>"></label></p>
      <p><label>TURN Credential<br><input type="text" id="wpgc_turn_credential" style="width:100%" value="<?php echo $turn_credential; ?>"></label></p>
      <hr>
      <h2>License Server</h2>
      <p><label>License API Base (WordPress) <small>example: https://sincotechs.com</small><br>
        <input type="url" id="wpgc_license_api_base" style="width:100%" value="<?php echo $license_api_base; ?>">
      </label></p>
      <p><button class="button button-primary">Save Settings</button></p>
    </form>
  </div>
</div>
