<!DOCTYPE html>
<html>
<head>
	<title><?= lang('quotation_details') ?></title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<?php
	$direction = $this->session->userdata('direction');
	if (!empty($direction) && $direction == 'rtl') {
		$RTL = 'on';
	} else {
		$RTL = config_item('RTL');
	}

	$client_info = $this->quotations_model->check_by(array('client_id' => $quotations_info->client_id), 'tbl_client');
	$user_info = $this->quotations_model->check_by(array('user_id' => $quotations_info->user_id), 'tbl_users');
	$reviewer_info = $this->quotations_model->check_by(array('user_id' => $quotations_info->reviewer_id), 'tbl_users');
	$currency = $this->quotations_model->client_currency_symbol($quotations_info->client_id);
	if (empty($currency)) {
		$currency = $this->quotations_model->check_by(array('code' => config_item('default_currency')), 'tbl_currencies');
	}

	if (!empty($user_info)) {
		if ($user_info->role_id == 1) {
			$user = lang('admin');
		} elseif ($user_info->role_id == 2) {
			$user = lang('client');
		} else {
			$user = lang('staff');
		}
	} else {
		$user = null;
	}

	if (!empty($reviewer_info)) {
		if ($reviewer_info->role_id == 1) {
			$r_user = lang('admin');
		} elseif ($reviewer_info->role_id == 2) {
			$r_user = lang('client');
		} else {
			$r_user = lang('staff');
		}
	} else {
		$r_user = null;
	}

	if (!empty($client_info)) {
		$client_status = $client_info->client_status == 1 ? lang('person') : lang('company');
	} else {
		$client_status = '';
	}
	?>
	<style>
		body {
			margin: 0;
			color: #172033;
			background: #ffffff;
			font: 12px/1.55 DejaVu Sans, Arial, Helvetica, sans-serif;
			min-width: 100%;
			min-height: 100%;
		<?php if (!empty($RTL)) { ?> text-align: right;
		<?php } ?>
		}

		table {
			width: 100%;
			border-collapse: collapse;
			border-spacing: 0;
		<?php if (!empty($RTL)) { ?> text-align: right;
		<?php } ?>
		}

		.page-wrap {
			padding: 18px 22px 24px;
		}

		.brand-shell {
			border: 1px solid #d7deea;
			padding: 18px 20px;
			background: #f8fafc;
			margin-bottom: 18px;
		}

		.brand-logo {
			width: 60px;
			height: 60px;
			background: #ffffff;
			border: 1px solid #d7deea;
			padding: 6px;
		}

		.brand-title {
			font-size: 24px;
			font-weight: 500;
			color: #0f172a;
			margin: 0 0 4px;
		}

		.brand-text {
			font-size: 12px;
			color: #64748b;
			margin: 0;
		}

		.report-meta {
			width: 280px;
		<?php if (!empty($RTL)) { ?> text-align: left;
		<?php } else { ?> text-align: right;
		<?php } ?>
		}

		.header-title {
			font-size: 20px;
			font-weight: 700;
			color: #0f172a;
			margin: 0 0 4px;
			line-height: 1.15;
		}

		.header-subtitle {
			font-size: 10px;
			color: #64748b;
			margin: 0;
			line-height: 1.35;
		}

		.range-chip {
			display: inline-block;
			padding: 4px 0 0;
			background: transparent;
			color: #475569;
			font-size: 9px;
			font-weight: 700;
			letter-spacing: .08em;
			text-transform: uppercase;
		}

		.metrics {
			margin: 0 0 18px;
		}

		.metric-card {
			width: 23.5%;
			border: 1px solid #d7deea;
			background: #ffffff;
			padding: 14px 16px;
			vertical-align: top;
		}

		.metric-gap {
			width: 2%;
		}

		.metric-label {
			font-size: 10px;
			font-weight: 700;
			text-transform: uppercase;
			letter-spacing: .12em;
			color: #64748b;
			margin-bottom: 6px;
		}

		.metric-value {
			font-size: 21px;
			font-weight: 700;
			color: #0f172a;
			margin: 0;
		}

		.metric-note {
			font-size: 11px;
			color: #94a3b8;
			margin-top: 4px;
		}

		.info-grid {
			margin-bottom: 18px;
		}

		.info-card {
			width: 49%;
			border: 1px solid #d7deea;
			background: #ffffff;
			vertical-align: top;
		}

		.info-gap {
			width: 2%;
		}

		.info-head {
			padding: 0;
		}

		.info-body {
			padding: 0;
		}

		.info-label {
			display: inline-block;
			margin-bottom: 12px;
			color: #64748b;
			font-size: 10px;
			font-weight: 700;
			letter-spacing: .12em;
			text-transform: uppercase;
		}

		.party-name {
			margin: 0 0 10px;
			font-size: 16px;
			font-weight: 700;
			color: #0f172a;
		}

		.info-line {
			margin-bottom: 7px;
			color: #475569;
		}

		.quote-box {
			border: 1px solid #d7deea;
			background: #ffffff;
			margin-bottom: 18px;
		}

		.quote-head {
			padding: 0;
		}

		.quote-body {
			padding: 0;
			color: #475569;
		}

		.info-inner,
		.quote-inner {
			padding: 18px 20px 20px;
		}

		.head-cell {
			padding: 16px 20px;
			background: #1e293b;
			color: #f8fafc;
			font-size: 11px;
			font-weight: 700;
			letter-spacing: .06em;
			text-transform: uppercase;
		}

		.quote-title {
			margin: 0 0 6px;
			font-size: 13px;
			font-weight: 700;
			color: #0f172a;
		}

		.quote-answer {
			margin: 0 0 16px;
			word-wrap: break-word;
		}

		.quote-item {
			margin: 0 0 6px 0;
		}
	</style>
