@extends('layouts.app')
@section('title')
{{ $user->name }}
@parent
@stop
@section('header_styles')
<meta name="csrf_token" content="{{ csrf_token() }}">
<link href="{{ asset('assets/vendors/jasny-bootstrap/css/jasny-bootstrap.css') }}" rel="stylesheet" />
<link href="{{ asset('assets/vendors/x-editable/css/bootstrap-editable.css') }}" rel="stylesheet" />
<link href="{{ asset('assets/css/pages/user_profile.css') }}" rel="stylesheet" />
<style type="text/css">
  .text-warning {
    color: var(--orange) !important;
  }

  .text-success {
    color: var(--teal) !important;
  }

  .card:hover,
  .text-success:hover,
  .text-warning:hover {
    opacity: 0.9;
    color: inherit;
  }

  .accordion-item {
    margin-bottom: 10px;
  }

  .accordion-header {
    cursor: pointer;
    display: flex;
    align-items: center;
    background-color: white;
    padding: 10px 20px;
  }

  .accordion-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: bold !important;
  }

  .accordion-icon {
    font-size: 20px;
  }

  .accordion-content {
    display: none;
  }

  .loader-container {
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: flex;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
  }

  .loader {
    border: 16px solid #f3f3f3;
    border-radius: 50%;
    border-top: 16px solid #3498db;
    width: 120px;
    height: 120px;
    -webkit-animation: spin 2s linear infinite;
    /* Safari */
    animation: spin 2s linear infinite;
  }

  .d-none {
    display: none;
  }

  .select2-container--bootstrap .select2-selection--single {
    height: 38px;
    padding-top: 9px;
  }

  /* Safari */
  @-webkit-keyframes spin {
    0% {
      -webkit-transform: rotate(0deg);
    }

    100% {
      -webkit-transform: rotate(360deg);
    }
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }

    100% {
      transform: rotate(360deg);
    }
  }

  .small-input {
    width: 150px;
    height: 30px;
    padding: 5px;
    font-size: 14px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #f9f9f9;
    color: #333;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: border-color 0.2s ease-in-out;
  }

  .small-input:focus {
    outline: none;
    border-color: #007bff;
  }
</style>
@stop

