<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; }
	/**
	 * Helper function to get a list of all supported forms.
	 *
	 * @return array
	 */
function sifency_addons_get_all_forms() {
	$forms = array( '' => __( 'Select a Form', 'sifency-addons' ) );
	if ( class_exists( 'WPCF7_ContactForm' ) ) {
		$cf7_forms = get_posts(
			array(
				'post_type'   => 'wpcf7_contact_form',
				'numberposts' => -1,
			)
		);
		if ( $cf7_forms ) {
			foreach ( $cf7_forms as $form ) {
				$forms[ 'cf7-' . $form->ID ] = '(CF7) ' . $form->post_title;
			}
		}
	}
	if ( function_exists( 'wpforms' ) ) {
		$wpforms = wpforms()->form->get();
		if ( $wpforms ) {
			foreach ( $wpforms as $form ) {
				$forms[ 'wpf-' . $form->ID ] = '(WPForms) ' . $form->post_title;
			}
		}
	}
	if ( post_type_exists( 'metform-form' ) ) {
		$metforms = get_posts(
			array(
				'post_type'   => 'metform-form',
				'numberposts' => -1,
			)
		);
		if ( $metforms ) {
			foreach ( $metforms as $form ) {
				$forms[ 'mf-' . $form->ID ] = '(MetForm) ' . $form->post_title;
			}
		}
	}
	if ( class_exists( 'Ninja_Forms' ) ) {
		$ninja_forms = Ninja_Forms()->form()->get_forms();
		if ( $ninja_forms ) {
			foreach ( $ninja_forms as $form ) {
				$forms[ 'nf-' . $form->get_id() ] = '(Ninja Forms) ' . $form->get_setting( 'title' );
			}
		}
	}
	if ( class_exists( 'GFAPI' ) ) {
		$gf_forms = \GFAPI::get_forms();
		if ( $gf_forms ) {
			foreach ( $gf_forms as $form ) {
				$forms[ 'gf-' . $form['id'] ] = '(Gravity Forms) ' . $form['title'];
			}
		}
	}

	return $forms;
}
