@php
    $wh = isset($venue) ? ($venue->working_hours ?? []) : [];
    $useDefault = isset($venue) ? (bool) ($wh['use_default'] ?? true) : true;
    $whDays  = $wh['days'] ?? [0, 1, 2, 3, 4, 5, 6];
    $whOpen  = $wh['open'] ?? '10:00';
    $whClose = $wh['close'] ?? '22:00';
    $dayKeys = ['d_sun', 'd_mon', 'd_tue', 'd_wed', 'd_thu', 'd_fri', 'd_sat'];
@endphp

<div class="row">
  <div class="col-md-6">
    <div class="form-group">
      {!! Form::label('name', __('bms::lang.venue') . ' (EN):*') !!}
      {!! Form::text('name', null, ['class' => 'form-control', 'required']) !!}
    </div>
  </div>
  <div class="col-md-6">
    <div class="form-group">
      {!! Form::label('name_ar', __('bms::lang.venue') . ' (AR):') !!}
      {!! Form::text('name_ar', null, ['class' => 'form-control', 'dir' => 'rtl']) !!}
    </div>
  </div>
</div>

<div class="form-group">
  {!! Form::label('location_id', __('business.business_location') . ':*') !!}
  {!! Form::select('location_id', $locations, null, ['class' => 'form-control', 'required', 'placeholder' => __('messages.please_select')]) !!}
  <span class="help-block">@lang('bms::lang.venue_location_note')</span>
</div>

{{-- Working days & hours: business default OR a custom set (not both). --}}
<div class="form-group bms-wh">
  {!! Form::label('working_hours', __('bms::lang.working_hours') . ':') !!}
  <div class="radio" style="margin:4px 0;">
    <label class="tw-font-normal">
      {!! Form::radio('wh_mode', 'default', $useDefault, ['class' => 'bms-wh-mode']) !!}
      @lang('bms::lang.use_default_hours')
    </label>
  </div>
  <div class="radio" style="margin:4px 0 8px;">
    <label class="tw-font-normal">
      {!! Form::radio('wh_mode', 'custom', ! $useDefault, ['class' => 'bms-wh-mode']) !!}
      @lang('bms::lang.custom_hours')
    </label>
  </div>
  <div class="bms-wh-custom" style="{{ $useDefault ? 'display:none;' : '' }} padding-inline-start:22px;">
    <div class="row">
      <div class="col-md-8">
        <label class="text-muted">@lang('bms::lang.working_days')</label>
        <div>
          @foreach ($dayKeys as $i => $dk)
            <label class="tw-font-normal" style="display:inline-block;margin-inline-end:12px;">
              {!! Form::checkbox('wh_days[]', $i, in_array($i, $whDays), ['class' => 'input-icheck']) !!}
              @lang('bms::lang.'.$dk)
            </label>
          @endforeach
        </div>
      </div>
      <div class="col-md-2">
        <label class="text-muted">@lang('bms::lang.open_time')</label>
        {!! Form::time('wh_open', $whOpen, ['class' => 'form-control']) !!}
      </div>
      <div class="col-md-2">
        <label class="text-muted">@lang('bms::lang.close_time')</label>
        {!! Form::time('wh_close', $whClose, ['class' => 'form-control']) !!}
      </div>
    </div>
  </div>
</div>
<script>
$(function () {
  var $wh = $('.bms-wh').last();
  $wh.off('change.whmode').on('change.whmode', '.bms-wh-mode', function () {
    $wh.find('.bms-wh-custom').toggle($wh.find('.bms-wh-mode:checked').val() === 'custom');
  });
});
</script>

<div class="row">
  <div class="col-md-9">
    <div class="form-group">
      {!! Form::label('description', __('bms::lang.description') . ':') !!}
      {!! Form::textarea('description', null, ['class' => 'form-control', 'rows' => 2]) !!}
    </div>
  </div>
  <div class="col-md-3">
    <div class="form-group">
      <label class="tw-mt-7">
        {!! Form::checkbox('is_active', 1, isset($venue) ? null : true, ['class' => 'input-icheck']) !!}
        @lang('bms::lang.active')
      </label>
    </div>
  </div>
</div>
