<?php
	/**
	 * Main Settings
	 *
	 * @package EASYFUA
	 */

	defined( 'ABSPATH' ) || exit;

	$lang        = easyfua_lang();
	$option_name = 'easyfua_settings' . $lang;
	$settings    = get_option( $option_name );
?>
	<h2><?php esc_html_e( 'Uploader Text', 'easy-file-upload-approval' ); ?></h2>
	<table class="form-table" role="presentation">
		<tbody>
			<tr>
				<th scope="row"><?php esc_html_e( 'Drag & Drop Text', 'easy-file-upload-approval' ); ?></th>
				<td class="easyfua-text-info">
					<div><input type="text" placeholder="Drag & Drop Files Here" name="<?php echo esc_attr( $option_name ); ?>[text]" class="regular-text" value="<?php echo esc_attr( easyfua_settings( 'text' ) ); ?>"></div>
					<div style="margin: 10px 0;"><input type="text" placeholder="or" name="<?php echo esc_attr( $option_name ); ?>[or]" value="<?php echo esc_attr( easyfua_settings( 'or' ) ); ?>" style="width: 60px;"></div>
					<div><input type="text" placeholder="Browse" name="<?php echo esc_attr( $option_name ); ?>[browse]" class="regular-text" value="<?php echo esc_attr( easyfua_settings( 'browse' ) ); ?>"></div>
				</td>
			</tr>
		</tbody>
	</table>
	<h2><?php esc_html_e( 'Display Uploader', 'easy-file-upload-approval' ); ?></h2>
	<table class="form-table" role="presentation">
		<tbody>
			<tr>
				<th scope="row"><?php esc_html_e( 'Show Uploader On', 'easy-file-upload-approval' ); ?></th>
				<td>
					<select class="regular-text" name="<?php echo esc_attr( $option_name ); ?>[display_on]">
						<?php
						$option_pages = easyfua_get_pages();
						if ( $option_pages ) {
							echo '<option value="">Select page</option>';
							foreach ( $option_pages as $i => $page_id ) {
								echo '<option value="' . esc_attr( $page_id ) . '" ' . selected( easyfua_settings( 'display_on' ), $page_id, false ) . '>' . esc_html( get_the_title( $page_id ) ) . '</option>';
							}
						} else {
							echo '<option value="">No Pages</option>';
						}
						?>
					</select>
					<p class="description">Select page to display the uploader, or use the <code>[easyfua_upload]</code> shortcode.</p>
				</td>
			</tr>
		</tbody>
	</table>
	<h2><?php esc_html_e( 'User Roles', 'easy-file-upload-approval' ); ?></h2>
	<table class="form-table" role="presentation">
		<tbody>
			<tr>
				<th scope="row"><?php esc_html_e( 'Login Required?', 'easy-file-upload-approval' ); ?></th>
				<td>
					<input type="hidden" name="<?php echo esc_attr( $option_name ); ?>[login_required]" value="" >
					<input type="checkbox" id="easyfua-login-req" name="<?php echo esc_attr( $option_name ); ?>[login_required]" value="yes" <?php checked( easyfua_settings( 'login_required' ), 'yes' ); ?>> Yes
					<p class="description">Require users to log in to upload files. If unchecked, guests can upload.</p>
				</td>
			</tr>
			<tr>
				<th scope="row"><?php esc_html_e( 'Roles Allowed to Upload', 'easy-file-upload-approval' ); ?></th>
				<td>
					<select class="regular-text" multiple size="4"name="<?php echo esc_attr( $option_name ); ?>[roles][]" id="easyfua-roles" <?php disabled( easyfua_settings( 'login_required' ) !== 'yes' ); ?>>
						<?php
							$option_roles  = get_editable_roles();
							$allowed_roles = (array) easyfua_settings( 'roles' );
						if ( $option_roles ) {
							echo '<option value="">' . esc_html__( 'Select a role', 'easy-file-upload-approval' ) . '</option>';
							echo '<option value="all" ' . ( in_array( 'all', $allowed_roles, true ) ? 'selected' : '' ) . '>All</option>';
							foreach ( $option_roles as $key => $_role ) {
								echo '<option value="' . esc_attr( $key ) . '"
									' . selected( in_array( $key, $allowed_roles, true ), true, false ) . '>
									' . esc_html( $_role['name'] ) . '</option>';
							}
						} else {
							echo '<option value="">No roles</option>';
						}
						?>
					</select>
				</td>
			</tr>
		</tbody>
	</table>
	<h2><?php esc_html_e( 'Upload Settings', 'easy-file-upload-approval' ); ?></h2>
	<table class="form-table" role="presentation">
		<tbody>
			<tr>
				<th scope="row"><?php esc_html_e( 'Required', 'easy-file-upload-approval' ); ?></th>
				<td>
					<input type="hidden" name="<?php echo esc_attr( $option_name ); ?>[required]" value="" >
					<input type="checkbox" name="<?php echo esc_attr( $option_name ); ?>[required]" value="yes" <?php checked( easyfua_settings( 'required' ), 'yes' ); ?>> Yes
				</td>
			</tr>
			<tr>
				<th scope="row"><?php esc_html_e( 'Upload Label', 'easy-file-upload-approval' ); ?></th>
				<td>
					<input type="text" class="regular-text" name="<?php echo esc_attr( $option_name ); ?>[label]" placeholder="Upload Files" value="<?php echo esc_attr( easyfua_settings( 'label' ) ); ?>">
				</td>
			</tr>
			<tr>
				<th scope="row"><?php esc_html_e( 'Min & Max File Upload', 'easy-file-upload-approval' ); ?></th>
				<td>
					<input type="text" placeholder="min" name="<?php echo esc_attr( $option_name ); ?>[min_upload]" value="<?php echo esc_attr( easyfua_settings( 'min_upload' ) ); ?>">
					<input type="text" name="<?php echo esc_attr( $option_name ); ?>[max_upload]" placeholder="max" value="<?php echo esc_attr( easyfua_settings( 'max_upload' ) ); ?>">
				</td>
			</tr>
			<tr>
				<th scope="row"><?php esc_html_e( 'Supported File Types', 'easy-file-upload-approval' ); ?></th>
				<td>
					<input type="text" placeholder="jpg, jpeg, png, gif, webp, mp4, pdf, eps, docx" name="<?php echo esc_attr( $option_name ); ?>[supported_types]" class="regular-text" value="<?php echo esc_attr( easyfua_settings( 'supported_types' ) ); ?>">
					<p class="description"><?php esc_html_e( 'Enter file types, separated by commas.', 'easy-file-upload-approval' ); ?></p>
				</td>
			</tr>
			<tr>
				<th scope="row"><?php esc_html_e( 'Max File Size (MB)', 'easy-file-upload-approval' ); ?></th>
				<td>
					<input type="text" placeholder="5MB" name="<?php echo esc_attr( $option_name ); ?>[max_file_size]" value="<?php echo esc_attr( easyfua_settings( 'max_file_size' ) ); ?>" class="regular-text">
					<p class="description"><?php esc_html_e( 'Set the maximum size per file (e.g., 5MB). Files exceeding the limit will show an error.', 'easy-file-upload-approval' ); ?></p>
					<?php if ( easyfua_max_upload() && ! easyfua_is_premium() ) : ?>
						<p class="description">
							Your WordPress default maximum upload file size limit is <strong><?php echo esc_html( easyfua_max_upload() ); ?></strong>. <a target="_blank" href="<?php echo esc_url( 'https://codedropz.com/easy-file-upload-approval-pro' ); ?>">Upgrade to Pro</a> to upload larger files.
						</p>
					<?php endif; ?>

				</td>
			</tr>
			<tr>
				<th scope="row"><?php esc_html_e( 'Upload Folder Name', 'easy-file-upload-approval' ); ?></th>
				<td>
					<input type="text" placeholder="<?php echo esc_attr( EASYFUA_UPLOAD_FOLDER ); ?>" id="easyfua-folder-name" name="<?php echo esc_attr( $option_name ); ?>[upload_folder_name]" class="regular-text" value="<?php echo esc_attr( easyfua_settings( 'upload_folder_name' ) ); ?>">
					<p class="description">Upload Path: "/wp-content/uploads/<code id="easyfua-folder-name-text"><?php echo easyfua_settings( 'upload_folder_name' ) ? esc_html( easyfua_settings( 'upload_folder_name' ) ) : esc_html( EASYFUA_UPLOAD_FOLDER ); ?></code>"</p>
				</td>
			</tr>
			<tr>
				<th scope="row"><?php esc_html_e( 'Add Mime Types', 'easy-file-upload-approval' ); ?></th>
				<td>
					<textarea name="<?php echo esc_attr( $option_name ); ?>[mime_types]"
					cols="40" rows="4"
					class="regular-text code"
					placeholder="psd|application/octet-stream&#10;eps|application/postscript&#10;stl|application/octet-stream"><?php echo esc_textarea( trim( easyfua_settings( 'mime_types' ) ) ); ?></textarea>
					<p class="description"><?php esc_html_e( 'Add custom MIME types if the file type is not supported in WordPress.', 'easy-file-upload-approval' ); ?></p>
				</td>
			</tr>
		</tbody>
	</table>
	<h2><?php esc_html_e( 'Auto Delete Files', 'easy-file-upload-approval' ); ?></h2>
	<table class="form-table" role="presentation">
		<tbody>
			<tr>
				<th scope="row"><?php esc_html_e( 'Delete Temp Files', 'easy-file-upload-approval' ); ?></th>
				<td>
					<input type="text" placeholder="24" name="<?php echo esc_attr( $option_name ); ?>[delete_temp_hours]" value="<?php echo esc_attr( easyfua_settings( 'delete_temp_hours' ) ); ?>"> Hour(s)
					<p class="description">
						<?php esc_html_e( 'Temporary files not submitted will be auto-deleted after the set time, or 24 hours by default.', 'easy-file-upload-approval' ); ?>
					</p>
				</td>
			</tr>
		</tbody>
	</table>
