<?php

namespace html2pdf\templates;

use html2pdf\helpers\html2pdf_template;

class material_transaction extends html2pdf_template
{
    /**
     * @inheritDoc
     */
    public function getHtml($data = null): string
    {
        // self::addImage(self::pathSrc('truckwash-banner-white-compressed.png'), 'Certificate Image', 100, 100, 'center');
        /** Add the styles */
        $html = self::getDefaultStyles();
        /** Add the header */
        $html .= self::getHeader();
        /** Add the issuer company */
        //$html .= self::getIssuerCompany();
        /** Add the registration numbers, time, date and the carried out by */
        $html .= self::getDetails();
        return $html;
    }

    /**
     * Get the HTML details for the wash certificate
     * @notation This method is used to generate the details of the wash certificate. (E.g. registration numbers, time, date and the carried out by)
     * @return string HTML table
     * @see addData() - This method is used to add data to the template.
     */
    public function getDetails(): string
    {
        $tmp = "
            <table class=\"table is-fullwidth is-bordered is-striped\">
		<tr>
			<th></th>
			<th></th>
			<th></th>
		</tr>
		<tr>
			<td>Truck #:</td>
			<td>" . htmlspecialchars($this->getKey('reg_1'), ENT_QUOTES, 'UTF-8') . "</td>
			<td>" . htmlspecialchars($this->getKey('date'), ENT_QUOTES, 'UTF-8') . "</td>
		</tr>
		<tr>
			<td>Trailer #:</td>
			<td>" . htmlspecialchars($this->getKey('reg_2'), ENT_QUOTES, 'UTF-8') . "</td>
			<td>
				Ref #: " . htmlspecialchars($this->getKey('reference'), ENT_QUOTES, 'UTF-8') . "
			</td>
		</tr>
		<tr>
			<td>Customer:</td>
			<td>" . htmlspecialchars($this->getKey('customer_name'), ENT_QUOTES, 'UTF-8') . "</td>
			<td></td>
		</tr>
	</table>
	<table class=\"table is-fullwidth is-bordered is-striped\">
		<tr>
			<th
			style=\"width: 45%\"
			>Modtaget (Antal)</th>
			<th
			style=\"width: 10%\"
			></th>
			<th
			style=\"width: 45%\"
			>Udleveret (Antal)</th>
		</tr>";
        foreach ( self::getProducts() as $product ) {
            $tmp .= "<tr>";
            if (isset($product['received'])) {
                $tmp .= '<td>' . $product['received'] . '</td>';
            } else {
                $tmp .= '<td></td>';
            }
            $tmp .= "<td>" . $product['name'] . "</td>";
            $tmp .= '<td>';
            $tmp .= '<div class="is-flex is-justify-content-center">';
            $tmp .= self::addImage(self::pathSrc($product['image']));
            $tmp .= '</div>';
            $tmp .= '</td>';
            if (isset($product['delivered'])) {
                $tmp .= '<td>' . $product['delivered'] . '</td>';
            } else {
                $tmp .= '<td></td>';
            }
            $tmp .= '</tr>';
        }
        $tmp .= "
	</table>
	<table class=\"table is-fullwidth is-bordered is-striped mb-0\">
		<tr>
			<th style=\"width: 25%; display: none\"></th>
			<th style=\"width: 25%; display: none\"></th>
			<th style=\"width: 25%; display: none\"></th>
			<th style=\"width: 25%; display: none\"></th>
		</tr>
		<tr>
			<td>Restacking</td>
			<td>{RESTACKING}</td>
			<td>Tag removal</td>
			<td>{TAG_REMOVAL}</td>
		</tr>
		<tr>
			<td>Trailer washed</td>
			<td>{TRUCK_WASHED}</td>
			<td>Trailer bond number</td>
			<td>" . htmlspecialchars($this->getKey('seal_number'), ENT_QUOTES, 'UTF-8') . "</td>
		</tr>
	</table>

	<table class=\"table is-fullwidth is-bordered is-striped mb-0\">
		<tr>
			<th>Remarks</th>
		</tr>
		<tr>
			<td>" . htmlspecialchars($this->getKey('notes'), ENT_QUOTES, 'UTF-8') . "</td>
		</tr>
	</table>
	<table class=\"table is-fullwidth is-bordered is-striped mb-0\">
		<tr>
			<th
			style=\"width: 50%;\"
			>Certification</th>
			<th
			style=\"width: 50%;\"
			>Operator</th>
		</tr>
		<tr>
			<td>This certifies that the trailer has been washed with an appropriate soap and rinsed with water. The driver has visually inspected the results of the wash. Data sheets can be obtained from Copenhagen Truck Wash.</td>
			<td>" . htmlspecialchars($this->getKey('carried_out_by'), ENT_QUOTES, 'UTF-8') . "</td>
		</tr>
	</table>
        ";
        return $tmp;
    }

