<?php

namespace CarDealerPress\Templates\Inventory;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use CarDealerPress\includes\helpers\helpers;
use CarDealerPress\Includes\Helpers\Option;

$admin_options = Option::get_cdp_admin_options();


$autocheck_error = '';

if ( null !== $admin_options && 0 !== helpers::company_id() ) {

	$host          = $admin_options['admin']['help']['host'];
	$autocheck_url = $host . '/companies/' . helpers::company_id() . '/autochecks/';

	if ( isset( $this->autocheck_vin ) ) {
		$autocheck_url .= $this->autocheck_vin . '/';
	} else {
		$autocheck_url = '';
	}
} else {
	$autocheck_url = '';
}

if ( ! empty( $autocheck_url ) ) {
	if ( extension_loaded( "curl" ) ) {
		$site = get_proxy_site_page( $autocheck_url );

		if ( 200 !== $site['http_code'] ) {
			$autocheck_error = '<h1 style="color:#FF0000;">Vehicle Not found in VMS system.<br>AC_ERROR #002</h1>';
		}
	} else {
		$autocheck_error = '<h1 style="color:#FF0000;">Please contact Host provider as curl extension is not installed and is required.<br>AC_ERROR #000</h1>';
	}
} else {
	$autocheck_error = '<h1 style="color:#FF0000;">Admin settings have not been setup to access AutoCheck.<br>AC_ERROR #001</h1>';
}

if ( empty( $autocheck_error ) ) {
	helpers::output_wp_kses( substr( $site['content'], $site['header_size'] ) );
} else {
	helpers::output_wp_kses( $autocheck_error );
}
