<?php
/**
 * My Account — the claim form.
 *
 * A partial because two screens need the same one: the warranties list and a
 * single warranty's page. It was written inline in the list, so the button on
 * the single page would have had no form to open — and copying it would have
 * left two sets of field IDs for one handler to bind to.
 *
 * Hidden until a warranty's button is pressed. The frontend bundle binds by
 * class rather than by page, so it works wherever this is included.
 *
 * @package WarrantyCart
 * @version 2.1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

?>
<?php /* Hidden until a warranty's button is pressed. */ ?>
	<form class="warranty-claim-form" id="warranty-claim-form" hidden>
		<h3 class="warranty-claim-form__title">
			<?php \esc_html_e( 'File a claim', 'warranty-cart' ); ?>
			<span class="warranty-claim-form__subject" id="warranty-claim-subject-name"></span>
		</h3>

		<input type="hidden" name="warranty_id" id="warranty-claim-warranty-id" value="">

		<p class="form-row">
			<label for="warranty-claim-subject">
				<?php \esc_html_e( 'Summary', 'warranty-cart' ); ?>
				<span class="required">*</span>
			</label>
			<input
				type="text"
				id="warranty-claim-subject"
				name="subject"
				required
				maxlength="255"
				placeholder="<?php \esc_attr_e( 'Compressor has stopped working', 'warranty-cart' ); ?>"
			>
		</p>

		<p class="form-row">
			<label for="warranty-claim-description">
				<?php \esc_html_e( 'What has gone wrong?', 'warranty-cart' ); ?>
				<span class="required">*</span>
			</label>
			<textarea
				id="warranty-claim-description"
				name="description"
				rows="5"
				required
				placeholder="<?php \esc_attr_e( 'When it started, what you were doing, and anything you have already tried.', 'warranty-cart' ); ?>"
			></textarea>
		</p>

		<?php
		/*
		 * Evidence.
		 *
		 * `accept` narrows the file picker to what the server will take, so a
		 * customer photographing a broken appliance on a phone is offered the
		 * camera rather than every file on the device — and does not choose a
		 * file that is refused after the upload.
		 */
		$max_files = \WarrantyCart\Core\ClaimAttachments::max_per_claim();
		$max_size  = \size_format( \WarrantyCart\Core\ClaimAttachments::max_bytes() );
		$required  = \WarrantyCart\Core\ClaimAttachments::proof_required();
		?>
		<p class="form-row">
			<label for="warranty-claim-attachments">
				<?php \esc_html_e( 'Photographs or receipt', 'warranty-cart' ); ?>
				<?php if ( $required ) : ?>
					<span class="required">*</span>
				<?php endif; ?>
			</label>
			<input
				type="file"
				id="warranty-claim-attachments"
				name="attachments[]"
				multiple
				accept="image/jpeg,image/png,image/gif,image/webp,image/heic,application/pdf"
				<?php echo $required ? 'required' : ''; ?>
			>
			<span class="warranty-claim-form__hint">
				<?php
				printf(
					/* translators: 1: maximum number of files, 2: maximum size of one file, e.g. "5 MB". */
					\esc_html( \_n( 'Up to %1$d file, %2$s each.', 'Up to %1$d files, %2$s each.', $max_files, 'warranty-cart' ) ),
					(int) $max_files,
					\esc_html( $max_size )
				);
				?>
			</span>
		</p>

		<p class="form-row warranty-claim-form__actions">
			<button type="submit" class="button alt" id="warranty-claim-submit">
				<?php \esc_html_e( 'Submit claim', 'warranty-cart' ); ?>
			</button>
			<button type="button" class="button warranty-claim-cancel">
				<?php \esc_html_e( 'Cancel', 'warranty-cart' ); ?>
			</button>
		</p>
	</form>