{{-- Page content --}}
@section('content')
<main id="users_ac">
  <!--section ends-->
  <section>
    <div class="container">
      <div class="row">

        <div class="col-md-12 mt-xs-5">
          @if ($message = Session::get('error'))
          <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <strong>Sorry !!!</strong>{{ $message }}
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          @endif
          <h2 class="h4 p-3 bg-dark-light text-primary-light">
            <a href="{{route('crm.dashboard')}}"><i class="fa fa-home"></i> Dashboard </a>
          </h2>
          <div class="row font-18">
            <div class="col-md-3">
              <div class="card card-body hvr-icon-bob w-100 bigbox-hvr-slow text-center mt-4">
                <a class="text-danger" href="{{route('crm.risk')}}">

                  <div class="d-flex justify-content-between">
                    <div class="col-9 text-left">
                      <p class="my-2"><strong class="small font-weight-bold">At Risk
                          <hr class="my-1"> &nbsp;
                        </strong>
                    </div>
                    <i class="fa-solid hvr-icon fa-triangle-exclamation fa-3x mb-auto"></i>
                  </div>


                </a>
              </div>
            </div>

            <div class="col-md-3">
              <div class="card card-body hvr-icon-bob w-100 bigbox-hvr-slow text-center mt-4">
                <a class="text-warning" href="{{route('crm.opportunity')}}">

                  <div class="d-flex justify-content-between">
                    <div class="col-9 text-left">
                      <p class="my-2"><strong class="small font-weight-bold">Opportunity
                          <hr class="my-1"> &nbsp;
                        </strong>
                    </div>
                    <i class="fas hvr-icon fa-lightbulb fa-3x mb-auto"></i>
                  </div>


                </a>
              </div>
            </div>

            <div class="col-md-3">
              <div class="card card-body hvr-icon-bob w-100 bigbox-hvr-slow text-center mt-4">
                <a class="text-success" href="#" data-toggle="modal" data-target="#marc_mdl">
                  <div class="d-flex justify-content-between">
                    <div class="col-9 text-left">
                      <p class="my-2"><strong class="small font-weight-bold">MARC Record
                          <hr class="my-1"> Journals & ebooks
                        </strong>
                    </div>
                    <i class="fa hvr-icon fa-area-chart fa-3x mb-auto"></i>
                  </div>
                </a>
              </div>
            </div>
            <div class="col-md-3">
              <div class="card card-body hvr-icon-bob w-100 bigbox-hvr-slow text-center mt-4">
                <a class="text-info" href="#" data-toggle="modal" data-target="#kbart_mdl">
                  <div class="d-flex justify-content-between">
                    <div class="col-9 text-left">
                      <p class="my-2"><strong class="small font-weight-bold">KBART
                          <hr class="my-1"> Journals & ebooks
                        </strong>
                    </div>
                    <i class="fa-solid fa-chart-column hvr-icon fa-3x mb-auto"></i>
                  </div>
                </a>
              </div>
            </div>

            <div class="col-md-12">
              <div class="card card-body bg-siteblue text-white hvr-icon-bob w-100 bigbox-hvr-slow text-center mt-4">
                <a class="text-white" href="#" data-toggle="collapse" data-target="#subsc_clp" aria-expanded="false" aria-controls="subsc_clp">
                  <div class="d-flex justify-content-between">
                    <div class="col-9 text-left">
                      <p class="my-2"><strong class="large font-weight-bold">CUSTOMERS </strong>
                        <hr class="my-1"> <small>List of subscribers Corporate or Trial</small>
                    </div>
                    <i class="fa-solid fa-users-line hvr-icon fa-3x mb-auto"></i>
                  </div>
                </a>
              </div>
            </div>

          </div>
          <div class="collapse show" id="subsc_clp">
            <hr>

            <form action="{{route('crm.dashboard')}}" method="GET" class="form-group">
              @csrf
              <div class="form-row">
                <div class="form-group col-md-2">
                  <label for="by_customer"><strong>Customer Type</strong></label>
                  <select class="form-control" id="customer_type" name="customer_type">
                    <option value="Org" @if('Org'==$customer_type || $customer_type=='' ) {{ 'selected' }} @endif>Organization</option>
                    <!-- only for user crmadmin and faizan123 -->
                    @if($user->id == 611344 || $user->id == 581876)
                    <option value="user" @if('user'==$customer_type) {{ 'selected' }} @endif>User</option>
                    @endif
                    <option value="consortiaorg" @if('consortiaorg'==$customer_type) {{ 'selected' }} @endif>Consortia Organization</option>
                  </select>
                </div>
                <div class="form-group col-md-3">
                  <label for="by_country"><strong>By Country</strong></label>
                  <select class="form-control" id="by_country" name="by_country">
                    <option value="" hidden="true">-- Select Country --</option>
                    @foreach ($country_list as $country)
                    <option value="{{$country->iso}}" {{ $country_id == $country->iso ? "selected" : "" }}> {{$country->printable_name}}</option>
                    @endforeach
                  </select>
                </div>
                <div class="form-group col-md-3">
                  <label for="by_customer"><strong>By Customer Name</strong></label>
                  <input type="text" name="by_customer" class="form-control" placeholder="Search by customer...." value="{{$customer_name}}">
                </div>
                <div class="form-group col-md-2">
                  <label for="by_customer"><strong>By Organization Name</strong></label>
                  <input type="text" name="by_organization" class="form-control" placeholder="Search by organization name...." value="{{$organization_name}}">
                </div>
                <div class="form-group col-md-2 mt-1">
                  <div class="row">
                    <div class="col-6 pt-4 px-1 pl-3">
                      <button type="submit" class="btn btn-primary btn-block" name="filter" value="filter"><i class="fas fa-filter"></i> Filter</button>
                    </div>
                    <div class="col-6 pt-4 px-1">
                      <a href="{{route('crm.dashboard')}}" class="btn btn-warning btn-block text-white"><i class="far fa-times-circle"></i> Reset </a>
                    </div>
                  </div>
                </div>
              </div>
            </form>

            @if (!empty($organization_list))
            <div class="col-md-12">
              <h3>Total Found: {{$organization_count}}</h3>
            </div>
            @foreach($organization_list as $key => $value)
            <div class="accordion">
              <div class="accordion-item" href="#{{$value->access_organization_id}}">
                <div class="accordion-header d-flex">
                  <span class="accordion-icon p-1">+</span>
                  <h3>{{$value->organization_name}} </h3> &nbsp;&nbsp;&nbsp; @if (!empty($value->parent_id)) <font style="color:#6f42c1">({{$value->parent_name}})</font>@endif
                  @if(auth()->user()->id == "611344")
                  @php
                  $nameArray = [];
                  $idArray = [];

                  foreach ($customers as $row) {
                  if ($value->access_organization_id == $row->access_organization_id) {
                  $nameArray[] = $row->name;
                  $idArray[] = $row->id;
                  }
                  }

                  $nameArrayString = implode(',', $nameArray);
                  $idArrayString = implode(',', $idArray);
                  @endphp
                  <!-- Merge Report Button -->
                  <a class="btn btn-secondary btn-sm text-white ml-auto" href="javascript:get_usage_form('{{$nameArrayString}}','{{$idArrayString}}')">Merge Report <i class="fas fa-file-export"></i></a>
                  @endif
                </div>

                <div class="accordion-content" id="{{$value->access_organization_id}}">
                  <table class="table table-striped  font-14">
                    <thead>
                      <tr bgcolor="#01547d" class="text-white">
                        <th>S.No</th>
                        <th>Name</th>
                        <th>Country</th>
                        <th>Organization</th>
                        <th>Access Type</th>
                        <th>Remarks</th>
                        <th>Status</th>
                        <th width="12%">Action</th>
                      </tr>
                    </thead>
                    @php $cnt = 1; @endphp
                    @foreach($customers as $row)
                    @if ($value->access_organization_id==$row->access_organization_id)
                    <tbody>
                      <tr>
                        <td>{{$cnt++}}</td>
                        <td>{{$row->display_name}} ({{$row->name}})</td>
                        <td>{{$row->country_name}}</td>
                        <td>
                          {{$row->organization_name}}
                        </td>
                        <td>{{$row->access_type_title}} ({{$row->access_type_on}})
                          <br>
                          @if($row->perpetual == "0")
                          <p class="mt-2 mb-0 text-secondary"> <b>From : </b> {{gmdate("d-M-Y", $row->access_date_from)}}
                            <b>To : </b>{{gmdate("d-M-Y", $row->access_date_to)}}
                          </p>
                          @else
                          <div class="record" data-record-id="{{ $row->user_access_id }}">
                            <p class="mt-2 mb-0 text-secondary">{{"Perpetual"}}</p>
                            <p class="mt-2 mb-0 text-secondary paragraph">
                              <b class="perpetual_date" id="createdOnDate_{{ $row->user_access_id }}">Created on : {{gmdate("d-M-Y", $row->access_setup_on)}}</b>
                            </p>
                            <!--crmadmin -->
                            @if(auth()->user()->id == "611344")
                            <form class="editForm" name="first" method="post" action="{{ route('crm.access_perpetual_date') }}" enctype="multipart/form-data" style="display: none;">
                              @csrf
                              <input type="text" class="small-input" name="user_access_id" value="{{ $row->user_access_id}}" hidden>
                              <input type="date" class="small-input" name="access_setup_on" value="{{ gmdate('Y-M-d', $row->access_setup_on) }}">
                              <button type="submit" class="saveButton btn-primary text-white" style="display: none;">Save</button>
                            </form>

                            <button class="editButton btn-secondary text-white">Edit</button>
                            @endif
                          </div>
                          @endif
                        </td>
                        <td>
                          <button type="button" class="btn btn-info btn-sm open-remarks-modal" data-toggle="modal" data-target="#openremarksmodal_{{ $row->user_access_id}}" data-modal-id="{{ $row->user_access_id }}">View</button>
                          <!-- ******************************************* User Remarks Modal ******************************************* -->
                          <div class="modal fade bd-example-modal-lg" role="dialog" id="openremarksmodal_{{ $row->user_access_id}}" aria-hidden="true">
                            <div class="modal-dialog modal-sm">
                              <div class="modal-content remarks_body" data-remarks-id="{{ $row->user_access_id }}">
                                <div class="modal-header">
                                  <h4 class="m-0">Remarks</h4>
                                </div>
                                <div class="modal-body readable_remarks">
                                  <div id="remarksOn_{{ $row->user_access_id }}">{{$row->remarks}}</div>
                                </div>
                                <div class="modal-footer border-1 edit_remarks">
                                  @if(auth()->user()->id == "611344")
                                  <button type="button" class="btn btn-danger btn-sm edit_remarks">Edit</button>
                                  @endif
                                  <button type="button" class="btn btn-secondary btn-sm close_btn" data-dismiss="modal">Close</button>
                                </div>

                                @if(auth()->user()->id == "611344")
                                <form class="editremarksForm" name="second" method="post" action="{{ route('crm.access_perpetual_date') }}" enctype="multipart/form-data" style="display: none;">
                                  <div class="modal-body">
                                    @csrf
                                    <input type="text" class="small-input" name="user_access_id" value="{{ $row->user_access_id}}" hidden>
                                    <input type="text" class="small-input" name="tableflag" value="{{ $row->tableflag}}" hidden>
                                    <textarea name="remarks" rows="5" columns="5" class="form-control" style="resize: vertical; border: 1px solid #ccc; border-radius: 5px; padding: 8px;">{{ $row->remarks }}</textarea>
                                  </div>
                                  <div class="modal-footer border-1">
                                    <button type="submit" class="btn btn-primary btn-sm save_remarks" name="save_remarks" value="save_remarks">Save</button>
                                    <button type="button" class="btn btn-secondary btn-sm close_btn" data-dismiss="modal">Close</button>
                                  </div>
                                </form>
                                @endif

                              </div>
                            </div>
                          </div>
                        </td>
                        <td>
                          @if($row->user_access_status == "1")
                          <span class="badge badge-success">Active</span>
                          @else
                          <span class="badge badge-danger">Expire</span>
                          @endif
                        </td>
                        <td>
                          <div class="dropdown">
                            <a class="btn btn-primary  btn-sm dropdown-toggle" href="#" role="button" id="bt-normal-dd" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                              Reports
                            </a>
                            <div class="dropdown-menu font-14 dropdown-menu-right" aria-labelledby="bt-norma-dd">
                              <a class="dropdown-item" href="javascript:get_openathens_form('{{$row->name}}','{{encrypt($row->id)}}','{{$row->display_name}}','{{$row->openathensOrganisationId}}','{{$row->openathensrealmName}}','{{$row->openathensderivedEduPersonScope}}')"><i class="fa-solid fa-gears hvr-icon"></i> Openathens/Shibboleth</a>
                              <a class="dropdown-item" href="javascript:get_usage_form('{{$row->name}}','{{$row->id}}')"><i class="fa-solid fa-chart-column hvr-icon"></i> Counter Report</a>
                              @if(($row->access_type_id == "444" || $row->access_type_id == "555" || $row->access_type_id == "666") && ($row->user_access_status == "1"))
                              <a class="btn dropdown-item" data-toggle="modal" id="tokenButton" data-target="#tokenModal" data-attr="{{ route('crm.user_token_report',[$row->id])}}"><i class="fa-solid fa-chart-column hvr-icon"></i> Token Report</a>
                              @endif
                              <a class="dropdown-item" href="{{route('crm.combinereport',['param'=>\Crypt::encryptString($row->ingenta_id),'year'=>date('Y'),'eurekausername'=>\Crypt::encryptString($row->name)]    )}}"><i class="fa-solid fa-chart-column hvr-icon"></i> Eureka & Ingenta Analytics</a>

                              @if($row->access_type_on != "ebook_volume")
                              <a class="dropdown-item" href="{{route('crm.user.subscribejournal',['param'=>\Crypt::encryptString($row->id),'type'=>\Crypt::encryptString($row->access_type_id),'access_on'=>\Crypt::encryptString($row->access_type_on)])}}"><i class="fa-solid fa-chart-column hvr-icon"></i>View Subscribed Journals List</a>
                              @endif
                              @if($row->access_type_on == "ebook_volume")
                              <a class="dropdown-item" href="{{route('crm.user.subscribeebook',['param'=>\Crypt::encryptString($row->id),'type'=>\Crypt::encryptString($row->access_type_id),'access_on'=>\Crypt::encryptString($row->access_type_on)])}}"><i class="fa-solid fa-chart-column hvr-icon"></i>View Subscribed Ebook Volume List</a>
                              @endif
                              @if($row->access_type_on != "ebook_volume")
                              <a class="dropdown-item" href="{{route('user.marcdata.subscribejournal',\Crypt::encryptString($row->id))}}" target="_blanck"><i class="fa-solid fa-chart-column hvr-icon"></i>Subscribed Journal MARC Record</a>
                              @endif
                              @if($row->access_type_on != "journal_volume")
                              <a class="dropdown-item" href="{{route('user.marcdata.subscribeebook',\Crypt::encryptString($row->id))}}" target="_blanck"><i class="fa-solid fa-chart-column hvr-icon"></i> Subscribed Ebook MARC Record</a>
                              @endif
                              @if($row->access_type_on != "ebook_volume")
                              <a class="dropdown-item" href="{{route('user.kbart.subscribejournal',\Crypt::encryptString($row->id))}}" target="_blanck"><i class="fa-solid fa-chart-column hvr-icon"></i> Subscribed Journal KBRT Record</a>
                              @endif
                              @if($row->access_type_on != "journal_volume")
                              <a class="dropdown-item" href="{{route('user.kbart.subscribeebook',\Crypt::encryptString($row->id))}}" target="_blanck"><i class="fa-solid fa-chart-column hvr-icon"></i> Subscribed Ebook KBRT Record</a>
                              @endif
                              <a class="dropdown-item" href="{{route('crm.agent.authors',\Crypt::encryptString($row->id))}}"><i class="fa-solid fa-chart-column hvr-icon"></i> Authors</a>
                              <a class="dropdown-item" href="#"><i class="fa-solid fa-chart-column hvr-icon"></i> Ambassador</a>
                              <a class="dropdown-item" href="javascript:get_sushi_link('{{$row->name}}','{{$row->access_type_on}}')"><i class="fa-solid fa-chart-column hvr-icon"></i> SUSHI Report Link</a>
                            </div>
                          </div>
                        </td>
                      </tr>
                    </tbody>
                    @endif
                    @endforeach
                  </table>
                </div>
              </div>
            </div>
            @endforeach
            @else
            <div class="text-center">No Customer(s) Assign !!!</div>
            @endif
            @if (!empty($organization_list))
            <div class="pt-2"> {{$organization_list->links()}}</div>
            @endif
          </div>
        </div>
      </div>
    </div>
  </section>
