56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
@props(['name', 'value' => null, 'id' => null, 'class' => '', 'required' => false])
|
|
|
|
@php
|
|
$calendar = session('calendar', 'jalali');
|
|
$inputId = $id ?? $name;
|
|
$gregorianValue = null;
|
|
$displayValue = '';
|
|
|
|
// Normalize the value to a Gregorian Y-m-d string
|
|
if ($value) {
|
|
if ($value instanceof \DateTimeInterface) {
|
|
$gregorianValue = $value->format('Y-m-d');
|
|
} elseif (is_string($value) && strlen($value) >= 10) {
|
|
$gregorianValue = substr($value, 0, 10);
|
|
}
|
|
|
|
if ($calendar === 'jalali' && $gregorianValue) {
|
|
try {
|
|
$displayValue = \Morilog\Jalali\Jalalian::fromDateTime($gregorianValue)->format('Y/m/d');
|
|
} catch (\Exception $e) {
|
|
$displayValue = $gregorianValue;
|
|
}
|
|
} else {
|
|
$displayValue = $gregorianValue ?? '';
|
|
}
|
|
}
|
|
|
|
$defaultClass = 'w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500';
|
|
$cssClass = $class ?: $defaultClass;
|
|
@endphp
|
|
|
|
@if($calendar === 'jalali')
|
|
<div class="jalali-date-wrapper relative" data-picker="jalali">
|
|
<input type="text"
|
|
id="{{ $inputId }}_display"
|
|
class="jalali-datepicker-input {{ $cssClass }}"
|
|
value="{{ $displayValue }}"
|
|
placeholder="1404/03/15"
|
|
autocomplete="off"
|
|
data-gregorian-target="{{ $inputId }}"
|
|
{{ $required ? 'required' : '' }}
|
|
dir="ltr" />
|
|
<input type="hidden"
|
|
id="{{ $inputId }}"
|
|
name="{{ $name }}"
|
|
value="{{ $gregorianValue }}" />
|
|
</div>
|
|
@else
|
|
<input type="date"
|
|
id="{{ $inputId }}"
|
|
name="{{ $name }}"
|
|
value="{{ $gregorianValue }}"
|
|
class="{{ $cssClass }}"
|
|
{{ $required ? 'required' : '' }} />
|
|
@endif
|