<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

$opts = get_option( 'trendly_ai_post_options', [] );
$regions = [
    'IN' => 'India (Default)', 'US' => 'United States', 'GB' => 'United Kingdom', 'PK' => 'Pakistan', 'CA' => 'Canada',
    'AU' => 'Australia', 'DE' => 'Germany', 'FR' => 'France', 'JP' => 'Japan', 'CN' => 'China', 'BR' => 'Brazil', 'RU' => 'Russia',
    'ZA' => 'South Africa', 'NG' => 'Nigeria', 'KE' => 'Kenya', 'EG' => 'Egypt', 'AE' => 'United Arab Emirates', 'SA' => 'Saudi Arabia',
    'SG' => 'Singapore', 'MY' => 'Malaysia', 'TH' => 'Thailand', 'ID' => 'Indonesia', 'PH' => 'Philippines', 'BD' => 'Bangladesh', 'LK' => 'Sri Lanka'
];
?>
<div class="wrap trendly-wrap">
  <h1><?php echo esc_html__( 'Generate Content', 'trendly-ai-post' ); ?></h1>
  <p class="description"><?php echo esc_html__( 'Fetch trending topics and generate AI-powered posts. Configure defaults in Settings.', 'trendly-ai-post' ); ?></p>

  <div class="trendly-panel">
    <label>
      <?php esc_html_e( 'Region', 'trendly-ai-post' ); ?>
      <select id="trendly-region">
        <?php foreach ( $regions as $code => $label ) : ?>
          <option value="<?php echo esc_attr( $code ); ?>" <?php selected( $opts['region'] ?? 'IN', $code ); ?>><?php echo esc_html( $label ); ?></option>
        <?php endforeach; ?>
      </select>
    </label>
    <label style="margin-left:10px;">
      <?php esc_html_e( 'Length', 'trendly-ai-post' ); ?>
      <select id="trendly-length">
        <option value="short" <?php selected( $opts['default_length'] ?? '', 'short' ); ?>><?php esc_html_e( 'Short', 'trendly-ai-post' ); ?></option>
        <option value="medium" <?php selected( $opts['default_length'] ?? 'medium', 'medium' ); ?>><?php esc_html_e( 'Medium', 'trendly-ai-post' ); ?></option>
        <option value="long" <?php selected( $opts['default_length'] ?? '', 'long' ); ?>><?php esc_html_e( 'Long', 'trendly-ai-post' ); ?></option>
        <option value="extra" <?php selected( $opts['default_length'] ?? '', 'extra' ); ?>><?php esc_html_e( 'Extra-Long', 'trendly-ai-post' ); ?></option>
      </select>
    </label>
    <label style="margin-left:10px;">
      <?php esc_html_e( 'Images', 'trendly-ai-post' ); ?>
      <select id="trendly-images">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
      </select>
    </label>
    <label style="margin-left:10px;">
      <?php esc_html_e( 'Post Status', 'trendly-ai-post' ); ?>
      <select id="trendly-status">
        <option value="draft"><?php esc_html_e( 'Draft', 'trendly-ai-post' ); ?></option>
        <option value="publish"><?php esc_html_e( 'Publish', 'trendly-ai-post' ); ?></option>
      </select>
    </label>
    <button id="trendly-fetch-trends" class="button">
      <?php esc_html_e( 'Fetch Trending Topics', 'trendly-ai-post' ); ?>
    </button>
  </div>

  <div id="trendly-topics" class="trendly-topics" style="margin-top:15px;">
    <table class="widefat fixed trendly-table" style="display:none;">
      <thead>
        <tr>
          <th style="width:60%;"><?php esc_html_e( 'Topic', 'trendly-ai-post' ); ?></th>
          <th style="width:15%;"><?php esc_html_e( 'Action', 'trendly-ai-post' ); ?></th>
          <th style="width:15%;"><?php esc_html_e( 'Status', 'trendly-ai-post' ); ?></th>
          <th style="width:10%;"><?php esc_html_e( 'View', 'trendly-ai-post' ); ?></th>
        </tr>
      </thead>
      <tbody></tbody>
    </table>
  </div>
  <div id="trendly-generate-result" style="margin-top:10px;"></div>
</div>