</main>

<!-- ******************************************* COUNTER REPORT ******************************************** -->

<div class="modal fade bd-example-modal-lg" role="dialog" id="usagereportformmodal" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-body">

        <div class="col-md-12 mt-xs-5">

          <h2 class="h4 p-3 bg-dark-light text-primary-light">Counter Report </h2>

          <div class="card card-primary ">

            <div class="card-body">

              @include('includes.usagereportform')

            </div>

          </div>

        </div>

        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>

  </div>
</div>

<div class="modal fade bd-example-modal-lg" role="dialog" id="openathensformmodal" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-body">

        <div class="col-md-12 mt-xs-5">

          <h2 class="h4 p-3 bg-dark-light text-primary-light">Update Openathens/Shibboleth Access</h2>

          <div class="card card-primary ">

            <div class="card-body">

              <form name="first" method="post" action="{{ route('profile') }}" enctype="multipart/form-data">
                <input type="hidden" name="_token" value="<?= csrf_token() ?>">
                <input type="hidden" name="utm" id="utm" value="">
                <input type="hidden" name="by_country" id="by_country" value="{{Request()->by_country}}">
                <input type="hidden" name="by_customer" id="by_customer" value="{{Request()->by_customer}}">
                <div class="form-group col-md-12 {{ $errors->first('name', 'has-error') }}">
                  <label for="name" class="control-label">User Name *</label>
                  <span id="oausername">{!! old('name', $user->name) !!}</span>
                </div>
                <div class="form-group col-md-12 {{ $errors->first('display_name', 'has-error') }}">
                  <label for="display_name" class="control-label">Display Name *</label>
                  <input id="display_name" name="display_name" type="text" placeholder="Display Name" class="form-control required" value="{!! old('display_name', $user->display_name) !!}" />
                  {!! $errors->first('display_name', '<span class="text-danger">:message</span>') !!}
                </div>
                <div class="form-group col-md-12 {{ $errors->first('openathensOrganisationId', 'has-error') }}">
                  <label for="openathensOrganisationId" class="control-label">Openathens Organisation Id </label>
                  <input id="openathensOrganisationId" name="openathensOrganisationId" type="text" placeholder="openathens Organisation Id" class="form-control required" value="{!! old('openathensOrganisationId', $user->openathensOrganisationId) !!}" />
                  {!! $errors->first('openathensOrganisationId', '<span class="text-danger">:message</span>') !!}
                </div>
                <div class="form-group col-md-12 {{ $errors->first('openathensrealmName', 'has-error') }}">
                  <label for="openathensrealmName" class="control-label">Openathens idp/entity </label>
                  <input id="openathensrealmName" name="openathensrealmName" type="text" placeholder="Openathens idp/entity" class="form-control required" value="{!! old('openathensrealmName', $user->openathensrealmName) !!}" />
                  {!! $errors->first('openathensrealmName', '<span class="text-danger">:message</span>') !!}
                </div>
                <div class="form-group col-md-12 {{ $errors->first('openathensderivedEduPersonScope', 'has-error') }}">
                  <label for="openathensderivedEduPersonScope" class="control-label">Openathens Affiliation Scope </label>
                  <input id="openathensderivedEduPersonScope" name="openathensderivedEduPersonScope" type="text" placeholder="comma separated values" class="form-control required" value="{!! old('openathensderivedEduPersonScope', $user->openathensderivedEduPersonScope) !!}" />
                  {!! $errors->first('openathensderivedEduPersonScope', '<span class="text-danger">:message</span>') !!}
                </div>

                <button class="btn btn-primary" id="oaSave" type="submit">Save</button>
              </form>
            </div>

          </div>

        </div>

        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>

  </div>
