@model Disco.Web.Models.Job.LogInsuranceModel
@{
    Authorization.RequireAny(Claims.Job.Properties.NonWarrantyProperties.InsuranceClaimFormSent, Claims.Job.Actions.LogInsurance);

    ViewBag.Title = Html.ToBreadcrumb("Jobs", MVC.Job.Index(), string.Format("Job: {0}", Model.Job.Id), MVC.Job.Show(Model.Job.Id), "Lodge Insurance Claim");
}
@using (Html.BeginForm(MVC.Job.LogInsurance(), FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    @Html.HiddenFor(m => m.JobId)
    @Html.HiddenFor(m => m.OrganisationAddressId)
    @Html.HiddenFor(m => m.ProviderId)
    @Html.HiddenFor(m => m.ProviderPropertiesJson)
    <input type="hidden" name="SubmissionAction" value="Submit" />
    <div id="insuranceJobForm" class="form" style="width: 650px">
        <table>
            <tr>
                <th>Internal Job Id:
                </th>
                <td>
                    @Model.JobId
                </td>
            </tr>
            <tr>
                <th>Device Serial Number:
                </th>
                <td>
                    @Model.Job.Device.SerialNumber
                </td>
            </tr>
            <tr>
                <th>Device Model:
                </th>
                <td>
                    @Model.Job.Device.DeviceModel.Manufacturer @Model.Job.Device.DeviceModel.Model
                </td>
            </tr>
            <tr>
                <th>Technician:
                </th>
                <td>
                    @Model.TechUser.DisplayName
                    <div class="smallMessage">
                        Email Address: @Model.TechUser.EmailAddress<br />
                        Phone Number: @Model.TechUser.PhoneNumber
                    </div>
                </td>
            </tr>
            <tr>
                <th style="width: 150px">Address:
                </th>
                <td>
                    <div id="organisationAddressDetails">
                        @Model.OrganisationAddress.Name
                        <div class="smallMessage">
                            <span>@Model.OrganisationAddress.Address</span><br />
                            <span>@Model.OrganisationAddress.Suburb, @Model.OrganisationAddress.Postcode</span><br />
                            <span>@Model.OrganisationAddress.State, @Model.OrganisationAddress.Country</span>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <th>Provider:
                </th>
                <td>
                    @Model.Provider.Name (@Model.Provider.Id) @Model.Provider.PluginManifest.Version.ToString(3)
                </td>
            </tr>
            <tr>
                <th>Disclosed Information
                </th>
                <td>
                    <div id="disclosedInformation">
                        <table>
                            @foreach (var dp in Model.DiscloseProperties)
                            {
                                <tr>
                                    <th>@dp.Key:
                                    </th>
                                    <td>@dp.Value
                                    </td>
                                </tr>   
                            }
                        </table>
                    </div>
                </td>
            </tr>
            @if (Model.Attachments.Count > 0)
            {
                <tr>
                    <th>Sending Attachments</th>
                    <td>
                        <div>
                            <div id="publishJobAttachments">
                                @foreach (var ja in Model.Attachments)
                                {
                                    <input type="hidden" name="AttachmentIds" value="@ja.Id" />
                                    <a href="@Url.Action(MVC.API.Job.AttachmentDownload(ja.Id))" data-attachmentid="@ja.Id" data-mimetype="@ja.MimeType">
                                        <span class="icon" title="@ja.Filename">
                                            <img alt="Attachment Thumbnail" src="@(Url.Action(MVC.API.Job.AttachmentThumbnail(ja.Id)))" /></span>
                                        <span class="comments" title="@ja.Comments">
                                            @{if (!string.IsNullOrEmpty(ja.DocumentTemplateId))
                                              { @ja.DocumentTemplate.Description}
                                              else
                                              { @ja.Comments }}
                                        </span><span class="author">@ja.TechUser.ToStringFriendly()</span><span class="timestamp" data-livestamp="@(ja.Timestamp.ToUnixEpoc())" title="@ja.Timestamp.ToFullDateTime()">@ja.Timestamp.ToFullDateTime()</span>
                                    </a>   
                                }
                            </div>
                        </div>
                    </td>
                </tr>
            }
        </table>
    </div>
    <div id="submitDialog" class="dialog" title="Please Wait">
        <h4><i class="fa fa-lg fa-cog fa-spin" title="Please Wait"></i>Lodging Insurance Claim...</h4>
    </div>
    <script>
        $(function () {
            var dialog = null;

            $('#submitJob').closest('form').submit(function () {
                if (dialog == null) {
                    dialog = $('#submitDialog').dialog({
                        width: 400,
                        height: 160,
                        resizable: false,
                        modal: true,
                        autoOpen: false
                    });
                }

                window.setTimeout(function () {
                    dialog.dialog('open');
                }, 100);
            });
        });
    </script>
    <div class="actionBar">
        <button id="submitJob" type="submit" class="button">Lodge Insurance Claim</button>
    </div>
}