All files / web/src/components/flowcharts FlowchartCard.tsx

0% Statements 0/216
0% Branches 0/1
0% Functions 0/1
0% Lines 0/216

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217                                                                                                                                                                                                                                                                                                                                                                                                                                                 
'use client'

import { css } from '../../../styled-system/css'
import { vstack, hstack } from '../../../styled-system/patterns'
import type { TeacherFlowchart } from '@/hooks/useTeacherFlowcharts'

interface Props {
  flowchart: TeacherFlowchart
  isLoading: boolean
  onEdit: () => void
  onPublish: () => void
  onUnpublish: () => void
  onDelete: () => void
  onUse: () => void
}

export function FlowchartCard({
  flowchart,
  isLoading,
  onEdit,
  onPublish,
  onUnpublish,
  onDelete,
  onUse,
}: Props) {
  return (
    <div
      data-element="flowchart-card"
      className={css({
        padding: '4',
        backgroundColor: { base: 'white', _dark: 'gray.800' },
        borderRadius: 'lg',
        border: '1px solid',
        borderColor: { base: 'gray.200', _dark: 'gray.700' },
      })}
    >
      <div
        className={hstack({ gap: '4', justifyContent: 'space-between', alignItems: 'flex-start' })}
      >
        <div className={hstack({ gap: '3', alignItems: 'flex-start' })}>
          <span className={css({ fontSize: '2xl' })}>{flowchart.emoji || '📊'}</span>
          <div className={vstack({ gap: '1', alignItems: 'flex-start' })}>
            <h3
              className={css({
                fontWeight: 'semibold',
                color: { base: 'gray.900', _dark: 'gray.100' },
              })}
            >
              {flowchart.title}
            </h3>
            {flowchart.description && (
              <p
                className={css({
                  fontSize: 'sm',
                  color: { base: 'gray.600', _dark: 'gray.400' },
                })}
              >
                {flowchart.description}
              </p>
            )}
            <div className={hstack({ gap: '2' })}>
              {flowchart.difficulty && (
                <span
                  className={css({
                    fontSize: 'xs',
                    padding: '0.5 2',
                    borderRadius: 'full',
                    backgroundColor: { base: 'blue.100', _dark: 'blue.900' },
                    color: { base: 'blue.700', _dark: 'blue.300' },
                  })}
                >
                  {flowchart.difficulty}
                </span>
              )}
              <span
                className={css({
                  fontSize: 'xs',
                  padding: '0.5 2',
                  borderRadius: 'full',
                  backgroundColor:
                    flowchart.status === 'published'
                      ? { base: 'green.100', _dark: 'green.900' }
                      : { base: 'gray.100', _dark: 'gray.700' },
                  color:
                    flowchart.status === 'published'
                      ? { base: 'green.700', _dark: 'green.300' }
                      : { base: 'gray.600', _dark: 'gray.400' },
                })}
              >
                {flowchart.status}
              </span>
              {flowchart.version > 1 && (
                <span
                  className={css({
                    fontSize: 'xs',
                    color: { base: 'gray.500', _dark: 'gray.500' },
                  })}
                >
                  v{flowchart.version}
                </span>
              )}
            </div>
          </div>
        </div>

        <div className={hstack({ gap: '2' })}>
          {flowchart.status === 'published' && (
            <button
              data-action="use"
              onClick={onUse}
              disabled={isLoading}
              className={css({
                paddingY: '2',
                paddingX: '3',
                borderRadius: 'md',
                backgroundColor: { base: 'blue.600', _dark: 'blue.500' },
                color: 'white',
                fontSize: 'sm',
                fontWeight: 'medium',
                border: 'none',
                cursor: 'pointer',
                _hover: { backgroundColor: { base: 'blue.700', _dark: 'blue.600' } },
                _disabled: { opacity: 0.5, cursor: 'not-allowed' },
              })}
            >
              Use
            </button>
          )}
          <button
            data-action="edit"
            onClick={onEdit}
            disabled={isLoading}
            className={css({
              paddingY: '2',
              paddingX: '3',
              borderRadius: 'md',
              backgroundColor: { base: 'gray.100', _dark: 'gray.700' },
              color: { base: 'gray.700', _dark: 'gray.300' },
              fontSize: 'sm',
              border: 'none',
              cursor: 'pointer',
              _hover: { backgroundColor: { base: 'gray.200', _dark: 'gray.600' } },
              _disabled: { opacity: 0.5, cursor: 'not-allowed' },
            })}
          >
            Edit
          </button>
          {flowchart.status === 'draft' ? (
            <button
              data-action="publish"
              onClick={onPublish}
              disabled={isLoading}
              className={css({
                paddingY: '2',
                paddingX: '3',
                borderRadius: 'md',
                backgroundColor: { base: 'green.100', _dark: 'green.900' },
                color: { base: 'green.700', _dark: 'green.300' },
                fontSize: 'sm',
                fontWeight: 'medium',
                border: 'none',
                cursor: 'pointer',
                _hover: { backgroundColor: { base: 'green.200', _dark: 'green.800' } },
                _disabled: { opacity: 0.5, cursor: 'not-allowed' },
              })}
            >
              {isLoading ? '…' : 'Publish'}
            </button>
          ) : (
            <button
              data-action="unpublish"
              onClick={onUnpublish}
              disabled={isLoading}
              className={css({
                paddingY: '2',
                paddingX: '3',
                borderRadius: 'md',
                backgroundColor: { base: 'yellow.100', _dark: 'yellow.900' },
                color: { base: 'yellow.700', _dark: 'yellow.300' },
                fontSize: 'sm',
                border: 'none',
                cursor: 'pointer',
                _hover: { backgroundColor: { base: 'yellow.200', _dark: 'yellow.800' } },
                _disabled: { opacity: 0.5, cursor: 'not-allowed' },
              })}
            >
              {isLoading ? '…' : 'Unpublish'}
            </button>
          )}
          <button
            data-action="delete"
            onClick={onDelete}
            disabled={isLoading}
            className={css({
              paddingY: '2',
              paddingX: '3',
              borderRadius: 'md',
              backgroundColor: 'transparent',
              color: { base: 'gray.500', _dark: 'gray.500' },
              fontSize: 'sm',
              border: 'none',
              cursor: 'pointer',
              _hover: {
                backgroundColor: { base: 'red.50', _dark: 'red.900/30' },
                color: { base: 'red.600', _dark: 'red.400' },
              },
              _disabled: { opacity: 0.5, cursor: 'not-allowed' },
            })}
          >
            Archive
          </button>
        </div>
      </div>
    </div>
  )
}