<?php
/**
 * Dashboard - Doctor Profile
 */

defined( 'ABSPATH' ) || exit;

global $doctor, $wp;

$nonce = isset( $_POST['docpro_profile_val'] ) ? sanitize_text_field( $_POST['docpro_profile_val'] ) : '';

if ( wp_verify_nonce( $nonce, 'docpro_profile' ) ) {

	$data_args   = array(
		'first_name' => isset( $_POST['first_name'] ) ? sanitize_text_field( $_POST['first_name'] ) : '',
		'last_name'  => isset( $_POST['last_name'] ) ? sanitize_text_field( $_POST['last_name'] ) : '',
	);
	$meta_fields = docpro()->metaBoxes->get_meta_fields( 'doctor' );
	$meta_fields = array_map( function ( $field ) {
		return $field['id'];
	}, $meta_fields );

	foreach ( $meta_fields as $meta_key ) {
		$data_args[ $meta_key ] = isset( $_POST[ $meta_key ] ) ? sanitize_text_field( $_POST[ $meta_key ] ) : '';
	}

	if ( $ret = $doctor->update_data( $data_args ) ) {
		wp_safe_redirect( site_url( $wp->request ) );
		exit();
	}
}

?>

<form action="<?php echo esc_url( site_url( $wp->request ) ); ?>" class="add-listing my-profile" method="post">

	<?php docpro()->metaBoxes->render_frontend_user_form_fields( $doctor->ID ); ?>

    <!-- Save Changes -->
    <div class="btn-box">
		<?php wp_nonce_field( 'docpro_profile', 'docpro_profile_val' ); ?>
        <button type="submit" class="theme-btn-one"><?php esc_html_e( 'Save Change', 'docpro' ); ?><i class="icon-Arrow-Right"></i></button>
        <button type="reset" class="cancel-btn"><?php esc_html_e( 'Cancel', 'docpro' ); ?></button>
    </div>
</form>