File size: 3,621 Bytes
4e1096a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import clsx from 'clsx';
import * as React from 'react';
import { PiX } from 'react-icons/pi';
import { ReadingStatus } from '@/types/book';
import { useTranslation } from '@/hooks/useTranslation';
import { useKeyDownActions } from '@/hooks/useKeyDownActions';

interface SetStatusAlertProps {
  selectedCount: number;
  safeAreaBottom: number;
  onCancel: () => void;
  onUpdateStatus: (status: ReadingStatus | undefined) => void;
}

const SetStatusAlert: React.FC<SetStatusAlertProps> = ({
  selectedCount,
  safeAreaBottom,
  onCancel,
  onUpdateStatus,
}) => {
  const _ = useTranslation();
  const divRef = useKeyDownActions({ onCancel });

  const statusButtons = [
    {
      label: _('Mark as Unread'),
      status: 'unread' as ReadingStatus,
      className:
        'not-eink:bg-amber-500/15 not-eink:text-amber-600 dark:not-eink:text-amber-400 not-eink:border-amber-500/20 eink-bordered',
    },
    {
      label: _('Mark as Finished'),
      status: 'finished' as ReadingStatus,
      className:
        'not-eink:bg-success/15 not-eink:text-success not-eink:border-success/20 eink-bordered',
    },
    {
      label: _('Clear Status'),
      status: undefined,
      className:
        'not-eink:bg-base-300 not-eink:text-base-content not-eink:border-base-content/10 eink-bordered',
    },
  ];

  return (
    <div
      ref={divRef}
      className={clsx('status-alert fixed bottom-0 left-0 right-0 z-50 flex justify-center')}
      style={{
        paddingBottom: `${safeAreaBottom + 16}px`,
      }}
    >
      <div
        className={clsx(
          'flex w-auto max-w-[90vw] flex-col gap-3',
          'border-base-content/10 bg-base-200/95 rounded-2xl border p-4',
          'shadow-lg backdrop-blur-sm',
        )}
      >
        {/* Header with close button for small screens */}
        <div className='relative flex items-center justify-center'>
          <div className='text-center text-sm font-medium'>
            {_('Set status for {{count}} book(s)', { count: selectedCount })}
          </div>
          <button
            className={clsx(
              'absolute right-0 flex items-center justify-center',
              'rounded-full p-1.5 transition-colors',
              'hover:bg-base-content/10',
              'sm:hidden',
            )}
            onClick={onCancel}
            aria-label={_('Cancel')}
          >
            <PiX className='size-5' />
          </button>
        </div>
        <div className='flex flex-wrap items-center justify-center gap-2'>
          {statusButtons.map(({ label, status, className }) => (
            <button
              key={label}
              className={clsx(
                'flex items-center gap-2 rounded-full border px-4 py-2',
                'shadow-sm transition-all duration-200 ease-out active:scale-[0.97]',
                className,
              )}
              onClick={() => onUpdateStatus(status)}
            >
              <span className='text-sm font-medium'>{label}</span>
            </button>
          ))}
          <button
            className={clsx(
              'hidden items-center gap-2 rounded-full border px-4 py-2',
              'not-eink:bg-base-300 not-eink:text-base-content not-eink:border-base-content/10 not-eink:shadow-sm',
              'eink-bordered',
              'transition-all duration-200 ease-out active:scale-[0.97]',
              'sm:flex',
            )}
            onClick={onCancel}
          >
            <span className='text-sm font-medium'>{_('Cancel')}</span>
          </button>
        </div>
      </div>
    </div>
  );
};

export default SetStatusAlert;