/*
Theme Name: Indian Matrimonial Theme
Theme URI: https://interasia.ae
Author: Theme Expert
Description: A complete, lightweight, and fully functional Indian Matrimonial theme featuring custom biodata management, community taxonomies, and search.
Version: 1.0.0
Text Domain: indian-matrimony
*/

/* Reset & Global Styles */
* {
    box-sizing: border-box;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f8f9fa;
    color: #333;
    line-height: 1.6;
}
a {
    color: #d91b5c;
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* Theme Layout Utilities */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
    padding: 20px 0;
}
.profile-card {
    border: 1px solid #e1e8ed;
    padding: 20px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    transition: transform 0.2s, box-shadow 0.2s;
    text-align: center;
}
.profile-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px rgba(0,0,0,0.05);
}
.profile-card img {
    max-width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 15px;
}
.search-filter-box {
    background: #fff;
    padding: 25px;
    margin-bottom: 30px;
    border-radius: 12px;
    border: 1px solid #e1e8ed;
}
.search-filter-box select, 
.search-filter-box input {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
}
.badge {
    background: #d91b5c;
    color: #fff;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
    margin-top: 5px;
}
.btn-primary {
    background: #d91b5c;
    color: #fff;
    border: none;
    padding: 12px 20px;
    font-size: 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    width: 100%;
    transition: background 0.2s;
}
.btn-primary:hover {
    background: #b21247;
}
// Automated Sample Data Generator
function matro_insert_sample_data() {
    // Only run this check once so it doesn't duplicate profiles
    if (get_option('matro_sample_data_imported') == 'yes') {
        return;
    }

    $samples = array(
        array(
            'title'      => 'Rahul Sharma',
            'gender'     => 'Groom',
            'age'        => 29,
            'gothra'     => 'Bhardwaj',
            'profession' => 'Senior Software Engineer',
            'religion'   => 'Hindu',
            'caste'      => 'Brahmin',
            'bio'        => 'Software engineer currently working in Dubai. Values tradition as much as modern perspectives.'
        ),
        array(
            'title'      => 'Ananya Patel',
            'gender'     => 'Bride',
            'age'        => 27,
            'gothra'     => 'Kashyap',
            'profession' => 'Interior Designer',
            'religion'   => 'Hindu',
            'caste'      => 'Leva Patel',
            'bio'        => 'Interior designer running her own creative studio in Mumbai. An avid traveler and passionate about art.'
        )
    );

    foreach ($samples as $sample) {
        // Create the post base
        $post_id = wp_insert_post(array(
            'post_title'   => $sample['title'],
            'post_content' => $sample['bio'],
            'post_status'  => 'publish',
            'post_type'    => 'matrimony'
        ));

        if ($post_id) {
            // Insert Custom Meta Fields
            update_post_meta($post_id, '_matro_gender', $sample['gender']);
            update_post_meta($post_id, '_matro_age', $sample['age']);
            update_post_meta($post_id, '_matro_gothra', $sample['gothra']);
            update_post_meta($post_id, '_matro_profession', $sample['profession']);

            // Insert Taxonomies
            wp_set_object_terms($post_id, $sample['religion'], 'religion');
            wp_set_object_terms($post_id, $sample['caste'], 'caste');
        }
    }

    // Mark as imported
    update_option('matro_sample_data_imported', 'yes');
}
add_action('admin_init', 'matro_insert_sample_data');
// Handle Front-End Matrimonial Profile Submissions Safely
function matro_handle_frontend_submission() {
    // Verify security nonce and check that data was posted
    if ( ! isset($_POST['matro_submission_nonce']) || ! wp_verify_nonce($_POST['matro_submission_nonce'], 'matro_submit_profile') ) {
        return;
    }

    // Sanitize user inputs
    $full_name  = sanitize_text_field($_POST['profile_name']);
    $gender     = sanitize_text_field($_POST['profile_gender']);
    $age        = absint($_POST['profile_age']);
    $gothra     = sanitize_text_field($_POST['profile_gothra']);
    $profession = sanitize_text_field($_POST['profile_profession']);
    $religion   = sanitize_text_field($_POST['profile_religion']);
    $caste      = sanitize_text_field($_POST['profile_caste']);
    $bio        = sanitize_textarea_field($_POST['profile_bio']);

    // Create a new post array mapping to our Custom Post Type
    $new_profile = array(
        'post_title'   => $full_name,
        'post_content' => $bio,
        'post_status'  => 'pending', // Keeps submissions as "Pending Review" so you can verify them first
        'post_type'    => 'matrimony'
    );

    // Insert the post into the WordPress database
    $post_id = wp_insert_post($new_profile);

    if ( $post_id && ! is_wp_error($post_id) ) {
        // Update the custom metadata
        update_post_meta($post_id, '_matro_gender', $gender);
        update_post_meta($post_id, '_matro_age', $age);
        update_post_meta($post_id, '_matro_gothra', $gothra);
        update_post_meta($post_id, '_matro_profession', $profession);

        // Assign taxonomies (Religion and Caste)
        wp_set_object_terms($post_id, $religion, 'religion');
        wp_set_object_terms($post_id, $caste, 'caste');

        // Redirect to a success parameter
        wp_redirect( add_query_arg('submission', 'success', $_POST['_wp_http_referer']) );
        exit;
    }
}
add_action('admin_init', 'matro_handle_frontend_submission');
