<?php
/**
 * Save Form as Template View
 *
 * @package Freelance_Studio
 */

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

<div class="wrap fs-wrap">
    <div class="fs-page-header">
        <h1><?php esc_html_e('Save as Template', 'freelance-studio'); ?></h1>
    </div>

    <div class="fs-form-container" style="max-width: 600px;">
        <form method="post">
            <?php wp_nonce_field('fs_save_template', 'fs_template_nonce'); ?>
            <input type="hidden" name="template_action" value="save_as_template">
            <input type="hidden" name="form_id" value="<?php echo esc_attr($form->id); ?>">

            <div class="fs-card">
                <div class="fs-card-body">
                    <?php /* translators: 1. save " value */ ?>
                    <p><?php echo wp_kses_post( sprintf( __('Save "%s" as a reusable template.', 'freelance-studio'), esc_html($form->name))); ?></p>
                    
                    <div class="fs-form-row">
                        <label for="template-name"><?php esc_html_e('Template Name', 'freelance-studio'); ?> <span class="required">*</span></label>
                        <input type="text" id="template-name" name="name" value="<?php echo esc_attr($form->name); ?>" class="regular-text" required>
                    </div>

                    <div class="fs-form-row">
                        <label for="template-description"><?php esc_html_e('Description', 'freelance-studio'); ?></label>
                        <textarea id="template-description" name="description" rows="3" class="large-text"><?php echo esc_textarea($form->description); ?></textarea>
                        <p class="description"><?php esc_html_e('Briefly describe when to use this template.', 'freelance-studio'); ?></p>
                    </div>

                    <div class="fs-form-row">
                        <label for="template-category"><?php esc_html_e('Category', 'freelance-studio'); ?></label>
                        <select id="template-category" name="category">
                            <?php foreach ($categories as $key => $label): ?>
                                <option value="<?php echo esc_attr($key); ?>"><?php echo esc_html($label); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>
                <div class="fs-card-footer">
                    <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-forms&action=edit&id=' . $form->id) ); ?>" class="button">
                        <?php esc_html_e('Cancel', 'freelance-studio'); ?>
                    </a>
                    <button type="submit" class="button button-primary">
                        <?php esc_html_e('Save as Template', 'freelance-studio'); ?>
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