</head>
<body>
	<?php
	$rootPath = defined('ROOTPATH') ? ROOTPATH : FCPATH;
	$img = $rootPath . '/' . config_item('company_logo');
	$a = file_exists($img);
	if (empty($a)) {
		$img = base_url() . config_item('company_logo');
	}
	if (!file_exists($img)) {
		$img = $rootPath . '/' . 'uploads/default_logo.png';
	}
	?>
	<div class="page-wrap">
		<div class="brand-shell">
			<table>
				<tr>
					<td style="width: 84px; border: 0;">
						<img class="brand-logo" src="<?= $img ?>" alt="<?= config_item('company_name') ?>">
					</td>
					<td style="border: 0;">
						<p class="brand-title"><?= config_item('company_name') ?></p>
						<p class="brand-text"><?= config_item('company_address') ?></p>
					</td>
					<td class="report-meta" style="border:0;">
						<p class="header-title"><?= lang('quotation_details') ?></p>
						<p class="header-subtitle">Quotation request profile, status summary, and submitted response details.</p>
						<span class="range-chip"><?= lang('generated_on') ?> <?= display_date(date('Y-m-d')) ?></span>
					</td>
				</tr>
			</table>
		</div>

		<table class="metrics">
			<tr>
				<td class="metric-card">
					<div class="metric-label"><?= lang('client') ?></div>
					<p class="metric-value"><?= !empty($quotations_info->name) ? $quotations_info->name : '-' ?></p>
					<div class="metric-note"><?= !empty($client_status) ? $client_status : lang('quotation') ?></div>
				</td>
				<td class="metric-gap"></td>
				<td class="metric-card">
					<div class="metric-label"><?= lang('date') ?></div>
					<p class="metric-value"><?= display_date($quotations_info->quotations_date) ?></p>
					<div class="metric-note"><?= lang('quotation_details') ?></div>
				</td>
				<td class="metric-gap"></td>
				<td class="metric-card">
					<div class="metric-label"><?= lang('status') ?></div>
					<p class="metric-value"><?= $quotations_info->quotations_status == 'completed' ? lang('completed') : lang('pending') ?></p>
					<div class="metric-note"><?= !empty($user_info->username) ? $user_info->username : '-' ?></div>
				</td>
				<td class="metric-gap"></td>
				<td class="metric-card">
					<div class="metric-label"><?= lang('amount') ?></div>
					<p class="metric-value"><?= !empty($quotations_info->quotations_amount) ? display_money($quotations_info->quotations_amount, $currency->symbol) : display_money(0, $currency->symbol) ?></p>
					<div class="metric-note"><?= lang('quotation') ?></div>
				</td>
			</tr>
		</table>

		<table class="info-grid">
			<tr>
				<td class="info-card">
					<table>
						<tr>
							<td class="head-cell" style="border:0;"><?= lang('quotation_details') ?></td>
						</tr>
					</table>
					<div class="info-body">
						<table>
							<tr>
								<td class="info-inner" style="border:0;">
									<span class="info-label"><?= lang('client') ?></span>
									<p class="party-name"><?= !empty($quotations_info->name) ? $quotations_info->name : '-' ?><?= !empty($client_status) ? ' ' . $client_status : '' ?></p>
									<div class="info-line"><?= lang('email') ?>: <?= !empty($quotations_info->email) ? $quotations_info->email : '-' ?></div>
									<div class="info-line"><?= lang('mobile') ?>: <?= !empty($quotations_info->mobile) ? $quotations_info->mobile : '-' ?></div>
									<div class="info-line"><?= lang('date') ?>: <?= display_date($quotations_info->quotations_date) ?></div>
									<div class="info-line"><?= lang('status') ?>: <?= $quotations_info->quotations_status == 'completed' ? lang('completed') : lang('pending') ?></div>
									<div class="info-line"><?= lang('generated_by') ?>: <?= (!empty($user_info->username) ? $user_info->username : '-') . (!empty($user) ? ' (' . $user . ')' : '') ?></div>
									<?php if (!empty($reviewer_info)) { ?>
										<div class="info-line"><?= lang('reviewer') ?>: <?= $reviewer_info->username . (!empty($r_user) ? ' (' . $r_user . ')' : '') ?></div>
										<div class="info-line"><?= lang('reviewed_date') ?>: <?= display_date($quotations_info->reviewed_date) ?></div>
									<?php } ?>
									<div class="info-line"><?= lang('amount') ?>: <?= !empty($quotations_info->quotations_amount) ? display_money($quotations_info->quotations_amount, $currency->symbol) : display_money(0, $currency->symbol) ?></div>
								</td>
							</tr>
						</table>
					</div>
				</td>
				<td class="info-gap"></td>
				<td class="info-card">
					<table>
						<tr>
							<td class="head-cell" style="border:0;"><?= lang('comments') ?></td>
						</tr>
					</table>
					<div class="info-body">
						<table>
							<tr>
								<td class="info-inner" style="border:0;">
									<span class="info-label"><?= lang('notes') ?></span>
									<p class="quote-answer"><?= !empty($quotations_info->notes) ? strip_html_tags($quotations_info->notes) : lang('nothing_to_display') ?></p>
								</td>
							</tr>
						</table>
					</div>
				</td>
			</tr>
		</table>

		<div class="quote-box">
			<table>
				<tr>
					<td class="head-cell" style="border:0;"><?= lang('quotaion_form_response') ?></td>
				</tr>
			</table>
			<div class="quote-body">
				<table>
					<tr>
						<td class="quote-inner" style="border:0;">
							<?php if (!empty($quotation_details)) : foreach ($quotation_details as $v_q_details) : ?>
								<p class="quote-title"><?= $v_q_details->quotation_form_data ?></p>
								<?php if (@unserialize($v_q_details->quotation_data)) {
									$multiple_data = unserialize($v_q_details->quotation_data);
									if (!empty($multiple_data)) {
										foreach ($multiple_data as $key => $value) { ?>
											<p class="quote-item"><?= ($key + 1) . '. ' . $value ?></p>
										<?php }
									}
								} else { ?>
									<p class="quote-answer"><?= $v_q_details->quotation_data ?></p>
								<?php } ?>
							<?php endforeach;
							else : ?>
								<p class="quote-answer"><?= lang('nothing_to_display') ?></p>
							<?php endif; ?>
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
</body>
</html>