</div>

<!-- ******************************************* MARC REPORT ******************************************** -->
<div class="modal fade bd-example-modal-lg" role="dialog" id="marc_mdl" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-body">
        @include('admin.marcdata.includes.marc_form')
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- ******************************************* KBART REPORT ******************************************** -->
<div class="modal fade bd-example-modal-lg" role="dialog" id="kbart_mdl" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-body">
        @include('admin.kbart.includes.kbart_form')
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- ******************************************* Token Report Modal ******************************************** -->
<div class="modal fade" id="tokenModal" tabindex="-1" role="dialog" aria-labelledby="tokenModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-body" id="tokenBody">
        <!-- the result to be displayed here -->
      </div>
    </div>
  </div>
</div>
<div class="loader-container" id="loader" style="display: none;">
  <div class="loader">
  </div>
</div>

<!-- ******************************************* SUSHI Link Modal ******************************************** -->
<div class="modal fade bd-example-modal-lg" role="dialog" id="opensushimodal" aria-hidden="true">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
      <div class="modal-body">
        <div class="col-md-12 mt-xs-5">
          <h2 class="h4 p-3 bg-dark-light text-primary-light">SUSHI Links</h2>
          <div class="card card-primary ">
            <div class="card-body">
              <div class="form-group col-md-12" id="rowj1_report">
                <h5 class="control-label">TR J1</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="j1_report"></div>
              </div>
              <div class="form-group col-md-12" id="rowj2_report">
                <h5 class="control-label">TR J2</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="j2_report"></div>
              </div>
              <div class="form-group col-md-12" id="rowj3_report">
                <h5 class="control-label">TR J3</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="j3_report"></div>
              </div>
              <div class="form-group col-md-12" id="rowj4_report">
                <h5 class="control-label">TR J4</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="j4_report"></div>
              </div>
              <div class="form-group col-md-12" id="rowtr_report">
                <h5 class="control-label">Title Report</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="tr_report"></div>
              </div>
              <div class="form-group col-md-12" id="rowpr_report">
                <h5 class="control-label">Platform Master Report</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="pr_report"></div>
              </div>


              <div class="form-group col-md-12" id="rowb1_report">
                <h5 class="control-label">TR B1</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="b1_report"></div>
              </div>
              <div class="form-group col-md-12" id="rowb2_report">
                <h5 class="control-label">TR B2</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="b2_report"></div>
              </div>
              <div class="form-group col-md-12" id="rowb3_report">
                <h5 class="control-label">TR B3</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="b3_report"></div>
              </div>
              <div class="form-group col-md-12" id="rowbook_tr_report">
                <h5 class="control-label">Title Report</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="book_tr_report"></div>
              </div>
              <div class="form-group col-md-12" id="rowbook_pr_report">
                <h5 class="control-label">Platform Master Report</h5>
                <div class="form-control h-auto " style="word-break: break-all;" id="book_pr_report"></div>
              </div>

            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer border-0">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>