    private function getProducts(): array
    {
        return [
            [
                'name' => 'Euro hooks (BIG)',
                'delivered' => self::getKey('delivered_euro_hooks_big') ?? 0,
                'received' => self::getKey('received_euro_hooks_big') ?? 0,
                'image' => 'euro_hooks_big.png',
            ],
            [
                'name' => 'TNC hooks (SMALL)',
                'delivered' => self::getKey('delivered_tnc_hooks_small') ?? 0,
                'received' => self::getKey('received_tnc_hooks_small') ?? 0,
                'image' => 'tnc_hooks_small.png',
            ],
            [
                'name' => 'Red hooks',
                'delivered' => self::getKey('delivered_red_hooks') ?? 0,
                'received' => self::getKey('received_red_hooks') ?? 0,
                'image' => 'red_hooks.png',
            ],
            [
                'name' => 'E2 boxes',
                'delivered' => self::getKey('delivered_e2_boxes') ?? 0,
                'received' => self::getKey('received_e2_boxes') ?? 0,
                'image' => 'e2_boxes.png',
            ],
            [
                'name' => 'Christmas trees',
                'delivered' => self::getKey('delivered_christmas_trees') ?? 0,
                'received' => self::getKey('received_christmas_trees') ?? 0,
                'image' => 'christmas_trees.png',
            ],
            [
                'name' => 'Euro pallets',
                'delivered' => self::getKey('delivered_euro_pallets') ?? 0,
                'received' => self::getKey('received_euro_pallets') ?? 0,
                'image' => 'euro_pallets.png',
            ],
            [
                'name' => 'H1 pallets',
                'delivered' => self::getKey('delivered_h1_pallets') ?? 0,
                'received' => self::getKey('received_h1_pallets') ?? 0,
                'image' => 'h1_pallets.png',
            ],
        ];
    }

    /**
     * Get the HTML provider details for the wash certificate
     * @notation This method is used to generate the provider details of the wash certificate. (E.g. department, company name, address, zip, city, phone prefix, phone, email and website)
     * @return string HTML table
     * @see addData() - This method is used to add data to the template.
     */
    public function getProviderDetails(): string
    {
        return '
            <table style="width: 80%; border-collapse: collapse; margin-left: 10%; margin-right: 10%; align-content: space-evenly;">
                <tr>
                    <!-- Service provider -->
                    <td style="width: 33%; padding: 10px; align-content: center; text-align: center">
                        <strong>Service Provider</strong>
                        <br>' . self::getCompanyName() . '
                        <br>' . self::getCompanyAddress() . '
                        <br>' . self::getCompanyZip() . ' ' . self::getCompanyCity() . '
                       
                    </td>
                    <!-- Contact details -->
                    <td style="width: 33%; padding: 10px; align-content: center; text-align: center">
                        <strong>Contact Details</strong>
                        <br>+' . self::getCompanyPhoneCountryCode() . ' ' . self::getCompanyPhone() . '
                        <br>' . self::getCompanyEmail() . '
                    </td>
                    <!-- Operator -->
                    <td style="width: 33%; padding: 10px; align-content: center; text-align: center">
                        <strong>Carried Out By</strong> 
                        <br>' . htmlspecialchars($this->getKey('carried_out_by'), ENT_QUOTES, 'UTF-8') . '
                    </td>
                </tr>
            </table>
        ';
    }

    /**
     * Get the regarding this document
     * @notation This method is used to generate the regarding this document.
     * @param string $language Language code (e.g. 'DK', 'EN', etc.)
     * @return string HTML table
     */
    public function getRegardingThisDocument(string $language = 'DK'): string
    {
        $translations = [
            'DK' => [
                'Angående dette dokument',
                'Der kvitteres herved for udførelse af indvendig vask af denne trailer. Vasken er udført med en godkendt sæbe til formålet – samt afskyllet med vand bagefter.',
                'Der er udført egenkontrol af vasken, Herved bekræftes det at vasken er udført optimalt.',
                'Datablade kan rekvireres hos Copenhagen Truck Wash.',
                'Bakterielle prøver bør tages umiddelbart efter vask, dog max 3 timer efter. Prøven skal tages på et tørt sted og ikke på gulvet',
            ],
            'EN' => [
                'Regarding this document',
                'This is hereby confirmed for the performance of internal washing of this trailer. The wash has been performed with an approved soap for the purpose - and rinsed with water afterwards.',
                'Self-control of the wash has been performed, hereby confirming that the wash has been performed optimally.',
                'Data sheets can be requested from Copenhagen Truck Wash.',
                'Bacterial samples should be taken immediately after washing, but no later than 3 hours after. The sample should be taken in a dry place and not on the floor.',
            ],
        ];
        return '
            <table style="width: 80%; border-collapse: collapse; margin-top: 20px; margin-left: 10%; margin-right: 10%; align-content: space-between;">
                <tr>
                    <!-- Regarding this document -->
                    <td style="width: 100%; padding: 10px; align-content: center; text-align: left">
                        <strong>' . htmlspecialchars($translations[$language][0], ENT_QUOTES, 'UTF-8') . '</strong>
                        <br>' . htmlspecialchars($translations[$language][1], ENT_QUOTES, 'UTF-8') . '
                        <br>' . htmlspecialchars($translations[$language][2], ENT_QUOTES, 'UTF-8') . '
                        <br>' . htmlspecialchars($translations[$language][3], ENT_QUOTES, 'UTF-8') . '
                        <br>' . htmlspecialchars($translations[$language][4], ENT_QUOTES, 'UTF-8') . '
                    </td>
                </tr>
            </table>
        ';
    }
}