<?php

namespace EnEchoDropshipTemplate;

use EnEchoWarehouse\EnEchoWarehouse;

if (!class_exists('EnEchoDropshipTemplate')) {

    class EnEchoDropshipTemplate
    {

        /**
         * Convert array to string for table using
         * @param string $index
         * @param array $data
         * @return string
         */
        static public function en_arrange_table_data($index, $data)
        {
            return "<$index> " . implode(" <$index> ", $data) . " </$index>";
        }

        /**
         * Warehouse template
         * @return false|string
         */
        static public function en_load()
        {
            $en_heading = $en_data = [];
            $en_dropship_list = EnEchoWarehouse::get_data(['location' => 'dropship']);

            extract(\EnLocation::en_location_filter_data('dropship'));

            ksort($en_heading);
            ksort($en_data);

            ob_start();
            ?> <!-- Close PHP-->

            <div class="en_location_dropship_main_div">

            <h1><?php _e('Drop ships', 'eniture-technology'); ?></h1>
            <button type="button" onclick="en_show_popup_location(false)"
                    class="button-primary" title="Add Drop Ship"><?php _e('Add', 'eniture-technology'); ?></button>
            <button type="button" class="en_echo_bulk_delete_dropship en_wd_add_dropship_btn button-primary" title="Delete Drop Ships" onclick="return en_echo_delete_bulk_locations(event, 'en_echo_delete_dropship_item', 'dropship');"><?php _e('Delete', 'eniture-technology'); ?></button>
            <p><?php _e('Locations that inventory specific items that are drop shipped to the destination. Use the products settings
                    page to identify it as a drop shipped item and its associated drop ship location. Orders that include drop
                    shipped items will display a single figure for the shipping rate estimate that is equal to the sum of the
                    cheapest option of each shipment required to fulfill the order.', 'eniture-technology'); ?></p>
            <div class="en_echo_dropship_success_message"><strong>Success!</strong> <span>Selected drop ships deleted successfully.</span></div>
            <div class="en_echo_dropship_error_message"><strong>Error!</strong> Please select at least one drop ship to delete.</div>

            <table class="en_location_table en_location_dropship_table">
            <thead>
            <tr>
                <th class="en_wd_dropship_list_heading en_echo_bulk_delete_col">
                    <!-- Bulk delete -->
                    <input type="checkbox" name="en_echo_bulk_delete_dropships" id="en_echo_bulk_delete_dropships" onclick="return en_echo_select_bulk_locations('en_echo_delete_dropship_item', this);" />
                </th>
                <?php echo force_balance_tags(\EnLocation::en_arrange_table_data('th', $en_heading)); ?>
                <th><?php _e('Action', 'eniture-technology'); ?></th>
            </tr>
            </thead>

            <?php
            // Start PHP

            echo force_balance_tags( \EnLocation::en_arrange_location_table_row($en_dropship_list, $en_data, 0));

            echo '</table>';

            echo '</div>';

            return ob_get_clean();
        }

    }

}