<?php

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

// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only parameters no nonce required.
$source      = ! empty( $_GET['source'] ) ? sanitize_text_field( wp_unslash( $_GET['source'] ) ) : '';
$ref         = ! empty( $_GET['ref'] ) ? sanitize_text_field( wp_unslash( $_GET['ref'] ) ) : '';
$p_id        = ! empty( $_GET['p_id'] ) ? absint( $_GET['p_id'] ) : 0;
$proposal_id = ! empty( $_GET['proposal_id'] ) ? absint( $_GET['proposal_id'] ) : 0;
// phpcs:enable WordPress.Security.NonceVerification.Recommended -- Read-only parameters no nonce required.

$invalid = false;

if ( empty( $source ) || empty( $p_id ) || ! in_array( $source, array( 'service', 'job' ), true ) ) {
	$invalid = true;
}

$post_data = get_post( $p_id );

if ( empty( $post_data ) || empty( $post_data->post_type ) ) {
	$invalid = true;
}

if ( $invalid ) {
	$not_found_args = array(
		'title'       => esc_html__( 'Invalid request', 'gigneo' ),
		'description' => esc_html__( 'The request you are looking for is invalid.', 'gigneo' ),
	);
	gigneo_not_found( 'hire', $not_found_args );

	return;
}

$template_args = array(
	'source'      => $source,
	'ref'         => $ref,
	'p_id'        => $p_id,
	'proposal_id' => $proposal_id,
);

if ( 'service' === $source ) {
	gigneo_load_template( 'single/hire/service/fixed', true, $template_args );
}

if ( 'job' === $source ) {
	gigneo_load_template( 'single/hire/job/fixed', true, $template_args );
}
