<?php
if(!defined('ABSPATH')){
    exit; // Exit if accessed directly
}
?>

<form method="post" action="options.php" id="" class="egps_options_form">

    <?php settings_fields( 'egps_photo_data' ); ?>
    <?php do_settings_sections( 'egps_photo_data' ); ?>


    <h3>Photo's Metadata settings</h3>
    <p>Select the metadata fields that you want to show on the frontend page, next to the photos.</p>


    <?php

        $options = get_option('egps_photometa');

        $chboxes = [
            "size_px"   => array(
                "name"      => "size_px",
                "title"     => "Size (w x h)",
                "label"     => ""
            ),
            "size_mpx"  => array(
                "name"      => "size_mpx",
                "title"     => "Size (MegaPixel)",
                "label"     => ""
            ),
            "camera"  => array(
                "name"      => "camera",
                "title"     => "Camera",
                "label"     => ""
            ),
            "focal_length"  => array(
                "name"      => "focal_length",
                "title"     => "Focal length",
                "label"     => ""
            ),
            "aperture"  => array(
                "name"      => "aperture",
                "title"     => "Aperture",
                "label"     => ""
            ),
            "iso"  => array(
                "name"      => "iso",
                "title"     => "ISO",
                "label"     => ""
            ),
            "creationTime"  => array(
                "name"      => "creationTime",
                "title"     => "Date",
                "label"     => ""
            )
        ];
         
        
    ?>

    <table class="form-table" role="presentation">
        <tbody>

        <?php
            foreach($chboxes as $chb){
                echo '
                    <tr>
                        <th scope="row">'.esc_html($chb["title"]).'</th>
                        <td>
                            <div class="custom-control custom-switch">
                                <input 
                                    type="checkbox" 
                                    class="custom-control-input" 
                                    id="'.esc_html($chb["name"]).'" 
                                    name="egps_photometa[' . esc_html($chb["name"]) . ']"';
                                    $btnison = (isset($options[$chb["name"]]) && $options[$chb["name"]] == 'on') ? ' checked ' : ''; 
                                    echo esc_html($btnison);
                                    echo '>
                                <label class="custom-control-label" for="'. esc_html($chb["name"]) .'"></label>
                            </div>
                        </td>
                    </tr>
                ';
            }
        ?>

        </tbody>
    </table>

    <?php submit_button(); ?>

</form>


