<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Render shortcode with template.
 *
 * @param array  $atts           Shortcode attributes.
 * @param string $template_path  Path to the template file.
 * @param string $tag            Shortcode tag name.
 * @return string                Rendered shortcode HTML.
 * @since 1.0.0
 */
function gigneo_render_shortcode( $atts, $template_path, $tag ) {
	ob_start();

	echo '<div class="gn-shortcode gn-shortcode-' . esc_attr( $tag ) . '">';

	// Make attributes available inside the template
	set_query_var( 'gigneo_shortcode_options', $atts );

	// Get template
	$template = gigneo_get_template( $template_path );

	if ( $template && file_exists( $template ) ) {
		gigneo_load_template( $template_path );
	}

	echo '</div>';

	return ob_get_clean();
}


/**
 * Render hire page shortcode.
 *
 * @param array       $atts    Shortcode attributes.
 * @param string|null $content Shortcode content.
 * @param string      $tag     Shortcode tag.
 * @return string
 * @since 1.0.0
 */
function gigneo_hire_shortcode( $atts = array(), $content = null, $tag = '' ) {
	return gigneo_render_shortcode( $atts, 'single/hire/general', $tag );
}
add_shortcode( 'gigneo_hire', 'gigneo_hire_shortcode' );


/**
 * Render login page shortcode.
 *
 * @param array       $atts    Shortcode attributes.
 * @param string|null $content Shortcode content.
 * @param string      $tag     Shortcode tag.
 * @return string
 * @since 1.0.0
 */
function gigneo_login_shortcode( $atts = array(), $content = null, $tag = '' ) {
	return gigneo_render_shortcode( $atts, 'auth/login', $tag );
}
add_shortcode( 'gigneo_login', 'gigneo_login_shortcode' );


/**
 * Render register page shortcode.
 *
 * @param array       $atts    Shortcode attributes.
 * @param string|null $content Shortcode content.
 * @param string      $tag     Shortcode tag.
 * @return string
 * @since 1.0.0
 */
function gigneo_register_shortcode( $atts = array(), $content = null, $tag = '' ) {
	return gigneo_render_shortcode( $atts, 'auth/register', $tag );
}
add_shortcode( 'gigneo_register', 'gigneo_register_shortcode' );


/**
 * Render forgot-password shortcode.
 *
 * @param array       $atts    Shortcode attributes.
 * @param string|null $content Shortcode content.
 * @param string      $tag     Shortcode tag.
 * @return string
 * @since 1.0.0
 */
function gigneo_forgot_password_shortcode( $atts = array(), $content = null, $tag = '' ) {
	return gigneo_render_shortcode( $atts, 'auth/forgot-password', $tag );
}
add_shortcode( 'gigneo_forgot_password', 'gigneo_forgot_password_shortcode' );


/**
 * Render freelancers archive shortcode.
 *
 * @param array       $atts    Shortcode attributes.
 * @param string|null $content Shortcode content.
 * @param string      $tag     Shortcode tag.
 * @return string
 * @since 1.0.0
 */
function gigneo_freelancers_shortcode( $atts = array(), $content = null, $tag = '' ) {
	return gigneo_render_shortcode( $atts, 'archive/freelancer/layout-1', $tag );
}
add_shortcode( 'gigneo_freelancers', 'gigneo_freelancers_shortcode' );


/**
 * Render employers archive shortcode.
 *
 * @param array       $atts    Shortcode attributes.
 * @param string|null $content Shortcode content.
 * @param string      $tag     Shortcode tag.
 * @return string
 * @since 1.0.0
 */
function gigneo_employers_shortcode( $atts = array(), $content = null, $tag = '' ) {
	return gigneo_render_shortcode( $atts, 'archive/employer/layout-1', $tag );
}
add_shortcode( 'gigneo_employers', 'gigneo_employers_shortcode' );


/**
 * Render services archive shortcode.
 *
 * @param array       $atts    Shortcode attributes.
 * @param string|null $content Shortcode content.
 * @param string      $tag     Shortcode tag.
 * @return string
 * @since 1.0.0
 */
function gigneo_services_shortcode( $atts = array(), $content = null, $tag = '' ) {
	return gigneo_render_shortcode( $atts, 'archive/service/layout-1', $tag );
}
add_shortcode( 'gigneo_services', 'gigneo_services_shortcode' );


/**
 * Render jobs archive shortcode.
 *
 * @param array       $atts    Shortcode attributes.
 * @param string|null $content Shortcode content.
 * @param string      $tag     Shortcode tag.
 * @return string
 * @since 1.0.0
 */
function gigneo_jobs_shortcode( $atts = array(), $content = null, $tag = '' ) {
	return gigneo_render_shortcode( $atts, 'archive/job/layout-1', $tag );
}
add_shortcode( 'gigneo_jobs', 'gigneo_jobs_shortcode' );
