function EditPostSheet({ post, onClose, onDone }) {
  const { BottomSheet, Button, ChipFilter } = window.SpotureDesignSystem_f7ad96;
  const p = post || {};
  const [caption, setCaption] = React.useState(p.caption || '');
  const [meal, setMeal] = React.useState(p.meal || '점심');
  const [tags, setTags] = React.useState((p.tags && p.tags[0]) || (p.menu ? [p.menu] : []));
  const [input, setInput] = React.useState('');
  const add = (raw) => { const v = (raw || '').trim().replace(/^#+/, '').slice(0, 15); if (!v) return; setTags(t => t.includes(v) || t.length >= 5 ? t : t.concat(v)); setInput(''); };
  const onKey = (ev) => {
    if (ev.key === 'Enter' || ev.key === ',') { ev.preventDefault(); add(input); }
    else if (ev.key === 'Backspace' && !input && tags.length) setTags(t => t.slice(0, -1));
  };
  return (
    <BottomSheet title="게시물 수정" titleAside={<span style={{ font: 'var(--text-small)', color: 'var(--text-muted)' }}>사진은 사진 관리에서</span>} onClose={onClose}
      footer={<div><Button variant="primary" onClick={() => onDone && onDone()}>수정 내용 저장</Button><p onClick={onClose} style={{ font: 'var(--text-caption)', color: 'var(--text-muted)', textAlign: 'center', margin: '12px 0 0', cursor: 'pointer' }}>취소</p></div>}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12, background: 'var(--surface-2)', borderRadius: 'var(--radius-tile)', padding: 12, marginBottom: 16 }}>
        <div style={{ width: 48, height: 48, borderRadius: 12, flexShrink: 0, background: 'var(--surface-1)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}><i className="ti ti-photo" style={{ fontSize: 19, color: 'var(--text-muted)' }}></i></div>
        <div style={{ minWidth: 0 }}>
          <span style={{ font: 'var(--text-body-strong)', display: 'block', marginBottom: 2 }}>{p.place || '장소 미지정'}</span>
          <span style={{ font: 'var(--text-small)', color: 'var(--text-secondary)' }}>{['사진 ' + (p.mediaCount || 1) + '장', p.time].filter(Boolean).join(' · ')}</span>
        </div>
      </div>
      <span style={{ font: 'var(--text-body-strong)', display: 'block', marginBottom: 10 }}>언제 먹었나요?</span>
      <div style={{ display: 'flex', gap: 8, marginBottom: 22 }}>
        {['아침', '점심', '저녁', '야식'].map(m => <ChipFilter key={m} label={m} active={meal === m} onClick={() => setMeal(m)} />)}
      </div>
      <span style={{ font: 'var(--text-body-strong)', display: 'block', marginBottom: 10 }}>메뉴 태그</span>
      <div style={{ background: 'var(--surface-1)', border: '1px solid ' + (tags.length ? 'var(--border-accent)' : 'var(--border)'), borderRadius: 'var(--radius-tile)', padding: '10px 12px', marginBottom: 22 }}>
        <div style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 7 }}>
          {tags.map(t => (
            <span key={t} style={{ display: 'inline-flex', alignItems: 'center', gap: 5, background: 'var(--bg-accent)', borderRadius: 999, padding: '7px 8px 7px 11px', font: '600 13px/1 var(--font-family)', color: 'var(--text-accent)' }}>
              #{t}<i className="ti ti-x" onClick={() => setTags(x => x.filter(v => v !== t))} style={{ fontSize: 13, cursor: 'pointer', opacity: .7 }}></i>
            </span>
          ))}
          {tags.length < 5 && <input value={input} onChange={ev => setInput(ev.target.value.slice(0, 15))} onKeyDown={onKey} onBlur={() => add(input)} placeholder={tags.length ? '하나 더' : '메뉴 태그 입력 · Enter로 추가'} style={{ flex: '1 1 96px', minWidth: 96, border: 'none', outline: 'none', background: 'transparent', font: 'var(--text-body)', color: 'var(--text-primary)', fontFamily: 'var(--font-family)', padding: '6px 2px' }} />}
        </div>
      </div>
      <span style={{ font: 'var(--text-body-strong)', display: 'block', marginBottom: 10 }}>어떤 점이 좋았나요?</span>
      <div style={{ background: 'var(--surface-1)', borderRadius: 'var(--radius-card)', padding: '16px 18px', boxShadow: 'var(--shadow-card)' }}>
        <textarea value={caption} onChange={ev => setCaption(ev.target.value.slice(0, 300))} placeholder="맛, 분위기, 추천 메뉴를 자유롭게 적어주세요" rows={4} style={{ width: '100%', border: 'none', outline: 'none', background: 'transparent', resize: 'none', font: 'var(--text-body)', lineHeight: 1.6, color: 'var(--text-primary)', fontFamily: 'var(--font-family)' }}></textarea>
        <div style={{ display: 'flex', justifyContent: 'flex-end' }}><span style={{ font: 'var(--text-micro)', color: 'var(--text-muted)' }}>{caption.length}/300</span></div>
      </div>
      <div style={{ display: 'flex', gap: 10, background: 'var(--surface-2)', borderRadius: 'var(--radius-tile)', padding: '13px 14px', marginTop: 12 }}>
        <i className="ti ti-info-circle" style={{ fontSize: 15, color: 'var(--text-secondary)', flexShrink: 0, marginTop: 1 }}></i>
        <span style={{ font: 'var(--text-small)', color: 'var(--text-secondary)', lineHeight: 1.6 }}>수정해도 좋아요와 댓글은 그대로 남아요. 장소는 「음식점 지정」에서 바꿀 수 있어요.</span>
      </div>
    </BottomSheet>
  );
}
window.EditPostSheet = EditPostSheet;

function HidePostConfirm({ post, hidden, onCancel, onConfirm }) {
  const acc = accountVis();
  const cur = postVisGet(post) || (hidden ? 'private' : 'public');
  return <VisibilitySheet current={cur} account={acc} word="게시물" title="게시물 공개 범위" onClose={onCancel} onPick={(v) => { postVisSet(post, v); onConfirm(v); }} />;
}
window.HidePostConfirm = HidePostConfirm;