@stop
<script>
  function get_usage_form(username, userid) {
    $("#user_name").val(username);
    $("#user_id").val(userid);

    $('#usagereportformmodal').modal('toggle');

    $('#usagereportformmodal').modal('show');

    CheckUserExist(userid);
  }

  function get_openathens_form(username, userid, displayname, openathensOrganisationId, openathensrealmName, openathensderivedEduPersonScope) {
    $("#oausername").html(username);
    $("#utm").val(userid);
    $("#display_name").val(displayname);
    $("#openathensOrganisationId").val(openathensOrganisationId);
    $("#openathensrealmName").val(openathensrealmName);
    $("#openathensderivedEduPersonScope").val(openathensderivedEduPersonScope);

    $('#openathensformmodal').modal('toggle');

    $('#openathensformmodal').modal('show');

    //CheckUserExist(userid);
  }
</script>
@section('footer_scripts')
<script>
  $(document).ready(function() {

    //$('input:radio[name=select_search_mode]:checked').val() == 'basic_search'
    $('#mtcolumn').hide();
    $('#dtcolumn').hide();
    $('#atcolumn').hide();
    $('#amcolumn').hide();
    $('#yopcolumn').hide();
    $('#emcolumn').hide();


  });

  function CheckUserExist(user) {

    $.ajax({
      type: "GET",
      url: '/admin/CheckUser/' + user,
      data: {},
      beforeSend: function() {

        $('#loader').addClass('fa-spin');
      },
      success: function(msg) {
        console.log(msg);
        if (msg == "0") {

          $('#exportbtn').hide();
          $('.input-group').addClass('has-error');
          $('#user_id').val('');

        } else {

          $('#exportbtn').show();
          $('.input-group').removeClass('has-error');

        }
      },

      complete: function() {

        $('#loader').removeClass('fa-spin');

      },
    });

  }

  function disabledebook(v, uid) {

    //

    $('#mtcolumn').hide();
    $('#dtcolumn').hide();
    $('#atcolumn').hide();
    $('#amcolumn').hide();
    $('#yopcolumn').hide();
    $('#emcolumn').hide();

    var journal = ['TR_J1', 'TR_J2', 'TR_J3', 'TR_J4', 'Title Report'];
    var ebook = ['TR_B1', 'TR_B2', 'TR_B3'];
    var chapter = ['BR2'];
    var platform = ['PR_P1', 'PR'];

    var x = document.getElementById("reporttype");
    for (i = 0; i < x.length;) {
      x.remove(x.length - 1);
    }

    var a;
    if (v == 'exportrange1') {
      a = ebook;
    } else if (v == 'exportrange2') {
      a = chapter;
    } else if (v == 'exportrange3') {
      a = journal;
    } else if (v == 'exportrange4') {
      a = platform;
    }

    for (i = 0; i < a.length; ++i) {
      var option = document.createElement("option");
      option.text = a[i];
      if (v == 'exportrange1') {
        option.value = '';
        option.value = i + 6;
        x.add(option);
      }
      if (v == 'exportrange2') {
        option.value = '';
        option.value = 7;
        x.add(option);
      }
      if (v == 'exportrange3') {
        option.value = '';
        option.value = i + 1;
        x.add(option);
      }
      if (v == 'exportrange4') {
        option.value = '';
        option.value = i + 8;
        x.add(option);
      }
      x.add(option);
    }


  }

  function LoadTRDetail(id) {

    if (id == 5 || id == 9) {
      $('#mtcolumn').show();
      $('#dtcolumn').show();
      $('#atcolumn').show();
      $('#amcolumn').show();
      $('#yopcolumn').show();
      $('#emcolumn').show();

    } else {

      $('#mtcolumn').hide();
      $('#dtcolumn').hide();
      $('#atcolumn').hide();
      $('#amcolumn').hide();
      $('#yopcolumn').hide();
      $('#emcolumn').hide();

    }
  }
