<?php

/**
 * Class SG_Action_Visit
 */
class SG_Action_Visit extends SG_Extra_Action {

	/**
	 * SG_Action_Visit constructor.
	 */
	public function __construct() {
		$this->slug = 'visit';
		$this->category = 'general';
		$this->title = __( 'Visit a Link', 'giveasap' );
		$this->description = __( 'Rewards the user for visiting a site.', 'giveasap' );
		$this->icon = 'fal fa-link';
	}

	/**
	 * Define the extra fields.
	 *
	 * @return array
	 */
	public function get_fields() {
		$this->fields = array(
			'url' => array(
				'type' => 'url',
				'label' => __( 'URL', 'giveasap' ),
				'id' => 'url',
                'required' => true,
			)
		);

		return parent::get_fields();
	}

	/**
	 * Get the action button.
	 * This is a general button for any action that can be used.
	 * In most cases, it will enable the complete button to submit it.
	 */
	public function action_button() {
		$data = $this->get_admin_data();
		$url  = $data['url'];

		if ( ! $url ) {
			return '';
		}

		if ( false === strpos( $url, 'http' ) ) {
			$prefix = is_ssl() ? 'https://' : 'http://';
			$url = $prefix . $url;
		}

		?>
		<a target="_blank" data-check-action class="sg_extra_action_button giveasap_button" href="<?php echo esc_attr( $url ); ?>">
			<?php echo $data['button_text']; ?>
		</a>
		<?php
	}
}