<?php

/**
 * Admin form: Tags widget.
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

// Exit if accessed directly
if ( ! defined( 'WPINC' ) ) {
	die;
}
?>
<div class="aiopod aiopod-widget-form aiopod-widget-form-tags aiopod-layout-<?php echo esc_attr( $instance['layout'] ); ?> aiopod-details">
	<div class="aiopod-form-control aiopod-form-control-title">
		<label class="aiopod-form-label" for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title', 'aio-podcast-studio' ); ?></label> 
		<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" class="aiopod-widget-field aiopod-widget-field-title widefat" value="<?php echo esc_attr( $instance['title'] ); ?>" />
	</div>

	<?php
	$i = 0;
	foreach ( $this->fields['tags']['sections'] as $key => $section ) :	?>
		<details<?php if ( 0 === $i ) : ?> open<?php endif; ++$i; ?>>
			<summary>
				<?php echo wp_kses_post( $section['title'] ); ?>
			</summary>
			
			<div class="aiopod-form-controls aiopod-details-content">
				<?php foreach ( $section['fields'] as $field ) :
					$field_name = $field['name'];

					$classes = array();
					$classes[] = 'aiopod-form-control';
					$classes[] = 'aiopod-form-control-' . esc_attr( $field['name'] );

					if ( isset( $field['class'] ) && ! empty( $field['class'] ) ) {
						$classes[] = esc_attr( $field['class'] );
					}
					?>
					<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
						<?php if ( 'header' === $field['type'] ) : ?>
							<label class="aiopod-form-label" for="<?php echo esc_attr( $this->get_field_id( $field_name ) ); ?>"><?php echo esc_html( $field['label'] ); ?></label>
						<?php elseif ( 'text' === $field['type'] || 'url' === $field['type'] || 'number' === $field['type'] ) : ?>
							<label class="aiopod-form-label" for="<?php echo esc_attr( $this->get_field_id( $field_name ) ); ?>"><?php echo esc_html( $field['label'] ); ?></label>
							<input type="text" name="<?php echo esc_attr( $this->get_field_name( $field_name ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( $field_name ) ); ?>" class="aiopod-widget-field aiopod-widget-field-<?php echo esc_attr( $field_name ); ?> widefat" value="<?php echo esc_attr( $instance[ $field_name ] ); ?>" />
						<?php elseif ( 'select' === $field['type'] ) : ?>
							<label class="aiopod-form-label" for="<?php echo esc_attr( $this->get_field_id( $field_name ) ); ?>"><?php echo esc_html( $field['label'] ); ?></label>
							<select name="<?php echo esc_attr( $this->get_field_name( $field_name ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( $field_name ) ); ?>" class="aiopod-widget-field aiopod-widget-field-<?php echo esc_attr( $field_name ); ?> widefat">
								<?php
								foreach ( $field['options'] as $key => $value ) {
									printf(
										'<option value="%s"%s>%s</option>',
										esc_attr( $key ),
										selected( $key, $instance[ $field_name ], false ),
										esc_html( $value )
									);
								}
								?>
							</select>
						<?php elseif ( 'checkbox' === $field['type'] ) : ?>
							<label for="<?php echo esc_attr( $this->get_field_id( $field_name ) ); ?>" class="aiopod-form-label">
								<input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( $field_name ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( $field_name ) ); ?>" class="aiopod-widget-field aiopod-widget-field-<?php echo esc_attr( $field_name ); ?>" value="1" <?php checked( 1, $instance[ $field_name ] ); ?> />
								<?php echo esc_html( $field['label'] ); ?>
							</label>
						<?php elseif ( 'color' === $field['type'] ) : ?>
							<label class="aiopod-form-label" for="<?php echo esc_attr( $this->get_field_id( $field_name ) ); ?>"><?php echo esc_html( $field['label'] ); ?></label> 
							<input type="text" name="<?php echo esc_attr( $this->get_field_name( $field_name ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( $field_name ) ); ?>" class="aiopod-widget-field aiopod-widget-field-<?php echo esc_attr( $field_name ); ?> aiopod-color-picker widefat" value="<?php echo esc_attr( $instance[ $field_name ] ); ?>" />
						<?php endif; ?>

						<?php if ( ! empty( $field['description'] ) ) : // Description ?>
							<p class="description"><?php echo wp_kses_post( $field['description'] ); ?></p>
						<?php endif; ?>
					</div>
				<?php endforeach; ?>
			</div>
		</details>				
	<?php endforeach; ?>
</div>