<?php
$rmDisplayData = [
	'icd_1' => [
		'title' => 'ICD 1',
		'reason' => $record->rm_reason_icd1,
		'description' => $record->rm_reason_icd1description
	],
	'icd_2' => [
		'title' => 'ICD 2',
		'reason' => $record->rm_reason_icd2,
		'description' => $record->rm_reason_icd2description
	],
	'icd_3' => [
		'title' => 'ICD 3',
		'reason' => $record->rm_reason_icd3,
		'description' => $record->rm_reason_icd3description
	],
	'icd_4' => [
		'title' => 'ICD 4',
		'reason' => $record->rm_reason_icd4,
		'description' => $record->rm_reason_icd4description
	],
];
if($recordType === 'NOTE'){
	$rmDisplayData['icd_1']['reason'] = $record->note_reason_icd1;
	$rmDisplayData['icd_1']['description'] = $record->note_reason_icd1description;
	$rmDisplayData['icd_2']['reason'] = $record->note_reason_icd2;
	$rmDisplayData['icd_2']['description'] = $record->note_reason_icd2description;
	$rmDisplayData['icd_3']['reason'] = $record->note_reason_icd3;
	$rmDisplayData['icd_3']['description'] = $record->note_reason_icd3description;
	$rmDisplayData['icd_4']['reason'] = $record->note_reason_icd4;
	$rmDisplayData['icd_4']['description'] = $record->note_reason_icd4description;
}

	$submitUrl = null;
	if(@$recordType === 'CLIENT') $submitUrl = '/api/client/putRmReasons';
	if(@$recordType === 'NOTE') $submitUrl = '/api/note/putReasons';
	if(@$recordType === 'CARE_MONTH') $submitUrl = '/api/careMonth/putRmReasons';
?>
<div moe>
	<a start show onclick="return refreshICDs()"><i class="fas fa-edit on-hover-opaque"></i></a>
	<form url="{{ $submitUrl }}" class="mcp-theme-1">
		<input type="hidden" name="uid" value="{{$record->uid}}">
		<div>
			<table class="table table-sm table-bordered">
				<thead class="bg-light">
					<tr>
						<th class="border-bottom-0">ICD</th>
						<th class="border-bottom-0">Description</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>
							<input type="text" class="icd-input" icd-autocomplete-code data-target="input[name=reasonIcd1Description]" name="reasonIcd1" value="{{ $rmDisplayData['icd_1']['reason'] }}" placeholder="ICD 1" />
						</td>
						<td>
							<input id="" type="text" class="form-control form-control-sm" icd-autocomplete-description name="reasonIcd1Description" value="{{ $rmDisplayData['icd_1']['description'] }}">
						</td>
					</tr>
					<tr>
						<td>
							<input type="text" class="icd-input" icd-autocomplete-code name="reasonIcd2" data-target="input[name=reasonIcd2Description]" value="{{ $rmDisplayData['icd_2']['reason'] }}" placeholder="ICD 2" />
						</td>
						<td>
							<input type="text" class="form-control form-control-sm" icd-autocomplete-description name="reasonIcd2Description" value="{{ $rmDisplayData['icd_2']['description'] }}">
						</td>
					</tr>
					<tr>
						<td>
							<input type="text" class="icd-input" icd-autocomplete-code name="reasonIcd3" data-target="input[name=reasonIcd3Description]" value="{{ $rmDisplayData['icd_3']['reason'] }}" placeholder="ICD 3" />
						</td>
						<td>
							<input type="text" class="form-control form-control-sm" icd-autocomplete-description name="reasonIcd3Description" value="{{ $rmDisplayData['icd_3']['description'] }}">
						</td>
					</tr>
					<tr>
						<td>
							<input type="text" class="icd-input" icd-autocomplete-code name="reasonIcd4" data-target="input[name=reasonIcd4Description]" value="{{ $rmDisplayData['icd_4']['reason'] }}" placeholder="ICD 4" />
						</td>
						<td>
							<input type="text" class="form-control form-control-sm" icd-autocomplete-description name="reasonIcd4Description" value="{{ $rmDisplayData['icd_4']['description'] }}">
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<div class="mb-2">
			<label class="font-weight-bold mb-1">{{ $recordType !== 'NOTE' ? 'RM' : '' }} Reason Memo:</label>
			<input type="text" class="form-control form-control-sm" name="reasonMemo" value="{{ $recordType === 'NOTE' ? $record->note_reason_memo : $record->rm_reason_memo }}">
		</div>
		<div>
			<button submit class="btn btn-sm btn-primary mr-1">Submit</button>
			<button cancel class="btn btn-sm btn-default border">Cancel</button>
		</div>
	</form>
</div>
<script type="text/javascript">
	function refreshICDs() {
		if (currentOrder) {
			$('[name=reasonIcd1]').val(currentOrder['reasonIcd1']);
			$('[name=reasonIcd1Description]').val(currentOrder['reasonIcd1Description']);
			$('[name=reasonIcd2]').val(currentOrder['reasonIcd2']);
			$('[name=reasonIcd2Description]').val(currentOrder['reasonIcd2Description']);
			$('[name=reasonIcd3]').val(currentOrder['reasonIcd3']);
			$('[name=reasonIcd3Description]').val(currentOrder['reasonIcd3Description']);
			$('[name=reasonIcd4]').val(currentOrder['reasonIcd4']);
			$('[name=reasonIcd4Description]').val(currentOrder['reasonIcd4Description']);
		}
	}
</script>