</script>

<script>
  // Get all the accordion items
  const accordionItems = document.querySelectorAll('.accordion-item');

  // Add click event listener to each accordion item
  accordionItems.forEach(item => {
    const header = item.querySelector('.accordion-header');
    const icon = item.querySelector('.accordion-icon');

    header.addEventListener('click', () => {
      // Toggle the content visibility
      const content = item.querySelector('.accordion-content');
      content.style.display = content.style.display === 'block' ? 'none' : 'block';

      // Change the icon
      icon.textContent = icon.textContent === '+' ? '-' : '+';
    });
  });
</script>

<script>
  // display a token modal
  $(document).on('click', '#tokenButton', function(event) {
    event.preventDefault();
    let href = $(this).attr('data-attr');
    $.ajax({
      url: href,
      beforeSend: function() {
        $('#loader').show();
      },
      // return the result
      success: function(result) {
        $("#loader").hide();
        $('#tokenModal').modal("show");
        $('#tokenBody').html(result).show();
      },
    })
  });
</script>

<script>
  function get_sushi_link(name, access_type_on) {

    let date = new Date().getFullYear();
    ////////////////Journal////////////////
    $("#j1_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/tr_j1?customer_id=' + name + '&requestor_id=counter001&begin_date=' + date + '-01&end_date=' + date + '-12');

    $("#j2_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/tr_j2?customer_id=' + name + '&requestor_id=counter001&begin_date=' + date + '-01&end_date=' + date + '-12');

    $("#j3_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/tr_j3?customer_id=' + name + '&requestor_id=counter001&begin_date=' + date + '-01&end_date=' + date + '-12');

    $("#j4_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/tr_j4?customer_id=' + name + '&requestor_id=counter001&begin_date=' + date + '-01&end_date=' + date + '-12');

    $("#tr_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/tr?requestor_id=counter001&customer_id=' + name + '&begin_date=' + date + '-01&end_date=' + date + '-12&metric_type=Total_Item_Requests|Unique_Item_Requests|Total_Item_Investigations|Unique_Item_Investigations|Unique_Item_Requests&access_type=Controlled|OA_Gold&data_type=Journal&access_method=Regular');

    $("#pr_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/pr?requestor_id=counter001&customer_id=' + name + '&begin_date=' + date + '-01&end_date=' + date + '-12');

    ///////////////book////////////////

    $("#b1_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/tr_b1?customer_id=' + name + '&requestor_id=counter001&begin_date=' + date + '-01&end_date=' + date + '-12');

    $("#b2_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/tr_b2?customer_id=' + name + '&requestor_id=counter001&begin_date=' + date + '-01&end_date=' + date + '-12');

    $("#b3_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/tr_b3?customer_id=' + name + '&requestor_id=counter001&begin_date=' + date + '-01&end_date=' + date + '-12');

    $("#book_tr_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/tr?requestor_id=counter001&customer_id=' + name + '&begin_date=' + date + '-01&end_date=' + date + '-12&metric_type=Total_Item_Requests|Unique_Item_Requests|Total_Item_Investigations|Unique_Item_Investigations|Unique_Item_Requests|Unique_Title_Investigations|Unique_Title_Requests&access_type=Controlled|OA_Gold&data_type=Book&access_method=Regular');

    $("#book_pr_report").html('https://www.eurekaselect.com/tool/sushi/R5/reports/pr?requestor_id=counter001&customer_id=' + name + '&begin_date=' + date + '-01&end_date=' + date + '-12');

    if (access_type_on == 'journal_volume') {
      $("#rowj1_report").show();
      $("#rowj2_report").show();
      $("#rowj3_report").show();
      $("#rowj4_report").show();
      $("#rowtr_report").show();
      $("#rowpr_report").show();

      $("#rowb1_report").hide();
      $("#rowb2_report").hide();
      $("#rowb3_report").hide();
      $("#rowbook_tr_report").hide();
      $("#rowbook_pr_report").hide();
    }
    if (access_type_on == 'ebook_volume') {
      $("#rowj1_report").hide();
      $("#rowj2_report").hide();
      $("#rowj3_report").hide();
      $("#rowj4_report").hide();
      $("#rowtr_report").hide();
      $("#rowpr_report").hide();

      $("#rowb1_report").show();
      $("#rowb2_report").show();
      $("#rowb3_report").show();
      $("#rowbook_tr_report").show();
      $("#rowbook_pr_report").show();
    }

    //$('#opensushimodal').modal('toggle');

    $('#opensushimodal').modal('show');
  }
</script>

<!-- Hide/Show Perpetual Date Edit Button -->
<script>
  $(document).ready(function() {

    $(".editButton").click(function() {
      var $record = $(this).closest('.record');
      $record.find('.editButton').hide();
      $record.find('.perpetual_date').hide();
      $record.find('.saveButton').show();
      $record.find('.editForm').show();
    });

    $(".saveButton").click(function() {
      var $record = $(this).closest('.record');
      $record.find('.editButton').show();
      $record.find('.perpetual_date').show();
      $record.find('.saveButton').hide();
      $record.find('.editForm').hide();
    });

    // When form is submitted
    $(".editForm").submit(function(event) {
      event.preventDefault();

      var $form = $(this);
      var recordId = $form.closest('.record').data("record-id");

      var formData = $form.serialize();

      $.ajax({
        type: "POST",
        url: $form.attr('action'),
        data: formData,
        beforeSend: function() {
          $('#loader').show();
        },
        success: function(response) {
          $("#loader").hide();

          var newDate = $form.find('input[name="access_setup_on"]').val();

          var $createdOnDate = $("#createdOnDate_" + recordId);

          $createdOnDate.empty().append('Created on : ' + newDate);
        },
        error: function() {
          alert('Error occurred while submitting the form.');
        }
      });
    });

  });
</script>

<!-- User Remarks -->
<script>
  $(document).ready(function() {

    // Show edit form when user click on edit button
    $(".edit_remarks").click(function() {
      var $remarks = $(this).closest('.remarks_body');
      $remarks.find('.edit_remarks').hide();
      $remarks.find('.readable_remarks').hide();
      $remarks.find('.editremarksForm').show();
    });

    // Hide form when user click close button
    $(".close_btn").click(function() {
      var $remarks = $(this).closest('.remarks_body');
      $remarks.find('.edit_remarks').show();
      $remarks.find('.readable_remarks').show();
      $remarks.find('.editremarksForm').css('display', 'none');
    });

    // When modal is shown hide the form
    $('.open-remarks-modal').on('click', function() {
      var modalId = $(this).data('modal-id');
      var $modal = $('#openremarksmodal_' + modalId);
      // Reset the form state by hiding it
      var $remarks = $modal.find('.remarks_body');
      $remarks.find('.edit_remarks').show();
      $remarks.find('.readable_remarks').show();
      $remarks.find('.editremarksForm').css('display', 'none');
    });

    // When remarks form is submitted
    $(".editremarksForm").submit(function(event) {
      event.preventDefault();

      var $form = $(this);
      var remarksId = $form.closest('.remarks_body').data("remarks-id");

      var remarksButtonValue = event.originalEvent.submitter.value;

      // Remove special characters from textarea value
      removeSpecialCharactersFromTextarea($form);

      var formData = $form.serialize();

      $.ajax({
        type: "POST",
        url: $form.attr('action'),
        data: formData + '&save_remarks=' + remarksButtonValue,
        beforeSend: function() {
          $('#loader').show();
        },
        success: function(response) {
          $("#loader").hide();

          var newRemarks = $form.find('textarea[name="remarks"]').val();

          var $remarksText = $("#remarksOn_" + remarksId);

          $remarksText.empty().append(newRemarks);

          $form.hide();

          // Show the "Edit" button and the readable_remarks section
          var $remarksBody = $form.closest('.remarks_body');
          $remarksBody.find('.edit_remarks').show();
          $remarksBody.find('.readable_remarks').show();

        },
        error: function() {
          alert('Error occurred while submitting the form.');
        }
      });
    });

  });

  // Function to remove special characters from textarea value
  function removeSpecialCharactersFromTextarea($form) {
    var $textarea = $form.find('textarea[name="remarks"]');
    var originalValue = $textarea.val();
    var sanitizedValue = removeSpecialCharacters(originalValue);
    $textarea.val(sanitizedValue);
  }

  // Function to remove special characters
  function removeSpecialCharacters(input) {
    // Define a regular expression to match special characters
    var regex = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/g;

    // Use the replace method to remove special characters
    return input.replace(regex, '');
  }
</script>

<!-- Select2 Dropdown -->
<script>
  jQuery.noConflict();
  (function($) {
    $(document).ready(function() {
      $("#by_country").select2({
        theme: "bootstrap",
        placeholder: "Select Country",
        width: '100%'
      });
    });
  })(jQuery);
</script>

@stop